From 4ccbc8d4e49bf26e43e6e7c99f53e9bdd61d39c6 Mon Sep 17 00:00:00 2001 From: fourtf Date: Mon, 2 Jan 2017 03:02:32 +0100 Subject: [PATCH] added settingsdialog --- notebook.cpp | 3 +- qss/settings.qss | 15 ++++++ resources.qrc | 5 +- settingsdialog.cpp | 116 +++++++++++++++++++++++++++++++++++++++++- settingsdialog.h | 27 ++++++++-- settingsdialogtab.cpp | 24 +++++++-- settingsdialogtab.h | 30 ++++++++++- 7 files changed, 206 insertions(+), 14 deletions(-) create mode 100644 qss/settings.qss diff --git a/notebook.cpp b/notebook.cpp index 3d61c4f9e..644d80a95 100644 --- a/notebook.cpp +++ b/notebook.cpp @@ -8,6 +8,7 @@ #include "QFormLayout" #include "colorscheme.h" #include "dialog.h" +#include "settingsdialog.h" Notebook::Notebook(QWidget *parent) : QWidget(parent), @@ -27,7 +28,7 @@ Notebook::Notebook(QWidget *parent) void Notebook::settingsButtonClicked() { - auto a = new Dialog(); + SettingsDialog* a = new SettingsDialog(); a->show(); } diff --git a/qss/settings.qss b/qss/settings.qss new file mode 100644 index 000000000..eb1e52820 --- /dev/null +++ b/qss/settings.qss @@ -0,0 +1,15 @@ +#tabWidget { + background-color: #333; +} + +SettingsDialogTab { + color: #FFF; +} + +SettingsDialogTab:hover { + border: 1px solid grey; +} + +QLabel { + color: white; +} diff --git a/resources.qrc b/resources.qrc index f9524c74f..f6c92dc7f 100644 --- a/resources.qrc +++ b/resources.qrc @@ -1,13 +1,13 @@ - + images/AppearanceEditorPart_16x.png images/BrowserLink_16x.png images/cheer1.png images/cheer100.png images/cheer1000.png - images/cheer5000.png images/cheer10000.png images/cheer100000.png + images/cheer5000.png images/CopyLongTextToClipboard_16x.png images/CustomActionEditor_16x.png images/Emoji_Color_1F60A_19.png @@ -17,5 +17,6 @@ images/settings.png images/tool_moreCollapser_off16.png images/twitchprime_bg.png + qss/settings.qss diff --git a/settingsdialog.cpp b/settingsdialog.cpp index 203f29125..bf6badb48 100644 --- a/settingsdialog.cpp +++ b/settingsdialog.cpp @@ -1,7 +1,121 @@ #include "settingsdialog.h" +#include "settingsdialogtab.h" + +#include "QPalette" +#include "QFile" +#include "QResource" +#include "QLabel" +#include "QFormLayout" +#include "QComboBox" SettingsDialog::SettingsDialog() - : tabs(this) { + QFile file(":/qss/settings.qss"); + file.open(QFile::ReadOnly); + QString styleSheet = QLatin1String(file.readAll()); + setStyleSheet(styleSheet); + QPalette palette; + palette.setColor(QPalette::Background, QColor("#444")); + setPalette(palette); + + pageStack.setObjectName("pages"); + + setLayout(&vbox); + + vbox.addLayout(&hbox); + + vbox.addWidget(&buttonBox); + + auto tabWidget = new QWidget(); + tabWidget->setObjectName("tabWidget"); + + tabWidget->setLayout(&tabs); + tabWidget->setFixedWidth(200); + + hbox.addWidget(tabWidget); + hbox.addLayout(&pageStack); + + buttonBox.addButton(&okButton, QDialogButtonBox::ButtonRole::AcceptRole); + buttonBox.addButton(&cancelButton, QDialogButtonBox::ButtonRole::RejectRole); + okButton.setText("OK"); + cancelButton.setText("Cancel"); + + resize(600, 500); + + addTabs(); +} + +void SettingsDialog::addTabs() +{ + QVBoxLayout* vbox; + + // Appearance + vbox = new QVBoxLayout(); + + { + auto form = new QFormLayout(); + auto combo = new QComboBox(); + auto slider = new QSlider(Qt::Horizontal); + auto font = new QPushButton("select"); + + form->addRow("Theme:", combo); + form->addRow("Theme Hue:", slider); + form->addRow("Font:", font); + + vbox->addLayout(form); + } + + vbox->addStretch(1); + + addTab(vbox, "Appearance", ":/images/AppearanceEditorPart_16x.png"); + + // Commands + vbox = new QVBoxLayout(); + + vbox->addWidget(new QLabel()); + + vbox->addStretch(1); + + addTab(vbox, "Commands", ":/images/CustomActionEditor_16x.png"); + + // Add stretch + tabs.addStretch(1); +} + +void SettingsDialog::addTab(QLayout* layout, QString title, QString imageRes) +{ + auto widget = new QWidget(); + + widget->setLayout(layout); + + auto tab = new SettingsDialogTab(this, title, imageRes); + + tab->widget = widget; + + tabs.addWidget(tab, 0, Qt::AlignTop); + + pageStack.addWidget(widget); + + if (tabs.count() == 1) + { + select(tab); + } +} + +void SettingsDialog::select(SettingsDialogTab* tab) +{ + pageStack.setCurrentWidget(tab->widget); + + if (selectedTab != NULL) + { + selectedTab->setSelected(false); + selectedTab->setStyleSheet(""); + } + + tab->setSelected(true); + tab->setStyleSheet("background: #F00;" + "background: qlineargradient( x1:0 y1:0, x2:1 y2:0, stop:0 #333, stop:1 #555);" + "border-right: none;"); + selectedTab = tab; } diff --git a/settingsdialog.h b/settingsdialog.h index f5413de4f..59cc79407 100644 --- a/settingsdialog.h +++ b/settingsdialog.h @@ -4,18 +4,35 @@ #include "QWidget" #include "QMainWindow" #include "QHBoxLayout" +#include "QVBoxLayout" #include "QListView" +#include "QButtonGroup" +#include "QPushButton" +#include "QDialogButtonBox" +#include "QStackedLayout" +#include "settingsdialogtab.h" -class SettingsDialog : QMainWindow +class SettingsDialog : public QWidget { public: SettingsDialog(); -private: - QListView tabs; - QHBoxLayout hbox; + void select(SettingsDialogTab* tab); - void addTab(QWidget* widget, QString title, QString imageRes); +private: + QVBoxLayout tabs; + QVBoxLayout vbox; + QHBoxLayout hbox; + QStackedLayout pageStack; + QDialogButtonBox buttonBox; + QPushButton okButton; + QPushButton cancelButton; + + void addTab(QLayout* layout, QString title, QString imageRes); + + void addTabs(); + + SettingsDialogTab* selectedTab = NULL; }; #endif // SETTINGSDIALOG_H diff --git a/settingsdialogtab.cpp b/settingsdialogtab.cpp index 3ac934169..e86b0b906 100644 --- a/settingsdialogtab.cpp +++ b/settingsdialogtab.cpp @@ -1,17 +1,28 @@ #include "settingsdialogtab.h" #include "QPainter" +#include "QStyleOption" +#include "settingsdialog.h" -SettingsDialogTab::SettingsDialogTab(QWidget *parent, QString label, QImage& image) - : QWidget(parent), - image(image) +SettingsDialogTab::SettingsDialogTab(SettingsDialog* dialog, QString label, QString imageRes) + : image(QImage(imageRes)) { + this->dialog = dialog; + this->label = label; + setFixedHeight(32); + + setCursor(QCursor(Qt::PointingHandCursor)); } void SettingsDialogTab::paintEvent(QPaintEvent *) { QPainter painter(this); + QStyleOption opt; + opt.init(this); + + style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); + int a = (height() - image.width()) / 2; painter.drawImage(a, a, image); @@ -20,3 +31,10 @@ void SettingsDialogTab::paintEvent(QPaintEvent *) painter.drawText(QRect(a, 0, width() - a, height()), label, QTextOption(Qt::AlignLeft | Qt::AlignVCenter)); } + +void SettingsDialogTab::mouseReleaseEvent(QMouseEvent *event) +{ + if (event->button() != Qt::LeftButton) return; + + dialog->select(this); +} diff --git a/settingsdialogtab.h b/settingsdialogtab.h index e928f758b..8d28f5b70 100644 --- a/settingsdialogtab.h +++ b/settingsdialogtab.h @@ -4,16 +4,42 @@ #include #include "QPaintEvent" +class SettingsDialog; + class SettingsDialogTab : public QWidget { Q_OBJECT + Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectedChanged) + public: - SettingsDialogTab(QWidget *parent, QString label, QImage& image); + SettingsDialogTab(SettingsDialog* dialog, QString label, QString imageRes); + + void setSelected(bool selected) + { + if (selected == m_selected) return; + + m_selected = selected; + emit selectedChanged(selected); + } + + bool selected() const + { return m_selected; } + + QWidget* widget; + +signals: + void selectedChanged(bool); private: void paintEvent(QPaintEvent *); + void mouseReleaseEvent(QMouseEvent *event); + QString label; - QImage& image; + QImage image; + + SettingsDialog* dialog = NULL; + + bool m_selected = false; }; #endif // SETTINGSNOTEBOOKTAB_H