diff --git a/resources/qss/settings.qss b/resources/qss/settings.qss index f43dbb295..c3d731241 100644 --- a/resources/qss/settings.qss +++ b/resources/qss/settings.qss @@ -3,7 +3,7 @@ } * { - font-size: 14px; + font-size: px; } SettingsDialogTab:hover { @@ -17,3 +17,8 @@ QLabel, QCheckBox, QGroupBox, SettingsDialogTab { QGroupBox { background-color: #444; } + +QCheckBox::indicator { + width: px; + height: px; +} diff --git a/src/main.cpp b/src/main.cpp index 493bfce4e..7f13c84cd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -69,6 +69,8 @@ inline bool initSettings(bool portable) int main(int argc, char *argv[]) { + // QApplication::setAttribute(Qt::AA_Use96Dpi, true); + QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL, true); QApplication a(argc, argv); #ifdef USEWINSDK diff --git a/src/widgets/basewidget.cpp b/src/widgets/basewidget.cpp index 4046db8ef..574f38d68 100644 --- a/src/widgets/basewidget.cpp +++ b/src/widgets/basewidget.cpp @@ -37,6 +37,7 @@ BaseWidget::BaseWidget(QWidget *parent) float BaseWidget::getDpiMultiplier() { + // return 1.f; BaseWidget *baseWidget = dynamic_cast(this->window()); if (baseWidget == nullptr) { @@ -90,8 +91,7 @@ bool BaseWidget::nativeEvent(const QByteArray &eventType, void *message, long *r this->dpiMultiplier = dpi / 96.f; float scale = this->dpiMultiplier / oldDpiMultiplier; - qDebug() << scale; - qDebug() << dpi; + this->dpiMultiplyerChanged(oldDpiMultiplier, this->dpiMultiplier); this->resize(static_cast(this->width() * scale), static_cast(this->height() * scale)); diff --git a/src/widgets/basewidget.hpp b/src/widgets/basewidget.hpp index 5aa88d65e..dadecfa29 100644 --- a/src/widgets/basewidget.hpp +++ b/src/widgets/basewidget.hpp @@ -34,6 +34,10 @@ protected: #ifdef USEWINSDK virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override; #endif + + virtual void dpiMultiplyerChanged(float oldDpi, float newDpi) + { + } void initAsWindow(); private: diff --git a/src/widgets/helper/settingsdialogtab.cpp b/src/widgets/helper/settingsdialogtab.cpp index 3a51555d9..0eadda0f1 100644 --- a/src/widgets/helper/settingsdialogtab.cpp +++ b/src/widgets/helper/settingsdialogtab.cpp @@ -14,9 +14,6 @@ SettingsDialogTab::SettingsDialogTab(SettingsDialog *_dialog, QString _labelText this->ui.labelText = _labelText; this->ui.image.load(imageFileName); - // XXX: DPI (not sure if this is auto-adjusted with custom DPI) - this->setFixedHeight(32); - this->setCursor(QCursor(Qt::PointingHandCursor)); this->setStyleSheet("color: #FFF"); @@ -28,6 +25,8 @@ void SettingsDialogTab::setSelected(bool _selected) return; } + // height: px; + this->selected = _selected; emit selectedChanged(selected); } diff --git a/src/widgets/settingsdialog.cpp b/src/widgets/settingsdialog.cpp index 4c4bd36f5..df106e8de 100644 --- a/src/widgets/settingsdialog.cpp +++ b/src/widgets/settingsdialog.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -31,11 +32,6 @@ SettingsDialog::SettingsDialog() { this->initAsWindow(); - QFile file(":/qss/settings.qss"); - file.open(QFile::ReadOnly); - QString styleSheet = QLatin1String(file.readAll()); - this->setStyleSheet(styleSheet); - QPalette palette; palette.setColor(QPalette::Background, QColor("#444")); this->setPalette(palette); @@ -48,11 +44,10 @@ SettingsDialog::SettingsDialog() this->ui.vbox.addWidget(&this->ui.buttonBox); - auto tabWidget = new QWidget(); + auto tabWidget = &ui.tabWidget; tabWidget->setObjectName("tabWidget"); tabWidget->setLayout(&this->ui.tabs); - tabWidget->setFixedWidth(200); this->ui.hbox.addWidget(tabWidget); this->ui.hbox.addLayout(&this->ui.pageStack); @@ -71,6 +66,8 @@ SettingsDialog::SettingsDialog() this->resize(600, 500); this->addTabs(); + + this->dpiMultiplyerChanged(this->getDpiMultiplier(), this->getDpiMultiplier()); } void SettingsDialog::addTabs() @@ -578,6 +575,7 @@ void SettingsDialog::addTab(QBoxLayout *layout, QString title, QString imageRes) tab->setWidget(widget); this->ui.tabs.addWidget(tab, 0, Qt::AlignTop); + tabs.push_back(tab); this->ui.pageStack.addWidget(widget); @@ -610,6 +608,44 @@ void SettingsDialog::showDialog() instance->setFocus(); } +void SettingsDialog::dpiMultiplyerChanged(float oldDpi, float newDpi) +{ + QFile file(":/qss/settings.qss"); + file.open(QFile::ReadOnly); + QString styleSheet = QLatin1String(file.readAll()); + styleSheet.replace("", QString::number((int)(14 * newDpi))); + styleSheet.replace("", QString::number((int)(14 * newDpi))); + + for (SettingsDialogTab *tab : this->tabs) { + tab->setFixedHeight((int)(30 * newDpi)); + } + + this->setStyleSheet(styleSheet); + + this->ui.tabWidget.setFixedWidth((int)(200 * newDpi)); +} + +void SettingsDialog::setChildrensFont(QLayout *object, QFont &font, int indent) +{ + // for (QWidget *widget : this->widgets) { + // widget->setFont(font); + // } + // for (int i = 0; i < object->count(); i++) { + // if (object->itemAt(i)->layout()) { + // setChildrensFont(object->layout()->itemAt(i)->layout(), font, indent + 2); + // } + + // if (object->itemAt(i)->widget()) { + // object->itemAt(i)->widget()->setFont(font); + + // if (object->itemAt(i)->widget()->layout() && + // !object->itemAt(i)->widget()->layout()->isEmpty()) { + // setChildrensFont(object->itemAt(i)->widget()->layout(), font, indent + 2); + // } + // } + // } +} + /// Widget creation helpers QVBoxLayout *SettingsDialog::createTabLayout() { diff --git a/src/widgets/settingsdialog.hpp b/src/widgets/settingsdialog.hpp index e9888a57e..2c5b777c6 100644 --- a/src/widgets/settingsdialog.hpp +++ b/src/widgets/settingsdialog.hpp @@ -33,8 +33,12 @@ public: static void showDialog(); +protected: + virtual void dpiMultiplyerChanged(float oldDpi, float newDpi) override; + private: SettingsSnapshot snapshot; + std::vector tabs; pajlada::Settings::Setting usernameDisplayMode; @@ -42,6 +46,7 @@ private: QVBoxLayout tabs; QVBoxLayout vbox; QHBoxLayout hbox; + QWidget tabWidget; QStackedLayout pageStack; QDialogButtonBox buttonBox; QPushButton okButton; @@ -49,8 +54,8 @@ private: } ui; void addTab(QBoxLayout *layout, QString title, QString imageRes); - void addTabs(); + QVBoxLayout *createAccountsTab(); QVBoxLayout *createAppearanceTab(); QVBoxLayout *createMessagesTab(); @@ -84,6 +89,8 @@ private: void cancelButtonClicked(); std::vector managedConnections; + + static void setChildrensFont(QLayout *object, QFont &font, int indent = 0); }; } // namespace widgets