diff --git a/resources/images/hflipTool.svg b/resources/images/hflipTool.svg new file mode 100644 index 00000000..c4659433 --- /dev/null +++ b/resources/images/hflipTool.svg @@ -0,0 +1,69 @@ + + + +image/svg+xml + + + + + \ No newline at end of file diff --git a/resources/images/vflipTool.svg b/resources/images/vflipTool.svg new file mode 100644 index 00000000..316b77bb --- /dev/null +++ b/resources/images/vflipTool.svg @@ -0,0 +1,68 @@ + + + +image/svg+xml + + + + + \ No newline at end of file diff --git a/resources/sankore.qrc b/resources/sankore.qrc index 9ac47637..89fbdaf7 100644 --- a/resources/sankore.qrc +++ b/resources/sankore.qrc @@ -33,6 +33,8 @@ images/resizeRuler.svg images/resizeCompass.svg images/closeTool.svg + images/hflipTool.svg + images/vflipTool.svg images/resetTool.svg images/angleMarker.svg images/currentDocument.png diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 1ed33cae..e95ae96e 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -2580,8 +2580,6 @@ UBGraphicsTriangle* UBSvgSubsetAdaptor::UBSvgSubsetReader::triangleFromSvg() QStringRef svgY = mXmlReader.attributes().value("y"); QStringRef svgWidth = mXmlReader.attributes().value("width"); QStringRef svgHeight = mXmlReader.attributes().value("height"); - - QStringRef orientationStringRef = mXmlReader.attributes().value("orientation"); UBGraphicsTriangle::UBGraphicsTriangleOrientation orientation = UBGraphicsTriangle::orientationFromStr(orientationStringRef); diff --git a/src/core/UBDisplayManager.cpp b/src/core/UBDisplayManager.cpp index aa2f824d..b1e8e3ff 100644 --- a/src/core/UBDisplayManager.cpp +++ b/src/core/UBDisplayManager.cpp @@ -117,7 +117,7 @@ void UBDisplayManager::setAsControl(QWidget* pControlWidget ) mControlWidget->showFullScreen(); // !!!! Should be included into Windows after QT recompilation #ifdef Q_WS_MAC - mControlWidget->setAttribute(Qt::WA_MacNoShadow); +// mControlWidget->setAttribute(Qt::WA_MacNoShadow); #endif } } @@ -133,7 +133,7 @@ void UBDisplayManager::setAsDisplay(QWidget* pDisplayWidget) mDisplayWidget->showFullScreen(); // !!!! Should be included into Windows after QT recompilation #ifdef Q_WS_MAC - mDisplayWidget->setAttribute(Qt::WA_MacNoShadow); +// mDisplayWidget->setAttribute(Qt::WA_MacNoShadow); #endif } } diff --git a/src/desktop/UBDesktopAnnotationController.cpp b/src/desktop/UBDesktopAnnotationController.cpp index 08a8b5cb..62836456 100644 --- a/src/desktop/UBDesktopAnnotationController.cpp +++ b/src/desktop/UBDesktopAnnotationController.cpp @@ -64,7 +64,7 @@ UBDesktopAnnotationController::UBDesktopAnnotationController(QObject *parent) mTransparentDrawingView->setAttribute(Qt::WA_TranslucentBackground, true); // !!!! Should be included into Windows after QT recompilation #ifdef Q_WS_MAC - mTransparentDrawingView->setAttribute(Qt::WA_MacNoShadow, true); + //mTransparentDrawingView->setAttribute(Qt::WA_MacNoShadow, true); #endif mTransparentDrawingView->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Window); mTransparentDrawingView->setCacheMode(QGraphicsView::CacheNone); diff --git a/src/gui/UBDockPalette.cpp b/src/gui/UBDockPalette.cpp index 1e3d1a64..d167c2f5 100644 --- a/src/gui/UBDockPalette.cpp +++ b/src/gui/UBDockPalette.cpp @@ -38,7 +38,7 @@ UBDockPalette::UBDockPalette(QWidget *parent, const char *name) // !!!! Should be included into Windows after QT recompilation #ifdef Q_WS_MAC - setAttribute(Qt::WA_MacNoShadow); + //setAttribute(Qt::WA_MacNoShadow); #endif } diff --git a/src/gui/UBFloatingPalette.cpp b/src/gui/UBFloatingPalette.cpp index 9171a0f4..511bc9ef 100644 --- a/src/gui/UBFloatingPalette.cpp +++ b/src/gui/UBFloatingPalette.cpp @@ -33,8 +33,8 @@ UBFloatingPalette::UBFloatingPalette(Qt::Corner position, QWidget *parent) setAttribute(Qt::WA_MacAlwaysShowToolWindow); #endif #ifdef Q_WS_MAC - setAttribute(Qt::WA_MacNonActivatingToolWindow); - setAttribute(Qt::WA_MacNoShadow); + //setAttribute(Qt::WA_MacNonActivatingToolWindow); + //setAttribute(Qt::WA_MacNoShadow); #endif } diff --git a/src/network/UBNetworkAccessManager.cpp b/src/network/UBNetworkAccessManager.cpp index a1aef846..9a681c0d 100644 --- a/src/network/UBNetworkAccessManager.cpp +++ b/src/network/UBNetworkAccessManager.cpp @@ -14,6 +14,7 @@ #include "UBCookieJar.h" + #include "core/memcheck.h" UBNetworkAccessManager *UBNetworkAccessManager::sNetworkAccessManager = 0; diff --git a/src/pdf/XPDFRenderer.cpp b/src/pdf/XPDFRenderer.cpp index 86ad687c..cf81d4ae 100644 --- a/src/pdf/XPDFRenderer.cpp +++ b/src/pdf/XPDFRenderer.cpp @@ -127,8 +127,9 @@ void XPDFRenderer::render(QPainter *p, int pageNumber, const QRectF &bounds) qreal xscale = p->worldTransform().m11(); qreal yscale = p->worldTransform().m22(); bool bZoomChanged = false; + bool bFirstThumbnail = false; - if(mScaleX != xscale || mScaleY != yscale) + if(fabs(mScaleX - xscale) > 0.1 || fabs(mScaleY - yscale) > 0.1) { mScaleX = xscale; mScaleY = yscale; @@ -138,9 +139,14 @@ void XPDFRenderer::render(QPainter *p, int pageNumber, const QRectF &bounds) // First verify if the thumbnails and the pages are generated if(!bThumbGenerated) { + if(pageNumber == 1) + { + bFirstThumbnail = true; + } if(!mThumbMap[pageNumber - 1]) { + // Generate the thumbnail mThumbs << *createPDFImage(pageNumber, xscale, yscale, bounds); mThumbMap[pageNumber - 1] = true; @@ -164,10 +170,9 @@ void XPDFRenderer::render(QPainter *p, int pageNumber, const QRectF &bounds) } } - // Warning: verify pagenumber QImage pdfImage; - if(!bThumbGenerated) + if(!bThumbGenerated || bFirstThumbnail) { pdfImage = mThumbs.at(pageNumber - 1); } @@ -176,8 +181,6 @@ void XPDFRenderer::render(QPainter *p, int pageNumber, const QRectF &bounds) pdfImage = mNumPageToPageMap[pageNumber]; } - pdfImage.rect(); - QTransform savedTransform = p->worldTransform(); p->resetTransform(); p->drawImage(QPointF(savedTransform.dx() + mSliceX, savedTransform.dy() + mSliceY), pdfImage); diff --git a/src/tools/UBAbstractDrawRuler.cpp b/src/tools/UBAbstractDrawRuler.cpp index 5297d99a..03ec15f0 100644 --- a/src/tools/UBAbstractDrawRuler.cpp +++ b/src/tools/UBAbstractDrawRuler.cpp @@ -19,9 +19,7 @@ const QColor UBAbstractDrawRuler::sDarkBackgroundEdgeFillColor = QColor(0xdd, 0x const QColor UBAbstractDrawRuler::sDarkBackgroundDrawColor = QColor(0xff, 0xff, 0xff, sDrawTransparency); UBAbstractDrawRuler::UBAbstractDrawRuler() - : mResizing(false) - , mRotating(false) - , mShowButtons(false) + : mShowButtons(false) , mAntiScaleRatio(1.0) {} @@ -36,12 +34,6 @@ void UBAbstractDrawRuler::create(QGraphicsItem& item) mCloseSvgItem = new QGraphicsSvgItem(":/images/closeTool.svg", &item); mCloseSvgItem->setVisible(false); 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() { } -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 { return Qt::SizeAllCursor; } -QCursor UBAbstractDrawRuler::resizeCursor() const -{ - return mResizeCursor; -} - QCursor UBAbstractDrawRuler::rotateCursor() const { return UBResources::resources()->rotateCursor; @@ -129,9 +100,6 @@ void UBAbstractDrawRuler::paint() mCloseSvgItem->setTransform(antiScaleTransform); mCloseSvgItem->setPos(closeButtonRect().topLeft()); - mRotateSvgItem->setTransform(antiScaleTransform); - mRotateSvgItem->setPos(rotateButtonRect().topLeft()); - } diff --git a/src/tools/UBAbstractDrawRuler.h b/src/tools/UBAbstractDrawRuler.h index 76c74fb6..ed2d411c 100644 --- a/src/tools/UBAbstractDrawRuler.h +++ b/src/tools/UBAbstractDrawRuler.h @@ -19,33 +19,27 @@ public: virtual void DrawLine(const QPointF& position, qreal width); virtual void EndLine(); + signals: + void hidden(); + protected: void paint(); virtual UBGraphicsScene* scene() const = 0; - virtual void rotateAroundTopLeftOrigin(qreal angle) = 0; + virtual void rotateAroundCenter(qreal angle) = 0; - virtual QPointF topLeftOrigin() const = 0; - virtual QRectF resizeButtonRect() const = 0; + virtual QPointF rotationCenter() const = 0; virtual QRectF closeButtonRect() const = 0; - virtual QRectF rotateButtonRect() const = 0; - - void updateResizeCursor(QGraphicsItem &item); - bool mResizing; - bool mRotating; bool mShowButtons; QGraphicsSvgItem* mCloseSvgItem; - QGraphicsSvgItem* mRotateSvgItem; - QCursor mResizeCursor; qreal mAntiScaleRatio; QPointF startDrawPosition; QCursor moveCursor() const; - QCursor resizeCursor() const; QCursor rotateCursor() const; QCursor closeCursor() const; QCursor drawRulerLineCursor() const; @@ -63,7 +57,6 @@ protected: static const QColor sDarkBackgroundDrawColor; static const int sLeftEdgeMargin = 10; - static const int sMinLength = 150; static const int sDegreeToQtAngleUnit = 16; static const int sRotationRadius = 15; static const int sPixelsPerMillimeter = 5; diff --git a/src/tools/UBGraphicsProtractor.cpp b/src/tools/UBGraphicsProtractor.cpp index 50457632..318b3e3f 100644 --- a/src/tools/UBGraphicsProtractor.cpp +++ b/src/tools/UBGraphicsProtractor.cpp @@ -13,7 +13,6 @@ #include "board/UBBoardController.h" #include "board/UBDrawingController.h" - #include "core/memcheck.h" @@ -31,8 +30,6 @@ UBGraphicsProtractor::UBGraphicsProtractor() , mResizeSvgItem(0) , mMarkerSvgItem(0) { - sFillTransparency = 127; - sDrawTransparency = 192; create(*this); @@ -44,17 +41,19 @@ UBGraphicsProtractor::UBGraphicsProtractor() mResetSvgItem = new QGraphicsSvgItem(":/images/resetTool.svg", this); mResetSvgItem->setVisible(false); mResetSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); - mResetSvgItem->setPos(resetButtonRect().topLeft()); mResizeSvgItem = new QGraphicsSvgItem(":/images/resizeTool.svg", this); mResizeSvgItem->setVisible(false); mResizeSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); - mResizeSvgItem->setPos(resizeButtonRect().topLeft()); mMarkerSvgItem = new QGraphicsSvgItem(":/images/angleMarker.svg", this); mMarkerSvgItem->setVisible(false); 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); } @@ -586,12 +585,12 @@ UBItem* UBGraphicsProtractor::deepCopy() const } -void UBGraphicsProtractor::rotateAroundTopLeftOrigin(qreal angle) +void UBGraphicsProtractor::rotateAroundCenter(qreal angle) { Q_UNUSED(angle); } -QPointF UBGraphicsProtractor::topLeftOrigin() const +QPointF UBGraphicsProtractor::rotationCenter() const { return QPointF(rect().x(), rect().y()); } diff --git a/src/tools/UBGraphicsProtractor.h b/src/tools/UBGraphicsProtractor.h index 354974c5..76dc2546 100644 --- a/src/tools/UBGraphicsProtractor.h +++ b/src/tools/UBGraphicsProtractor.h @@ -41,10 +41,6 @@ class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipse return Type; } - signals: - - void hidden(); - protected: virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget); @@ -62,10 +58,10 @@ class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipse private: // Helpers void paintGraduations (QPainter *painter); - void paintButtons (QPainter *painter); + void paintButtons (QPainter *painter); void paintAngleMarker (QPainter *painter); - Tool toolFromPos (QPointF pos); - qreal antiScale () const; + Tool toolFromPos (QPointF pos); + qreal antiScale () const; UBGraphicsScene* scene() const; QBrush fillBrush() const; @@ -90,14 +86,12 @@ class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipse QGraphicsSvgItem* mResetSvgItem; QGraphicsSvgItem* mResizeSvgItem; QGraphicsSvgItem* mMarkerSvgItem; + QGraphicsSvgItem* mRotateSvgItem; static const QRectF sDefaultRect; - virtual void rotateAroundTopLeftOrigin(qreal angle); - virtual QPointF topLeftOrigin() const; - - int sFillTransparency; - int sDrawTransparency; + virtual void rotateAroundCenter(qreal angle); + virtual QPointF rotationCenter() const; }; #endif /* UBGRAPHICSPROTRACTOR_H_ */ diff --git a/src/tools/UBGraphicsRuler.cpp b/src/tools/UBGraphicsRuler.cpp index cfc952ef..dd3c2f1f 100644 --- a/src/tools/UBGraphicsRuler.cpp +++ b/src/tools/UBGraphicsRuler.cpp @@ -22,6 +22,8 @@ const QRect UBGraphicsRuler::sDefaultRect = QRect(0, 0, 800, UBGraphicsRuler::UBGraphicsRuler() : QGraphicsRectItem() + , mResizing(false) + , mRotating(false) { setRect(sDefaultRect); @@ -29,10 +31,31 @@ UBGraphicsRuler::UBGraphicsRuler() mResizeSvgItem->setVisible(false); 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); + + 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() { // NOOP @@ -62,9 +85,14 @@ void UBGraphicsRuler::paint(QPainter *painter, const QStyleOptionGraphicsItem *s QTransform antiScaleTransform2; qreal ratio = mAntiScaleRatio > 1.0 ? mAntiScaleRatio : 1.0; antiScaleTransform2.scale(ratio, 1.0); + mResizeSvgItem->setTransform(antiScaleTransform2); mResizeSvgItem->setPos(resizeButtonRect().topLeft()); + mRotateSvgItem->setTransform(antiScaleTransform2); + mRotateSvgItem->setPos(rotateButtonRect().topLeft()); + + painter->setPen(drawColor()); painter->drawRoundedRect(rect(), sRoundingRadius, sRoundingRadius); @@ -122,13 +150,13 @@ void UBGraphicsRuler::paintGraduations(QPainter *painter) QFontMetricsF fontMetrics(painter->font()); 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) ? centimeterGraduationHeight : ((0 == millimeters % millimetersPerHalfCentimeter) ? halfCentimeterGraduationHeight : millimeterGraduationHeight); - painter->drawLine(QLine(graduationX, topLeftOrigin().y(), graduationX, topLeftOrigin().y() + graduationHeight)); - painter->drawLine(QLine(graduationX, topLeftOrigin().y() + rect().height(), graduationX, topLeftOrigin().y() + rect().height() - graduationHeight)); + painter->drawLine(QLine(graduationX, rotationCenter().y(), graduationX, rotationCenter().y() + graduationHeight)); + painter->drawLine(QLine(graduationX, rotationCenter().y() + rect().height(), graduationX, rotationCenter().y() + rect().height() - graduationHeight)); if (0 == millimeters % millimetersPerCentimeter) { QString text = QString("%1").arg((int)(millimeters / millimetersPerCentimeter)); @@ -151,21 +179,21 @@ void UBGraphicsRuler::paintGraduations(QPainter *painter) void UBGraphicsRuler::paintRotationCenter(QPainter *painter) { painter->drawArc( - topLeftOrigin().x() - sRotationRadius, topLeftOrigin().y() - sRotationRadius, + rotationCenter().x() - sRotationRadius, rotationCenter().y() - sRotationRadius, 2 * sRotationRadius, 2 * sRotationRadius, 270 * sDegreeToQtAngleUnit, 90 * sDegreeToQtAngleUnit); } -void UBGraphicsRuler::rotateAroundTopLeftOrigin(qreal angle) +void UBGraphicsRuler::rotateAroundCenter(qreal angle) { QTransform transform; - transform.translate(topLeftOrigin().x(), topLeftOrigin().y()); + transform.translate(rotationCenter().x(), rotationCenter().y()); transform.rotate(angle); - transform.translate(- topLeftOrigin().x(), - topLeftOrigin().y()); + transform.translate(- rotationCenter().x(), - rotationCenter().y()); setTransform(transform, true); } -QPointF UBGraphicsRuler::topLeftOrigin() const +QPointF UBGraphicsRuler::rotationCenter() const { return QPointF(rect().x() + sLeftEdgeMargin, rect().y()); } @@ -246,7 +274,7 @@ void UBGraphicsRuler::hoverMoveEvent(QGraphicsSceneHoverEvent *event) event->accept(); } - else if (currentTool == UBStylusTool::Pen || currentTool == UBStylusTool::Marker) + else if (UBDrawingController::drawingController()->isDrawingTool()) { event->accept(); } @@ -292,9 +320,9 @@ void UBGraphicsRuler::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } else { - QLineF currentLine(topLeftOrigin(), event->pos()); - QLineF lastLine(topLeftOrigin(), event->lastPos()); - rotateAroundTopLeftOrigin(currentLine.angleTo(lastLine)); + QLineF currentLine(rotationCenter(), event->pos()); + QLineF lastLine(rotationCenter(), event->lastPos()); + rotateAroundCenter(currentLine.angleTo(lastLine)); } event->accept(); @@ -311,8 +339,8 @@ void UBGraphicsRuler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) else if (mRotating) { mRotating = false; - updateResizeCursor(*this); - update(QRectF(topLeftOrigin(), QSizeF(sRotationRadius, sRotationRadius))); + updateResizeCursor(); + update(QRectF(rotationCenter(), QSizeF(sRotationRadius, sRotationRadius))); event->accept(); } else if (closeButtonRect().contains(event->pos())) diff --git a/src/tools/UBGraphicsRuler.h b/src/tools/UBGraphicsRuler.h index 99dcfdc8..ee5658d2 100644 --- a/src/tools/UBGraphicsRuler.h +++ b/src/tools/UBGraphicsRuler.h @@ -39,10 +39,6 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu virtual void DrawLine(const QPointF& position, qreal width); virtual void EndLine(); - signals: - - void hidden(); - protected: virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget); @@ -57,24 +53,37 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); private: + + bool mResizing; + bool mRotating; + + // Helpers void fillBackground(QPainter *painter); void paintGraduations(QPainter *painter); void paintRotationCenter(QPainter *painter); - virtual void rotateAroundTopLeftOrigin(qreal angle); + virtual void rotateAroundCenter(qreal angle); + QGraphicsSvgItem* mRotateSvgItem; QGraphicsSvgItem* mResizeSvgItem; - virtual QPointF topLeftOrigin() const; + void updateResizeCursor(); + QCursor resizeCursor() const{return mResizeCursor;} + + virtual QPointF rotationCenter() const; virtual QRectF resizeButtonRect() const; virtual QRectF closeButtonRect() const; virtual QRectF rotateButtonRect() const; virtual UBGraphicsScene* scene() const; + QCursor mResizeCursor; + int drawLineDirection; // Constants static const QRect sDefaultRect; + + static const int sMinLength = 150; }; #endif /* UBGRAPHICSRULER_H_ */ diff --git a/src/tools/UBGraphicsTriangle.cpp b/src/tools/UBGraphicsTriangle.cpp index 7c3f1a70..376c0230 100644 --- a/src/tools/UBGraphicsTriangle.cpp +++ b/src/tools/UBGraphicsTriangle.cpp @@ -15,12 +15,30 @@ const UBGraphicsTriangle::UBGraphicsTriangleOrientation UBGraphicsTriangle::sDef UBGraphicsTriangle::BottomLeft; UBGraphicsTriangle::UBGraphicsTriangle() - :QGraphicsPolygonItem() + : QGraphicsPolygonItem() + , UBAbstractDrawRuler() + , mResizing1(false) + , mResizing2(false) + , mRotating(false) + { setRect(sDefaultRect, sDefaultOrientation); 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(); } @@ -45,50 +63,33 @@ UBItem* UBGraphicsTriangle::deepCopy(void) const 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; 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) { case BottomLeft: t.setMatrix(1, 0, 0, 0, 1, 0, 0, 0, 1); break; case BottomRight: - t.setMatrix(-1, 0, 0, 0, 1, 0, x, 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); + t.setMatrix(-1, 0, 0, 0, 1, 0, boundingRect().right(), 0, 1); break; 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; 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; } - */ - setPolygon(polygon); - setTransform(t); + setTransform(t, true); } UBGraphicsScene* UBGraphicsTriangle::scene() const @@ -96,26 +97,25 @@ UBGraphicsScene* UBGraphicsTriangle::scene() const return static_cast(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 B1(mRect.x(), mRect.y() + mRect.height()); - QPointF C1(mRect.x() + mRect.width(), mRect.y() + mRect.height()); + 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 d = 70; - qreal C = sqrt(mRect.width() * mRect.width() + mRect.height() * mRect.height()); - qreal L = (C * d + mRect.width() * d)/ mRect.height(); - qreal K = (C * d + mRect.height() * d)/ mRect.width(); + qreal C = sqrt(rect().width() * rect().width() + rect().height() * rect().height()); + qreal L = (C * d + rect().width() * d)/ rect().height(); + qreal K = (C * d + rect().height() * d)/ rect().width(); - qreal W1 = mRect.height() * d / C; - qreal H1 = mRect.width() * d / C; + qreal W1 = rect().height() * d / C; + qreal H1 = rect().width() * d / C; - QPointF A2(mRect.x() + d, mRect.y() + K); - QPointF B2(mRect.x() + d, mRect.y() + mRect.height() - d); - QPointF C2(mRect.x() + mRect.width() - L, mRect.y() + mRect.height() - d); + QPointF A2(rect().x() + d, rect().y() + K); + QPointF B2(rect().x() + d, rect().y() + rect().height() - d); + QPointF C2(rect().x() + rect().width() - L, rect().y() + rect().height() - d); - QPoint CC(mRect.x() + mRect.width() - L + W1, - mRect.y() + mRect.height() - d - H1); + QPoint CC(rect().x() + rect().width() - L + W1, + rect().y() + rect().height() - d - H1); painter->setPen(Qt::NoPen); @@ -157,6 +157,29 @@ void UBGraphicsTriangle::paint(QPainter *painter, const QStyleOptionGraphicsItem painter->drawPolygon(polygon); 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) @@ -172,7 +195,7 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter) QFontMetricsF fontMetrics(painter->font()); 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) ? centimeterGraduationHeight : ((0 == millimeters % millimetersPerHalfCentimeter) ? @@ -180,10 +203,10 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter) // Check that grad. line inside triangle 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; - 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) { QString text = QString("%1").arg((int)(millimeters / millimetersPerCentimeter)); @@ -208,25 +231,315 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter) } -void UBGraphicsTriangle::rotateAroundTopLeftOrigin(qreal angle) -{} - -QPointF UBGraphicsTriangle::topLeftOrigin() const +void UBGraphicsTriangle::rotateAroundCenter(qreal angle) { - 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 { - 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(); + } } diff --git a/src/tools/UBGraphicsTriangle.h b/src/tools/UBGraphicsTriangle.h index 5cebf4a1..e74f2c06 100644 --- a/src/tools/UBGraphicsTriangle.h +++ b/src/tools/UBGraphicsTriangle.h @@ -60,30 +60,58 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt setRect(rect.x(), rect.y(), rect.width(), rect.height(), 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; + protected: + 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 QRectF resizeButtonRect() const; - virtual QRectF closeButtonRect() const; - virtual QRectF rotateButtonRect() const; + virtual QPointF rotationCenter() 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: + bool mResizing1; + bool mResizing2; + bool mRotating; + + QGraphicsSvgItem* mHFlipSvgItem; + QGraphicsSvgItem* mVFlipSvgItem; + QGraphicsSvgItem* mRotateSvgItem; + static const QRect sDefaultRect; static const UBGraphicsTriangleOrientation sDefaultOrientation; void paintGraduations(QPainter *painter); - QRectF mRect; 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_ */