-
Notifications
You must be signed in to change notification settings - Fork 105
/
draw_line_and_area_tool.h
146 lines (110 loc) · 4.04 KB
/
draw_line_and_area_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
/*
* Copyright 2012, 2013 Thomas Schöps
* Copyright 2014 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_DRAW_LINE_AND_AREA_H
#define OPENORIENTEERING_DRAW_LINE_AND_AREA_H
#include <memory>
#include <vector>
#include <QObject>
#include <QRectF>
#include <QString>
#include "tools/tool.h"
class QAction;
class QEvent;
class QPainter;
class QRectF;
namespace OpenOrienteering {
class CombinedSymbol;
class LineSymbol;
struct LineSymbolBorder;
class MapCoordF;
class MapEditorController;
class MapRenderables;
class MapWidget;
class PathObject;
class PointObject;
class PointSymbol;
class Symbol;
/**
* Base class for drawing tools for line and area symbols.
* Provides some common functionality, e.g. displaying the preview objects or
* coping with changing symbols.
*/
class DrawLineAndAreaTool : public MapEditorTool
{
Q_OBJECT
public:
DrawLineAndAreaTool(MapEditorController* editor, Type type, QAction* tool_action, bool is_helper_tool);
~DrawLineAndAreaTool() override;
void leaveEvent(QEvent* event) override;
void finishEditing() override;
signals:
void dirtyRectChanged(const QRectF& rect);
void pathAborted();
void pathFinished(OpenOrienteering::PathObject* path);
protected slots:
virtual void setDrawingSymbol(const OpenOrienteering::Symbol* symbol);
protected:
/**
* Creates point objects and symbols which serve as a preview for
* drawing the selected symbol.
*/
void createPreviewPoints();
/** Creates preview point symbols for the given symbol. */
void addPreviewPointSymbols(const Symbol* symbol);
/** Creates preview point symbols for the border of the given line symbol. */
void addPreviewPointSymbolsForBorder(const LineSymbol* line, const LineSymbolBorder* border);
/**
* Sets the position of the preview objects (after cursor movements).
* @param map_coord The new position.
* @param points_index The index of the points set; there are two sets,
* so the preview points can be displayed at two positions at the same time.
*/
void setPreviewPointsPosition(const MapCoordF& map_coord, int points_index = 0);
/** Hides all preview points. */
void hidePreviewPoints();
/** Does necessary preparations to start drawing. */
void startDrawing();
/** Calls update() on the preview path, correctly handling its renderables. */
virtual void updatePreviewPath();
/** Aborts drawing. */
virtual void abortDrawing();
/** Finishes drawing, creating a new undo step. */
virtual void finishDrawing();
/** Finishes drawing, appending to the given object if not nullptr. */
void finishDrawing(PathObject* append_to_object);
/** Deletes preview all objects and points. */
void deletePreviewObjects();
/** Extends the rect to conver all preview objects. */
void includePreviewRects(QRectF& rect);
/** Draws the preview objects. */
void drawPreviewObjects(QPainter* painter, MapWidget* widget);
std::vector<PointSymbol*> preview_point_symbols;
std::vector<bool> preview_point_symbols_external;
std::vector<PointObject*> preview_points[2];
std::unique_ptr<CombinedSymbol> path_combination;
std::unique_ptr<MapRenderables> renderables;
const Symbol* drawing_symbol = nullptr;
PathObject* preview_path = nullptr;
int preview_point_radius = 0;
bool preview_points_shown = false;
bool is_helper_tool = false;
};
} // namespace OpenOrienteering
#endif