CurveItemWidget.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 <QPainter>
20 #include <QPaintEvent>
21 
22 #include <ui_CurveItemWidget.h>
23 
25 
26 namespace rqt_multiplot {
27 
28 /*****************************************************************************/
29 /* Constructors and Destructor */
30 /*****************************************************************************/
31 
33  QWidget(parent),
34  ui_(new Ui::CurveItemWidget()),
35  config_(0) {
36  ui_->setupUi(this);
37 
38  ui_->frameColor->installEventFilter(this);
39 }
40 
42  delete ui_;
43 }
44 
45 /*****************************************************************************/
46 /* Accessors */
47 /*****************************************************************************/
48 
50  if (config != config_) {
51  if (config_) {
52  disconnect(config_, SIGNAL(titleChanged(const QString&)), this,
53  SLOT(configTitleChanged(const QString&)));
55  SIGNAL(changed()), this, SLOT(configXAxisConfigChanged()));
57  SIGNAL(changed()), this, SLOT(configYAxisConfigChanged()));
58  disconnect(config_->getColorConfig(), SIGNAL(currentColorChanged(const
59  QColor&)), this, SLOT(configColorConfigCurrentColorChanged(const
60  QColor&)));
61  }
62 
63  config_ = config;
64 
65  if (config) {
66  connect(config, SIGNAL(titleChanged(const QString&)), this,
67  SLOT(configTitleChanged(const QString&)));
68  connect(config->getAxisConfig(CurveConfig::X),
69  SIGNAL(changed()), this, SLOT(configXAxisConfigChanged()));
70  connect(config->getAxisConfig(CurveConfig::Y),
71  SIGNAL(changed()), this, SLOT(configYAxisConfigChanged()));
72  connect(config->getColorConfig(), SIGNAL(currentColorChanged(const
73  QColor&)), this, SLOT(configColorConfigCurrentColorChanged(const
74  QColor&)));
75 
76  configTitleChanged(config->getTitle());
80  getCurrentColor());
81  }
82  }
83 }
84 
86  return config_;
87 }
88 
89 /*****************************************************************************/
90 /* Methods */
91 /*****************************************************************************/
92 
93 bool CurveItemWidget::eventFilter(QObject* object, QEvent* event) {
94  if (config_) {
95  if ((object == ui_->frameColor) && (event->type() == QEvent::Paint)) {
96  QPaintEvent* paintEvent = static_cast<QPaintEvent*>(event);
97 
98  QPainter painter(ui_->frameColor);
99  QColor color = config_->getColorConfig()->getCurrentColor();
100 
101  painter.setBrush(color);
102  painter.setPen((color.lightnessF() > 0.5) ? Qt::black : Qt::white);
103 
104  painter.fillRect(paintEvent->rect(), color);
105  painter.drawText(paintEvent->rect(), color.name().toUpper(),
106  Qt::AlignHCenter | Qt::AlignVCenter);
107  }
108  }
109 
110  return false;
111 }
112 
113 /*****************************************************************************/
114 /* Slots */
115 /*****************************************************************************/
116 
117 void CurveItemWidget::configTitleChanged(const QString& title) {
118  ui_->labelTitle->setText(config_->getTitle());
119 }
120 
123 
124  QString text = config->getTopic();
125 
127  text += "/"+config->getField();
128  else
129  text += "/receipt_time";
130 
131  ui_->labelXAxis->setText(text);
132 }
133 
136 
137  QString text = config->getTopic();
138 
140  text += "/"+config->getField();
141  else
142  text += "/receipt_time";
143 
144  ui_->labelYAxis->setText(text);
145 }
146 
148  color) {
149  ui_->frameColor->repaint();
150 }
151 
152 }
const QString & getTopic() const
void configColorConfigCurrentColorChanged(const QColor &color)
config
Ui::CurveItemWidget * ui_
CurveAxisConfig * getAxisConfig(Axis axis) const
Definition: CurveConfig.cpp:73
CurveItemWidget(QWidget *parent=0)
void configTitleChanged(const QString &title)
bool eventFilter(QObject *object, QEvent *event)
const QString & getField() const
void setConfig(CurveConfig *config)
const QString & getTitle() const
Definition: CurveConfig.cpp:69
CurveConfig * getConfig() const
CurveColorConfig * getColorConfig() const
Definition: CurveConfig.cpp:82


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