diff --git a/utils/fgqcanvas/fgcanvastext.cpp b/utils/fgqcanvas/fgcanvastext.cpp index 029d72203..cf73552bd 100644 --- a/utils/fgqcanvas/fgcanvastext.cpp +++ b/utils/fgqcanvas/fgcanvastext.cpp @@ -145,6 +145,10 @@ void FGCanvasText::rebuildAlignment(QVariant var) const return; } + if (_quickItem) { + _quickItem->setProperty("canvasAlignment", alignString); + } + if (alignString == "center") { _alignment = Qt::AlignCenter; return; diff --git a/utils/fgqcanvas/fgqcanvasimage.cpp b/utils/fgqcanvas/fgqcanvasimage.cpp index 71407b4c6..cca0a64cf 100644 --- a/utils/fgqcanvas/fgqcanvasimage.cpp +++ b/utils/fgqcanvas/fgqcanvasimage.cpp @@ -39,8 +39,6 @@ class ImageQuickItem : public CanvasItem { Q_OBJECT - - public: ImageQuickItem(QQuickItem* parent) : CanvasItem(parent) diff --git a/utils/fgqcanvas/qml/text.qml b/utils/fgqcanvas/qml/text.qml index e5ff8e181..d97be4680 100644 --- a/utils/fgqcanvas/qml/text.qml +++ b/utils/fgqcanvas/qml/text.qml @@ -2,17 +2,80 @@ import QtQuick 2.0 import FlightGear 1.0 CanvasItem { - implicitHeight: text.implicitHeight - implicitWidth: text.implicitWidth + id: root +// implicitHeight: text.implicitHeight + // implicitWidth: text.implicitWidth property alias text: text.text property alias fontPixelSize: text.font.pixelSize property alias fontFamily: text.font.family property alias color: text.color + property string canvasAlignment: "center" + + property string __canvasVAlign: "center" + property string __canvasHAlign: "center" + + onCanvasAlignmentChanged: { + if (canvasAlignment == "center") { + __canvasVAlign = __canvasVAlign = "center"; + } else { + var pieces = canvasAlignment.split("-"); + __canvasHAlign = pieces[0] + __canvasVAlign = pieces[1] + } + } + Text { id: text - font.pixelSize: 20 - color: "yellow" + } + + Binding { + when: __canvasHAlign == "left" + target: text + property: "anchors.left" + value: root.left + } + + Binding { + when: __canvasHAlign == "right" + target: text + property: "anchors.right" + value: root.left + } + + Binding { + when: __canvasHAlign == "center" + target: text + property: "anchors.horizontalCenter" + value: root.left + } + + Binding { + when: __canvasVAlign == "top" + target: text + property: "anchors.top" + value: root.top + } + + Binding { + when: __canvasVAlign == "bottom" + target: text + property: "anchors.bottom" + value: root.top + } + + Binding { + when: __canvasVAlign == "center" + target: text + property: "anchors.verticalCenter" + value: root.top + } + + Binding { + when: __canvasVAlign == "baseline" + target: text + property: "anchors.baseline" + value: root.top } }