Mercurial > projects > qtd
comparison examples/draganddrop/dropsite/dropsitewindow.d @ 372:a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Thu, 08 Jul 2010 17:19:05 +0300 |
parents | 31520b2c0b3c |
children | 681af90e1d53 |
comparison
equal
deleted
inserted
replaced
370:7fd4b69378bf | 372:a032df77b6ab |
---|---|
51 import qt.gui.QDialogButtonBox; | 51 import qt.gui.QDialogButtonBox; |
52 | 52 |
53 import droparea; | 53 import droparea; |
54 | 54 |
55 | 55 |
56 import std.stdio; //TODO: remove | |
57 | |
58 | |
56 class DropSiteWindow : public QWidget | 59 class DropSiteWindow : public QWidget |
57 { | 60 { |
58 public: | 61 public: |
59 | 62 |
60 this() | 63 this() |
61 { | 64 { |
62 abstractLabel = new QLabel(tr("This example accepts drags from other " | 65 abstractLabel = new QLabel(tr("This example accepts drags from other " |
63 "applications and displays the MIME types " | 66 "applications and displays the MIME types " |
64 "provided by the drag object.")); | 67 "provided by the drag object.")); |
65 | 68 |
66 abstractLabel.setWordWrap(true); | 69 abstractLabel.setWordWrap(true); |
67 abstractLabel.adjustSize(); | 70 abstractLabel.adjustSize(); |
68 | 71 |
69 dropArea = new DropArea; | 72 dropArea = new DropArea; |
70 connect(dropArea, "changed", this, "updateFormatsTable"); | 73 connect(dropArea, "changed", this, "updateFormatsTable"); |
71 | 74 |
72 string[] labels; | 75 string[] labels; |
73 labels ~= tr("Format"); | 76 labels ~= tr("Format"); |
74 labels ~= tr("Content"); | 77 labels ~= tr("Content"); |
75 | 78 |
76 formatsTable = new QTableWidget; | 79 formatsTable = new QTableWidget; |
77 formatsTable.setColumnCount(2); | 80 formatsTable.setColumnCount(2); |
78 formatsTable.setEditTriggers(QAbstractItemView.NoEditTriggers); | 81 formatsTable.setEditTriggers(QAbstractItemView.NoEditTriggers); |
79 formatsTable.setHorizontalHeaderLabels(labels.toQList()); | 82 formatsTable.setHorizontalHeaderLabels(labels.toQList()); |
80 formatsTable.horizontalHeader().setStretchLastSection(true); | 83 formatsTable.horizontalHeader().setStretchLastSection(true); |
81 | 84 |
82 clearButton = new QPushButton(tr("Clear")); | 85 clearButton = new QPushButton(tr("Clear")); |
83 quitButton = new QPushButton(tr("Quit")); | 86 quitButton = new QPushButton(tr("Quit")); |
84 | 87 |
85 buttonBox = new QDialogButtonBox; | 88 buttonBox = new QDialogButtonBox; |
86 buttonBox.addButton(clearButton, QDialogButtonBox.ActionRole); | 89 buttonBox.addButton(clearButton, QDialogButtonBox.ActionRole); |
87 buttonBox.addButton(quitButton, QDialogButtonBox.RejectRole); | 90 buttonBox.addButton(quitButton, QDialogButtonBox.RejectRole); |
88 | 91 |
89 connect(quitButton, "pressed", this, "close"); | 92 connect(quitButton, "pressed", this, "close"); |
90 connect(clearButton, "pressed", dropArea, "clearArea"); | 93 connect(clearButton, "pressed", dropArea, "clearArea"); |
91 | 94 |
92 QVBoxLayout mainLayout = new QVBoxLayout; | 95 QVBoxLayout mainLayout = new QVBoxLayout; |
93 mainLayout.addWidget(abstractLabel); | 96 mainLayout.addWidget(abstractLabel); |
94 mainLayout.addWidget(dropArea); | 97 mainLayout.addWidget(dropArea); |
95 mainLayout.addWidget(formatsTable); | 98 mainLayout.addWidget(formatsTable); |
96 mainLayout.addWidget(buttonBox); | 99 mainLayout.addWidget(buttonBox); |
97 setLayout(mainLayout); | 100 setLayout(mainLayout); |
98 | 101 |
99 setWindowTitle(tr("Drop Site")); | 102 setWindowTitle(tr("Drop Site")); |
100 setMinimumSize(350, 500); | 103 setMinimumSize(350, 500); |
101 } | 104 } |
102 | 105 |
103 void slot_updateFormatsTable(QMimeData mimeData) | 106 void slot_updateFormatsTable(QMimeData mimeData) |
104 { | 107 { |
105 formatsTable.setRowCount(0); | 108 formatsTable.setRowCount(0); |
106 if (!mimeData) | 109 if (!mimeData) |
107 return; | 110 return; |
108 | 111 |
109 foreach (string format; mimeData.formats()) { | 112 foreach (string format; mimeData.formats()) { |
110 QTableWidgetItem formatItem = new QTableWidgetItem(format); | |
111 formatItem.setFlags(Qt.ItemIsEnabled); | |
112 formatItem.setTextAlignment(Qt.AlignTop | Qt.AlignLeft); | |
113 | 113 |
114 string text; | 114 writeln("Point 1"); |
115 if (format == "text/plain") { | 115 QTableWidgetItem formatItem = new QTableWidgetItem(format); |
116 text = strip(mimeData.text()); | 116 formatItem.setFlags(Qt.ItemIsEnabled); |
117 } else if (format == "text/html") { | 117 formatItem.setTextAlignment(Qt.AlignTop | Qt.AlignLeft); |
118 text = strip(mimeData.html()); | |
119 } else if (format == "text/uri-list") { | |
120 auto urlList = mimeData.urls(); | |
121 for (int i = 0; i < urlList.length && i < 32; ++i) { | |
122 string url = urlList[i].path(); | |
123 text ~= url ~ " "; | |
124 } | |
125 } else { | |
126 QByteArray data = mimeData.data(format); | |
127 for (int i = 0; i < data.size() && i < 32; ++i) { | |
128 string hex = toupper(std.string.format("%x", data.at(i))); | |
129 text ~= hex ~ " "; | |
130 } | |
131 } | |
132 | 118 |
133 int row = formatsTable.rowCount(); | 119 string text; |
134 formatsTable.insertRow(row); | 120 if (format == "text/plain") { |
135 formatsTable.setItem(row, 0, new QTableWidgetItem(format)); | 121 text = strip(mimeData.text()); |
136 formatsTable.setItem(row, 1, new QTableWidgetItem(text)); | 122 } else if (format == "text/html") { |
137 } | 123 text = strip(mimeData.html()); |
124 } else if (format == "text/uri-list") { | |
125 auto urlList = mimeData.urls(); | |
126 for (int i = 0; i < urlList.length && i < 32; ++i) { | |
127 string url = urlList[i].path(); | |
128 text ~= url ~ " "; | |
129 } | |
130 } else { | |
131 QByteArray data = mimeData.data(format); | |
132 for (int i = 0; i < data.size() && i < 32; ++i) { | |
133 string hex = toupper(std.string.format("%x", data.at(i))); | |
134 text ~= hex ~ " "; | |
135 } | |
136 } | |
138 | 137 |
139 formatsTable.resizeColumnToContents(0); | 138 int row = formatsTable.rowCount(); |
140 } | 139 formatsTable.insertRow(row); |
140 | |
141 writeln("Point 2"); | |
142 formatsTable.setItem(row, 0, new QTableWidgetItem(format)); | |
143 writeln("Point 3"); | |
144 formatsTable.setItem(row, 1, new QTableWidgetItem(text)); | |
145 } | |
146 | |
147 formatsTable.resizeColumnToContents(0); | |
148 } | |
149 | |
150 ~this() | |
151 { | |
152 writeln("deleting dropsitewindow"); | |
153 } | |
141 | 154 |
142 private: | 155 private: |
143 | 156 |
144 DropArea dropArea; | 157 DropArea dropArea; |
145 QLabel abstractLabel; | 158 QLabel abstractLabel; |
146 QTableWidget formatsTable; | 159 QTableWidget formatsTable; |
147 | 160 |
148 QPushButton clearButton; | 161 QPushButton clearButton; |
149 QPushButton quitButton; | 162 QPushButton quitButton; |
150 QDialogButtonBox buttonBox; | 163 QDialogButtonBox buttonBox; |
151 | 164 |
152 mixin Q_OBJECT; | 165 mixin Q_OBJECT; |
153 } | 166 } |