CurveColorConfigWidget.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (C) 2015 by Ralf Kaestner                                        *
00003  * ralf.kaestner@gmail.com                                                    *
00004  *                                                                            *
00005  * This program is free software; you can redistribute it and/or modify       *
00006  * it under the terms of the Lesser GNU General Public License as published by*
00007  * the Free Software Foundation; either version 3 of the License, or          *
00008  * (at your option) any later version.                                        *
00009  *                                                                            *
00010  * This program is distributed in the hope that it will be useful,            *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               *
00013  * Lesser GNU General Public License for more details.                        *
00014  *                                                                            *
00015  * You should have received a copy of the Lesser GNU General Public License   *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.       *
00017  ******************************************************************************/
00018 
00019 #include <QColorDialog>
00020 
00021 #include <ui_CurveColorConfigWidget.h>
00022 
00023 #include "rqt_multiplot/CurveColorConfigWidget.h"
00024 
00025 namespace rqt_multiplot {
00026 
00027 /*****************************************************************************/
00028 /* Constructors and Destructor                                               */
00029 /*****************************************************************************/
00030 
00031 CurveColorConfigWidget::CurveColorConfigWidget(QWidget* parent) :
00032   QWidget(parent),
00033   ui_(new Ui::CurveColorConfigWidget()),
00034   config_(0) {
00035   ui_->setupUi(this);
00036     
00037   ui_->labelColor->setAutoFillBackground(true);
00038   
00039   connect(ui_->checkBoxAuto, SIGNAL(stateChanged(int)), this,
00040     SLOT(checkBoxAutoStateChanged(int)));
00041   
00042   ui_->labelColor->installEventFilter(this);
00043 }
00044 
00045 CurveColorConfigWidget::~CurveColorConfigWidget() {
00046   delete ui_;
00047 }
00048 
00049 /*****************************************************************************/
00050 /* Accessors                                                                 */
00051 /*****************************************************************************/
00052 
00053 void CurveColorConfigWidget::setConfig(CurveColorConfig* config) {
00054   if (config_ != config) {
00055     if (config_) {
00056       disconnect(config_, SIGNAL(typeChanged(int)), this,
00057         SLOT(colorTypeChanged(int)));
00058       disconnect(config_, SIGNAL(currentColorChanged(const QColor&)), this,
00059         SLOT(colorCurrentColorChanged(const QColor&)));
00060     }
00061     
00062     config_ = config;
00063     
00064     if (config) {
00065       connect(config, SIGNAL(typeChanged(int)), this,
00066         SLOT(configTypeChanged(int)));
00067       connect(config, SIGNAL(currentColorChanged(const QColor&)), this,
00068         SLOT(configCurrentColorChanged(const QColor&)));
00069       
00070       configTypeChanged(config->getType());
00071       configCurrentColorChanged(config->getCurrentColor());
00072     }
00073   }
00074 }
00075 
00076 /*****************************************************************************/
00077 /* Methods                                                                   */
00078 /*****************************************************************************/
00079 
00080 bool CurveColorConfigWidget::eventFilter(QObject* object, QEvent* event) {
00081   if ((object == ui_->labelColor) && (ui_->labelColor->isEnabled()) &&
00082       config_ && (event->type() == QEvent::MouseButtonPress)) {
00083     QColorDialog dialog(this);
00084   
00085     dialog.setCurrentColor(config_->getCustomColor());
00086   
00087     if (dialog.exec() == QDialog::Accepted)
00088       config_->setCustomColor(dialog.currentColor());
00089   }
00090   
00091   return false;
00092 }
00093 
00094 /*****************************************************************************/
00095 /* Slots                                                                     */
00096 /*****************************************************************************/
00097 
00098 void CurveColorConfigWidget::configTypeChanged(int type) {
00099   ui_->checkBoxAuto->setCheckState((type == CurveColorConfig::Auto) ?
00100     Qt::Checked : Qt::Unchecked);
00101 }
00102 
00103 void CurveColorConfigWidget::configCurrentColorChanged(const QColor& color) {
00104   QPalette palette = ui_->labelColor->palette();
00105   palette.setColor(QPalette::Window, color);
00106   palette.setColor(QPalette::WindowText, (color.lightnessF() > 0.5) ?
00107     Qt::black : Qt::white);
00108   
00109   ui_->labelColor->setPalette(palette);
00110   ui_->labelColor->setText(color.name().toUpper());
00111 }
00112 
00113 void CurveColorConfigWidget::checkBoxAutoStateChanged(int state) {
00114   ui_->labelColor->setEnabled(state != Qt::Checked);
00115   
00116   if (config_)
00117     config_->setType((state == Qt::Checked) ? CurveColorConfig::Auto :
00118       CurveColorConfig::Custom);
00119 }
00120 
00121 }


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Thu Jun 6 2019 21:49:10