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_ */
This diff is collapsed.
...@@ -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