annotate examples/draganddrop/dropsite/droparea.d @ 19:d54443f1ce1e

add dropsite example
author mandel
date Thu, 14 May 2009 18:20:24 +0000
parents
children e747af2e6b46
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
1 /****************************************************************************
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
2 **
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
4 ** Contact: Qt Software Information (qt-info@nokia.com)
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
5 **
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
6 ** This file is part of the examples of the Qt Toolkit.
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
7 **
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
8 ** $QT_BEGIN_LICENSE:LGPL$
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
9 ** Commercial Usage
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
10 ** Licensees holding valid Qt Commercial licenses may use this file in
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
11 ** accordance with the Qt Commercial License Agreement provided with the
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
12 ** Software or, alternatively, in accordance with the terms contained in
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
13 ** a written agreement between you and Nokia.
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
14 **
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
15 ** GNU Lesser General Public License Usage
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
16 ** Alternatively, this file may be used under the terms of the GNU Lesser
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
17 ** General Public License version 2.1 as published by the Free Software
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
18 ** Foundation and appearing in the file LICENSE.LGPL included in the
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
19 ** packaging of this file. Please review the following information to
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
20 ** ensure the GNU Lesser General Public License version 2.1 requirements
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
22 **
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
23 ** In addition, as a special exception, Nokia gives you certain
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
24 ** additional rights. These rights are described in the Nokia Qt LGPL
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
26 ** package.
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
27 **
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
28 ** GNU General Public License Usage
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
29 ** Alternatively, this file may be used under the terms of the GNU
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
30 ** General Public License version 3.0 as published by the Free Software
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
31 ** Foundation and appearing in the file LICENSE.GPL included in the
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
32 ** packaging of this file. Please review the following information to
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
33 ** ensure the GNU General Public License version 3.0 requirements will be
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
34 ** met: http://www.gnu.org/copyleft/gpl.html.
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
35 **
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
36 ** If you are unsure which license is appropriate for your use, please
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
37 ** contact the sales department at qt-sales@nokia.com.
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
38 ** $QT_END_LICENSE$
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
39 **
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
40 ****************************************************************************/
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
41
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
42 module droparea;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
43
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
44 import qt.gui.QLabel;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
45
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
46 import tango.io.Stdout;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
47
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
48
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
49 class DropArea : public QLabel
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
50 {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
51 public:
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
52 this(QWidget parent = null)
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
53 {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
54 super(parent);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
55
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
56 setMinimumSize(200, 200);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
57 setFrameStyle(QFrame.Sunken | QFrame.StyledPanel);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
58 setAlignment(Qt.AlignCenter);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
59 setAcceptDrops(true);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
60 setAutoFillBackground(true);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
61 clearArea();
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
62 }
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
63
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
64 void clearArea()
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
65 {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
66 setText(tr("<drop content>"));
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
67 setBackgroundRole(QPalette.Dark);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
68
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
69 changed.emit(null);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
70 }
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
71
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
72 mixin Signal!("changed", QMimeData);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
73
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
74 protected:
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
75
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
76 void dragEnterEvent(QDragEnterEvent event)
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
77 {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
78 setText(tr("<drop content>"));
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
79 setBackgroundRole(QPalette.Highlight);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
80
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
81 event.acceptProposedAction();
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
82 changed.emit(event.mimeData);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
83 }
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
84
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
85 void dragMoveEvent(QDragMoveEvent event)
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
86 {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
87 event.acceptProposedAction();
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
88 }
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
89
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
90 void dragLeaveEvent(QDragLeaveEvent event)
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
91 {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
92 clearArea();
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
93 event.accept();
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
94 }
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
95
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
96 void dropEvent(QDropEvent event)
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
97 {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
98 QMimeData mimeData = event.mimeData();
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
99
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
100 if (mimeData.hasImage()) {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
101 //TODO setPixmap(qvariant_cast<QPixmap>(mimeData.imageData());
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
102 } else if (mimeData.hasHtml()) {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
103 setText(mimeData.html());
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
104 setTextFormat(Qt.RichText);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
105 } else if (mimeData.hasText()) {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
106 setText(mimeData.text());
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
107 setTextFormat(Qt.PlainText);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
108 } else if (mimeData.hasUrls()) {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
109 QUrl[] urlList = mimeData.urls();
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
110 char[] text;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
111 for (int i = 0; i < urlList.length && i < 32; ++i) {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
112 text ~= urlList[i].path() ~ "\n";
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
113 }
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
114 setText(text);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
115 } else {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
116 setText(tr("Cannot display data"));
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
117 }
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
118
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
119 setBackgroundRole(QPalette.Dark);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
120 event.acceptProposedAction();
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
121 }
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
122
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
123 private:
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
124 QLabel label;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
125 }
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
126