1 /*******************************************************************************
2 **
3 ** Photivo
4 **
5 ** Copyright (C) 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 #include "ptSpotInteraction.h"
24 
25 //==============================================================================
26 
ptSpotInteraction(QGraphicsView * AView)27 ptSpotInteraction::ptSpotInteraction(QGraphicsView *AView)
28 : ptAbstractInteraction(AView),
29   FAbortNextMouseAction(false)
30 {
31   FView->setCursor(Qt::CrossCursor);
32 }
33 
34 //==============================================================================
35 
~ptSpotInteraction()36 ptSpotInteraction::~ptSpotInteraction() {
37   FView->setCursor(Qt::ArrowCursor);
38 }
39 
40 //==============================================================================
41 
abortMouseAction(const ptMouseAction)42 void ptSpotInteraction::abortMouseAction(const ptMouseAction /*AAction*/) {
43   FAbortNextMouseAction = true;
44 }
45 
46 //==============================================================================
47 
stop()48 void ptSpotInteraction::stop() {
49   emit finished(stSuccess);
50 }
51 
52 //==============================================================================
53 
mouseAction(QMouseEvent * AEvent)54 void ptSpotInteraction::mouseAction(QMouseEvent *AEvent) {
55   if (FAbortNextMouseAction) {
56     FAbortNextMouseAction = false;
57     return;
58   }
59 
60   if (AEvent->type() == QEvent::MouseButtonRelease &&
61       AEvent->button() == Qt::LeftButton &&
62       AEvent->modifiers() == Qt::NoModifier)
63   {
64     QPointF hClickPos = FView->mapToScene(AEvent->pos());
65     // ensure click was inside image, then emit signal
66     if (FView->scene()->sceneRect().contains(hClickPos)) {
67       emit clicked(QPoint(qRound(hClickPos.x()), qRound(hClickPos.y())));
68     }
69   }
70 }
71 
72 //==============================================================================
73