comparison src/dialog/settings.cpp @ 6:1d82f6e04d7d

Update: add first parts to the settings dialog
author Paper <mrpapersonic@gmail.com>
date Wed, 16 Aug 2023 00:49:17 -0400
parents
children 07a9095eaeed
comparison
equal deleted inserted replaced
5:51ae25154b70 6:1d82f6e04d7d
1 #include <QHBoxLayout>
2 #include <QVBoxLayout>
3 #include <QDialogButtonBox>
4 #include <QPlainTextEdit>
5 #include <QPlainTextDocumentLayout>
6 #include <QComboBox>
7 #include <QGroupBox>
8 #include <QWidget>
9 #include <QTextDocument>
10 #include "settings.h"
11 #include "sidebar.h"
12 #include "ui_utils.h"
13
14 SettingsPage::SettingsPage(QWidget* parent, QString title)
15 : QWidget(parent) {
16 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
17 page_title = new QLabel(title, this);
18 page_title->setWordWrap(false);
19 page_title->setFrameShape(QFrame::Panel);
20 page_title->setFrameShadow(QFrame::Sunken);
21 page_title->setStyleSheet("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::OnSidebar(QListWidgetItem* item) {
48 layout->itemAt(1)->widget()->setVisible(false); // old widget
49 layout->replaceWidget(layout->itemAt(1)->widget(), pages[item->listWidget()->row(item)], Qt::FindDirectChildrenOnly);
50 pages[item->listWidget()->row(item)]->setVisible(true); // new widget
51 }
52
53 void SettingsDialog::OnOK() {
54 for (const auto& page : pages) {
55 page->SaveInfo();
56 }
57 QDialog::accept();
58 }
59
60 SettingsDialog::SettingsDialog(QWidget* parent)
61 : QDialog(parent) {
62 setFixedSize(755, 566);
63 setWindowTitle(tr("Settings"));
64 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
65 QWidget* widget = new QWidget(this);
66 widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
67 sidebar = new SideBar(widget);
68 sidebar->setCurrentItem(sidebar->AddItem(tr("Services"), UiUtils::CreateSideBarIcon(":/icons/24x24/globe.png")));
69 //sidebar->AddItem(tr("Library"), UiUtils::CreateSideBarIcon(":/icons/24x24/inbox-film.png"));
70 sidebar->AddItem(tr("Application"), UiUtils::CreateSideBarIcon(":/icons/24x24/application-sidebar-list.png"));
71 //sidebar->AddItem(tr("Recognition"), UiUtils::CreateSideBarIcon(":/icons/24x24/question.png"));
72 //sidebar->AddItem(tr("Sharing"), UiUtils::CreateSideBarIcon(":/icons/24x24/megaphone.png"));
73 //sidebar->AddItem(tr("Torrents"), UiUtils::CreateSideBarIcon(":/icons/24x24/feed.png"));
74 //sidebar->AddItem(tr("Advanced"), UiUtils::CreateSideBarIcon(":/icons/24x24/gear.png"));
75 sidebar->setIconSize(QSize(24, 24));
76 sidebar->setFrameShape(QFrame::Box);
77 sidebar->setStyleSheet("QListWidget { background-color: white; font-size: 12px; }");
78 sidebar->setFixedWidth(158);
79 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
80 connect(sidebar, &QListWidget::itemActivated, this, &SettingsDialog::OnSidebar);
81
82 SettingsPageServices* services_page = new SettingsPageServices(this);
83 pages.push_back(services_page);
84 SettingsPageApplication* application_page = new SettingsPageApplication(this);
85 application_page->setVisible(false);
86 pages.push_back(application_page);
87
88 layout = new QHBoxLayout;
89 layout->addWidget(sidebar);
90 layout->addWidget(services_page);
91 layout->setMargin(0);
92 widget->setLayout(layout);
93
94 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
95 connect(button_box, &QDialogButtonBox::accepted, this, &SettingsDialog::OnOK);
96 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
97
98 QVBoxLayout* buttons_layout = new QVBoxLayout(this);
99 buttons_layout->addWidget(widget);
100 buttons_layout->addWidget(button_box);
101 setLayout(buttons_layout);
102 }
103
104 #include "moc_settings.cpp"