mandel@19: /**************************************************************************** mandel@19: ** mandel@19: ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). mandel@19: ** Contact: Qt Software Information (qt-info@nokia.com) mandel@19: ** mandel@19: ** This file is part of the examples of the Qt Toolkit. mandel@19: ** mandel@19: ** $QT_BEGIN_LICENSE:LGPL$ mandel@19: ** Commercial Usage mandel@19: ** Licensees holding valid Qt Commercial licenses may use this file in mandel@19: ** accordance with the Qt Commercial License Agreement provided with the mandel@19: ** Software or, alternatively, in accordance with the terms contained in mandel@19: ** a written agreement between you and Nokia. mandel@19: ** mandel@19: ** GNU Lesser General Public License Usage mandel@19: ** Alternatively, this file may be used under the terms of the GNU Lesser mandel@19: ** General Public License version 2.1 as published by the Free Software mandel@19: ** Foundation and appearing in the file LICENSE.LGPL included in the mandel@19: ** packaging of this file. Please review the following information to mandel@19: ** ensure the GNU Lesser General Public License version 2.1 requirements mandel@19: ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. mandel@19: ** mandel@19: ** In addition, as a special exception, Nokia gives you certain mandel@19: ** additional rights. These rights are described in the Nokia Qt LGPL mandel@19: ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this mandel@19: ** package. mandel@19: ** mandel@19: ** GNU General Public License Usage mandel@19: ** Alternatively, this file may be used under the terms of the GNU mandel@19: ** General Public License version 3.0 as published by the Free Software mandel@19: ** Foundation and appearing in the file LICENSE.GPL included in the mandel@19: ** packaging of this file. Please review the following information to mandel@19: ** ensure the GNU General Public License version 3.0 requirements will be mandel@19: ** met: http://www.gnu.org/copyleft/gpl.html. mandel@19: ** mandel@19: ** If you are unsure which license is appropriate for your use, please mandel@19: ** contact the sales department at qt-sales@nokia.com. mandel@19: ** $QT_END_LICENSE$ mandel@19: ** mandel@19: ****************************************************************************/ mandel@19: mandel@19: module dropsitewindow; mandel@19: maxter@350: import std.string : format, strip, toupper; mandel@19: mandel@19: import qt.gui.QWidget; mandel@19: import qt.gui.QLabel; mandel@19: import qt.gui.QTableWidget; mandel@19: import qt.gui.QPushButton; mandel@19: import qt.gui.QVBoxLayout; mandel@19: import qt.gui.QDialogButtonBox; mandel@19: mandel@19: import droparea; mandel@19: mandel@19: class DropSiteWindow : public QWidget mandel@19: { mandel@19: public: maxter@350: maxter@372: this() maxter@372: { maxter@372: abstractLabel = new QLabel(tr("This example accepts drags from other " maxter@372: "applications and displays the MIME types " maxter@372: "provided by the drag object.")); maxter@350: maxter@372: abstractLabel.setWordWrap(true); maxter@372: abstractLabel.adjustSize(); mandel@19: maxter@372: dropArea = new DropArea; maxter@372: connect(dropArea, "changed", this, "updateFormatsTable"); mandel@19: maxter@372: string[] labels; maxter@372: labels ~= tr("Format"); maxter@372: labels ~= tr("Content"); mandel@19: maxter@372: formatsTable = new QTableWidget; maxter@372: formatsTable.setColumnCount(2); maxter@372: formatsTable.setEditTriggers(QAbstractItemView.NoEditTriggers); maxter@372: formatsTable.setHorizontalHeaderLabels(labels.toQList()); maxter@372: formatsTable.horizontalHeader().setStretchLastSection(true); mandel@19: maxter@372: clearButton = new QPushButton(tr("Clear")); maxter@372: quitButton = new QPushButton(tr("Quit")); maxter@372: maxter@372: buttonBox = new QDialogButtonBox; maxter@372: buttonBox.addButton(clearButton, QDialogButtonBox.ActionRole); maxter@372: buttonBox.addButton(quitButton, QDialogButtonBox.RejectRole); mandel@19: maxter@372: connect(quitButton, "pressed", this, "close"); maxter@372: connect(clearButton, "pressed", dropArea, "clearArea"); mandel@19: maxter@372: QVBoxLayout mainLayout = new QVBoxLayout; maxter@372: mainLayout.addWidget(abstractLabel); maxter@372: mainLayout.addWidget(dropArea); maxter@372: mainLayout.addWidget(formatsTable); maxter@372: mainLayout.addWidget(buttonBox); maxter@372: setLayout(mainLayout); maxter@372: maxter@372: setWindowTitle(tr("Drop Site")); maxter@372: setMinimumSize(350, 500); maxter@372: } mandel@19: maxter@372: void slot_updateFormatsTable(QMimeData mimeData) maxter@372: { maxter@372: formatsTable.setRowCount(0); maxter@372: if (!mimeData) maxter@372: return; mandel@19: maxter@372: foreach (string format; mimeData.formats()) { eldar@21: maxter@372: QTableWidgetItem formatItem = new QTableWidgetItem(format); maxter@372: formatItem.setFlags(Qt.ItemIsEnabled); maxter@372: formatItem.setTextAlignment(Qt.AlignTop | Qt.AlignLeft); mandel@19: maxter@372: string text; maxter@372: if (format == "text/plain") { maxter@372: text = strip(mimeData.text()); maxter@372: } else if (format == "text/html") { maxter@372: text = strip(mimeData.html()); maxter@372: } else if (format == "text/uri-list") { maxter@372: auto urlList = mimeData.urls(); maxter@372: for (int i = 0; i < urlList.length && i < 32; ++i) { maxter@372: string url = urlList[i].path(); maxter@372: text ~= url ~ " "; maxter@372: } maxter@372: } else { maxter@372: QByteArray data = mimeData.data(format); maxter@372: for (int i = 0; i < data.size() && i < 32; ++i) { maxter@372: string hex = toupper(std.string.format("%x", data.at(i))); maxter@372: text ~= hex ~ " "; maxter@372: } maxter@372: } mandel@19: maxter@372: int row = formatsTable.rowCount(); maxter@374: maxter@372: formatsTable.insertRow(row); maxter@372: formatsTable.setItem(row, 0, new QTableWidgetItem(format)); maxter@372: formatsTable.setItem(row, 1, new QTableWidgetItem(text)); maxter@372: } maxter@372: maxter@372: formatsTable.resizeColumnToContents(0); maxter@372: } maxter@374: mandel@19: private: mandel@19: maxter@372: DropArea dropArea; maxter@372: QLabel abstractLabel; maxter@372: QTableWidget formatsTable; mandel@19: maxter@372: QPushButton clearButton; maxter@372: QPushButton quitButton; maxter@372: QDialogButtonBox buttonBox; maxter@350: eldar_ins@323: mixin Q_OBJECT; mandel@19: }