summaryrefslogtreecommitdiffstats
path: root/kmail/kcursorsaver.h
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /kmail/kcursorsaver.h
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kmail/kcursorsaver.h')
-rw-r--r--kmail/kcursorsaver.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/kmail/kcursorsaver.h b/kmail/kcursorsaver.h
new file mode 100644
index 000000000..930cab6f0
--- /dev/null
+++ b/kmail/kcursorsaver.h
@@ -0,0 +1,61 @@
+#ifndef kcursorsaver_h
+#define kcursorsaver_h
+
+#include <qcursor.h>
+#include <qapplication.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 Qt
+{
+public:
+ /// constructor taking QCursor shapes
+ KCursorSaver(Qt::CursorShape shape) {
+ QApplication::setOverrideCursor( QCursor(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)
+ QApplication::restoreOverrideCursor();
+ }
+
+ /// call this to explitly restore the cursor
+ inline void restoreCursor(void) {
+ QApplication::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(QCursor::ArrowCursor);
+ }
+ inline KCursorSaver busy() {
+ return KCursorSaver(QCursor::WaitCursor);
+ }
+}
+
+#endif /*kbusyptr_h_*/