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 CCANVAS_H
20 #define CCANVAS_H
21 
22 #include <QLabel>
23 #include <QMovie>
24 #include <QMutex>
25 #include <QPointer>
26 #include <QWidget>
27 
28 class ITool;
29 class CMainWindow;
30 class QStackedWidget;
31 
32 class CCanvas : public QWidget
33 {
34     Q_OBJECT
35 public:
36     CCanvas(QWidget* parent);
37     virtual ~CCanvas() = default;
38 
39     static void setOverrideCursor(const QCursor& cursor, const QString&);
40     static void restoreOverrideCursor(const QString& src);
41     static void changeOverrideCursor(const QCursor& cursor, const QString& src);
42 
43     enum redraw_e
44     {
45         eRedrawNone = 0
46         , eRedrawMap = 0x01
47         , eRedrawOverlay = 0x08
48         , eRedrawAll = 0xFFFFFFFF
49     };
50 
setToolInterface(ITool * t)51     void setToolInterface(ITool* t)
52     {
53         tool = t;
54     }
55 
56 signals:
57     void sigChangedSize(const QSize& size);
58 
59 public slots:
60     void slotTriggerCompleteUpdate(CCanvas::redraw_e flags);
61 
62     void slotShowLoadIndicator();
63     void slotHideLoadIndicator();
64 
65 protected:
66     void resizeEvent(QResizeEvent* e) override;
67     void paintEvent(QPaintEvent* e) override;
68     void mousePressEvent(QMouseEvent* e) override;
69     void mouseMoveEvent(QMouseEvent* e) override;
70     void mouseReleaseEvent(QMouseEvent* e) override;
71     void mouseDoubleClickEvent(QMouseEvent* e) override;
72     void wheelEvent(QWheelEvent* e) override;
73     void enterEvent(QEvent* e) override;
74     void leaveEvent(QEvent* e) override;
75     void keyPressEvent(QKeyEvent* e) override;
76 
77 private:
78     mutable QMutex mutex {QMutex::Recursive};
79 
80     QColor backColor = 0xFFFFFFBF;       //< the background color used in case of missing map tiles
81     redraw_e needsRedraw = eRedrawAll;  //< set true to initiate a complete redraw of the screen content
82 
83     /// load indicator for maps
84     QMovie* loadIndicator1;
85     QLabel* mapLoadIndicator;
86     qint32 mapLoadIndicatorCount = 0;
87 
88     ITool* tool = nullptr;
89 };
90 
91 #endif //CCANVAS_H
92 
93