2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/BaseWidget.hpp"
|
2018-04-27 22:11:19 +02:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
|
|
|
#include "debug/Log.hpp"
|
2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Settings.hpp"
|
2018-06-28 20:03:04 +02:00
|
|
|
#include "singletons/Theme.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/BaseWindow.hpp"
|
2017-07-02 14:28:37 +02:00
|
|
|
|
2018-01-25 20:49:49 +01:00
|
|
|
#include <QChildEvent>
|
2017-07-02 14:28:37 +02:00
|
|
|
#include <QDebug>
|
2018-01-05 03:30:43 +01:00
|
|
|
#include <QIcon>
|
2017-12-18 02:47:01 +01:00
|
|
|
#include <QLayout>
|
|
|
|
#include <QtGlobal>
|
2017-07-02 14:28:37 +02:00
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
BaseWidget::BaseWidget(QWidget *parent, Qt::WindowFlags f)
|
2018-01-15 01:35:35 +01:00
|
|
|
: QWidget(parent, f)
|
2017-07-02 14:28:37 +02:00
|
|
|
{
|
2018-07-06 17:11:37 +02:00
|
|
|
this->theme = getApp()->themes;
|
2017-07-02 14:28:37 +02:00
|
|
|
|
2018-07-06 17:11:37 +02:00
|
|
|
this->signalHolder_.managedConnect(this->theme->updated, [this]() {
|
|
|
|
this->themeChangedEvent();
|
|
|
|
|
|
|
|
this->update();
|
|
|
|
});
|
2018-04-13 23:17:10 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 20:49:49 +01:00
|
|
|
float BaseWidget::getScale() const
|
2017-09-22 00:50:43 +02:00
|
|
|
{
|
2018-07-06 17:11:37 +02:00
|
|
|
if (this->overrideScale_) {
|
|
|
|
return this->overrideScale_.get();
|
2018-06-25 22:06:17 +02:00
|
|
|
}
|
|
|
|
|
2017-09-22 00:50:43 +02:00
|
|
|
BaseWidget *baseWidget = dynamic_cast<BaseWidget *>(this->window());
|
|
|
|
|
|
|
|
if (baseWidget == nullptr) {
|
|
|
|
return 1.f;
|
|
|
|
}
|
2018-03-31 13:44:15 +02:00
|
|
|
|
2018-07-06 17:11:37 +02:00
|
|
|
return baseWidget->scale_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWidget::setScale(float value)
|
|
|
|
{
|
|
|
|
// update scale value
|
|
|
|
this->scale_ = value;
|
|
|
|
|
|
|
|
this->scaleChangedEvent(this->getScale());
|
|
|
|
this->scaleChanged.invoke(this->getScale());
|
|
|
|
|
|
|
|
this->setScaleIndependantSize(this->getScaleIndependantSize());
|
2017-09-22 00:50:43 +02:00
|
|
|
}
|
|
|
|
|
2018-06-25 22:06:17 +02:00
|
|
|
void BaseWidget::setOverrideScale(boost::optional<float> value)
|
|
|
|
{
|
2018-07-06 17:11:37 +02:00
|
|
|
this->overrideScale_ = value;
|
2018-06-25 22:06:17 +02:00
|
|
|
this->setScale(this->getScale());
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::optional<float> BaseWidget::getOverrideScale() const
|
|
|
|
{
|
2018-07-06 17:11:37 +02:00
|
|
|
return this->overrideScale_;
|
2018-06-25 22:06:17 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 21:11:14 +01:00
|
|
|
QSize BaseWidget::getScaleIndependantSize() const
|
|
|
|
{
|
2018-07-06 17:11:37 +02:00
|
|
|
return this->scaleIndependantSize_;
|
2018-01-25 21:11:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int BaseWidget::getScaleIndependantWidth() const
|
|
|
|
{
|
2018-07-06 17:11:37 +02:00
|
|
|
return this->scaleIndependantSize_.width();
|
2018-01-25 21:11:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int BaseWidget::getScaleIndependantHeight() const
|
|
|
|
{
|
2018-07-06 17:11:37 +02:00
|
|
|
return this->scaleIndependantSize_.height();
|
2018-01-25 21:11:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWidget::setScaleIndependantSize(int width, int height)
|
|
|
|
{
|
|
|
|
this->setScaleIndependantSize(QSize(width, height));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWidget::setScaleIndependantSize(QSize size)
|
|
|
|
{
|
2018-07-06 17:11:37 +02:00
|
|
|
this->scaleIndependantSize_ = size;
|
2018-01-25 21:11:14 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2018-07-06 17:11:37 +02:00
|
|
|
this->setScaleIndependantSize(QSize(value, this->scaleIndependantSize_.height()));
|
2018-01-25 21:11:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWidget::setScaleIndependantHeight(int value)
|
|
|
|
{
|
2018-07-06 17:11:37 +02:00
|
|
|
this->setScaleIndependantSize(QSize(this->scaleIndependantSize_.height(), value));
|
2017-07-02 14:28:37 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 20:49:49 +01:00
|
|
|
void BaseWidget::childEvent(QChildEvent *event)
|
|
|
|
{
|
|
|
|
if (event->added()) {
|
|
|
|
BaseWidget *widget = dynamic_cast<BaseWidget *>(event->child());
|
|
|
|
|
2018-03-31 13:44:15 +02:00
|
|
|
if (widget != nullptr) {
|
2018-07-06 17:11:37 +02:00
|
|
|
this->widgets_.push_back(widget);
|
2018-01-25 20:49:49 +01:00
|
|
|
}
|
|
|
|
} else if (event->removed()) {
|
2018-07-06 17:11:37 +02:00
|
|
|
for (auto it = this->widgets_.begin(); it != this->widgets_.end(); it++) {
|
2018-01-25 20:49:49 +01:00
|
|
|
if (*it == event->child()) {
|
2018-07-06 17:11:37 +02:00
|
|
|
this->widgets_.erase(it);
|
2018-01-25 20:49:49 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-25 21:11:14 +01:00
|
|
|
|
2018-04-18 09:33:05 +02:00
|
|
|
void BaseWidget::showEvent(QShowEvent *)
|
|
|
|
{
|
2018-05-08 15:12:04 +02:00
|
|
|
this->setScale(this->getScale());
|
2018-07-06 17:11:37 +02:00
|
|
|
this->themeChangedEvent();
|
2018-01-25 20:49:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWidget::scaleChangedEvent(float newDpi)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-07-06 17:11:37 +02:00
|
|
|
void BaseWidget::themeChangedEvent()
|
2017-07-02 14:28:37 +02:00
|
|
|
{
|
|
|
|
// Do any color scheme updates here
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|