1 /**********************************************************************************************
2     Copyright (C) 2017 Oliver Eichler <oliver.eichler@gmx.de>
3 
4     This program is free software: you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation, either version 3 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 
17 **********************************************************************************************/
18 
19 #ifndef IITEM_H
20 #define IITEM_H
21 
22 
23 #include "tool/ITool.h"
24 #include <QObject>
25 
26 class QSettings;
27 class IDrawContext;
28 
29 class IItem : public QObject, public ITool
30 {
31     Q_OBJECT
32 public:
33     IItem(const QString& filename);
34     virtual ~IItem() = default;
35 
36     virtual void saveSettings(QSettings& cfg);
37     virtual void loadSettings(QSettings& cfg);
38 
getFilename()39     const QString& getFilename() const
40     {
41         return filename;
42     }
43 
getDrawContext()44     IDrawContext* getDrawContext() const
45     {
46         return drawContext;
47     }
48 
getMapDidMove()49     bool getMapDidMove() const
50     {
51         return mapDidMove;
52     }
53 
getMapIsMoving()54     bool getMapIsMoving() const
55     {
56         return mapIsMoving;
57     }
58 
59     /// reload file into draw context
60     virtual void reload();
61     /// item has been selected, bring everything to front (to be displayed)
toFront()62     virtual void toFront(){}
63 
64     bool drawFx(QPainter& p, CCanvas::redraw_e needsRedraw) override;
65     void mousePressEventFx(QMouseEvent* e) override;
66     void mouseMoveEventFx(QMouseEvent* e) override;
67     void mouseReleaseEventFx(QMouseEvent* e) override;
68     void wheelEventFx(QWheelEvent* e) override;
69 
isOk()70     virtual bool isOk() const
71     {
72         return false;
73     }
74 
75 signals:
76     void sigChanged();
77 
78 protected:
79     QString filename;
80     IDrawContext* drawContext = nullptr;
81 
82     /// true while left mouse button is pressed down
83     bool mapIsMoving = false;
84     /// true if map actually moved, if not it's a single click
85     bool mapDidMove = false;
86 
87     /// last mouse position
88     QPoint lastPos;
89     /// mouse position when left button was pressed
90     QPoint firstPos;
91 
92     /// current accumulated angleDelta, used/required for zooming on track pads
93     int zoomAngleDelta = 0;
94 };
95 
96 #endif //IITEM_H
97 
98