Mercurial > minori
comparison src/gui/dialog/settings.cpp @ 9:5c0397762b53
INCOMPLETE: megacommit :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 10 Sep 2023 03:59:16 -0400 |
parents | src/dialog/settings.cpp@07a9095eaeed |
children | cde8f67a7c7d |
comparison
equal
deleted
inserted
replaced
8:b1f73678ef61 | 9:5c0397762b53 |
---|---|
1 #include "gui/dialog/settings.h" | |
2 #include "gui/sidebar.h" | |
3 #include "gui/ui_utils.h" | |
4 #include <QComboBox> | |
5 #include <QDialogButtonBox> | |
6 #include <QGroupBox> | |
7 #include <QHBoxLayout> | |
8 #include <QPlainTextDocumentLayout> | |
9 #include <QPlainTextEdit> | |
10 #include <QStackedWidget> | |
11 #include <QVBoxLayout> | |
12 #include <QWidget> | |
13 | |
14 SettingsPage::SettingsPage(QWidget* parent, QString title) : QWidget(parent) { | |
15 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | |
16 page_title = new QLabel(title, this); | |
17 page_title->setWordWrap(false); | |
18 page_title->setFrameShape(QFrame::Panel); | |
19 page_title->setFrameShadow(QFrame::Sunken); | |
20 page_title->setStyleSheet( | |
21 "QLabel { font-size: 10pt; font-weight: bold; background-color: #ABABAB; color: white; }"); | |
22 page_title->setFixedHeight(23); | |
23 page_title->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); | |
24 page_title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); | |
25 tab_widget = new QTabWidget(this); | |
26 tab_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | |
27 | |
28 QVBoxLayout* layout = new QVBoxLayout; | |
29 layout->setMargin(0); | |
30 layout->addWidget(page_title); | |
31 layout->addWidget(tab_widget); | |
32 setLayout(layout); | |
33 } | |
34 | |
35 void SettingsPage::SetTitle(QString title) { | |
36 page_title->setText(title); | |
37 } | |
38 | |
39 void SettingsPage::AddTab(QWidget* tab, QString title) { | |
40 tab_widget->addTab(tab, title); | |
41 } | |
42 | |
43 void SettingsPage::SaveInfo() { | |
44 // no-op... child classes will implement this | |
45 } | |
46 | |
47 void SettingsDialog::OnOK() { | |
48 QStackedWidget* stacked = (QStackedWidget*)layout->itemAt(1)->widget(); | |
49 for (int i = 0; i < stacked->count(); i++) { | |
50 ((SettingsPage*)stacked->widget(i))->SaveInfo(); | |
51 } | |
52 QDialog::accept(); | |
53 } | |
54 | |
55 SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) { | |
56 setFixedSize(755, 566); | |
57 setWindowTitle(tr("Settings")); | |
58 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); | |
59 QWidget* widget = new QWidget(this); | |
60 widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | |
61 sidebar = new SideBar(widget); | |
62 sidebar->setCurrentItem(sidebar->AddItem(tr("Services"), SideBar::CreateIcon(":/icons/24x24/globe.png"))); | |
63 // sidebar->AddItem(tr("Library"), SideBar::CreateIcon(":/icons/24x24/inbox-film.png")); | |
64 sidebar->AddItem(tr("Application"), SideBar::CreateIcon(":/icons/24x24/application-sidebar-list.png")); | |
65 // sidebar->AddItem(tr("Recognition"), SideBar::CreateIcon(":/icons/24x24/question.png")); | |
66 // sidebar->AddItem(tr("Sharing"), SideBar::CreateIcon(":/icons/24x24/megaphone.png")); | |
67 // sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/24x24/feed.png")); | |
68 // sidebar->AddItem(tr("Advanced"), SideBar::CreateIcon(":/icons/24x24/gear.png")); | |
69 sidebar->setIconSize(QSize(24, 24)); | |
70 sidebar->setFrameShape(QFrame::Box); | |
71 sidebar->setStyleSheet("QListWidget { background-color: white; font-size: 12px; }"); | |
72 sidebar->setFixedWidth(158); | |
73 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); | |
74 | |
75 QStackedWidget* stacked = new QStackedWidget; | |
76 stacked->addWidget(new SettingsPageServices(stacked)); | |
77 stacked->addWidget(new SettingsPageApplication(stacked)); | |
78 stacked->setCurrentIndex(0); | |
79 | |
80 connect(sidebar, &QListWidget::currentRowChanged, stacked, &QStackedWidget::setCurrentIndex); | |
81 | |
82 layout = new QHBoxLayout; | |
83 layout->addWidget(sidebar); | |
84 layout->addWidget(stacked); | |
85 layout->setMargin(0); | |
86 widget->setLayout(layout); | |
87 | |
88 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); | |
89 connect(button_box, &QDialogButtonBox::accepted, this, &SettingsDialog::OnOK); | |
90 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); | |
91 | |
92 QVBoxLayout* buttons_layout = new QVBoxLayout(this); | |
93 buttons_layout->addWidget(widget); | |
94 buttons_layout->addWidget(button_box); | |
95 setLayout(buttons_layout); | |
96 } | |
97 | |
98 #include "gui/dialog/moc_settings.cpp" |