[qet] [4583] Element editor : graphic part |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 4583
Author: blacksun
Date: 2016-07-19 19:12:30 +0200 (Tue, 19 Jul 2016)
Log Message:
-----------
Element editor : graphic part
Diagram editor : shape item
Gain a new way to be resized: mirror resizing. Click on the item for switch the resize mode
Modified Paths:
--------------
trunk/sources/QetGraphicsItemModeler/qetgraphicshandlerutility.cpp
trunk/sources/QetGraphicsItemModeler/qetgraphicshandlerutility.h
trunk/sources/editor/elementprimitivedecorator.cpp
trunk/sources/editor/graphicspart/partarc.cpp
trunk/sources/editor/graphicspart/partarc.h
trunk/sources/editor/graphicspart/partellipse.cpp
trunk/sources/editor/graphicspart/partellipse.h
trunk/sources/editor/graphicspart/partrectangle.cpp
trunk/sources/editor/graphicspart/partrectangle.h
trunk/sources/qetgraphicsitem/qetshapeitem.cpp
trunk/sources/qetgraphicsitem/qetshapeitem.h
Modified: trunk/sources/QetGraphicsItemModeler/qetgraphicshandlerutility.cpp
===================================================================
--- trunk/sources/QetGraphicsItemModeler/qetgraphicshandlerutility.cpp 2016-07-19 14:37:08 UTC (rev 4582)
+++ trunk/sources/QetGraphicsItemModeler/qetgraphicshandlerutility.cpp 2016-07-19 17:12:30 UTC (rev 4583)
@@ -24,8 +24,7 @@
* @param size : the size of the handler
*/
QetGraphicsHandlerUtility::QetGraphicsHandlerUtility(qreal size) :
- m_size (size),
- m_zoom_factor(1)
+ m_size (size)
{}
/**
@@ -34,19 +33,15 @@
* @param painter : painter to use for drawing the handler
* @param point : point to draw the handler
*/
-void QetGraphicsHandlerUtility::drawHandler(QPainter *painter, const QPointF &point, bool color2)
+void QetGraphicsHandlerUtility::drawHandler(QPainter *painter, const QPointF &point)
{
- //Color of handler
- QColor inner(0xFF, 0xFF, 0xFF);
- QColor outer(0x00, 0x61, 0xFF);
- if(color2) outer = QColor(0x1A, 0x5C, 0x14);
//Setup the zoom factor to draw the handler in the same size at screen,
//no matter the zoom of the QPainter
m_zoom_factor = 1.0/painter->transform().m11();
painter->save();
- painter->setBrush(QBrush(inner));
- QPen square_pen(QBrush(outer), 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
+ painter->setBrush(QBrush(m_inner_color));
+ QPen square_pen(QBrush(m_outer_color), 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
square_pen.setCosmetic(true);
painter->setPen(square_pen);
painter->drawRect(getRect(point));
@@ -55,14 +50,14 @@
/**
* @brief QetGraphicsHandlerUtility::drawHandler
- * Conveniance method for void QetGraphicsHandlerUtility::drawHandler(QPainter *painter, const QPointF &point, bool color2)
+ * Conveniance method for void QetGraphicsHandlerUtility::drawHandler(QPainter *painter, const QPointF &point)
* @param painter
* @param points
* @param color2
*/
-void QetGraphicsHandlerUtility::drawHandler(QPainter *painter, const QVector<QPointF> &points, bool color2) {
+void QetGraphicsHandlerUtility::drawHandler(QPainter *painter, const QVector<QPointF> &points) {
foreach(QPointF point, points)
- drawHandler(painter, point, color2);
+ drawHandler(painter, point);
}
/**
@@ -107,6 +102,14 @@
return rect_vector;
}
+void QetGraphicsHandlerUtility::setInnerColor(QColor color) {
+ m_inner_color = color;
+}
+
+void QetGraphicsHandlerUtility::setOuterColor(QColor color) {
+ m_outer_color = color;
+}
+
/**
* @brief QetGraphicsHandlerUtility::getRect
* @param point
@@ -193,6 +196,64 @@
}
/**
+ * @brief QetGraphicsHandlerUtility::mirrorRectForPosAtIndex
+ * Return a rectangle after modification of the point '@pos' at index '@index' of original rectangle '@old_rect'.
+ * the opposite edge is modified inversely (like a mirror)
+ * @param old_rect : the rectangle befor modification
+ * @param pos : the new position of a key point
+ * @param index : the index of the key point to modifie see QetGraphicsHandlerUtility::pointsForRect to know
+ * the index of each keys points of a rectangle)
+ * @return : the rectangle with modification. If index is lower than 0 or higher than 7, this method return old_rect.
+ */
+QRectF QetGraphicsHandlerUtility::mirrorRectForPosAtIndex(const QRectF &old_rect, const QPointF &pos, int index)
+{
+ if (index < 0 || index > 7) return old_rect;
+
+ QRectF rect = old_rect;
+ QPointF center = rect.center();
+
+ if (index == 0) {
+ qreal x = pos.x() + (pos.x() - rect.topLeft().x());
+ qreal y = pos.y() + (pos.y() - rect.topLeft().y());
+ rect.setTopLeft(QPointF(x,y));
+ }
+ else if (index == 1) {
+ qreal y = pos.y() + (pos.y() - rect.topLeft().y());
+ rect.setTop(y);
+ }
+ else if (index == 2) {
+ qreal x = pos.x() + (pos.x() - rect.topRight().x());
+ qreal y = pos.y() + (pos.y() - rect.topLeft().y());
+ rect.setTopRight(QPointF(x,y));
+ }
+ else if (index == 3) {
+ qreal x = pos.x() + (pos.x() - rect.left());
+ rect.setLeft(x);
+ }
+ else if (index == 4) {
+ qreal x = pos.x() + (pos.x() - rect.right());
+ rect.setRight(x);
+ }
+ else if (index == 5) {
+ qreal x = pos.x() + (pos.x() - rect.bottomLeft().x());
+ qreal y = pos.y() + (pos.y() - rect.bottomLeft().y());
+ rect.setBottomLeft(QPointF(x,y));
+ }
+ else if (index == 6) {
+ qreal y = pos.y() + (pos.y() - rect.bottom());
+ rect.setBottom(y);
+ }
+ else if (index == 7) {
+ qreal x = pos.x() + (pos.x() - rect.bottomRight().x());
+ qreal y = pos.y() + (pos.y() - rect.bottomRight().y());
+ rect.setBottomRight(QPointF(x,y));
+ }
+
+ rect.moveCenter(center);
+ return rect;
+}
+
+/**
* @brief QetGraphicsHandlerUtility::lineForPosAtIndex
* Return a line after modification of @pos at index @index of @old_line.
* @param old_line
Modified: trunk/sources/QetGraphicsItemModeler/qetgraphicshandlerutility.h
===================================================================
--- trunk/sources/QetGraphicsItemModeler/qetgraphicshandlerutility.h 2016-07-19 14:37:08 UTC (rev 4582)
+++ trunk/sources/QetGraphicsItemModeler/qetgraphicshandlerutility.h 2016-07-19 17:12:30 UTC (rev 4583)
@@ -20,6 +20,7 @@
#include <QRectF>
#include <QLineF>
+#include <QColor>
class QPainter;
@@ -34,22 +35,27 @@
public:
QetGraphicsHandlerUtility (qreal size = 1);
void setSize(qreal size) {m_size = size;}
- void drawHandler (QPainter *painter, const QPointF & point, bool color2 = false);
- void drawHandler(QPainter *painter, const QVector<QPointF> &points, bool color2 = false);
+ void drawHandler (QPainter *painter, const QPointF & point);
+ void drawHandler(QPainter *painter, const QVector<QPointF> &points);
QPointF posForHandler(const QPointF &point) const;
bool pointIsInHandler (const QPointF &point, const QPointF &key_point) const;
int pointIsHoverHandler (const QPointF &point, const QVector<QPointF> &vector) const;
QVector<QRectF> handlerRect (const QVector<QPointF> &vector) const;
+ void setInnerColor (QColor color);
+ void setOuterColor (QColor color);
private:
QRectF getRect (const QPointF &point) const;
qreal m_size;
- qreal m_zoom_factor;
+ qreal m_zoom_factor = 1;
+ QColor m_inner_color = Qt::white,
+ m_outer_color = Qt::blue;
public:
static QVector <QPointF> pointsForRect (const QRectF &rect);
static QVector <QPointF> pointsForLine (const QLineF &line);
static QRectF rectForPosAtIndex (const QRectF &old_rect, const QPointF &pos, int index);
+ static QRectF mirrorRectForPosAtIndex (const QRectF &old_rect, const QPointF &pos, int index);
static QLineF lineForPosAtIndex (const QLineF &old_line, const QPointF &pos, int index);
};
Modified: trunk/sources/editor/elementprimitivedecorator.cpp
===================================================================
--- trunk/sources/editor/elementprimitivedecorator.cpp 2016-07-19 14:37:08 UTC (rev 4582)
+++ trunk/sources/editor/elementprimitivedecorator.cpp 2016-07-19 17:12:30 UTC (rev 4583)
@@ -21,11 +21,9 @@
#include "editorcommands.h"
#include "qet.h"
#include <QPainter>
-#include <QDebug>
#include <QGraphicsSceneHoverEvent>
#include <QStyleOptionGraphicsItem>
#include <QGraphicsScene>
-#include <QTransform>
/**
Constructor
@@ -36,6 +34,7 @@
m_handler(10)
{
init();
+ m_handler.setOuterColor(Qt::darkGreen);
}
/**
@@ -97,8 +96,9 @@
pen.setCosmetic(true);
painter -> setPen(pen);
painter -> drawRect(modified_bounding_rect_);
+
//Draw the handlers
- m_handler.drawHandler(painter, getResizingsPoints(), decorated_items_.size()-1);
+ m_handler.drawHandler(painter, getResizingsPoints());
// uncomment to draw the real bouding rect (=adjusted internal bounding rect)
// painter -> setBrush(QBrush(QColor(240, 0, 0, 127)));
Modified: trunk/sources/editor/graphicspart/partarc.cpp
===================================================================
--- trunk/sources/editor/graphicspart/partarc.cpp 2016-07-19 14:37:08 UTC (rev 4582)
+++ trunk/sources/editor/graphicspart/partarc.cpp 2016-07-19 17:12:30 UTC (rev 4583)
@@ -232,7 +232,11 @@
{
QPointF pos_ = event->modifiers() == Qt::ControlModifier ? event->pos() : mapFromScene(elementScene()->snapToGrid(event->scenePos()));
prepareGeometryChange();
- setRect(m_handler.rectForPosAtIndex(m_rect, pos_, m_handler_index));
+
+ if (m_resize_mode == 1)
+ setRect(m_handler.rectForPosAtIndex(m_rect, pos_, m_handler_index));
+ else
+ setRect(m_handler.mirrorRectForPosAtIndex(m_rect, pos_, m_handler_index));
}
else
CustomElementGraphicPart::mouseMoveEvent(event);
@@ -245,8 +249,11 @@
*/
void PartArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
- if (event->button() == Qt::LeftButton)
+ if (event->button() == Qt::LeftButton) {
setCursor(Qt::OpenHandCursor);
+ if (event->buttonDownPos(Qt::LeftButton) == event->pos())
+ switchResizeMode();
+ }
if (m_handler_index >= 0 && m_handler_index <= 7)
{
@@ -261,3 +268,16 @@
else
CustomElementGraphicPart::mouseReleaseEvent(event);
}
+
+void PartArc::switchResizeMode()
+{
+ if (m_resize_mode == 1) {
+ m_resize_mode = 2;
+ m_handler.setOuterColor(Qt::darkGreen);
+ }
+ else {
+ m_resize_mode = 1;
+ m_handler.setOuterColor(Qt::blue);
+ }
+ update();
+}
Modified: trunk/sources/editor/graphicspart/partarc.h
===================================================================
--- trunk/sources/editor/graphicspart/partarc.h 2016-07-19 14:37:08 UTC (rev 4582)
+++ trunk/sources/editor/graphicspart/partarc.h 2016-07-19 17:12:30 UTC (rev 4583)
@@ -65,8 +65,12 @@
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
private:
+ void switchResizeMode();
+
+ private:
QetGraphicsHandlerUtility m_handler;
int m_handler_index;
QPropertyUndoCommand *m_undo_command;
+ int m_resize_mode = 1;
};
#endif
Modified: trunk/sources/editor/graphicspart/partellipse.cpp
===================================================================
--- trunk/sources/editor/graphicspart/partellipse.cpp 2016-07-19 14:37:08 UTC (rev 4582)
+++ trunk/sources/editor/graphicspart/partellipse.cpp 2016-07-19 17:12:30 UTC (rev 4583)
@@ -227,7 +227,11 @@
{
QPointF pos_ = event->modifiers() == Qt::ControlModifier ? event->pos() : mapFromScene(elementScene()->snapToGrid(event->scenePos()));
prepareGeometryChange();
- setRect(m_handler.rectForPosAtIndex(m_rect, pos_, m_handler_index));
+
+ if (m_resize_mode == 1)
+ setRect(m_handler.rectForPosAtIndex(m_rect, pos_, m_handler_index));
+ else
+ setRect(m_handler.mirrorRectForPosAtIndex(m_rect, pos_, m_handler_index));
}
else
CustomElementGraphicPart::mouseMoveEvent(event);
@@ -240,8 +244,11 @@
*/
void PartEllipse::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
- if (event->button() == Qt::LeftButton)
+ if (event->button() == Qt::LeftButton) {
setCursor(Qt::OpenHandCursor);
+ if (event->buttonDownPos(Qt::LeftButton) == event->pos())
+ switchResizeMode();
+ }
if (m_handler_index >= 0 && m_handler_index <= 7)
{
@@ -256,3 +263,16 @@
else
CustomElementGraphicPart::mouseReleaseEvent(event);
}
+
+void PartEllipse::switchResizeMode()
+{
+ if (m_resize_mode == 1) {
+ m_resize_mode = 2;
+ m_handler.setOuterColor(Qt::darkGreen);
+ }
+ else {
+ m_resize_mode = 1;
+ m_handler.setOuterColor(Qt::blue);
+ }
+ update();
+}
Modified: trunk/sources/editor/graphicspart/partellipse.h
===================================================================
--- trunk/sources/editor/graphicspart/partellipse.h 2016-07-19 14:37:08 UTC (rev 4582)
+++ trunk/sources/editor/graphicspart/partellipse.h 2016-07-19 17:12:30 UTC (rev 4583)
@@ -67,8 +67,12 @@
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
private:
+ void switchResizeMode();
+
+ private:
QetGraphicsHandlerUtility m_handler;
int m_handler_index;
QPropertyUndoCommand *m_undo_command;
+ int m_resize_mode = 1;
};
#endif
Modified: trunk/sources/editor/graphicspart/partrectangle.cpp
===================================================================
--- trunk/sources/editor/graphicspart/partrectangle.cpp 2016-07-19 14:37:08 UTC (rev 4582)
+++ trunk/sources/editor/graphicspart/partrectangle.cpp 2016-07-19 17:12:30 UTC (rev 4583)
@@ -298,7 +298,11 @@
{
QPointF pos_ = event->modifiers() == Qt::ControlModifier ? event->pos() : mapFromScene(elementScene()->snapToGrid(event->scenePos()));
prepareGeometryChange();
- setRect(m_handler.rectForPosAtIndex(m_rect, pos_, m_handler_index));
+
+ if (m_resize_mode == 1)
+ setRect(m_handler.rectForPosAtIndex(m_rect, pos_, m_handler_index));
+ else
+ setRect(m_handler.mirrorRectForPosAtIndex(m_rect, pos_, m_handler_index));
}
else
CustomElementGraphicPart::mouseMoveEvent(event);
@@ -311,8 +315,11 @@
*/
void PartRectangle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
- if (event->button() == Qt::LeftButton)
+ if (event->button() == Qt::LeftButton) {
setCursor(Qt::OpenHandCursor);
+ if (event->buttonDownPos(Qt::LeftButton) == event->pos())
+ switchResizeMode();
+ }
if (m_handler_index >= 0 && m_handler_index <= 7)
{
@@ -327,3 +334,16 @@
else
CustomElementGraphicPart::mouseReleaseEvent(event);
}
+
+void PartRectangle::switchResizeMode()
+{
+ if (m_resize_mode == 1) {
+ m_resize_mode = 2;
+ m_handler.setOuterColor(Qt::darkGreen);
+ }
+ else {
+ m_resize_mode = 1;
+ m_handler.setOuterColor(Qt::blue);
+ }
+ update();
+}
Modified: trunk/sources/editor/graphicspart/partrectangle.h
===================================================================
--- trunk/sources/editor/graphicspart/partrectangle.h 2016-07-19 14:37:08 UTC (rev 4582)
+++ trunk/sources/editor/graphicspart/partrectangle.h 2016-07-19 17:12:30 UTC (rev 4583)
@@ -79,6 +79,9 @@
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+
+ private:
+ void switchResizeMode();
private:
QRectF m_rect;
@@ -86,5 +89,6 @@
QetGraphicsHandlerUtility m_handler;
int m_handler_index;
QPropertyUndoCommand *m_undo_command;
+ int m_resize_mode = 1;
};
#endif
Modified: trunk/sources/qetgraphicsitem/qetshapeitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/qetshapeitem.cpp 2016-07-19 14:37:08 UTC (rev 4582)
+++ trunk/sources/qetgraphicsitem/qetshapeitem.cpp 2016-07-19 17:12:30 UTC (rev 4583)
@@ -435,8 +435,24 @@
m_vector_index == 0 ? m_P1 = new_pos : m_P2 = new_pos;
break;
- case Rectangle: setRect(m_handler.rectForPosAtIndex(QRectF(m_P1, m_P2), new_pos, m_vector_index)); break;
- case Ellipse: setRect(m_handler.rectForPosAtIndex(QRectF(m_P1, m_P2), new_pos, m_vector_index)); break;
+ case Rectangle:
+ if (m_resize_mode == 1) {
+ setRect(m_handler.rectForPosAtIndex(QRectF(m_P1, m_P2), new_pos, m_vector_index));
+ break;
+ }
+ else {
+ setRect(m_handler.mirrorRectForPosAtIndex(QRectF(m_P1, m_P2), new_pos, m_vector_index));
+ break;
+ }
+ case Ellipse:
+ if (m_resize_mode == 1) {
+ setRect(m_handler.rectForPosAtIndex(QRectF(m_P1, m_P2), new_pos, m_vector_index));
+ break;
+ }
+ else {
+ setRect(m_handler.mirrorRectForPosAtIndex(QRectF(m_P1, m_P2), new_pos, m_vector_index));
+ break;
+ }
case Polygon:
prepareGeometryChange();
@@ -456,6 +472,9 @@
*/
void QetShapeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
+ if ((m_shapeType & (Rectangle | Ellipse)) && event->buttonDownPos(Qt::LeftButton) == event->pos())
+ switchResizeMode();
+
if (m_mouse_grab_handler)
{
m_mouse_grab_handler = false;
@@ -488,6 +507,19 @@
QetGraphicsItem::mouseReleaseEvent(event);
}
+void QetShapeItem::switchResizeMode()
+{
+ if (m_resize_mode == 1) {
+ m_resize_mode = 2;
+ m_handler.setOuterColor(Qt::darkGreen);
+ }
+ else {
+ m_resize_mode = 1;
+ m_handler.setOuterColor(Qt::blue);
+ }
+ update();
+}
+
/**
* @brief QetShapeItem::fromXml
* Build this item from the xml description
Modified: trunk/sources/qetgraphicsitem/qetshapeitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/qetshapeitem.h 2016-07-19 14:37:08 UTC (rev 4582)
+++ trunk/sources/qetgraphicsitem/qetshapeitem.h 2016-07-19 17:12:30 UTC (rev 4583)
@@ -102,6 +102,9 @@
virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
+ private:
+ void switchResizeMode();
+
///ATTRIBUTES
private:
ShapeType m_shapeType;
@@ -114,5 +117,6 @@
int m_vector_index;
QetGraphicsHandlerUtility m_handler;
bool m_close = false;
+ int m_resize_mode = 1;
};
#endif // QETSHAPEITEM_H