File indexing completed on 2024-04-14 03:52:05

0001 /*
0002     SPDX-License-Identifier: LGPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2003 Marc Mutz <mutz@kde.org>
0004     SPDX-FileCopyrightText: 2020 Laurent Montel <montel@kde.org>
0005 */
0006 
0007 #ifndef KCURSORSAVER_H
0008 #define KCURSORSAVER_H
0009 #include <kguiaddons_export.h>
0010 
0011 #include <QCursor>
0012 
0013 class KCursorSaverPrivate;
0014 
0015 /**
0016  * @class KCursorSaver kcursorsaver.h KCursorSaver
0017  *
0018  * @short Class to temporarily set a mouse cursor and restore the previous one on destruction
0019  *
0020  * Create a KCursorSaver object when you want to set the cursor.
0021  * As soon as it gets out of scope, it will restore the original
0022  * cursor.
0023  * @code
0024     KCursorSaver saver(Qt::WaitCursor);
0025     ... long-running operation here ...
0026    @endcode
0027  * @since 5.73
0028  */
0029 class KGUIADDONS_EXPORT KCursorSaver
0030 {
0031 public:
0032     /// Creates a KCursorSaver, setting the mouse cursor to @p shape.
0033     explicit KCursorSaver(Qt::CursorShape shape);
0034 
0035     /// Move-constructs a KCursorSaver from other
0036     KCursorSaver(KCursorSaver &&other);
0037 
0038     /// restore the cursor
0039     ~KCursorSaver();
0040 
0041     /// call this to explicitly restore the cursor
0042     void restoreCursor();
0043 
0044     KCursorSaver &operator=(KCursorSaver &&other);
0045 
0046 private:
0047     KCursorSaver(KCursorSaver &other) = delete;
0048     void operator=(const KCursorSaver &rhs) = delete;
0049     KCursorSaverPrivate *const d; ///< @internal
0050 };
0051 
0052 #endif