1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the examples of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this 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 have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include <QtGui>
|
---|
43 |
|
---|
44 | #include "droparea.h"
|
---|
45 | #include "dropsitewindow.h"
|
---|
46 |
|
---|
47 | //! [constructor part1]
|
---|
48 | DropSiteWindow::DropSiteWindow()
|
---|
49 | {
|
---|
50 | abstractLabel = new QLabel(tr("This example accepts drags from other "
|
---|
51 | "applications and displays the MIME types "
|
---|
52 | "provided by the drag object."));
|
---|
53 | abstractLabel->setWordWrap(true);
|
---|
54 | abstractLabel->adjustSize();
|
---|
55 | //! [constructor part1]
|
---|
56 |
|
---|
57 | //! [constructor part2]
|
---|
58 | dropArea = new DropArea;
|
---|
59 | connect(dropArea, SIGNAL(changed(const QMimeData*)),
|
---|
60 | this, SLOT(updateFormatsTable(const QMimeData*)));
|
---|
61 | //! [constructor part2]
|
---|
62 |
|
---|
63 | //! [constructor part3]
|
---|
64 | QStringList labels;
|
---|
65 | labels << tr("Format") << tr("Content");
|
---|
66 |
|
---|
67 | formatsTable = new QTableWidget;
|
---|
68 | formatsTable->setColumnCount(2);
|
---|
69 | formatsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
---|
70 | formatsTable->setHorizontalHeaderLabels(labels);
|
---|
71 | formatsTable->horizontalHeader()->setStretchLastSection(true);
|
---|
72 | //! [constructor part3]
|
---|
73 |
|
---|
74 | //! [constructor part4]
|
---|
75 | clearButton = new QPushButton(tr("Clear"));
|
---|
76 | quitButton = new QPushButton(tr("Quit"));
|
---|
77 |
|
---|
78 | buttonBox = new QDialogButtonBox;
|
---|
79 | buttonBox->addButton(clearButton, QDialogButtonBox::ActionRole);
|
---|
80 | buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
|
---|
81 |
|
---|
82 | connect(quitButton, SIGNAL(pressed()), this, SLOT(close()));
|
---|
83 | connect(clearButton, SIGNAL(pressed()), dropArea, SLOT(clear()));
|
---|
84 | //! [constructor part4]
|
---|
85 |
|
---|
86 | //! [constructor part5]
|
---|
87 | QVBoxLayout *mainLayout = new QVBoxLayout;
|
---|
88 | mainLayout->addWidget(abstractLabel);
|
---|
89 | mainLayout->addWidget(dropArea);
|
---|
90 | mainLayout->addWidget(formatsTable);
|
---|
91 | mainLayout->addWidget(buttonBox);
|
---|
92 | setLayout(mainLayout);
|
---|
93 |
|
---|
94 | setWindowTitle(tr("Drop Site"));
|
---|
95 | setMinimumSize(350, 500);
|
---|
96 | }
|
---|
97 | //! [constructor part5]
|
---|
98 |
|
---|
99 | //! [updateFormatsTable() part1]
|
---|
100 | void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData)
|
---|
101 | {
|
---|
102 | formatsTable->setRowCount(0);
|
---|
103 | if (!mimeData)
|
---|
104 | return;
|
---|
105 | //! [updateFormatsTable() part1]
|
---|
106 |
|
---|
107 | //! [updateFormatsTable() part2]
|
---|
108 | foreach (QString format, mimeData->formats()) {
|
---|
109 | QTableWidgetItem *formatItem = new QTableWidgetItem(format);
|
---|
110 | formatItem->setFlags(Qt::ItemIsEnabled);
|
---|
111 | formatItem->setTextAlignment(Qt::AlignTop | Qt::AlignLeft);
|
---|
112 | //! [updateFormatsTable() part2]
|
---|
113 |
|
---|
114 | //! [updateFormatsTable() part3]
|
---|
115 | QString text;
|
---|
116 | if (format == "text/plain") {
|
---|
117 | text = mimeData->text().simplified();
|
---|
118 | } else if (format == "text/html") {
|
---|
119 | text = mimeData->html().simplified();
|
---|
120 | } else if (format == "text/uri-list") {
|
---|
121 | QList<QUrl> urlList = mimeData->urls();
|
---|
122 | for (int i = 0; i < urlList.size() && i < 32; ++i)
|
---|
123 | text.append(urlList[i].toString() + " ");
|
---|
124 | } else {
|
---|
125 | QByteArray data = mimeData->data(format);
|
---|
126 | for (int i = 0; i < data.size() && i < 32; ++i) {
|
---|
127 | QString hex = QString("%1").arg(uchar(data[i]), 2, 16,
|
---|
128 | QChar('0'))
|
---|
129 | .toUpper();
|
---|
130 | text.append(hex + " ");
|
---|
131 | }
|
---|
132 | }
|
---|
133 | //! [updateFormatsTable() part3]
|
---|
134 |
|
---|
|
---|