44 DEFAULT_SETTINGS_PLUGIN_NAME(
"OperatorViewWidgetGuiPlugin"),
45 DEFAULT_SETTINGS_CUSTOM_TEXT(
"custom text")
48 this->updateTimer =
new QTimer(
this);
49 this->updateTimer->start(50);
59 settings->value(
"demoStateProxyName", QString::fromStdString(demoStateProxyName))
68 settings->setValue(
"demoStateProxyName", QString::fromStdString(demoStateProxyName));
83 getProxy(demoStateManagerPrx, demoStateProxyName);
94 stopCheckStateTask.store(
false);
95 checkStateTask = std::thread([&] {
checkState(); });
106 QObject::disconnect(
this,
111 catch (Ice::Exception
const&)
122 while (not stopCheckStateTask.load())
127 auto stateAndSeverity = this->demoStateManagerPrx->getStateAndSeverity();
131 static_cast<int>(stateAndSeverity.severity));
133 catch (Ice::Exception
const&)
139 metronome.waitForNextTick();
146 std::string color = mapColor(
static_cast<armarx::severity::SeverityEnum
>(severity));
147 std::string coloredSeverity =
148 "<span style='color:" + color +
";'>" + state.toStdString() +
"</span>";
149 std::string finalText =
"Current State: " + coloredSeverity;
151 widget.currentState->setText(QString::fromStdString(finalText));
158 widget.groupSend->setLayout(
new QVBoxLayout(
getWidget()));
167 if (QVBoxLayout* hLayout = qobject_cast<QVBoxLayout*>(widget.groupSend->layout()))
169 hLayout->addLayout(this->layoutNormal);
170 hLayout->addLayout(this->layoutWarning);
171 hLayout->addLayout(this->layoutError);
172 hLayout->addLayout(this->layoutFatal);
179 std::string newStateSend = text.toStdString() ==
""
180 ? this->widget.newState->text().toStdString()
181 : text.toStdString();
182 int newSeveritySend = severity == -1 ? this->widget.severity->currentIndex() : severity;
186 this->demoStateManagerPrx->insertState(
187 newStateSend,
static_cast<armarx::severity::SeverityEnum
>(newSeveritySend));
189 catch (Ice::Exception
const&)
194 QString newState = text.toStdString() ==
"" ? this->widget.newState->text() : text;
195 int newSeverity = severity == -1 ? this->widget.severity->currentIndex() : severity;
197 armarx::severity::SeverityEnum buttonSeverity =
198 static_cast<armarx::severity::SeverityEnum
>(newSeverity);
200 QPushButton* button =
new QPushButton(newState,
getWidget());
201 button->setToolTip(
"Leftclick to send to presenter view; Rightclick to delete.");
204 QString color = QString::fromStdString(mapColor(buttonSeverity));
205 if (!color.isEmpty())
207 QPalette palette = button->palette();
208 palette.setColor(QPalette::Button, QColor(color));
209 button->setPalette(palette);
210 button->setStyleSheet(
"background-color: " + color +
";");
212 switch (buttonSeverity)
214 case armarx::severity::SeverityEnum::normal:
215 this->layoutNormal->addWidget(button);
217 case armarx::severity::SeverityEnum::warning:
218 this->layoutWarning->addWidget(button);
220 case armarx::severity::SeverityEnum::error:
221 this->layoutError->addWidget(button);
223 case armarx::severity::SeverityEnum::fatal:
224 this->layoutFatal->addWidget(button);
229 &QPushButton::clicked,
231 [
this, newState, buttonSeverity]()
233 button->setContextMenuPolicy(Qt::CustomContextMenu);
236 &QPushButton::customContextMenuRequested,
238 [
this, button, newStateSend, newSeveritySend](
const QPoint& pos)
241 QAction* deleteAction = menu.addAction(
"Delete");
243 QAction* selectedAction = menu.exec(button->mapToGlobal(pos));
244 if (selectedAction == deleteAction)
248 static_cast<armarx::severity::SeverityEnum
>(newSeveritySend));
256 std::string newState = text.toStdString() ==
""
257 ? this->widget.newState->text().toStdString()
258 : text.toStdString();
259 int newSeverity = severity == -1 ? this->widget.severity->currentIndex() : severity;
263 this->demoStateManagerPrx->setState(
264 newState,
static_cast<armarx::severity::SeverityEnum
>(newSeverity));
266 catch (Ice::Exception
const&)
273 OperatorViewWidgetController::createButtons()
275 std::vector<StateAndSeverity> allStates;
278 allStates = demoStateManagerPrx->getCurrentStates();
280 catch (Ice::Exception
const&)
285 for (
const StateAndSeverity& state : allStates)
287 QPushButton* button =
new QPushButton(QString::fromStdString(state.state),
getWidget());
289 QString color = QString::fromStdString(mapColor(state.severity));
290 if (!color.isEmpty())
292 QPalette palette = button->palette();
293 palette.setColor(QPalette::Button, QColor(color));
294 button->setPalette(palette);
295 button->setStyleSheet(
"background-color: " + color +
";");
297 switch (state.severity)
299 case armarx::severity::SeverityEnum::normal:
300 this->layoutNormal->addWidget(button);
302 case armarx::severity::SeverityEnum::warning:
303 this->layoutWarning->addWidget(button);
305 case armarx::severity::SeverityEnum::error:
306 this->layoutError->addWidget(button);
308 case armarx::severity::SeverityEnum::fatal:
309 this->layoutFatal->addWidget(button);
313 button->setToolTip(
"Leftclick to send to presenter view; Rightclick to delete.");
316 &QPushButton::clicked,
319 button->setContextMenuPolicy(Qt::CustomContextMenu);
322 &QPushButton::customContextMenuRequested,
324 [
this, button, state](
const QPoint& pos)
327 QAction* deleteAction = menu.addAction(
"Delete");
329 QAction* selectedAction = menu.exec(button->mapToGlobal(pos));
330 if (selectedAction == deleteAction)
332 this->deleteButton(state.state, state.severity);
339 OperatorViewWidgetController::deleteButton(std::string state,
340 armarx::severity::SeverityEnum severity)
345 this->demoStateManagerPrx->deleteState(state, severity);
347 catch (Ice::Exception
const&)
359 armarx::severity::SeverityEnum severity)
363 this->demoStateManagerPrx->setState(state, severity);
365 catch (Ice::Exception
const&)
374 std::string exportProperty =
"";
375 QList<QPushButton*> normalButtons = getButtonsFromLayout(this->layoutNormal);
376 QList<QPushButton*> warningButtons = getButtonsFromLayout(this->layoutWarning);
377 QList<QPushButton*> errorButtons = getButtonsFromLayout(this->layoutError);
378 QList<QPushButton*> fatalButtons = getButtonsFromLayout(this->layoutFatal);
379 std::vector<QList<QPushButton*>> buttons;
380 buttons.push_back(normalButtons);
381 buttons.push_back(warningButtons);
382 buttons.push_back(errorButtons);
383 buttons.push_back(fatalButtons);
385 for (
unsigned long i = 0; i < buttons.size(); i++)
387 auto buttonList = buttons[i];
389 for (
auto it = buttonList.begin(); it != buttonList.end(); ++it)
391 std::string buttonText = (*it)->text().toStdString();
392 exportProperty.append(buttonText +
":" + std::to_string(i) +
";");
395 QClipboard* clipboard = QGuiApplication::clipboard();
396 clipboard->setText(QString::fromStdString(exportProperty));
397 ARMARX_INFO <<
"Button configuration: " << exportProperty;
401 OperatorViewWidgetController::getButtonsFromLayout(QLayout* layout)
403 QList<QPushButton*> buttons;
408 for (
int i = 0; i < layout->count(); ++i)
410 if (
auto* button = qobject_cast<QPushButton*>(layout->itemAt(i)->widget()))
412 buttons.append(button);
420 OperatorViewWidgetController::mapColor(severity::SeverityEnum severity)
425 case severity::SeverityEnum::normal:
428 case severity::SeverityEnum::warning:
431 case severity::SeverityEnum::error:
434 case severity::SeverityEnum::fatal:
453 clearLayout(this->layoutNormal);
454 clearLayout(this->layoutWarning);
455 clearLayout(this->layoutError);
456 clearLayout(this->layoutFatal);
458 delete this->layoutNormal;
459 delete this->layoutWarning;
460 delete this->layoutError;
461 delete this->layoutFatal;
463 this->layoutNormal =
nullptr;
464 this->layoutWarning =
nullptr;
465 this->layoutError =
nullptr;
466 this->layoutFatal =
nullptr;
468 stopCheckStateTask.store(
true);
469 checkStateTask.join();
476 OperatorViewWidgetController::clearLayout(QLayout* layout)
481 while (QLayoutItem* item = layout->takeAt(0))
483 if (QWidget* widget = item->widget())
485 widget->deleteLater();
487 else if (QLayout* subLayout = item->layout())
514 if (not m_config_dialog)
518 {
"DemoStateManager",
"Demo State Manager",
"*"});
520 return qobject_cast<QDialog*>(m_config_dialog);
530 demoStateProxyName = m_config_dialog->getProxyName(
"DemoStateManager");
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
A config-dialog containing one (or multiple) proxy finders.
void addProxyFinder(const std::vector< EntryData > &entryData)
static Frequency Hertz(std::int64_t hertz)
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
This file offers overloads of toIce() and fromIce() functions for STL container types.
const LogSender::manipulator flush