2017-01-18 21:30:23 +01:00
|
|
|
#include "widgets/settingsdialogtab.h"
|
|
|
|
#include "widgets/settingsdialog.h"
|
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QStyleOption>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
2017-01-01 18:43:52 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
SettingsDialogTab::SettingsDialogTab(SettingsDialog *dialog, QString label, QString imageRes)
|
|
|
|
: _label(label)
|
|
|
|
, _image(QImage(imageRes))
|
|
|
|
, _dialog(dialog)
|
|
|
|
, _selected(false)
|
2017-01-01 18:43:52 +01:00
|
|
|
{
|
2017-01-02 03:02:32 +01:00
|
|
|
setFixedHeight(32);
|
|
|
|
|
|
|
|
setCursor(QCursor(Qt::PointingHandCursor));
|
2017-02-02 00:25:57 +01:00
|
|
|
|
|
|
|
setStyleSheet("color: #FFF");
|
2017-01-01 18:43:52 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void SettingsDialogTab::setSelected(bool selected)
|
|
|
|
{
|
|
|
|
if (_selected == selected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_selected = selected;
|
|
|
|
emit selectedChanged(selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SettingsDialogTab::getSelected() const
|
|
|
|
{
|
|
|
|
return _selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *SettingsDialogTab::getWidget()
|
|
|
|
{
|
|
|
|
return _widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialogTab::setWidget(QWidget *widget)
|
|
|
|
{
|
|
|
|
_widget = widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
int a = (height() - _image.width()) / 2;
|
2017-01-01 18:43:52 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
painter.drawImage(a, a, _image);
|
2017-01-01 18:43:52 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
a = a + a + _image.width();
|
2017-01-01 18:43:52 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
painter.drawText(QRect(a, 0, width() - a, height()), _label,
|
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-04-12 17:46:44 +02:00
|
|
|
_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
|