1 /** -*- mode: c++ ; c-basic-offset: 2 -*-
2  *
3  *  @file OverrideCursor.cpp
4  *
5  *  Copyright 2017 Sebastien Fourey
6  *
7  *  This file is part of G'MIC-Qt, a generic plug-in for raster graphics
8  *  editors, offering hundreds of filters thanks to the underlying G'MIC
9  *  image processing framework.
10  *
11  *  gmic_qt is free software: you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation, either version 3 of the License, or
14  *  (at your option) any later version.
15  *
16  *  gmic_qt is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with gmic_qt.  If not, see <http://www.gnu.org/licenses/>.
23  *
24  */
25 
26 #include "OverrideCursor.h"
27 #include <QApplication>
28 #include <QDebug>
29 #include "Common.h"
30 
31 namespace GmicQt
32 {
33 bool OverrideCursor::_waiting = false;
34 bool OverrideCursor::_pointingHand = false;
35 
setWaiting(bool waiting)36 void OverrideCursor::setWaiting(bool waiting)
37 {
38   if (waiting == _waiting) {
39     return;
40   }
41   _waiting = waiting;
42   updateCurrentCursor();
43 }
44 
setPointingHand(bool pointingHand)45 void OverrideCursor::setPointingHand(bool pointingHand)
46 {
47   if (pointingHand == _pointingHand) {
48     return;
49   }
50   _pointingHand = pointingHand;
51   updateCurrentCursor();
52 }
53 
updateCurrentCursor()54 void OverrideCursor::updateCurrentCursor()
55 {
56   while (QApplication::overrideCursor()) {
57     QApplication::restoreOverrideCursor();
58   }
59   if (_pointingHand) {
60     QApplication::setOverrideCursor(Qt::PointingHandCursor);
61   } else if (_waiting) {
62     QApplication::setOverrideCursor(Qt::WaitCursor);
63   }
64 }
65 
currentCursorIsWaiting()66 bool OverrideCursor::currentCursorIsWaiting()
67 {
68   return QApplication::overrideCursor() && QApplication::overrideCursor()->shape() == Qt::WaitCursor;
69 }
70 
currentCursorIsPointingHand()71 bool OverrideCursor::currentCursorIsPointingHand()
72 {
73   return QApplication::overrideCursor() && QApplication::overrideCursor()->shape() == Qt::PointingHandCursor;
74 }
75 
76 } // namespace GmicQt
77