2017-07-02 14:28:37 +02:00
|
|
|
#include "widgets/basewidget.hpp"
|
|
|
|
#include "colorscheme.hpp"
|
|
|
|
|
2017-09-22 00:50:43 +02:00
|
|
|
//#include <QApplication>
|
2017-07-02 14:28:37 +02:00
|
|
|
#include <QDebug>
|
2017-09-22 00:50:43 +02:00
|
|
|
//#include <QDesktopWidget>
|
|
|
|
//#include <QScreen>
|
2017-07-02 14:28:37 +02:00
|
|
|
#include <boost/signals2.hpp>
|
2017-09-22 00:50:43 +02:00
|
|
|
#include "util/nativeeventhelper.hpp"
|
2017-07-02 14:28:37 +02:00
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
|
|
|
|
2017-09-22 00:50:43 +02:00
|
|
|
// BaseWidget::BaseWidget(ColorScheme &_colorScheme, WindowManager &_windowManager, QWidget *parent)
|
2017-07-02 14:28:37 +02:00
|
|
|
BaseWidget::BaseWidget(ColorScheme &_colorScheme, QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, colorScheme(_colorScheme)
|
2017-09-22 00:50:43 +02:00
|
|
|
// , windowManager(_windowManager)
|
2017-07-02 14:28:37 +02:00
|
|
|
{
|
|
|
|
this->init();
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseWidget::BaseWidget(BaseWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, colorScheme(parent->colorScheme)
|
2017-09-22 00:50:43 +02:00
|
|
|
// , windowManager(parent->windowManager)
|
2017-07-02 14:28:37 +02:00
|
|
|
{
|
|
|
|
this->init();
|
|
|
|
}
|
|
|
|
|
2017-09-22 00:50:43 +02:00
|
|
|
float BaseWidget::getDpiMultiplier()
|
|
|
|
{
|
|
|
|
BaseWidget *baseWidget = dynamic_cast<BaseWidget *>(this->window());
|
|
|
|
|
|
|
|
if (baseWidget == nullptr) {
|
|
|
|
return 1.f;
|
|
|
|
} else {
|
|
|
|
return baseWidget->dpiMultiplier;
|
|
|
|
// int screenNr = QApplication::desktop()->screenNumber(this);
|
|
|
|
// QScreen *screen = QApplication::screens().at(screenNr);
|
|
|
|
// return screen->logicalDotsPerInch() / 96.f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-02 14:28:37 +02:00
|
|
|
void BaseWidget::init()
|
|
|
|
{
|
|
|
|
this->colorScheme.updated.connect([this]() {
|
|
|
|
this->refreshTheme();
|
|
|
|
|
|
|
|
this->update();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseWidget::refreshTheme()
|
|
|
|
{
|
|
|
|
// Do any color scheme updates here
|
|
|
|
}
|
|
|
|
|
2017-09-22 00:50:43 +02:00
|
|
|
#ifdef USEWINSDK
|
|
|
|
bool BaseWidget::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
|
|
|
{
|
|
|
|
int dpi;
|
|
|
|
|
|
|
|
if (util::tryHandleDpiChangedMessage(message, dpi)) {
|
|
|
|
qDebug() << "dpi changed";
|
|
|
|
|
|
|
|
float oldDpiMultiplier = this->dpiMultiplier;
|
|
|
|
this->dpiMultiplier = dpi / 96.f;
|
|
|
|
float scale = this->dpiMultiplier / oldDpiMultiplier;
|
|
|
|
|
|
|
|
qDebug() << scale;
|
|
|
|
qDebug() << dpi;
|
|
|
|
|
|
|
|
this->resize(static_cast<int>(this->width() * scale),
|
|
|
|
static_cast<int>(this->height() * scale));
|
|
|
|
}
|
|
|
|
|
|
|
|
return QWidget::nativeEvent(eventType, message, result);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-07-02 14:28:37 +02:00
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|