-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathCommentTool.cpp
104 lines (87 loc) · 2.99 KB
/
CommentTool.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* This file is part of the KDE project
* SPDX-FileCopyrightText: 2010 Carlos Licea <[email protected]>
*
* SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "CommentTool.h"
#include "CommentShape.h"
#include "InitialsCommentShape.h"
#include <KoCanvasBase.h>
#include <KoShape.h>
#include <KoShapeManager.h>
#include <KoPointerEvent.h>
#include <QSet>
CommentTool::CommentTool(KoCanvasBase *canvas)
: KoToolBase(canvas)
, m_canvas(canvas)
, m_previouseActiveCommentShape(0)
{
}
CommentTool::~CommentTool()
{
}
void CommentTool::activate(KoToolBase::ToolActivation toolActivation, const QSet<KoShape *> & /*shapes*/)
{
const QCursor cursor(Qt::ArrowCursor);
Q_EMIT useCursor(cursor);
QList<KoShape *> allShapes = m_canvas->shapeManager()->shapes();
foreach (KoShape *shape, allShapes) {
InitialsCommentShape *initialsShape = dynamic_cast<InitialsCommentShape *>(shape);
if (initialsShape) {
initialsShape->setSelectable(true);
}
}
m_temporary = toolActivation == KoToolBase::TemporaryActivation;
}
void CommentTool::deactivate()
{
QList<KoShape *> allShapes = m_canvas->shapeManager()->shapes();
foreach (KoShape *shape, allShapes) {
InitialsCommentShape *initialsShape = dynamic_cast<InitialsCommentShape *>(shape);
if (initialsShape) {
initialsShape->setSelectable(false);
}
}
if (m_previouseActiveCommentShape) {
m_previouseActiveCommentShape->toogleActive();
m_previouseActiveCommentShape = 0;
}
}
void CommentTool::mouseReleaseEvent(KoPointerEvent *event)
{
// disable the previous activeshape
if (m_previouseActiveCommentShape) {
m_previouseActiveCommentShape->setActive(false);
}
InitialsCommentShape *initialsUnderCursor =
dynamic_cast<InitialsCommentShape *>(m_canvas->shapeManager()->shapeAt(event->point, KoFlake::ShapeOnTop, false));
if (initialsUnderCursor) {
// don't re-activate the shape we just deactivated
if (m_previouseActiveCommentShape == initialsUnderCursor->parent()) {
m_previouseActiveCommentShape = 0;
return;
}
CommentShape *commentUnderCursor = dynamic_cast<CommentShape *>(initialsUnderCursor->parent());
Q_ASSERT(commentUnderCursor);
commentUnderCursor->setActive(true);
m_previouseActiveCommentShape = commentUnderCursor;
}
event->accept();
}
void CommentTool::mouseMoveEvent(KoPointerEvent *event)
{
InitialsCommentShape *shapeUnderCursor = dynamic_cast<InitialsCommentShape *>(m_canvas->shapeManager()->shapeAt(event->point, KoFlake::ShapeOnTop, false));
if (shapeUnderCursor) {
const QCursor cursor(Qt::PointingHandCursor);
Q_EMIT useCursor(cursor);
} else {
const QCursor cursor(Qt::ArrowCursor);
Q_EMIT useCursor(cursor);
}
}
void CommentTool::mousePressEvent(KoPointerEvent * /*event*/)
{
}
void CommentTool::paint(QPainter & /*painter*/, const KoViewConverter & /*converter*/)
{
}