Mercurial > minori
comparison src/gui/dialog/settings.cc @ 316:180714442770
settings: clean up code
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Tue, 11 Jun 2024 15:11:09 -0400 |
parents | 99cbc51433e4 |
children |
comparison
equal
deleted
inserted
replaced
315:34347fd2a2de | 316:180714442770 |
---|---|
10 #include <QWidget> | 10 #include <QWidget> |
11 #ifdef WIN32 | 11 #ifdef WIN32 |
12 # include "sys/win32/dark_theme.h" | 12 # include "sys/win32/dark_theme.h" |
13 #endif | 13 #endif |
14 | 14 |
15 SettingsPage::SettingsPage(QWidget* parent, QString title) : QWidget(parent) { | 15 SettingsPage::SettingsPage(QWidget* parent, QString title) |
16 : QWidget(parent) | |
17 , page_title_(title) | |
18 , layout_(this) { | |
16 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | 19 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
17 page_title = new QLabel(title, this); | |
18 page_title->setWordWrap(false); | |
19 page_title->setFrameShape(QFrame::Panel); | |
20 page_title->setFrameShadow(QFrame::Sunken); | |
21 | 20 |
22 QFont font(page_title->font()); | 21 page_title_.setWordWrap(false); |
23 font.setPixelSize(12); | 22 page_title_.setFrameShape(QFrame::Panel); |
24 font.setWeight(QFont::Bold); | 23 page_title_.setFrameShadow(QFrame::Sunken); |
25 page_title->setFont(font); | |
26 | 24 |
27 { | 25 { |
28 QPalette pal(page_title->palette()); | 26 QFont fnt(page_title_.font()); |
27 fnt.setPixelSize(12); | |
28 fnt.setWeight(QFont::Bold); | |
29 page_title_.setFont(fnt); | |
30 } | |
31 | |
32 { | |
33 QPalette pal(page_title_.palette()); | |
29 pal.setColor(QPalette::Window, QColor(0xAB, 0xAB, 0xAB)); | 34 pal.setColor(QPalette::Window, QColor(0xAB, 0xAB, 0xAB)); |
30 pal.setColor(QPalette::WindowText, Qt::white); | 35 pal.setColor(QPalette::WindowText, Qt::white); |
31 page_title->setPalette(pal); | 36 page_title_.setPalette(pal); |
32 } | 37 } |
33 | 38 |
34 page_title->setAutoFillBackground(true); | 39 page_title_.setAutoFillBackground(true); |
35 | 40 |
36 page_title->setFixedHeight(23); | 41 page_title_.setFixedHeight(23); |
37 page_title->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); | 42 page_title_.setAlignment(Qt::AlignVCenter | Qt::AlignLeft); |
38 page_title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); | 43 page_title_.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); |
39 | 44 |
40 tab_widget = new QTabWidget(this); | 45 tab_widget_.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
41 tab_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | |
42 | 46 |
43 QVBoxLayout* layout = new QVBoxLayout(this); | 47 layout_.setContentsMargins(0, 0, 0, 0); |
44 layout->setContentsMargins(0, 0, 0, 0); | 48 layout_.addWidget(&page_title_); |
45 layout->addWidget(page_title); | 49 layout_.addWidget(&tab_widget_); |
46 layout->addWidget(tab_widget); | |
47 } | 50 } |
48 | 51 |
49 void SettingsPage::SetTitle(QString title) { | 52 void SettingsPage::SetTitle(QString title) { |
50 page_title->setText(title); | 53 page_title_.setText(title); |
51 } | 54 } |
52 | 55 |
53 void SettingsPage::AddTab(QWidget* tab, QString title) { | 56 void SettingsPage::AddTab(QWidget* tab, QString title) { |
54 tab_widget->addTab(tab, title); | 57 tab_widget_.addTab(tab, title); |
55 } | 58 } |
56 | 59 |
57 void SettingsPage::SaveInfo() { | 60 void SettingsPage::SaveInfo() { |
58 // no-op... child classes will implement this | 61 // no-op... child classes will implement this |
59 } | 62 } |
60 | 63 |
61 void SettingsDialog::OnOK() { | 64 void SettingsDialog::OnOK() { |
62 for (int i = 0; i < stacked->count(); i++) { | 65 services_page_.SaveInfo(); |
63 reinterpret_cast<SettingsPage*>(stacked->widget(i))->SaveInfo(); | 66 library_page_.SaveInfo(); |
64 } | 67 application_page_.SaveInfo(); |
68 recognition_page_.SaveInfo(); | |
69 torrents_page_.SaveInfo(); | |
70 | |
65 QDialog::accept(); | 71 QDialog::accept(); |
66 } | 72 } |
67 | 73 |
68 void SettingsDialog::showEvent(QShowEvent* event) { | 74 void SettingsDialog::showEvent(QShowEvent* event) { |
69 QDialog::showEvent(event); | 75 QDialog::showEvent(event); |
70 #ifdef WIN32 | 76 #ifdef WIN32 |
71 win32::SetTitleBarsToBlack(session.config.theme.IsInDarkTheme()); | 77 win32::SetTitleBarsToBlack(session.config.theme.IsInDarkTheme()); |
72 #endif | 78 #endif |
73 } | 79 } |
74 | 80 |
75 SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) { | 81 SettingsDialog::SettingsDialog(QWidget* parent) |
82 : QDialog(parent) | |
83 , layout_(this) | |
84 , widget_layout_(&widget_) | |
85 , button_box_(QDialogButtonBox::Ok | QDialogButtonBox::Cancel) { | |
76 setFixedSize(755, 566); | 86 setFixedSize(755, 566); |
77 setWindowTitle(tr("Settings")); | 87 setWindowTitle(tr("Settings")); |
78 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); | 88 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); |
79 | 89 |
80 QVBoxLayout* full_layout = new QVBoxLayout(this); | |
81 | |
82 { | 90 { |
83 QWidget* widget = new QWidget(this); | 91 widget_.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
84 widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | |
85 QHBoxLayout* layout = new QHBoxLayout(widget); | |
86 | 92 |
87 { | 93 { |
88 sidebar = new SideBar(widget); | 94 sidebar_.setCurrentItem(sidebar_.AddItem(tr("Services"), SideBar::CreateIcon(":/icons/24x24/globe.png"))); |
89 | 95 sidebar_.AddItem(tr("Library"), SideBar::CreateIcon(":/icons/24x24/inbox-film.png")); |
90 sidebar->setCurrentItem(sidebar->AddItem(tr("Services"), SideBar::CreateIcon(":/icons/24x24/globe.png"))); | 96 sidebar_.AddItem(tr("Application"), SideBar::CreateIcon(":/icons/24x24/application-sidebar-list.png")); |
91 sidebar->AddItem(tr("Library"), SideBar::CreateIcon(":/icons/24x24/inbox-film.png")); | 97 sidebar_.AddItem(tr("Recognition"), SideBar::CreateIcon(":/icons/24x24/question.png")); |
92 sidebar->AddItem(tr("Application"), SideBar::CreateIcon(":/icons/24x24/application-sidebar-list.png")); | |
93 sidebar->AddItem(tr("Recognition"), SideBar::CreateIcon(":/icons/24x24/question.png")); | |
94 // sidebar->AddItem(tr("Sharing"), SideBar::CreateIcon(":/icons/24x24/megaphone.png")); | 98 // sidebar->AddItem(tr("Sharing"), SideBar::CreateIcon(":/icons/24x24/megaphone.png")); |
95 sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/24x24/feed.png")); | 99 sidebar_.AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/24x24/feed.png")); |
96 // sidebar->AddItem(tr("Advanced"), SideBar::CreateIcon(":/icons/24x24/gear.png")); | 100 // sidebar->AddItem(tr("Advanced"), SideBar::CreateIcon(":/icons/24x24/gear.png")); |
97 | 101 |
98 sidebar->setIconSize(QSize(24, 24)); | 102 sidebar_.setIconSize(QSize(24, 24)); |
99 sidebar->setFrameShape(QFrame::Box); | 103 sidebar_.setFrameShape(QFrame::Box); |
100 | 104 |
101 sidebar->SetBackgroundTransparent(false); | 105 sidebar_.SetBackgroundTransparent(false); |
102 sidebar->setBackgroundRole(QPalette::Base); | 106 sidebar_.setBackgroundRole(QPalette::Base); |
103 | 107 |
104 sidebar->setFixedWidth(158); | 108 sidebar_.setFixedWidth(158); |
105 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); | 109 sidebar_.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
106 layout->addWidget(sidebar); | 110 widget_layout_.addWidget(&sidebar_); |
107 } | 111 } |
108 | 112 |
109 { | 113 { |
110 stacked = new QStackedWidget(widget); | 114 stacked_.addWidget(&services_page_); |
111 stacked->addWidget(new SettingsPageServices(stacked)); | 115 stacked_.addWidget(&library_page_); |
112 stacked->addWidget(new SettingsPageLibrary(stacked)); | 116 stacked_.addWidget(&application_page_); |
113 stacked->addWidget(new SettingsPageApplication(stacked)); | 117 stacked_.addWidget(&recognition_page_); |
114 stacked->addWidget(new SettingsPageRecognition(stacked)); | 118 stacked_.addWidget(&torrents_page_); |
115 stacked->addWidget(new SettingsPageTorrents(stacked)); | 119 stacked_.setCurrentIndex(0); |
116 stacked->setCurrentIndex(0); | |
117 | 120 |
118 connect(sidebar, &QListWidget::currentRowChanged, stacked, &QStackedWidget::setCurrentIndex); | 121 connect(&sidebar_, &QListWidget::currentRowChanged, &stacked_, &QStackedWidget::setCurrentIndex); |
119 | 122 |
120 layout->addWidget(stacked); | 123 widget_layout_.addWidget(&stacked_); |
121 } | 124 } |
122 | 125 |
123 layout->setContentsMargins(0, 0, 0, 0); | 126 widget_layout_.setContentsMargins(0, 0, 0, 0); |
124 full_layout->addWidget(widget); | 127 layout_.addWidget(&widget_); |
125 } | 128 } |
126 | 129 |
127 { | 130 { |
128 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); | 131 connect(&button_box_, &QDialogButtonBox::accepted, this, &SettingsDialog::OnOK); |
129 connect(button_box, &QDialogButtonBox::accepted, this, &SettingsDialog::OnOK); | 132 connect(&button_box_, &QDialogButtonBox::rejected, this, &QDialog::reject); |
130 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); | 133 layout_.addWidget(&button_box_); |
131 full_layout->addWidget(button_box); | |
132 } | 134 } |
133 } | 135 } |