annotate examples/draganddrop/dropsite/dropsitewindow.d @ 21:e747af2e6b46

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