2017-11-12 17:21:50 +01:00
|
|
|
#include "widgets/helper/settingsdialogtab.hpp"
|
2017-06-11 09:31:45 +02:00
|
|
|
#include "widgets/settingsdialog.hpp"
|
2017-01-18 21:30:23 +01:00
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QStyleOption>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
2017-01-01 18:43:52 +01:00
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
SettingsDialogTab::SettingsDialogTab(SettingsDialog *_dialog, settingspages::SettingsPage *_page,
|
2017-07-02 12:36:50 +02:00
|
|
|
QString imageFileName)
|
|
|
|
: dialog(_dialog)
|
2018-01-12 23:09:05 +01:00
|
|
|
, page(_page)
|
2017-01-01 18:43:52 +01:00
|
|
|
{
|
2018-01-12 23:09:05 +01:00
|
|
|
this->ui.labelText = page->getName();
|
2018-01-02 03:44:52 +01:00
|
|
|
this->ui.icon.addFile(imageFileName);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
this->setCursor(QCursor(Qt::PointingHandCursor));
|
|
|
|
|
|
|
|
this->setStyleSheet("color: #FFF");
|
2017-01-01 18:43:52 +01:00
|
|
|
}
|
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
void SettingsDialogTab::setSelected(bool _selected)
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2017-07-02 12:36:50 +02:00
|
|
|
if (this->selected == _selected) {
|
2017-04-12 17:46:44 +02:00
|
|
|
return;
|
2017-07-02 12:36:50 +02:00
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-12-18 00:54:17 +01:00
|
|
|
// height: <checkbox-size>px;
|
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
this->selected = _selected;
|
2017-04-12 17:46:44 +02:00
|
|
|
emit selectedChanged(selected);
|
|
|
|
}
|
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
settingspages::SettingsPage *SettingsDialogTab::getSettingsPage()
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2018-01-12 23:09:05 +01:00
|
|
|
return this->page;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialogTab::paintEvent(QPaintEvent *)
|
2017-01-01 18:43:52 +01:00
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
|
2017-01-02 03:02:32 +01:00
|
|
|
QStyleOption opt;
|
|
|
|
opt.init(this);
|
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
this->style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2018-01-02 03:44:52 +01:00
|
|
|
int a = (this->height() - 20) / 2;
|
2018-01-12 23:09:05 +01:00
|
|
|
QPixmap pixmap = this->ui.icon.pixmap(QSize(20, 20));
|
2017-01-01 18:43:52 +01:00
|
|
|
|
2018-01-02 03:44:52 +01:00
|
|
|
painter.drawPixmap(0, a, pixmap);
|
|
|
|
|
|
|
|
a = a + a + 20;
|
2017-01-01 18:43:52 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
painter.drawText(QRect(a, 0, width() - a, height()), this->ui.labelText,
|
2017-01-11 18:52:09 +01:00
|
|
|
QTextOption(Qt::AlignLeft | Qt::AlignVCenter));
|
2017-01-01 18:43:52 +01:00
|
|
|
}
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-04-14 17:47:28 +02:00
|
|
|
void SettingsDialogTab::mousePressEvent(QMouseEvent *event)
|
2017-01-02 03:02:32 +01:00
|
|
|
{
|
2017-04-14 17:47:28 +02:00
|
|
|
if (event->button() != Qt::LeftButton) {
|
2017-01-11 18:52:09 +01:00
|
|
|
return;
|
2017-04-14 17:47:28 +02:00
|
|
|
}
|
2017-01-02 03:02:32 +01:00
|
|
|
|
2017-07-02 12:36:50 +02:00
|
|
|
this->dialog->select(this);
|
2017-01-02 03:02:32 +01:00
|
|
|
}
|
2017-06-07 10:09:24 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|