annotate examples/draganddrop/dropsite/dropsitewindow.d @ 206:aeeaae4dd540

'Dropsite' fixes for d2.
author SokoL_SD
date Tue, 14 Jul 2009 09:13:27 +0000
parents 6aeaf24018d7
children 7ea67ec3cf29
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 dropsitewindow;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
43
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 69
diff changeset
44 version(Tango) {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 69
diff changeset
45 import tango.text.Util;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 69
diff changeset
46 import tango.text.Ascii;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 69
diff changeset
47 import tango.text.convert.Format: format = Format;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 69
diff changeset
48 } else {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 69
diff changeset
49 import std.string;
206
aeeaae4dd540 'Dropsite' fixes for d2.
SokoL_SD
parents: 204
diff changeset
50 alias strip trim;
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 69
diff changeset
51 }
19
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
52
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
53 import qt.gui.QWidget;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
54 import qt.gui.QLabel;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
55 import qt.gui.QTableWidget;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
56 import qt.gui.QPushButton;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
57 import qt.gui.QVBoxLayout;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
58 import qt.gui.QDialogButtonBox;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
59
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
60 import droparea;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
61
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
62
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
63 class DropSiteWindow : public QWidget
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
64 {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
65 public:
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
66
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
67 this()
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
68 {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
69 abstractLabel = new QLabel(tr("This example accepts drags from other "
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
70 "applications and displays the MIME types "
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
71 "provided by the drag object."));
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
72
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
73 abstractLabel.setWordWrap(true);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
74 abstractLabel.adjustSize();
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
75
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
76 dropArea = new DropArea;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
77 dropArea.changed.connect(&updateFormatsTable);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
78
206
aeeaae4dd540 'Dropsite' fixes for d2.
SokoL_SD
parents: 204
diff changeset
79 string[] labels;
19
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
80 labels ~= tr("Format");
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
81 labels ~= tr("Content");
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
82
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
83 formatsTable = new QTableWidget;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
84 formatsTable.setColumnCount(2);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
85 formatsTable.setEditTriggers(QAbstractItemView.NoEditTriggers);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
86 formatsTable.setHorizontalHeaderLabels(labels);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
87 formatsTable.horizontalHeader().setStretchLastSection(true);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
88
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
89 clearButton = new QPushButton(tr("Clear"));
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
90 quitButton = new QPushButton(tr("Quit"));
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
91
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
92 buttonBox = new QDialogButtonBox;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
93 buttonBox.addButton(clearButton, QDialogButtonBox.ActionRole);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
94 buttonBox.addButton(quitButton, QDialogButtonBox.RejectRole);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
95
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
96 quitButton.pressed.connect(&close);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
97 clearButton.pressed.connect(&dropArea.clearArea);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
98
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
99 QVBoxLayout mainLayout = new QVBoxLayout;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
100 mainLayout.addWidget(abstractLabel);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
101 mainLayout.addWidget(dropArea);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
102 mainLayout.addWidget(formatsTable);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
103 mainLayout.addWidget(buttonBox);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
104 setLayout(mainLayout);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
105
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
106 setWindowTitle(tr("Drop Site"));
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
107 setMinimumSize(350, 500);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
108 }
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
109
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
110 void updateFormatsTable(QMimeData mimeData)
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
111 {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
112 formatsTable.setRowCount(0);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
113 if (!mimeData)
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
114 return;
21
e747af2e6b46 temporary(?) fix for dropsite example
eldar
parents: 19
diff changeset
115
206
aeeaae4dd540 'Dropsite' fixes for d2.
SokoL_SD
parents: 204
diff changeset
116 foreach (string format; mimeData.formats()) {
19
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
117 QTableWidgetItem formatItem = new QTableWidgetItem(format);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
118 formatItem.setFlags(Qt.ItemIsEnabled);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
119 formatItem.setTextAlignment(Qt.AlignTop | Qt.AlignLeft);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
120
206
aeeaae4dd540 'Dropsite' fixes for d2.
SokoL_SD
parents: 204
diff changeset
121 string text;
19
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
122 if (format == "text/plain") {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
123 text = trim(mimeData.text());
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
124 } else if (format == "text/html") {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
125 text = trim(mimeData.html());
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
126 } else if (format == "text/uri-list") {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
127 QUrl[] urlList = mimeData.urls();
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
128 for (int i = 0; i < urlList.length && i < 32; ++i) {
206
aeeaae4dd540 'Dropsite' fixes for d2.
SokoL_SD
parents: 204
diff changeset
129 string url = urlList[i].path();
19
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
130 text ~= url ~ " ";
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
131 }
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
132 } else {
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
133 QByteArray data = mimeData.data(format);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
134 for (int i = 0; i < data.size() && i < 32; ++i) {
206
aeeaae4dd540 'Dropsite' fixes for d2.
SokoL_SD
parents: 204
diff changeset
135 version(Tango)
aeeaae4dd540 'Dropsite' fixes for d2.
SokoL_SD
parents: 204
diff changeset
136 string hex = toUupper(Format("{0:x}", data.at(i)));
aeeaae4dd540 'Dropsite' fixes for d2.
SokoL_SD
parents: 204
diff changeset
137 else
aeeaae4dd540 'Dropsite' fixes for d2.
SokoL_SD
parents: 204
diff changeset
138 string hex = toupper(std.string.format("%x", data.at(i)));
19
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
139 text ~= hex ~ " ";
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
140 }
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
141 }
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
142
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
143 int row = formatsTable.rowCount();
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
144 formatsTable.insertRow(row);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
145 formatsTable.setItem(row, 0, new QTableWidgetItem(format));
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
146 formatsTable.setItem(row, 1, new QTableWidgetItem(text));
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
147 }
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
148
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
149 formatsTable.resizeColumnToContents(0);
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
150 }
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
151
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
152 private:
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
153
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
154 DropArea dropArea;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
155 QLabel abstractLabel;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
156 QTableWidget formatsTable;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
157
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
158 QPushButton clearButton;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
159 QPushButton quitButton;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
160 QDialogButtonBox buttonBox;
d54443f1ce1e add dropsite example
mandel
parents:
diff changeset
161 }