annotate examples/draganddrop/dropsite/dropsitewindow.d @ 323:7a3c43424dca signals

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