2019-07-23 22:18:36 +02:00
|
|
|
#include "widgets/BaseWidget.hpp"
|
|
|
|
|
2024-01-06 11:42:45 +01:00
|
|
|
#include "Application.hpp"
|
2021-11-21 18:46:21 +01:00
|
|
|
#include "common/QLogging.hpp"
|
|
|
|
#include "controllers/hotkeys/HotkeyController.hpp"
|
2022-11-10 10:07:50 +01:00
|
|
|
#include "singletons/Theme.hpp"
|
2019-07-23 22:18:36 +02:00
|
|
|
#include "widgets/BaseWindow.hpp"
|
|
|
|
|
|
|
|
#include <QChildEvent>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QLayout>
|
|
|
|
#include <QtGlobal>
|
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
|
|
|
|
2020-04-19 21:05:40 +02:00
|
|
|
#include <algorithm>
|
2019-07-23 22:18:36 +02:00
|
|
|
|
2019-10-07 15:46:08 +02:00
|
|
|
namespace chatterino {
|
2019-07-23 22:18:36 +02:00
|
|
|
|
|
|
|
BaseWidget::BaseWidget(QWidget *parent, Qt::WindowFlags f)
|
|
|
|
: QWidget(parent, f)
|
2024-01-06 11:42:45 +01:00
|
|
|
, theme(getIApp()->getThemes())
|
2019-07-23 22:18:36 +02:00
|
|
|
{
|
|
|
|
this->signalHolder_.managedConnect(this->theme->updated, [this]() {
|
|
|
|
this->themeChangedEvent();
|
|
|
|
|
|
|
|
this->update();
|
|
|
|
});
|
|
|
|
}
|
2021-11-21 18:46:21 +01:00
|
|
|
void BaseWidget::clearShortcuts()
|
|
|
|
{
|
|
|
|
for (auto shortcut : this->shortcuts_)
|
|
|
|
{
|
|
|
|
shortcut->setKey(QKeySequence());
|
|
|
|
shortcut->removeEventFilter(this);
|
|
|
|
shortcut->deleteLater();
|
|
|
|
}
|
|
|
|
this->shortcuts_.clear();
|
|
|
|
}
|
2019-07-23 22:18:36 +02:00
|
|
|
|
|
|
|
float BaseWidget::scale() const
|
|
|
|
{
|
|
|
|
if (this->overrideScale_)
|
|
|
|
{
|
2023-10-08 18:50:48 +02:00
|
|
|
return *this->overrideScale_;
|
2019-07-23 22:18:36 +02:00
|
|
|
}
|
2023-10-08 18:50:48 +02:00
|
|
|
|
|
|
|
if (auto *baseWidget = dynamic_cast<BaseWidget *>(this->window()))
|
2019-07-23 22:18:36 +02:00
|
|
|
{
|
|
|
|
return baseWidget->scale_;
|
|
|
|
}
|
2023-10-08 18:50:48 +02:00
|
|
|
|
|
|
|
return 1.F;
|
2019-07-23 22:18:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWidget::setScale(float value)
|
|
|
|
{
|
|
|
|
// update scale value
|
|
|
|
this->scale_ = value;
|
|
|
|
|
|
|
|
this->scaleChangedEvent(this->scale());
|
|
|
|
this->scaleChanged.invoke(this->scale());
|
|
|
|
|
|
|
|
this->setScaleIndependantSize(this->scaleIndependantSize());
|
|
|
|
}
|
|
|
|
|
2023-10-08 18:50:48 +02:00
|
|
|
void BaseWidget::setOverrideScale(std::optional<float> value)
|
2019-07-23 22:18:36 +02:00
|
|
|
{
|
|
|
|
this->overrideScale_ = value;
|
|
|
|
this->setScale(this->scale());
|
|
|
|
}
|
|
|
|
|
2023-10-08 18:50:48 +02:00
|
|
|
std::optional<float> BaseWidget::overrideScale() const
|
2019-07-23 22:18:36 +02:00
|
|
|
{
|
|
|
|
return this->overrideScale_;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize BaseWidget::scaleIndependantSize() const
|
|
|
|
{
|
|
|
|
return this->scaleIndependantSize_;
|
|
|
|
}
|
|
|
|
|
|
|
|
int BaseWidget::scaleIndependantWidth() const
|
|
|
|
{
|
|
|
|
return this->scaleIndependantSize_.width();
|
|
|
|
}
|
|
|
|
|
|
|
|
int BaseWidget::scaleIndependantHeight() const
|
|
|
|
{
|
|
|
|
return this->scaleIndependantSize_.height();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWidget::setScaleIndependantSize(int width, int height)
|
|
|
|
{
|
|
|
|
this->setScaleIndependantSize(QSize(width, height));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWidget::setScaleIndependantSize(QSize size)
|
|
|
|
{
|
|
|
|
this->scaleIndependantSize_ = size;
|
|
|
|
|
|
|
|
if (size.width() > 0)
|
|
|
|
{
|
|
|
|
this->setFixedWidth(int(size.width() * this->scale()));
|
|
|
|
}
|
|
|
|
if (size.height() > 0)
|
|
|
|
{
|
|
|
|
this->setFixedHeight(int(size.height() * this->scale()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWidget::setScaleIndependantWidth(int value)
|
|
|
|
{
|
|
|
|
this->setScaleIndependantSize(
|
|
|
|
QSize(value, this->scaleIndependantSize_.height()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWidget::setScaleIndependantHeight(int value)
|
|
|
|
{
|
|
|
|
this->setScaleIndependantSize(
|
|
|
|
QSize(this->scaleIndependantSize_.width(), value));
|
|
|
|
}
|
|
|
|
|
|
|
|
float BaseWidget::qtFontScale() const
|
|
|
|
{
|
|
|
|
if (auto window = dynamic_cast<BaseWindow *>(this->window()))
|
|
|
|
{
|
2020-04-19 21:05:40 +02:00
|
|
|
// ensure no div by 0
|
|
|
|
return this->scale() / std::max<float>(0.01f, window->nativeScale_);
|
2019-07-23 22:18:36 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this->scale();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWidget::childEvent(QChildEvent *event)
|
|
|
|
{
|
|
|
|
if (event->added())
|
|
|
|
{
|
|
|
|
// add element if it's a basewidget
|
|
|
|
if (auto widget = dynamic_cast<BaseWidget *>(event->child()))
|
|
|
|
{
|
|
|
|
this->widgets_.push_back(widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event->removed())
|
|
|
|
{
|
|
|
|
// find element to be removed
|
|
|
|
auto it = std::find_if(this->widgets_.begin(), this->widgets_.end(),
|
2020-11-08 12:02:19 +01:00
|
|
|
[&](auto &&x) {
|
|
|
|
return x == event->child();
|
|
|
|
});
|
2019-07-23 22:18:36 +02:00
|
|
|
|
|
|
|
// remove if found
|
|
|
|
if (it != this->widgets_.end())
|
|
|
|
{
|
|
|
|
this->widgets_.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWidget::showEvent(QShowEvent *)
|
|
|
|
{
|
|
|
|
this->setScale(this->scale());
|
|
|
|
this->themeChangedEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWidget::scaleChangedEvent(float newDpi)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWidget::themeChangedEvent()
|
|
|
|
{
|
|
|
|
// Do any color scheme updates here
|
|
|
|
}
|
|
|
|
|
2019-10-07 15:46:08 +02:00
|
|
|
} // namespace chatterino
|