diff --git a/Qt/CMakeLists.txt b/Qt/CMakeLists.txt index 61afe1a..4c89917 100644 --- a/Qt/CMakeLists.txt +++ b/Qt/CMakeLists.txt @@ -45,6 +45,8 @@ set(PROJECT_SOURCES IterableEnum.hpp better_radiobutton.h better_radiobutton.cpp + led.h + led.cpp networkerror.h networkerror.cpp diff --git a/Qt/helpers.cpp b/Qt/helpers.cpp index ca19444..0aacc6b 100644 --- a/Qt/helpers.cpp +++ b/Qt/helpers.cpp @@ -65,17 +65,6 @@ void reset_widget_color(QWidget* widget) widget->setStyleSheet(""); } -bool is_read_only(QWidget* widget) -{ - return widget->testAttribute(Qt::WA_TransparentForMouseEvents) || (widget->focusPolicy() == Qt::NoFocus); -} - -void set_read_only(QWidget* widget, bool read_only) -{ - widget->setAttribute(Qt::WA_TransparentForMouseEvents, read_only); - widget->setFocusPolicy(read_only ? Qt::NoFocus : Qt::StrongFocus); -} - QString network_reply_to_fix(QNetworkReply::NetworkError error) { switch (error) { diff --git a/Qt/helpers.h b/Qt/helpers.h index ea958a7..230ff5a 100644 --- a/Qt/helpers.h +++ b/Qt/helpers.h @@ -19,8 +19,6 @@ void set_widget_color(QWidget* widget, QString color, QString bg); QColor widget_bg_color(QWidget* widget); QColor widget_color(QWidget* widget); void reset_widget_color(QWidget* widget); -void set_read_only(QWidget* widget, bool readOnly = true); -bool is_read_only(QWidget* widget); QString network_reply_to_fix(QNetworkReply::NetworkError error); #endif // HELPERS_H diff --git a/Qt/led.cpp b/Qt/led.cpp new file mode 100644 index 0000000..e83a882 --- /dev/null +++ b/Qt/led.cpp @@ -0,0 +1,33 @@ +#include "led.h" + +Led::Led(QWidget* parrent) + : QPushButton(parrent) +{ + set_read_only(this, true); +} + +Led::Led(const QString &text, QWidget *parent) +{ + set_read_only(this, true); +} + +Led::Led(const QIcon& icon, const QString &text, QWidget *parent) +{ + set_read_only(this, true); +} + +Led::~Led() +{ + +} + +bool Led::is_read_only(QWidget* widget) +{ + return widget->testAttribute(Qt::WA_TransparentForMouseEvents) || (widget->focusPolicy() == Qt::NoFocus); +} + +void Led::set_read_only(QWidget* widget, bool read_only) +{ + widget->setAttribute(Qt::WA_TransparentForMouseEvents, read_only); + widget->setFocusPolicy(read_only ? Qt::NoFocus : Qt::StrongFocus); +} diff --git a/Qt/led.h b/Qt/led.h new file mode 100644 index 0000000..adf970e --- /dev/null +++ b/Qt/led.h @@ -0,0 +1,18 @@ +#ifndef LED_H +#define LED_H + +#include "QPushButton" + +class Led : public QPushButton { + Q_OBJECT + public: + explicit Led(QWidget *parent = nullptr); + explicit Led(const QString &text, QWidget *parent = nullptr); + Led(const QIcon& icon, const QString &text, QWidget *parent = nullptr); + ~Led(); + private: + bool is_read_only(QWidget* widget); + void set_read_only(QWidget* widget, bool read_only); +}; + +#endif // LED_H diff --git a/Qt/simulatorbase.cpp b/Qt/simulatorbase.cpp index 9c7e49e..c3fccbc 100644 --- a/Qt/simulatorbase.cpp +++ b/Qt/simulatorbase.cpp @@ -408,7 +408,7 @@ void SimulatorBase::process_ui_led(json& uiItem) return; } - auto led = qobject_cast(widget); + auto led = qobject_cast(widget); if (led == nullptr) { QD << "widget is not of type led"; diff --git a/Qt/simulatorbase.h b/Qt/simulatorbase.h index 6590cd8..7fa208d 100644 --- a/Qt/simulatorbase.h +++ b/Qt/simulatorbase.h @@ -6,6 +6,7 @@ #include "web_socket_wrapper.h" #include "networkerror.h" #include "helpers.h" +#include "led.h" #include #include "IterableEnum.hpp" diff --git a/Qt/simulators/sim-test.ui b/Qt/simulators/sim-test.ui index f9afe0e..e309743 100644 --- a/Qt/simulators/sim-test.ui +++ b/Qt/simulators/sim-test.ui @@ -23,7 +23,7 @@ - + PushButton @@ -124,6 +124,11 @@ QWidget
qwt_thermo.h
+ + Led + QPushButton +
led.h
+