annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
1 #include "gui/dialog/settings.h"
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
2 #include "core/session.h"
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
3 #include "gui/widgets/sidebar.h"
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
4 #include "gui/widgets/text.h"
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
5 #include <QDialogButtonBox>
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 74
diff changeset
6 #include <QHBoxLayout>
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 74
diff changeset
7 #include <QLabel>
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
8 #include <QStackedWidget>
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
9 #include <QVBoxLayout>
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 #include <QWidget>
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
11 #ifdef WIN32
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
12 # include "sys/win32/dark_theme.h"
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
13 #endif
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
15 SettingsPage::SettingsPage(QWidget* parent, QString title)
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
16 : QWidget(parent)
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
17 , page_title_(title)
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
18 , layout_(this) {
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
36
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
20
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
21 page_title_.setWordWrap(false);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
22 page_title_.setFrameShape(QFrame::Panel);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
23 page_title_.setFrameShadow(QFrame::Sunken);
36
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
24
102
b315f3759c56 *: big patch
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
25 {
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
26 QFont fnt(page_title_.font());
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
27 fnt.setPixelSize(12);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
28 fnt.setWeight(QFont::Bold);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
29 page_title_.setFont(fnt);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
30 }
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
31
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
32 {
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
33 QPalette pal(page_title_.palette());
102
b315f3759c56 *: big patch
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
34 pal.setColor(QPalette::Window, QColor(0xAB, 0xAB, 0xAB));
b315f3759c56 *: big patch
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
35 pal.setColor(QPalette::WindowText, Qt::white);
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
36 page_title_.setPalette(pal);
102
b315f3759c56 *: big patch
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
37 }
118
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 116
diff changeset
38
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
39 page_title_.setAutoFillBackground(true);
36
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
40
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
41 page_title_.setFixedHeight(23);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
42 page_title_.setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
43 page_title_.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
44
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
45 tab_widget_.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
46
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
47 layout_.setContentsMargins(0, 0, 0, 0);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
48 layout_.addWidget(&page_title_);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
49 layout_.addWidget(&tab_widget_);
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
50 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
51
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
52 void SettingsPage::SetTitle(QString title) {
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
53 page_title_.setText(title);
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
54 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
55
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
56 void SettingsPage::AddTab(QWidget* tab, QString title) {
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
57 tab_widget_.addTab(tab, title);
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
58 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
59
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
60 void SettingsPage::SaveInfo() {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
61 // no-op... child classes will implement this
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
62 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
63
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
64 void SettingsDialog::OnOK() {
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
65 services_page_.SaveInfo();
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
66 library_page_.SaveInfo();
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
67 application_page_.SaveInfo();
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
68 recognition_page_.SaveInfo();
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
69 torrents_page_.SaveInfo();
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
70
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
71 QDialog::accept();
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
72 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
73
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
74 void SettingsDialog::showEvent(QShowEvent* event) {
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
75 QDialog::showEvent(event);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
76 #ifdef WIN32
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
77 win32::SetTitleBarsToBlack(session.config.theme.IsInDarkTheme());
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
78 #endif
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
79 }
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
80
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
81 SettingsDialog::SettingsDialog(QWidget* parent)
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
82 : QDialog(parent)
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
83 , layout_(this)
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
84 , widget_layout_(&widget_)
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
85 , button_box_(QDialogButtonBox::Ok | QDialogButtonBox::Cancel) {
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
86 setFixedSize(755, 566);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
87 setWindowTitle(tr("Settings"));
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
88 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
89
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
90 {
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
91 widget_.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
92
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
93 {
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
94 sidebar_.setCurrentItem(sidebar_.AddItem(tr("Services"), SideBar::CreateIcon(":/icons/24x24/globe.png")));
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
95 sidebar_.AddItem(tr("Library"), SideBar::CreateIcon(":/icons/24x24/inbox-film.png"));
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
96 sidebar_.AddItem(tr("Application"), SideBar::CreateIcon(":/icons/24x24/application-sidebar-list.png"));
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
97 sidebar_.AddItem(tr("Recognition"), SideBar::CreateIcon(":/icons/24x24/question.png"));
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
98 // sidebar->AddItem(tr("Sharing"), SideBar::CreateIcon(":/icons/24x24/megaphone.png"));
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
99 sidebar_.AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/24x24/feed.png"));
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
100 // sidebar->AddItem(tr("Advanced"), SideBar::CreateIcon(":/icons/24x24/gear.png"));
36
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
101
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
102 sidebar_.setIconSize(QSize(24, 24));
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
103 sidebar_.setFrameShape(QFrame::Box);
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
104
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
105 sidebar_.SetBackgroundTransparent(false);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
106 sidebar_.setBackgroundRole(QPalette::Base);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
107
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
108 sidebar_.setFixedWidth(158);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
109 sidebar_.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
110 widget_layout_.addWidget(&sidebar_);
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
111 }
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
112
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
113 {
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
114 stacked_.addWidget(&services_page_);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
115 stacked_.addWidget(&library_page_);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
116 stacked_.addWidget(&application_page_);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
117 stacked_.addWidget(&recognition_page_);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
118 stacked_.addWidget(&torrents_page_);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
119 stacked_.setCurrentIndex(0);
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
120
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
121 connect(&sidebar_, &QListWidget::currentRowChanged, &stacked_, &QStackedWidget::setCurrentIndex);
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
122
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
123 widget_layout_.addWidget(&stacked_);
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
124 }
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
125
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
126 widget_layout_.setContentsMargins(0, 0, 0, 0);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
127 layout_.addWidget(&widget_);
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
128 }
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
129
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
130 {
316
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
131 connect(&button_box_, &QDialogButtonBox::accepted, this, &SettingsDialog::OnOK);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
132 connect(&button_box_, &QDialogButtonBox::rejected, this, &QDialog::reject);
180714442770 settings: clean up code
Paper <paper@paper.us.eu.org>
parents: 294
diff changeset
133 layout_.addWidget(&button_box_);
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 102
diff changeset
134 }
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
135 }