-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathListWidgetDropSignal.h
More file actions
44 lines (37 loc) · 1.04 KB
/
Copy pathListWidgetDropSignal.h
File metadata and controls
44 lines (37 loc) · 1.04 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
#ifndef LISTWIDGETDROPSIGNAL_H
#define LISTWIDGETDROPSIGNAL_H
#include <QDropEvent>
#include <QListWidget>
class ListWidgetDropSignal : public QListWidget
{
Q_OBJECT
public:
ListWidgetDropSignal(QWidget * parent) : QListWidget(parent), m_acceptDrop(true), m_acceptFromSource(this) {}
void SetAcceptDropFromOthers(bool accept) { m_acceptDrop = accept; }
void SetAcceptFromSource(QWidget* widget) { m_acceptFromSource = widget; }
signals:
void dropEventSignal(bool isSelf);
protected:
void dragMoveEvent(QDragMoveEvent *e)
{
if (e->source() == this || (m_acceptDrop && e->source() == m_acceptFromSource))
{
QListWidget::dragMoveEvent(e);
e->accept();
}
else
{
e->ignore();
}
}
void dropEvent(QDropEvent *event)
{
QListWidget::dropEvent(event);
event->accept();
emit dropEventSignal(event->source() == this);
}
private:
bool m_acceptDrop;
QWidget* m_acceptFromSource;
};
#endif // LISTWIDGETDROPSIGNAL_H