-
Notifications
You must be signed in to change notification settings - Fork 105
/
edit_line_tool.h
151 lines (113 loc) · 3.77 KB
/
edit_line_tool.h
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* Copyright 2012, 2013 Thomas Schöps
* Copyright 2013-2017 Kai Pastor
*
* This file is part of OpenOrienteering.
*
* OpenOrienteering is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenOrienteering is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenOrienteering. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPENORIENTEERING_EDIT_LINE_TOOL_H
#define OPENORIENTEERING_EDIT_LINE_TOOL_H
#include <QElapsedTimer>
#include <QObject>
#include <QRectF>
#include <QScopedPointer>
#include <QString>
#include "core/map_coord.h"
#include "tools/edit_tool.h"
class QAction;
class QKeyEvent;
class QMouseEvent;
class QPainter;
class QRectF;
namespace OpenOrienteering {
class MapEditorController;
class MapRenderables;
class MapWidget;
class ObjectMover;
class PathObject;
/**
* A tool to edit lines of PathObjects.
*/
class EditLineTool : public EditTool
{
Q_OBJECT
public:
EditLineTool(MapEditorController* editor, QAction* tool_action);
~EditLineTool() override;
bool mousePressEvent(QMouseEvent* event, const MapCoordF& map_coord, MapWidget* widget) override;
bool mouseMoveEvent(QMouseEvent* event, const MapCoordF& map_coord, MapWidget* widget) override;
bool mouseReleaseEvent(QMouseEvent* event, const MapCoordF& map_coord, MapWidget* widget) override;
void mouseMove() override;
void clickPress() override;
void clickRelease() override;
void dragStart() override;
void dragMove() override;
void dragFinish() override;
void dragCanceled() override;
protected:
bool keyPress(QKeyEvent* event) override;
bool keyRelease(QKeyEvent* event) override;
void initImpl() override;
void objectSelectionChangedImpl() override;
int updateDirtyRectImpl(QRectF& rect) override;
void drawImpl(QPainter* painter, MapWidget* widget) override;
/** In addition to the base class implementation, updates the status text. */
void updatePreviewObjects() override;
/** Deletes the highlight object if it exists and correctly removes its renderables. */
void deleteHighlightObject();
void updateStatusText() override;
/** Recalculates hover_line. */
void updateHoverState(const MapCoordF& cursor_pos);
bool hoveringOverFrame() const;
private:
/** Measures the time a click takes to decide whether to do selection. */
QElapsedTimer click_timer;
/** Bounding box of the selection */
QRectF selection_extent;
/**
* Provides general information on what is hovered over.
*/
HoverState hover_state = OverNothing;
/**
* Object which is hovered over (if any).
*/
PathObject* hover_object = nullptr;
/**
* Coordinate identifying the hover_object's line which is hovered over.
*/
MapCoordVector::size_type hover_line;
/**
* An object created for the current hover_line.
*/
PathObject* highlight_object = nullptr;
/** Is a box selection in progress? */
bool box_selection = false;
bool waiting_for_mouse_release = false;
/**
* Offset from cursor position to drag handle of moved element.
* When snapping to another element, this offset must be corrected.
*/
MapCoordF handle_offset;
QScopedPointer<ObjectMover> object_mover;
QScopedPointer<MapRenderables> highlight_renderables;
};
// ### EditLineTool inline code ###
inline
bool EditLineTool::hoveringOverFrame() const
{
return hover_state == OverFrame;
}
} // namespace OpenOrienteering
#endif