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
|
IterableEnum.hpp
|
||||||
better_radiobutton.h
|
better_radiobutton.h
|
||||||
better_radiobutton.cpp
|
better_radiobutton.cpp
|
||||||
|
led.h
|
||||||
|
led.cpp
|
||||||
|
|
||||||
networkerror.h
|
networkerror.h
|
||||||
networkerror.cpp
|
networkerror.cpp
|
||||||
|
|||||||
@@ -65,17 +65,6 @@ void reset_widget_color(QWidget* widget)
|
|||||||
widget->setStyleSheet("");
|
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)
|
QString network_reply_to_fix(QNetworkReply::NetworkError error)
|
||||||
{
|
{
|
||||||
switch (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_bg_color(QWidget* widget);
|
||||||
QColor widget_color(QWidget* widget);
|
QColor widget_color(QWidget* widget);
|
||||||
void reset_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);
|
QString network_reply_to_fix(QNetworkReply::NetworkError error);
|
||||||
|
|
||||||
#endif // HELPERS_H
|
#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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto led = qobject_cast<QPushButton*>(widget);
|
auto led = qobject_cast<Led*>(widget);
|
||||||
if (led == nullptr)
|
if (led == nullptr)
|
||||||
{
|
{
|
||||||
QD << "widget is not of type led";
|
QD << "widget is not of type led";
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "web_socket_wrapper.h"
|
#include "web_socket_wrapper.h"
|
||||||
#include "networkerror.h"
|
#include "networkerror.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
#include "led.h"
|
||||||
#include <magic_enum.hpp>
|
#include <magic_enum.hpp>
|
||||||
#include "IterableEnum.hpp"
|
#include "IterableEnum.hpp"
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="3">
|
<item row="1" column="3">
|
||||||
<widget class="QPushButton" name="led">
|
<widget class="Led" name="led">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>PushButton</string>
|
<string>PushButton</string>
|
||||||
</property>
|
</property>
|
||||||
@@ -124,6 +124,11 @@
|
|||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header>qwt_thermo.h</header>
|
<header>qwt_thermo.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>Led</class>
|
||||||
|
<extends>QPushButton</extends>
|
||||||
|
<header>led.h</header>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|||||||
Reference in New Issue
Block a user