Graphics ruler: drawing lines

preferencesAboutTextFull
Anatoly Mihalchenko 14 years ago
parent 4f09fe08a5
commit 3d8deb8c13
  1. BIN
      resources/images/cursors/drawRulerLine.png
  2. 1
      resources/sankore.qrc
  3. 3
      src/api/UBWidgetUniboardAPI.cpp
  4. 26
      src/board/UBBoardView.cpp
  5. 1
      src/board/UBDrawingController.cpp
  6. 4
      src/board/UBDrawingController.h
  7. 12
      src/core/UB.h
  8. 6
      src/core/UBDisplayManager.cpp
  9. 3
      src/desktop/UBDesktopAnnotationController.cpp
  10. 1
      src/domain/UBGraphicsDelegateFrame.cpp
  11. 60
      src/domain/UBGraphicsScene.cpp
  12. 8
      src/domain/UBGraphicsScene.h
  13. 7
      src/gui/UBDockPalette.cpp
  14. 3
      src/gui/UBFloatingPalette.cpp
  15. 1
      src/gui/UBResources.cpp
  16. 1
      src/gui/UBResources.h
  17. 9
      src/tools/UBAbstractDrawRuler.cpp
  18. 21
      src/tools/UBAbstractDrawRuler.h
  19. 8
      src/tools/UBGraphicsCompass.cpp
  20. 1
      src/tools/UBGraphicsProtractor.cpp
  21. 165
      src/tools/UBGraphicsRuler.cpp
  22. 12
      src/tools/UBGraphicsRuler.h
  23. 6
      src/tools/tools.pri

Binary file not shown.

After

Width:  |  Height:  |  Size: 444 B

@ -173,6 +173,7 @@
<file>images/cursors/rotate.png</file> <file>images/cursors/rotate.png</file>
<file>images/cursors/resize.png</file> <file>images/cursors/resize.png</file>
<file>images/cursors/drawCompass.png</file> <file>images/cursors/drawCompass.png</file>
<file>images/cursors/drawRulerLine.png</file>
<file>images/print/onepage.png</file> <file>images/print/onepage.png</file>
<file>images/print/thumbnails.png</file> <file>images/print/thumbnails.png</file>
<file>images/print/twopages.png</file> <file>images/print/twopages.png</file>

@ -179,7 +179,8 @@ void UBWidgetUniboardAPI::drawLineTo(const qreal x, const qreal y, const qreal p
return; return;
if (mScene) if (mScene)
mScene->drawLineTo(QPointF(x, y), pWidth); mScene->drawLineTo(QPointF(x, y), pWidth,
UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line);
} }

@ -450,15 +450,18 @@ UBBoardView::mousePressEvent (QMouseEvent *event)
event->accept (); event->accept ();
} }
else else
{ {
viewport ()->setCursor (QCursor (Qt::BlankCursor)); if(UBDrawingController::drawingController()->mActiveRuler==NULL)
{
if (scene () && !mTabletStylusIsPressed) viewport()->setCursor (QCursor (Qt::BlankCursor));
{ }
scene ()->inputDevicePress (mapToScene (UBGeometryUtils::pointConstrainedInRect (event->pos (), rect ())));
} if (scene () && !mTabletStylusIsPressed)
event->accept (); {
scene ()->inputDevicePress (mapToScene (UBGeometryUtils::pointConstrainedInRect (event->pos (), rect ())));
}
event->accept ();
} }
} }
} }
@ -487,6 +490,11 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
{ {
QGraphicsView::mouseMoveEvent (event); QGraphicsView::mouseMoveEvent (event);
} }
else if ((UBDrawingController::drawingController()->isDrawingTool())
&& !mMouseButtonIsPressed)
{
QGraphicsView::mouseMoveEvent (event);
}
else if (currentTool == UBStylusTool::Text || currentTool == UBStylusTool::Capture) else if (currentTool == UBStylusTool::Text || currentTool == UBStylusTool::Capture)
{ {
if (mRubberBand && (mIsCreatingTextZone || mIsCreatingSceneGrabZone)) if (mRubberBand && (mIsCreatingTextZone || mIsCreatingSceneGrabZone))

@ -27,6 +27,7 @@ UBDrawingController::UBDrawingController(QObject * parent)
: QObject(parent) : QObject(parent)
, mStylusTool((UBStylusTool::Enum)-1) , mStylusTool((UBStylusTool::Enum)-1)
, mLatestDrawingTool((UBStylusTool::Enum)-1) , mLatestDrawingTool((UBStylusTool::Enum)-1)
, mActiveRuler(NULL)
{ {
connect(UBSettings::settings(), SIGNAL(colorContextChanged()), this, SIGNAL(colorPaletteChanged())); connect(UBSettings::settings(), SIGNAL(colorContextChanged()), this, SIGNAL(colorPaletteChanged()));

@ -12,6 +12,8 @@
#include "core/UB.h" #include "core/UB.h"
class UBAbstractDrawRuler;
class UBDrawingController : public QObject class UBDrawingController : public QObject
{ {
Q_OBJECT; Q_OBJECT;
@ -39,6 +41,8 @@ class UBDrawingController : public QObject
void setMarkerColor(bool onDarkBackground, const QColor& color, int pIndex); void setMarkerColor(bool onDarkBackground, const QColor& color, int pIndex);
void setMarkerAlpha(qreal alpha); void setMarkerAlpha(qreal alpha);
UBAbstractDrawRuler* mActiveRuler;
public slots: public slots:
void setStylusTool(int tool); void setStylusTool(int tool);

@ -16,7 +16,17 @@ struct UBStylusTool
{ {
enum Enum enum Enum
{ {
Pen = 0, Eraser, Marker, Selector, Hand, ZoomIn, ZoomOut, Pointer, Line, Text, Capture Pen = 0,
Eraser,
Marker,
Selector,
Hand,
ZoomIn,
ZoomOut,
Pointer,
Line,
Text,
Capture
}; };
}; };

@ -114,7 +114,10 @@ void UBDisplayManager::setAsControl(QWidget* pControlWidget )
mControlWidget->hide(); mControlWidget->hide();
mControlWidget->setGeometry(mDesktop->screenGeometry(mControlScreenIndex)); mControlWidget->setGeometry(mDesktop->screenGeometry(mControlScreenIndex));
mControlWidget->showFullScreen(); mControlWidget->showFullScreen();
// !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN
mControlWidget->setAttribute(Qt::WA_MacNoShadow); mControlWidget->setAttribute(Qt::WA_MacNoShadow);
#endif
} }
} }
@ -127,7 +130,10 @@ void UBDisplayManager::setAsDisplay(QWidget* pDisplayWidget)
mDisplayWidget->hide(); mDisplayWidget->hide();
mDisplayWidget->setGeometry(mDesktop->screenGeometry(mDisplayScreenIndex)); mDisplayWidget->setGeometry(mDesktop->screenGeometry(mDisplayScreenIndex));
mDisplayWidget->showFullScreen(); mDisplayWidget->showFullScreen();
// !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN
mDisplayWidget->setAttribute(Qt::WA_MacNoShadow); mDisplayWidget->setAttribute(Qt::WA_MacNoShadow);
#endif
} }
} }

@ -60,7 +60,10 @@ UBDesktopAnnotationController::UBDesktopAnnotationController(QObject *parent)
mTransparentDrawingView = new UBBoardView(UBApplication::boardController, 0); // deleted in UBDesktopAnnotationController::destructor mTransparentDrawingView = new UBBoardView(UBApplication::boardController, 0); // deleted in UBDesktopAnnotationController::destructor
mTransparentDrawingView->setAttribute(Qt::WA_TranslucentBackground, true); mTransparentDrawingView->setAttribute(Qt::WA_TranslucentBackground, true);
// !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN
mTransparentDrawingView->setAttribute(Qt::WA_MacNoShadow, true); mTransparentDrawingView->setAttribute(Qt::WA_MacNoShadow, true);
#endif
mTransparentDrawingView->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Window); mTransparentDrawingView->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Window);
mTransparentDrawingView->setCacheMode(QGraphicsView::CacheNone); mTransparentDrawingView->setCacheMode(QGraphicsView::CacheNone);
mTransparentDrawingView->resize(UBApplication::desktop()->width(), UBApplication::desktop()->height()); mTransparentDrawingView->resize(UBApplication::desktop()->width(), UBApplication::desktop()->height());

@ -19,7 +19,6 @@
#include "gui/UBResources.h" #include "gui/UBResources.h"
const double PI = 4.0 * atan(1.0);
qreal const UBGraphicsDelegateFrame::mAngleTolerance = 6; qreal const UBGraphicsDelegateFrame::mAngleTolerance = 6;
UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelegate, QRectF pRect, qreal pFrameWidth, bool respectRatio) UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelegate, QRectF pRect, qreal pFrameWidth, bool respectRatio)

@ -59,8 +59,6 @@ qreal UBGraphicsScene::toolOffsetEraser = 200;
qreal UBGraphicsScene::toolOffsetCurtain = 1000; qreal UBGraphicsScene::toolOffsetCurtain = 1000;
qreal UBGraphicsScene::toolOffsetPointer = 1100; qreal UBGraphicsScene::toolOffsetPointer = 1100;
const double PI = 4.0 * atan(1.0);
UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
: UBCoreGraphicsScene(parent) : UBCoreGraphicsScene(parent)
, mEraser(0) , mEraser(0)
@ -163,8 +161,18 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre
mAddedItems.clear(); mAddedItems.clear();
mRemovedItems.clear(); mRemovedItems.clear();
moveTo(scenePos);
drawLineTo(scenePos, width); if (UBDrawingController::drawingController()->mActiveRuler)
{
UBDrawingController::drawingController()->mActiveRuler->StartLine(
scenePos, width);
}
else
{
moveTo(scenePos);
drawLineTo(scenePos, width,
UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line);
}
accepted = true; accepted = true;
} }
else if (currentTool == UBStylusTool::Eraser) else if (currentTool == UBStylusTool::Eraser)
@ -220,21 +228,29 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
width /= UBApplication::boardController->systemScaleFactor(); width /= UBApplication::boardController->systemScaleFactor();
width /= UBApplication::boardController->currentZoom(); width /= UBApplication::boardController->currentZoom();
if (currentTool == UBStylusTool::Line) if (dc->mActiveRuler)
{ {
QLineF radius(mPreviousPoint, position); dc->mActiveRuler->DrawLine(position, width);
qreal angle = radius.angle(); }
angle = qRound(angle / 45) * 45; else
qreal radiusLength = radius.length(); {
QPointF newPosition( if (currentTool == UBStylusTool::Line)
mPreviousPoint.x() + radiusLength * cos((angle * PI) / 180), {
mPreviousPoint.y() - radiusLength * sin((angle * PI) / 180)); QLineF radius(mPreviousPoint, position);
QLineF chord(position, newPosition); qreal angle = radius.angle();
if (chord.length() < qMin((int)16, (int)(radiusLength / 20))) angle = qRound(angle / 45) * 45;
position = newPosition; qreal radiusLength = radius.length();
} QPointF newPosition(
mPreviousPoint.x() + radiusLength * cos((angle * PI) / 180),
drawLineTo(position, width); mPreviousPoint.y() - radiusLength * sin((angle * PI) / 180));
QLineF chord(position, newPosition);
if (chord.length() < qMin((int)16, (int)(radiusLength / 20)))
position = newPosition;
}
drawLineTo(position, width,
UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line);
}
} }
else if (currentTool == UBStylusTool::Eraser) else if (currentTool == UBStylusTool::Eraser)
{ {
@ -348,7 +364,7 @@ void UBGraphicsScene::moveTo(const QPointF &pPoint)
} }
void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth) void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth, bool bLineStyle)
{ {
if (mPreviousWidth == -1.0) if (mPreviousWidth == -1.0)
mPreviousWidth = pWidth; mPreviousWidth = pWidth;
@ -364,7 +380,7 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth)
} }
} }
if (UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line) if (bLineStyle)
{ {
QSetIterator<QGraphicsItem*> itItems(mAddedItems); QSetIterator<QGraphicsItem*> itItems(mAddedItems);
@ -388,7 +404,7 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth)
mPreviousPolygonItems.append(polygonItem); mPreviousPolygonItems.append(polygonItem);
if (UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Line) if (!bLineStyle)
{ {
mPreviousPoint = pEndPoint; mPreviousPoint = pEndPoint;
mPreviousWidth = pWidth; mPreviousWidth = pWidth;

@ -37,6 +37,7 @@ class UBDocumentProxy;
class UBGraphicsCurtainItem; class UBGraphicsCurtainItem;
class UBGraphicsStroke; class UBGraphicsStroke;
const double PI = 4.0 * atan(1.0);
class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
{ {
@ -99,7 +100,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
QRectF normalizedSceneRect(qreal ratio = -1.0); QRectF normalizedSceneRect(qreal ratio = -1.0);
void moveTo(const QPointF& pPoint); void moveTo(const QPointF& pPoint);
void drawLineTo(const QPointF& pEndPoint, const qreal& pWidth); void drawLineTo(const QPointF& pEndPoint, const qreal& pWidth, bool bLineStyle);
void eraseLineTo(const QPointF& pEndPoint, const qreal& pWidth); void eraseLineTo(const QPointF& pEndPoint, const qreal& pWidth);
void drawArcTo(const QPointF& pCenterPoint, qreal pSpanAngle); void drawArcTo(const QPointF& pCenterPoint, qreal pSpanAngle);
@ -240,6 +241,11 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
mTools << item; mTools << item;
} }
const QPointF& previousPoint()
{
return mPreviousPoint;
}
public slots: public slots:
void hideEraser(); void hideEraser();

@ -33,7 +33,12 @@ UBDockPalette::UBDockPalette(QWidget *parent, const char *name)
{ {
// standalone window // standalone window
setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_MacNoShadow);
// !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN
setAttribute(Qt::WA_MacNoShadow);
#endif
} }
mBackgroundBrush = QBrush(UBSettings::paletteColor); mBackgroundBrush = QBrush(UBSettings::paletteColor);

@ -26,10 +26,13 @@ UBFloatingPalette::UBFloatingPalette(Qt::Corner position, QWidget *parent)
else else
{ {
// standalone window // standalone window
// !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN
setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_MacAlwaysShowToolWindow); setAttribute(Qt::WA_MacAlwaysShowToolWindow);
setAttribute(Qt::WA_MacNonActivatingToolWindow); setAttribute(Qt::WA_MacNonActivatingToolWindow);
setAttribute(Qt::WA_MacNoShadow); setAttribute(Qt::WA_MacNoShadow);
#endif
} }
mBackgroundBrush = QBrush(UBSettings::paletteColor); mBackgroundBrush = QBrush(UBSettings::paletteColor);

@ -43,4 +43,5 @@ void UBResources::init()
arrowCursor = QCursor(Qt::ArrowCursor); arrowCursor = QCursor(Qt::ArrowCursor);
textCursor = QCursor(Qt::ArrowCursor); textCursor = QCursor(Qt::ArrowCursor);
rotateCursor = QCursor(QPixmap(":/images/cursors/rotate.png"), 16, 16); rotateCursor = QCursor(QPixmap(":/images/cursors/rotate.png"), 16, 16);
drawLineRulerCursor = QCursor(QPixmap(":/images/cursors/drawRulerLine.png"), 3, 12);
} }

@ -31,6 +31,7 @@ class UBResources : public QObject
QCursor arrowCursor; QCursor arrowCursor;
QCursor textCursor; QCursor textCursor;
QCursor rotateCursor; QCursor rotateCursor;
QCursor drawLineRulerCursor;
}; };
#endif /* UBRESOURCES_H_ */ #endif /* UBRESOURCES_H_ */

@ -0,0 +1,9 @@
#include "UBAbstractDrawRuler.h"
UBAbstractDrawRuler::UBAbstractDrawRuler()
{}
UBAbstractDrawRuler::~UBAbstractDrawRuler()
{}

@ -0,0 +1,21 @@
#ifndef UB_ABSTRACTDRAWRULER_H_
#define UB_ABSTRACTDRAWRULER_H_
#include <QtGui>
class UBGraphicsScene;
class UBAbstractDrawRuler : public QObject
{
Q_OBJECT;
public:
UBAbstractDrawRuler();
~UBAbstractDrawRuler();
virtual void StartLine(const QPointF& position, qreal width) = 0;
virtual void DrawLine(const QPointF& position, qreal width) = 0;
virtual void EndLine() = 0;
};
#endif

@ -16,8 +16,6 @@
#include "board/UBBoardController.h" // TODO UB 4.x clean that dependency #include "board/UBBoardController.h" // TODO UB 4.x clean that dependency
#include "board/UBDrawingController.h" // TODO UB 4.x clean that dependency #include "board/UBDrawingController.h" // TODO UB 4.x clean that dependency
const double PI = 4.0 * atan(1.0);
const QRect UBGraphicsCompass::sDefaultRect = QRect(0, -20, 300, 48); const QRect UBGraphicsCompass::sDefaultRect = QRect(0, -20, 300, 48);
const QColor UBGraphicsCompass::sLightBackgroundMiddleFillColor = QColor(0x72, 0x72, 0x72, sFillTransparency); const QColor UBGraphicsCompass::sLightBackgroundMiddleFillColor = QColor(0x72, 0x72, 0x72, sFillTransparency);
const QColor UBGraphicsCompass::sLightBackgroundEdgeFillColor = QColor(0xc3, 0xc3, 0xc3, sFillTransparency); const QColor UBGraphicsCompass::sLightBackgroundEdgeFillColor = QColor(0xc3, 0xc3, 0xc3, sFillTransparency);
@ -511,9 +509,11 @@ void UBGraphicsCompass::paintCenterCross()
{ {
QPointF needleCrossCenter = mapToScene(needlePosition()); QPointF needleCrossCenter = mapToScene(needlePosition());
scene()->moveTo(QPointF(needleCrossCenter.x() - 5, needleCrossCenter.y())); scene()->moveTo(QPointF(needleCrossCenter.x() - 5, needleCrossCenter.y()));
scene()->drawLineTo(QPointF(needleCrossCenter.x() + 5, needleCrossCenter.y()), 1); scene()->drawLineTo(QPointF(needleCrossCenter.x() + 5, needleCrossCenter.y()), 1,
UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line);
scene()->moveTo(QPointF(needleCrossCenter.x(), needleCrossCenter.y() - 5)); scene()->moveTo(QPointF(needleCrossCenter.x(), needleCrossCenter.y() - 5));
scene()->drawLineTo(QPointF(needleCrossCenter.x(), needleCrossCenter.y() + 5), 1); scene()->drawLineTo(QPointF(needleCrossCenter.x(), needleCrossCenter.y() + 5), 1,
UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line);
} }
QPointF UBGraphicsCompass::needlePosition() const QPointF UBGraphicsCompass::needlePosition() const

@ -13,7 +13,6 @@
#include "board/UBBoardController.h" #include "board/UBBoardController.h"
const double PI = 4.0 * atan(1.0);
const int UBGraphicsProtractor::sFillTransparency = 127; const int UBGraphicsProtractor::sFillTransparency = 127;
const int UBGraphicsProtractor::sDrawTransparency = 192; const int UBGraphicsProtractor::sDrawTransparency = 192;
const QRectF UBGraphicsProtractor::sDefaultRect = QRectF(-175, -175, 350, 350); const QRectF UBGraphicsProtractor::sDefaultRect = QRectF(-175, -175, 350, 350);

@ -13,6 +13,7 @@
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "gui/UBResources.h" #include "gui/UBResources.h"
#include "board/UBBoardController.h" // TODO UB 4.x clean that dependency #include "board/UBBoardController.h" // TODO UB 4.x clean that dependency
#include "board/UBDrawingController.h"
const QRect UBGraphicsRuler::sDefaultRect = QRect(0, 0, 800, 96); const QRect UBGraphicsRuler::sDefaultRect = QRect(0, 0, 800, 96);
const QColor UBGraphicsRuler::sLightBackgroundMiddleFillColor = QColor(0x72, 0x72, 0x72, sFillTransparency); const QColor UBGraphicsRuler::sLightBackgroundMiddleFillColor = QColor(0x72, 0x72, 0x72, sFillTransparency);
@ -200,29 +201,40 @@ void UBGraphicsRuler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void UBGraphicsRuler::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void UBGraphicsRuler::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
mCloseSvgItem->setParentItem(this); UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
mResizeSvgItem->setParentItem(this);
mRotateSvgItem->setParentItem(this); if (currentTool == UBStylusTool::Selector)
{
mShowButtons = true; mCloseSvgItem->setParentItem(this);
mCloseSvgItem->setVisible(mShowButtons); mResizeSvgItem->setParentItem(this);
mResizeSvgItem->setVisible(mShowButtons); mRotateSvgItem->setParentItem(this);
mRotateSvgItem->setVisible(mShowButtons);
if (event->pos().x() >= resizeButtonRect().left()) mShowButtons = true;
{ mCloseSvgItem->setVisible(mShowButtons);
setCursor(resizeCursor()); mResizeSvgItem->setVisible(mShowButtons);
} mRotateSvgItem->setVisible(mShowButtons);
else if (event->pos().x() >= resizeButtonRect().left())
{ {
if (closeButtonRect().contains(event->pos())) setCursor(resizeCursor());
setCursor(closeCursor()); }
else if (rotateButtonRect().contains(event->pos())) else
setCursor(rotateCursor()); {
else if (closeButtonRect().contains(event->pos()))
setCursor(moveCursor()); setCursor(closeCursor());
} else if (rotateButtonRect().contains(event->pos()))
event->accept(); setCursor(rotateCursor());
update(); else
setCursor(moveCursor());
}
event->accept();
update();
}
else if (UBDrawingController::drawingController()->isDrawingTool())
{
setCursor(drawRulerLineCursor());
UBDrawingController::drawingController()->mActiveRuler = this;
event->accept();
}
} }
void UBGraphicsRuler::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void UBGraphicsRuler::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
@ -232,29 +244,39 @@ void UBGraphicsRuler::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
mCloseSvgItem->setVisible(mShowButtons); mCloseSvgItem->setVisible(mShowButtons);
mResizeSvgItem->setVisible(mShowButtons); mResizeSvgItem->setVisible(mShowButtons);
mRotateSvgItem->setVisible(mShowButtons); mRotateSvgItem->setVisible(mShowButtons);
UBDrawingController::drawingController()->mActiveRuler = NULL;
event->accept(); event->accept();
update(); update();
} }
void UBGraphicsRuler::hoverMoveEvent(QGraphicsSceneHoverEvent *event) void UBGraphicsRuler::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{ {
mCloseSvgItem->setVisible(mShowButtons); UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
mResizeSvgItem->setVisible(mShowButtons);
mRotateSvgItem->setVisible(mShowButtons); if (currentTool == UBStylusTool::Selector)
if (event->pos().x() >= resizeButtonRect().left()) {
{ mCloseSvgItem->setVisible(mShowButtons);
setCursor(resizeCursor()); mResizeSvgItem->setVisible(mShowButtons);
} mRotateSvgItem->setVisible(mShowButtons);
else if (event->pos().x() >= resizeButtonRect().left())
{ {
if (closeButtonRect().contains(event->pos())) setCursor(resizeCursor());
setCursor(closeCursor()); }
else if (rotateButtonRect().contains(event->pos())) else
setCursor(rotateCursor()); {
else if (closeButtonRect().contains(event->pos()))
setCursor(moveCursor()); setCursor(closeCursor());
} else if (rotateButtonRect().contains(event->pos()))
event->accept(); setCursor(rotateCursor());
else
setCursor(moveCursor());
}
event->accept();
}
else if (currentTool == UBStylusTool::Pen || currentTool == UBStylusTool::Marker)
{
event->accept();
}
} }
void UBGraphicsRuler::fillBackground(QPainter *painter) void UBGraphicsRuler::fillBackground(QPainter *painter)
@ -456,3 +478,66 @@ void UBGraphicsRuler::updateResizeCursor()
QCursor resizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2); QCursor resizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2);
mResizeCursor = resizeCursor; mResizeCursor = resizeCursor;
} }
QCursor UBGraphicsRuler::drawRulerLineCursor() const
{
return UBResources::resources()->drawLineRulerCursor;
}
void UBGraphicsRuler::StartLine(const QPointF& scenePos, qreal width)
{
QPointF itemPos = mapFromScene(scenePos);
qreal y;
if (itemPos.y() > rect().y() + rect().height() / 2)
{
drawLineDirection = 0;
y = rect().y() + rect().height() + width / 2;
}
else
{
drawLineDirection = 1;
y = rect().y() - width /2;
}
if (itemPos.x() < rect().x() + sLeftEdgeMargin)
itemPos.setX(rect().x() + sLeftEdgeMargin);
if (itemPos.x() > rect().x() + rect().width() - sLeftEdgeMargin)
itemPos.setX(rect().x() + rect().width() - sLeftEdgeMargin);
itemPos.setY(y);
itemPos = mapToScene(itemPos);
scene()->moveTo(itemPos);
scene()->drawLineTo(itemPos, width, true);
}
void UBGraphicsRuler::DrawLine(const QPointF& scenePos, qreal width)
{
QPointF itemPos = mapFromScene(scenePos);
qreal y;
if (drawLineDirection == 0)
{
y = rect().y() + rect().height() + width / 2;
}
else
{
y = rect().y() - width /2;
}
if (itemPos.x() < rect().x() + sLeftEdgeMargin)
itemPos.setX(rect().x() + sLeftEdgeMargin);
if (itemPos.x() > rect().x() + rect().width() - sLeftEdgeMargin)
itemPos.setX(rect().x() + rect().width() - sLeftEdgeMargin);
itemPos.setY(y);
itemPos = mapToScene(itemPos);
// We have to use "pointed" line for marker tool
scene()->drawLineTo(itemPos, width,
UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Marker);
}
void UBGraphicsRuler::EndLine()
{}

@ -14,10 +14,11 @@
#include "core/UB.h" #include "core/UB.h"
#include "domain/UBItem.h" #include "domain/UBItem.h"
#include "tools/UBAbstractDrawRuler.h"
class UBGraphicsScene; class UBGraphicsScene;
class UBGraphicsRuler : public QObject, public QGraphicsRectItem, public UBItem class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, public UBItem
{ {
Q_OBJECT; Q_OBJECT;
@ -34,6 +35,10 @@ class UBGraphicsRuler : public QObject, public QGraphicsRectItem, public UBItem
virtual UBItem* deepCopy() const; virtual UBItem* deepCopy() const;
virtual void StartLine(const QPointF& position, qreal width);
virtual void DrawLine(const QPointF& position, qreal width);
virtual void EndLine();
signals: signals:
void hidden(); void hidden();
@ -63,6 +68,7 @@ class UBGraphicsRuler : public QObject, public QGraphicsRectItem, public UBItem
QCursor resizeCursor() const; QCursor resizeCursor() const;
QCursor rotateCursor() const; QCursor rotateCursor() const;
QCursor closeCursor() const; QCursor closeCursor() const;
QCursor drawRulerLineCursor() const;
QRectF resizeButtonRect() const; QRectF resizeButtonRect() const;
QRectF closeButtonRect() const; QRectF closeButtonRect() const;
QRectF rotateButtonRect() const; QRectF rotateButtonRect() const;
@ -72,6 +78,8 @@ class UBGraphicsRuler : public QObject, public QGraphicsRectItem, public UBItem
QColor edgeFillColor() const; QColor edgeFillColor() const;
QFont font() const; QFont font() const;
int drawLineDirection;
// Members // Members
bool mResizing; bool mResizing;
bool mRotating; bool mRotating;
@ -82,6 +90,8 @@ class UBGraphicsRuler : public QObject, public QGraphicsRectItem, public UBItem
QCursor mResizeCursor; QCursor mResizeCursor;
qreal mAntiScaleRatio; qreal mAntiScaleRatio;
QPointF startDrawPosition;
// Constants // Constants
static const QRect sDefaultRect; static const QRect sDefaultRect;
static const int sLeftEdgeMargin = 10; static const int sLeftEdgeMargin = 10;

@ -4,11 +4,13 @@ HEADERS += src/tools/UBGraphicsRuler.h \
src/tools/UBGraphicsCompass.h \ src/tools/UBGraphicsCompass.h \
src/tools/UBToolsManager.h \ src/tools/UBToolsManager.h \
src/tools/UBGraphicsCurtainItem.h \ src/tools/UBGraphicsCurtainItem.h \
src/tools/UBGraphicsCurtainItemDelegate.h src/tools/UBGraphicsCurtainItemDelegate.h \
src/tools/UBAbstractDrawRuler.h
SOURCES += src/tools/UBGraphicsRuler.cpp \ SOURCES += src/tools/UBGraphicsRuler.cpp \
src/tools/UBGraphicsProtractor.cpp \ src/tools/UBGraphicsProtractor.cpp \
src/tools/UBGraphicsCompass.cpp \ src/tools/UBGraphicsCompass.cpp \
src/tools/UBToolsManager.cpp \ src/tools/UBToolsManager.cpp \
src/tools/UBGraphicsCurtainItem.cpp \ src/tools/UBGraphicsCurtainItem.cpp \
src/tools/UBGraphicsCurtainItemDelegate.cpp \ src/tools/UBGraphicsCurtainItemDelegate.cpp \
src/tools/UBAbstractDrawRuler.cpp
Loading…
Cancel
Save