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:
parent
928fd31f2c
commit
905d8ae734
3 changed files with 71 additions and 6 deletions
|
@ -145,6 +145,10 @@ void FGCanvasText::rebuildAlignment(QVariant var) const
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_quickItem) {
|
||||||
|
_quickItem->setProperty("canvasAlignment", alignString);
|
||||||
|
}
|
||||||
|
|
||||||
if (alignString == "center") {
|
if (alignString == "center") {
|
||||||
_alignment = Qt::AlignCenter;
|
_alignment = Qt::AlignCenter;
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -39,8 +39,6 @@ class ImageQuickItem : public CanvasItem
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ImageQuickItem(QQuickItem* parent)
|
ImageQuickItem(QQuickItem* parent)
|
||||||
: CanvasItem(parent)
|
: CanvasItem(parent)
|
||||||
|
|
|
@ -2,17 +2,80 @@ import QtQuick 2.0
|
||||||
import FlightGear 1.0
|
import FlightGear 1.0
|
||||||
|
|
||||||
CanvasItem {
|
CanvasItem {
|
||||||
implicitHeight: text.implicitHeight
|
id: root
|
||||||
implicitWidth: text.implicitWidth
|
// implicitHeight: text.implicitHeight
|
||||||
|
// implicitWidth: text.implicitWidth
|
||||||
|
|
||||||
property alias text: text.text
|
property alias text: text.text
|
||||||
property alias fontPixelSize: text.font.pixelSize
|
property alias fontPixelSize: text.font.pixelSize
|
||||||
property alias fontFamily: text.font.family
|
property alias fontFamily: text.font.family
|
||||||
property alias color: text.color
|
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 {
|
Text {
|
||||||
id: 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue