1
0
Fork 0

Text alignment support mostly working

Baseline is still being strange, possibly need to use an
AnchorChange instead of multiple Binding elements
This commit is contained in:
James Turner 2017-02-17 08:16:48 -08:00
parent 928fd31f2c
commit 905d8ae734
3 changed files with 71 additions and 6 deletions

View file

@ -145,6 +145,10 @@ void FGCanvasText::rebuildAlignment(QVariant var) const
return;
}
if (_quickItem) {
_quickItem->setProperty("canvasAlignment", alignString);
}
if (alignString == "center") {
_alignment = Qt::AlignCenter;
return;

View file

@ -39,8 +39,6 @@ class ImageQuickItem : public CanvasItem
{
Q_OBJECT
public:
ImageQuickItem(QQuickItem* parent)
: CanvasItem(parent)

View file

@ -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
}
}