1 /*******************************************************************************
2 **
3 ** Photivo
4 **
5 ** Copyright (C) 2011-2012 Bernd Schoeler <brjohn@brother-john.net>
6 **
7 ** This file is part of Photivo.
8 **
9 ** Photivo is free software: you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License version 3
11 ** as published by the Free Software Foundation.
12 **
13 ** Photivo is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with Photivo.  If not, see <http://www.gnu.org/licenses/>.
20 **
21 *******************************************************************************/
22 /*!
23   \class ptRepairInteraction
24 
25   \brief On-image user interaction for the spot repair tool
26 
27   This class provides all the functionality for the interactive spot repair
28   mode, i.e. all manipulation of repair spots that happen directly on the image.
29 */
30 
31 //==============================================================================
32 
33 #ifndef PTREPAIRINTERACTION_H
34 #define PTREPAIRINTERACTION_H
35 
36 #include <QGraphicsItemGroup>
37 #include <QGraphicsEllipseItem>
38 #include <QGraphicsLineItem>
39 #include <QGraphicsRectItem>
40 #include <QGraphicsDropShadowEffect>
41 
42 #include <ptAbstractInteraction.h>
43 #include "ptRepairSpot.h"
44 #include "ptImageSpotModel.h"
45 
46 //==============================================================================
47 
48 class ptRepairInteraction : public ptAbstractInteraction {
49 Q_OBJECT
50 
51 public:
52   /*! Create a repair interaction object.
53     \param View
54       A pointer to an existing \c QGraphicsView object that will be used for
55       drawing the spot. \c View must have a \c QGraphicsScene assigned.
56     \param ListView
57       A pointer to an existing list view widget containing the spots. \c ListView must
58       have a model assigned.
59   */
60   ptRepairInteraction(QGraphicsView *AView);
61 
62   ~ptRepairInteraction();
63 
64   // TODO: key/mouse flags are very preliminary!
65   /*! Reimplemented from base class. */
modifiers()66   virtual Qt::KeyboardModifiers modifiers()    const { return Qt::NoModifier; }
67 
68   /*! Reimplemented from base class. */
mouseActions()69   virtual ptMouseActions        mouseActions() const { return maClick; }
70 
71   /*! Reimplemented from base class. */
mouseButtons()72   virtual Qt::MouseButtons      mouseButtons() const { return Qt::LeftButton; }
73 
74   /*! Stop the repair interaction.
75     Cleans up the QGraphicsScene and then emits the \c finished() signal. */
76   void stop();
77 
78 //------------------------------------------------------------------------------
79 
80 private:
81   struct TSpotShape {
82     QGraphicsItemGroup   *Root;             // container for the complete spot-shape
83     QGraphicsItemGroup   *SpotGroup;        // container for the spot
84     QGraphicsItemGroup   *RepairerGroup;    // container for repairer and connector line
85 
86     QGraphicsEllipseItem *Spot;             // outer border of the area to be repaired
87     QGraphicsEllipseItem *SpotBorder;       // inner border, for edge blur
88     QGraphicsRectItem    *RadiusHandle;     // mouse handle to change spot radius
89     QGraphicsEllipseItem *RotationHandle;   // mouse handle to rotate the spot
90 
91     QGraphicsEllipseItem *Repairer;         // area with the repair reference data
92     QGraphicsLineItem    *Connector;        // connector line between spot and repairer
93   };
94 
95   /*! Creates and initialises a TSpotShape. The shape is hidden. Component positions are not set. */
96   TSpotShape  *CreateShape();
97 
98   /*! Destroys all objects of a TSpotShape as well as the shape struct itself. */
99   void        DestroyShape(TSpotShape *AShape);
100 
101   /*! Draws a spotshape.
102       \param AShape
103         A pointer to the TSpotShape that should be drawn.
104       \param ASpotData
105         A pointer to the spot data to use. */
106   void        Draw(TSpotShape *AShape, ptRepairSpot *ASpotData);
107 
108   void        MousePressHandler(QMouseEvent* AEvent);
109   void        MouseDblClickHandler(QMouseEvent* AEvent);
110 
111 //  ptImageSpotListView      *FListView;
112 
113   // Components of the spot visual spot shape
114   QGraphicsDropShadowEffect *FShadow;      // for the b/w line effect
115   QList<TSpotShape*>        *FShapes;      // container for the complete spot shape
116 
117 //------------------------------------------------------------------------------
118 
119 private slots:
120   /*! Slot that is called when the current spot is changed.
121     \param index
122       The model index of the new spot.
123   */
124   void changeSpot(const QModelIndex &AIndex);
125 
126   /*! Slot for all keyboard events.
127     \param event
128       A pointer to the QKeyEvent that triggered this slot.
129   */
130   void keyAction(QKeyEvent *AEvent);
131 
132   /*! Slot for all mouse events.
133     \param event
134       A pointer to the QMouseEvent that triggered this slot.
135   */
136   void mouseAction(QMouseEvent *AEvent);
137 
138 
139 };
140 #endif // PTREPAIRINTERACTION_H
141