Commit 04ad9bb1 authored by Marco Bubke's avatar Marco Bubke
Browse files

First version of a feedback system in the formeditor

parent 2ce5d7d9
......@@ -110,6 +110,126 @@ void FormEditorGraphicsView::mouseReleaseEvent(QMouseEvent *event)
}
}
void FormEditorGraphicsView::drawForeground(QPainter *painter, const QRectF &/*rect*/ )
{
if (!m_feedbackNode.isValid())
return;
painter->save();
if (m_beginX != m_feedbackNode.instanceValue("x"))
painter->setPen(Qt::green);
else
painter->setPen(Qt::black);
painter->drawText(mapToScene(QPoint(2.0, 12.0)), QString("x: \t\t%1").arg(m_feedbackNode.instanceValue("x").toString()));
if (m_beginY != m_feedbackNode.instanceValue("y"))
painter->setPen(Qt::green);
else
painter->setPen(Qt::black);
painter->drawText(mapToScene(QPoint(2.0, 24.0)), QString("y: \t\t%1").arg(m_feedbackNode.instanceValue("y").toString()));
if (m_beginWidth != m_feedbackNode.instanceValue("width"))
painter->setPen(Qt::green);
else
painter->setPen(Qt::black);
painter->drawText(mapToScene(QPoint(2.0, 36.0)), QString("width: \t\t%1").arg(m_feedbackNode.instanceValue("width").toString()));
if (m_beginHeight != m_feedbackNode.instanceValue("height"))
painter->setPen(Qt::green);
else
painter->setPen(Qt::black);
painter->drawText(mapToScene(QPoint(2.0, 48.0)), QString("height:\t\t%1").arg(m_feedbackNode.instanceValue("height").toString()));
if (m_parentNode == m_feedbackNode.instanceParent()) {
if (m_feedbackNode.canReparent()) {
painter->setPen(Qt::black);
painter->drawText(mapToScene(QPoint(2.0, 60.0)), QString("Can reparent."));
} else {
painter->setPen(Qt::red);
painter->drawText(mapToScene(QPoint(2.0, 60.0)), QString("Cannot reparent."));
}
} else {
painter->setPen(Qt::yellow);
if (m_feedbackNode.instanceParent().id().isEmpty())
painter->drawText(mapToScene(QPoint(2.0, 60.0)), QString("Parent has changed."));
else
painter->drawText(mapToScene(QPoint(2.0, 60.0)), QString("Parent has changed to %1.").arg(m_feedbackNode.instanceParent().id()));
}
if (m_beginTopMargin != m_feedbackNode.instanceValue("anchors.leftMargin"))
painter->setPen(Qt::green);
else
painter->setPen(Qt::black);
painter->drawText(mapToScene(QPoint(2.0, 72.0)), QString("leftMargin: \t\t%1").arg(m_feedbackNode.instanceValue("anchors.leftMargin").toString()));
if (m_beginRightMargin != m_feedbackNode.instanceValue("anchors.rightMargin"))
painter->setPen(Qt::green);
else
painter->setPen(Qt::black);
painter->drawText(mapToScene(QPoint(2.0, 84.0)), QString("rightMargin: \t\t%1").arg(m_feedbackNode.instanceValue("anchors.rightMargin").toString()));
if (m_beginTopMargin != m_feedbackNode.instanceValue("anchors.topMargin"))
painter->setPen(Qt::green);
else
painter->setPen(Qt::black);
painter->drawText(mapToScene(QPoint(2.0, 96.0)), QString("topMargin: \t\t%1").arg(m_feedbackNode.instanceValue("anchors.topMargin").toString()));
if (m_beginBottomMargin != m_feedbackNode.instanceValue("anchors.bottomMargin"))
painter->setPen(Qt::green);
else
painter->setPen(Qt::black);
painter->drawText(mapToScene(QPoint(2.0, 108.0)), QString("bottomMargin: \t%1").arg(m_feedbackNode.instanceValue("anchors.bottomMargin").toString()));
painter->restore();
}
void FormEditorGraphicsView::setFeedbackNode(const QmlItemNode &node)
{
if (node == m_feedbackNode)
return;
m_feedbackNode = node;
if (m_feedbackNode.isValid()) {
m_beginX = m_feedbackNode.instanceValue("x");
m_beginY = m_feedbackNode.instanceValue("y");
m_beginWidth = m_feedbackNode.instanceValue("width");
m_beginHeight = m_feedbackNode.instanceValue("height");
m_parentNode = m_feedbackNode.instanceParent();
m_beginLeftMargin = m_feedbackNode.instanceValue("anchors.leftMargin");
m_beginRightMargin = m_feedbackNode.instanceValue("anchors.rightMargin");
m_beginTopMargin = m_feedbackNode.instanceValue("anchors.topMargin");
m_beginBottomMargin = m_feedbackNode.instanceValue("anchors.bottomMargin");
} else {
m_beginX = QVariant();
m_beginY = QVariant();
m_beginWidth = QVariant();
m_beginHeight = QVariant();
m_parentNode = QmlObjectNode();
m_beginLeftMargin = QVariant();
m_beginRightMargin = QVariant();
m_beginTopMargin = QVariant();
m_beginBottomMargin = QVariant();
}
}
void FormEditorGraphicsView::drawBackground(QPainter *painter, const QRectF &rect)
{
painter->save();
......
......@@ -31,6 +31,7 @@
#define FORMEDITORGRAPHICSVIEW_H
#include <QGraphicsView>
#include <qmlitemnode.h>
namespace QmlDesigner {
......@@ -40,12 +41,25 @@ Q_OBJECT
public:
explicit FormEditorGraphicsView(QWidget *parent = 0);
void setFeedbackNode(const QmlItemNode &node);
protected:
void drawForeground(QPainter *painter, const QRectF &rect );
void drawBackground(QPainter *painter, const QRectF &rect);
void wheelEvent(QWheelEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
private:
QmlItemNode m_feedbackNode;
QmlObjectNode m_parentNode;
QVariant m_beginX;
QVariant m_beginY;
QVariant m_beginWidth;
QVariant m_beginHeight;
QVariant m_beginLeftMargin;
QVariant m_beginRightMargin;
QVariant m_beginTopMargin;
QVariant m_beginBottomMargin;
};
} // namespace QmlDesigner
......
......@@ -251,6 +251,11 @@ void FormEditorView::selectedNodesChanged(const QList<ModelNode> &selectedNodeLi
item->update();
}
if (selectedNodeList.count() == 1)
m_formEditorWidget->setFeedbackNode(QmlItemNode(selectedNodeList.first()));
else
m_formEditorWidget->setFeedbackNode(QmlItemNode());
m_scene->update();
}
......@@ -482,6 +487,8 @@ void FormEditorView::transformChanged(const QmlObjectNode &qmlObjectNode)
m_scene->synchronizeTransformation(itemNode);
m_currentTool->formEditorItemsChanged(QList<FormEditorItem*>() << m_scene->itemForQmlItemNode(itemNode));
}
scene()->update();
}
void FormEditorView::parentChanged(const QmlObjectNode &qmlObjectNode)
......
......@@ -284,6 +284,11 @@ double FormEditorWidget::margins() const
return m_snappingMarginAction->currentValue().toDouble();
}
void FormEditorWidget::setFeedbackNode(const QmlItemNode &node)
{
m_graphicsView->setFeedbackNode(node);
}
}
......@@ -42,6 +42,8 @@ class FormEditorScene;
class FormEditorGraphicsView;
class ToolBox;
class NumberSeriesAction;
class QmlItemNode;
class FormEditorWidget : public QWidget
{
......@@ -63,6 +65,8 @@ public:
double spacing() const;
double margins() const;
void setFeedbackNode(const QmlItemNode &node);
protected:
void enterEvent(QEvent *event);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment