Skip to content

Commit f60aedb

Browse files
authored
Add ability to change app font family & size (RedisInsight#3717)
Issue RedisInsight#3576
1 parent 3f6e906 commit f60aedb

File tree

4 files changed

+114
-14
lines changed

4 files changed

+114
-14
lines changed

src/app/app.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <QUrl>
55
#include <QSysInfo>
66
#include <QQmlContext>
7+
#include <QSettings>
78
#include <QMessageBox>
89
#include <easylogging++.h>
910
#include <googlemp.h>
@@ -68,8 +69,21 @@ void Application::initAppInfo()
6869

6970
void Application::initAppFonts()
7071
{
71-
QFontDatabase::addApplicationFont("://fonts/OpenSans-Regular.ttc");
72-
QFont defaultFont("OpenSans", 11);
72+
QSettings settings;
73+
QString appFont = settings.value("app/appFont", "Open Sans").toString();
74+
int appFontSize = settings.value("app/appFontSize", 11).toInt();
75+
76+
if (appFont == "Open Sans") {
77+
int result = QFontDatabase::addApplicationFont("://fonts/OpenSans.ttc");
78+
79+
#ifdef Q_OS_LINUX
80+
if (result == -1) {
81+
appFont = "Ubuntu";
82+
}
83+
#endif
84+
}
85+
qDebug() << "App font:" << appFont << appFontSize;
86+
QFont defaultFont(appFont, appFontSize);
7387
QApplication::setFont(defaultFont);
7488
}
7589

src/qml/GlobalSettings.qml

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ Dialog {
1010
id: root
1111
title: "Settings"
1212

13-
Settings {
14-
id: globalSettings
15-
category: "app"
16-
17-
property alias reopenNamespacesOnReload: nsReload.value
18-
property alias enableKeySortingInTree: keySorting.value
19-
property alias liveUpdateKeysLimit: liveKeyLimit.value
20-
property alias liveUpdateInterval: liveUpdateInterval.value
21-
}
22-
2313
contentItem: Item {
2414
implicitWidth: 800
2515
implicitHeight: 600
@@ -29,7 +19,36 @@ Dialog {
2919
anchors.margins: 20
3020

3121
Text {
32-
text: "Connections Tree Settings"
22+
text: "Appearance"
23+
font.pixelSize: 20
24+
}
25+
26+
ComboboxOption {
27+
id: appFont
28+
29+
Layout.fillWidth: true
30+
Layout.preferredHeight: 40
31+
32+
value: "Open Sans"
33+
model: Qt.fontFamilies()
34+
label: "Font"
35+
description: ""
36+
}
37+
38+
ComboboxOption {
39+
id: appFontSize
40+
41+
Layout.fillWidth: true
42+
Layout.preferredHeight: 40
43+
44+
model: ["8", "9", "10", "11", "12"]
45+
value: "10"
46+
label: "Font Size"
47+
description: "in pixels"
48+
}
49+
50+
Text {
51+
text: "Connections Tree"
3352
font.pixelSize: 20
3453
}
3554

@@ -96,4 +115,16 @@ Dialog {
96115
}
97116
}
98117
}
118+
119+
Settings {
120+
id: globalSettings
121+
category: "app"
122+
123+
property alias reopenNamespacesOnReload: nsReload.value
124+
property alias enableKeySortingInTree: keySorting.value
125+
property alias liveUpdateKeysLimit: liveKeyLimit.value
126+
property alias liveUpdateInterval: liveUpdateInterval.value
127+
property alias appFont: appFont.value
128+
property alias appFontSize: appFontSize.value
129+
}
99130
}

src/qml/qml.qrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<file>value-editor/editors/editor.js</file>
3131
<file>3rdparty/php-unserialize-js/phpUnserialize.js</file>
3232
<file>console/QConsole.qml</file>
33-
<file>console/BaseConsole.qml</file>
33+
<file>console/BaseConsole.qml</file>
3434
<file>console/Consoles.qml</file>
3535
<file>connections-tree/BetterTreeView.qml</file>
3636
<file>AppToolBar.qml</file>
@@ -41,5 +41,6 @@
4141
<file>settings/IntOption.qml</file>
4242
<file>bulk-operations/BulkOperationsDialog.qml</file>
4343
<file>value-editor/editors/formatters/json-tools.js</file>
44+
<file>settings/ComboboxOption.qml</file>
4445
</qresource>
4546
</RCC>

src/qml/settings/ComboboxOption.qml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import QtQuick 2.3
2+
import QtQuick.Layouts 1.1
3+
import QtQuick.Controls 1.2
4+
5+
Item {
6+
id: root
7+
property string label
8+
property string description
9+
property string value
10+
property alias model: val.model
11+
12+
onValueChanged: {
13+
if (val.currentText != root.value) {
14+
val.currentIndex = val.find(root.value)
15+
}
16+
}
17+
18+
RowLayout {
19+
anchors.fill: parent
20+
21+
ColumnLayout {
22+
Layout.fillWidth: true
23+
spacing: 1
24+
25+
Label {
26+
Layout.fillWidth: true
27+
text: root.label
28+
}
29+
30+
Text {
31+
color: "#cccccc"
32+
text: root.description
33+
}
34+
}
35+
36+
ComboBox {
37+
id: val
38+
39+
Layout.minimumWidth: 80
40+
41+
onActivated: {
42+
if (index >= 0)
43+
root.value = textAt(index)
44+
}
45+
46+
onCountChanged: {
47+
if (model) {
48+
currentIndex = val.find(root.value)
49+
}
50+
}
51+
}
52+
}
53+
}
54+

0 commit comments

Comments
 (0)