mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
adf3ff3075
cstdint) Make MessageElement to a class to fit better with the derived classes. Make MessageLayoutElement to a class to fit better with the derived classes. Remove virtual from override functions Replace all instances of boost::signals2 with pajlada::Signals. This lets us properly use clang code model to check for issues. Add missing virtual destructor to AbstractIrcServer Add missing virtual destructor to MessageLayoutElement Remove unused "connectedConnection" connection in TwitchChannel Fix typo in TrimChannelName function Fix typo in MessageParseArgs Replace some raw pointers with unique pointers where it made more sense. This allowed us to remove some manually written destructors whose only purpose was to delete that raw pointer. Reformat: Add namespace comments Reformat: Add empty empty lines between main namespace beginning and end Reformat: Re-order includes Reformat: Fix some includes that used quotes where they should use angle brackets Reformat: Replace some typedef's with using's Filter out more useless warnings
165 lines
3.8 KiB
C++
165 lines
3.8 KiB
C++
#include "widgets/basewidget.hpp"
|
|
#include "debug/log.hpp"
|
|
#include "singletons/settingsmanager.hpp"
|
|
#include "singletons/thememanager.hpp"
|
|
|
|
#include <QChildEvent>
|
|
#include <QDebug>
|
|
#include <QIcon>
|
|
#include <QLayout>
|
|
#include <QtGlobal>
|
|
|
|
namespace chatterino {
|
|
namespace widgets {
|
|
|
|
BaseWidget::BaseWidget(singletons::ThemeManager &_themeManager, QWidget *parent, Qt::WindowFlags f)
|
|
: QWidget(parent, f)
|
|
, themeManager(_themeManager)
|
|
{
|
|
this->init();
|
|
}
|
|
|
|
BaseWidget::BaseWidget(BaseWidget *parent, Qt::WindowFlags f)
|
|
: QWidget(parent, f)
|
|
, themeManager(singletons::ThemeManager::getInstance())
|
|
{
|
|
this->init();
|
|
}
|
|
|
|
float BaseWidget::getScale() const
|
|
{
|
|
// return 1.f;
|
|
BaseWidget *baseWidget = dynamic_cast<BaseWidget *>(this->window());
|
|
|
|
if (baseWidget == nullptr) {
|
|
return 1.f;
|
|
}
|
|
|
|
return baseWidget->scale;
|
|
}
|
|
|
|
QSize BaseWidget::getScaleIndependantSize() const
|
|
{
|
|
return this->scaleIndependantSize;
|
|
}
|
|
|
|
int BaseWidget::getScaleIndependantWidth() const
|
|
{
|
|
return this->scaleIndependantSize.width();
|
|
}
|
|
|
|
int BaseWidget::getScaleIndependantHeight() 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->getScale()));
|
|
}
|
|
if (size.height() > 0) {
|
|
this->setFixedHeight((int)(size.height() * this->getScale()));
|
|
}
|
|
}
|
|
|
|
void BaseWidget::setScaleIndependantWidth(int value)
|
|
{
|
|
this->setScaleIndependantSize(QSize(value, this->scaleIndependantSize.height()));
|
|
}
|
|
|
|
void BaseWidget::setScaleIndependantHeight(int value)
|
|
{
|
|
this->setScaleIndependantSize(QSize(this->scaleIndependantSize.height(), value));
|
|
}
|
|
|
|
void BaseWidget::init()
|
|
{
|
|
pajlada::Signals::Connection connection = this->themeManager.updated.connect([this]() {
|
|
this->themeRefreshEvent();
|
|
|
|
this->update();
|
|
});
|
|
|
|
QObject::connect(this, &QObject::destroyed, [connection]() mutable {
|
|
connection.disconnect(); //
|
|
});
|
|
}
|
|
|
|
void BaseWidget::childEvent(QChildEvent *event)
|
|
{
|
|
if (event->added()) {
|
|
BaseWidget *widget = dynamic_cast<BaseWidget *>(event->child());
|
|
|
|
if (widget != nullptr) {
|
|
this->widgets.push_back(widget);
|
|
}
|
|
} else if (event->removed()) {
|
|
for (auto it = this->widgets.begin(); it != this->widgets.end(); it++) {
|
|
if (*it == event->child()) {
|
|
this->widgets.erase(it);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void BaseWidget::setScale(float value)
|
|
{
|
|
// update scale value
|
|
this->scale = value;
|
|
|
|
this->scaleChangedEvent(value);
|
|
this->scaleChanged.invoke(value);
|
|
|
|
this->setScaleIndependantSize(this->getScaleIndependantSize());
|
|
|
|
// set scale for all children
|
|
BaseWidget::setScaleRecursive(value, this);
|
|
}
|
|
|
|
void BaseWidget::setScaleRecursive(float scale, QObject *object)
|
|
{
|
|
for (QObject *child : object->children()) {
|
|
BaseWidget *widget = dynamic_cast<BaseWidget *>(child);
|
|
if (widget != nullptr) {
|
|
widget->setScale(scale);
|
|
continue;
|
|
}
|
|
|
|
// QLayout *layout = nullptr;
|
|
// QWidget *widget = dynamic_cast<QWidget *>(child);
|
|
|
|
// if (widget != nullptr) {
|
|
// layout = widget->layout();
|
|
// }
|
|
|
|
// else {
|
|
QLayout *layout = dynamic_cast<QLayout *>(object);
|
|
|
|
if (layout != nullptr) {
|
|
setScaleRecursive(scale, layout);
|
|
}
|
|
// }
|
|
}
|
|
}
|
|
|
|
void BaseWidget::scaleChangedEvent(float newDpi)
|
|
{
|
|
}
|
|
|
|
void BaseWidget::themeRefreshEvent()
|
|
{
|
|
// Do any color scheme updates here
|
|
}
|
|
|
|
} // namespace widgets
|
|
} // namespace chatterino
|