1 /** -*- mode: c++ ; c-basic-offset: 2 -*-
2  * @file   OverrideCursor.cpp
3  * @author Sebastien Fourey
4  * @date   June 2018
5  * @brief Definition of the methods of the class OverrideCursor.
6  *
7  * This file is part of the ZArt software's source code.
8  *
9  * Copyright Sebastien Fourey / GREYC Ensicaen (2010-...)
10  *
11  *                    https://foureys.users.greyc.fr/
12  *
13  * This software is a computer program whose purpose is to demonstrate
14  * the possibilities of the GMIC image processing language by offering the
15  * choice of several manipulations on a video stream acquired from a webcam. In
16  * other words, ZArt is a GUI for G'MIC real-time manipulations on the output
17  * of a webcam.
18  *
19  * This software is governed by the CeCILL  license under French law and
20  * abiding by the rules of distribution of free software.  You can  use,
21  * modify and/ or redistribute the software under the terms of the CeCILL
22  * license as circulated by CEA, CNRS and INRIA at the following URL
23  * "http://www.cecill.info". See also the directory "Licence" which comes
24  * with this source code for the full text of the CeCILL license.
25  *
26  * As a counterpart to the access to the source code and  rights to copy,
27  * modify and redistribute granted by the license, users are provided only
28  * with a limited warranty  and the software's author,  the holder of the
29  * economic rights,  and the successive licensors  have only  limited
30  * liability.
31  *
32  * In this respect, the user's attention is drawn to the risks associated
33  * with loading,  using,  modifying and/or developing or reproducing the
34  * software by the user in light of its specific status of free software,
35  * that may mean  that it is complicated to manipulate,  and  that  also
36  * therefore means  that it is reserved for developers  and  experienced
37  * professionals having in-depth computer knowledge. Users are therefore
38  * encouraged to load and test the software's suitability as regards their
39  * requirements in conditions enabling the security of their systems and/or
40  * data to be ensured and,  more generally, to use and operate it in the
41  * same conditions as regards security.
42  *
43  * The fact that you are presently reading this means that you have had
44  * knowledge of the CeCILL license and that you accept its terms.
45  *
46  */
47 #include "OverrideCursor.h"
48 #include <QApplication>
49 #include <QDebug>
50 #include "Common.h"
51 
52 bool OverrideCursor::_waiting = false;
53 bool OverrideCursor::_pointingHand = false;
54 
setWaiting(bool waiting)55 void OverrideCursor::setWaiting(bool waiting)
56 {
57   if (waiting == _waiting) {
58     return;
59   }
60   _waiting = waiting;
61   updateCurrentCursor();
62 }
63 
setPointingHand(bool pointingHand)64 void OverrideCursor::setPointingHand(bool pointingHand)
65 {
66   if (pointingHand == _pointingHand) {
67     return;
68   }
69   _pointingHand = pointingHand;
70   updateCurrentCursor();
71 }
72 
updateCurrentCursor()73 void OverrideCursor::updateCurrentCursor()
74 {
75   while (QApplication::overrideCursor()) {
76     QApplication::restoreOverrideCursor();
77   }
78   if (_pointingHand) {
79     QApplication::setOverrideCursor(Qt::PointingHandCursor);
80   } else if (_waiting) {
81     QApplication::setOverrideCursor(Qt::WaitCursor);
82   }
83 }
84 
currentCursorIsWaiting()85 bool OverrideCursor::currentCursorIsWaiting()
86 {
87   return QApplication::overrideCursor() && QApplication::overrideCursor()->shape() == Qt::WaitCursor;
88 }
89 
currentCursorIsPointingHand()90 bool OverrideCursor::currentCursorIsPointingHand()
91 {
92   return QApplication::overrideCursor() && QApplication::overrideCursor()->shape() == Qt::PointingHandCursor;
93 }
94