Mercurial > projects > qtd
annotate examples/mainwindows/dockwidgets/mainwindow.d @ 350:31520b2c0b3c
Removed dependency on parent trait and stringof
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Thu, 20 May 2010 15:49:08 +0300 |
parents | 7a3c43424dca |
children |
rev | line source |
---|---|
1 | 1 /**************************************************************************** |
2 ** | |
3 ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). | |
4 ** Contact: Qt Software Information (qt-info@nokia.com) | |
5 ** | |
6 ** This file is part of the example classes of the Qt Toolkit. | |
7 ** | |
8 ** Commercial Usage | |
9 ** Licensees holding valid Qt Commercial licenses may use this file in | |
10 ** accordance with the Qt Commercial License Agreement provided with the | |
11 ** Software or, alternatively, in accordance with the terms contained in | |
12 ** a written agreement between you and Nokia. | |
13 ** | |
14 ** | |
15 ** GNU General Public License Usage | |
16 ** Alternatively, this file may be used under the terms of the GNU | |
17 ** General Public License versions 2.0 or 3.0 as published by the Free | |
18 ** Software Foundation and appearing in the file LICENSE.GPL included in | |
19 ** the packaging of this file. Please review the following information | |
20 ** to ensure GNU General Public Licensing requirements will be met: | |
21 ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and | |
22 ** http://www.gnu.org/copyleft/gpl.html. In addition, as a special | |
23 ** exception, Nokia gives you certain additional rights. These rights | |
24 ** are described in the Nokia Qt GPL Exception version 1.3, included in | |
25 ** the file GPL_EXCEPTION.txt in this package. | |
26 ** | |
27 ** Qt for Windows(R) Licensees | |
28 ** As a special exception, Nokia, as the sole copyright holder for Qt | |
29 ** Designer, grants users of the Qt/Eclipse Integration plug-in the | |
30 ** right for the Qt/Eclipse Integration to link to functionality | |
31 ** provided by Qt Designer and its related libraries. | |
32 ** | |
33 ** If you are unsure which license is appropriate for your use, please | |
34 ** contact the sales department at qt-sales@nokia.com. | |
35 ** | |
36 ****************************************************************************/ | |
37 | |
38 | |
39 import qt.gui.QMainWindow; | |
40 | |
41 import qt.gui.QListWidget; | |
42 import qt.gui.QMenu; | |
43 import qt.gui.QToolBar; | |
44 import qt.gui.QDockWidget; | |
45 import qt.gui.QListWidget; | |
46 import qt.gui.QMessageBox; | |
47 import qt.gui.QTextEdit; | |
48 import qt.gui.QTextCursor; | |
49 import qt.gui.QTextFrame; | |
50 import qt.gui.QTextFrameFormat; | |
51 import qt.gui.QTextCharFormat; | |
52 import qt.gui.QTextTableFormat; | |
53 import qt.gui.QAction; | |
54 import qt.gui.QStatusBar; | |
55 import qt.gui.QFont; | |
56 import qt.gui.QIcon; | |
215 | 57 import qt.core.QDate; |
1 | 58 |
350
31520b2c0b3c
Removed dependency on parent trait and stringof
Max Samukha <maxter@spambox.com>
parents:
323
diff
changeset
|
59 import std.string : split; |
1 | 60 |
61 class MainWindow : public QMainWindow | |
62 { | |
63 // Q_OBJECT | |
64 | |
65 public: | |
66 this() | |
67 { | |
68 textEdit = new QTextEdit; | |
69 setCentralWidget(textEdit); | |
70 | |
71 createActions(); | |
72 createMenus(); | |
73 createToolBars(); | |
74 createStatusBar(); | |
75 createDockWindows(); | |
76 | |
77 setWindowTitle(tr("Dock Widgets")); | |
78 newLetter(); | |
79 } | |
80 | |
81 private : //slots: | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
82 void slot_newLetter() |
1 | 83 { |
84 textEdit.clear(); | |
85 | |
86 scope cursor = textEdit.textCursor; | |
87 cursor.movePosition(QTextCursor.Start); | |
88 QTextFrame topFrame = cursor.currentFrame(); | |
89 QTextFrameFormat topFrameFormat = topFrame.frameFormat(); | |
90 topFrameFormat.setPadding(16); | |
91 topFrame.setFrameFormat(topFrameFormat); | |
92 | |
93 scope textFormat = new QTextCharFormat; | |
94 scope boldFormat = new QTextCharFormat; | |
95 scope italicFormat = new QTextCharFormat; | |
96 boldFormat.setFontWeight(QFont.Bold); | |
97 italicFormat.setFontItalic(true); | |
98 | |
99 scope tableFormat = new QTextTableFormat; | |
100 tableFormat.setBorder(1); | |
101 tableFormat.setCellPadding(16); | |
102 tableFormat.setAlignment(Qt.AlignRight); | |
103 cursor.insertTable(1, 1, tableFormat); | |
104 cursor.insertText("The Firm", boldFormat); | |
105 cursor.insertBlock(); | |
106 cursor.insertText("321 City Street", textFormat); | |
107 cursor.insertBlock(); | |
108 cursor.insertText("Industry Park"); | |
109 cursor.insertBlock(); | |
110 cursor.insertText("Some Country"); | |
111 cursor.setPosition(topFrame.lastPosition()); | |
112 cursor.insertText(QDate.currentDate.toString("d MMMM yyyy"), textFormat); | |
113 cursor.insertBlock(); | |
114 cursor.insertBlock(); | |
115 cursor.insertText("Dear ", textFormat); | |
116 cursor.insertText("NAME", italicFormat); | |
117 cursor.insertText(",", textFormat); | |
118 for (int i = 0; i < 3; ++i) | |
119 cursor.insertBlock(); | |
120 cursor.insertText(tr("Yours sincerely,"), textFormat); | |
121 for (int i = 0; i < 3; ++i) | |
122 cursor.insertBlock(); | |
123 cursor.insertText("The Boss", textFormat); | |
124 cursor.insertBlock(); | |
125 cursor.insertText("ADDRESS", italicFormat); | |
126 } | |
127 /* | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
128 void slot_save() |
1 | 129 { |
130 char[] fileName = QFileDialog.getSaveFileName(this, | |
131 tr("Choose a file name"), ".", | |
132 tr("HTML (*.html *.htm)")); | |
133 if (fileName.isEmpty()) | |
134 return; | |
135 scope file = new QFile(fileName); | |
136 if (!file.open(QFile.WriteOnly | QFile.Text)) { | |
137 QMessageBox.warning(this, tr("Dock Widgets"), | |
138 tr(layout("Cannot write file %1:\n%2.", fileName, file.errorString)) | |
139 return; | |
140 } | |
141 | |
142 scope outStream = new QTextStream(file); | |
143 QApplication.setOverrideCursor(Qt.WaitCursor); | |
144 outStream << textEdit.toHtml(); | |
145 QApplication.restoreOverrideCursor(); | |
146 | |
147 statusBar.showMessage(layout("Saved '%1'", fileName), 2000); | |
148 }*/ | |
149 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
150 void slot_print() { } |
1 | 151 |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
152 void slot_undo() { |
1 | 153 auto document = textEdit.document(); |
154 document.undo(); | |
155 } | |
156 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
157 void slot_insertCustomer(string customer) |
1 | 158 { |
159 if (customer == "") | |
160 return; | |
350
31520b2c0b3c
Removed dependency on parent trait and stringof
Max Samukha <maxter@spambox.com>
parents:
323
diff
changeset
|
161 |
191 | 162 string[] customerList = customer.split(", "); |
1 | 163 auto document = textEdit.document(); |
164 QTextCursor cursor = document.find("NAME"); | |
165 if (!cursor.isNull) { | |
166 cursor.beginEditBlock(); | |
167 cursor.insertText(customerList[0]); | |
168 scope oldcursor = new QTextCursor(cursor); | |
169 cursor = document.find("ADDRESS"); | |
170 if (!cursor.isNull) { | |
171 for (int i = 1; i < customerList.length; ++i) { | |
172 cursor.insertBlock(); | |
173 cursor.insertText(customerList[i]); | |
174 } | |
175 cursor.endEditBlock(); | |
176 } | |
177 else | |
178 oldcursor.endEditBlock(); | |
179 } | |
180 } | |
181 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
182 void slot_addParagraph(string paragraph) |
1 | 183 { |
184 if (paragraph == "") | |
185 return; | |
186 auto document = textEdit.document(); | |
187 scope cursor = document.find(tr("Yours sincerely,")); | |
188 if (cursor.isNull) | |
189 return; | |
190 cursor.beginEditBlock(); | |
191 cursor.movePosition(QTextCursor.PreviousBlock, QTextCursor.MoveAnchor, 2); | |
192 cursor.insertBlock(); | |
193 cursor.insertText(paragraph); | |
194 cursor.insertBlock(); | |
195 cursor.endEditBlock(); | |
196 | |
197 } | |
198 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
199 void slot_about() |
1 | 200 { |
201 QMessageBox.about(this, "About Dock Widgets", | |
202 "The <b>Dock Widgets</b> example demonstrates how to " | |
203 "use Qt's dock widgets. You can enter your own text, " | |
204 "click a customer to add a customer name and " | |
205 "address, and click standard paragraphs to add them."); | |
206 } | |
207 | |
208 private: | |
209 void createActions() | |
210 { | |
61
a2871e6b8b15
drcc: automatic initialization of resources with program start (disabled with option -no-static-initialize)
SokoL_SD
parents:
1
diff
changeset
|
211 newLetterAct = new QAction(new QIcon(":images/new.png"), tr("&New Letter"), this); |
1 | 212 newLetterAct.setShortcut(tr("Ctrl+N")); |
213 newLetterAct.setStatusTip(tr("Create a new form letter")); | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
214 connect(newLetterAct, "triggered", this, "newLetter"); |
1 | 215 |
61
a2871e6b8b15
drcc: automatic initialization of resources with program start (disabled with option -no-static-initialize)
SokoL_SD
parents:
1
diff
changeset
|
216 saveAct = new QAction(new QIcon(":images/save.png"), tr("&Save..."), this); |
1 | 217 saveAct.setShortcut(tr("Ctrl+S")); |
218 saveAct.setStatusTip(tr("Save the current form letter")); | |
219 // saveAct.triggered.connect(&save); | |
220 | |
61
a2871e6b8b15
drcc: automatic initialization of resources with program start (disabled with option -no-static-initialize)
SokoL_SD
parents:
1
diff
changeset
|
221 printAct = new QAction(new QIcon(":images/print.png"), tr("&Print..."), this); |
1 | 222 printAct.setShortcut(tr("Ctrl+P")); |
223 printAct.setStatusTip(tr("Print the current form letter")); | |
224 // printAct.triggered.connect(&print); | |
225 | |
61
a2871e6b8b15
drcc: automatic initialization of resources with program start (disabled with option -no-static-initialize)
SokoL_SD
parents:
1
diff
changeset
|
226 undoAct = new QAction(new QIcon(":images/undo.png"), tr("&Undo"), this); |
1 | 227 undoAct.setShortcut(tr("Ctrl+Z")); |
228 undoAct.setStatusTip(tr("Undo the last editing action")); | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
229 connect(undoAct, "triggered", this, "undo"); |
1 | 230 |
231 quitAct = new QAction(tr("&Quit"), this); | |
232 quitAct.setShortcut(tr("Ctrl+Q")); | |
233 quitAct.setStatusTip(tr("Quit the application")); | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
234 connect(quitAct, "triggered", this, "close"); |
1 | 235 |
236 aboutAct = new QAction(tr("&About"), this); | |
237 aboutAct.setStatusTip(tr("Show the application's About box")); | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
238 connect(aboutAct, "triggered", this, "about"); |
1 | 239 |
240 aboutQtAct = new QAction(tr("About &Qt"), this); | |
241 aboutQtAct.setStatusTip(tr("Show the Qt library's About box")); | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
242 connect(aboutQtAct, "triggered", qApp, "aboutQt"); |
1 | 243 } |
244 | |
245 void createMenus() | |
246 { | |
247 fileMenu = menuBar.addMenu(tr("&File")); | |
248 fileMenu.addAction(newLetterAct); | |
249 fileMenu.addAction(saveAct); | |
250 fileMenu.addAction(printAct); | |
251 fileMenu.addSeparator(); | |
252 fileMenu.addAction(quitAct); | |
253 | |
254 editMenu = menuBar.addMenu(tr("&Edit")); | |
255 editMenu.addAction(undoAct); | |
256 | |
257 viewMenu = menuBar.addMenu(tr("&View")); | |
258 | |
259 menuBar().addSeparator(); | |
260 | |
261 helpMenu = menuBar.addMenu(tr("&Help")); | |
262 helpMenu.addAction(aboutAct); | |
263 helpMenu.addAction(aboutQtAct); | |
264 } | |
265 | |
266 void createToolBars() | |
267 { | |
268 fileToolBar = addToolBar(tr("File")); | |
269 fileToolBar.addAction(newLetterAct); | |
270 fileToolBar.addAction(saveAct); | |
271 fileToolBar.addAction(printAct); | |
272 | |
273 editToolBar = addToolBar(tr("Edit")); | |
274 editToolBar.addAction(undoAct); | |
275 } | |
276 | |
277 void createStatusBar() | |
278 { | |
279 statusBar.showMessage(tr("Ready")); | |
280 } | |
281 | |
282 void createDockWindows() | |
283 { | |
284 QDockWidget dock = new QDockWidget(tr("Customers"), this); | |
285 dock.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea); | |
286 customerList = new QListWidget(dock); | |
287 customerList.addItems([ | |
288 "John Doe, Harmony Enterprises, 12 Lakeside, Ambleton", | |
289 "Jane Doe, Memorabilia, 23 Watersedge, Beaton", | |
290 "Tammy Shea, Tiblanka, 38 Sea Views, Carlton", | |
291 "Tim Sheen, Caraba Gifts, 48 Ocean Way, Deal", | |
292 "Sol Harvey, Chicos Coffee, 53 New Springs, Eccleston", | |
293 "Sally Hobart, Tiroli Tea, 67 Long River, Fedula"]); | |
294 dock.setWidget(customerList); | |
295 addDockWidget(Qt.RightDockWidgetArea, dock); | |
296 viewMenu.addAction(dock.toggleViewAction()); | |
297 | |
298 dock = new QDockWidget(tr("Paragraphs"), this); | |
299 paragraphsList = new QListWidget(dock); | |
300 paragraphsList.addItems([ | |
301 "Thank you for your payment which we have received today.", | |
302 "Your order has been dispatched and should be with you " | |
303 "within 28 days.", | |
304 | |
305 "We have dispatched those items that were in stock. The " | |
306 "rest of your order will be dispatched once all the " | |
307 "remaining items have arrived at our warehouse. No " | |
308 "additional shipping charges will be made.", | |
309 | |
310 "You made a small overpayment (less than $5) which we " | |
311 "will keep on account for you, or return at your request.", | |
312 | |
313 "You made a small underpayment (less than $1), but we have " | |
314 "sent your order anyway. We'll add this underpayment to " | |
315 "your next bill.", | |
316 | |
317 "Unfortunately you did not send enough money. Please remit " | |
318 "an additional $. Your order will be dispatched as soon as " | |
319 "the complete amount has been received.", | |
320 | |
321 "You made an overpayment (more than $5). Do you wish to " | |
322 "buy more items, or should we return the excess to you?"]); | |
323 dock.setWidget(paragraphsList); | |
324 addDockWidget(Qt.RightDockWidgetArea, dock); | |
325 viewMenu.addAction(dock.toggleViewAction()); | |
326 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
327 connect(customerList, "currentTextChanged", this, "insertCustomer"); |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
328 connect(paragraphsList, "currentTextChanged", this, "addParagraph"); |
1 | 329 } |
330 | |
331 QTextEdit textEdit; | |
332 QListWidget customerList; | |
333 QListWidget paragraphsList; | |
334 | |
335 QMenu fileMenu; | |
336 QMenu editMenu; | |
337 QMenu viewMenu; | |
338 QMenu helpMenu; | |
339 QToolBar fileToolBar; | |
340 QToolBar editToolBar; | |
341 QAction newLetterAct; | |
342 QAction saveAct; | |
343 QAction printAct; | |
344 QAction undoAct; | |
345 QAction aboutAct; | |
346 QAction aboutQtAct; | |
347 QAction quitAct; | |
350
31520b2c0b3c
Removed dependency on parent trait and stringof
Max Samukha <maxter@spambox.com>
parents:
323
diff
changeset
|
348 |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
349 mixin Q_OBJECT; |
1 | 350 } |