-
Notifications
You must be signed in to change notification settings - Fork 3
/
pushbutton.cpp
48 lines (45 loc) · 1.3 KB
/
pushbutton.cpp
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
#include "pushbutton.h"
// button & first are pointers to the parent's variables. These are used to
// convey information that the parent needs. "button" for which mouse button
// was pressed, and "first" for whether this was the first operation in
// a "click and drag" operation or not.
PushButton::PushButton(int *b, bool *f, QWidget *parent) : button(b), first(f), QPushButton(parent) {
setAcceptDrops(true);
setStyleSheet("background-color: rgb(215, 215, 215)");
setMinimumSize(SIZE, SIZE);
setMaximumSize(SIZE, SIZE);
processed = false;
}
void PushButton::mousePressEvent(QMouseEvent *e) {
if (e->button() != Qt::LeftButton && e->button() != Qt::RightButton) {
return;
}
*(button) = e->button();
*(first) = true;
processed = true;
if (e->button() == Qt::LeftButton) {
emit solid();
}
else {
emit dot();
}
// Qt will clean up the QDrag and associated QMimeData objects, so they mustn't be deleted.
QDrag *drag = new QDrag(this);
QMimeData *md = new QMimeData();
drag->setMimeData(md);
drag->exec(Qt::IgnoreAction);
// After a drag action the released signal isn't auto-emitted, but we need it.
emit released();
}
void PushButton::dragEnterEvent(QDragEnterEvent *e) {
if (processed) {
processed = false;
return;
}
if (*(button) == Qt::LeftButton) {
emit solid();
}
else {
emit dot();
}
}