Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpenBoard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
Nicolas Ollinger
OpenBoard
Commits
3d8deb8c
Commit
3d8deb8c
authored
Jun 21, 2011
by
Anatoly Mihalchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Graphics ruler: drawing lines
parent
4f09fe08
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
275 additions
and
84 deletions
+275
-84
drawRulerLine.png
resources/images/cursors/drawRulerLine.png
+0
-0
sankore.qrc
resources/sankore.qrc
+1
-0
UBWidgetUniboardAPI.cpp
src/api/UBWidgetUniboardAPI.cpp
+2
-1
UBBoardView.cpp
src/board/UBBoardView.cpp
+17
-9
UBDrawingController.cpp
src/board/UBDrawingController.cpp
+1
-0
UBDrawingController.h
src/board/UBDrawingController.h
+4
-0
UB.h
src/core/UB.h
+11
-1
UBDisplayManager.cpp
src/core/UBDisplayManager.cpp
+6
-0
UBDesktopAnnotationController.cpp
src/desktop/UBDesktopAnnotationController.cpp
+3
-0
UBGraphicsDelegateFrame.cpp
src/domain/UBGraphicsDelegateFrame.cpp
+0
-1
UBGraphicsScene.cpp
src/domain/UBGraphicsScene.cpp
+38
-22
UBGraphicsScene.h
src/domain/UBGraphicsScene.h
+7
-1
UBDockPalette.cpp
src/gui/UBDockPalette.cpp
+6
-1
UBFloatingPalette.cpp
src/gui/UBFloatingPalette.cpp
+3
-0
UBResources.cpp
src/gui/UBResources.cpp
+1
-0
UBResources.h
src/gui/UBResources.h
+1
-0
UBAbstractDrawRuler.cpp
src/tools/UBAbstractDrawRuler.cpp
+9
-0
UBAbstractDrawRuler.h
src/tools/UBAbstractDrawRuler.h
+21
-0
UBGraphicsCompass.cpp
src/tools/UBGraphicsCompass.cpp
+4
-4
UBGraphicsProtractor.cpp
src/tools/UBGraphicsProtractor.cpp
+0
-1
UBGraphicsRuler.cpp
src/tools/UBGraphicsRuler.cpp
+125
-40
UBGraphicsRuler.h
src/tools/UBGraphicsRuler.h
+11
-1
tools.pri
src/tools/tools.pri
+4
-2
No files found.
resources/images/cursors/drawRulerLine.png
0 → 100644
View file @
3d8deb8c
444 Bytes
resources/sankore.qrc
View file @
3d8deb8c
...
...
@@ -173,6 +173,7 @@
<file>images/cursors/rotate.png</file>
<file>images/cursors/resize.png</file>
<file>images/cursors/drawCompass.png</file>
<file>images/cursors/drawRulerLine.png</file>
<file>images/print/onepage.png</file>
<file>images/print/thumbnails.png</file>
<file>images/print/twopages.png</file>
...
...
src/api/UBWidgetUniboardAPI.cpp
View file @
3d8deb8c
...
...
@@ -179,7 +179,8 @@ void UBWidgetUniboardAPI::drawLineTo(const qreal x, const qreal y, const qreal p
return
;
if
(
mScene
)
mScene
->
drawLineTo
(
QPointF
(
x
,
y
),
pWidth
);
mScene
->
drawLineTo
(
QPointF
(
x
,
y
),
pWidth
,
UBDrawingController
::
drawingController
()
->
stylusTool
()
==
UBStylusTool
::
Line
);
}
...
...
src/board/UBBoardView.cpp
View file @
3d8deb8c
...
...
@@ -450,15 +450,18 @@ UBBoardView::mousePressEvent (QMouseEvent *event)
event
->
accept
();
}
else
{
viewport
()
->
setCursor
(
QCursor
(
Qt
::
BlankCursor
));
if
(
scene
()
&&
!
mTabletStylusIsPressed
)
{
scene
()
->
inputDevicePress
(
mapToScene
(
UBGeometryUtils
::
pointConstrainedInRect
(
event
->
pos
(),
rect
())));
}
event
->
accept
();
else
{
if
(
UBDrawingController
::
drawingController
()
->
mActiveRuler
==
NULL
)
{
viewport
()
->
setCursor
(
QCursor
(
Qt
::
BlankCursor
));
}
if
(
scene
()
&&
!
mTabletStylusIsPressed
)
{
scene
()
->
inputDevicePress
(
mapToScene
(
UBGeometryUtils
::
pointConstrainedInRect
(
event
->
pos
(),
rect
())));
}
event
->
accept
();
}
}
}
...
...
@@ -487,6 +490,11 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
{
QGraphicsView
::
mouseMoveEvent
(
event
);
}
else
if
((
UBDrawingController
::
drawingController
()
->
isDrawingTool
())
&&
!
mMouseButtonIsPressed
)
{
QGraphicsView
::
mouseMoveEvent
(
event
);
}
else
if
(
currentTool
==
UBStylusTool
::
Text
||
currentTool
==
UBStylusTool
::
Capture
)
{
if
(
mRubberBand
&&
(
mIsCreatingTextZone
||
mIsCreatingSceneGrabZone
))
...
...
src/board/UBDrawingController.cpp
View file @
3d8deb8c
...
...
@@ -27,6 +27,7 @@ UBDrawingController::UBDrawingController(QObject * parent)
:
QObject
(
parent
)
,
mStylusTool
((
UBStylusTool
::
Enum
)
-
1
)
,
mLatestDrawingTool
((
UBStylusTool
::
Enum
)
-
1
)
,
mActiveRuler
(
NULL
)
{
connect
(
UBSettings
::
settings
(),
SIGNAL
(
colorContextChanged
()),
this
,
SIGNAL
(
colorPaletteChanged
()));
...
...
src/board/UBDrawingController.h
View file @
3d8deb8c
...
...
@@ -12,6 +12,8 @@
#include "core/UB.h"
class
UBAbstractDrawRuler
;
class
UBDrawingController
:
public
QObject
{
Q_OBJECT
;
...
...
@@ -39,6 +41,8 @@ class UBDrawingController : public QObject
void
setMarkerColor
(
bool
onDarkBackground
,
const
QColor
&
color
,
int
pIndex
);
void
setMarkerAlpha
(
qreal
alpha
);
UBAbstractDrawRuler
*
mActiveRuler
;
public
slots
:
void
setStylusTool
(
int
tool
);
...
...
src/core/UB.h
View file @
3d8deb8c
...
...
@@ -16,7 +16,17 @@ struct UBStylusTool
{
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
};
};
...
...
src/core/UBDisplayManager.cpp
View file @
3d8deb8c
...
...
@@ -114,7 +114,10 @@ void UBDisplayManager::setAsControl(QWidget* pControlWidget )
mControlWidget
->
hide
();
mControlWidget
->
setGeometry
(
mDesktop
->
screenGeometry
(
mControlScreenIndex
));
mControlWidget
->
showFullScreen
();
// !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN
mControlWidget
->
setAttribute
(
Qt
::
WA_MacNoShadow
);
#endif
}
}
...
...
@@ -127,7 +130,10 @@ void UBDisplayManager::setAsDisplay(QWidget* pDisplayWidget)
mDisplayWidget
->
hide
();
mDisplayWidget
->
setGeometry
(
mDesktop
->
screenGeometry
(
mDisplayScreenIndex
));
mDisplayWidget
->
showFullScreen
();
// !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN
mDisplayWidget
->
setAttribute
(
Qt
::
WA_MacNoShadow
);
#endif
}
}
...
...
src/desktop/UBDesktopAnnotationController.cpp
View file @
3d8deb8c
...
...
@@ -60,7 +60,10 @@ UBDesktopAnnotationController::UBDesktopAnnotationController(QObject *parent)
mTransparentDrawingView
=
new
UBBoardView
(
UBApplication
::
boardController
,
0
);
// deleted in UBDesktopAnnotationController::destructor
mTransparentDrawingView
->
setAttribute
(
Qt
::
WA_TranslucentBackground
,
true
);
// !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN
mTransparentDrawingView
->
setAttribute
(
Qt
::
WA_MacNoShadow
,
true
);
#endif
mTransparentDrawingView
->
setWindowFlags
(
Qt
::
FramelessWindowHint
|
Qt
::
WindowStaysOnTopHint
|
Qt
::
Window
);
mTransparentDrawingView
->
setCacheMode
(
QGraphicsView
::
CacheNone
);
mTransparentDrawingView
->
resize
(
UBApplication
::
desktop
()
->
width
(),
UBApplication
::
desktop
()
->
height
());
...
...
src/domain/UBGraphicsDelegateFrame.cpp
View file @
3d8deb8c
...
...
@@ -19,7 +19,6 @@
#include "gui/UBResources.h"
const
double
PI
=
4.0
*
atan
(
1.0
);
qreal
const
UBGraphicsDelegateFrame
::
mAngleTolerance
=
6
;
UBGraphicsDelegateFrame
::
UBGraphicsDelegateFrame
(
UBGraphicsItemDelegate
*
pDelegate
,
QRectF
pRect
,
qreal
pFrameWidth
,
bool
respectRatio
)
...
...
src/domain/UBGraphicsScene.cpp
View file @
3d8deb8c
...
...
@@ -59,8 +59,6 @@ qreal UBGraphicsScene::toolOffsetEraser = 200;
qreal
UBGraphicsScene
::
toolOffsetCurtain
=
1000
;
qreal
UBGraphicsScene
::
toolOffsetPointer
=
1100
;
const
double
PI
=
4.0
*
atan
(
1.0
);
UBGraphicsScene
::
UBGraphicsScene
(
UBDocumentProxy
*
parent
)
:
UBCoreGraphicsScene
(
parent
)
,
mEraser
(
0
)
...
...
@@ -163,8 +161,18 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre
mAddedItems
.
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
;
}
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
->
currentZoom
();
if
(
currentTool
==
UBStylusTool
::
Line
)
{
QLineF
radius
(
mPreviousPoint
,
position
);
qreal
angle
=
radius
.
angle
();
angle
=
qRound
(
angle
/
45
)
*
45
;
qreal
radiusLength
=
radius
.
length
();
QPointF
newPosition
(
mPreviousPoint
.
x
()
+
radiusLength
*
cos
((
angle
*
PI
)
/
180
),
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
);
if
(
dc
->
mActiveRuler
)
{
dc
->
mActiveRuler
->
DrawLine
(
position
,
width
);
}
else
{
if
(
currentTool
==
UBStylusTool
::
Line
)
{
QLineF
radius
(
mPreviousPoint
,
position
);
qreal
angle
=
radius
.
angle
();
angle
=
qRound
(
angle
/
45
)
*
45
;
qreal
radiusLength
=
radius
.
length
();
QPointF
newPosition
(
mPreviousPoint
.
x
()
+
radiusLength
*
cos
((
angle
*
PI
)
/
180
),
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
)
{
...
...
@@ -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
)
mPreviousWidth
=
pWidth
;
...
...
@@ -364,7 +380,7 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth)
}
}
if
(
UBDrawingController
::
drawingController
()
->
stylusTool
()
==
UBStylusTool
::
Lin
e
)
if
(
bLineStyl
e
)
{
QSetIterator
<
QGraphicsItem
*>
itItems
(
mAddedItems
);
...
...
@@ -388,7 +404,7 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth)
mPreviousPolygonItems
.
append
(
polygonItem
);
if
(
UBDrawingController
::
drawingController
()
->
stylusTool
()
!=
UBStylusTool
::
Lin
e
)
if
(
!
bLineStyl
e
)
{
mPreviousPoint
=
pEndPoint
;
mPreviousWidth
=
pWidth
;
...
...
src/domain/UBGraphicsScene.h
View file @
3d8deb8c
...
...
@@ -37,6 +37,7 @@ class UBDocumentProxy;
class
UBGraphicsCurtainItem
;
class
UBGraphicsStroke
;
const
double
PI
=
4
.
0
*
atan
(
1
.
0
);
class
UBGraphicsScene
:
public
UBCoreGraphicsScene
,
public
UBItem
{
...
...
@@ -99,7 +100,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
QRectF
normalizedSceneRect
(
qreal
ratio
=
-
1
.
0
);
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
drawArcTo
(
const
QPointF
&
pCenterPoint
,
qreal
pSpanAngle
);
...
...
@@ -240,6 +241,11 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
mTools
<<
item
;
}
const
QPointF
&
previousPoint
()
{
return
mPreviousPoint
;
}
public
slots
:
void
hideEraser
();
...
...
src/gui/UBDockPalette.cpp
View file @
3d8deb8c
...
...
@@ -33,7 +33,12 @@ UBDockPalette::UBDockPalette(QWidget *parent, const char *name)
{
// standalone window
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
);
...
...
src/gui/UBFloatingPalette.cpp
View file @
3d8deb8c
...
...
@@ -26,10 +26,13 @@ UBFloatingPalette::UBFloatingPalette(Qt::Corner position, QWidget *parent)
else
{
// standalone window
// !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN
setAttribute
(
Qt
::
WA_TranslucentBackground
);
setAttribute
(
Qt
::
WA_MacAlwaysShowToolWindow
);
setAttribute
(
Qt
::
WA_MacNonActivatingToolWindow
);
setAttribute
(
Qt
::
WA_MacNoShadow
);
#endif
}
mBackgroundBrush
=
QBrush
(
UBSettings
::
paletteColor
);
...
...
src/gui/UBResources.cpp
View file @
3d8deb8c
...
...
@@ -43,4 +43,5 @@ void UBResources::init()
arrowCursor
=
QCursor
(
Qt
::
ArrowCursor
);
textCursor
=
QCursor
(
Qt
::
ArrowCursor
);
rotateCursor
=
QCursor
(
QPixmap
(
":/images/cursors/rotate.png"
),
16
,
16
);
drawLineRulerCursor
=
QCursor
(
QPixmap
(
":/images/cursors/drawRulerLine.png"
),
3
,
12
);
}
src/gui/UBResources.h
View file @
3d8deb8c
...
...
@@ -31,6 +31,7 @@ class UBResources : public QObject
QCursor
arrowCursor
;
QCursor
textCursor
;
QCursor
rotateCursor
;
QCursor
drawLineRulerCursor
;
};
#endif
/* UBRESOURCES_H_ */
src/tools/UBAbstractDrawRuler.cpp
0 → 100644
View file @
3d8deb8c
#include "UBAbstractDrawRuler.h"
UBAbstractDrawRuler
::
UBAbstractDrawRuler
()
{}
UBAbstractDrawRuler
::~
UBAbstractDrawRuler
()
{}
src/tools/UBAbstractDrawRuler.h
0 → 100644
View file @
3d8deb8c
#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
\ No newline at end of file
src/tools/UBGraphicsCompass.cpp
View file @
3d8deb8c
...
...
@@ -16,8 +16,6 @@
#include "board/UBBoardController.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
QColor
UBGraphicsCompass
::
sLightBackgroundMiddleFillColor
=
QColor
(
0x72
,
0x72
,
0x72
,
sFillTransparency
);
const
QColor
UBGraphicsCompass
::
sLightBackgroundEdgeFillColor
=
QColor
(
0xc3
,
0xc3
,
0xc3
,
sFillTransparency
);
...
...
@@ -511,9 +509,11 @@ void UBGraphicsCompass::paintCenterCross()
{
QPointF
needleCrossCenter
=
mapToScene
(
needlePosition
());
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
()
->
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
...
...
src/tools/UBGraphicsProtractor.cpp
View file @
3d8deb8c
...
...
@@ -13,7 +13,6 @@
#include "board/UBBoardController.h"
const
double
PI
=
4.0
*
atan
(
1.0
);
const
int
UBGraphicsProtractor
::
sFillTransparency
=
127
;
const
int
UBGraphicsProtractor
::
sDrawTransparency
=
192
;
const
QRectF
UBGraphicsProtractor
::
sDefaultRect
=
QRectF
(
-
175
,
-
175
,
350
,
350
);
...
...
src/tools/UBGraphicsRuler.cpp
View file @
3d8deb8c
...
...
@@ -13,6 +13,7 @@
#include "core/UBApplication.h"
#include "gui/UBResources.h"
#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
QColor
UBGraphicsRuler
::
sLightBackgroundMiddleFillColor
=
QColor
(
0x72
,
0x72
,
0x72
,
sFillTransparency
);
...
...
@@ -200,29 +201,40 @@ void UBGraphicsRuler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void
UBGraphicsRuler
::
hoverEnterEvent
(
QGraphicsSceneHoverEvent
*
event
)
{
mCloseSvgItem
->
setParentItem
(
this
);
mResizeSvgItem
->
setParentItem
(
this
);
mRotateSvgItem
->
setParentItem
(
this
);
mShowButtons
=
true
;
mCloseSvgItem
->
setVisible
(
mShowButtons
);
mResizeSvgItem
->
setVisible
(
mShowButtons
);
mRotateSvgItem
->
setVisible
(
mShowButtons
);
if
(
event
->
pos
().
x
()
>=
resizeButtonRect
().
left
())
{
setCursor
(
resizeCursor
());
}
else
{
if
(
closeButtonRect
().
contains
(
event
->
pos
()))
setCursor
(
closeCursor
());
else
if
(
rotateButtonRect
().
contains
(
event
->
pos
()))
setCursor
(
rotateCursor
());
else
setCursor
(
moveCursor
());
}
event
->
accept
();
update
();
UBStylusTool
::
Enum
currentTool
=
(
UBStylusTool
::
Enum
)
UBDrawingController
::
drawingController
()
->
stylusTool
();
if
(
currentTool
==
UBStylusTool
::
Selector
)
{
mCloseSvgItem
->
setParentItem
(
this
);
mResizeSvgItem
->
setParentItem
(
this
);
mRotateSvgItem
->
setParentItem
(
this
);
mShowButtons
=
true
;
mCloseSvgItem
->
setVisible
(
mShowButtons
);
mResizeSvgItem
->
setVisible
(
mShowButtons
);
mRotateSvgItem
->
setVisible
(
mShowButtons
);
if
(
event
->
pos
().
x
()
>=
resizeButtonRect
().
left
())
{
setCursor
(
resizeCursor
());
}
else
{
if
(
closeButtonRect
().
contains
(
event
->
pos
()))
setCursor
(
closeCursor
());
else
if
(
rotateButtonRect
().
contains
(
event
->
pos
()))
setCursor
(
rotateCursor
());
else
setCursor
(
moveCursor
());
}
event
->
accept
();
update
();
}
else
if
(
UBDrawingController
::
drawingController
()
->
isDrawingTool
())
{
setCursor
(
drawRulerLineCursor
());
UBDrawingController
::
drawingController
()
->
mActiveRuler
=
this
;
event
->
accept
();
}
}
void
UBGraphicsRuler
::
hoverLeaveEvent
(
QGraphicsSceneHoverEvent
*
event
)
...
...
@@ -232,29 +244,39 @@ void UBGraphicsRuler::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
mCloseSvgItem
->
setVisible
(
mShowButtons
);
mResizeSvgItem
->
setVisible
(
mShowButtons
);
mRotateSvgItem
->
setVisible
(
mShowButtons
);
UBDrawingController
::
drawingController
()
->
mActiveRuler
=
NULL
;
event
->
accept
();
update
();
}
void
UBGraphicsRuler
::
hoverMoveEvent
(
QGraphicsSceneHoverEvent
*
event
)
{
mCloseSvgItem
->
setVisible
(
mShowButtons
);
mResizeSvgItem
->
setVisible
(
mShowButtons
);
mRotateSvgItem
->
setVisible
(
mShowButtons
);
if
(
event
->
pos
().
x
()
>=
resizeButtonRect
().
left
())
{
setCursor
(
resizeCursor
());
}
else
{
if
(
closeButtonRect
().
contains
(
event
->
pos
()))
setCursor
(
closeCursor
());
else
if
(
rotateButtonRect
().
contains
(
event
->
pos
()))
setCursor
(
rotateCursor
());
else
setCursor
(
moveCursor
());
}
event
->
accept
();
UBStylusTool
::
Enum
currentTool
=
(
UBStylusTool
::
Enum
)
UBDrawingController
::
drawingController
()
->
stylusTool
();
if
(
currentTool
==
UBStylusTool
::
Selector
)
{
mCloseSvgItem
->
setVisible
(
mShowButtons
);
mResizeSvgItem
->
setVisible
(
mShowButtons
);
mRotateSvgItem
->
setVisible
(
mShowButtons
);
if
(
event
->
pos
().
x
()
>=
resizeButtonRect
().
left
())
{
setCursor
(
resizeCursor
());
}
else
{
if
(
closeButtonRect
().
contains
(
event
->
pos
()))
setCursor
(
closeCursor
());
else
if
(
rotateButtonRect
().
contains
(
event
->
pos
()))
setCursor
(
rotateCursor
());
else
setCursor
(
moveCursor
());
}
event
->
accept
();
}
else
if
(
currentTool
==
UBStylusTool
::
Pen
||
currentTool
==
UBStylusTool
::
Marker
)
{
event
->
accept
();
}
}
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
);
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
()
{}
src/tools/UBGraphicsRuler.h
View file @
3d8deb8c
...
...
@@ -14,10 +14,11 @@
#include "core/UB.h"
#include "domain/UBItem.h"
#include "tools/UBAbstractDrawRuler.h"
class
UBGraphicsScene
;
class
UBGraphicsRuler
:
public
QObject
,
public
QGraphicsRectItem
,
public
UBItem
class
UBGraphicsRuler
:
public
UBAbstractDrawRuler
,
public
QGraphicsRectItem
,
public
UBItem
{
Q_OBJECT
;
...
...
@@ -34,6 +35,10 @@ class UBGraphicsRuler : public QObject, public QGraphicsRectItem, public UBItem
virtual
UBItem
*
deepCopy
()
const
;
virtual
void
StartLine
(
const
QPointF
&
position
,
qreal
width
);
virtual
void
DrawLine
(
const
QPointF
&
position
,
qreal
width
);
virtual
void
EndLine
();
signals
:
void
hidden
();
...
...
@@ -63,6 +68,7 @@ class UBGraphicsRuler : public QObject, public QGraphicsRectItem, public UBItem
QCursor
resizeCursor
()
const
;
QCursor
rotateCursor
()
const
;
QCursor
closeCursor
()
const
;
QCursor
drawRulerLineCursor
()
const
;
QRectF
resizeButtonRect
()
const
;
QRectF
closeButtonRect
()
const
;
QRectF
rotateButtonRect
()
const
;
...
...
@@ -72,6 +78,8 @@ class UBGraphicsRuler : public QObject, public QGraphicsRectItem, public UBItem
QColor
edgeFillColor
()
const
;
QFont
font
()
const
;
int
drawLineDirection
;
// Members
bool
mResizing
;
bool
mRotating
;
...
...
@@ -82,6 +90,8 @@ class UBGraphicsRuler : public QObject, public QGraphicsRectItem, public UBItem
QCursor
mResizeCursor
;
qreal
mAntiScaleRatio
;
QPointF
startDrawPosition
;
// Constants
static
const
QRect
sDefaultRect
;
static
const
int
sLeftEdgeMargin
=
10
;
...
...
src/tools/tools.pri
View file @
3d8deb8c
...
...
@@ -4,11 +4,13 @@ HEADERS += src/tools/UBGraphicsRuler.h \
src/tools/UBGraphicsCompass.h \
src/tools/UBToolsManager.h \
src/tools/UBGraphicsCurtainItem.h \
src/tools/UBGraphicsCurtainItemDelegate.h
src/tools/UBGraphicsCurtainItemDelegate.h \
src/tools/UBAbstractDrawRuler.h
SOURCES += src/tools/UBGraphicsRuler.cpp \
src/tools/UBGraphicsProtractor.cpp \
src/tools/UBGraphicsCompass.cpp \
src/tools/UBToolsManager.cpp \
src/tools/UBGraphicsCurtainItem.cpp \
src/tools/UBGraphicsCurtainItemDelegate.cpp \
\ No newline at end of file
src/tools/UBGraphicsCurtainItemDelegate.cpp \
src/tools/UBAbstractDrawRuler.cpp
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment