diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-12-05 15:08:23 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-12-05 15:08:23 +0100 |
commit | 052fde2c37b56ab4af4598878eb14ae3d4fe204e (patch) | |
tree | 8374babfedbdca030c03167179d5f5592eecb3d9 /confui | |
parent | 0a506540dad3a6b2de43917734efb58b2ccc1e0a (diff) |
add seperate scroll container class
Diffstat (limited to 'confui')
-rw-r--r-- | confui/confui.pro | 6 | ||||
-rw-r--r-- | confui/ui_scroll_container.cpp | 29 | ||||
-rw-r--r-- | confui/ui_scroll_container.h | 22 | ||||
-rw-r--r-- | confui/ui_tab_automations.cpp | 18 | ||||
-rw-r--r-- | confui/ui_tab_node_overview.cpp | 37 | ||||
-rw-r--r-- | confui/ui_tab_node_overview.h | 4 |
6 files changed, 79 insertions, 37 deletions
diff --git a/confui/confui.pro b/confui/confui.pro index e0950b9..6d36db2 100644 --- a/confui/confui.pro +++ b/confui/confui.pro @@ -7,7 +7,8 @@ SOURCES += \ ui_tab_automations.cpp \ ui_tab_node_overview.cpp \ ui_node.cpp \ - ui_automation.cpp + ui_automation.cpp \ + ui_scroll_container.cpp HEADERS += \ mainwindow.h \ @@ -15,7 +16,8 @@ HEADERS += \ ui_tab_automations.h \ ui_tab_node_overview.h \ ui_node.h \ - ui_automation.h + ui_automation.h \ + ui_scroll_container.h CONFIG += c++17 CONFIG += force_debug_info diff --git a/confui/ui_scroll_container.cpp b/confui/ui_scroll_container.cpp new file mode 100644 index 0000000..5a412f8 --- /dev/null +++ b/confui/ui_scroll_container.cpp @@ -0,0 +1,29 @@ +#include "ui_scroll_container.h" + +CDScrollContainerLayout::~CDScrollContainerLayout() { } +CDScrollContainerLayout::CDScrollContainerLayout(QWidget *parent) : QVBoxLayout(parent) { + scroll_area = new QScrollArea; + scroll_container = new QWidget; + scroll_inner = new QVBoxLayout; + + scroll_area->setWidgetResizable(true); + scroll_area->setFrameShape(QFrame::NoFrame); + scroll_area->setBackgroundRole(QPalette::Window); + scroll_area->setFrameShadow(QFrame::Plain); + scroll_area->setWidget(scroll_container); + scroll_area->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + + scroll_container->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); + scroll_container->setLayout(scroll_inner); + + QVBoxLayout::addWidget(scroll_area); +} + +void CDScrollContainerLayout::addWidget(QWidget* widget) { + scroll_inner->addWidget(widget); +} + +void CDScrollContainerLayout::removeWidget(QWidget* widget) { + scroll_inner->removeWidget(widget); +} + diff --git a/confui/ui_scroll_container.h b/confui/ui_scroll_container.h new file mode 100644 index 0000000..e731f6a --- /dev/null +++ b/confui/ui_scroll_container.h @@ -0,0 +1,22 @@ +#pragma once + +#include <QScrollArea> +#include <QWidget> +#include <QVBoxLayout> + +class CDScrollContainerLayout : public QVBoxLayout { + Q_OBJECT + +private: + QVBoxLayout* main_layout; + QScrollArea* scroll_area; + QWidget* scroll_container; + QVBoxLayout* scroll_inner; + +public: + CDScrollContainerLayout(QWidget *parent = nullptr); + virtual ~CDScrollContainerLayout(); + virtual void addWidget(QWidget* widget); + virtual void removeWidget(QWidget* widget); +}; + diff --git a/confui/ui_tab_automations.cpp b/confui/ui_tab_automations.cpp index d1148d5..90581f3 100644 --- a/confui/ui_tab_automations.cpp +++ b/confui/ui_tab_automations.cpp @@ -1,9 +1,27 @@ #include <QVBoxLayout> #include <QWidget> #include <QLabel> +#include <QPushButton> #include "ui_tab_automations.h" +class CDAddAutomationWidget : public QWidget { +public: + CDAddAutomationWidget(QWidget* parent) : QWidget(parent) { + QHBoxLayout* main_layout = new QHBoxLayout; + QPushButton* button_add = new QPushButton("Add automation"); + + main_layout->addStretch(); + main_layout->addWidget(button_add); + main_layout->addStretch(); + + setLayout(main_layout); + } + + ~CDAddAutomationWidget() {} +}; + + CDAutomationsTabWidget::~CDAutomationsTabWidget() { } CDAutomationsTabWidget::CDAutomationsTabWidget(CDMainWindow* main_window) : QWidget(main_window) { this->mainwindow = main_window; diff --git a/confui/ui_tab_node_overview.cpp b/confui/ui_tab_node_overview.cpp index b60085c..44ef788 100644 --- a/confui/ui_tab_node_overview.cpp +++ b/confui/ui_tab_node_overview.cpp @@ -5,49 +5,16 @@ #include "ui_tab_node_overview.h" #include "ui_node.h" -#include "ui_automation.h" - -class CDAddAutomationWidget : public QWidget { -public: - CDAddAutomationWidget(QWidget* parent) : QWidget(parent) { - QHBoxLayout* main_layout = new QHBoxLayout; - QPushButton* button_add = new QPushButton("Add automation"); - - main_layout->addStretch(); - main_layout->addWidget(button_add); - main_layout->addStretch(); - - setLayout(main_layout); - } - - ~CDAddAutomationWidget() {} -}; CDNodeOverviewTabWidget::~CDNodeOverviewTabWidget() { } CDNodeOverviewTabWidget::CDNodeOverviewTabWidget(CDMainWindow* main_window) : QWidget(main_window) { this->mainwindow = main_window; - - QVBoxLayout* main_layout = new QVBoxLayout; - QScrollArea* scroll_area = new QScrollArea; - QWidget* scroll_container = new QWidget; - QVBoxLayout* scroll_inner = new QVBoxLayout; - - scroll_area->setWidgetResizable(true); - scroll_area->setFrameShape(QFrame::NoFrame); - scroll_area->setBackgroundRole(QPalette::Window); - scroll_area->setFrameShadow(QFrame::Plain); - scroll_area->setWidget(scroll_container); - scroll_area->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - - scroll_container->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); - scroll_container->setLayout(scroll_inner); + main_layout = new CDScrollContainerLayout(this); vector<cd_s_node*> nodes = this->mainwindow->mesh_connector->get_nodes(); CDNodeWidget* nd_w = new CDNodeWidget(nodes[0], this); - scroll_inner->addWidget(nd_w); - - main_layout->addWidget(scroll_area); + main_layout->addWidget(nd_w); update(); setLayout(main_layout); diff --git a/confui/ui_tab_node_overview.h b/confui/ui_tab_node_overview.h index ec5713c..d541dc6 100644 --- a/confui/ui_tab_node_overview.h +++ b/confui/ui_tab_node_overview.h @@ -2,11 +2,15 @@ #include <QMainWindow> +#include "ui_scroll_container.h" #include "mainwindow.h" class CDNodeOverviewTabWidget : public QWidget { Q_OBJECT +private: + CDScrollContainerLayout* main_layout; + public: CDMainWindow *mainwindow = nullptr; |