use kDebug
[kdegraphics.git] / kolourpaint / generic / kpSetOverrideCursorSaver.h
blobcdc0d018a0a4c6cb476fc4b6b36ccf970981f241
2 /*
3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef kpSetOverrideCursorSaver_H
30 #define kpSetOverrideCursorSaver_H
33 class QCursor;
37 // A less error-prone way of setting the override cursor, compared to
38 // the QApplication::{set,restore}OverrideCursor() pair.
40 // To use this class, allocate it on the stack with the desired cursor.
42 // This class sets the application's override cursor to <cursor> on
43 // construction. It restores the cursor on destruction.
45 // Example Usage 1 - Cursor active during the entire method:
47 // void method ()
48 // {
49 // kpSetOverrideCursorSaver cursorSaver (Qt::WaitCursor);
51 // <potentially time-consuming operation>
53 // } // Stack unwinds, calling cursorSaver's destructor,
54 // // which restores the cursor
56 // Example Usage 2 - Cursor active during part of the method:
58 // void method ()
59 // {
60 // <some code>
62 // {
63 // kpSetOverrideCursorSaver cursorSaver (Qt::WaitCursor);
65 // <potentially time-consuming operation>
67 // } // Stack unwinds, calling cursorSaver's destructor,
68 // // which restores the cursor
70 // // (cursor is restored before this code executes)
71 // <more code>
72 // }
74 // Note that the kpSetOverrideCursorSaver must be defined as a local
75 // variable inside -- not outside --- the braces containing the code the
76 // cursor can be active over, else the destruction and cursor restoration
77 // might not occur at the right time. In other words, the following usage
78 // is wrong:
80 // INCORRECT Example Usage 2:
82 // void method ()
83 // {
84 // <some code>
86 // kpSetOverrideCursorSaver cursorSaver (Qt::WaitCursor);
87 // // BUG: These braces do nothing to limit the effect of cursorSaver.
88 // {
89 // <potentially time-consuming operation>
90 // }
92 // // BUG: cursorSaver has not yet restored the cursor before this
93 // // code executes.
94 // <more code>
96 // } // Stack unwinds, calling cursorSaver's destructor,
97 // // which restores the cursor
99 class kpSetOverrideCursorSaver
101 public:
102 kpSetOverrideCursorSaver (const QCursor &cursor);
103 ~kpSetOverrideCursorSaver ();
107 #endif // kpSetOverrideCursorSaver_H