mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
tab widget
started working on implementation
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "ui_slider.hpp"
|
||||
#include "ui_spinbox.hpp"
|
||||
#include "ui_table.hpp"
|
||||
#include "ui_tab_widget.hpp"
|
||||
#include "ui_textbox.hpp"
|
||||
#include "ui_thermo.hpp"
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
#include "ui_tab_widget.hpp"
|
||||
|
||||
UI_tab_widget::UI_tab_widget(QObject *parent)
|
||||
: UI_item(UI_TAB_WIDGET_TYPE, parent)
|
||||
{
|
||||
}
|
||||
|
||||
UI_tab_widget::UI_tab_widget(std::vector<std::string> tab_names, size_t selected,
|
||||
QObject *parent)
|
||||
: UI_item(UI_TAB_WIDGET_TYPE, parent), m_selected_tab(selected), m_tab_names(tab_names)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UI_tab_widget::set_selected(size_t selected)
|
||||
{
|
||||
m_selected_tab = selected;
|
||||
emit ui_changed();
|
||||
emit this->selected(m_selected_tab);
|
||||
}
|
||||
size_t UI_tab_widget::selected() const
|
||||
{
|
||||
return m_selected_tab;
|
||||
}
|
||||
|
||||
void UI_tab_widget::set_visible(size_t index, bool visible)
|
||||
{
|
||||
if (index >= m_tab_visible.size()) {
|
||||
m_tab_visible.resize(index + 1);
|
||||
}
|
||||
m_tab_visible.at(index) = visible;
|
||||
emit ui_changed();
|
||||
}
|
||||
bool UI_tab_widget::visible(size_t index) const
|
||||
{
|
||||
return m_tab_visible.at(index);
|
||||
}
|
||||
|
||||
void UI_tab_widget::set_tab_name(size_t index, std::string name)
|
||||
{
|
||||
if (index >= m_tab_names.size()) {
|
||||
m_tab_names.resize(index + 1);
|
||||
}
|
||||
m_tab_names.at(index) = name;
|
||||
emit ui_changed();
|
||||
}
|
||||
std::string UI_tab_widget::tab_name(size_t index) const
|
||||
{
|
||||
return m_tab_names.at(index);
|
||||
}
|
||||
|
||||
void UI_tab_widget::from_json(const json &j)
|
||||
{
|
||||
UI_item::from_json(j);
|
||||
if (j.contains("tab_names"))
|
||||
{
|
||||
this->m_tab_names.clear();
|
||||
for (auto option : j["tab_names"])
|
||||
{
|
||||
this->m_tab_names.push_back(option);
|
||||
}
|
||||
}
|
||||
if (j.contains("tab_visible"))
|
||||
{
|
||||
this->m_tab_visible.clear();
|
||||
for (auto option : j["tab_visible"])
|
||||
{
|
||||
this->m_tab_visible.push_back(option);
|
||||
}
|
||||
}
|
||||
m_selected_tab = j.at("selected");
|
||||
}
|
||||
json UI_tab_widget::to_json(size_t id) const
|
||||
{
|
||||
json j = UI_item::to_json(id);
|
||||
j["tab_names"] = m_tab_names;
|
||||
j["tab_visible"] = m_tab_visible;
|
||||
j["selected"] = m_selected_tab;
|
||||
return j;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef UI_TAB_WIDGET_HPP
|
||||
#define UI_TAB_WIDGET_HPP
|
||||
|
||||
#include "ui_item.hpp"
|
||||
|
||||
#define UI_TAB_WIDGET_TYPE std::string("ui_tab_widget")
|
||||
|
||||
class UI_tab_widget : public UI_item
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UI_tab_widget(QObject *parent = nullptr);
|
||||
UI_tab_widget(std::vector<std::string> tab_names, size_t selected = 0,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
void set_selected(size_t selected) override;
|
||||
size_t selected() const;
|
||||
|
||||
void set_visible(size_t index, bool visible);
|
||||
bool visible(size_t index) const;
|
||||
|
||||
void set_tab_name(size_t index, std::string name);
|
||||
std::string tab_name(size_t index) const;
|
||||
|
||||
void from_json(const json &j) override;
|
||||
json to_json(size_t id) const override;
|
||||
signals:
|
||||
void selected(size_t index);
|
||||
private:
|
||||
size_t m_selected_tab;
|
||||
std::vector<std::string> m_tab_names;
|
||||
std::vector<bool> m_tab_visible;
|
||||
};
|
||||
|
||||
#endif // UI_TAB_WIDGET_HPP
|
||||
Reference in New Issue
Block a user