2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/helper/SettingsDialogTab.hpp"
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
|
2018-06-26 15:11:45 +02:00
|
|
|
#include "widgets/dialogs/SettingsDialog.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/settingspages/SettingsPage.hpp"
|
2017-01-18 21:30:23 +01:00
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QStyleOption>
|
|
|
|
|
|
|
|
namespace chatterino {
|
2017-01-01 18:43:52 +01:00
|
|
|
|
2018-06-26 17:06:17 +02:00
|
|
|
SettingsDialogTab::SettingsDialogTab(SettingsDialog *_dialog,
|
2020-02-21 01:59:58 +01:00
|
|
|
std::function<SettingsPage *()> _lazyPage,
|
|
|
|
const QString &name, QString imageFileName,
|
2020-02-21 01:17:22 +01:00
|
|
|
SettingsTabId id)
|
2018-01-27 21:51:08 +01:00
|
|
|
: BaseWidget(_dialog)
|
2018-07-06 19:23:47 +02:00
|
|
|
, dialog_(_dialog)
|
2020-02-21 01:59:58 +01:00
|
|
|
, lazyPage_(std::move(_lazyPage))
|
2020-02-21 01:17:22 +01:00
|
|
|
, id_(id)
|
2020-02-21 01:59:58 +01:00
|
|
|
, name_(name)
|
2017-01-01 18:43:52 +01:00
|
|
|
{
|
2020-02-21 01:59:58 +01:00
|
|
|
this->ui_.labelText = name;
|
2018-07-06 19:23:47 +02: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
|
|
|
{
|
2018-07-06 19:23:47 +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;
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->selected_ = _selected;
|
|
|
|
emit selectedChanged(selected_);
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2020-02-21 00:46:19 +01:00
|
|
|
SettingsPage *SettingsDialogTab::page()
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2020-02-21 01:59:58 +01:00
|
|
|
if (this->page_)
|
2024-01-14 17:54:52 +01:00
|
|
|
{
|
2020-02-21 01:59:58 +01:00
|
|
|
return this->page_;
|
2024-01-14 17:54:52 +01:00
|
|
|
}
|
2020-02-21 01:59:58 +01:00
|
|
|
|
|
|
|
this->page_ = this->lazyPage_();
|
|
|
|
this->page_->setTab(this);
|
2018-07-06 19:23:47 +02: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;
|
2023-02-19 20:19:18 +01:00
|
|
|
opt.initFrom(this);
|
2017-01-02 03:02:32 +01:00
|
|
|
|
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
|
|
|
|
2022-04-30 12:04:45 +02:00
|
|
|
int iconSize = 20 * this->scale();
|
|
|
|
int pad = (this->height() - iconSize) / 2;
|
2018-07-06 19:23:47 +02:00
|
|
|
QPixmap pixmap = this->ui_.icon.pixmap(
|
2022-04-30 12:04:45 +02:00
|
|
|
QSize(this->height() - pad * 2, this->height() - pad * 2));
|
2017-01-01 18:43:52 +01:00
|
|
|
|
2022-04-30 12:04:45 +02:00
|
|
|
painter.drawPixmap(pad, pad, pixmap);
|
2018-01-02 03:44:52 +01:00
|
|
|
|
2022-04-30 12:04:45 +02:00
|
|
|
pad = (3 * pad) + iconSize;
|
2017-01-01 18:43:52 +01:00
|
|
|
|
2022-04-30 12:04:45 +02:00
|
|
|
this->style()->drawItemText(&painter,
|
|
|
|
QRect(pad, 0, width() - pad, height()),
|
2020-10-23 09:32:45 +02:00
|
|
|
Qt::AlignLeft | Qt::AlignVCenter,
|
|
|
|
this->palette(), false, this->ui_.labelText);
|
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
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->dialog_->selectTab(this);
|
2019-09-02 18:59:37 +02:00
|
|
|
|
|
|
|
this->setFocus();
|
2017-01-02 03:02:32 +01:00
|
|
|
}
|
2017-06-07 10:09:24 +02:00
|
|
|
|
2020-02-21 01:59:58 +01:00
|
|
|
const QString &SettingsDialogTab::name() const
|
|
|
|
{
|
|
|
|
return name_;
|
|
|
|
}
|
|
|
|
|
2020-02-21 01:17:22 +01:00
|
|
|
SettingsTabId SettingsDialogTab::id() const
|
|
|
|
{
|
|
|
|
return id_;
|
|
|
|
}
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace chatterino
|