- Bypass the boundRect() method at each resizepolygon.

preferencesAboutTextFull
agriche 9 years ago
parent 691eb2a8b3
commit 8b6a9279d3
  1. 42
      src/tools/UBGraphicsTriangle.cpp
  2. 19
      src/tools/UBGraphicsTriangle.h

@ -25,8 +25,10 @@
#include <QGraphicsPolygonItem>
//#include <QGraphicsPolygonItem>
#include <QPolygonF>
#include <QtWidgets/QGraphicsPolygonItem>
#include "tools/UBGraphicsTriangle.h"
#include "core/UBApplication.h"
@ -131,19 +133,38 @@ void UBGraphicsTriangle::setRect(qreal x, qreal y, qreal w, qreal h, UBGraphicsT
polygon << QPointF(x, y) << QPoint(x, y + h) << QPoint(x+w, y + h);
setPolygon(polygon);
// Save the bounds rect
bounds_rect.setX(x); bounds_rect.setY(y); bounds_rect.setWidth(w); bounds_rect.setHeight(h);
setOrientation(orientation);
}
void UBGraphicsTriangle::setOrientation(UBGraphicsTriangleOrientation orientation)
{
mOrientation = orientation;
calculatePoints(boundingRect());
//calculatePoints(boundingRect());
calculatePoints(bounds_rect);
QPolygonF polygon;
polygon << A1 << B1 << C1;
setPolygon(polygon);
}
QRectF UBGraphicsTriangle::bounding_Rect() const
{
QRectF bounds = QRectF(0,0,0,0);
bounds.setX(bounds_rect.x());
bounds.setY(bounds_rect.y());
bounds.setWidth(bounds_rect.width());
bounds.setHeight(bounds_rect.height());
return bounds;
}
UBGraphicsScene* UBGraphicsTriangle::scene() const
{
return static_cast<UBGraphicsScene*>(QGraphicsPolygonItem::scene());
@ -151,6 +172,8 @@ UBGraphicsScene* UBGraphicsTriangle::scene() const
void UBGraphicsTriangle::calculatePoints(const QRectF& r)
{
//qDebug() << "UBGraphicsTriangle calculatePoints()"<<"r ="<<r<<"mOrientation ="<<mOrientation;
switch(mOrientation)
{
@ -277,6 +300,10 @@ void UBGraphicsTriangle::paint(QPainter *painter, const QStyleOptionGraphicsItem
mRotateSvgItem->setTransform(antiScaleTransform);
mCloseSvgItem->setPos(closeButtonRect().topLeft());
qDebug() << "UBGraphicsTriangle Paint"<<"closeButtonRect().topLeft()="
<<closeButtonRect().topLeft();
mHFlipSvgItem->setPos(hFlipRect().topLeft());
mVFlipSvgItem->setPos(vFlipRect().topLeft());
mRotateSvgItem->setPos(rotateRect().topLeft());
@ -289,6 +316,8 @@ void UBGraphicsTriangle::paint(QPainter *painter, const QStyleOptionGraphicsItem
if (mShowButtons || mResizing2)
painter->drawPolygon(resize2Polygon());
}
}
QPainterPath UBGraphicsTriangle::shape() const
@ -296,6 +325,8 @@ QPainterPath UBGraphicsTriangle::shape() const
QPainterPath tShape;
QPolygonF tPolygon;
qDebug() << "UBGraphicsTriangle shape()"<<"A1 ="<<A1<<"B1 ="<<B1<<"C1 ="<<C1;
tPolygon << A1 << B1 << C1;
tShape.addPolygon(tPolygon);
tPolygon.clear();
@ -304,6 +335,9 @@ QPainterPath UBGraphicsTriangle::shape() const
tShape.addPolygon(tPolygon);
tPolygon.clear();
qDebug() << "UBGraphicsTriangle shape()"<<"A1 ="<<A1<<"B1 ="<<B1<<"C1 ="<<C1;
qDebug() << "UBGraphicsTriangle shape()"<<"A2 ="<<A2<<"B2 ="<<B2<<"C2 ="<<C2;
return tShape;
}
@ -800,6 +834,10 @@ void UBGraphicsTriangle::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
UBDrawingController::drawingController()->mActiveRuler = this;
event->accept();
}
//
//event->accept(); //**
//update(); //**
}
void UBGraphicsTriangle::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)

@ -28,9 +28,14 @@
#ifndef UBGRAPHICSTRIANGLE_H_
#define UBGRAPHICSTRIANGLE_H_
#include <QtGui>
//#include <QtGui>
#include <QtWidgets>
#include <QtSvg>
#include <QGraphicsPolygonItem>
#include <QtWidgets/QGraphicsItem>
#include <QtWidgets/QGraphicsPolygonItem>
#include "core/UB.h"
#include "domain/UBItem.h"
@ -92,7 +97,9 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
void setRect(const QRectF &rect, UBGraphicsTriangleOrientation orientation)
{
setRect(rect.x(), rect.y(), rect.width(), rect.height(), orientation);
qDebug() << "setRect"<<"rect = "<<rect<<"orientation :"<<orientation;
setRect(rect.x(), rect.y(), rect.width(), rect.height(), orientation);
}
void setRect(qreal x, qreal y, qreal w, qreal h, UBGraphicsTriangleOrientation orientation);
void setOrientation(UBGraphicsTriangleOrientation orientation);
@ -119,6 +126,8 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
QRectF vFlipRect() const;
QRectF rotateRect() const;
QRectF bounding_Rect() const;
QCursor resizeCursor1() const;
QCursor resizeCursor2() const;
@ -149,6 +158,10 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
// Coordinates are transformed....
QPoint lastPos;
// Save the last bounds rect
QRectF bounds_rect;
QGraphicsSvgItem* mHFlipSvgItem;
QGraphicsSvgItem* mVFlipSvgItem;
QGraphicsSvgItem* mRotateSvgItem;

Loading…
Cancel
Save