summaryrefslogtreecommitdiffstats
path: root/kmail/kcursorsaver.h
blob: a4efe26de17afd188910510ae2bc55fa65cf3abf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef kcursorsaver_h
#define kcursorsaver_h

#include <tqcursor.h>
#include <tqapplication.h>

/**
 * @short sets a cursor and makes sure it's restored on destruction
 * Create a KCursorSaver object when you want to set the cursor.
 * As soon as it gets out of scope, it will restore the original
 * cursor.
 */
class KCursorSaver : public TQt
{
public:
    /// constructor taking TQCursor shapes
    KCursorSaver(TQt::CursorShape shape) {
        TQApplication::setOverrideCursor( TQCursor(shape) );
        inited = true;
    }

    /// copy constructor. The right side won't restore the cursor
    KCursorSaver( const KCursorSaver &rhs ) {
        *this = rhs;
    }

    /// restore the cursor
    ~KCursorSaver() {
        if (inited)
            TQApplication::restoreOverrideCursor();
    }

    /// call this to explitly restore the cursor
    inline void restoreCursor(void) {
        TQApplication::restoreOverrideCursor();
        inited = false;
    }

protected:
    void operator=( const KCursorSaver &rhs ) {
        inited = rhs.inited;
        rhs.inited = false;
    }

private:
    mutable bool inited;
};

/**
 * convenience functions
 */
namespace KBusyPtr {
    inline KCursorSaver idle() {
        return KCursorSaver(TQCursor::ArrowCursor);
    }
    inline KCursorSaver busy() {
        return KCursorSaver(TQCursor::WaitCursor);
    }
}

#endif /*kbusyptr_h_*/