FontsTab.qml
author sl
Wed, 28 May 2014 21:31:03 +0200
changeset 14 9903a5edeb56
parent 13 40da62e57d85
child 15 737f8bb110be
permissions -rw-r--r--
Working around our font dialog option listing issues.
Font dialog options are now persisted.
Fixing issue with italic font being cut by using proper string width from boundigRect.
     1 import QtQuick 2.2
     2 import QtQuick.Controls 1.2
     3 import QtQuick.Dialogs 1.1
     4 import QtQuick.Layouts 1.1
     5 import Qt.labs.settings 1.0
     6 
     7 Item {
     8     clip: true
     9     //
    10     Settings {
    11         property alias font: textFontDemoLowerCase.font;
    12         property alias checkBoxScalableFonts: checkBoxScalableFonts.checked
    13         property alias checkBoxNonScalableFonts: checkBoxNonScalableFonts.checked
    14         property alias checkBoxMonospacedFonts: checkBoxMonospacedFonts.checked
    15         property alias checkBoxProportionalFonts: checkBoxProportionalFonts.checked
    16 
    17     }
    18 
    19 
    20     //
    21     FontDialog {
    22         id: fontDialog
    23         visible: false
    24         modality: Qt.WindowModal
    25         scalableFonts: checkBoxScalableFonts.checked
    26         nonScalableFonts: checkBoxNonScalableFonts.checked
    27         monospacedFonts: checkBoxMonospacedFonts.checked
    28         proportionalFonts: checkBoxProportionalFonts.checked
    29         title: qsTr("Choose a font")
    30         font: textFontDemoLowerCase.font
    31         currentFont: textFontDemoLowerCase.font
    32         //onCurrentFontChanged: { console.log("CurrentFontChanged: " + currentFont) }
    33         //onFontChanged: { console.log("FontChanged: " + font) }
    34         onAccepted: {
    35             //console.log("Accepted: " + font);
    36             textFontDemoLowerCase.font = currentFont;
    37             display.font = currentFont;
    38             //textFontDemoUpperCase.font = currentFont;
    39             //textFontDemoDigits.font = currentFont;
    40         }
    41         //onRejected: { console.log("Rejected") }
    42     }
    43     //
    44     ColumnLayout {
    45         anchors.fill: parent
    46         anchors.margins: 8
    47         spacing: 8
    48 
    49         Label {
    50             id: fontLabel
    51             text: "Current font: <b>" + textFontDemoLowerCase.font.family + " - " + textFontDemoLowerCase.font.pointSize +"</b>"
    52             MouseArea {
    53                 anchors.fill: parent
    54                 onClicked: fontDialog.open()
    55             }
    56         }
    57 
    58         ColumnLayout {
    59             anchors.margins: 0
    60             spacing: 0
    61 
    62             Label {
    63                 id: textFontDemoLowerCase
    64                 anchors.margins: 0
    65                 text: "abcdefghijklmnopqrstyvwxyz"
    66                 font: Qt.font({ family: "Arial", pointSize: 16, weight: Font.Normal })
    67             }
    68 
    69             Label {
    70                 id: textFontDemoUpperCase
    71                 anchors.margins: 0
    72                 text: "ABCDEFGHIJKLMNOPQRSTYVWXYZ"
    73                 font: textFontDemoLowerCase.font
    74             }
    75 
    76             Label {
    77                 id: textFontDemoDigits
    78                 anchors.margins: 0
    79                 text: "0123456789"
    80                 font: textFontDemoLowerCase.font
    81             }
    82         }
    83 
    84         //Font selection options
    85         GridLayout {
    86             anchors.margins: 8
    87             columns: 2
    88             columnSpacing: 8
    89 
    90             CheckBox {
    91                 id: checkBoxScalableFonts
    92                 text: "Scalable fonts"
    93                 checked: true
    94                 //Binding on checked { value: fontDialog.scalableFonts }
    95             }
    96             CheckBox {
    97                 id: checkBoxNonScalableFonts
    98                 text: "Non scalable fonts"
    99                 checked: true
   100                 //Binding on checked { value: fontDialog.nonScalableFonts }
   101             }
   102             CheckBox {
   103                 id: checkBoxMonospacedFonts
   104                 text: "Monospaced fonts"
   105                 checked: true
   106                 //Binding on checked { value: fontDialog.monospacedFonts }
   107             }
   108             CheckBox {
   109                 id: checkBoxProportionalFonts
   110                 text: "Proportional fonts"
   111                 checked: true
   112                 //Binding on checked { value: fontDialog.proportionalFonts }
   113             }
   114         }
   115 
   116 
   117 
   118         Button {
   119             text: qsTr("Change font")
   120             onClicked: {
   121                 //We had to do this double magic cause otherwise our font list
   122                 //would not reflect our options.
   123                 fontDialog.setVisible(true);
   124                 fontDialog.open();
   125             }
   126         }
   127     } //ColumnLayout
   128 } //Item