mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
Move leds to custom led class
This commit is contained in:
@@ -45,6 +45,8 @@ set(PROJECT_SOURCES
|
||||
IterableEnum.hpp
|
||||
better_radiobutton.h
|
||||
better_radiobutton.cpp
|
||||
led.h
|
||||
led.cpp
|
||||
|
||||
networkerror.h
|
||||
networkerror.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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
+33
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
@@ -408,7 +408,7 @@ void SimulatorBase::process_ui_led(json& uiItem)
|
||||
return;
|
||||
}
|
||||
|
||||
auto led = qobject_cast<QPushButton*>(widget);
|
||||
auto led = qobject_cast<Led*>(widget);
|
||||
if (led == nullptr)
|
||||
{
|
||||
QD << "widget is not of type led";
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "web_socket_wrapper.h"
|
||||
#include "networkerror.h"
|
||||
#include "helpers.h"
|
||||
#include "led.h"
|
||||
#include <magic_enum.hpp>
|
||||
#include "IterableEnum.hpp"
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QPushButton" name="led">
|
||||
<widget class="Led" name="led">
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
@@ -124,6 +124,11 @@
|
||||
<extends>QWidget</extends>
|
||||
<header>qwt_thermo.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Led</class>
|
||||
<extends>QPushButton</extends>
|
||||
<header>led.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
Reference in New Issue
Block a user