mirror-chatterino2/settingsdialogtab.cpp

41 lines
926 B
C++
Raw Normal View History

2017-01-01 18:43:52 +01:00
#include "settingsdialogtab.h"
#include "QPainter"
2017-01-02 03:02:32 +01:00
#include "QStyleOption"
#include "settingsdialog.h"
2017-01-01 18:43:52 +01:00
2017-01-02 03:02:32 +01:00
SettingsDialogTab::SettingsDialogTab(SettingsDialog* dialog, QString label, QString imageRes)
: 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
}
void SettingsDialogTab::paintEvent(QPaintEvent *)
{
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();
painter.drawText(QRect(a, 0, width() - a, height()), label, QTextOption(Qt::AlignLeft | Qt::AlignVCenter));
}
2017-01-02 03:02:32 +01:00
void SettingsDialogTab::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() != Qt::LeftButton) return;
dialog->select(this);
}