comparison examples/mainwindows/sdi/mainwindow.d @ 323:7a3c43424dca signals

make all examples compile with new signals/slots
author eldar_ins@eldar-laptop
date Mon, 28 Dec 2009 16:28:55 +0500
parents 256ab6cb8e85
children 31520b2c0b3c
comparison
equal deleted inserted replaced
322:7c2cf27391c4 323:7a3c43424dca
96 } 96 }
97 } 97 }
98 98
99 private: // slots 99 private: // slots
100 100
101 void newFile() 101 void slot_newFile()
102 { 102 {
103 MainWindow other = new MainWindow; 103 MainWindow other = new MainWindow;
104 other.move(x() + 40, y() + 40); 104 other.move(x() + 40, y() + 40);
105 other.show(); 105 other.show();
106 } 106 }
107 107
108 void open() 108 void slot_open()
109 { 109 {
110 scope fileName = QFileDialog.getOpenFileName(this); 110 scope fileName = QFileDialog.getOpenFileName(this);
111 if (fileName) { 111 if (fileName) {
112 MainWindow existing = findMainWindow(fileName); 112 MainWindow existing = findMainWindow(fileName);
113 if (existing) { 113 if (existing) {
129 other.show(); 129 other.show();
130 } 130 }
131 } 131 }
132 } 132 }
133 133
134 bool save() 134 bool slot_save()
135 { 135 {
136 if (isUntitled) { 136 if (isUntitled) {
137 return saveAs(); 137 return saveAs();
138 } else { 138 } else {
139 return saveFile(curFile); 139 return saveFile(curFile);
140 } 140 }
141 } 141 }
142 142
143 bool saveAs() 143 bool slot_saveAs()
144 { 144 {
145 string fileName = QFileDialog.getSaveFileName(this, tr("Save As"), 145 string fileName = QFileDialog.getSaveFileName(this, tr("Save As"),
146 curFile); 146 curFile);
147 if (!fileName) 147 if (!fileName)
148 return false; 148 return false;
149 149
150 return saveFile(fileName); 150 return saveFile(fileName);
151 } 151 }
152 152
153 void about() 153 void slot_about()
154 { 154 {
155 QMessageBox.about(this, tr("About SDI"), 155 QMessageBox.about(this, tr("About SDI"),
156 tr("The <b>SDI</b> example demonstrates how to write single " ~ 156 tr("The <b>SDI</b> example demonstrates how to write single " ~
157 "document interface applications using Qt.")); 157 "document interface applications using Qt."));
158 } 158 }
159 159
160 void documentWasModified() 160 void slot_documentWasModified()
161 { 161 {
162 setWindowModified(true); 162 setWindowModified(true);
163 } 163 }
164 164
165 private: 165 private:
178 createToolBars(); 178 createToolBars();
179 createStatusBar(); 179 createStatusBar();
180 180
181 readSettings(); 181 readSettings();
182 182
183 connect!("contentsChanged")(textEdit.document(), &this.documentWasModified); 183 connect(textEdit.document(), "contentsChanged", this, "documentWasModified");
184 184
185 setUnifiedTitleAndToolBarOnMac(true); 185 setUnifiedTitleAndToolBarOnMac(true);
186 } 186 }
187 187
188 void createActions() 188 void createActions()
189 { 189 {
190 newAct = new QAction(new QIcon(":/images/new.png"), tr("&New"), this); 190 newAct = new QAction(new QIcon(":/images/new.png"), tr("&New"), this);
191 newAct.setShortcuts(QKeySequence.New); 191 newAct.setShortcuts(QKeySequence.New);
192 newAct.setStatusTip(tr("Create a new file")); 192 newAct.setStatusTip(tr("Create a new file"));
193 connect!("triggered")(newAct, &this.newFile); 193 connect(newAct, "triggered", this, "newFile");
194 194
195 openAct = new QAction(new QIcon(":/images/open.png"), tr("&Open..."), this); 195 openAct = new QAction(new QIcon(":/images/open.png"), tr("&Open..."), this);
196 openAct.setShortcuts(QKeySequence.Open); 196 openAct.setShortcuts(QKeySequence.Open);
197 openAct.setStatusTip(tr("Open an existing file")); 197 openAct.setStatusTip(tr("Open an existing file"));
198 connect!("triggered")(openAct, &this.open); 198 connect(openAct, "triggered", this, "open");
199 199
200 saveAct = new QAction(new QIcon(":/images/save.png"), tr("&Save"), this); 200 saveAct = new QAction(new QIcon(":/images/save.png"), tr("&Save"), this);
201 saveAct.setShortcuts(QKeySequence.Save); 201 saveAct.setShortcuts(QKeySequence.Save);
202 saveAct.setStatusTip(tr("Save the document to disk")); 202 saveAct.setStatusTip(tr("Save the document to disk"));
203 connect!("triggered")(saveAct, &this.save); 203 connect(saveAct, "triggered", this, "save");
204 204
205 saveAsAct = new QAction(tr("Save &As..."), this); 205 saveAsAct = new QAction(tr("Save &As..."), this);
206 saveAsAct.setShortcuts(QKeySequence.SaveAs); 206 saveAsAct.setShortcuts(QKeySequence.SaveAs);
207 saveAsAct.setStatusTip(tr("Save the document under a new name")); 207 saveAsAct.setStatusTip(tr("Save the document under a new name"));
208 connect!("triggered")(saveAsAct, &this.saveAs); 208 connect(saveAsAct, "triggered", this, "saveAs");
209 209
210 closeAct = new QAction(tr("&Close"), this); 210 closeAct = new QAction(tr("&Close"), this);
211 closeAct.setShortcut(tr("Ctrl+W")); 211 closeAct.setShortcut(tr("Ctrl+W"));
212 closeAct.setStatusTip(tr("Close this window")); 212 closeAct.setStatusTip(tr("Close this window"));
213 connect!("triggered")(closeAct, &this.close); 213 connect(closeAct, "triggered", this, "close");
214 214
215 exitAct = new QAction(tr("E&xit"), this); 215 exitAct = new QAction(tr("E&xit"), this);
216 exitAct.setShortcut(tr("Ctrl+Q")); 216 exitAct.setShortcut(tr("Ctrl+Q"));
217 exitAct.setStatusTip(tr("Exit the application")); 217 exitAct.setStatusTip(tr("Exit the application"));
218 connect!("triggered")(exitAct, &QApplication.closeAllWindows); 218 connect(exitAct, "triggered", qApp(), "closeAllWindows");
219 219
220 cutAct = new QAction(new QIcon(":/images/cut.png"), tr("Cu&t"), this); 220 cutAct = new QAction(new QIcon(":/images/cut.png"), tr("Cu&t"), this);
221 cutAct.setShortcuts(QKeySequence.Cut); 221 cutAct.setShortcuts(QKeySequence.Cut);
222 cutAct.setStatusTip(tr("Cut the current selection's contents to the " ~ 222 cutAct.setStatusTip(tr("Cut the current selection's contents to the " ~
223 "clipboard")); 223 "clipboard"));
224 connect!("triggered")(cutAct, &textEdit.cut); 224 connect(cutAct, "triggered", textEdit, "cut");
225 225
226 copyAct = new QAction(new QIcon(":/images/copy.png"), tr("&Copy"), this); 226 copyAct = new QAction(new QIcon(":/images/copy.png"), tr("&Copy"), this);
227 copyAct.setShortcuts(QKeySequence.Copy); 227 copyAct.setShortcuts(QKeySequence.Copy);
228 copyAct.setStatusTip(tr("Copy the current selection's contents to the " ~ 228 copyAct.setStatusTip(tr("Copy the current selection's contents to the " ~
229 "clipboard")); 229 "clipboard"));
230 connect!("triggered")(copyAct, &textEdit.copy); 230 connect(copyAct, "triggered", textEdit, "copy");
231 231
232 pasteAct = new QAction(new QIcon(":/images/paste.png"), tr("&Paste"), this); 232 pasteAct = new QAction(new QIcon(":/images/paste.png"), tr("&Paste"), this);
233 pasteAct.setShortcuts(QKeySequence.Paste); 233 pasteAct.setShortcuts(QKeySequence.Paste);
234 pasteAct.setStatusTip(tr("Paste the clipboard's contents into the current " ~ 234 pasteAct.setStatusTip(tr("Paste the clipboard's contents into the current " ~
235 "selection")); 235 "selection"));
236 connect!("triggered")(pasteAct, &textEdit.paste); 236 connect(pasteAct, "triggered", textEdit, "paste");
237 237
238 aboutAct = new QAction(tr("&About"), this); 238 aboutAct = new QAction(tr("&About"), this);
239 aboutAct.setStatusTip(tr("Show the application's About box")); 239 aboutAct.setStatusTip(tr("Show the application's About box"));
240 connect!("triggered")(aboutAct, &this.about); 240 connect(aboutAct, "triggered", this, "about");
241 241
242 aboutQtAct = new QAction(tr("About &Qt"), this); 242 aboutQtAct = new QAction(tr("About &Qt"), this);
243 aboutQtAct.setStatusTip(tr("Show the Qt library's About box")); 243 aboutQtAct.setStatusTip(tr("Show the Qt library's About box"));
244 connect!("triggered")(aboutQtAct, &QApplication.aboutQt); 244 connect(aboutQtAct, "triggered", qApp, "aboutQt");
245 245
246 cutAct.setEnabled(false); 246 cutAct.setEnabled(false);
247 copyAct.setEnabled(false); 247 copyAct.setEnabled(false);
248 248
249 connect!("copyAvailable")(textEdit, &cutAct.setEnabled); 249 connect(textEdit, "copyAvailable", cutAct, "setEnabled");
250 connect!("copyAvailable")(textEdit, &copyAct.setEnabled); 250 connect(textEdit, "copyAvailable", copyAct, "setEnabled");
251 } 251 }
252 252
253 void createMenus() 253 void createMenus()
254 { 254 {
255 fileMenu = menuBar.addMenu(tr("&File")); 255 fileMenu = menuBar.addMenu(tr("&File"));
424 QAction cutAct; 424 QAction cutAct;
425 QAction copyAct; 425 QAction copyAct;
426 QAction pasteAct; 426 QAction pasteAct;
427 QAction aboutAct; 427 QAction aboutAct;
428 QAction aboutQtAct; 428 QAction aboutQtAct;
429
430 mixin Q_OBJECT;
429 }; 431 };