mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
UI
add statusbar
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "ui_slider.hpp"
|
||||
#include "ui_spinbox.hpp"
|
||||
#include "ui_stacked_widget.hpp"
|
||||
#include "ui_status_bar.hpp"
|
||||
#include "ui_tab_widget.hpp"
|
||||
#include "ui_table.hpp"
|
||||
#include "ui_textbox.hpp"
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "ui_status_bar.hpp"
|
||||
|
||||
UI_status_bar::UI_status_bar(QObject *parent) : UI_item{UI_STATUS_BAR_TYPE, parent}
|
||||
{
|
||||
}
|
||||
|
||||
UI_status_bar::UI_status_bar(std::string message, QObject *parent)
|
||||
: UI_item(UI_STATUS_BAR_TYPE, parent), m_current_message(message)
|
||||
{
|
||||
}
|
||||
|
||||
void UI_status_bar::show_message(std::string message, size_t timeout)
|
||||
{
|
||||
m_current_message = message;
|
||||
m_timeout = timeout;
|
||||
emit ui_changed();
|
||||
}
|
||||
|
||||
std::string UI_status_bar::message() const
|
||||
{
|
||||
return m_current_message;
|
||||
}
|
||||
|
||||
void UI_status_bar::from_json(const json &j)
|
||||
{
|
||||
UI_item::from_json(j);
|
||||
m_current_message = j.at("current_message");
|
||||
m_timeout = j.at("timeout");
|
||||
}
|
||||
|
||||
json UI_status_bar::to_json(size_t id) const
|
||||
{
|
||||
json j = UI_item::to_json(id);
|
||||
j["current_message"] = m_current_message;
|
||||
j["timeout"] = m_timeout;
|
||||
return j;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef UI_STATUS_BAR_HPP
|
||||
#define UI_STATUS_BAR_HPP
|
||||
|
||||
#include "ui_item.hpp"
|
||||
#define UI_STATUS_BAR_TYPE std::string("ui_status_bar")
|
||||
|
||||
class UI_status_bar : public UI_item
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UI_status_bar(QObject *parent = nullptr);
|
||||
UI_status_bar(std::string message, QObject *parent = nullptr);
|
||||
|
||||
void show_message(std::string message, size_t timeout = 0);
|
||||
std::string message() const;
|
||||
|
||||
void from_json(const json &j) override;
|
||||
json to_json(size_t id) const override;
|
||||
|
||||
private:
|
||||
std::string m_current_message;
|
||||
size_t m_timeout;
|
||||
};
|
||||
|
||||
#endif // UI_STATUS_BAR_HPP
|
||||
@@ -185,6 +185,11 @@ void Simulator_base::UI_item_parser(json &input)
|
||||
process_ui_stacked_widget(ui_item, widget);
|
||||
continue;
|
||||
}
|
||||
if (ui_item.at("type") == "ui_status_bar")
|
||||
{
|
||||
process_ui_status_bar(ui_item, widget);
|
||||
continue;
|
||||
}
|
||||
if (ui_item.at("type") == "ui_plot")
|
||||
{
|
||||
process_ui_plot(ui_item, widget);
|
||||
@@ -758,6 +763,21 @@ void Simulator_base::process_ui_stacked_widget(json &ui_item, QWidget *widget)
|
||||
}
|
||||
}
|
||||
|
||||
void Simulator_base::process_ui_status_bar(json &ui_item, QWidget *widget)
|
||||
{
|
||||
auto status_bar = qobject_cast<QStatusBar *>(widget);
|
||||
if (status_bar == nullptr)
|
||||
{
|
||||
SPDLOG_WARN("widget is not of type QStatusBar");
|
||||
return;
|
||||
}
|
||||
|
||||
if (status_bar->currentMessage() != QString::fromStdString(ui_item.at("current_message")))
|
||||
{
|
||||
status_bar->showMessage(QString::fromStdString(ui_item.at("current_message")), ui_item.at("timeout"));
|
||||
}
|
||||
}
|
||||
|
||||
void Simulator_base::process_ui_plot(json &ui_item, QWidget *widget)
|
||||
{
|
||||
auto plot = qobject_cast<Plot_wrapper *>(widget);
|
||||
|
||||
@@ -58,6 +58,7 @@ class Simulator_base : public QMainWindow
|
||||
virtual void process_ui_hex_spinbox(json &ui_item, QWidget *widget);
|
||||
virtual void process_ui_tab_widget(json &ui_item, QWidget *widget);
|
||||
virtual void process_ui_stacked_widget(json &ui_item, QWidget *widget);
|
||||
virtual void process_ui_status_bar(json &ui_item, QWidget *widget);
|
||||
virtual void process_ui_plot(json &ui_item, QWidget *widget);
|
||||
virtual void process_ui_table(json &ui_item, QWidget *widget);
|
||||
virtual void process_ui_can(json &ui_item, QWidget *widget);
|
||||
|
||||
@@ -23,6 +23,7 @@ Test_Sim::Test_Sim(Web_socket_wrapper *web_socket, QWidget *parent)
|
||||
PUSH_UI_ITEM(hexSpinBox);
|
||||
PUSH_UI_ITEM(tabWidget);
|
||||
PUSH_UI_ITEM(stackedWidget);
|
||||
PUSH_UI_ITEM(statusbar);
|
||||
}
|
||||
|
||||
Test_Sim::~Test_Sim()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "test_sim.hpp"
|
||||
#include "test.hpp"
|
||||
|
||||
EXPORT_SIM(Test_Sim);
|
||||
|
||||
@@ -11,7 +11,7 @@ Test_Sim::Test_Sim(Communication *com, QObject *parent)
|
||||
m_thermo("Thermo", "%", Color::White, Color::Black, 0, 100, 0), m_led("Led", Color::White, Color::Red),
|
||||
m_table(4, 4, {"Row 1", "Row 2", "Row 3", "Row 4"}, {"Column 1", "Column 2", "Column 3", "Column 4"}),
|
||||
m_spinbox(0, 255, 0), m_double_spinbox(0, 255, 0), m_hex_spinbox(0, 255, 0),
|
||||
m_tab_widget({"Tab 1", "Tab 2", "Tab 3"}, 0), m_stacked_widget(3, 0)
|
||||
m_tab_widget({"Tab 1", "Tab 2", "Tab 3"}, 0), m_stacked_widget(3, 0), m_status_bar()
|
||||
{
|
||||
m_thermo.set_start_color(Color::Red);
|
||||
m_thermo.set_end_color(Color::Red);
|
||||
@@ -35,6 +35,7 @@ Test_Sim::Test_Sim(Communication *com, QObject *parent)
|
||||
PUSH_UI_ITEM(m_hex_spinbox);
|
||||
PUSH_UI_ITEM(m_tab_widget);
|
||||
PUSH_UI_ITEM(m_stacked_widget);
|
||||
PUSH_UI_ITEM(m_status_bar);
|
||||
|
||||
for (size_t i = 0; i < m_table.capacity(); i++)
|
||||
{
|
||||
@@ -90,6 +91,7 @@ void Test_Sim::slider_changed(UI_slider *id, double value)
|
||||
m_spinbox.set_value(value);
|
||||
m_double_spinbox.set_value(value);
|
||||
m_hex_spinbox.set_value(value);
|
||||
m_status_bar.show_message("Test slider changed to " + std::to_string(value));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -29,4 +29,5 @@ class Test_Sim : public Simulator_base
|
||||
UI_hex_spinbox m_hex_spinbox;
|
||||
UI_tab_widget m_tab_widget;
|
||||
UI_stacked_widget m_stacked_widget;
|
||||
UI_status_bar m_status_bar;
|
||||
};
|
||||
Reference in New Issue
Block a user