[qet] qet/qet: [5417] Minor code refactoring |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 5417
Author: blacksun
Date: 2018-06-29 09:55:48 +0200 (Fri, 29 Jun 2018)
Log Message:
-----------
Minor code refactoring
Modified Paths:
--------------
trunk/sources/QetGraphicsItemModeler/qetgraphicshandleritem.cpp
trunk/sources/QetGraphicsItemModeler/qetgraphicshandleritem.h
trunk/sources/qetgraphicsitem/conductor.cpp
Modified: trunk/sources/QetGraphicsItemModeler/qetgraphicshandleritem.cpp
===================================================================
--- trunk/sources/QetGraphicsItemModeler/qetgraphicshandleritem.cpp 2018-06-25 05:06:46 UTC (rev 5416)
+++ trunk/sources/QetGraphicsItemModeler/qetgraphicshandleritem.cpp 2018-06-29 07:55:48 UTC (rev 5417)
@@ -25,18 +25,19 @@
*/
QetGraphicsHandlerItem::QetGraphicsHandlerItem(qreal size) :
m_size(size)
-{}
+{
+ setFlag(QGraphicsItem::ItemIgnoresTransformations);
+
+ m_handler_rect.setRect(0-m_size/2, 0-m_size/2, m_size, m_size);
+ m_br.setRect(-1-m_size/2, -1-m_size/2, m_size+2, m_size+2);
+}
/**
* @brief QetGraphicsHandlerItem::boundingRect
* @return
*/
-QRectF QetGraphicsHandlerItem::boundingRect() const
-{
- qreal rect_size = m_size * m_previous_zoom_factor;
- QRectF rect(0-rect_size/2, 0-rect_size/2, rect_size, rect_size);
- rect.adjust(-0.1, -0.1, 0.1, 0.1);
- return rect;
+QRectF QetGraphicsHandlerItem::boundingRect() const {
+ return m_br;
}
/**
@@ -60,16 +61,6 @@
Q_UNUSED(option);
Q_UNUSED(widget);
- qreal zoom_factor = 1.0/painter->transform().m11();
- if(zoom_factor != m_previous_zoom_factor)
- {
- prepareGeometryChange();
- m_previous_zoom_factor = zoom_factor;
- }
-
- qreal rect_size = m_size * m_previous_zoom_factor;
- QRectF rect(0-rect_size/2, 0-rect_size/2, rect_size, rect_size);
-
painter->save();
painter->setBrush(QBrush(m_color));
QPen pen(QBrush(m_color), 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
@@ -76,7 +67,7 @@
pen.setCosmetic(true);
painter->setPen(pen);
painter->setRenderHint(QPainter::Antialiasing, true);
- painter->drawEllipse(rect);
+ painter->drawEllipse(m_handler_rect);
painter->restore();
}
Modified: trunk/sources/QetGraphicsItemModeler/qetgraphicshandleritem.h
===================================================================
--- trunk/sources/QetGraphicsItemModeler/qetgraphicshandleritem.h 2018-06-25 05:06:46 UTC (rev 5416)
+++ trunk/sources/QetGraphicsItemModeler/qetgraphicshandleritem.h 2018-06-29 07:55:48 UTC (rev 5417)
@@ -19,6 +19,7 @@
#define QETGRAPHICSHANDLERITEM_H
#include <QGraphicsItem>
+#include <QPen>
/**
* @brief The QetGraphicsHandlerItem class
@@ -42,9 +43,11 @@
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
private:
- qreal m_size,
- m_previous_zoom_factor = 1;
+ QRectF m_handler_rect,
+ m_br;
+ qreal m_size;
QColor m_color;
+ QPen m_pen;
public:
static QVector<QetGraphicsHandlerItem *> handlerForPoint(const QVector<QPointF> &points, int size = 10);
Modified: trunk/sources/qetgraphicsitem/conductor.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.cpp 2018-06-25 05:06:46 UTC (rev 5416)
+++ trunk/sources/qetgraphicsitem/conductor.cpp 2018-06-29 07:55:48 UTC (rev 5417)
@@ -780,7 +780,7 @@
if (m_moving_segment)
{
//Snap the mouse pos to grid
- QPointF pos_ = Diagram::snapToGrid(mapFromItem(qghi, event->pos()));
+ QPointF pos_ = Diagram::snapToGrid(mapFromScene(event->scenePos()));
//Position of the last point
QPointF p = m_moved_segment -> middle();