Rev 19153 | Rev 19168 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
19153 | craig | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
7 | |||
8 | #include <QDebug> |
||
9 | #include <QDropEvent> |
||
10 | #include <QFileInfo> |
||
11 | #include <QKeyEvent> |
||
12 | #include <QMimeData> |
||
13 | |||
14 | #include "filedialogeventcatcher.h" |
||
15 | |||
16 | FileDialogEventCatcher::FileDialogEventCatcher(QObject* parent) |
||
17 | : QObject(parent) |
||
18 | { |
||
19 | } |
||
20 | |||
21 | bool FileDialogEventCatcher::eventFilter(QObject *o, QEvent *e) |
||
22 | { |
||
23 | if (e->type() == QEvent::KeyPress) |
||
24 | { |
||
25 | QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e); |
||
26 | if (keyEvent->key() == Qt::Key_Escape) |
||
27 | { |
||
28 | emit escapePressed(); |
||
29 | return true; |
||
30 | } |
||
31 | } |
||
32 | else |
||
33 | if (e->type() == QEvent::DragEnter) |
||
34 | { |
||
35 | e->accept(); |
||
36 | return true; |
||
37 | } |
||
38 | else |
||
39 | if (e->type() == QEvent::Drop) |
||
40 | { |
||
41 | QDropEvent *dropEvent = static_cast<QDropEvent *>(e); |
||
42 | if (dropEvent) |
||
43 | { |
||
44 | if ( dropEvent->mimeData()->hasFormat("text/uri-list")) |
||
45 | { |
||
46 | QString fileUrl; |
||
47 | QList<QUrl> fileUrls = dropEvent->mimeData()->urls(); |
||
48 | if (fileUrls.count()>0) |
||
49 | { |
||
50 | fileUrl = fileUrls[0].toLocalFile(); |
||
51 | if (fileUrls[0].isLocalFile()) |
||
52 | { |
||
53 | QFileInfo fi(fileUrl); |
||
19154 | jghali | 54 | if (fi.isDir()) |
55 | emit dropLocation(fi.absoluteFilePath()); |
||
56 | else |
||
57 | emit dropLocation(fi.absolutePath()); |
||
19153 | craig | 58 | } |
59 | } |
||
60 | } |
||
61 | } |
||
62 | e->accept(); |
||
63 | return true; |
||
64 | } |
||
65 | return QObject::eventFilter(o, e); |
||
66 | } |