Mercurial > minori
annotate src/gui/dialog/settings.cc @ 108:2004b41d4a59
*: huge commit
1. WORKING LOCALIZATION + translation for Spanish and British English
2. idk like 2 changes for the dark theme :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 05 Nov 2023 23:31:49 -0500 |
parents | b315f3759c56 |
children | 254b1d2b7096 |
rev | line source |
---|---|
9 | 1 #include "gui/dialog/settings.h" |
108 | 2 #include "core/session.h" |
46 | 3 #include "gui/widgets/sidebar.h" |
4 #include "gui/widgets/text.h" | |
9 | 5 #include <QDialogButtonBox> |
76 | 6 #include <QHBoxLayout> |
7 #include <QLabel> | |
9 | 8 #include <QStackedWidget> |
9 #include <QVBoxLayout> | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
10 #include <QWidget> |
108 | 11 #ifdef WIN32 |
12 #include "sys/win32/dark_theme.h" | |
13 #endif | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
14 |
9 | 15 SettingsPage::SettingsPage(QWidget* parent, QString title) : QWidget(parent) { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
16 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
17 page_title = new QLabel(title, this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
18 page_title->setWordWrap(false); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
19 page_title->setFrameShape(QFrame::Panel); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
20 page_title->setFrameShadow(QFrame::Sunken); |
36 | 21 |
22 QFont font(page_title->font()); | |
77 | 23 font.setPixelSize(12); |
36 | 24 font.setWeight(QFont::Bold); |
25 page_title->setFont(font); | |
26 | |
102 | 27 { |
28 QPalette pal = page_title->palette(); | |
29 pal.setColor(QPalette::Window, QColor(0xAB, 0xAB, 0xAB)); | |
30 pal.setColor(QPalette::WindowText, Qt::white); | |
31 page_title->setPalette(pal); | |
32 } | |
46 | 33 page_title->setAutoFillBackground(true); |
36 | 34 |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
35 page_title->setFixedHeight(23); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
36 page_title->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
37 page_title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); |
46 | 38 |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
39 tab_widget = new QTabWidget(this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
40 tab_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
41 |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
42 QVBoxLayout* layout = new QVBoxLayout(this); |
62 | 43 layout->setContentsMargins(0, 0, 0, 0); |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
44 layout->addWidget(page_title); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
45 layout->addWidget(tab_widget); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
46 } |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
47 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
48 void SettingsPage::SetTitle(QString title) { |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
49 page_title->setText(title); |
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::AddTab(QWidget* tab, QString title) { |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
53 tab_widget->addTab(tab, title); |
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::SaveInfo() { |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
57 // no-op... child classes will implement this |
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 SettingsDialog::OnOK() { |
7 | 61 for (int i = 0; i < stacked->count(); i++) { |
64 | 62 reinterpret_cast<SettingsPage*>(stacked->widget(i))->SaveInfo(); |
6
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 QDialog::accept(); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
65 } |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
66 |
108 | 67 void SettingsDialog::showEvent(QShowEvent* event) { |
68 QDialog::showEvent(event); | |
69 #ifdef WIN32 | |
70 win32::SetTitleBarsToBlack(session.config.theme.IsInDarkTheme()); | |
71 #endif | |
72 } | |
73 | |
9 | 74 SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
75 setFixedSize(755, 566); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
76 setWindowTitle(tr("Settings")); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
77 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); |
108 | 78 |
79 QVBoxLayout* full_layout = new QVBoxLayout(this); | |
80 | |
81 { | |
82 QWidget* widget = new QWidget(this); | |
83 widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | |
84 QHBoxLayout* layout = new QHBoxLayout(widget); | |
85 | |
86 { | |
87 sidebar = new SideBar(widget); | |
36 | 88 |
108 | 89 sidebar->setCurrentItem(sidebar->AddItem(tr("Services"), SideBar::CreateIcon(":/icons/24x24/globe.png"))); |
90 // sidebar->AddItem(tr("Library"), SideBar::CreateIcon(":/icons/24x24/inbox-film.png")); | |
91 sidebar->AddItem(tr("Application"), SideBar::CreateIcon(":/icons/24x24/application-sidebar-list.png")); | |
92 // sidebar->AddItem(tr("Recognition"), SideBar::CreateIcon(":/icons/24x24/question.png")); | |
93 // sidebar->AddItem(tr("Sharing"), SideBar::CreateIcon(":/icons/24x24/megaphone.png")); | |
94 // sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/24x24/feed.png")); | |
95 // sidebar->AddItem(tr("Advanced"), SideBar::CreateIcon(":/icons/24x24/gear.png")); | |
36 | 96 |
108 | 97 sidebar->setIconSize(QSize(24, 24)); |
98 sidebar->setFrameShape(QFrame::Box); | |
99 | |
100 QPalette pal(sidebar->palette()); | |
101 sidebar->SetBackgroundColor(pal.color(QPalette::Base)); | |
9 | 102 |
108 | 103 sidebar->setFixedWidth(158); |
104 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); | |
105 layout->addWidget(sidebar); | |
106 } | |
7 | 107 |
108 | 108 { |
109 stacked = new QStackedWidget(widget); | |
110 stacked->addWidget(new SettingsPageServices(stacked)); | |
111 stacked->addWidget(new SettingsPageApplication(stacked)); | |
112 stacked->setCurrentIndex(0); | |
113 | |
114 connect(sidebar, &QListWidget::currentRowChanged, stacked, &QStackedWidget::setCurrentIndex); | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
115 |
108 | 116 layout->addWidget(stacked); |
117 } | |
118 | |
119 layout->setContentsMargins(0, 0, 0, 0); | |
120 full_layout->addWidget(widget); | |
121 } | |
9 | 122 |
108 | 123 { |
124 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); | |
125 connect(button_box, &QDialogButtonBox::accepted, this, &SettingsDialog::OnOK); | |
126 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); | |
127 full_layout->addWidget(button_box); | |
128 } | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
129 } |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
130 |
9 | 131 #include "gui/dialog/moc_settings.cpp" |