summaryrefslogtreecommitdiffstats
path: root/akregator/src/kcursorsaver.h
diff options
context:
space:
mode:
Diffstat (limited to 'akregator/src/kcursorsaver.h')
-rw-r--r--akregator/src/kcursorsaver.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/akregator/src/kcursorsaver.h b/akregator/src/kcursorsaver.h
new file mode 100644
index 00000000..c77a7377
--- /dev/null
+++ b/akregator/src/kcursorsaver.h
@@ -0,0 +1,67 @@
+// taken from kmail/, moved to Akregator namespace to avoid clashes
+
+#ifndef kcursorsaver_h
+#define kcursorsaver_h
+
+#include <qcursor.h>
+#include <qapplication.h>
+
+namespace Akregator {
+
+/**
+ * @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);
+ }
+}
+
+} // namespace Akregator
+
+#endif /*kbusyptr_h_*/