forked from qt-creator/qt-creator
QmlDesigner: Add transition item label
* Add label to transition item * Change signature of drawArrow() Task-number: QDS-2085 Change-Id: Ia719958ead404ea083a15fdee440a8e6a306ee62 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
committed by
Thomas Hartmann
parent
c9b5671754
commit
d1728fbb6b
@@ -26,6 +26,7 @@
|
|||||||
#include "formeditoritem.h"
|
#include "formeditoritem.h"
|
||||||
#include "formeditorscene.h"
|
#include "formeditorscene.h"
|
||||||
|
|
||||||
|
#include <variantproperty.h>
|
||||||
#include <bindingproperty.h>
|
#include <bindingproperty.h>
|
||||||
|
|
||||||
#include <modelnode.h>
|
#include <modelnode.h>
|
||||||
@@ -814,8 +815,46 @@ static bool horizontalOverlap(const QRectF &from, const QRectF &to)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void drawLabel(QPainter *painter,
|
||||||
|
const QPainterPath &path,
|
||||||
|
const QString &text,
|
||||||
|
const qreal percent,
|
||||||
|
const qreal offset,
|
||||||
|
bool flipSide)
|
||||||
|
{
|
||||||
|
if (text.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
const int flags = Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextDontClip;
|
||||||
|
|
||||||
|
QPointF pos = path.pointAtPercent(percent);
|
||||||
|
qreal angle = path.angleAtPercent(percent);
|
||||||
|
|
||||||
|
QLineF tmp(pos, QPointF(10, 10));
|
||||||
|
tmp.setLength(offset);
|
||||||
|
tmp.setAngle(angle + (flipSide ? 270 : 90));
|
||||||
|
|
||||||
|
QRectF textRect(0, 0, 100, 50);
|
||||||
|
textRect.moveCenter(tmp.p2());
|
||||||
|
|
||||||
|
auto normalizeAngle = [](int angle) {
|
||||||
|
int newAngle = angle;
|
||||||
|
while (newAngle <= -90) newAngle += 180;
|
||||||
|
while (newAngle > 90) newAngle -= 180;
|
||||||
|
return newAngle;
|
||||||
|
};
|
||||||
|
|
||||||
|
painter->save();
|
||||||
|
painter->translate(textRect.center());
|
||||||
|
painter->rotate(-normalizeAngle(angle));
|
||||||
|
painter->translate(-textRect.center());
|
||||||
|
painter->drawText(textRect, flags, text);
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
static void drawArrow(QPainter *painter,
|
static void drawArrow(QPainter *painter,
|
||||||
const QLineF &line,
|
const QPointF &point,
|
||||||
|
const qreal &angle,
|
||||||
int arrowLength,
|
int arrowLength,
|
||||||
int arrowWidth)
|
int arrowWidth)
|
||||||
{
|
{
|
||||||
@@ -825,8 +864,8 @@ static void drawArrow(QPainter *painter,
|
|||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
painter->translate(line.p2());
|
painter->translate(point);
|
||||||
painter->rotate(-line.angle());
|
painter->rotate(-angle);
|
||||||
painter->drawLine(leftP, peakP);
|
painter->drawLine(leftP, peakP);
|
||||||
painter->drawLine(rightP, peakP);
|
painter->drawLine(rightP, peakP);
|
||||||
|
|
||||||
@@ -1029,7 +1068,8 @@ static QPainterPath sShapedConnection(const QPointF &start,
|
|||||||
static void paintConnection(QPainter *painter,
|
static void paintConnection(QPainter *painter,
|
||||||
const QRectF &from,
|
const QRectF &from,
|
||||||
const QRectF &to,
|
const QRectF &to,
|
||||||
const ConnectionStyle &style)
|
const ConnectionStyle &style,
|
||||||
|
const QString &label)
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
@@ -1126,11 +1166,18 @@ static void paintConnection(QPainter *painter,
|
|||||||
pen.setStyle(Qt::SolidLine);
|
pen.setStyle(Qt::SolidLine);
|
||||||
painter->setPen(pen);
|
painter->setPen(pen);
|
||||||
|
|
||||||
drawArrow(painter, QLineF(path.pointAtPercent(0.9), endP), arrowLength, arrowWidth);
|
qreal anglePercent = 1.0;
|
||||||
|
|
||||||
|
if (extraLine && style.bezier < 80)
|
||||||
|
anglePercent = 1.0 - qMin(1.0, (80 - style.bezier) / 10.0) * 0.05;
|
||||||
|
|
||||||
|
drawArrow(painter, endP, path.angleAtPercent(anglePercent), arrowLength, arrowWidth);
|
||||||
|
|
||||||
painter->setBrush(Qt::white);
|
painter->setBrush(Qt::white);
|
||||||
painter->drawEllipse(startP, arrowLength / 3, arrowLength / 3);
|
painter->drawEllipse(startP, arrowLength / 3, arrowLength / 3);
|
||||||
|
|
||||||
|
drawLabel(painter, path, label, style.labelPosition / 100.0, style.labelOffset, style.labelFlipSide);
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1260,10 +1307,35 @@ void FormEditorTransitionItem::paint(QPainter *painter, const QStyleOptionGraphi
|
|||||||
if (qmlItemNode().modelNode().hasAuxiliaryData("type"))
|
if (qmlItemNode().modelNode().hasAuxiliaryData("type"))
|
||||||
style.type = static_cast<ConnectionType>(qmlItemNode().modelNode().auxiliaryData("type").toInt());
|
style.type = static_cast<ConnectionType>(qmlItemNode().modelNode().auxiliaryData("type").toInt());
|
||||||
|
|
||||||
|
|
||||||
|
QFont font = painter->font();
|
||||||
|
font.setPixelSize(16 / scaleFactor);
|
||||||
|
painter->setFont(font);
|
||||||
|
|
||||||
|
QString label;
|
||||||
|
|
||||||
|
if (qmlItemNode().modelNode().hasBindingProperty("condition"))
|
||||||
|
label = qmlItemNode().modelNode().bindingProperty("condition").expression();
|
||||||
|
|
||||||
|
if (qmlItemNode().modelNode().hasVariantProperty("question"))
|
||||||
|
label = qmlItemNode().modelNode().variantProperty("question").value().toString();
|
||||||
|
|
||||||
|
style.labelOffset = 14 / scaleFactor;
|
||||||
|
|
||||||
|
style.labelPosition = 50.0;
|
||||||
|
|
||||||
|
if (qmlItemNode().modelNode().hasAuxiliaryData("labelPosition"))
|
||||||
|
style.labelPosition = qmlItemNode().modelNode().auxiliaryData("labelPosition").toReal();
|
||||||
|
|
||||||
|
style.labelFlipSide = false;
|
||||||
|
|
||||||
|
if (qmlItemNode().modelNode().hasAuxiliaryData("labelFlipSide"))
|
||||||
|
style.labelFlipSide = qmlItemNode().modelNode().auxiliaryData("labelFlipSide").toBool();
|
||||||
|
|
||||||
if (resolved.isStartLine)
|
if (resolved.isStartLine)
|
||||||
fromRect.translate(0, style.outOffset);
|
fromRect.translate(0, style.outOffset);
|
||||||
|
|
||||||
paintConnection(painter, fromRect, toRect, style);
|
paintConnection(painter, fromRect, toRect, style, label);
|
||||||
|
|
||||||
if (resolved.isStartLine) {
|
if (resolved.isStartLine) {
|
||||||
|
|
||||||
|
@@ -66,6 +66,9 @@ public:
|
|||||||
int radius;
|
int radius;
|
||||||
int bezier;
|
int bezier;
|
||||||
ConnectionType type;
|
ConnectionType type;
|
||||||
|
qreal labelOffset;
|
||||||
|
qreal labelPosition;
|
||||||
|
bool labelFlipSide;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QMLDESIGNERCORE_EXPORT FormEditorItem : public QGraphicsItem
|
class QMLDESIGNERCORE_EXPORT FormEditorItem : public QGraphicsItem
|
||||||
|
@@ -179,6 +179,10 @@ QVariant properDefaultAuxiliaryProperties(const QmlObjectNode &qmlObjectNode,
|
|||||||
return 50;
|
return 50;
|
||||||
else if (propertyName == "bezier")
|
else if (propertyName == "bezier")
|
||||||
return 50;
|
return 50;
|
||||||
|
else if (propertyName == "labelPosition")
|
||||||
|
return 50.0;
|
||||||
|
else if (propertyName == "labelFlipSide")
|
||||||
|
return false;
|
||||||
else if (propertyName == "customId")
|
else if (propertyName == "customId")
|
||||||
return QString();
|
return QString();
|
||||||
else if (propertyName == "joinConnection")
|
else if (propertyName == "joinConnection")
|
||||||
@@ -248,7 +252,7 @@ void PropertyEditorQmlBackend::setupAuxiliaryProperties(const QmlObjectNode &qml
|
|||||||
propertyNames.append("customId");
|
propertyNames.append("customId");
|
||||||
|
|
||||||
if (itemNode.isFlowTransition()) {
|
if (itemNode.isFlowTransition()) {
|
||||||
propertyNames.append({"color", "width", "inOffset", "outOffset", "dash", "breakPoint", "type", "radius", "bezier"});
|
propertyNames.append({"color", "width", "inOffset", "outOffset", "dash", "breakPoint", "type", "radius", "bezier", "labelPosition", "labelFlipSide"});
|
||||||
} else if (itemNode.isFlowItem()) {
|
} else if (itemNode.isFlowItem()) {
|
||||||
propertyNames.append({"color", "width", "inOffset", "outOffset", "joinConnection"});
|
propertyNames.append({"color", "width", "inOffset", "outOffset", "joinConnection"});
|
||||||
} else if (itemNode.isFlowActionArea()) {
|
} else if (itemNode.isFlowActionArea()) {
|
||||||
|
Reference in New Issue
Block a user