comparison src/gui/dialog/settings.cc @ 81:9b2b41f83a5e

boring: mass rename to cc because this is a very unix-y project, it makes more sense to use the 'cc' extension
author Paper <mrpapersonic@gmail.com>
date Mon, 23 Oct 2023 12:07:27 -0400
parents src/gui/dialog/settings.cpp@6f7385bd334c
children b315f3759c56
comparison
equal deleted inserted replaced
80:825506f0e221 81:9b2b41f83a5e
1 #include "gui/dialog/settings.h"
2 #include "gui/widgets/sidebar.h"
3 #include "gui/widgets/text.h"
4 #include <QDialogButtonBox>
5 #include <QHBoxLayout>
6 #include <QLabel>
7 #include <QStackedWidget>
8 #include <QVBoxLayout>
9 #include <QWidget>
10
11 SettingsPage::SettingsPage(QWidget* parent, QString title) : QWidget(parent) {
12 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
13 page_title = new QLabel(title, this);
14 page_title->setWordWrap(false);
15 page_title->setFrameShape(QFrame::Panel);
16 page_title->setFrameShadow(QFrame::Sunken);
17
18 QFont font(page_title->font());
19 font.setPixelSize(12);
20 font.setWeight(QFont::Bold);
21 page_title->setFont(font);
22
23 QPalette pal = page_title->palette();
24 pal.setColor(QPalette::Window, QColor(0xAB, 0xAB, 0xAB));
25 pal.setColor(QPalette::WindowText, Qt::white);
26 page_title->setPalette(pal);
27 page_title->setAutoFillBackground(true);
28
29 page_title->setFixedHeight(23);
30 page_title->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
31 page_title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
32
33 tab_widget = new QTabWidget(this);
34 tab_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
35
36 QVBoxLayout* layout = new QVBoxLayout(this);
37 layout->setContentsMargins(0, 0, 0, 0);
38 layout->addWidget(page_title);
39 layout->addWidget(tab_widget);
40 }
41
42 void SettingsPage::SetTitle(QString title) {
43 page_title->setText(title);
44 }
45
46 void SettingsPage::AddTab(QWidget* tab, QString title) {
47 tab_widget->addTab(tab, title);
48 }
49
50 void SettingsPage::SaveInfo() {
51 // no-op... child classes will implement this
52 }
53
54 void SettingsDialog::OnOK() {
55 for (int i = 0; i < stacked->count(); i++) {
56 reinterpret_cast<SettingsPage*>(stacked->widget(i))->SaveInfo();
57 }
58 QDialog::accept();
59 }
60
61 SettingsDialog::SettingsDialog(QWidget* parent) : 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"), 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"));
75 sidebar->setIconSize(QSize(24, 24));
76 sidebar->setFrameShape(QFrame::Box);
77
78 QPalette pal(sidebar->palette());
79 sidebar->SetBackgroundColor(pal.color(QPalette::Base));
80
81 sidebar->setFixedWidth(158);
82 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
83
84 stacked = new QStackedWidget(this);
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);
90
91 QHBoxLayout* layout = new QHBoxLayout(widget);
92 layout->addWidget(sidebar);
93 layout->addWidget(stacked);
94 layout->setContentsMargins(0, 0, 0, 0);
95
96 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
97 connect(button_box, &QDialogButtonBox::accepted, this, &SettingsDialog::OnOK);
98 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
99
100 QVBoxLayout* buttons_layout = new QVBoxLayout(this);
101 buttons_layout->addWidget(widget);
102 buttons_layout->addWidget(button_box);
103 }
104
105 #include "gui/dialog/moc_settings.cpp"