Warning, /maui/mauikit/src/controls.6/FontPicker.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *   Copyright 2020 Camilo Higuita <milo.h@aol.com>
0003  *
0004  *   This program is free software; you can redistribute it and/or modify
0005  *   it under the terms of the GNU Library General Public License as
0006  *   published by the Free Software Foundation; either version 2, or
0007  *   (at your option) any later version.
0008  *
0009  *   This program is distributed in the hope that it will be useful,
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *   GNU General Public License for more details
0013  *
0014  *   You should have received a copy of the GNU Library General Public
0015  *   License along with this program; if not, write to the
0016  *   Free Software Foundation, Inc.,
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018  */
0019 
0020 
0021 import QtQuick
0022 import QtQuick.Controls
0023 import QtQuick.Layouts
0024 
0025 import org.mauikit.controls 1.3 as Maui
0026 
0027 /**
0028  * @inherit QtQuick.Controls.Control
0029  * @brief A custom control use to pick a font and its properties.
0030  * 
0031  * <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>
0032  * 
0033  * @image html Misc/fontpicker.png
0034  * 
0035  * 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.
0036  * 
0037  * 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.
0038  * 
0039  * @code
0040  * Maui.Page
0041  * {
0042  *    id: _page
0043  * 
0044  *    anchors.fill: parent
0045  *    Maui.Controls.showCSD: true
0046  * 
0047  *    Maui.FontPicker
0048  *    {
0049  *        anchors.fill: parent
0050  *    }
0051  * } 
0052  * @endcode
0053  * 
0054  *  <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>
0055  * 
0056  */
0057 Control
0058 {
0059     id: control
0060     
0061     implicitHeight: _layout.implicitHeight + topPadding + bottomPadding
0062     padding: 0
0063     
0064     /**
0065      * @brief The model used to list the fonts. It is exposed to access its internal properties.
0066      * @see FontPickerModel
0067      * @property FontPickerModel FontPicker::model
0068      */
0069     readonly property alias model : _model
0070     
0071     /**
0072      * @brief The current font picked. 
0073      * @property font FontPicker::mfont
0074      */
0075     property alias mfont : _model.font
0076     
0077     spacing: Maui.Style.space.medium
0078     
0079     /**
0080      * @brief Emitted when a new font has been picked or its properties have been modified.
0081      * @param font The font object of the newly modified font.
0082      */
0083     signal fontModified(var font)
0084     
0085     Maui.FontPickerModel
0086     {
0087         id: _model
0088     }
0089     
0090     contentItem: ColumnLayout
0091     {
0092         id: _layout
0093         spacing: control.spacing
0094         
0095         Maui.FlexSectionItem
0096         {
0097             label1.text: i18n ("Family")
0098             label2.text: i18n("Pick the font family.")
0099             wide: control.width > 600
0100             
0101             Maui.FontsComboBox
0102             {
0103                 Layout.fillWidth: true
0104                 Component.onCompleted: currentIndex = find(control.mfont.family, Qt.MatchExactly)
0105                 model: _model.fontsModel
0106                 
0107                 onActivated:
0108                 {
0109                     let newFont = control.mfont
0110                     newFont.family = currentText
0111                     
0112                     control.mfont = newFont
0113                     control.fontModified(control.mfont)
0114                 }
0115             }
0116         }
0117         
0118         Maui.FlexSectionItem
0119         {
0120             label1.text: i18n("Style")
0121             label2.text: i18n("Font style.")
0122             wide: control.width > 600
0123             
0124             ComboBox
0125             {
0126                 Layout.fillWidth: true
0127                 model: _model.styles
0128                 Component.onCompleted: currentIndex = find(control.mfont.styleName, Qt.MatchExactly)
0129                 icon.source: "format-text-color"
0130                 onActivated:
0131                 {
0132                     control.mfont.styleName = currentText
0133                     control.fontModified(control.mfont)
0134                 }
0135             }
0136         }
0137         
0138         Maui.FlexSectionItem
0139         {
0140             label1.text: i18n("Size")
0141             label2.text: i18n("Font size from recommended values.")
0142             wide: control.width > 600
0143             
0144             ComboBox
0145             {
0146                 Layout.fillWidth: true
0147                 model: _model.sizes
0148                 Component.onCompleted: currentIndex = find(control.mfont.pointSize, Qt.MatchExactly)
0149                 icon.source: "font-size-down"
0150                 onActivated:
0151                 {
0152                     control.mfont.pointSize = currentText
0153                     control.fontModified(control.mfont)
0154                 }
0155             }
0156         }
0157         
0158         Maui.FlexSectionItem
0159         {
0160             label1.text: i18n("Monospaced Fonts")
0161             label2.text: i18n("Display only monospaced fonts.")
0162             
0163             Switch
0164             {
0165                 checked: control.model.onlyMonospaced
0166                 onToggled: control.model.onlyMonospaced = !control.model.onlyMonospaced
0167             }
0168         }
0169         
0170         Maui.SectionItem
0171         {
0172             label1.text: i18n("Preview")
0173             label2.text: i18n("Test the font.")
0174             
0175             TextArea
0176             {
0177                 Layout.fillWidth: true
0178                 implicitHeight: contentHeight + topPadding + bottomPadding
0179                 
0180                 text: i18n("The Quick Brown Fox Jumps Over The Lazy Dog")
0181                 font: control.mfont
0182             }
0183         }
0184     }
0185 }