Mercurial > minori
annotate src/gui/dialog/settings.cpp @ 77:6f7385bd334c
*: update
formatted all source files, no more subclassing QThread... many other
changes :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 06 Oct 2023 06:18:53 -0400 |
parents | 3364fadc8a36 |
children |
rev | line source |
---|---|
9 | 1 #include "gui/dialog/settings.h" |
46 | 2 #include "gui/widgets/sidebar.h" |
3 #include "gui/widgets/text.h" | |
9 | 4 #include <QDialogButtonBox> |
76 | 5 #include <QHBoxLayout> |
6 #include <QLabel> | |
9 | 7 #include <QStackedWidget> |
8 #include <QVBoxLayout> | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
9 #include <QWidget> |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
10 |
9 | 11 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
|
12 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
13 page_title = new QLabel(title, this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
14 page_title->setWordWrap(false); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
15 page_title->setFrameShape(QFrame::Panel); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
16 page_title->setFrameShadow(QFrame::Sunken); |
36 | 17 |
18 QFont font(page_title->font()); | |
77 | 19 font.setPixelSize(12); |
36 | 20 font.setWeight(QFont::Bold); |
21 page_title->setFont(font); | |
22 | |
46 | 23 QPalette pal = page_title->palette(); |
24 pal.setColor(QPalette::Window, QColor(0xAB, 0xAB, 0xAB)); | |
25 pal.setColor(QPalette::WindowText, Qt::white); | |
36 | 26 page_title->setPalette(pal); |
46 | 27 page_title->setAutoFillBackground(true); |
36 | 28 |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
29 page_title->setFixedHeight(23); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
30 page_title->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
31 page_title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); |
46 | 32 |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
33 tab_widget = new QTabWidget(this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
34 tab_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
35 |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
36 QVBoxLayout* layout = new QVBoxLayout(this); |
62 | 37 layout->setContentsMargins(0, 0, 0, 0); |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
38 layout->addWidget(page_title); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
39 layout->addWidget(tab_widget); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
40 } |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
41 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
42 void SettingsPage::SetTitle(QString title) { |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
43 page_title->setText(title); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
44 } |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
45 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
46 void SettingsPage::AddTab(QWidget* tab, QString title) { |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
47 tab_widget->addTab(tab, title); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
48 } |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
49 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
50 void SettingsPage::SaveInfo() { |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
51 // no-op... child classes will implement this |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
52 } |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
53 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
54 void SettingsDialog::OnOK() { |
7 | 55 for (int i = 0; i < stacked->count(); i++) { |
64 | 56 reinterpret_cast<SettingsPage*>(stacked->widget(i))->SaveInfo(); |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
57 } |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
58 QDialog::accept(); |
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 |
9 | 61 SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
62 setFixedSize(755, 566); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
63 setWindowTitle(tr("Settings")); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
64 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
65 QWidget* widget = new QWidget(this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
66 widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
67 sidebar = new SideBar(widget); |
9 | 68 sidebar->setCurrentItem(sidebar->AddItem(tr("Services"), SideBar::CreateIcon(":/icons/24x24/globe.png"))); |
69 // sidebar->AddItem(tr("Library"), SideBar::CreateIcon(":/icons/24x24/inbox-film.png")); | |
70 sidebar->AddItem(tr("Application"), SideBar::CreateIcon(":/icons/24x24/application-sidebar-list.png")); | |
71 // sidebar->AddItem(tr("Recognition"), SideBar::CreateIcon(":/icons/24x24/question.png")); | |
72 // sidebar->AddItem(tr("Sharing"), SideBar::CreateIcon(":/icons/24x24/megaphone.png")); | |
73 // sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/24x24/feed.png")); | |
74 // sidebar->AddItem(tr("Advanced"), SideBar::CreateIcon(":/icons/24x24/gear.png")); | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
75 sidebar->setIconSize(QSize(24, 24)); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
76 sidebar->setFrameShape(QFrame::Box); |
36 | 77 |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
78 QPalette pal(sidebar->palette()); |
69 | 79 sidebar->SetBackgroundColor(pal.color(QPalette::Base)); |
36 | 80 |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
81 sidebar->setFixedWidth(158); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
82 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
9 | 83 |
69 | 84 stacked = new QStackedWidget(this); |
7 | 85 stacked->addWidget(new SettingsPageServices(stacked)); |
86 stacked->addWidget(new SettingsPageApplication(stacked)); | |
87 stacked->setCurrentIndex(0); | |
88 | |
89 connect(sidebar, &QListWidget::currentRowChanged, stacked, &QStackedWidget::setCurrentIndex); | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
90 |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
91 QHBoxLayout* layout = new QHBoxLayout(widget); |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
92 layout->addWidget(sidebar); |
7 | 93 layout->addWidget(stacked); |
62 | 94 layout->setContentsMargins(0, 0, 0, 0); |
9 | 95 |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
96 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
97 connect(button_box, &QDialogButtonBox::accepted, this, &SettingsDialog::OnOK); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
98 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
99 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
100 QVBoxLayout* buttons_layout = new QVBoxLayout(this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
101 buttons_layout->addWidget(widget); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
102 buttons_layout->addWidget(button_box); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
103 } |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
104 |
9 | 105 #include "gui/dialog/moc_settings.cpp" |