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