mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
fixed hidpi scaling for the settings window
This commit is contained in:
parent
87182d078c
commit
01e9c723fa
|
@ -3,7 +3,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
* {
|
* {
|
||||||
font-size: 14px;
|
font-size: <font-size>px;
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingsDialogTab:hover {
|
SettingsDialogTab:hover {
|
||||||
|
@ -17,3 +17,8 @@ QLabel, QCheckBox, QGroupBox, SettingsDialogTab {
|
||||||
QGroupBox {
|
QGroupBox {
|
||||||
background-color: #444;
|
background-color: #444;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QCheckBox::indicator {
|
||||||
|
width: <checkbox-size>px;
|
||||||
|
height: <checkbox-size>px;
|
||||||
|
}
|
||||||
|
|
|
@ -69,6 +69,8 @@ inline bool initSettings(bool portable)
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
// QApplication::setAttribute(Qt::AA_Use96Dpi, true);
|
||||||
|
QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL, true);
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
#ifdef USEWINSDK
|
#ifdef USEWINSDK
|
||||||
|
|
|
@ -37,6 +37,7 @@ BaseWidget::BaseWidget(QWidget *parent)
|
||||||
|
|
||||||
float BaseWidget::getDpiMultiplier()
|
float BaseWidget::getDpiMultiplier()
|
||||||
{
|
{
|
||||||
|
// return 1.f;
|
||||||
BaseWidget *baseWidget = dynamic_cast<BaseWidget *>(this->window());
|
BaseWidget *baseWidget = dynamic_cast<BaseWidget *>(this->window());
|
||||||
|
|
||||||
if (baseWidget == nullptr) {
|
if (baseWidget == nullptr) {
|
||||||
|
@ -90,8 +91,7 @@ bool BaseWidget::nativeEvent(const QByteArray &eventType, void *message, long *r
|
||||||
this->dpiMultiplier = dpi / 96.f;
|
this->dpiMultiplier = dpi / 96.f;
|
||||||
float scale = this->dpiMultiplier / oldDpiMultiplier;
|
float scale = this->dpiMultiplier / oldDpiMultiplier;
|
||||||
|
|
||||||
qDebug() << scale;
|
this->dpiMultiplyerChanged(oldDpiMultiplier, this->dpiMultiplier);
|
||||||
qDebug() << dpi;
|
|
||||||
|
|
||||||
this->resize(static_cast<int>(this->width() * scale),
|
this->resize(static_cast<int>(this->width() * scale),
|
||||||
static_cast<int>(this->height() * scale));
|
static_cast<int>(this->height() * scale));
|
||||||
|
|
|
@ -34,6 +34,10 @@ protected:
|
||||||
#ifdef USEWINSDK
|
#ifdef USEWINSDK
|
||||||
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
virtual void dpiMultiplyerChanged(float oldDpi, float newDpi)
|
||||||
|
{
|
||||||
|
}
|
||||||
void initAsWindow();
|
void initAsWindow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -14,9 +14,6 @@ SettingsDialogTab::SettingsDialogTab(SettingsDialog *_dialog, QString _labelText
|
||||||
this->ui.labelText = _labelText;
|
this->ui.labelText = _labelText;
|
||||||
this->ui.image.load(imageFileName);
|
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->setCursor(QCursor(Qt::PointingHandCursor));
|
||||||
|
|
||||||
this->setStyleSheet("color: #FFF");
|
this->setStyleSheet("color: #FFF");
|
||||||
|
@ -28,6 +25,8 @@ void SettingsDialogTab::setSelected(bool _selected)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// height: <checkbox-size>px;
|
||||||
|
|
||||||
this->selected = _selected;
|
this->selected = _selected;
|
||||||
emit selectedChanged(selected);
|
emit selectedChanged(selected);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QFont>
|
||||||
#include <QFontDialog>
|
#include <QFontDialog>
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
|
@ -31,11 +32,6 @@ SettingsDialog::SettingsDialog()
|
||||||
{
|
{
|
||||||
this->initAsWindow();
|
this->initAsWindow();
|
||||||
|
|
||||||
QFile file(":/qss/settings.qss");
|
|
||||||
file.open(QFile::ReadOnly);
|
|
||||||
QString styleSheet = QLatin1String(file.readAll());
|
|
||||||
this->setStyleSheet(styleSheet);
|
|
||||||
|
|
||||||
QPalette palette;
|
QPalette palette;
|
||||||
palette.setColor(QPalette::Background, QColor("#444"));
|
palette.setColor(QPalette::Background, QColor("#444"));
|
||||||
this->setPalette(palette);
|
this->setPalette(palette);
|
||||||
|
@ -48,11 +44,10 @@ SettingsDialog::SettingsDialog()
|
||||||
|
|
||||||
this->ui.vbox.addWidget(&this->ui.buttonBox);
|
this->ui.vbox.addWidget(&this->ui.buttonBox);
|
||||||
|
|
||||||
auto tabWidget = new QWidget();
|
auto tabWidget = &ui.tabWidget;
|
||||||
tabWidget->setObjectName("tabWidget");
|
tabWidget->setObjectName("tabWidget");
|
||||||
|
|
||||||
tabWidget->setLayout(&this->ui.tabs);
|
tabWidget->setLayout(&this->ui.tabs);
|
||||||
tabWidget->setFixedWidth(200);
|
|
||||||
|
|
||||||
this->ui.hbox.addWidget(tabWidget);
|
this->ui.hbox.addWidget(tabWidget);
|
||||||
this->ui.hbox.addLayout(&this->ui.pageStack);
|
this->ui.hbox.addLayout(&this->ui.pageStack);
|
||||||
|
@ -71,6 +66,8 @@ SettingsDialog::SettingsDialog()
|
||||||
this->resize(600, 500);
|
this->resize(600, 500);
|
||||||
|
|
||||||
this->addTabs();
|
this->addTabs();
|
||||||
|
|
||||||
|
this->dpiMultiplyerChanged(this->getDpiMultiplier(), this->getDpiMultiplier());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::addTabs()
|
void SettingsDialog::addTabs()
|
||||||
|
@ -578,6 +575,7 @@ void SettingsDialog::addTab(QBoxLayout *layout, QString title, QString imageRes)
|
||||||
tab->setWidget(widget);
|
tab->setWidget(widget);
|
||||||
|
|
||||||
this->ui.tabs.addWidget(tab, 0, Qt::AlignTop);
|
this->ui.tabs.addWidget(tab, 0, Qt::AlignTop);
|
||||||
|
tabs.push_back(tab);
|
||||||
|
|
||||||
this->ui.pageStack.addWidget(widget);
|
this->ui.pageStack.addWidget(widget);
|
||||||
|
|
||||||
|
@ -610,6 +608,44 @@ void SettingsDialog::showDialog()
|
||||||
instance->setFocus();
|
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("<font-size>", QString::number((int)(14 * newDpi)));
|
||||||
|
styleSheet.replace("<checkbox-size>", 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
|
/// Widget creation helpers
|
||||||
QVBoxLayout *SettingsDialog::createTabLayout()
|
QVBoxLayout *SettingsDialog::createTabLayout()
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,8 +33,12 @@ public:
|
||||||
|
|
||||||
static void showDialog();
|
static void showDialog();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void dpiMultiplyerChanged(float oldDpi, float newDpi) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SettingsSnapshot snapshot;
|
SettingsSnapshot snapshot;
|
||||||
|
std::vector<SettingsDialogTab *> tabs;
|
||||||
|
|
||||||
pajlada::Settings::Setting<int> usernameDisplayMode;
|
pajlada::Settings::Setting<int> usernameDisplayMode;
|
||||||
|
|
||||||
|
@ -42,6 +46,7 @@ private:
|
||||||
QVBoxLayout tabs;
|
QVBoxLayout tabs;
|
||||||
QVBoxLayout vbox;
|
QVBoxLayout vbox;
|
||||||
QHBoxLayout hbox;
|
QHBoxLayout hbox;
|
||||||
|
QWidget tabWidget;
|
||||||
QStackedLayout pageStack;
|
QStackedLayout pageStack;
|
||||||
QDialogButtonBox buttonBox;
|
QDialogButtonBox buttonBox;
|
||||||
QPushButton okButton;
|
QPushButton okButton;
|
||||||
|
@ -49,8 +54,8 @@ private:
|
||||||
} ui;
|
} ui;
|
||||||
|
|
||||||
void addTab(QBoxLayout *layout, QString title, QString imageRes);
|
void addTab(QBoxLayout *layout, QString title, QString imageRes);
|
||||||
|
|
||||||
void addTabs();
|
void addTabs();
|
||||||
|
|
||||||
QVBoxLayout *createAccountsTab();
|
QVBoxLayout *createAccountsTab();
|
||||||
QVBoxLayout *createAppearanceTab();
|
QVBoxLayout *createAppearanceTab();
|
||||||
QVBoxLayout *createMessagesTab();
|
QVBoxLayout *createMessagesTab();
|
||||||
|
@ -84,6 +89,8 @@ private:
|
||||||
void cancelButtonClicked();
|
void cancelButtonClicked();
|
||||||
|
|
||||||
std::vector<pajlada::Signals::ScopedConnection> managedConnections;
|
std::vector<pajlada::Signals::ScopedConnection> managedConnections;
|
||||||
|
|
||||||
|
static void setChildrensFont(QLayout *object, QFont &font, int indent = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace widgets
|
} // namespace widgets
|
||||||
|
|
Loading…
Reference in a new issue