Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_cursor_cache.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Michael Abrahams <miabraha@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include "kis_cursor_cache.h"
8
9#include <QScreen>
10#include <QWindow>
11#include <QBitmap>
12#include <qmath.h>
13#include <QDebug>
14#include <QPainter>
15#include <QApplication>
16
17#include "KoResourcePaths.h"
18
20
21namespace {
22
23 QCursor loadImpl(const QString &cursorName, int hotspotX, int hotspotY) {
24 QPixmap cursorImage = QPixmap(":/" + cursorName);
25 if (cursorImage.isNull()) {
26 qWarning() << "Could not load cursor from qrc, trying filesystem" << cursorName;
27 cursorImage = QPixmap(KoResourcePaths::findAsset("kis_pics", cursorName));
28 if (cursorImage.isNull()) {
29 qWarning() << "Could not load cursor from filesystem" << cursorName;
30 return Qt::ArrowCursor;
31 }
32 }
33
34 return QCursor(cursorImage, hotspotX, hotspotY);
35 }
36
37}
38
40
42{
43 return s_instance;
44}
45
46QCursor KisCursorCache::load(const QString & cursorName, int hotspotX, int hotspotY)
47{
48 if (cursorHash.contains(cursorName)) {
49 return cursorHash[ cursorName ].second;
50 }
51
52 // Otherwise, construct the cursor
53 QCursor newCursor = loadImpl(cursorName, hotspotX, hotspotY);
54 cursorHash.insert(cursorName, QPair<QPoint, QCursor>(QPoint(hotspotX, hotspotY), newCursor));
55 return newCursor;
56}
Q_GLOBAL_STATIC(KisStoragePluginRegistry, s_instance)
static KisCursorCache * instance()
QHash< QString, QPair< QPoint, QCursor > > cursorHash
QCursor load(const QString &cursorName, int hotspotX, int hotspotY)
static QString findAsset(const QString &type, const QString &fileName)