CurveColorConfigWidget.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2015 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
19 #include <QColorDialog>
20 
21 #include <ui_CurveColorConfigWidget.h>
22 
24 
25 namespace rqt_multiplot {
26 
27 /*****************************************************************************/
28 /* Constructors and Destructor */
29 /*****************************************************************************/
30 
32  QWidget(parent),
33  ui_(new Ui::CurveColorConfigWidget()),
34  config_(0) {
35  ui_->setupUi(this);
36 
37  ui_->labelColor->setAutoFillBackground(true);
38 
39  connect(ui_->checkBoxAuto, SIGNAL(stateChanged(int)), this,
40  SLOT(checkBoxAutoStateChanged(int)));
41 
42  ui_->labelColor->installEventFilter(this);
43 }
44 
46  delete ui_;
47 }
48 
49 /*****************************************************************************/
50 /* Accessors */
51 /*****************************************************************************/
52 
54  if (config_ != config) {
55  if (config_) {
56  disconnect(config_, SIGNAL(typeChanged(int)), this,
57  SLOT(colorTypeChanged(int)));
58  disconnect(config_, SIGNAL(currentColorChanged(const QColor&)), this,
59  SLOT(colorCurrentColorChanged(const QColor&)));
60  }
61 
62  config_ = config;
63 
64  if (config) {
65  connect(config, SIGNAL(typeChanged(int)), this,
66  SLOT(configTypeChanged(int)));
67  connect(config, SIGNAL(currentColorChanged(const QColor&)), this,
68  SLOT(configCurrentColorChanged(const QColor&)));
69 
70  configTypeChanged(config->getType());
72  }
73  }
74 }
75 
76 /*****************************************************************************/
77 /* Methods */
78 /*****************************************************************************/
79 
80 bool CurveColorConfigWidget::eventFilter(QObject* object, QEvent* event) {
81  if ((object == ui_->labelColor) && (ui_->labelColor->isEnabled()) &&
82  config_ && (event->type() == QEvent::MouseButtonPress)) {
83  QColorDialog dialog(this);
84 
85  dialog.setCurrentColor(config_->getCustomColor());
86 
87  if (dialog.exec() == QDialog::Accepted)
88  config_->setCustomColor(dialog.currentColor());
89  }
90 
91  return false;
92 }
93 
94 /*****************************************************************************/
95 /* Slots */
96 /*****************************************************************************/
97 
99  ui_->checkBoxAuto->setCheckState((type == CurveColorConfig::Auto) ?
100  Qt::Checked : Qt::Unchecked);
101 }
102 
104  QPalette palette = ui_->labelColor->palette();
105  palette.setColor(QPalette::Window, color);
106  palette.setColor(QPalette::WindowText, (color.lightnessF() > 0.5) ?
107  Qt::black : Qt::white);
108 
109  ui_->labelColor->setPalette(palette);
110  ui_->labelColor->setText(color.name().toUpper());
111 }
112 
114  ui_->labelColor->setEnabled(state != Qt::Checked);
115 
116  if (config_)
117  config_->setType((state == Qt::Checked) ? CurveColorConfig::Auto :
119 }
120 
121 }
void currentColorChanged(const QColor &color)
const QColor & getCustomColor() const
void setConfig(CurveColorConfig *config)
bool eventFilter(QObject *object, QEvent *event)
void configCurrentColorChanged(const QColor &color)
void setCustomColor(const QColor &color)


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Wed Jul 10 2019 03:49:44