mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-01-05 20:20:52 +01:00
Minor code refactoring
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5417 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -25,18 +25,19 @@
|
|||||||
*/
|
*/
|
||||||
QetGraphicsHandlerItem::QetGraphicsHandlerItem(qreal size) :
|
QetGraphicsHandlerItem::QetGraphicsHandlerItem(qreal size) :
|
||||||
m_size(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
|
* @brief QetGraphicsHandlerItem::boundingRect
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
QRectF QetGraphicsHandlerItem::boundingRect() const
|
QRectF QetGraphicsHandlerItem::boundingRect() const {
|
||||||
{
|
return m_br;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,23 +61,13 @@ void QetGraphicsHandlerItem::paint(QPainter *painter, const QStyleOptionGraphics
|
|||||||
Q_UNUSED(option);
|
Q_UNUSED(option);
|
||||||
Q_UNUSED(widget);
|
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->save();
|
||||||
painter->setBrush(QBrush(m_color));
|
painter->setBrush(QBrush(m_color));
|
||||||
QPen pen(QBrush(m_color), 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
|
QPen pen(QBrush(m_color), 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
|
||||||
pen.setCosmetic(true);
|
pen.setCosmetic(true);
|
||||||
painter->setPen(pen);
|
painter->setPen(pen);
|
||||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||||
painter->drawEllipse(rect);
|
painter->drawEllipse(m_handler_rect);
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#define QETGRAPHICSHANDLERITEM_H
|
#define QETGRAPHICSHANDLERITEM_H
|
||||||
|
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
|
#include <QPen>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The QetGraphicsHandlerItem class
|
* @brief The QetGraphicsHandlerItem class
|
||||||
@@ -42,9 +43,11 @@ class QetGraphicsHandlerItem : public QGraphicsItem
|
|||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
qreal m_size,
|
QRectF m_handler_rect,
|
||||||
m_previous_zoom_factor = 1;
|
m_br;
|
||||||
|
qreal m_size;
|
||||||
QColor m_color;
|
QColor m_color;
|
||||||
|
QPen m_pen;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static QVector<QetGraphicsHandlerItem *> handlerForPoint(const QVector<QPointF> &points, int size = 10);
|
static QVector<QetGraphicsHandlerItem *> handlerForPoint(const QVector<QPointF> &points, int size = 10);
|
||||||
|
|||||||
@@ -780,7 +780,7 @@ void Conductor::handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSce
|
|||||||
if (m_moving_segment)
|
if (m_moving_segment)
|
||||||
{
|
{
|
||||||
//Snap the mouse pos to grid
|
//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
|
//Position of the last point
|
||||||
QPointF p = m_moved_segment -> middle();
|
QPointF p = m_moved_segment -> middle();
|
||||||
|
|||||||
Reference in New Issue
Block a user