CurveItemWidget.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 <QPainter>
00020 #include <QPaintEvent>
00021 
00022 #include <ui_CurveItemWidget.h>
00023 
00024 #include "rqt_multiplot/CurveItemWidget.h"
00025 
00026 namespace rqt_multiplot {
00027 
00028 /*****************************************************************************/
00029 /* Constructors and Destructor                                               */
00030 /*****************************************************************************/
00031 
00032 CurveItemWidget::CurveItemWidget(QWidget* parent) :
00033   QWidget(parent),
00034   ui_(new Ui::CurveItemWidget()),
00035   config_(0) {
00036   ui_->setupUi(this);
00037 
00038   ui_->frameColor->installEventFilter(this);
00039 }
00040 
00041 CurveItemWidget::~CurveItemWidget() {
00042   delete ui_;
00043 }
00044 
00045 /*****************************************************************************/
00046 /* Accessors                                                                 */
00047 /*****************************************************************************/
00048 
00049 void CurveItemWidget::setConfig(CurveConfig* config) {
00050   if (config != config_) {
00051     if (config_) {
00052       disconnect(config_, SIGNAL(titleChanged(const QString&)), this,
00053         SLOT(configTitleChanged(const QString&)));
00054       disconnect(config_->getAxisConfig(CurveConfig::X),
00055         SIGNAL(changed()), this, SLOT(configXAxisConfigChanged()));
00056       disconnect(config_->getAxisConfig(CurveConfig::Y),
00057         SIGNAL(changed()), this, SLOT(configYAxisConfigChanged()));
00058       disconnect(config_->getColorConfig(), SIGNAL(currentColorChanged(const
00059         QColor&)), this, SLOT(configColorConfigCurrentColorChanged(const
00060         QColor&)));
00061     }
00062     
00063     config_ = config;
00064     
00065     if (config) {
00066       connect(config, SIGNAL(titleChanged(const QString&)), this,
00067         SLOT(configTitleChanged(const QString&)));
00068       connect(config->getAxisConfig(CurveConfig::X),
00069         SIGNAL(changed()), this, SLOT(configXAxisConfigChanged()));
00070       connect(config->getAxisConfig(CurveConfig::Y),
00071         SIGNAL(changed()), this, SLOT(configYAxisConfigChanged()));
00072       connect(config->getColorConfig(), SIGNAL(currentColorChanged(const
00073         QColor&)), this, SLOT(configColorConfigCurrentColorChanged(const
00074         QColor&)));
00075       
00076       configTitleChanged(config->getTitle());
00077       configXAxisConfigChanged();
00078       configYAxisConfigChanged();
00079       configColorConfigCurrentColorChanged(config->getColorConfig()->
00080         getCurrentColor());
00081     }
00082   }
00083 }
00084 
00085 CurveConfig* CurveItemWidget::getConfig() const {
00086   return config_;
00087 }
00088 
00089 /*****************************************************************************/
00090 /* Methods                                                                   */
00091 /*****************************************************************************/
00092 
00093 bool CurveItemWidget::eventFilter(QObject* object, QEvent* event) {
00094   if (config_) {
00095     if ((object == ui_->frameColor) && (event->type() == QEvent::Paint)) {
00096       QPaintEvent* paintEvent = static_cast<QPaintEvent*>(event);
00097       
00098       QPainter painter(ui_->frameColor);
00099       QColor color = config_->getColorConfig()->getCurrentColor();
00100       
00101       painter.setBrush(color);
00102       painter.setPen((color.lightnessF() > 0.5) ? Qt::black : Qt::white);
00103       
00104       painter.fillRect(paintEvent->rect(), color);
00105       painter.drawText(paintEvent->rect(), color.name().toUpper(),
00106         Qt::AlignHCenter | Qt::AlignVCenter);
00107     }
00108   }
00109   
00110   return false;
00111 }
00112 
00113 /*****************************************************************************/
00114 /* Slots                                                                     */
00115 /*****************************************************************************/
00116 
00117 void CurveItemWidget::configTitleChanged(const QString& title) {
00118   ui_->labelTitle->setText(config_->getTitle());  
00119 }
00120 
00121 void CurveItemWidget::configXAxisConfigChanged() {
00122   CurveAxisConfig* config = config_->getAxisConfig(CurveConfig::X);
00123   
00124   QString text = config->getTopic();
00125   
00126   if (config->getFieldType() == CurveAxisConfig::MessageData)
00127     text += "/"+config->getField();
00128   else
00129     text += "/receipt_time";
00130 
00131   ui_->labelXAxis->setText(text);
00132 }
00133 
00134 void CurveItemWidget::configYAxisConfigChanged() {
00135   CurveAxisConfig* config = config_->getAxisConfig(CurveConfig::Y);
00136   
00137   QString text = config->getTopic();
00138   
00139   if (config->getFieldType() == CurveAxisConfig::MessageData)
00140     text += "/"+config->getField();
00141   else
00142     text += "/receipt_time";
00143 
00144   ui_->labelYAxis->setText(text);
00145 }
00146 
00147 void CurveItemWidget::configColorConfigCurrentColorChanged(const QColor&
00148     color) {
00149   ui_->frameColor->repaint();
00150 }
00151 
00152 }


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