1 /*
2  *  Copyright (c) 2013 Dmitry Kazakov <dimula73@gmail.com>
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 2 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, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef __KIS_INFINITY_MANAGER_H
20 #define __KIS_INFINITY_MANAGER_H
21 
22 #include "kis_canvas_decoration.h"
23 
24 #include <QPointer>
25 #include <QPainterPath>
26 #include <QCursor>
27 
28 #include <kis_canvas2.h>
29 
30 class KisView;
31 
32 static const QString INFINITY_DECORATION_ID = "infinity-decorations";
33 
34 class KRITAUI_EXPORT KisInfinityManager : public KisCanvasDecoration
35 {
36 Q_OBJECT
37 
38 public:
39 KisInfinityManager(QPointer<KisView>view, KisCanvas2 *canvas);
40 
41 protected:
42     void drawDecoration(QPainter& gc, const QRectF& updateArea, const KisCoordinatesConverter *converter, KisCanvas2 *canvas) override;
43     bool eventFilter(QObject *obj, QEvent *event) override;
44 
45 public Q_SLOTS:
46     void imagePositionChanged();
47 
48 private:
49     enum Side {
50         Right = 0,
51         Bottom,
52         Left,
53         Top,
54 
55         NSides
56     };
57     inline void addDecoration(const QRect &areaRect, const QPointF &handlePoint, qreal angle, Side side);
58 
59 private:
60     QPainterPath m_decorationPath;
61 
62     bool m_filteringEnabled;
63     bool m_cursorSwitched;
64     QCursor m_oldCursor;
65     QVector<QTransform> m_handleTransform;
66 
67     QVector<QRect> m_sideRects;
68 
69     QPointer<KisCanvas2> m_canvas;
70 };
71 
72 #endif /* __KIS_INFINITY_MANAGER_H */
73