Mercurial > projects > qtd
annotate examples/draganddrop/dropsite/dropsitewindow.d @ 282:256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
author | eldar |
---|---|
date | Fri, 16 Oct 2009 02:43:59 +0000 |
parents | 8aaa84d48451 |
children | 7a3c43424dca |
rev | line source |
---|---|
19 | 1 /**************************************************************************** |
2 ** | |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | |
4 ** Contact: Qt Software Information (qt-info@nokia.com) | |
5 ** | |
6 ** This file is part of the examples of the Qt Toolkit. | |
7 ** | |
8 ** $QT_BEGIN_LICENSE:LGPL$ | |
9 ** Commercial Usage | |
10 ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 ** accordance with the Qt Commercial License Agreement provided with the | |
12 ** Software or, alternatively, in accordance with the terms contained in | |
13 ** a written agreement between you and Nokia. | |
14 ** | |
15 ** GNU Lesser General Public License Usage | |
16 ** Alternatively, this file may be used under the terms of the GNU Lesser | |
17 ** General Public License version 2.1 as published by the Free Software | |
18 ** Foundation and appearing in the file LICENSE.LGPL included in the | |
19 ** packaging of this file. Please review the following information to | |
20 ** ensure the GNU Lesser General Public License version 2.1 requirements | |
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
22 ** | |
23 ** In addition, as a special exception, Nokia gives you certain | |
24 ** additional rights. These rights are described in the Nokia Qt LGPL | |
25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this | |
26 ** package. | |
27 ** | |
28 ** GNU General Public License Usage | |
29 ** Alternatively, this file may be used under the terms of the GNU | |
30 ** General Public License version 3.0 as published by the Free Software | |
31 ** Foundation and appearing in the file LICENSE.GPL included in the | |
32 ** packaging of this file. Please review the following information to | |
33 ** ensure the GNU General Public License version 3.0 requirements will be | |
34 ** met: http://www.gnu.org/copyleft/gpl.html. | |
35 ** | |
36 ** If you are unsure which license is appropriate for your use, please | |
37 ** contact the sales department at qt-sales@nokia.com. | |
38 ** $QT_END_LICENSE$ | |
39 ** | |
40 ****************************************************************************/ | |
41 | |
42 module dropsitewindow; | |
43 | |
215 | 44 import std.string; |
19 | 45 |
46 import qt.gui.QWidget; | |
47 import qt.gui.QLabel; | |
48 import qt.gui.QTableWidget; | |
49 import qt.gui.QPushButton; | |
50 import qt.gui.QVBoxLayout; | |
51 import qt.gui.QDialogButtonBox; | |
52 | |
53 import droparea; | |
54 | |
55 | |
56 class DropSiteWindow : public QWidget | |
57 { | |
58 public: | |
59 | |
60 this() | |
61 { | |
62 abstractLabel = new QLabel(tr("This example accepts drags from other " | |
63 "applications and displays the MIME types " | |
64 "provided by the drag object.")); | |
65 | |
66 abstractLabel.setWordWrap(true); | |
67 abstractLabel.adjustSize(); | |
68 | |
69 dropArea = new DropArea; | |
282
256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents:
215
diff
changeset
|
70 connect!("changed")(dropArea, &updateFormatsTable); |
19 | 71 |
206 | 72 string[] labels; |
19 | 73 labels ~= tr("Format"); |
74 labels ~= tr("Content"); | |
75 | |
76 formatsTable = new QTableWidget; | |
77 formatsTable.setColumnCount(2); | |
78 formatsTable.setEditTriggers(QAbstractItemView.NoEditTriggers); | |
79 formatsTable.setHorizontalHeaderLabels(labels); | |
80 formatsTable.horizontalHeader().setStretchLastSection(true); | |
81 | |
82 clearButton = new QPushButton(tr("Clear")); | |
83 quitButton = new QPushButton(tr("Quit")); | |
84 | |
85 buttonBox = new QDialogButtonBox; | |
86 buttonBox.addButton(clearButton, QDialogButtonBox.ActionRole); | |
87 buttonBox.addButton(quitButton, QDialogButtonBox.RejectRole); | |
88 | |
282
256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents:
215
diff
changeset
|
89 connect!("pressed")(quitButton, &close); |
256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents:
215
diff
changeset
|
90 connect!("pressed")(clearButton, &dropArea.clearArea); |
19 | 91 |
92 QVBoxLayout mainLayout = new QVBoxLayout; | |
93 mainLayout.addWidget(abstractLabel); | |
94 mainLayout.addWidget(dropArea); | |
95 mainLayout.addWidget(formatsTable); | |
96 mainLayout.addWidget(buttonBox); | |
97 setLayout(mainLayout); | |
98 | |
99 setWindowTitle(tr("Drop Site")); | |
100 setMinimumSize(350, 500); | |
101 } | |
102 | |
103 void updateFormatsTable(QMimeData mimeData) | |
104 { | |
105 formatsTable.setRowCount(0); | |
106 if (!mimeData) | |
107 return; | |
21 | 108 |
206 | 109 foreach (string format; mimeData.formats()) { |
19 | 110 QTableWidgetItem formatItem = new QTableWidgetItem(format); |
111 formatItem.setFlags(Qt.ItemIsEnabled); | |
112 formatItem.setTextAlignment(Qt.AlignTop | Qt.AlignLeft); | |
113 | |
206 | 114 string text; |
19 | 115 if (format == "text/plain") { |
215 | 116 text = strip(mimeData.text()); |
19 | 117 } else if (format == "text/html") { |
215 | 118 text = strip(mimeData.html()); |
19 | 119 } else if (format == "text/uri-list") { |
120 QUrl[] urlList = mimeData.urls(); | |
121 for (int i = 0; i < urlList.length && i < 32; ++i) { | |
206 | 122 string url = urlList[i].path(); |
19 | 123 text ~= url ~ " "; |
124 } | |
125 } else { | |
126 QByteArray data = mimeData.data(format); | |
127 for (int i = 0; i < data.size() && i < 32; ++i) { | |
215 | 128 string hex = toupper(std.string.format("%x", data.at(i))); |
19 | 129 text ~= hex ~ " "; |
130 } | |
131 } | |
132 | |
133 int row = formatsTable.rowCount(); | |
134 formatsTable.insertRow(row); | |
135 formatsTable.setItem(row, 0, new QTableWidgetItem(format)); | |
136 formatsTable.setItem(row, 1, new QTableWidgetItem(text)); | |
137 } | |
138 | |
139 formatsTable.resizeColumnToContents(0); | |
140 } | |
141 | |
142 private: | |
143 | |
144 DropArea dropArea; | |
145 QLabel abstractLabel; | |
146 QTableWidget formatsTable; | |
147 | |
148 QPushButton clearButton; | |
149 QPushButton quitButton; | |
150 QDialogButtonBox buttonBox; | |
151 } |