Init custom DPI.

This commit is contained in:
Black Hat 2018-11-18 20:08:01 +08:00
parent 2fb563619d
commit a8cbd0a9cd
5 changed files with 54 additions and 4 deletions

View File

@ -432,10 +432,10 @@ Rectangle {
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
padding: 16
padding: 32
ColumnLayout {
width: main.width
width: main.width - 64
spacing: 0
Switch {
@ -465,6 +465,32 @@ Rectangle {
onCheckedChanged: MSettings.confirmOnExit = checked
}
RowLayout {
Layout.fillWidth: true
Label {
text: "DPI"
}
Slider {
Layout.fillWidth: true
value: controller.dpi()
from: 100
to: 300
stepSize: 25
snapMode: Slider.SnapAlways
ToolTip {
Material.foreground: "white"
visible: parent.pressed
text: parent.value
}
onMoved: controller.setDpi(value)
}
}
}
}
}

View File

@ -128,6 +128,8 @@ ApplicationWindow {
ToolTip {
id: loginButtonTooltip
Material.foreground: "white"
}
}

View File

@ -239,3 +239,11 @@ void Controller::postNotification(const QString& roomId, const QString& eventId,
notificationsManager.postNotification(roomId, eventId, roomName, senderName,
text, icon, iconPath);
}
int Controller::dpi() {
return SettingsGroup("Interface").value("dpi", 100).toInt();
}
void Controller::setDpi(int dpi) {
SettingsGroup("Interface").setValue("dpi", dpi);
}

View File

@ -32,6 +32,9 @@ class Controller : public QObject {
QVector<Connection*> connections() { return m_connections; }
Q_INVOKABLE int dpi();
Q_INVOKABLE void setDpi(int dpi);
// All the non-Q_INVOKABLE functions.
void addConnection(Connection* c);
void dropConnection(Connection* c);

View File

@ -23,10 +23,21 @@
using namespace QMatrixClient;
int main(int argc, char *argv[]) {
#if defined(Q_OS_WIN)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#if defined(Q_OS_LINUX) || defined(Q_OS_WIN) || defined(Q_OS_FREEBSD)
if (qgetenv("QT_SCALE_FACTOR").size() == 0) {
QSettings settings("ENCOM", "Spectral");
float factor = settings.value("Interface/dpi", 100).toFloat() / 100;
qDebug() << "DPI:" << factor;
if (factor != -1)
qputenv("QT_SCALE_FACTOR", QString::number(factor).toUtf8());
}
#endif
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
app.setOrganizationName("ENCOM");