diff --git a/source/RobotAPI/libraries/skills_gui/CMakeLists.txt b/source/RobotAPI/libraries/skills_gui/CMakeLists.txt index da9c1899308efa4cbff8992c8fd6c7f51cf28aaf..fc814c041b943c66c9486f45d074f5fed4ff764e 100644 --- a/source/RobotAPI/libraries/skills_gui/CMakeLists.txt +++ b/source/RobotAPI/libraries/skills_gui/CMakeLists.txt @@ -64,7 +64,7 @@ set(SOURCES PeriodicUpdateWidget.cpp SkillMemoryGui.cpp gui_utils.cpp - ConnectionStatusLabel.cpp + StatusLabel.cpp ) set(HEADERS aron_tree_widget/visitors/AronTreeWidgetCreator.h @@ -107,7 +107,7 @@ set(HEADERS PeriodicUpdateWidget.h SkillMemoryGui.h gui_utils.h - ConnectionStatusLabel.h + StatusLabel.h ) armarx_gui_library("${LIB_NAME}" "${SOURCES}" "${GUI_MOC_HDRS}" "${GUI_UIS}" "" "${LIBRARIES}") diff --git a/source/RobotAPI/libraries/skills_gui/ConnectionStatusLabel.cpp b/source/RobotAPI/libraries/skills_gui/ConnectionStatusLabel.cpp deleted file mode 100644 index 7cdf488c56fb9446de3fb53f68e580ac1f19792e..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/skills_gui/ConnectionStatusLabel.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "ConnectionStatusLabel.h" - -namespace armarx::skills::gui -{ - ConnectionStatusLabel::ConnectionStatusLabel(int ms) - { - timer = new QTimer(); - setStyleSheet("color: red"); - ms_delay = ms; - } - - void - ConnectionStatusLabel::handleMessage(std::string const& message) - { - // reset the timer if it is running - if (timer->isActive()) - { - timer->stop(); - } - - setText(QString::fromStdString(message)); - - timer->singleShot(2000, this, &ConnectionStatusLabel::resetLabel); - } - - void - ConnectionStatusLabel::resetLabel() - { - setText(QString::fromStdString("")); - } -} // namespace armarx::skills::gui diff --git a/source/RobotAPI/libraries/skills_gui/SkillMemoryGui.cpp b/source/RobotAPI/libraries/skills_gui/SkillMemoryGui.cpp index 257699aaaff68969e3cab9d0b2daed4323643360..d71d5c269fb9d51d3de50c3064aa2855989a01f3 100644 --- a/source/RobotAPI/libraries/skills_gui/SkillMemoryGui.cpp +++ b/source/RobotAPI/libraries/skills_gui/SkillMemoryGui.cpp @@ -14,7 +14,7 @@ namespace armarx::skills::gui QLayout* stopAllLayout, - QLabel* _connectionStatusLabel, + QWidget* _connectionStatusLabel, std::shared_ptr<SkillManagerWrapper> _memory) { @@ -62,7 +62,7 @@ namespace armarx::skills::gui stopAllButton = new QPushButton(QString::fromStdString(STOP_ALL_BUTTON_TEXT)); stopAllLayout->addWidget(stopAllButton); - this->connectionStatusLabel = new ConnectionStatusLabel(); + this->connectionStatusLabel = new StatusLabel(); armarx::gui::replaceWidget(_connectionStatusLabel, this->connectionStatusLabel, _connectionStatusLabel->parentWidget()->layout()); @@ -128,6 +128,6 @@ namespace armarx::skills::gui connect(memory.get(), &SkillManagerWrapper::connectionUpdate, connectionStatusLabel, - &ConnectionStatusLabel::handleMessage); + &StatusLabel::handleMessage); } } // namespace armarx::skills::gui diff --git a/source/RobotAPI/libraries/skills_gui/SkillMemoryGui.h b/source/RobotAPI/libraries/skills_gui/SkillMemoryGui.h index 30ac10f786659596f7db206e6c847e43e806be96..e8962eb867180240b691a49df3c1262ac3fd109f 100644 --- a/source/RobotAPI/libraries/skills_gui/SkillMemoryGui.h +++ b/source/RobotAPI/libraries/skills_gui/SkillMemoryGui.h @@ -9,7 +9,7 @@ #include <ArmarXCore/core/logging/Logging.h> -#include "RobotAPI/libraries/skills_gui/ConnectionStatusLabel.h" +#include "RobotAPI/libraries/skills_gui/StatusLabel.h" #include "./PeriodicUpdateWidget.h" #include "./aron_tree_widget/widgets/SkillDescriptionWidget.h" @@ -36,7 +36,7 @@ namespace armarx::skills::gui QLayout* stopAllLayout, - QLabel* connectionStatusLabel, + QWidget* connectionStatusLabel, std::shared_ptr<SkillManagerWrapper> _memory); @@ -72,7 +72,7 @@ namespace armarx::skills::gui QPushButton* stopAllButton = nullptr; - ConnectionStatusLabel* connectionStatusLabel = nullptr; + StatusLabel* connectionStatusLabel = nullptr; }; } // namespace armarx::skills::gui diff --git a/source/RobotAPI/libraries/skills_gui/StatusLabel.cpp b/source/RobotAPI/libraries/skills_gui/StatusLabel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6affe9671a0b8d85c234503263c500ba3a492d46 --- /dev/null +++ b/source/RobotAPI/libraries/skills_gui/StatusLabel.cpp @@ -0,0 +1,39 @@ +#include "StatusLabel.h" + +#include <QHBoxLayout> + +namespace armarx::skills::gui +{ + + StatusLabel::StatusLabel() + { + this->label = new QLabel(""); + this->resetButton = new QPushButton("Reset"); + this->setupUi(); + } + + void + StatusLabel::handleMessage(const std::string& message) + { + this->label->setText(QString::fromStdString(message)); + } + + void + StatusLabel::resetLabel() + { + this->label->setText(QString::fromStdString("")); + } + + void + StatusLabel::setupUi() + { + QHBoxLayout* layout = new QHBoxLayout(); + layout->addWidget(label); + layout->addWidget(resetButton); + this->setLayout(layout); + layout->setStretch(0, 2); + + connect(this->resetButton, &QPushButton::clicked, this, &StatusLabel::resetLabel); + } + +} // namespace armarx::skills::gui diff --git a/source/RobotAPI/libraries/skills_gui/ConnectionStatusLabel.h b/source/RobotAPI/libraries/skills_gui/StatusLabel.h similarity index 51% rename from source/RobotAPI/libraries/skills_gui/ConnectionStatusLabel.h rename to source/RobotAPI/libraries/skills_gui/StatusLabel.h index 36881fad928f121a1e5f7d6e339c082d88613f26..f3693ab0fb7c1e116fb6a010841454e3a7bae3e5 100644 --- a/source/RobotAPI/libraries/skills_gui/ConnectionStatusLabel.h +++ b/source/RobotAPI/libraries/skills_gui/StatusLabel.h @@ -1,22 +1,21 @@ #pragma once #include <QLabel> -#include <QTimer> +#include <QPushButton> namespace armarx::skills::gui { - class ConnectionStatusLabel : public QLabel + class StatusLabel : public QWidget { public: /** - * @brief Constructor for ConnectionStatusLabel - * @param ms The time in [ms], for which the message appears. + * @brief Constructor for StatusLabel */ - ConnectionStatusLabel(int ms = 3000); + StatusLabel(); public slots: /** - * @brief Display a message to indicate a connection drop. + * @brief Display a message to indicate an update. */ void handleMessage(std::string const& message); @@ -27,7 +26,10 @@ namespace armarx::skills::gui void resetLabel(); private: - QTimer* timer = nullptr; - int ms_delay; + void setupUi(); + + // contents + QLabel* label = nullptr; + QPushButton* resetButton = nullptr; }; } // namespace armarx::skills::gui