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 <string>
26 #include <sstream>
27 #include <QPushButton>
28 #include <QToolBar>
29 
30 namespace armarx
31 {
32 #define FADE_TIMER_MSEC 100
33 #define FADE_DURATION 2000
34 
36  {
37  widget.setupUi(getWidget());
38  }
39 
40 
42  {
43 
44  }
45 
46 
48  {
49 
50  }
51 
53  {
54 
55  }
56 
57 
59  {
60  usingTopic("MessageDisplayTopic");
61 
62  // Don't display anything on startup
63  widget.labelCaption->setText("");
64  widget.labelSubcaption->setText("");
65 
66  connect(&fadeTimer, SIGNAL(timeout()), this, SLOT(timerEvent()));
67  connect(this, SIGNAL(setMessageContent(QString, QString)), this, SLOT(setMessageContentImpl(QString, QString)));
68  connect(this, SIGNAL(setCaptionContent(QString)), this, SLOT(setCaptionContentImpl(QString)));
69  connect(this, SIGNAL(setSubCaptionContent(QString)), this, SLOT(setSubCaptionContentImpl(QString)));
70  connect(widget.labelCaption, SIGNAL(doubleClicked()), this, SLOT(clearText()));
71  }
72 
73 
75  {
76 
77  }
78 
79  void MessageDisplayPluginWidgetController::setMessage(const std::string& caption, const std::string& subCaption, const Ice::Current&)
80  {
81  ARMARX_DEBUG << "New message: " << caption << " (" << subCaption << ")";
82  emit setMessageContent(QString::fromStdString(caption), QString::fromStdString(subCaption));
83  }
84 
85  void armarx::MessageDisplayPluginWidgetController::setCaption(const std::string& caption, const Ice::Current&)
86  {
87  ARMARX_DEBUG << "New caption: " << caption;
88  emit setCaptionContent(QString::fromStdString(caption));
89  }
90 
91  void armarx::MessageDisplayPluginWidgetController::setSubCaption(const std::string& subCaption, const Ice::Current&)
92  {
93  ARMARX_DEBUG << "New subCaption: " << subCaption;
94  emit setSubCaptionContent(QString::fromStdString(subCaption));
95  }
96 
97 
98 
100  {
101  fadeDuration -= FADE_TIMER_MSEC;
102  if (fadeDuration <= 0)
103  {
104  fadeTimer.stop();
105  }
106 
107  std::stringstream ss;
108  ss << "#" << std::hex << (int)(255 * (((float)fadeDuration) / FADE_DURATION)) << "0000";
109 
110  ARMARX_INFO << ("<font color='" + QString::fromStdString(ss.str()) + "'>" + currentCaption + "</font>").toStdString();
111  widget.labelCaption->setText("<font color='" + QString::fromStdString(ss.str()) + "'>" + currentCaption + "</font>");
112  widget.labelSubcaption->setText("<font color='" + QString::fromStdString(ss.str()) + "'>" + currentSubCaption + "</font>");
113  }
114 
115  void MessageDisplayPluginWidgetController::setMessageContentImpl(const QString& caption, const QString& subcaption)
116  {
117  currentCaption = caption;
118  currentSubCaption = subcaption;
119  updateLabels();
120  }
121 
123  {
124  currentCaption = caption;
125  updateLabels();
126  }
128  {
129  currentSubCaption = subcaption;
130  updateLabels();
131  }
132 
134  {
135  fadeTimer.stop();
136 
137  widget.labelCaption->setText("<font color='#FF0000'>" + currentCaption + "</font>");
138  widget.labelSubcaption->setText("<font color='#FF0000'>" + currentSubCaption + "</font>");
139 
140  fadeDuration = FADE_DURATION;
141  fadeTimer.start(FADE_TIMER_MSEC);
142  }
143 
145  {
146  widget.labelCaption->setText("");
147  widget.labelSubcaption->setText("");
148  }
149 
151  {
152  QToolBar* customToolbar = new QToolBar(parent);
153  customToolbar->addAction("clear", this, SLOT(clearText()));
154  return customToolbar;
155  }
156 }
armarx::MessageDisplayPluginWidgetController::onConnectComponent
void onConnectComponent() override
Definition: MessageDisplayPluginWidgetController.cpp:74
FADE_TIMER_MSEC
#define FADE_TIMER_MSEC
Definition: MessageDisplayPluginWidgetController.cpp:32
armarx::MessageDisplayPluginWidgetController::setSubCaption
void setSubCaption(const std::string &subCaption, const Ice::Current &) override
Definition: MessageDisplayPluginWidgetController.cpp:91
armarx::MessageDisplayPluginWidgetController::setCaption
void setCaption(const std::string &caption, const Ice::Current &) override
Definition: MessageDisplayPluginWidgetController.cpp:85
armarx::MessageDisplayPluginWidgetController::setMessageContent
void setMessageContent(const QString &caption, const QString &subcaption)
armarx::MessageDisplayPluginWidgetController::clearText
void clearText()
Definition: MessageDisplayPluginWidgetController.cpp:144
armarx::MessageDisplayPluginWidgetController::~MessageDisplayPluginWidgetController
virtual ~MessageDisplayPluginWidgetController()
Controller destructor.
Definition: MessageDisplayPluginWidgetController.cpp:41
armarx::MessageDisplayPluginWidgetController::saveSettings
void saveSettings(QSettings *settings) override
Definition: MessageDisplayPluginWidgetController.cpp:52
armarx::MessageDisplayPluginWidgetController::timerEvent
void timerEvent()
Definition: MessageDisplayPluginWidgetController.cpp:99
FADE_DURATION
#define FADE_DURATION
Definition: MessageDisplayPluginWidgetController.cpp:33
armarx::MessageDisplayPluginWidgetController::setMessage
void setMessage(const std::string &caption, const std::string &subCaption, const Ice::Current &) override
Definition: MessageDisplayPluginWidgetController.cpp:79
MessageDisplayPluginWidgetController.h
armarx::MessageDisplayPluginWidgetController::getCustomTitlebarWidget
QPointer< QWidget > getCustomTitlebarWidget(QWidget *parent) override
getTitleToolbar returns a pointer to the a toolbar widget of this controller.
Definition: MessageDisplayPluginWidgetController.cpp:150
armarx::MessageDisplayPluginWidgetController::loadSettings
void loadSettings(QSettings *settings) override
Definition: MessageDisplayPluginWidgetController.cpp:47
armarx::MessageDisplayPluginWidgetController::setSubCaptionContent
void setSubCaptionContent(const QString &subcaption)
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::MessageDisplayPluginWidgetController::onInitComponent
void onInitComponent() override
Definition: MessageDisplayPluginWidgetController.cpp:58
armarx::MessageDisplayPluginWidgetController::updateLabels
void updateLabels()
Definition: MessageDisplayPluginWidgetController.cpp:133
armarx::MessageDisplayPluginWidgetController::setCaptionContent
void setCaptionContent(const QString &caption)
armarx::MessageDisplayPluginWidgetController::MessageDisplayPluginWidgetController
MessageDisplayPluginWidgetController()
Controller Constructor.
Definition: MessageDisplayPluginWidgetController.cpp:35
armarx::MessageDisplayPluginWidgetController::setMessageContentImpl
void setMessageContentImpl(const QString &caption, const QString &subcaption)
Definition: MessageDisplayPluginWidgetController.cpp:115
armarx::MessageDisplayPluginWidgetController::setSubCaptionContentImpl
void setSubCaptionContentImpl(const QString &subcaption)
Definition: MessageDisplayPluginWidgetController.cpp:127
armarx::ManagedIceObject::usingTopic
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
Definition: ManagedIceObject.cpp:248
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::ArmarXWidgetController::getWidget
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
Definition: ArmarXWidgetController.cpp:54
armarx::MessageDisplayPluginWidgetController::setCaptionContentImpl
void setCaptionContentImpl(const QString &caption)
Definition: MessageDisplayPluginWidgetController.cpp:122
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28