Debian Codegraph @

src/Gui/WaitCursor.h

raw
1 /***************************************************************************
2 * Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23 #ifndef GUI_WAIT_CURSOR_H
24 #define GUI_WAIT_CURSOR_H
25
26 #include <FCGlobal.h>
27
28 namespace Gui
29 {
30
31 /**
32 * This class sets a waitcursor automatically while a slow operation is running.
33 * Therefore you just have to create an instance of WaitCursor before the time
34 * consuming operation starts.
35 *
36 * \code:
37 * WaitCursor ac;
38 * ...
39 * ... // slow operation
40 * ...
41 * \endcode
42 *
43 * Sometimes you have two slow operations with some user interactions in between them.
44 * Avoiding to show the waiting cursor then you have to call the methods @ref restoreCursor()
45 * and setWaitCursor manually, like:
46 *
47 * \code:
48 * WaitCursor ac;
49 * ...
50 * ... // 1st slow operation
51 * ac.restoreCursor();
52 * ...
53 * ... // some dialog stuff
54 * ac.setWaitCursor();
55 * ...
56 * ... // 2nd slow operation
57 * \endcode
58 *
59 * @author Werner Mayer
60 */
61 class GuiExport WaitCursor
62 {
63 public:
64 enum FilterEventsFlag
65 {
66 NoEvents = 0x00,
67 KeyEvents = 0x01,
68 MouseEvents = 0x02,
69 AllEvents = KeyEvents | MouseEvents
70 };
71 Q_DECLARE_FLAGS(FilterEventsFlags, FilterEventsFlag)
72
73 WaitCursor();
74 ~WaitCursor();
75
76 void setWaitCursor();
77 void restoreCursor();
78 FilterEventsFlags ignoreEvents() const;
79 void setIgnoreEvents(FilterEventsFlags flags = AllEvents);
80
81 /**
82 * @brief Suspends the wait cursor state by restoring the normal cursor
83 * and removing the event filter. To be used before showing an interactive
84 * dialog during a long operation.
85 */
86 static void suspend();
87
88 /**
89 * @brief Resumes the wait cursor state by setting the wait cursor
90 * and reinstalling the event filter, if a WaitCursor is active.
91 */
92 static void resume();
93
94 private:
95 FilterEventsFlags filter;
96 static int instances;
97 };
98
99 } // namespace Gui
100
101 #endif // GUI_WAIT_CURSOR_H