mirror-chatterino2/widgets/settingsdialogtab.cpp

52 lines
1 KiB
C++
Raw Normal View History

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-01-11 18:52:09 +01:00
SettingsDialogTab::SettingsDialogTab(SettingsDialog *dialog, QString label,
QString imageRes)
2017-01-02 03:02:32 +01:00
: image(QImage(imageRes))
2017-01-01 18:43:52 +01:00
{
2017-01-02 03:02:32 +01:00
this->dialog = dialog;
2017-01-01 18:43:52 +01:00
this->label = label;
2017-01-02 03:02:32 +01:00
setFixedHeight(32);
setCursor(QCursor(Qt::PointingHandCursor));
2017-01-01 18:43:52 +01:00
}
2017-01-11 18:52:09 +01: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);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
2017-01-01 18:43:52 +01:00
int a = (height() - image.width()) / 2;
painter.drawImage(a, a, image);
a = a + a + image.width();
2017-01-11 18:52:09 +01:00
painter.drawText(QRect(a, 0, width() - a, height()), label,
QTextOption(Qt::AlignLeft | Qt::AlignVCenter));
2017-01-01 18:43:52 +01:00
}
2017-01-02 03:02:32 +01:00
2017-01-11 18:52:09 +01:00
void
SettingsDialogTab::mouseReleaseEvent(QMouseEvent *event)
2017-01-02 03:02:32 +01:00
{
2017-01-11 18:52:09 +01:00
if (event->button() != Qt::LeftButton)
return;
2017-01-02 03:02:32 +01:00
dialog->select(this);
}
2017-01-18 21:30:23 +01:00
}
}