annotate examples/draganddrop/dropsite/dropsitewindow.d @ 374:681af90e1d53

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