From a8a7ce2538887e6a4875ffa7f68a3f2859bd7dab Mon Sep 17 00:00:00 2001 From: blue Date: Wed, 19 Jan 2022 23:46:42 +0300 Subject: [PATCH] some more thoughts about settings widgets --- ui/widgets/settings/CMakeLists.txt | 6 ++ ui/widgets/settings/pageappearance.cpp | 13 +++ ui/widgets/settings/pageappearance.h | 26 +++++ ui/widgets/settings/pageappearance.ui | 28 ++++++ ui/widgets/settings/pagegeneral.cpp | 13 +++ ui/widgets/settings/pagegeneral.h | 26 +++++ ui/widgets/settings/pagegeneral.ui | 28 ++++++ ui/widgets/settings/settings.cpp | 10 ++ ui/widgets/settings/settings.h | 4 + ui/widgets/settings/settings.ui | 127 ++++++++++++++++--------- ui/widgets/settings/settingslist.cpp | 11 +++ ui/widgets/settings/settingslist.h | 1 + 12 files changed, 248 insertions(+), 45 deletions(-) create mode 100644 ui/widgets/settings/pageappearance.cpp create mode 100644 ui/widgets/settings/pageappearance.h create mode 100644 ui/widgets/settings/pageappearance.ui create mode 100644 ui/widgets/settings/pagegeneral.cpp create mode 100644 ui/widgets/settings/pagegeneral.h create mode 100644 ui/widgets/settings/pagegeneral.ui diff --git a/ui/widgets/settings/CMakeLists.txt b/ui/widgets/settings/CMakeLists.txt index 9f0fa76..e100bfe 100644 --- a/ui/widgets/settings/CMakeLists.txt +++ b/ui/widgets/settings/CMakeLists.txt @@ -4,4 +4,10 @@ target_sources(squawk PRIVATE settings.h settings.cpp settings.ui + pagegeneral.h + pagegeneral.cpp + pagegeneral.ui + pageappearance.h + pageappearance.cpp + pageappearance.ui ) diff --git a/ui/widgets/settings/pageappearance.cpp b/ui/widgets/settings/pageappearance.cpp new file mode 100644 index 0000000..725f452 --- /dev/null +++ b/ui/widgets/settings/pageappearance.cpp @@ -0,0 +1,13 @@ +#include "pageappearance.h" +#include "ui_pageappearance.h" + +PageAppearance::PageAppearance(QWidget* parent): + QWidget(parent), + m_ui(new Ui::PageAppearance()) +{ + m_ui->setupUi(this); +} + +PageAppearance::~PageAppearance() +{ +} diff --git a/ui/widgets/settings/pageappearance.h b/ui/widgets/settings/pageappearance.h new file mode 100644 index 0000000..85d45a1 --- /dev/null +++ b/ui/widgets/settings/pageappearance.h @@ -0,0 +1,26 @@ +#ifndef PAGEAPPEARANCE_H +#define PAGEAPPEARANCE_H + +#include +#include + +namespace Ui +{ +class PageAppearance; +} + +/** + * @todo write docs + */ +class PageAppearance : public QWidget +{ + Q_OBJECT +public: + PageAppearance(QWidget* parent = nullptr); + ~PageAppearance(); + +private: + QScopedPointer m_ui; +}; + +#endif // PAGEAPPEARANCE_H diff --git a/ui/widgets/settings/pageappearance.ui b/ui/widgets/settings/pageappearance.ui new file mode 100644 index 0000000..1199347 --- /dev/null +++ b/ui/widgets/settings/pageappearance.ui @@ -0,0 +1,28 @@ + + + PageAppearance + + + + 0 + 0 + 400 + 300 + + + + + + + Theme + + + + + + + + + + + diff --git a/ui/widgets/settings/pagegeneral.cpp b/ui/widgets/settings/pagegeneral.cpp new file mode 100644 index 0000000..e448f80 --- /dev/null +++ b/ui/widgets/settings/pagegeneral.cpp @@ -0,0 +1,13 @@ +#include "pagegeneral.h" +#include "ui_pagegeneral.h" + +PageGeneral::PageGeneral(QWidget* parent): + QWidget(parent), + m_ui(new Ui::PageGeneral()) +{ + m_ui->setupUi(this); +} + +PageGeneral::~PageGeneral() +{ +} diff --git a/ui/widgets/settings/pagegeneral.h b/ui/widgets/settings/pagegeneral.h new file mode 100644 index 0000000..77c0c3a --- /dev/null +++ b/ui/widgets/settings/pagegeneral.h @@ -0,0 +1,26 @@ +#ifndef PAGEGENERAL_H +#define PAGEGENERAL_H + +#include +#include + +namespace Ui +{ +class PageGeneral; +} + +/** + * @todo write docs + */ +class PageGeneral : public QWidget +{ + Q_OBJECT +public: + PageGeneral(QWidget* parent = nullptr); + ~PageGeneral(); + +private: + QScopedPointer m_ui; +}; + +#endif // PAGEGENERAL_H diff --git a/ui/widgets/settings/pagegeneral.ui b/ui/widgets/settings/pagegeneral.ui new file mode 100644 index 0000000..9921715 --- /dev/null +++ b/ui/widgets/settings/pagegeneral.ui @@ -0,0 +1,28 @@ + + + PageGeneral + + + + 0 + 0 + 400 + 300 + + + + + + + Downloads path + + + + + + + + + + + diff --git a/ui/widgets/settings/settings.cpp b/ui/widgets/settings/settings.cpp index 0397d0c..cdcf0cc 100644 --- a/ui/widgets/settings/settings.cpp +++ b/ui/widgets/settings/settings.cpp @@ -6,9 +6,19 @@ Settings::Settings(QWidget* parent): m_ui(new Ui::Settings()) { m_ui->setupUi(this); + + connect(m_ui->list, &QListWidget::currentItemChanged, this, &Settings::onCurrentPageChanged); } Settings::~Settings() { } +void Settings::onCurrentPageChanged(QListWidgetItem* current) +{ + if (current != nullptr) { + m_ui->header->setText(current->text()); + + m_ui->content->setCurrentIndex(m_ui->list->currentRow()); + } +} diff --git a/ui/widgets/settings/settings.h b/ui/widgets/settings/settings.h index 61129d8..f961e08 100644 --- a/ui/widgets/settings/settings.h +++ b/ui/widgets/settings/settings.h @@ -2,6 +2,7 @@ #define SETTINGS_H #include +#include #include namespace Ui @@ -19,6 +20,9 @@ public: Settings(QWidget* parent = nullptr); ~Settings(); +protected slots: + void onCurrentPageChanged(QListWidgetItem* current); + private: QScopedPointer m_ui; }; diff --git a/ui/widgets/settings/settings.ui b/ui/widgets/settings/settings.ui index ca9946e..fe092dc 100644 --- a/ui/widgets/settings/settings.ui +++ b/ui/widgets/settings/settings.ui @@ -6,7 +6,7 @@ 0 0 - 465 + 502 363 @@ -21,33 +21,13 @@ 0 - 7 + 0 0 - - - - Apply - - - - - - - - - - Ok - - - - - - - - + + 0 @@ -66,12 +46,12 @@ 16777215 + + + QFrame::NoFrame - - 0 - Qt::ScrollBarAlwaysOff @@ -103,7 +83,7 @@ QListView::Adjust - QListView::Batched + QListView::SinglePass QListView::IconMode @@ -143,24 +123,71 @@ - - - - - - - General - - - - - - - Cancel - - - + + + + + 0 + 0 + + + + + + Apply + + + + .. + + + + + + + Cancel + + + + .. + + + + + + + Ok + + + + .. + + + + + + + font-size: 14pt; + + + General + + + + + + + + 0 + 0 + + + + + + + @@ -171,6 +198,16 @@ QListWidget
ui/widgets/settings/settingslist.h
+ + PageGeneral + QWidget +
ui/widgets/settings/pagegeneral.h
+
+ + PageAppearance + QWidget +
ui/widgets/settings/pageappearance.h
+
diff --git a/ui/widgets/settings/settingslist.cpp b/ui/widgets/settings/settingslist.cpp index 1925632..3a5e2cb 100644 --- a/ui/widgets/settings/settingslist.cpp +++ b/ui/widgets/settings/settingslist.cpp @@ -4,6 +4,7 @@ SettingsList::SettingsList(QWidget* parent): QListWidget(parent), lastWidth(0) { + } SettingsList::~SettingsList() @@ -25,3 +26,13 @@ void SettingsList::resizeEvent(QResizeEvent* event) lastWidth = event->size().width(); QListWidget::resizeEvent(event); } + +QRect SettingsList::visualRect(const QModelIndex& index) const +{ + QRect res = QListWidget::visualRect(index); + if (index.isValid()) { + res.setWidth(lastWidth); + } + return res; +} + diff --git a/ui/widgets/settings/settingslist.h b/ui/widgets/settings/settingslist.h index 9621c67..a51fc3a 100644 --- a/ui/widgets/settings/settingslist.h +++ b/ui/widgets/settings/settingslist.h @@ -17,6 +17,7 @@ public: protected: QStyleOptionViewItem viewOptions() const override; void resizeEvent(QResizeEvent * event) override; + QRect visualRect(const QModelIndex & index) const override; private: int lastWidth;