Warning, file /frameworks/kguiaddons/src/util/kcursorsaver.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 #include "kcursorsaver.h"
0008 #include "kguiaddons_debug.h"
0009 #include <QGuiApplication>
0010 
0011 class KCursorSaverPrivate
0012 {
0013 public:
0014     bool ownsCursor = true;
0015 };
0016 
0017 KCursorSaver::KCursorSaver(Qt::CursorShape shape)
0018     : d(new KCursorSaverPrivate)
0019 {
0020     QGuiApplication::setOverrideCursor(QCursor(shape));
0021     d->ownsCursor = true;
0022 }
0023 
0024 KCursorSaver::KCursorSaver(KCursorSaver &&other)
0025     : d(other.d)
0026 {
0027     *this = std::move(other);
0028 }
0029 
0030 KCursorSaver::~KCursorSaver()
0031 {
0032     if (d->ownsCursor) {
0033         QGuiApplication::restoreOverrideCursor();
0034         delete d;
0035     }
0036 }
0037 
0038 void KCursorSaver::restoreCursor()
0039 {
0040     if (!d->ownsCursor) {
0041         qCWarning(KGUIADDONS_LOG) << "This KCursorSaver doesn't own the cursor anymore, invalid call to restoreCursor().";
0042         return;
0043     }
0044     d->ownsCursor = false;
0045     QGuiApplication::restoreOverrideCursor();
0046 }
0047 
0048 KCursorSaver &KCursorSaver::operator=(KCursorSaver &&other)
0049 {
0050     if (this != &other) {
0051         d->ownsCursor = false;
0052     }
0053     return *this;
0054 }