-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathinteractiveimageitem.cc
More file actions
63 lines (51 loc) · 1.43 KB
/
interactiveimageitem.cc
File metadata and controls
63 lines (51 loc) · 1.43 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
#include "interactiveimageitem.hpp"
#include <QDebug>
#include <QEvent>
class InteractiveImageItem::InteractiveImageItemPrivate
{
public:
explicit InteractiveImageItemPrivate(InteractiveImageItem *q)
: q_ptr(q)
{}
InteractiveImageItem *q_ptr;
QPixmap sourcePixmap;
};
InteractiveImageItem::InteractiveImageItem(QGraphicsItem *parent)
: QGraphicsPixmapItem(parent)
, d_ptr(new InteractiveImageItemPrivate(this))
{
setAcceptHoverEvents(true);
}
InteractiveImageItem::~InteractiveImageItem() {}
void InteractiveImageItem::setSourcePixmap(const QPixmap &pixmap)
{
d_ptr->sourcePixmap = pixmap;
setPixmap(pixmap);
}
QPixmap InteractiveImageItem::sourcePixmap() const
{
return d_ptr->sourcePixmap;
}
void InteractiveImageItem::setSize(const QSize &size)
{
if (!d_ptr->sourcePixmap.isNull()) {
setPixmap(d_ptr->sourcePixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
}
QSize InteractiveImageItem::size() const
{
return pixmap().size();
}
bool InteractiveImageItem::sceneEvent(QEvent *event)
{
switch (event->type()) {
case QEvent::GraphicsSceneMousePress:
event->accept();
emit itemClicked();
return true;
case QEvent::GraphicsSceneHoverEnter: emit mouseEntered(); return true;
case QEvent::GraphicsSceneHoverLeave: emit mouseLeft(); return true;
default: break;
}
return QGraphicsPixmapItem::sceneEvent(event);
}