mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
stacked widget
tested and working
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "ui_plot.hpp"
|
||||
#include "ui_slider.hpp"
|
||||
#include "ui_spinbox.hpp"
|
||||
#include "ui_stacked_widget.hpp"
|
||||
#include "ui_tab_widget.hpp"
|
||||
#include "ui_table.hpp"
|
||||
#include "ui_textbox.hpp"
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "ui_stacked_widget.hpp"
|
||||
|
||||
UI_stacked_widget::UI_stacked_widget(QObject *parent) : UI_item(UI_STACKED_WIDGET_TYPE, parent)
|
||||
{
|
||||
}
|
||||
|
||||
UI_stacked_widget::UI_stacked_widget(size_t tab_count, size_t current_tab, QObject *parent)
|
||||
: UI_item(UI_STACKED_WIDGET_TYPE, parent), m_tab_count(tab_count), m_current_tab(current_tab)
|
||||
{
|
||||
}
|
||||
|
||||
void UI_stacked_widget::set_selected(size_t selected)
|
||||
{
|
||||
if (selected >= m_tab_count)
|
||||
return;
|
||||
m_current_tab = selected;
|
||||
emit ui_changed();
|
||||
}
|
||||
size_t UI_stacked_widget::selected() const
|
||||
{
|
||||
return m_current_tab;
|
||||
}
|
||||
|
||||
void UI_stacked_widget::advance_tab()
|
||||
{
|
||||
if (m_tab_count == 0)
|
||||
return;
|
||||
m_current_tab = (m_current_tab + 1) % m_tab_count;
|
||||
emit ui_changed();
|
||||
}
|
||||
|
||||
void UI_stacked_widget::from_json(const json &j)
|
||||
{
|
||||
UI_item::from_json(j);
|
||||
m_tab_count = j.at("tab_count");
|
||||
m_current_tab = j.at("current_tab");
|
||||
}
|
||||
json UI_stacked_widget::to_json(size_t id) const
|
||||
{
|
||||
json j = UI_item::to_json(id);
|
||||
j["tab_count"] = m_tab_count;
|
||||
j["current_tab"] = m_current_tab;
|
||||
return j;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef UI_STACKED_WIDGET_HPP
|
||||
#define UI_STACKED_WIDGET_HPP
|
||||
|
||||
#include "ui_item.hpp"
|
||||
#define UI_STACKED_WIDGET_TYPE std::string("ui_stacked_widget")
|
||||
|
||||
class UI_stacked_widget : public UI_item
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UI_stacked_widget(QObject *parent = nullptr);
|
||||
UI_stacked_widget(size_t tab_count, size_t current_tab, QObject *parent = nullptr);
|
||||
|
||||
void set_selected(size_t selected) override;
|
||||
size_t selected() const;
|
||||
void advance_tab();
|
||||
|
||||
void from_json(const json &j) override;
|
||||
json to_json(size_t id) const override;
|
||||
private:
|
||||
size_t m_tab_count;
|
||||
size_t m_current_tab;
|
||||
};
|
||||
|
||||
#endif // UI_STACKED_WIDGET_HPP
|
||||
Reference in New Issue
Block a user