1 /*
2  * Copyright (C) 2018 Damir Porobic <damir.porobic@gmx.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser 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 Lesser General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef KIMAGEANNOTATOR_ANNOTATIONITEMRESIZER_H
21 #define KIMAGEANNOTATOR_ANNOTATIONITEMRESIZER_H
22 
23 #include <QGraphicsWidget>
24 
25 #include "resizeHandles/ResizeHandlesFactory.h"
26 #include "src/annotations/undo/ResizeCommand.h"
27 #include "src/annotations/core/ZoomValueProvider.h"
28 
29 namespace kImageAnnotator {
30 
31 class AnnotationItemResizer : public QGraphicsWidget
32 {
33 Q_OBJECT
34 public:
35     AnnotationItemResizer(AbstractAnnotationItem *item, ZoomValueProvider *zoomValueProvider);
36     ~AnnotationItemResizer() override;
37     QRectF boundingRect() const override;
38     void grabHandle(const QPointF &pos);
39     void moveHandle(const QPointF &pos, bool isCtrlPressed);
40     void releaseHandle();
41     bool isResizing() const;
42     void refresh();
43     bool isItemVisible() const;
44     Qt::CursorShape cursorForPos(const QPointF &pos);
45     Qt::CursorShape cursorForCurrentHandle();
46 
47 signals:
48     void newCommand(ResizeCommand *resize) const;
49 
50 protected:
51     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
52 
53 private:
54     AbstractItemResizeHandles *mResizeHandles;
55     AbstractAnnotationItem *mAnnotationItem;
56     ZoomValueProvider *mZoomValueProvider;
57     int mCurrentHandle;
58     QPointF mClickOffset;
59 
60     void applyZoomValue(double value);
61 };
62 
63 } // namespace kImageAnnotator
64 
65 #endif // KIMAGEANNOTATOR_ANNOTATIONITEMRESIZER_H
66