refactored SplitInput
This commit is contained in:
+64
-13
@@ -2,6 +2,7 @@
|
||||
#include "singletons/settingsmanager.hpp"
|
||||
#include "singletons/thememanager.hpp"
|
||||
|
||||
#include <QChildEvent>
|
||||
#include <QDebug>
|
||||
#include <QIcon>
|
||||
#include <QLayout>
|
||||
@@ -25,13 +26,7 @@ BaseWidget::BaseWidget(BaseWidget *parent, Qt::WindowFlags f)
|
||||
this->init();
|
||||
}
|
||||
|
||||
BaseWidget::BaseWidget(QWidget *parent, Qt::WindowFlags f)
|
||||
: QWidget(parent, f)
|
||||
, themeManager(singletons::ThemeManager::getInstance())
|
||||
{
|
||||
}
|
||||
|
||||
float BaseWidget::getDpiMultiplier()
|
||||
float BaseWidget::getScale() const
|
||||
{
|
||||
// return 1.f;
|
||||
BaseWidget *baseWidget = dynamic_cast<BaseWidget *>(this->window());
|
||||
@@ -39,17 +34,14 @@ float BaseWidget::getDpiMultiplier()
|
||||
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;
|
||||
return baseWidget->scale;
|
||||
}
|
||||
}
|
||||
|
||||
void BaseWidget::init()
|
||||
{
|
||||
auto connection = this->themeManager.updated.connect([this]() {
|
||||
this->refreshTheme();
|
||||
this->themeRefreshEvent();
|
||||
|
||||
this->update();
|
||||
});
|
||||
@@ -59,7 +51,66 @@ void BaseWidget::init()
|
||||
});
|
||||
}
|
||||
|
||||
void BaseWidget::refreshTheme()
|
||||
void BaseWidget::childEvent(QChildEvent *event)
|
||||
{
|
||||
if (event->added()) {
|
||||
BaseWidget *widget = dynamic_cast<BaseWidget *>(event->child());
|
||||
|
||||
if (widget) {
|
||||
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);
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user