-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaritem.cpp
More file actions
52 lines (44 loc) · 1.12 KB
/
baritem.cpp
File metadata and controls
52 lines (44 loc) · 1.12 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
#include "baritem.h"
#include <QMouseEvent>
/**
* Author: Yunus Rahbar
* Date: 6/10/13
*
*/
/**
* BarItem
*
* An abstract class for items in the sidebar, which can be dragged into the gameView.
*/
BarItem::BarItem(QString imageName, QWidget *parent) :
QLabel(parent), movingLabel(new QLabel(parent)), delta(QPoint(0,0)), imgPath(imageName)
{
offset = QPoint(0,30);
image = QPixmap(imageName).scaledToWidth(sideLength,Qt::SmoothTransformation);
setPixmap(image);
resize(image.size());
movingLabel->setPixmap(image);
movingLabel->resize(image.size());
movingLabel->hide();
}
BarItem::~BarItem()
{
//delete image;
delete movingLabel;
}
void BarItem::mouseMoveEvent(QMouseEvent *ev)
{
movingLabel->move(ev->globalPos() + delta + offset);
}
void BarItem::mousePressEvent(QMouseEvent *ev)
{
delta = this->pos() - ev->globalPos();
movingLabel->move(this->pos() + offset);
movingLabel->show();
}
void BarItem::mouseReleaseEvent(QMouseEvent *ev)
{
movingLabel->hide();
//move(movingLabel->pos());
dropAction(ev->globalPos()+delta-QPoint(0,this->pos().y()));
}