main.qml 10.9 KB
Newer Older
Marco Martin's avatar
Marco Martin committed
1
2
3
/*
   Copyright (c) 2015 Antonis Tsiapaliokas <antonis.tsiapaliokas@kde.org>
   Copyright (c) 2017 Marco Martin <mart@kde.org>
Benjamin Port's avatar
Benjamin Port committed
4
   Copyright (c) 2019 Benjamin Port <benjamin.port@enioka.com>
Marco Martin's avatar
Marco Martin committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

import QtQuick 2.1
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.0 as QtControls
import QtQuick.Dialogs 1.2 as QtDialogs
25
import org.kde.kirigami 2.4 as Kirigami
Marco Martin's avatar
Marco Martin committed
26
27
28
29
30
import org.kde.kcm 1.1 as KCM

KCM.SimpleKCM {
    id: root

31
    KCM.ConfigModule.quickHelp: i18n("This module lets you configure the system fonts.")
Marco Martin's avatar
Marco Martin committed
32

33
    ColumnLayout {
Marco Martin's avatar
Marco Martin committed
34

35
36
37
38
39
        Kirigami.InlineMessage {
            id: antiAliasingMessage
            Layout.fillWidth: true
            showCloseButton: true
            text: i18n("Some changes such as anti-aliasing or DPI will only affect newly started applications.")
Marco Martin's avatar
Marco Martin committed
40

41
42
43
44
            Connections {
                target: kcm.fontAASettings
                onAliasingChangeApplied: antiAliasingMessage.visible = true
            }
Marco Martin's avatar
Marco Martin committed
45
46
        }

47
48
49
        Kirigami.FormLayout {
            id: formLayout
            readonly property int maxImplicitWidth: Math.max(adjustAllFontsButton.implicitWidth, excludeField.implicitWidth, subPixelCombo.implicitWidth, hintingCombo.implicitWidth)
Marco Martin's avatar
Marco Martin committed
50

51
52
53
54
55
            QtControls.Button {
                id: adjustAllFontsButton
                Layout.preferredWidth: formLayout.maxImplicitWidth
                icon.name: "font-select-symbolic"
                text: i18n("&Adjust All Fonts...")
Marco Martin's avatar
Marco Martin committed
56

57
58
                onClicked: kcm.adjustAllFonts();
            }
Marco Martin's avatar
Marco Martin committed
59

60
61
62
            FontWidget {
                id: generalFontWidget
                label: i18n("General:")
Benjamin Port's avatar
Benjamin Port committed
63
64
                category: "font"
                font: kcm.fontsSettings.font
65
66
67
            }
            FontWidget {
                label: i18n("Fixed width:")
Benjamin Port's avatar
Benjamin Port committed
68
69
                category: "fixed"
                font: kcm.fontsSettings.fixed
70
71
72
            }
            FontWidget {
                label: i18n("Small:")
Benjamin Port's avatar
Benjamin Port committed
73
74
                category: "smallestReadableFont"
                font: kcm.fontsSettings.smallestReadableFont
75
76
77
            }
            FontWidget {
                label: i18n("Toolbar:")
Benjamin Port's avatar
Benjamin Port committed
78
79
                category: "toolBarFont"
                font: kcm.fontsSettings.toolBarFont
80
81
82
83
            }
            FontWidget {
                label: i18n("Menu:")
                category: "menuFont"
Benjamin Port's avatar
Benjamin Port committed
84
                font: kcm.fontsSettings.menuFont
85
86
87
            }
            FontWidget {
                label: i18n("Window title:")
Benjamin Port's avatar
Benjamin Port committed
88
89
                category: "activeFont"
                font: kcm.fontsSettings.activeFont
Marco Martin's avatar
Marco Martin committed
90
91
            }

92
93
            Kirigami.Separator {
                Kirigami.FormData.isSection: true
Marco Martin's avatar
Marco Martin committed
94
95
            }

96
97
98
99
100
101
102
            QtControls.CheckBox {
                id: antiAliasingCheckBox
                checked: kcm.fontAASettings.antiAliasing
                onCheckedChanged: kcm.fontAASettings.antiAliasing = checked
                Kirigami.FormData.label: i18n("Anti-Aliasing:")
                text: i18n("Enable")
                Layout.fillWidth: true
Marco Martin's avatar
Marco Martin committed
103
            }
104
105
106
107
108
109
110
111

            QtControls.CheckBox {
                id: excludeCheckBox
                checked: kcm.fontAASettings.exclude
                onCheckedChanged: kcm.fontAASettings.exclude = checked;
                text: i18n("Exclude range from anti-aliasing")
                Layout.fillWidth: true
                enabled: antiAliasingCheckBox.checked
Marco Martin's avatar
Marco Martin committed
112
113
            }

114
115
116
117
118
119
120
121
122
            RowLayout {
                id: excludeField
                Layout.preferredWidth: formLayout.maxImplicitWidth
                enabled: antiAliasingCheckBox.checked
                QtControls.SpinBox {
                    id: excludeFromSpinBox
                    stepSize: 1
                    onValueChanged: kcm.fontAASettings.excludeFrom = value
                    textFromValue: function(value, locale) { return i18n("%1 pt", value)}
Nate Graham's avatar
Nate Graham committed
123
124
                    valueFromText: function(text, locale) { return parseInt(text) }
                    editable: true
125
                    enabled: excludeCheckBox.checked
Julian Wolff's avatar
Julian Wolff committed
126
                }
127
128
129
130
131
132
133
134
135
136
137
138
139

                QtControls.Label {
                    Layout.fillWidth: true
                    horizontalAlignment: Text.AlignHCenter
                    text: i18n("to")
                    enabled: excludeCheckBox.checked
                }

                QtControls.SpinBox {
                    id: excludeToSpinBox
                    stepSize: 1
                    onValueChanged: kcm.fontAASettings.excludeTo = value
                    textFromValue: function(value, locale) { return i18n("%1 pt", value)}
Nate Graham's avatar
Nate Graham committed
140
141
                    valueFromText: function(text, locale) { return parseInt(text) }
                    editable: true
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
                    enabled: excludeCheckBox.checked
                }
                Connections {
                    target: kcm.fontAASettings
                    onExcludeFromChanged: excludeFromSpinBox.value = kcm.fontAASettings.excludeFrom;
                    onExcludeToChanged: excludeToSpinBox.value = kcm.fontAASettings.excludeTo;
                }
            }

            QtControls.ComboBox {
                id: subPixelCombo
                Layout.preferredWidth: formLayout.maxImplicitWidth
                Kirigami.FormData.label: i18nc("Used as a noun, and precedes a combobox full of options", "Sub-pixel rendering:")
                currentIndex: kcm.fontAASettings.subPixelCurrentIndex
                onCurrentIndexChanged: kcm.fontAASettings.subPixelCurrentIndex = currentIndex;
                model: kcm.fontAASettings.subPixelOptionsModel
                textRole: "display"
                enabled: antiAliasingCheckBox.checked
                popup.height: popup.implicitHeight
                delegate: QtControls.ItemDelegate {
                    id: subPixelDelegate
                    onWidthChanged: {
                        subPixelCombo.popup.width = Math.max(subPixelCombo.popup.width, width)
Julian Wolff's avatar
Julian Wolff committed
165
                    }
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
                    contentItem: ColumnLayout {
                        id: subPixelLayout
                        Kirigami.Heading {
                            id: subPixelComboText
                            text: model.display
                            level: 5
                        }
                        Image {
                            id: subPixelComboImage
                            source: "image://preview/" + model.index + "_" + kcm.fontAASettings.hintingCurrentIndex + ".png"
                            // Setting sourceSize here is necessary as a workaround for QTBUG-38127
                            //
                            // With this bug, images requested from a QQuickImageProvider have an incorrect scale with devicePixelRatio != 1 when sourceSize is not set.
                            //
                            // TODO: Check if QTBUG-38127 is fixed and remove the next two lines.
                            sourceSize.width: 1
                            sourceSize.height: 1
                        }
Julian Wolff's avatar
Julian Wolff committed
184
185
186
                    }
                }
            }
Marco Martin's avatar
Marco Martin committed
187

188
189
190
191
192
193
194
195
196
197
198
199
200
201
            QtControls.ComboBox {
                id: hintingCombo
                Layout.preferredWidth: formLayout.maxImplicitWidth
                Kirigami.FormData.label: i18nc("Used as a noun, and precedes a combobox full of options", "Hinting:")
                currentIndex: kcm.fontAASettings.hintingCurrentIndex
                onCurrentTextChanged: kcm.fontAASettings.hintingCurrentIndex = currentIndex;
                model: kcm.fontAASettings.hintingOptionsModel
                textRole: "display"
                enabled: antiAliasingCheckBox.checked
                popup.height: popup.implicitHeight
                delegate: QtControls.ItemDelegate {
                    id: hintingDelegate
                    onWidthChanged: {
                        hintingCombo.popup.width = Math.max(hintingCombo.popup.width, width)
Julian Wolff's avatar
Julian Wolff committed
202
                    }
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
                    contentItem: ColumnLayout {
                        id: hintingLayout
                        Kirigami.Heading {
                            id: hintingComboText
                            text: model.display
                            level: 5
                        }
                        Image {
                            id: hintingComboImage
                            source: "image://preview/" + kcm.fontAASettings.subPixelCurrentIndex + "_" + model.index + ".png"
                            // Setting sourceSize here is necessary as a workaround for QTBUG-38127
                            //
                            // With this bug, images requested from a QQuickImageProvider have an incorrect scale with devicePixelRatio != 1 when sourceSize is not set.
                            //
                            // TODO: Check if QTBUG-38127 is fixed and remove the next two lines.
                            sourceSize.width: 1
                            sourceSize.height: 1
                        }
Julian Wolff's avatar
Julian Wolff committed
221
222
223
                    }
                }
            }
Marco Martin's avatar
Marco Martin committed
224

225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
            RowLayout {
                QtControls.CheckBox {
                    id: dpiCheckBox
                    checked: kcm.fontAASettings.dpi !== 0
                    text: i18n("Force font DPI:")
                    onClicked: kcm.fontAASettings.dpi = (checked ? dpiSpinBox.value : 0)
                }

                QtControls.SpinBox {
                    id: dpiSpinBox
                    stepSize: 24
                    editable: true
                    enabled: dpiCheckBox.checked
                    value: kcm.fontAASettings.dpi !== 0 ? kcm.fontAASettings.dpi : 96
                    onValueModified: kcm.fontAASettings.dpi = value
240
241
242
243
                    // to: need to divide to stepSize
                    to: 1008
                    // lowest vaue here can be == stepSize, that is because 0 means off
                    from: 24
244
                }
Marco Martin's avatar
Marco Martin committed
245
246
            }

247
248
249
250
251
252
253
254
255
256
            QtDialogs.FontDialog {
                id: fontDialog
                title: i18n("Select Font")
                modality: Qt.WindowModal
                property string currentCategory
                property bool adjustAllFonts: false
                onAccepted: {
                    if (adjustAllFonts) {
                        kcm.adjustAllFonts(font);
                    } else {
Benjamin Port's avatar
Benjamin Port committed
257
                        kcm.fontsSettings[currentCategory] = font;
258
                    }
Marco Martin's avatar
Marco Martin committed
259
260
261
262
263
                }
            }
        }
    }
}