1 /* 2 * Copyright 2012, 2013 Thomas Schöps 3 * Copyright 2012-2016 Kai Pastor 4 * 5 * This file is part of OpenOrienteering. 6 * 7 * OpenOrienteering is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * OpenOrienteering is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with OpenOrienteering. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 22 #ifndef OPENORIENTEERING_PRINT_TOOL_H 23 #define OPENORIENTEERING_PRINT_TOOL_H 24 25 #ifdef QT_PRINTSUPPORT_LIB 26 27 #include <QObject> 28 #include <QPoint> 29 30 #include "core/map_coord.h" 31 #include "tools/tool.h" 32 33 class QCursor; 34 class QMouseEvent; 35 class QPainter; 36 37 namespace OpenOrienteering { 38 39 class MapEditorController; 40 class MapPrinter; 41 class MapWidget; 42 43 44 /** 45 * The PrintTool lets the user see and modify the print area on the map 46 * by dragging 47 * 48 * It interacts with a MapEditorController and a PrintWidget which are set in 49 * the constructor. 50 */ 51 class PrintTool : public MapEditorTool 52 { 53 Q_OBJECT 54 public: 55 /** Constructs a new PrintTool to configure the given map printer in the 56 * context of the editor. 57 * 58 * The parameters must not be null. */ 59 PrintTool(MapEditorController* editor, MapPrinter* map_printer); 60 61 ~PrintTool() override; 62 63 /** Notifies the tool that it becomes active. */ 64 void init() override; 65 66 /** Always returns the tool's default cursor. */ 67 const QCursor& getCursor() const override; 68 69 /** Starts a dragging interaction. */ 70 bool mousePressEvent(QMouseEvent* event, const MapCoordF& map_coord, MapWidget* widget) override; 71 72 /** Updates the state of a running dragging interaction. When not dragging, 73 * it will update the cursor to indicate a possible interaction. */ 74 bool mouseMoveEvent(QMouseEvent* event, const MapCoordF& map_coord, MapWidget* widget) override; 75 76 /** Finishes dragging interactions. */ 77 bool mouseReleaseEvent(QMouseEvent* event, const MapCoordF& map_coord, MapWidget* widget) override; 78 79 /** Draws a visualization of the print area the map widget. */ 80 void draw(QPainter* painter, MapWidget* widget) override; 81 82 public slots: 83 /** Updates the print area visualization in the map editors. */ 84 void updatePrintArea(); 85 86 protected: 87 /** Modifies the print area while dragging. 88 * This must not be called when the region is Outside. */ 89 void updateDragging(const MapCoordF& mouse_pos_map); 90 91 /** Updates the current interaction region. 92 * This must not be called during dragging. */ 93 void mouseMoved(const MapCoordF& mouse_pos_map, MapWidget* widget); 94 95 /** Regions of interaction with the print area. */ 96 enum InteractionRegion { 97 Inside = 0x00, 98 Outside = 0x01, 99 LeftBorder = 0x02, 100 TopLeftCorner = 0x06, 101 TopBorder = 0x04, 102 TopRightCorner = 0x0c, 103 RightBorder = 0x08, 104 BottomRightCorner = 0x18, 105 BottomBorder = 0x10, 106 BottomLeftCorner = 0x12, 107 Unknown = 0xFF 108 }; 109 110 /** The map printer this tool is operation on. */ 111 MapPrinter* const map_printer; 112 113 /** The region of the print area where the current interaction takes place. */ 114 InteractionRegion region; 115 116 /** Indicates whether an interaction is taking place at the moment. */ 117 bool dragging; 118 119 /** The screen position where the initial click was made. */ 120 QPoint click_pos; 121 122 /** The map position where the initial click was made. */ 123 MapCoordF click_pos_map; 124 }; 125 126 #endif // QT_PRINTSUPPORT_LIB 127 128 129 } // namespace OpenOrienteering 130 131 #endif // OPENORIENTEERING_PRINT_TOOL_H 132