1 /*
2  * Copyright (C) 2020 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_ANNOTATIONITEMMODIFIER_H
21 #define KIMAGEANNOTATOR_ANNOTATIONITEMMODIFIER_H
22 
23 #include <QObject>
24 #include <QGraphicsItemGroup>
25 #include <QGraphicsSceneMouseEvent>
26 #include <QGraphicsSceneDragDropEvent>
27 
28 #include "AnnotationMultiItemResizer.h"
29 #include "AnnotationItemSelector.h"
30 #include "AnnotationItemMover.h"
31 #include "AnnotationItemEditor.h"
32 
33 namespace kImageAnnotator {
34 
35 class AnnotationItemModifier : public QObject, public QGraphicsItemGroup
36 {
37 Q_OBJECT
38 
39 public:
40 	explicit AnnotationItemModifier(ZoomValueProvider *zoomValueProvider);
41 	~AnnotationItemModifier() override;
42 	void handleMousePress(const QPointF &pos, QList<AbstractAnnotationItem *> *items, bool isCtrlPressed);
43 	void handleMouseMove(const QPointF &pos, bool isCtrlPressed);
44 	void handleMouseRelease(QList<AbstractAnnotationItem *> *items);
45 	void handleMouseDoubleClick(const QPointF &pos, QList<AbstractAnnotationItem *> *items);
46 	void handleSelectionAt(const QPointF &pos, QList<AbstractAnnotationItem *> *items, bool isCtrlPressed);
47 	QList<AbstractAnnotationItem *> selectedItems() const;
48 	QRectF boundingRect() const override;
49 	void selectItem(AbstractAnnotationItem *item);
50 
51 public slots:
52 	void clear();
53 	void updateSelection();
54 
55 signals:
56 	void newCommand(QUndoCommand *command);
57 	void itemsSelected(const QList<AbstractAnnotationItem *> &items) const;
58 	void itemsDeselected();
59 	void itemModified() const;
60 	void itemEdit();
61 
62 protected:
63 	void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
64 	void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
65 
66 private:
67 	AnnotationMultiItemResizer *mItemResizer;
68 	AnnotationItemSelector *mItemSelector;
69 	AnnotationItemMover *mItemMover;
70 	AnnotationItemEditor *mItemEditor;
71 
72 	void handleSelection();
73 	void updateCursor(Qt::CursorShape cursor);
74 
75 private slots:
76 	void itemChanged(QUndoCommand *command);
77 };
78 
79 } // namespace kImageAnnotator
80 
81 #endif // KIMAGEANNOTATOR_ANNOTATIONITEMMODIFIER_H
82