comboboxbutton.cpp
Go to the documentation of this file.
1 #include "comboboxbutton.h"
2 #include "scenariomodel.h"
3 #include <QMouseEvent>
4 #include <QStylePainter>
9 
10 
11 ComboBoxButton::ComboBoxButton(const QAbstractItemModel* model, const QString& scenarioName, QWidget* parent) :
12  QComboBox(parent), model(model), buttonPress(false), scenarioName(scenarioName)
13 {
14 }
15 
17 {
18 }
19 
20 
22 {
23  if (active)
24  {
25  QObject::connect(this, SIGNAL(currentIndexChanged(QString)), this, SLOT(onIndexChange(QString)));
26  }
27  else
28  {
29  QObject::disconnect(this, SIGNAL(currentIndexChanged(QString)), this, SLOT(onIndexChange(QString)));
30  }
31 }
32 
33 void ComboBoxButton::paintEvent(QPaintEvent* e)
34 {
35  if (buttonPress)
36  {
37  QStylePainter painter(this);
38  QStyleOptionComboBox opt;
39  opt.rect = e->rect();
40  opt.currentIcon = itemIcon(currentIndex());
41  opt.currentText = currentText();
42  opt.iconSize = iconSize();
43  opt.state |= QStyle::State_Sunken;
44  painter.drawComplexControl(QStyle::CC_ComboBox, opt);
45  painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
46  }
47  else
48  {
49  QComboBox::paintEvent(e);
50  }
51 }
52 
53 
54 void ComboBoxButton::mousePressEvent(QMouseEvent* e)
55 {
56  if (e->x() < this->width() - 20)
57  {
58  buttonPress = true;
59  }
60  else
61  {
62  QComboBox::mousePressEvent(e);
63  }
64 }
65 
67 {
68  if (e->x() < this->width() - 20)
69  {
70  emit released(this->currentText(), model, scenarioName);
71  }
72  else
73  {
74  QComboBox::mouseReleaseEvent(e);
75  }
76  buttonPress = false;
77 }
78 
79 void ComboBoxButton::onIndexChange(const QString& text)
80 {
81  ScenarioManager::StatusManager statusManager;
82 
83  ScenarioItem* item = ScenarioModel::FindScenario(model, scenarioName);
84  ARMARX_CHECK_EXPRESSION(item) << scenarioName.toStdString();
85 
86  statusManager.setIceScenario(item->getScenario(), false);
87 }
88 
89 
ScenarioItem
TreeItem representing data contained in a Scenario or an Application.
Definition: scenarioitem.h:38
scenariomodel.h
ComboBoxButton::~ComboBoxButton
~ComboBoxButton()
Definition: comboboxbutton.cpp:16
ComboBoxButton::mousePressEvent
virtual void mousePressEvent(QMouseEvent *e)
Definition: comboboxbutton.cpp:54
scenarioitem.h
comboboxbutton.h
ComboBoxButton::paintEvent
virtual void paintEvent(QPaintEvent *e)
Definition: comboboxbutton.cpp:33
StatusManager.h
ComboBoxButton::released
void released(QString, const QAbstractItemModel *, QString)
ScenarioManager::StatusManager
Definition: StatusManager.h:7
ExpressionException.h
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
ScenarioModel::FindScenario
static ScenarioItem * FindScenario(const QAbstractItemModel *model, const QString &scenarioName)
Definition: scenariomodel.cpp:244
ComboBoxButton::setIceStatesActive
void setIceStatesActive(bool active)
Definition: comboboxbutton.cpp:21
ComboBoxButton::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *e)
Definition: comboboxbutton.cpp:66
Logging.h
ScenarioItem::getScenario
ScenarioManager::Data_Structure::ScenarioPtr getScenario()
If this item represents a Scenario, it is returned.
Definition: scenarioitem.cpp:185
ScenarioManager::StatusManager::setIceScenario
void setIceScenario(Data_Structure::ScenarioPtr scenario, bool state)
Definition: StatusManager.cpp:97
ComboBoxButton::ComboBoxButton
ComboBoxButton(const QAbstractItemModel *model, const QString &scenarioName, QWidget *parent=0)
Definition: comboboxbutton.cpp:11