~benomrane-b/avogadro/avogadro

« back to all changes in this revision

Viewing changes to avogadro/src/enginecolorswidget.cpp

  • Committer: benomrane_b at yahoo
  • Date: 2014-07-02 17:22:21 UTC
  • Revision ID: benomrane_b@yahoo.fr-20140702172221-vf3hdle85h6szhhf
Release version 1.1.1 2013-12-11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**********************************************************************
 
2
  EngineColorsWidget - Widget for setting the engine color map.
 
3
 
 
4
  Copyright (C) 2008 Tim Vandermeersch
 
5
 
 
6
  This file is part of the Avogadro molecular editor project.
 
7
  For more information, see <http://avogadro.openmolecules.net/>
 
8
 
 
9
  Avogadro is free software; you can redistribute it and/or modify
 
10
  it under the terms of the GNU General Public License as published by
 
11
  the Free Software Foundation; either version 2 of the License, or
 
12
  (at your option) any later version.
 
13
 
 
14
  Avogadro is distributed in the hope that it will be useful,
 
15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
  GNU General Public License for more details.
 
18
 
 
19
  You should have received a copy of the GNU General Public License
 
20
  along with this program; if not, write to the Free Software
 
21
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
22
  02110-1301, USA.
 
23
 **********************************************************************/
 
24
 
 
25
#include "enginecolorswidget.h"
 
26
 
 
27
#include <avogadro/engine.h>
 
28
#include <avogadro/color.h>
 
29
#include <avogadro/pluginmanager.h>
 
30
 
 
31
#include <QDialog>
 
32
#include <QDebug>
 
33
 
 
34
namespace Avogadro {
 
35
 
 
36
  class EngineColorsWidgetPrivate
 
37
  {
 
38
  public:
 
39
    EngineColorsWidgetPrivate() : engine(0), currentSettingsWidget(0) {};
 
40
    
 
41
    Engine *engine;
 
42
    PluginManager *pluginManager;
 
43
    QWidget *currentSettingsWidget;
 
44
  };
 
45
 
 
46
  EngineColorsWidget::EngineColorsWidget( PluginManager *pluginManager,
 
47
                                          QWidget *parent )
 
48
    : QWidget(parent), d(new EngineColorsWidgetPrivate)
 
49
  {
 
50
    ui.setupUi(this);
 
51
    d->pluginManager = pluginManager;
 
52
 
 
53
    foreach(Color *color, pluginManager->colors())
 
54
    {
 
55
      ui.colorCombo->addItem(color->name());
 
56
    }
 
57
 
 
58
    connect(ui.colorCombo, SIGNAL(currentIndexChanged(int)),
 
59
        this, SLOT(colorChanged(int)));
 
60
    // we should actually check the engine settings for the current color choice
 
61
  }
 
62
 
 
63
  EngineColorsWidget::~EngineColorsWidget()
 
64
  {
 
65
    d->currentSettingsWidget = NULL;
 
66
    delete d;
 
67
  }
 
68
 
 
69
  void EngineColorsWidget::colorChanged(int index)
 
70
  {
 
71
    Color *color = d->pluginManager->colors().at(index);
 
72
 
 
73
    if (!color)
 
74
      return;
 
75
 
 
76
    d->engine->setColorMap(color);
 
77
    if (d->currentSettingsWidget) {
 
78
      d->currentSettingsWidget->hide();
 
79
      ui.verticalLayout->removeWidget(d->currentSettingsWidget);
 
80
 
 
81
      // Remove the bottom spacer
 
82
      QLayoutItem *space;
 
83
      space = ui.verticalLayout->takeAt(-1);
 
84
      ui.verticalLayout->removeItem(space);
 
85
      
 
86
      d->currentSettingsWidget = NULL;
 
87
    }
 
88
    
 
89
    if (color->settingsWidget()) {
 
90
      d->currentSettingsWidget = color->settingsWidget();
 
91
      ui.verticalLayout->addWidget(d->currentSettingsWidget);
 
92
      ui.verticalLayout->addStretch();
 
93
      d->currentSettingsWidget->show();
 
94
    }
 
95
  }
 
96
 
 
97
  void EngineColorsWidget::setEngine( Engine *engine )
 
98
  {
 
99
    d->engine = engine;
 
100
    //ui.colorCombo->setEnabled(true);
 
101
  }
 
102
 
 
103
} // end namespace Avogadro
 
104
 
 
105
#include "enginecolorswidget.moc"