Mercurial > projects > qtd
annotate examples/draganddrop/dropsite/dropsitewindow.d @ 350:31520b2c0b3c
Removed dependency on parent trait and stringof
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Thu, 20 May 2010 15:49:08 +0300 |
parents | 7a3c43424dca |
children | a032df77b6ab |
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 | |
350
31520b2c0b3c
Removed dependency on parent trait and stringof
Max Samukha <maxter@spambox.com>
parents:
323
diff
changeset
|
44 import std.string : format, strip, toupper; |
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: | |
350
31520b2c0b3c
Removed dependency on parent trait and stringof
Max Samukha <maxter@spambox.com>
parents:
323
diff
changeset
|
59 |
19 | 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.")); | |
350
31520b2c0b3c
Removed dependency on parent trait and stringof
Max Samukha <maxter@spambox.com>
parents:
323
diff
changeset
|
65 |
19 | 66 abstractLabel.setWordWrap(true); |
67 abstractLabel.adjustSize(); | |
68 | |
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 | 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); | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
79 formatsTable.setHorizontalHeaderLabels(labels.toQList()); |
19 | 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 | |
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 | 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 | |
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 | 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") { |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
120 auto urlList = mimeData.urls(); |
19 | 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) { | |
350
31520b2c0b3c
Removed dependency on parent trait and stringof
Max Samukha <maxter@spambox.com>
parents:
323
diff
changeset
|
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; | |
350
31520b2c0b3c
Removed dependency on parent trait and stringof
Max Samukha <maxter@spambox.com>
parents:
323
diff
changeset
|
151 |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
152 mixin Q_OBJECT; |
19 | 153 } |