Mercurial > minori
changeset 316:180714442770
settings: clean up code
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Tue, 11 Jun 2024 15:11:09 -0400 |
parents | 34347fd2a2de |
children | b1f4d1867ab1 |
files | include/gui/dialog/settings.h src/gui/dialog/settings.cc |
diffstat | 2 files changed, 87 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- a/include/gui/dialog/settings.h Tue Jun 11 14:16:40 2024 -0400 +++ b/include/gui/dialog/settings.h Tue Jun 11 15:11:09 2024 -0400 @@ -4,16 +4,17 @@ #include "core/anime.h" #include "core/config.h" #include "core/session.h" +#include "gui/widgets/sidebar.h" #include <QDialog> +#include <QDialogButtonBox> +#include <QLabel> #include <QListWidget> #include <QLocale> +#include <QStackedWidget> +#include <QTabWidget> +#include <QVBoxLayout> #include <QWidget> -class QLabel; -class QTabWidget; -class QStackedWidget; -class SideBar; - /* !!! MOVE THIS ELSEWHERE! */ class DroppableListWidget : public QListWidget { Q_OBJECT @@ -40,8 +41,9 @@ void AddTab(QWidget* tab, QString title = ""); private: - QLabel* page_title; - QTabWidget* tab_widget; + QLabel page_title_; + QTabWidget tab_widget_; + QVBoxLayout layout_; }; class SettingsPageServices final : public SettingsPage { @@ -133,8 +135,21 @@ void showEvent(QShowEvent* event) override; private: - SideBar* sidebar; - QStackedWidget* stacked; + QVBoxLayout layout_; + + QWidget widget_; + QHBoxLayout widget_layout_; + + SideBar sidebar_; + QStackedWidget stacked_; + + SettingsPageServices services_page_; + SettingsPageApplication application_page_; + SettingsPageTorrents torrents_page_; + SettingsPageRecognition recognition_page_; + SettingsPageLibrary library_page_; + + QDialogButtonBox button_box_; }; #endif // MINORI_GUI_DIALOG_SETTINGS_H_
--- a/src/gui/dialog/settings.cc Tue Jun 11 14:16:40 2024 -0400 +++ b/src/gui/dialog/settings.cc Tue Jun 11 15:11:09 2024 -0400 @@ -12,46 +12,49 @@ # include "sys/win32/dark_theme.h" #endif -SettingsPage::SettingsPage(QWidget* parent, QString title) : QWidget(parent) { +SettingsPage::SettingsPage(QWidget* parent, QString title) + : QWidget(parent) + , page_title_(title) + , layout_(this) { setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); - page_title = new QLabel(title, this); - page_title->setWordWrap(false); - page_title->setFrameShape(QFrame::Panel); - page_title->setFrameShadow(QFrame::Sunken); - QFont font(page_title->font()); - font.setPixelSize(12); - font.setWeight(QFont::Bold); - page_title->setFont(font); + page_title_.setWordWrap(false); + page_title_.setFrameShape(QFrame::Panel); + page_title_.setFrameShadow(QFrame::Sunken); { - QPalette pal(page_title->palette()); + QFont fnt(page_title_.font()); + fnt.setPixelSize(12); + fnt.setWeight(QFont::Bold); + page_title_.setFont(fnt); + } + + { + QPalette pal(page_title_.palette()); pal.setColor(QPalette::Window, QColor(0xAB, 0xAB, 0xAB)); pal.setColor(QPalette::WindowText, Qt::white); - page_title->setPalette(pal); + page_title_.setPalette(pal); } - page_title->setAutoFillBackground(true); + page_title_.setAutoFillBackground(true); - page_title->setFixedHeight(23); - page_title->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); - page_title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + page_title_.setFixedHeight(23); + page_title_.setAlignment(Qt::AlignVCenter | Qt::AlignLeft); + page_title_.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - tab_widget = new QTabWidget(this); - tab_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); + tab_widget_.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); - QVBoxLayout* layout = new QVBoxLayout(this); - layout->setContentsMargins(0, 0, 0, 0); - layout->addWidget(page_title); - layout->addWidget(tab_widget); + layout_.setContentsMargins(0, 0, 0, 0); + layout_.addWidget(&page_title_); + layout_.addWidget(&tab_widget_); } void SettingsPage::SetTitle(QString title) { - page_title->setText(title); + page_title_.setText(title); } void SettingsPage::AddTab(QWidget* tab, QString title) { - tab_widget->addTab(tab, title); + tab_widget_.addTab(tab, title); } void SettingsPage::SaveInfo() { @@ -59,9 +62,12 @@ } void SettingsDialog::OnOK() { - for (int i = 0; i < stacked->count(); i++) { - reinterpret_cast<SettingsPage*>(stacked->widget(i))->SaveInfo(); - } + services_page_.SaveInfo(); + library_page_.SaveInfo(); + application_page_.SaveInfo(); + recognition_page_.SaveInfo(); + torrents_page_.SaveInfo(); + QDialog::accept(); } @@ -72,62 +78,58 @@ #endif } -SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) { +SettingsDialog::SettingsDialog(QWidget* parent) + : QDialog(parent) + , layout_(this) + , widget_layout_(&widget_) + , button_box_(QDialogButtonBox::Ok | QDialogButtonBox::Cancel) { setFixedSize(755, 566); setWindowTitle(tr("Settings")); setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); - QVBoxLayout* full_layout = new QVBoxLayout(this); - { - QWidget* widget = new QWidget(this); - widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); - QHBoxLayout* layout = new QHBoxLayout(widget); + widget_.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); { - sidebar = new SideBar(widget); - - sidebar->setCurrentItem(sidebar->AddItem(tr("Services"), SideBar::CreateIcon(":/icons/24x24/globe.png"))); - sidebar->AddItem(tr("Library"), SideBar::CreateIcon(":/icons/24x24/inbox-film.png")); - sidebar->AddItem(tr("Application"), SideBar::CreateIcon(":/icons/24x24/application-sidebar-list.png")); - sidebar->AddItem(tr("Recognition"), SideBar::CreateIcon(":/icons/24x24/question.png")); + sidebar_.setCurrentItem(sidebar_.AddItem(tr("Services"), SideBar::CreateIcon(":/icons/24x24/globe.png"))); + sidebar_.AddItem(tr("Library"), SideBar::CreateIcon(":/icons/24x24/inbox-film.png")); + sidebar_.AddItem(tr("Application"), SideBar::CreateIcon(":/icons/24x24/application-sidebar-list.png")); + sidebar_.AddItem(tr("Recognition"), SideBar::CreateIcon(":/icons/24x24/question.png")); // sidebar->AddItem(tr("Sharing"), SideBar::CreateIcon(":/icons/24x24/megaphone.png")); - sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/24x24/feed.png")); + sidebar_.AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/24x24/feed.png")); // sidebar->AddItem(tr("Advanced"), SideBar::CreateIcon(":/icons/24x24/gear.png")); - sidebar->setIconSize(QSize(24, 24)); - sidebar->setFrameShape(QFrame::Box); + sidebar_.setIconSize(QSize(24, 24)); + sidebar_.setFrameShape(QFrame::Box); - sidebar->SetBackgroundTransparent(false); - sidebar->setBackgroundRole(QPalette::Base); + sidebar_.SetBackgroundTransparent(false); + sidebar_.setBackgroundRole(QPalette::Base); - sidebar->setFixedWidth(158); - sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); - layout->addWidget(sidebar); + sidebar_.setFixedWidth(158); + sidebar_.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + widget_layout_.addWidget(&sidebar_); } { - stacked = new QStackedWidget(widget); - stacked->addWidget(new SettingsPageServices(stacked)); - stacked->addWidget(new SettingsPageLibrary(stacked)); - stacked->addWidget(new SettingsPageApplication(stacked)); - stacked->addWidget(new SettingsPageRecognition(stacked)); - stacked->addWidget(new SettingsPageTorrents(stacked)); - stacked->setCurrentIndex(0); + stacked_.addWidget(&services_page_); + stacked_.addWidget(&library_page_); + stacked_.addWidget(&application_page_); + stacked_.addWidget(&recognition_page_); + stacked_.addWidget(&torrents_page_); + stacked_.setCurrentIndex(0); - connect(sidebar, &QListWidget::currentRowChanged, stacked, &QStackedWidget::setCurrentIndex); + connect(&sidebar_, &QListWidget::currentRowChanged, &stacked_, &QStackedWidget::setCurrentIndex); - layout->addWidget(stacked); + widget_layout_.addWidget(&stacked_); } - layout->setContentsMargins(0, 0, 0, 0); - full_layout->addWidget(widget); + widget_layout_.setContentsMargins(0, 0, 0, 0); + layout_.addWidget(&widget_); } { - QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); - connect(button_box, &QDialogButtonBox::accepted, this, &SettingsDialog::OnOK); - connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); - full_layout->addWidget(button_box); + connect(&button_box_, &QDialogButtonBox::accepted, this, &SettingsDialog::OnOK); + connect(&button_box_, &QDialogButtonBox::rejected, this, &QDialog::reject); + layout_.addWidget(&button_box_); } }