MessageDisplayPluginWidgetController.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * \package ArmarXGui::gui-plugins::MessageDisplayPluginWidgetController
17 * \author Peter Kaiser ( peter dot kaiser at kit dot edu )
18 * \date 2018
19 * \copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
25#include <sstream>
26#include <string>
27
28#include <QPushButton>
29#include <QToolBar>
30
31namespace armarx
32{
33#define FADE_TIMER_MSEC 100
34#define FADE_DURATION 2000
35
40
44
45 void
49
50 void
54
55 void
57 {
58 usingTopic("MessageDisplayTopic");
59
60 // Don't display anything on startup
61 widget.labelCaption->setText("");
62 widget.labelSubcaption->setText("");
63
64 connect(&fadeTimer, SIGNAL(timeout()), this, SLOT(timerEvent()));
65 connect(this,
66 SIGNAL(setMessageContent(QString, QString)),
67 this,
68 SLOT(setMessageContentImpl(QString, QString)));
69 connect(
70 this, SIGNAL(setCaptionContent(QString)), this, SLOT(setCaptionContentImpl(QString)));
71 connect(this,
72 SIGNAL(setSubCaptionContent(QString)),
73 this,
74 SLOT(setSubCaptionContentImpl(QString)));
75 connect(widget.labelCaption, SIGNAL(doubleClicked()), this, SLOT(clearText()));
76 }
77
78 void
82
83 void
85 const std::string& subCaption,
86 const Ice::Current&)
87 {
88 ARMARX_DEBUG << "New message: " << caption << " (" << subCaption << ")";
89 emit setMessageContent(QString::fromStdString(caption), QString::fromStdString(subCaption));
90 }
91
92 void
94 const Ice::Current&)
95 {
96 ARMARX_DEBUG << "New caption: " << caption;
97 emit setCaptionContent(QString::fromStdString(caption));
98 }
99
100 void
102 const Ice::Current&)
103 {
104 ARMARX_DEBUG << "New subCaption: " << subCaption;
105 emit setSubCaptionContent(QString::fromStdString(subCaption));
106 }
107
108 void
110 {
111 fadeDuration -= FADE_TIMER_MSEC;
112 if (fadeDuration <= 0)
113 {
114 fadeTimer.stop();
115 }
116
117 std::stringstream ss;
118 ss << "#" << std::hex << (int)(255 * (((float)fadeDuration) / FADE_DURATION)) << "0000";
119
120 ARMARX_INFO << ("<font color='" + QString::fromStdString(ss.str()) + "'>" + currentCaption +
121 "</font>")
122 .toStdString();
123 widget.labelCaption->setText("<font color='" + QString::fromStdString(ss.str()) + "'>" +
124 currentCaption + "</font>");
125 widget.labelSubcaption->setText("<font color='" + QString::fromStdString(ss.str()) + "'>" +
126 currentSubCaption + "</font>");
127 }
128
129 void
131 const QString& subcaption)
132 {
133 currentCaption = caption;
134 currentSubCaption = subcaption;
135 updateLabels();
136 }
137
138 void
140 {
141 currentCaption = caption;
142 updateLabels();
143 }
144
145 void
147 {
148 currentSubCaption = subcaption;
149 updateLabels();
150 }
151
152 void
154 {
155 fadeTimer.stop();
156
157 widget.labelCaption->setText("<font color='#FF0000'>" + currentCaption + "</font>");
158 widget.labelSubcaption->setText("<font color='#FF0000'>" + currentSubCaption + "</font>");
159
160 fadeDuration = FADE_DURATION;
161 fadeTimer.start(FADE_TIMER_MSEC);
162 }
163
164 void
166 {
167 widget.labelCaption->setText("");
168 widget.labelSubcaption->setText("");
169 }
170
171 QPointer<QWidget>
173 {
174 QToolBar* customToolbar = new QToolBar(parent);
175 customToolbar->addAction("clear", this, SLOT(clearText()));
176 return customToolbar;
177 }
178} // namespace armarx
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
void setSubCaptionContent(const QString &subcaption)
QPointer< QWidget > getCustomTitlebarWidget(QWidget *parent) override
getTitleToolbar returns a pointer to the a toolbar widget of this controller.
void setCaptionContent(const QString &caption)
void setMessage(const std::string &caption, const std::string &subCaption, const Ice::Current &) override
void setMessageContentImpl(const QString &caption, const QString &subcaption)
void setCaption(const std::string &caption, const Ice::Current &) override
void setMessageContent(const QString &caption, const QString &subcaption)
void setSubCaption(const std::string &subCaption, const Ice::Current &) override
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
This file offers overloads of toIce() and fromIce() functions for STL container types.