-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomcursor.cpp
More file actions
74 lines (60 loc) · 1.92 KB
/
Copy pathcustomcursor.cpp
File metadata and controls
74 lines (60 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "customcursor.h"
CustomCursor::CustomCursor(QObject *parent)
: QObject{parent}, m_customCursor(nullptr)
{
}
CustomCursor::~CustomCursor()
{
delete m_customCursor;
}
bool CustomCursor::setupCustomCursor(const QUrl &imageUrl, int width, int height, int hotX, int hotY)
{
if(imageUrl.scheme() == "file")
{
m_cursorImage.load(imageUrl.toLocalFile());
if(!m_cursorImage.isNull())
{
//check for image size if its too large show error dont proceed
if(m_cursorImage.height()>64 || m_cursorImage.width()>64)
{
qWarning()<< "selected image is too large to set for custom cursor!";
return false;
}
//make sure no memory leak from previous call this function
if(m_customCursor!=nullptr)
delete m_customCursor;
cursorPixmap = QPixmap::fromImage(m_cursorImage);
m_customCursor = new QCursor(cursorPixmap, hotX, hotY);
return true;
}
else
qWarning() << "failed to load image for custom cursor:" << imageUrl.toLocalFile();
}
else
qWarning() << "unsupported url scheme for custom cursor image, only local files are supported:";
return false;
}
bool CustomCursor::setCursor(int cursor)
{
if(cursor>=0 && cursor <= 24) //cursor valuse from enum Qt::CursorShape
{
m_currentCursor = QCursor(static_cast<Qt::CursorShape>(cursor));
QGuiApplication::setOverrideCursor(m_currentCursor);
return true;
}
//invalid cursor
qWarning() << "invalid cursor id to set.";
return false;
}
void CustomCursor::loadCustom()
{
QGuiApplication::setOverrideCursor(*m_customCursor);
}
bool CustomCursor::isCustomSet() const
{
return (m_customCursor!=nullptr)? true : false;
}
void CustomCursor::restoreDefaultCursor()
{
QGuiApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
}