Commit d515d0e5 authored by unknown's avatar unknown

Triangle tool

parent bfd3c05b
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 14.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 43363) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="Layer_1"
x="0px"
y="0px"
width="26.703px"
height="22.297px"
viewBox="0 0 26.703 22.297"
enable-background="new 0 0 26.703 22.297"
xml:space="preserve"
inkscape:version="0.48.1 "
sodipodi:docname="closeTool.svg"><metadata
id="metadata3009"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs3007" /><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1016"
inkscape:window-height="660"
id="namedview3005"
showgrid="false"
inkscape:snap-bbox="false"
inkscape:zoom="11.70561"
inkscape:cx="13.3515"
inkscape:cy="11.1485"
inkscape:window-x="289"
inkscape:window-y="195"
inkscape:window-maximized="0"
inkscape:current-layer="g2999" />
<g
id="g2999"
transform="translate(0.08542912,0)">
<path
clip-rule="evenodd"
stroke-miterlimit="3.8637"
d="m 17.978,0.507 c 4.546179,-0.0864046 8.231,3.686 8.231,8.232 l 0,4.838 c 0,4.547 -3.685,8.232 -8.231,8.232 l -9.246,0 c -4.546,0 -8.231,-3.686 -8.231,-8.232 l 0,-4.838 c 0,-4.547 3.943108,-7.97477519 8.4872874,-8.06114175 z"
id="path3001"
inkscape:connector-curvature="0"
style="fill:#333333;fill-rule:evenodd;stroke:#cdcccc;stroke-miterlimit:3.86369991"
sodipodi:nodetypes="sssssssss" />
<path
style="fill:none;stroke:#f9f9f9;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 14.950096,5.2111765 0.170859,12.4726515 5.894609,-2.562873 z"
id="path3015"
inkscape:connector-curvature="0"
transform="translate(-0.08542912,-8.119964e-7)" /><path
style="fill:#cccccc;stroke:#f9f9f9;stroke-width:1.04033172000000000px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 12.50192,5.211176 12.317001,17.683828 5.9373238,15.120955 z"
id="path3015-5"
inkscape:connector-curvature="0" /></g>
</svg>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 14.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 43363) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="Layer_1"
x="0px"
y="0px"
width="26.703px"
height="22.297px"
viewBox="0 0 26.703 22.297"
enable-background="new 0 0 26.703 22.297"
xml:space="preserve"
inkscape:version="0.48.1 "
sodipodi:docname="hrotateTool.svg"><metadata
id="metadata3009"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs3007" /><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1016"
inkscape:window-height="660"
id="namedview3005"
showgrid="false"
inkscape:snap-bbox="false"
inkscape:zoom="11.70561"
inkscape:cx="13.3515"
inkscape:cy="11.1485"
inkscape:window-x="289"
inkscape:window-y="195"
inkscape:window-maximized="0"
inkscape:current-layer="g2999" />
<g
id="g2999"
transform="translate(0.08542912,0)">
<path
clip-rule="evenodd"
stroke-miterlimit="3.8637"
d="m 17.892571,0.59242912 c 4.546179,-0.0864046 8.231,3.68599998 8.231,8.23199998 l 0,4.8379999 c 0,4.547 -3.685,8.232 -8.231,8.232 l -9.2460001,0 c -4.546,0 -8.23100002,-3.686 -8.23100002,-8.232 l 0,-4.8379999 c 0,-4.547 3.94310802,-7.97477517 8.48728742,-8.06114173 z"
id="path3001"
inkscape:connector-curvature="0"
style="fill:#333333;fill-rule:evenodd;stroke:#cdcccc;stroke-miterlimit:3.86369991"
sodipodi:nodetypes="sssssssss" />
<path
style="fill:none;stroke:#f9f9f9;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 6.4498984,10.208779 18.922551,10.03792 16.359678,4.1433112 z"
id="path3015"
inkscape:connector-curvature="0" /><path
style="fill:#cccccc;stroke:#f9f9f9;stroke-width:1.04033172px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 6.4004609,12.094944 18.873113,12.279863 16.31024,18.65954 z"
id="path3015-5"
inkscape:connector-curvature="0" /></g>
</svg>
\ No newline at end of file
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
<file>images/resizeRuler.svg</file> <file>images/resizeRuler.svg</file>
<file>images/resizeCompass.svg</file> <file>images/resizeCompass.svg</file>
<file>images/closeTool.svg</file> <file>images/closeTool.svg</file>
<file>images/hflipTool.svg</file>
<file>images/vflipTool.svg</file>
<file>images/resetTool.svg</file> <file>images/resetTool.svg</file>
<file>images/angleMarker.svg</file> <file>images/angleMarker.svg</file>
<file>images/currentDocument.png</file> <file>images/currentDocument.png</file>
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "UBCookieJar.h" #include "UBCookieJar.h"
#include "core/memcheck.h" #include "core/memcheck.h"
UBNetworkAccessManager *UBNetworkAccessManager::sNetworkAccessManager = 0; UBNetworkAccessManager *UBNetworkAccessManager::sNetworkAccessManager = 0;
......
...@@ -19,9 +19,7 @@ const QColor UBAbstractDrawRuler::sDarkBackgroundEdgeFillColor = QColor(0xdd, 0x ...@@ -19,9 +19,7 @@ const QColor UBAbstractDrawRuler::sDarkBackgroundEdgeFillColor = QColor(0xdd, 0x
const QColor UBAbstractDrawRuler::sDarkBackgroundDrawColor = QColor(0xff, 0xff, 0xff, sDrawTransparency); const QColor UBAbstractDrawRuler::sDarkBackgroundDrawColor = QColor(0xff, 0xff, 0xff, sDrawTransparency);
UBAbstractDrawRuler::UBAbstractDrawRuler() UBAbstractDrawRuler::UBAbstractDrawRuler()
: mResizing(false) : mShowButtons(false)
, mRotating(false)
, mShowButtons(false)
, mAntiScaleRatio(1.0) , mAntiScaleRatio(1.0)
{} {}
...@@ -36,12 +34,6 @@ void UBAbstractDrawRuler::create(QGraphicsItem& item) ...@@ -36,12 +34,6 @@ void UBAbstractDrawRuler::create(QGraphicsItem& item)
mCloseSvgItem = new QGraphicsSvgItem(":/images/closeTool.svg", &item); mCloseSvgItem = new QGraphicsSvgItem(":/images/closeTool.svg", &item);
mCloseSvgItem->setVisible(false); mCloseSvgItem->setVisible(false);
mCloseSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); mCloseSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
mRotateSvgItem = new QGraphicsSvgItem(":/images/rotateTool.svg", &item);
mRotateSvgItem->setVisible(false);
mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
updateResizeCursor(item);
} }
...@@ -49,32 +41,11 @@ UBAbstractDrawRuler::~UBAbstractDrawRuler() ...@@ -49,32 +41,11 @@ UBAbstractDrawRuler::~UBAbstractDrawRuler()
{ {
} }
void UBAbstractDrawRuler::updateResizeCursor(QGraphicsItem &item)
{
QPixmap pix(":/images/cursors/resize.png");
QTransform itemTransform = item.sceneTransform();
QRectF itemRect = item.boundingRect();
QPointF topLeft = itemTransform.map(itemRect.topLeft());
QPointF topRight = itemTransform.map(itemRect.topRight());
QLineF topLine(topLeft, topRight);
qreal angle = topLine.angle();
QTransform tr;
tr.rotate(- angle);
QCursor resizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2);
mResizeCursor = resizeCursor;
}
QCursor UBAbstractDrawRuler::moveCursor() const QCursor UBAbstractDrawRuler::moveCursor() const
{ {
return Qt::SizeAllCursor; return Qt::SizeAllCursor;
} }
QCursor UBAbstractDrawRuler::resizeCursor() const
{
return mResizeCursor;
}
QCursor UBAbstractDrawRuler::rotateCursor() const QCursor UBAbstractDrawRuler::rotateCursor() const
{ {
return UBResources::resources()->rotateCursor; return UBResources::resources()->rotateCursor;
...@@ -129,9 +100,6 @@ void UBAbstractDrawRuler::paint() ...@@ -129,9 +100,6 @@ void UBAbstractDrawRuler::paint()
mCloseSvgItem->setTransform(antiScaleTransform); mCloseSvgItem->setTransform(antiScaleTransform);
mCloseSvgItem->setPos(closeButtonRect().topLeft()); mCloseSvgItem->setPos(closeButtonRect().topLeft());
mRotateSvgItem->setTransform(antiScaleTransform);
mRotateSvgItem->setPos(rotateButtonRect().topLeft());
} }
...@@ -19,33 +19,27 @@ public: ...@@ -19,33 +19,27 @@ public:
virtual void DrawLine(const QPointF& position, qreal width); virtual void DrawLine(const QPointF& position, qreal width);
virtual void EndLine(); virtual void EndLine();
signals:
void hidden();
protected: protected:
void paint(); void paint();
virtual UBGraphicsScene* scene() const = 0; virtual UBGraphicsScene* scene() const = 0;
virtual void rotateAroundTopLeftOrigin(qreal angle) = 0; virtual void rotateAroundCenter(qreal angle) = 0;
virtual QPointF topLeftOrigin() const = 0; virtual QPointF rotationCenter() const = 0;
virtual QRectF resizeButtonRect() const = 0;
virtual QRectF closeButtonRect() const = 0; virtual QRectF closeButtonRect() const = 0;
virtual QRectF rotateButtonRect() const = 0;
void updateResizeCursor(QGraphicsItem &item);
bool mResizing;
bool mRotating;
bool mShowButtons; bool mShowButtons;
QGraphicsSvgItem* mCloseSvgItem; QGraphicsSvgItem* mCloseSvgItem;
QGraphicsSvgItem* mRotateSvgItem;
QCursor mResizeCursor;
qreal mAntiScaleRatio; qreal mAntiScaleRatio;
QPointF startDrawPosition; QPointF startDrawPosition;
QCursor moveCursor() const; QCursor moveCursor() const;
QCursor resizeCursor() const;
QCursor rotateCursor() const; QCursor rotateCursor() const;
QCursor closeCursor() const; QCursor closeCursor() const;
QCursor drawRulerLineCursor() const; QCursor drawRulerLineCursor() const;
...@@ -63,7 +57,6 @@ protected: ...@@ -63,7 +57,6 @@ protected:
static const QColor sDarkBackgroundDrawColor; static const QColor sDarkBackgroundDrawColor;
static const int sLeftEdgeMargin = 10; static const int sLeftEdgeMargin = 10;
static const int sMinLength = 150;
static const int sDegreeToQtAngleUnit = 16; static const int sDegreeToQtAngleUnit = 16;
static const int sRotationRadius = 15; static const int sRotationRadius = 15;
static const int sPixelsPerMillimeter = 5; static const int sPixelsPerMillimeter = 5;
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "board/UBBoardController.h" #include "board/UBBoardController.h"
#include "board/UBDrawingController.h" #include "board/UBDrawingController.h"
#include "core/memcheck.h" #include "core/memcheck.h"
...@@ -31,8 +30,6 @@ UBGraphicsProtractor::UBGraphicsProtractor() ...@@ -31,8 +30,6 @@ UBGraphicsProtractor::UBGraphicsProtractor()
, mResizeSvgItem(0) , mResizeSvgItem(0)
, mMarkerSvgItem(0) , mMarkerSvgItem(0)
{ {
sFillTransparency = 127;
sDrawTransparency = 192;
create(*this); create(*this);
...@@ -44,17 +41,19 @@ UBGraphicsProtractor::UBGraphicsProtractor() ...@@ -44,17 +41,19 @@ UBGraphicsProtractor::UBGraphicsProtractor()
mResetSvgItem = new QGraphicsSvgItem(":/images/resetTool.svg", this); mResetSvgItem = new QGraphicsSvgItem(":/images/resetTool.svg", this);
mResetSvgItem->setVisible(false); mResetSvgItem->setVisible(false);
mResetSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); mResetSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
mResetSvgItem->setPos(resetButtonRect().topLeft());
mResizeSvgItem = new QGraphicsSvgItem(":/images/resizeTool.svg", this); mResizeSvgItem = new QGraphicsSvgItem(":/images/resizeTool.svg", this);
mResizeSvgItem->setVisible(false); mResizeSvgItem->setVisible(false);
mResizeSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); mResizeSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
mResizeSvgItem->setPos(resizeButtonRect().topLeft());
mMarkerSvgItem = new QGraphicsSvgItem(":/images/angleMarker.svg", this); mMarkerSvgItem = new QGraphicsSvgItem(":/images/angleMarker.svg", this);
mMarkerSvgItem->setVisible(false); mMarkerSvgItem->setVisible(false);
mMarkerSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); mMarkerSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool));
mMarkerSvgItem->setPos(markerButtonRect().topLeft());
mRotateSvgItem = new QGraphicsSvgItem(":/images/rotateTool.svg", this);
mRotateSvgItem->setVisible(false);
mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
scale(1.5, 1.5); scale(1.5, 1.5);
} }
...@@ -586,12 +585,12 @@ UBItem* UBGraphicsProtractor::deepCopy() const ...@@ -586,12 +585,12 @@ UBItem* UBGraphicsProtractor::deepCopy() const
} }
void UBGraphicsProtractor::rotateAroundTopLeftOrigin(qreal angle) void UBGraphicsProtractor::rotateAroundCenter(qreal angle)
{ {
Q_UNUSED(angle); Q_UNUSED(angle);
} }
QPointF UBGraphicsProtractor::topLeftOrigin() const QPointF UBGraphicsProtractor::rotationCenter() const
{ {
return QPointF(rect().x(), rect().y()); return QPointF(rect().x(), rect().y());
} }
...@@ -41,10 +41,6 @@ class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipse ...@@ -41,10 +41,6 @@ class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipse
return Type; return Type;
} }
signals:
void hidden();
protected: protected:
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget); virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget);
...@@ -62,10 +58,10 @@ class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipse ...@@ -62,10 +58,10 @@ class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipse
private: private:
// Helpers // Helpers
void paintGraduations (QPainter *painter); void paintGraduations (QPainter *painter);
void paintButtons (QPainter *painter); void paintButtons (QPainter *painter);
void paintAngleMarker (QPainter *painter); void paintAngleMarker (QPainter *painter);
Tool toolFromPos (QPointF pos); Tool toolFromPos (QPointF pos);
qreal antiScale () const; qreal antiScale () const;
UBGraphicsScene* scene() const; UBGraphicsScene* scene() const;
QBrush fillBrush() const; QBrush fillBrush() const;
...@@ -90,14 +86,12 @@ class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipse ...@@ -90,14 +86,12 @@ class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipse
QGraphicsSvgItem* mResetSvgItem; QGraphicsSvgItem* mResetSvgItem;
QGraphicsSvgItem* mResizeSvgItem; QGraphicsSvgItem* mResizeSvgItem;
QGraphicsSvgItem* mMarkerSvgItem; QGraphicsSvgItem* mMarkerSvgItem;
QGraphicsSvgItem* mRotateSvgItem;
static const QRectF sDefaultRect; static const QRectF sDefaultRect;
virtual void rotateAroundTopLeftOrigin(qreal angle); virtual void rotateAroundCenter(qreal angle);
virtual QPointF topLeftOrigin() const; virtual QPointF rotationCenter() const;
int sFillTransparency;
int sDrawTransparency;
}; };
#endif /* UBGRAPHICSPROTRACTOR_H_ */ #endif /* UBGRAPHICSPROTRACTOR_H_ */
...@@ -22,6 +22,8 @@ const QRect UBGraphicsRuler::sDefaultRect = QRect(0, 0, 800, ...@@ -22,6 +22,8 @@ const QRect UBGraphicsRuler::sDefaultRect = QRect(0, 0, 800,
UBGraphicsRuler::UBGraphicsRuler() UBGraphicsRuler::UBGraphicsRuler()
: QGraphicsRectItem() : QGraphicsRectItem()
, mResizing(false)
, mRotating(false)
{ {
setRect(sDefaultRect); setRect(sDefaultRect);
...@@ -29,10 +31,31 @@ UBGraphicsRuler::UBGraphicsRuler() ...@@ -29,10 +31,31 @@ UBGraphicsRuler::UBGraphicsRuler()
mResizeSvgItem->setVisible(false); mResizeSvgItem->setVisible(false);
mResizeSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); mResizeSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
mRotateSvgItem = new QGraphicsSvgItem(":/images/rotateTool.svg", this);
mRotateSvgItem->setVisible(false);
mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
create(*this); create(*this);
updateResizeCursor();
} }
void UBGraphicsRuler::updateResizeCursor()
{
QPixmap pix(":/images/cursors/resize.png");
QTransform itemTransform = sceneTransform();
QRectF itemRect = boundingRect();
QPointF topLeft = itemTransform.map(itemRect.topLeft());
QPointF topRight = itemTransform.map(itemRect.topRight());
QLineF topLine(topLeft, topRight);
qreal angle = topLine.angle();
QTransform tr;
tr.rotate(- angle);
QCursor resizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2);
mResizeCursor = resizeCursor;
}
UBGraphicsRuler::~UBGraphicsRuler() UBGraphicsRuler::~UBGraphicsRuler()
{ {
// NOOP // NOOP
...@@ -62,9 +85,14 @@ void UBGraphicsRuler::paint(QPainter *painter, const QStyleOptionGraphicsItem *s ...@@ -62,9 +85,14 @@ void UBGraphicsRuler::paint(QPainter *painter, const QStyleOptionGraphicsItem *s
QTransform antiScaleTransform2; QTransform antiScaleTransform2;
qreal ratio = mAntiScaleRatio > 1.0 ? mAntiScaleRatio : 1.0; qreal ratio = mAntiScaleRatio > 1.0 ? mAntiScaleRatio : 1.0;
antiScaleTransform2.scale(ratio, 1.0); antiScaleTransform2.scale(ratio, 1.0);
mResizeSvgItem->setTransform(antiScaleTransform2); mResizeSvgItem->setTransform(antiScaleTransform2);
mResizeSvgItem->setPos(resizeButtonRect().topLeft()); mResizeSvgItem->setPos(resizeButtonRect().topLeft());
mRotateSvgItem->setTransform(antiScaleTransform2);
mRotateSvgItem->setPos(rotateButtonRect().topLeft());
painter->setPen(drawColor()); painter->setPen(drawColor());
painter->drawRoundedRect(rect(), sRoundingRadius, sRoundingRadius); painter->drawRoundedRect(rect(), sRoundingRadius, sRoundingRadius);
...@@ -122,13 +150,13 @@ void UBGraphicsRuler::paintGraduations(QPainter *painter) ...@@ -122,13 +150,13 @@ void UBGraphicsRuler::paintGraduations(QPainter *painter)
QFontMetricsF fontMetrics(painter->font()); QFontMetricsF fontMetrics(painter->font());
for (int millimeters = 0; millimeters < (rect().width() - sLeftEdgeMargin - sRoundingRadius) / sPixelsPerMillimeter; millimeters++) for (int millimeters = 0; millimeters < (rect().width() - sLeftEdgeMargin - sRoundingRadius) / sPixelsPerMillimeter; millimeters++)
{ {
int graduationX = topLeftOrigin().x() + sPixelsPerMillimeter * millimeters; int graduationX = rotationCenter().x() + sPixelsPerMillimeter * millimeters;
int graduationHeight = (0 == millimeters % millimetersPerCentimeter) ? int graduationHeight = (0 == millimeters % millimetersPerCentimeter) ?
centimeterGraduationHeight : centimeterGraduationHeight :
((0 == millimeters % millimetersPerHalfCentimeter) ? ((0 == millimeters % millimetersPerHalfCentimeter) ?
halfCentimeterGraduationHeight : millimeterGraduationHeight); halfCentimeterGraduationHeight : millimeterGraduationHeight);
painter->drawLine(QLine(graduationX, topLeftOrigin().y(), graduationX, topLeftOrigin().y() + graduationHeight)); painter->drawLine(QLine(graduationX, rotationCenter().y(), graduationX, rotationCenter().y() + graduationHeight));
painter->drawLine(QLine(graduationX, topLeftOrigin().y() + rect().height(), graduationX, topLeftOrigin().y() + rect().height() - graduationHeight)); painter->drawLine(QLine(graduationX, rotationCenter().y() + rect().height(), graduationX, rotationCenter().y() + rect().height() - graduationHeight));
if (0 == millimeters % millimetersPerCentimeter) if (0 == millimeters % millimetersPerCentimeter)
{ {
QString text = QString("%1").arg((int)(millimeters / millimetersPerCentimeter)); QString text = QString("%1").arg((int)(millimeters / millimetersPerCentimeter));
...@@ -151,21 +179,21 @@ void UBGraphicsRuler::paintGraduations(QPainter *painter) ...@@ -151,21 +179,21 @@ void UBGraphicsRuler::paintGraduations(QPainter *painter)
void UBGraphicsRuler::paintRotationCenter(QPainter *painter) void UBGraphicsRuler::paintRotationCenter(QPainter *painter)
{ {
painter->drawArc( painter->drawArc(
topLeftOrigin().x() - sRotationRadius, topLeftOrigin().y() - sRotationRadius, rotationCenter().x() - sRotationRadius, rotationCenter().y() - sRotationRadius,
2 * sRotationRadius, 2 * sRotationRadius, 2 * sRotationRadius, 2 * sRotationRadius,
270 * sDegreeToQtAngleUnit, 90 * sDegreeToQtAngleUnit); 270 * sDegreeToQtAngleUnit, 90 * sDegreeToQtAngleUnit);
} }
void UBGraphicsRuler::rotateAroundTopLeftOrigin(qreal angle) void UBGraphicsRuler::rotateAroundCenter(qreal angle)
{ {
QTransform transform; QTransform transform;
transform.translate(topLeftOrigin().x(), topLeftOrigin().y()); transform.translate(rotationCenter().x(), rotationCenter().y());
transform.rotate(angle); transform.rotate(angle);
transform.translate(- topLeftOrigin().x(), - topLeftOrigin().y()); transform.translate(- rotationCenter().x(), - rotationCenter().y());
setTransform(transform, true); setTransform(transform, true);
} }
QPointF UBGraphicsRuler::topLeftOrigin() const QPointF UBGraphicsRuler::rotationCenter() const
{ {
return QPointF(rect().x() + sLeftEdgeMargin, rect().y()); return QPointF(rect().x() + sLeftEdgeMargin, rect().y());
} }
...@@ -246,7 +274,7 @@ void UBGraphicsRuler::hoverMoveEvent(QGraphicsSceneHoverEvent *event) ...@@ -246,7 +274,7 @@ void UBGraphicsRuler::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
event->accept(); event->accept();
} }
else if (currentTool == UBStylusTool::Pen || currentTool == UBStylusTool::Marker) else if (UBDrawingController::drawingController()->isDrawingTool())
{ {
event->accept(); event->accept();
} }
...@@ -292,9 +320,9 @@ void UBGraphicsRuler::mouseMoveEvent(QGraphicsSceneMouseEvent *event) ...@@ -292,9 +320,9 @@ void UBGraphicsRuler::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
} }
else else
{ {
QLineF currentLine(topLeftOrigin(), event->pos()); QLineF currentLine(rotationCenter(), event->pos());
QLineF lastLine(topLeftOrigin(), event->lastPos()); QLineF lastLine(rotationCenter(), event->lastPos());
rotateAroundTopLeftOrigin(currentLine.angleTo(lastLine)); rotateAroundCenter(currentLine.angleTo(lastLine));
} }
event->accept(); event->accept();
...@@ -311,8 +339,8 @@ void UBGraphicsRuler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) ...@@ -311,8 +339,8 @@ void UBGraphicsRuler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
else if (mRotating) else if (mRotating)
{ {
mRotating = false; mRotating = false;
updateResizeCursor(*this); updateResizeCursor();
update(QRectF(topLeftOrigin(), QSizeF(sRotationRadius, sRotationRadius))); update(QRectF(rotationCenter(), QSizeF(sRotationRadius, sRotationRadius)));
event->accept(); event->accept();
} }
else if (closeButtonRect().contains(event->pos())) else if (closeButtonRect().contains(event->pos()))
......
...@@ -39,10 +39,6 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu ...@@ -39,10 +39,6 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu
virtual void DrawLine(const QPointF& position, qreal width); virtual void DrawLine(const QPointF& position, qreal width);
virtual void EndLine(); virtual void EndLine();
signals:
void hidden();
protected: protected:
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget);
...@@ -57,24 +53,37 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu ...@@ -57,24 +53,37 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
private: private:
bool mResizing;
bool mRotating;
// Helpers // Helpers
void fillBackground(QPainter *painter); void fillBackground(QPainter *painter);
void paintGraduations(QPainter *painter); void paintGraduations(QPainter *painter);
void paintRotationCenter(QPainter *painter); void paintRotationCenter(QPainter *painter);
virtual void rotateAroundTopLeftOrigin(qreal angle); virtual void rotateAroundCenter(qreal angle);
QGraphicsSvgItem* mRotateSvgItem;
QGraphicsSvgItem* mResizeSvgItem; QGraphicsSvgItem* mResizeSvgItem;
virtual QPointF topLeftOrigin() const; void updateResizeCursor();
QCursor resizeCursor() const{return mResizeCursor;}
virtual QPointF rotationCenter() const;
virtual QRectF resizeButtonRect() const; virtual QRectF resizeButtonRect() const;
virtual QRectF closeButtonRect() const; virtual QRectF closeButtonRect() const;
virtual QRectF rotateButtonRect() const; virtual QRectF rotateButtonRect() const;
virtual UBGraphicsScene* scene() const; virtual UBGraphicsScene* scene() const;
QCursor mResizeCursor;
int drawLineDirection; int drawLineDirection;
// Constants // Constants
static const QRect sDefaultRect; static const QRect sDefaultRect;
static const int sMinLength = 150;
}; };
#endif /* UBGRAPHICSRULER_H_ */ #endif /* UBGRAPHICSRULER_H_ */
...@@ -15,12 +15,30 @@ const UBGraphicsTriangle::UBGraphicsTriangleOrientation UBGraphicsTriangle::sDef ...@@ -15,12 +15,30 @@ const UBGraphicsTriangle::UBGraphicsTriangleOrientation UBGraphicsTriangle::sDef
UBGraphicsTriangle::BottomLeft; UBGraphicsTriangle::BottomLeft;
UBGraphicsTriangle::UBGraphicsTriangle() UBGraphicsTriangle::UBGraphicsTriangle()
:QGraphicsPolygonItem() : QGraphicsPolygonItem()
, UBAbstractDrawRuler()
, mResizing1(false)
, mResizing2(false)
, mRotating(false)
{ {
setRect(sDefaultRect, sDefaultOrientation); setRect(sDefaultRect, sDefaultOrientation);
create(*this); create(*this);
mHFlipSvgItem = new QGraphicsSvgItem(":/images/hflipTool.svg", this);
mHFlipSvgItem->setVisible(false);
mHFlipSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
mVFlipSvgItem = new QGraphicsSvgItem(":/images/vflipTool.svg", this);
mVFlipSvgItem->setVisible(false);
mVFlipSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
mRotateSvgItem = new QGraphicsSvgItem(":/images/rotateTool.svg", this);
mRotateSvgItem->setVisible(false);
mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
//updateResizeCursor(); //updateResizeCursor();
} }
...@@ -45,50 +63,33 @@ UBItem* UBGraphicsTriangle::deepCopy(void) const ...@@ -45,50 +63,33 @@ UBItem* UBGraphicsTriangle::deepCopy(void) const
void UBGraphicsTriangle::setRect(qreal x, qreal y, qreal w, qreal h, UBGraphicsTriangleOrientation orientation) void UBGraphicsTriangle::setRect(qreal x, qreal y, qreal w, qreal h, UBGraphicsTriangleOrientation orientation)
{ {
mRect.setCoords(x, y, x+w, y+h);
mOrientation = orientation;
QPolygonF polygon; QPolygonF polygon;
polygon << QPointF(x, y) << QPoint(x, y + h) << QPoint(x+w, y + h) << QPoint(x, y); polygon << QPointF(x, y) << QPoint(x, y + h) << QPoint(x+w, y + h) << QPoint(x, y);
setPolygon(polygon);
QTransform t; setOrientation(orientation);
}
void UBGraphicsTriangle::setOrientation(UBGraphicsTriangleOrientation orientation)
{
mOrientation = orientation;
QTransform t;
switch(orientation) switch(orientation)
{ {
case BottomLeft: case BottomLeft:
t.setMatrix(1, 0, 0, 0, 1, 0, 0, 0, 1); t.setMatrix(1, 0, 0, 0, 1, 0, 0, 0, 1);
break; break;
case BottomRight: case BottomRight:
t.setMatrix(-1, 0, 0, 0, 1, 0, x, 0, 1); t.setMatrix(-1, 0, 0, 0, 1, 0, boundingRect().right(), 0, 1);
break;
case TopLeft:
t.setMatrix(1, 0, 0, 0, -1, 0, 0, y, 1);
break;
case TopRight:
t.setMatrix(-1, 0, 0, 0, -1, 0, x, y, 1);
break;
}
/*
switch(orientation)
{
case BottomLeft:
polygon << QPointF(x, y) << QPoint(x, y + h) << QPoint(x+w, y + h) << QPoint(x, y);
break;
case BottomRight:
polygon << QPointF(x, y + h) << QPoint(x + w, y + y) << QPoint(x + w, y) << QPoint(x, y + h);
break; break;
case TopLeft: case TopLeft:
polygon << QPointF(x, y) << QPoint(x, y + h) << QPoint(x + w, y) << QPoint(x, y); t.setMatrix(1, 0, 0, 0, -1, 0, 0, boundingRect().bottom(), 1);
break; break;
case TopRight: case TopRight:
polygon << QPointF(x, y) << QPoint(x + w, y + h) << QPoint(x+w, y) << QPoint(x, y ); t.setMatrix(-1, 0, 0, 0, -1, 0, boundingRect().right(), boundingRect().bottom(), 1);
break; break;
} }
*/ setTransform(t, true);
setPolygon(polygon);
setTransform(t);
} }
UBGraphicsScene* UBGraphicsTriangle::scene() const UBGraphicsScene* UBGraphicsTriangle::scene() const
...@@ -96,26 +97,25 @@ UBGraphicsScene* UBGraphicsTriangle::scene() const ...@@ -96,26 +97,25 @@ UBGraphicsScene* UBGraphicsTriangle::scene() const
return static_cast<UBGraphicsScene*>(QGraphicsPolygonItem::scene()); return static_cast<UBGraphicsScene*>(QGraphicsPolygonItem::scene());
} }
void UBGraphicsTriangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget) void UBGraphicsTriangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{ {
QPointF A1(mRect.x(), mRect.y()); QPointF A1(rect().x(), rect().y());
QPointF B1(mRect.x(), mRect.y() + mRect.height()); QPointF B1(rect().x(), rect().y() + rect().height());
QPointF C1(mRect.x() + mRect.width(), mRect.y() + mRect.height()); QPointF C1(rect().x() + rect().width(), rect().y() + rect().height());
qreal d = 70; qreal C = sqrt(rect().width() * rect().width() + rect().height() * rect().height());
qreal C = sqrt(mRect.width() * mRect.width() + mRect.height() * mRect.height()); qreal L = (C * d + rect().width() * d)/ rect().height();
qreal L = (C * d + mRect.width() * d)/ mRect.height(); qreal K = (C * d + rect().height() * d)/ rect().width();
qreal K = (C * d + mRect.height() * d)/ mRect.width();
qreal W1 = mRect.height() * d / C; qreal W1 = rect().height() * d / C;
qreal H1 = mRect.width() * d / C; qreal H1 = rect().width() * d / C;
QPointF A2(mRect.x() + d, mRect.y() + K); QPointF A2(rect().x() + d, rect().y() + K);
QPointF B2(mRect.x() + d, mRect.y() + mRect.height() - d); QPointF B2(rect().x() + d, rect().y() + rect().height() - d);
QPointF C2(mRect.x() + mRect.width() - L, mRect.y() + mRect.height() - d); QPointF C2(rect().x() + rect().width() - L, rect().y() + rect().height() - d);
QPoint CC(mRect.x() + mRect.width() - L + W1, QPoint CC(rect().x() + rect().width() - L + W1,
mRect.y() + mRect.height() - d - H1); rect().y() + rect().height() - d - H1);
painter->setPen(Qt::NoPen); painter->setPen(Qt::NoPen);
...@@ -157,6 +157,29 @@ void UBGraphicsTriangle::paint(QPainter *painter, const QStyleOptionGraphicsItem ...@@ -157,6 +157,29 @@ void UBGraphicsTriangle::paint(QPainter *painter, const QStyleOptionGraphicsItem
painter->drawPolygon(polygon); painter->drawPolygon(polygon);
paintGraduations(painter); paintGraduations(painter);
mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom());
QTransform antiScaleTransform;
antiScaleTransform.scale(mAntiScaleRatio, mAntiScaleRatio);
mCloseSvgItem->setTransform(antiScaleTransform);
mHFlipSvgItem->setTransform(antiScaleTransform);
mVFlipSvgItem->setTransform(antiScaleTransform);
mRotateSvgItem->setTransform(antiScaleTransform);
mCloseSvgItem->setPos(closeButtonRect().topLeft());
mHFlipSvgItem->setPos(hFlipRect().topLeft());
mVFlipSvgItem->setPos(vFlipRect().topLeft());
mRotateSvgItem->setPos(rotateRect().topLeft());
if (mShowButtons || mResizing1 || mResizing2)
{
painter->setBrush(QColor(0, 0, 0));
if (mShowButtons || mResizing1)
painter->drawPolygon(resize1Polygon());
if (mShowButtons || mResizing2)
painter->drawPolygon(resize2Polygon());
}
} }
void UBGraphicsTriangle::paintGraduations(QPainter *painter) void UBGraphicsTriangle::paintGraduations(QPainter *painter)
...@@ -172,7 +195,7 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter) ...@@ -172,7 +195,7 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter)
QFontMetricsF fontMetrics(painter->font()); QFontMetricsF fontMetrics(painter->font());
for (int millimeters = 0; millimeters < (rect().width() - sLeftEdgeMargin - sRoundingRadius) / sPixelsPerMillimeter; millimeters++) for (int millimeters = 0; millimeters < (rect().width() - sLeftEdgeMargin - sRoundingRadius) / sPixelsPerMillimeter; millimeters++)
{ {
int graduationX = topLeftOrigin().x() + sPixelsPerMillimeter * millimeters; int graduationX = rotationCenter().x() + sPixelsPerMillimeter * millimeters;
int graduationHeight = (0 == millimeters % millimetersPerCentimeter) ? int graduationHeight = (0 == millimeters % millimetersPerCentimeter) ?
centimeterGraduationHeight : centimeterGraduationHeight :
((0 == millimeters % millimetersPerHalfCentimeter) ? ((0 == millimeters % millimetersPerHalfCentimeter) ?
...@@ -180,10 +203,10 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter) ...@@ -180,10 +203,10 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter)
// Check that grad. line inside triangle // Check that grad. line inside triangle
qreal lineY = rect().bottom() - rect().height()/rect().width()*(rect().width() - graduationX); qreal lineY = rect().bottom() - rect().height()/rect().width()*(rect().width() - graduationX);
if (lineY >= topLeftOrigin().y() + rect().height() - graduationHeight) if (lineY >= rotationCenter().y() + rect().height() - graduationHeight)
break; break;
painter->drawLine(QLine(graduationX, topLeftOrigin().y() + rect().height(), graduationX, topLeftOrigin().y() + rect().height() - graduationHeight)); painter->drawLine(QLine(graduationX, rotationCenter().y(), graduationX, rotationCenter().y() - graduationHeight));
if (0 == millimeters % millimetersPerCentimeter) if (0 == millimeters % millimetersPerCentimeter)
{ {
QString text = QString("%1").arg((int)(millimeters / millimetersPerCentimeter)); QString text = QString("%1").arg((int)(millimeters / millimetersPerCentimeter));
...@@ -208,25 +231,315 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter) ...@@ -208,25 +231,315 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter)
} }
void UBGraphicsTriangle::rotateAroundTopLeftOrigin(qreal angle) void UBGraphicsTriangle::rotateAroundCenter(qreal angle)
{}
QPointF UBGraphicsTriangle::topLeftOrigin() const
{ {
return QPointF(mRect.x() + sLeftEdgeMargin , mRect.y()); QTransform transform;
transform.translate(rotationCenter().x(), rotationCenter().y());
transform.rotate(angle);
transform.translate(- rotationCenter().x(), - rotationCenter().y());
setTransform(transform, true);
} }
QRectF UBGraphicsTriangle::resizeButtonRect() const QPointF UBGraphicsTriangle::rotationCenter() const
{ {
return QRectF(0,0,0,0); return QPointF(rect().x() + sLeftEdgeMargin , rect().bottom());
} }
QRectF UBGraphicsTriangle::closeButtonRect() const QRectF UBGraphicsTriangle::closeButtonRect() const
{ {
return QRectF(0,0,0,0); return QRectF(rect().x() + d - mCloseSvgItem->boundingRect().width() - 5,
rect().bottom() - d - mCloseSvgItem->boundingRect().height() - 5,
mCloseSvgItem->boundingRect().width(),
mCloseSvgItem->boundingRect().height());
}
QPolygonF UBGraphicsTriangle::resize1Polygon() const
{
qreal C = sqrt(rect().width() * rect().width() + rect().height() * rect().height());
QPolygonF p;
QPointF P1(rect().right() - sArrowLength, rect().bottom());
QPointF P2(rect().right() - sArrowLength * rect().width() / C,
rect().bottom() - sArrowLength * rect().height() / C );
p << QPointF(rect().right(), rect().bottom()) << P1 << P2;
return p;
}
QPolygonF UBGraphicsTriangle::resize2Polygon() const
{
qreal C = sqrt(rect().width() * rect().width() + rect().height() * rect().height());
QPolygonF p;
QPointF P1(rect().left(), rect().top() + sArrowLength);
QPointF P2(rect().left() + sArrowLength * rect().width() / C,
rect().top() + sArrowLength * rect().height() / C );
p << QPointF(rect().left(), rect().top()) << P1 << P2;
return p;
}
QRectF UBGraphicsTriangle::hFlipRect() const
{
return QRectF(rect().x() + d - mHFlipSvgItem->boundingRect().width() - 5,
rect().bottom() - d - mCloseSvgItem->boundingRect().height() - mVFlipSvgItem->boundingRect().height() -
mVFlipSvgItem->boundingRect().height() - 15,
mHFlipSvgItem->boundingRect().width(),
mHFlipSvgItem->boundingRect().height());
}
QRectF UBGraphicsTriangle::vFlipRect() const
{
return QRectF(rect().x() + d - mVFlipSvgItem->boundingRect().width() - 5,
rect().bottom() - d - mCloseSvgItem->boundingRect().height() - mVFlipSvgItem->boundingRect().height() - 10,
mVFlipSvgItem->boundingRect().width(),
mVFlipSvgItem->boundingRect().height());
}
QRectF UBGraphicsTriangle::rotateRect() const
{
QPointF A1(rect().x(), rect().y());
QPointF B1(rect().x(), rect().y() + rect().height());
QPointF C1(rect().x() + rect().width(), rect().y() + rect().height());
qreal C = sqrt(rect().width() * rect().width() + rect().height() * rect().height());
qreal L = (C * d + rect().width() * d)/ rect().height();
QPointF C2(rect().x() + rect().width() - L, rect().y() + rect().height() - d);
return QRectF(C2 + QPointF(20, 5), QSizeF(mRotateSvgItem->boundingRect().size()));
}
QCursor UBGraphicsTriangle::moveResizeCursor() const
{
return Qt::OpenHandCursor;
}
QCursor UBGraphicsTriangle::flipCursor() const
{
return Qt::ArrowCursor;
}
void UBGraphicsTriangle::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (resize1Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill))
{
mResizing1 = true;
event->accept();
}
else if (resize2Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill))
{
mResizing2 = true;
event->accept();
}
else if(rotateRect().contains(event->pos()))
{
mRotating = true;
event->accept();
}
else
{
QGraphicsItem::mousePressEvent(event);
}
mShowButtons = false;
mCloseSvgItem->setVisible(false);
mHFlipSvgItem->setVisible(false);
mVFlipSvgItem->setVisible(false);
mRotateSvgItem->setVisible(mRotating);
update();
}
void UBGraphicsTriangle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (!mResizing1 && !mResizing2 && !mRotating)
{
QGraphicsItem::mouseMoveEvent(event);
}
else
{
if (mResizing1)
{
QPointF delta = event->pos() - event->lastPos();
if (rect().width() + delta.x() < sMinWidth)
delta.setX(sMinWidth - rect().width());
if (mOrientation == TopLeft || mOrientation == BottomLeft)
{
setRect(QRectF(
rect().topLeft(),
QSizeF(rect().width() + delta.x(),
rect().height())),
mOrientation);
}
else
{
setRect(
rect().left() - delta.x(),
rect().top(),
rect().width() + delta.x(),
rect().height(),
mOrientation
);
}
}
if (mResizing2)
{
QPointF delta = event->pos() - event->lastPos();
if (rect().height() + delta.y() < sMinHeight)
delta.setY(sMinHeight - rect().height());
qDebug() << delta;
setRect(QRect(
rect().left(),
rect().top() + delta.y(),
rect().width(),
rect().height() - delta.y()),
mOrientation);
}
if (mRotating)
{
QLineF currentLine(rotationCenter(), event->pos());
QLineF lastLine(rotationCenter(), event->lastPos());
rotateAroundCenter(currentLine.angleTo(lastLine));
}
event->accept();
}
}
void UBGraphicsTriangle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (mResizing1 || mResizing2 || mRotating)
{
mResizing1 = false;
mResizing2 = false;
mRotating = false;
event->accept();
}
else if (closeButtonRect().contains(event->pos()))
{
hide();
emit hidden();
event->accept();
}
else if (hFlipRect().contains(event->pos()))
{
switch(mOrientation)
{
case BottomLeft:
setOrientation(BottomRight);
break;
case BottomRight:
setOrientation(BottomLeft);
break;
case TopLeft:
setOrientation(TopRight);
break;
case TopRight:
setOrientation(TopLeft);
break;
}
}
else if (vFlipRect().contains(event->pos()))
{
switch(mOrientation)
{
case BottomLeft:
setOrientation(TopLeft);
break;
case BottomRight:
setOrientation(TopRight);
break;
case TopLeft:
setOrientation(BottomLeft);
break;
case TopRight:
setOrientation(BottomRight);
break;
}
}
else
{
QGraphicsItem::mouseReleaseEvent(event);
}
mShowButtons = true;
update();
if (scene())
scene()->setModified(true);
} }
QRectF UBGraphicsTriangle::rotateButtonRect() const void UBGraphicsTriangle::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
return QRectF(0,0,0,0); UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
if (currentTool == UBStylusTool::Selector)
{
mCloseSvgItem->setParentItem(this);
mShowButtons = true;
mCloseSvgItem->setVisible(true);
mHFlipSvgItem->setVisible(true);
mVFlipSvgItem->setVisible(true);
mRotateSvgItem->setVisible(true);
if (resize1Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill) ||
resize2Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill))
setCursor(moveResizeCursor());
else if (closeButtonRect().contains(event->pos()))
setCursor(closeCursor());
else if (hFlipRect().contains(event->pos())
|| vFlipRect().contains(event->pos()))
setCursor(flipCursor());
else if (rotateRect().contains(event->pos()))
setCursor(rotateCursor());
else
setCursor(moveCursor());
event->accept();
update();
}
}
void UBGraphicsTriangle::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
mShowButtons = false;
setCursor(Qt::ArrowCursor);
mCloseSvgItem->setVisible(false);
mVFlipSvgItem->setVisible(false);
mHFlipSvgItem->setVisible(false);
mRotateSvgItem->setVisible(false);
event->accept();
update();
}
void UBGraphicsTriangle::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
if (currentTool == UBStylusTool::Selector)
{
mCloseSvgItem->setVisible(mShowButtons);
mVFlipSvgItem->setVisible(mShowButtons);
mHFlipSvgItem->setVisible(mShowButtons);
mRotateSvgItem->setVisible(mShowButtons);
if (resize1Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill) ||
resize2Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill))
setCursor(moveResizeCursor());
else if (closeButtonRect().contains(event->pos()))
setCursor(closeCursor());
else if (hFlipRect().contains(event->pos())
|| vFlipRect().contains(event->pos()))
setCursor(flipCursor());
else if (rotateRect().contains(event->pos()))
setCursor(rotateCursor());
else
setCursor(moveCursor());
event->accept();
}
} }
...@@ -60,30 +60,58 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt ...@@ -60,30 +60,58 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
setRect(rect.x(), rect.y(), rect.width(), rect.height(), orientation); setRect(rect.x(), rect.y(), rect.width(), rect.height(), orientation);
} }
void setRect(qreal x, qreal y, qreal w, qreal h, UBGraphicsTriangleOrientation orientation); void setRect(qreal x, qreal y, qreal w, qreal h, UBGraphicsTriangleOrientation orientation);
QRectF rect() const {return mRect;} void setOrientation(UBGraphicsTriangleOrientation orientation);
QRectF rect() const {return boundingRect();}
UBGraphicsScene* scene() const; UBGraphicsScene* scene() const;
protected: protected:
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget); virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget);
virtual void rotateAroundTopLeftOrigin(qreal angle); virtual void rotateAroundCenter(qreal angle);
virtual QPointF topLeftOrigin() const; virtual QPointF rotationCenter() const;
virtual QRectF resizeButtonRect() const;
virtual QRectF closeButtonRect() const;
virtual QRectF rotateButtonRect() const;
virtual QRectF closeButtonRect() const;
QPolygonF resize1Polygon() const;
QPolygonF resize2Polygon() const;
QRectF hFlipRect() const;
QRectF vFlipRect() const;
QRectF rotateRect() const;
QCursor moveResizeCursor() const;
QCursor flipCursor() const;
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
private: private:
bool mResizing1;
bool mResizing2;
bool mRotating;
QGraphicsSvgItem* mHFlipSvgItem;
QGraphicsSvgItem* mVFlipSvgItem;
QGraphicsSvgItem* mRotateSvgItem;
static const QRect sDefaultRect; static const QRect sDefaultRect;
static const UBGraphicsTriangleOrientation sDefaultOrientation; static const UBGraphicsTriangleOrientation sDefaultOrientation;
void paintGraduations(QPainter *painter); void paintGraduations(QPainter *painter);
QRectF mRect;
UBGraphicsTriangleOrientation mOrientation; UBGraphicsTriangleOrientation mOrientation;
static const int d = 70; // width of triangle border
static const int sArrowLength = 30;
static const int sMinWidth = 200;
static const int sMinHeight = 150;
}; };
#endif /* UBGRAPHICSTRIANGLE_H_ */ #endif /* UBGRAPHICSTRIANGLE_H_ */
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