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 bool OverrideCursor::_waiting = false;
32 bool OverrideCursor::_pointingHand = false;
33 
setWaiting(bool waiting)34 void OverrideCursor::setWaiting(bool waiting)
35 {
36   if (waiting == _waiting) {
37     return;
38   }
39   _waiting = waiting;
40   updateCurrentCursor();
41 }
42 
setPointingHand(bool pointingHand)43 void OverrideCursor::setPointingHand(bool pointingHand)
44 {
45   if (pointingHand == _pointingHand) {
46     return;
47   }
48   _pointingHand = pointingHand;
49   updateCurrentCursor();
50 }
51 
updateCurrentCursor()52 void OverrideCursor::updateCurrentCursor()
53 {
54   while (QApplication::overrideCursor()) {
55     QApplication::restoreOverrideCursor();
56   }
57   if (_pointingHand) {
58     QApplication::setOverrideCursor(Qt::PointingHandCursor);
59   } else if (_waiting) {
60     QApplication::setOverrideCursor(Qt::WaitCursor);
61   }
62 }
63 
currentCursorIsWaiting()64 bool OverrideCursor::currentCursorIsWaiting()
65 {
66   return QApplication::overrideCursor() && QApplication::overrideCursor()->shape() == Qt::WaitCursor;
67 }
68 
currentCursorIsPointingHand()69 bool OverrideCursor::currentCursorIsPointingHand()
70 {
71   return QApplication::overrideCursor() && QApplication::overrideCursor()->shape() == Qt::PointingHandCursor;
72 }
73