Mercurial > minori
annotate src/gui/dialog/settings.cpp @ 65:26721c28bf22
*: avoid usage of (to|from)StdString
in Qt5 (and probably Qt6 as well) these functions are only
available (or even usable) if Qt and Minori were built with the
*same standard headers*, which may not be the case in some
circumstances. hence, we'll use our own conversion functions,
which we probably should use anyway.
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 01 Oct 2023 23:26:35 -0400 |
parents | fe719c109dbc |
children | 2417121d894e |
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 <QComboBox> |
5 #include <QDialogButtonBox> | |
6 #include <QGroupBox> | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
7 #include <QHBoxLayout> |
9 | 8 #include <QPlainTextDocumentLayout> |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
9 #include <QPlainTextEdit> |
9 | 10 #include <QStackedWidget> |
11 #include <QVBoxLayout> | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
12 #include <QWidget> |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
13 |
9 | 14 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
|
15 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
16 page_title = new QLabel(title, this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
17 page_title->setWordWrap(false); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
18 page_title->setFrameShape(QFrame::Panel); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
19 page_title->setFrameShadow(QFrame::Sunken); |
36 | 20 |
21 QFont font(page_title->font()); | |
22 font.setPointSize(10); | |
23 font.setWeight(QFont::Bold); | |
24 page_title->setFont(font); | |
25 | |
46 | 26 QPalette pal = page_title->palette(); |
27 pal.setColor(QPalette::Window, QColor(0xAB, 0xAB, 0xAB)); | |
28 pal.setColor(QPalette::WindowText, Qt::white); | |
36 | 29 page_title->setPalette(pal); |
46 | 30 page_title->setAutoFillBackground(true); |
36 | 31 |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
32 page_title->setFixedHeight(23); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
33 page_title->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
34 page_title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); |
46 | 35 |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
36 tab_widget = new QTabWidget(this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
37 tab_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
38 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
39 QVBoxLayout* layout = new QVBoxLayout; |
62 | 40 layout->setContentsMargins(0, 0, 0, 0); |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
41 layout->addWidget(page_title); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
42 layout->addWidget(tab_widget); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
43 setLayout(layout); |
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::SetTitle(QString title) { |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
47 page_title->setText(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::AddTab(QWidget* tab, QString title) { |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
51 tab_widget->addTab(tab, title); |
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 SettingsPage::SaveInfo() { |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
55 // no-op... child classes will implement this |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
56 } |
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 void SettingsDialog::OnOK() { |
64 | 59 QStackedWidget* stacked = reinterpret_cast<QStackedWidget*>(layout->itemAt(1)->widget()); |
7 | 60 for (int i = 0; i < stacked->count(); i++) { |
64 | 61 reinterpret_cast<SettingsPage*>(stacked->widget(i))->SaveInfo(); |
6
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 QDialog::accept(); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
64 } |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
65 |
9 | 66 SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
67 setFixedSize(755, 566); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
68 setWindowTitle(tr("Settings")); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
69 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
|
70 QWidget* widget = new QWidget(this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
71 widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
72 sidebar = new SideBar(widget); |
9 | 73 sidebar->setCurrentItem(sidebar->AddItem(tr("Services"), SideBar::CreateIcon(":/icons/24x24/globe.png"))); |
74 // sidebar->AddItem(tr("Library"), SideBar::CreateIcon(":/icons/24x24/inbox-film.png")); | |
75 sidebar->AddItem(tr("Application"), SideBar::CreateIcon(":/icons/24x24/application-sidebar-list.png")); | |
76 // sidebar->AddItem(tr("Recognition"), SideBar::CreateIcon(":/icons/24x24/question.png")); | |
77 // sidebar->AddItem(tr("Sharing"), SideBar::CreateIcon(":/icons/24x24/megaphone.png")); | |
78 // sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/24x24/feed.png")); | |
79 // 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
|
80 sidebar->setIconSize(QSize(24, 24)); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
81 sidebar->setFrameShape(QFrame::Box); |
36 | 82 |
83 QFont font(sidebar->font()); | |
84 font.setPointSize(9); | |
85 sidebar->setFont(font); | |
86 | |
87 QPalette pal; | |
88 pal.setColor(QPalette::Window, Qt::white); | |
89 sidebar->setPalette(pal); | |
90 | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
91 sidebar->setFixedWidth(158); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
92 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
9 | 93 |
7 | 94 QStackedWidget* stacked = new QStackedWidget; |
95 stacked->addWidget(new SettingsPageServices(stacked)); | |
96 stacked->addWidget(new SettingsPageApplication(stacked)); | |
97 stacked->setCurrentIndex(0); | |
98 | |
99 connect(sidebar, &QListWidget::currentRowChanged, stacked, &QStackedWidget::setCurrentIndex); | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
100 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
101 layout = new QHBoxLayout; |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
102 layout->addWidget(sidebar); |
7 | 103 layout->addWidget(stacked); |
62 | 104 layout->setContentsMargins(0, 0, 0, 0); |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
105 widget->setLayout(layout); |
9 | 106 |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
107 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
|
108 connect(button_box, &QDialogButtonBox::accepted, this, &SettingsDialog::OnOK); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
109 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
110 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
111 QVBoxLayout* buttons_layout = new QVBoxLayout(this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
112 buttons_layout->addWidget(widget); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
113 buttons_layout->addWidget(button_box); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
114 setLayout(buttons_layout); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
115 } |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
116 |
9 | 117 #include "gui/dialog/moc_settings.cpp" |