FontsTab.qml
author sl
Tue, 17 Jun 2014 09:49:12 +0200
changeset 36 f2a9369e7fb9
parent 14 9903a5edeb56
permissions -rw-r--r--
Adding reset function called when changing font.
     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.clear();
    38             display.font = currentFont;
    39             display.swapBuffers();
    40             //textFontDemoUpperCase.font = currentFont;
    41             //textFontDemoDigits.font = currentFont;
    42         }
    43         //onRejected: { console.log("Rejected") }
    44     }
    45     //
    46     ColumnLayout {
    47         anchors.fill: parent
    48         anchors.margins: 8
    49         spacing: 8
    50 
    51         Label {
    52             id: fontLabel
    53             text: "Current font: <b>" + textFontDemoLowerCase.font.family + " - " + textFontDemoLowerCase.font.pointSize +"</b>"
    54             MouseArea {
    55                 anchors.fill: parent
    56                 onClicked: fontDialog.open()
    57             }
    58         }
    59 
    60         ColumnLayout {
    61             anchors.margins: 0
    62             spacing: 0
    63 
    64             Label {
    65                 id: textFontDemoLowerCase
    66                 anchors.margins: 0
    67                 text: "abcdefghijklmnopqrstyvwxyz"
    68                 font: Qt.font({ family: "Arial", pointSize: 16, weight: Font.Normal })
    69             }
    70 
    71             Label {
    72                 id: textFontDemoUpperCase
    73                 anchors.margins: 0
    74                 text: "ABCDEFGHIJKLMNOPQRSTYVWXYZ"
    75                 font: textFontDemoLowerCase.font
    76             }
    77 
    78             Label {
    79                 id: textFontDemoDigits
    80                 anchors.margins: 0
    81                 text: "0123456789"
    82                 font: textFontDemoLowerCase.font
    83             }
    84         }
    85 
    86         //Font selection options
    87         GridLayout {
    88             anchors.margins: 8
    89             columns: 2
    90             columnSpacing: 8
    91 
    92             CheckBox {
    93                 id: checkBoxScalableFonts
    94                 text: "Scalable fonts"
    95                 checked: true
    96                 //Binding on checked { value: fontDialog.scalableFonts }
    97             }
    98             CheckBox {
    99                 id: checkBoxNonScalableFonts
   100                 text: "Non scalable fonts"
   101                 checked: true
   102                 //Binding on checked { value: fontDialog.nonScalableFonts }
   103             }
   104             CheckBox {
   105                 id: checkBoxMonospacedFonts
   106                 text: "Monospaced fonts"
   107                 checked: true
   108                 //Binding on checked { value: fontDialog.monospacedFonts }
   109             }
   110             CheckBox {
   111                 id: checkBoxProportionalFonts
   112                 text: "Proportional fonts"
   113                 checked: true
   114                 //Binding on checked { value: fontDialog.proportionalFonts }
   115             }
   116         }
   117 
   118 
   119 
   120         Button {
   121             text: qsTr("Change font")
   122             onClicked: {
   123                 //We had to do this double magic cause otherwise our font list
   124                 //would not reflect our options.
   125                 fontDialog.setVisible(true);
   126                 fontDialog.open();
   127             }
   128         }
   129     } //ColumnLayout
   130 } //Item