MauiKit Controls

FontPicker.qml
1/*
2 * Copyright 2020 Camilo Higuita <milo.h@aol.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20
21import QtQuick
22import QtQuick.Controls
23import QtQuick.Layouts
24
25import org.mauikit.controls 1.3 as Maui
26
27/**
28 * @inherit QtQuick.Controls.Control
29 * @brief A custom control use to pick a font and its properties.
30 *
31 * <a href="https://doc.qt.io/qt-6/qml-qtquick-controls-control.html">This controls inherits from QQC2 Control, to checkout its inherited properties refer to the Qt Docs.</a>
32 *
33 * @image html Misc/fontpicker.png
34 *
35 * The FontPicker controls allows to pick a font and its derived properties - there is an extra option to restrain the listing to only mono-spaced fonts, using the model property `model.onlyMonospaced`. This option is visually exposed in the control with a Switch toggle.
36 *
37 * The control includes a section to display a text paragraph using the selected font and its properties. The example text is a text area where more text can be typed.
38 *
39 * @code
40 * Maui.Page
41 * {
42 * id: _page
43 *
44 * anchors.fill: parent
45 * Maui.Controls.showCSD: true
46 *
47 * Maui.FontPicker
48 * {
49 * anchors.fill: parent
50 * }
51 * }
52 * @endcode
53 *
54 * <a href="https://invent.kde.org/maui/mauikit/-/blob/qt6-2/examples/FontPicker.qml">You can find a more complete example at this link.</a>
55 *
56 */
57Control
58{
59 id: control
60
61 implicitHeight: _layout.implicitHeight + topPadding + bottomPadding
62 padding: 0
64 /**
65 * @brief The model used to list the fonts. It is exposed to access its internal properties.
66 * @see FontPickerModel
67 * @property FontPickerModel FontPicker::model
68 */
69 readonly property alias model : _model
70
71 /**
72 * @brief The current font picked.
73 * @property font FontPicker::mfont
74 */
75 property alias mfont : _model.font
77 spacing: Maui.Style.space.medium
78
79 /**
80 * @brief Emitted when a new font has been picked or its properties have been modified.
81 * @param font The font object of the newly modified font.
82 */
83 signal fontModified(var font)
84
85 Maui.FontPickerModel
86 {
87 id: _model
88 }
89
90 contentItem: ColumnLayout
91 {
92 id: _layout
93 spacing: control.spacing
94
95 Maui.FlexSectionItem
96 {
97 label1.text: i18n ("Family")
98 label2.text: i18n("Pick the font family.")
99 wide: control.width > 600
100
101 Maui.FontsComboBox
102 {
103 Layout.fillWidth: true
104 Component.onCompleted: currentIndex = find(control.mfont.family, Qt.MatchExactly)
105 model: _model.fontsModel
106
107 onActivated:
108 {
109 let newFont = control.mfont
110 newFont.family = currentText
111
112 control.mfont = newFont
113 control.fontModified(control.mfont)
114 }
115 }
116 }
117
118 Maui.FlexSectionItem
119 {
120 label1.text: i18n("Style")
121 label2.text: i18n("Font style.")
122 wide: control.width > 600
123
124 ComboBox
125 {
126 Layout.fillWidth: true
127 model: _model.styles
128 Component.onCompleted: currentIndex = find(control.mfont.styleName, Qt.MatchExactly)
129 icon.source: "format-text-color"
130 onActivated:
131 {
132 control.mfont.styleName = currentText
133 control.fontModified(control.mfont)
134 }
135 }
136 }
137
138 Maui.FlexSectionItem
139 {
140 label1.text: i18n("Size")
141 label2.text: i18n("Font size from recommended values.")
142 wide: control.width > 600
143
144 ComboBox
145 {
146 Layout.fillWidth: true
147 model: _model.sizes
148 Component.onCompleted: currentIndex = find(control.mfont.pointSize, Qt.MatchExactly)
149 icon.source: "font-size-down"
150 onActivated:
151 {
152 control.mfont.pointSize = currentText
153 control.fontModified(control.mfont)
154 }
155 }
156 }
157
158 Maui.FlexSectionItem
159 {
160 label1.text: i18n("Monospaced Fonts")
161 label2.text: i18n("Display only monospaced fonts.")
162
163 Switch
164 {
165 checked: control.model.onlyMonospaced
166 onToggled: control.model.onlyMonospaced = !control.model.onlyMonospaced
167 }
168 }
169
170 Maui.SectionItem
171 {
172 label1.text: i18n("Preview")
173 label2.text: i18n("Test the font.")
174
175 TextArea
176 {
177 Layout.fillWidth: true
178 implicitHeight: contentHeight + topPadding + bottomPadding
179
180 text: i18n("The Quick Brown Fox Jumps Over The Lazy Dog")
181 font: control.mfont
182 }
183 }
184 }
185}
A combo-box element to list the system fonts with a inline style preview.
QString i18n(const char *text, const TYPE &arg...)
QAction * find(const QObject *recvr, const char *slot, QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:56:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.