Adding font property and example C++ code for rendering font in bitmap.
Cleaning up our MiniDisplay signal names.
1.1 --- a/DisplayTab.qml Tue May 27 19:50:28 2014 +0200
1.2 +++ b/DisplayTab.qml Tue May 27 22:14:29 2014 +0200
1.3 @@ -11,12 +11,7 @@
1.4 //SystemPalette { id: palette }
1.5 clip: true
1.6 //
1.7 - MiniDisplay {
1.8 - id: display
1.9 - onMiniDisplayOpened:{ textDisplayStatus.text=qsTr("Connected"); buttonOpenClose.enabled = true;}
1.10 - onMiniDisplayClosed:textDisplayStatus.text=qsTr("Disconnected")
1.11 - onMiniDisplayOpenError:{ textDisplayStatus.text=qsTr("Connection error"); buttonOpenClose.enabled = true;}
1.12 - }
1.13 +
1.14
1.15 //
1.16 ColumnLayout {
2.1 --- a/FontsTab.qml Tue May 27 19:50:28 2014 +0200
2.2 +++ b/FontsTab.qml Tue May 27 22:14:29 2014 +0200
2.3 @@ -34,6 +34,7 @@
2.4 onAccepted: {
2.5 console.log("Accepted: " + font);
2.6 textFontDemoLowerCase.font = currentFont;
2.7 + display.font = currentFont;
2.8 //textFontDemoUpperCase.font = currentFont;
2.9 //textFontDemoDigits.font = currentFont;
2.10 }
3.1 --- a/MiniDisplay/minidisplay.cpp Tue May 27 19:50:28 2014 +0200
3.2 +++ b/MiniDisplay/minidisplay.cpp Tue May 27 22:14:29 2014 +0200
3.3 @@ -1,4 +1,5 @@
3.4 #include "minidisplay.h"
3.5 +#include <QPainter>
3.6
3.7 MiniDisplay::MiniDisplay(QQuickItem *parent):
3.8 QQuickItem(parent)
3.9 @@ -22,12 +23,12 @@
3.10 {
3.11 if (iDisplay.Open())
3.12 {
3.13 - emit miniDisplayOpened();
3.14 - emit miniDisplayStatusChanged();
3.15 + emit opened();
3.16 + emit statusChanged();
3.17 }
3.18 else
3.19 {
3.20 - emit miniDisplayOpenError();
3.21 + emit openError();
3.22 }
3.23 }
3.24
3.25 @@ -35,8 +36,8 @@
3.26 void MiniDisplay::close()
3.27 {
3.28 iDisplay.Close();
3.29 - emit miniDisplayClosed();
3.30 - emit miniDisplayStatusChanged();
3.31 + emit closed();
3.32 + emit statusChanged();
3.33 }
3.34
3.35 bool MiniDisplay::isOpen()
3.36 @@ -64,3 +65,26 @@
3.37 //
3.38 iDisplay.SwapBuffers();
3.39 }
3.40 +
3.41 +/**
3.42 + * @brief setFont
3.43 + * @param aFont
3.44 + */
3.45 +void MiniDisplay::setFont(const QFont& aFont)
3.46 +{
3.47 + iFont=aFont;
3.48 + QString strDemo="0123456789ABCDEF";
3.49 + QFontMetrics metrics(iFont);
3.50 + QSize size(metrics.width(strDemo),metrics.height());
3.51 + QImage image(size,QImage::Format_Mono);
3.52 + image.fill(0xFFFFFFFF);
3.53 + {
3.54 + QPainter painter(&image);
3.55 + //painter.begin(&image);
3.56 + painter.setPen(0xFF000000);
3.57 + painter.setFont(iFont);
3.58 + painter.drawText(0,metrics.ascent(),strDemo);
3.59 + }
3.60 + //painter.end();
3.61 + image.save("font.png");
3.62 +}
4.1 --- a/MiniDisplay/minidisplay.h Tue May 27 19:50:28 2014 +0200
4.2 +++ b/MiniDisplay/minidisplay.h Tue May 27 22:14:29 2014 +0200
4.3 @@ -9,23 +9,31 @@
4.4 Q_OBJECT
4.5 Q_DISABLE_COPY(MiniDisplay)
4.6 //
4.7 - Q_PROPERTY(bool isOpen READ isOpen NOTIFY miniDisplayStatusChanged)
4.8 + Q_PROPERTY(bool isOpen READ isOpen NOTIFY statusChanged)
4.9 + Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
4.10
4.11
4.12 public:
4.13 + //Methods
4.14 Q_INVOKABLE void open();
4.15 Q_INVOKABLE void close();
4.16 - bool isOpen();
4.17 //
4.18 Q_INVOKABLE void clear();
4.19 Q_INVOKABLE void fill();
4.20 Q_INVOKABLE void swapBuffers();
4.21
4.22 +public:
4.23 + //Properties
4.24 + bool isOpen();
4.25 + QFont font() const {return iFont;}
4.26 + void setFont(const QFont& aFont);
4.27 +
4.28 signals:
4.29 - void miniDisplayOpened();
4.30 - void miniDisplayOpenError();
4.31 - void miniDisplayClosed();
4.32 - void miniDisplayStatusChanged();
4.33 + void opened();
4.34 + void openError();
4.35 + void closed();
4.36 + void statusChanged();
4.37 + void fontChanged();
4.38
4.39 public:
4.40 MiniDisplay(QQuickItem *parent = 0);
4.41 @@ -33,6 +41,7 @@
4.42
4.43 private:
4.44 GP1212A01A iDisplay;
4.45 + QFont iFont;
4.46 };
4.47
4.48 #endif // MINIDISPLAY_H
5.1 --- a/main.qml Tue May 27 19:50:28 2014 +0200
5.2 +++ b/main.qml Tue May 27 22:14:29 2014 +0200
5.3 @@ -5,6 +5,8 @@
5.4 import QtQuick.Dialogs 1.2
5.5 import QtQuick.Window 2.1
5.6 import Qt.labs.settings 1.0
5.7 +import MiniDisplay 1.0
5.8 +
5.9
5.10
5.11 ApplicationWindow {
5.12 @@ -34,6 +36,13 @@
5.13
5.14 }*/
5.15
5.16 + MiniDisplay {
5.17 + id: display
5.18 + onOpened:{ textDisplayStatus.text=qsTr("Connected");}
5.19 + onClosed:textDisplayStatus.text=qsTr("Disconnected")
5.20 + onOpenError:{ textDisplayStatus.text=qsTr("Connection error");}
5.21 + }
5.22 +
5.23 TabView {
5.24 anchors.fill: parent
5.25 anchors.margins: 8