mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
added settingsdialog
This commit is contained in:
parent
a75cfa61f7
commit
4ccbc8d4e4
7 changed files with 206 additions and 14 deletions
|
@ -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();
|
||||
}
|
||||
|
|
15
qss/settings.qss
Normal file
15
qss/settings.qss
Normal file
|
@ -0,0 +1,15 @@
|
|||
#tabWidget {
|
||||
background-color: #333;
|
||||
}
|
||||
|
||||
SettingsDialogTab {
|
||||
color: #FFF;
|
||||
}
|
||||
|
||||
SettingsDialogTab:hover {
|
||||
border: 1px solid grey;
|
||||
}
|
||||
|
||||
QLabel {
|
||||
color: white;
|
||||
}
|
|
@ -1,13 +1,13 @@
|
|||
<RCC>
|
||||
<qresource prefix="/images">
|
||||
<qresource prefix="/">
|
||||
<file>images/AppearanceEditorPart_16x.png</file>
|
||||
<file>images/BrowserLink_16x.png</file>
|
||||
<file>images/cheer1.png</file>
|
||||
<file>images/cheer100.png</file>
|
||||
<file>images/cheer1000.png</file>
|
||||
<file>images/cheer5000.png</file>
|
||||
<file>images/cheer10000.png</file>
|
||||
<file>images/cheer100000.png</file>
|
||||
<file>images/cheer5000.png</file>
|
||||
<file>images/CopyLongTextToClipboard_16x.png</file>
|
||||
<file>images/CustomActionEditor_16x.png</file>
|
||||
<file>images/Emoji_Color_1F60A_19.png</file>
|
||||
|
@ -17,5 +17,6 @@
|
|||
<file>images/settings.png</file>
|
||||
<file>images/tool_moreCollapser_off16.png</file>
|
||||
<file>images/twitchprime_bg.png</file>
|
||||
<file>qss/settings.qss</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -4,16 +4,42 @@
|
|||
#include <QWidget>
|
||||
#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
|
||||
|
|
Loading…
Reference in a new issue