1 | /* |
2 | SPDX-License-Identifier: LGPL-2.0-or-later |
3 | SPDX-FileCopyrightText: 2003 Marc Mutz <mutz@kde.org> |
4 | SPDX-FileCopyrightText: 2020 Laurent Montel <montel@kde.org> |
5 | */ |
6 | |
7 | #include "kcursorsaver.h" |
8 | #include "kguiaddons_debug.h" |
9 | #include <QGuiApplication> |
10 | |
11 | class KCursorSaverPrivate |
12 | { |
13 | public: |
14 | bool ownsCursor = true; |
15 | }; |
16 | |
17 | KCursorSaver::KCursorSaver(Qt::CursorShape shape) |
18 | : d(new KCursorSaverPrivate) |
19 | { |
20 | QGuiApplication::setOverrideCursor(QCursor(shape)); |
21 | d->ownsCursor = true; |
22 | } |
23 | |
24 | KCursorSaver::KCursorSaver(KCursorSaver &&other) |
25 | : d(other.d) |
26 | { |
27 | *this = std::move(other); |
28 | } |
29 | |
30 | KCursorSaver::~KCursorSaver() |
31 | { |
32 | if (d->ownsCursor) { |
33 | QGuiApplication::restoreOverrideCursor(); |
34 | delete d; |
35 | } |
36 | } |
37 | |
38 | void KCursorSaver::restoreCursor() |
39 | { |
40 | if (!d->ownsCursor) { |
41 | qCWarning(KGUIADDONS_LOG) << "This KCursorSaver doesn't own the cursor anymore, invalid call to restoreCursor()." ; |
42 | return; |
43 | } |
44 | d->ownsCursor = false; |
45 | QGuiApplication::restoreOverrideCursor(); |
46 | } |
47 | |
48 | KCursorSaver &KCursorSaver::operator=(KCursorSaver &&other) |
49 | { |
50 | if (this != &other) { |
51 | d->ownsCursor = false; |
52 | } |
53 | return *this; |
54 | } |
55 | |