[190] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
| 2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/action/application.doc:5 -->
|
---|
| 3 | <html>
|
---|
| 4 | <head>
|
---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
| 6 | <title>A Complete Application Window with Actions</title>
|
---|
| 7 | <style type="text/css"><!--
|
---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
| 9 | a:link { color: #004faf; text-decoration: none }
|
---|
| 10 | a:visited { color: #672967; text-decoration: none }
|
---|
| 11 | body { background: #ffffff; color: black; }
|
---|
| 12 | --></style>
|
---|
| 13 | </head>
|
---|
| 14 | <body>
|
---|
| 15 |
|
---|
| 16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
| 17 | <tr bgcolor="#E5E5E5">
|
---|
| 18 | <td valign=center>
|
---|
| 19 | <a href="index.html">
|
---|
| 20 | <font color="#004faf">Home</font></a>
|
---|
| 21 | | <a href="classes.html">
|
---|
| 22 | <font color="#004faf">All Classes</font></a>
|
---|
| 23 | | <a href="mainclasses.html">
|
---|
| 24 | <font color="#004faf">Main Classes</font></a>
|
---|
| 25 | | <a href="annotated.html">
|
---|
| 26 | <font color="#004faf">Annotated</font></a>
|
---|
| 27 | | <a href="groups.html">
|
---|
| 28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
| 29 | | <a href="functions.html">
|
---|
| 30 | <font color="#004faf">Functions</font></a>
|
---|
| 31 | </td>
|
---|
| 32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>A Complete Application Window with Actions</h1>
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | <p>
|
---|
| 36 | <p> The <a href="qaction.html">QAction</a> class provides a way of associating user input from different
|
---|
| 37 | user interface elements with abstract high level actions. This approach makes
|
---|
| 38 | it easy to customize applications for different types of users.
|
---|
| 39 | <p> This example program is just like the
|
---|
| 40 | <a href="simple-application-example.html">application example</a>,
|
---|
| 41 | but uses QAction to build the menu and the toolbar.
|
---|
| 42 | <p> <hr>
|
---|
| 43 | <p> Header file:
|
---|
| 44 | <p> <pre>/****************************************************************************
|
---|
| 45 | ** $Id: qaction-application-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
| 46 | **
|
---|
| 47 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
| 48 | **
|
---|
| 49 | ** This file is part of an example program for Qt. This example
|
---|
| 50 | ** program may be used, distributed and modified without limitation.
|
---|
| 51 | **
|
---|
| 52 | *****************************************************************************/
|
---|
| 53 |
|
---|
| 54 | #ifndef APPLICATION_H
|
---|
| 55 | #define APPLICATION_H
|
---|
| 56 |
|
---|
| 57 | #include <<a href="qmainwindow-h.html">qmainwindow.h</a>>
|
---|
| 58 |
|
---|
| 59 | class QTextEdit;
|
---|
| 60 |
|
---|
| 61 | class ApplicationWindow: public <a href="qmainwindow.html">QMainWindow</a>
|
---|
| 62 | {
|
---|
| 63 | <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
|
---|
| 64 |
|
---|
| 65 | public:
|
---|
| 66 | ApplicationWindow();
|
---|
| 67 | ~ApplicationWindow();
|
---|
| 68 |
|
---|
| 69 | protected:
|
---|
| 70 | void closeEvent( <a href="qcloseevent.html">QCloseEvent</a>* );
|
---|
| 71 |
|
---|
| 72 | private slots:
|
---|
| 73 | void newDoc();
|
---|
| 74 | void choose();
|
---|
| 75 | void load( const <a href="qstring.html">QString</a> &fileName );
|
---|
| 76 | void save();
|
---|
| 77 | void saveAs();
|
---|
| 78 | void print();
|
---|
| 79 |
|
---|
| 80 | void about();
|
---|
| 81 | void aboutQt();
|
---|
| 82 |
|
---|
| 83 | private:
|
---|
| 84 | <a href="qprinter.html">QPrinter</a> *printer;
|
---|
| 85 | <a href="qtextedit.html">QTextEdit</a> *e;
|
---|
| 86 | <a href="qstring.html">QString</a> filename;
|
---|
| 87 | };
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 | #endif
|
---|
| 91 | </pre>
|
---|
| 92 |
|
---|
| 93 | <p> <hr>
|
---|
| 94 | <p> Implementation:
|
---|
| 95 | <p> <pre>/****************************************************************************
|
---|
| 96 | ** $Id: qaction-application-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
| 97 | **
|
---|
| 98 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
| 99 | **
|
---|
| 100 | ** This file is part of an example program for Qt. This example
|
---|
| 101 | ** program may be used, distributed and modified without limitation.
|
---|
| 102 | **
|
---|
| 103 | *****************************************************************************/
|
---|
| 104 |
|
---|
| 105 | #include "application.h"
|
---|
| 106 |
|
---|
| 107 | #include <<a href="qimage-h.html">qimage.h</a>>
|
---|
| 108 | #include <<a href="qpixmap-h.html">qpixmap.h</a>>
|
---|
| 109 | #include <<a href="qtoolbar-h.html">qtoolbar.h</a>>
|
---|
| 110 | #include <<a href="qtoolbutton-h.html">qtoolbutton.h</a>>
|
---|
| 111 | #include <<a href="qpopupmenu-h.html">qpopupmenu.h</a>>
|
---|
| 112 | #include <<a href="qmenubar-h.html">qmenubar.h</a>>
|
---|
| 113 | #include <<a href="qtextedit-h.html">qtextedit.h</a>>
|
---|
| 114 | #include <<a href="qfile-h.html">qfile.h</a>>
|
---|
| 115 | #include <<a href="qfiledialog-h.html">qfiledialog.h</a>>
|
---|
| 116 | #include <<a href="qstatusbar-h.html">qstatusbar.h</a>>
|
---|
| 117 | #include <<a href="qmessagebox-h.html">qmessagebox.h</a>>
|
---|
| 118 | #include <<a href="qprinter-h.html">qprinter.h</a>>
|
---|
| 119 | #include <<a href="qapplication-h.html">qapplication.h</a>>
|
---|
| 120 | #include <<a href="qaccel-h.html">qaccel.h</a>>
|
---|
| 121 | #include <<a href="qtextstream-h.html">qtextstream.h</a>>
|
---|
| 122 | #include <<a href="qpainter-h.html">qpainter.h</a>>
|
---|
| 123 | #include <<a href="qpaintdevicemetrics-h.html">qpaintdevicemetrics.h</a>>
|
---|
| 124 | #include <<a href="qwhatsthis-h.html">qwhatsthis.h</a>>
|
---|
| 125 | #include <<a href="qaction-h.html">qaction.h</a>>
|
---|
| 126 | #include <<a href="qsimplerichtext-h.html">qsimplerichtext.h</a>>
|
---|
| 127 |
|
---|
| 128 | #include "filesave.xpm"
|
---|
| 129 | #include "fileopen.xpm"
|
---|
| 130 | #include "fileprint.xpm"
|
---|
| 131 |
|
---|
| 132 |
|
---|
| 133 | <a name="f375"></a>ApplicationWindow::ApplicationWindow()
|
---|
| 134 | : <a href="qmainwindow.html">QMainWindow</a>( 0, "example application main window", WDestructiveClose )
|
---|
| 135 | {
|
---|
| 136 | printer = new <a href="qprinter.html">QPrinter</a>( QPrinter::HighResolution );
|
---|
| 137 |
|
---|
| 138 | <a href="qaction.html">QAction</a> * fileNewAction;
|
---|
| 139 | <a href="qaction.html">QAction</a> * fileOpenAction;
|
---|
| 140 | <a href="qaction.html">QAction</a> * fileSaveAction, * fileSaveAsAction, * filePrintAction;
|
---|
| 141 | <a href="qaction.html">QAction</a> * fileCloseAction, * fileQuitAction;
|
---|
| 142 |
|
---|
| 143 | fileNewAction = new <a href="qaction.html">QAction</a>( "&New", CTRL+Key_N, this, "new" );
|
---|
| 144 | <a name="x1123"></a> <a href="qobject.html#connect">connect</a>( fileNewAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ) , this,
|
---|
| 145 | SLOT( newDoc() ) );
|
---|
| 146 |
|
---|
| 147 | fileOpenAction = new <a href="qaction.html">QAction</a>( QPixmap( fileopen ), "&Open...",
|
---|
| 148 | CTRL+Key_O, this, "open" );
|
---|
| 149 | <a href="qobject.html#connect">connect</a>( fileOpenAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ) , this, SLOT( choose() ) );
|
---|
| 150 |
|
---|
| 151 | const char * fileOpenText = "<p><img source=\"fileopen\"> "
|
---|
| 152 | "Click this button to open a <em>new file</em>. <br>"
|
---|
| 153 | "You can also select the <b>Open</b> command "
|
---|
| 154 | "from the <b>File</b> menu.</p>";
|
---|
| 155 | <a name="x1140"></a> QMimeSourceFactory::<a href="qmimesourcefactory.html#defaultFactory">defaultFactory</a>()->setPixmap( "fileopen",
|
---|
| 156 | <a name="x1125"></a> fileOpenAction-><a href="qaction.html#iconSet">iconSet</a>().pixmap() );
|
---|
| 157 | <a name="x1126"></a> fileOpenAction-><a href="qaction.html#setWhatsThis">setWhatsThis</a>( fileOpenText );
|
---|
| 158 |
|
---|
| 159 | fileSaveAction = new <a href="qaction.html">QAction</a>( QPixmap( filesave ),
|
---|
| 160 | "&Save", CTRL+Key_S, this, "save" );
|
---|
| 161 | <a href="qobject.html#connect">connect</a>( fileSaveAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ) , this, SLOT( save() ) );
|
---|
| 162 |
|
---|
| 163 | const char * fileSaveText = "<p>Click this button to save the file you "
|
---|
| 164 | "are editing. You will be prompted for a file name.\n"
|
---|
| 165 | "You can also select the <b>Save</b> command "
|
---|
| 166 | "from the <b>File</b> menu.</p>";
|
---|
| 167 | fileSaveAction-><a href="qaction.html#setWhatsThis">setWhatsThis</a>( fileSaveText );
|
---|
| 168 |
|
---|
| 169 | fileSaveAsAction = new <a href="qaction.html">QAction</a>( "Save File As", "Save &As...", 0, this,
|
---|
| 170 | "save as" );
|
---|
| 171 | <a href="qobject.html#connect">connect</a>( fileSaveAsAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ) , this,
|
---|
| 172 | SLOT( saveAs() ) );
|
---|
| 173 | fileSaveAsAction-><a href="qaction.html#setWhatsThis">setWhatsThis</a>( fileSaveText );
|
---|
| 174 |
|
---|
| 175 | filePrintAction = new <a href="qaction.html">QAction</a>( "Print File", QPixmap( fileprint ),
|
---|
| 176 | "&Print...", CTRL+Key_P, this, "print" );
|
---|
| 177 | <a href="qobject.html#connect">connect</a>( filePrintAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ) , this,
|
---|
| 178 | SLOT( print() ) );
|
---|
| 179 |
|
---|
| 180 | const char * filePrintText = "Click this button to print the file you "
|
---|
| 181 | "are editing.\n You can also select the Print "
|
---|
| 182 | "command from the File menu.";
|
---|
| 183 | filePrintAction-><a href="qaction.html#setWhatsThis">setWhatsThis</a>( filePrintText );
|
---|
| 184 |
|
---|
| 185 | fileCloseAction = new <a href="qaction.html">QAction</a>( "Close", "&Close", CTRL+Key_W, this,
|
---|
| 186 | "close" );
|
---|
| 187 | <a href="qobject.html#connect">connect</a>( fileCloseAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ) , this,
|
---|
| 188 | SLOT( <a href="qwidget.html#close">close</a>() ) );
|
---|
| 189 |
|
---|
| 190 | fileQuitAction = new <a href="qaction.html">QAction</a>( "Quit", "&Quit", CTRL+Key_Q, this,
|
---|
| 191 | "quit" );
|
---|
| 192 | <a name="x1127"></a> <a href="qobject.html#connect">connect</a>( fileQuitAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ) , qApp,
|
---|
| 193 | SLOT( <a href="qapplication.html#closeAllWindows">closeAllWindows</a>() ) );
|
---|
| 194 |
|
---|
| 195 | // populate a tool bar with some actions
|
---|
| 196 |
|
---|
| 197 | <a href="qtoolbar.html">QToolBar</a> * fileTools = new <a href="qtoolbar.html">QToolBar</a>( this, "file operations" );
|
---|
| 198 | <a name="x1172"></a> fileTools-><a href="qtoolbar.html#setLabel">setLabel</a>( "File Operations" );
|
---|
| 199 | <a name="x1124"></a> fileOpenAction-><a href="qaction.html#addTo">addTo</a>( fileTools );
|
---|
| 200 | fileSaveAction-><a href="qaction.html#addTo">addTo</a>( fileTools );
|
---|
| 201 | filePrintAction-><a href="qaction.html#addTo">addTo</a>( fileTools );
|
---|
| 202 | (void)QWhatsThis::whatsThisButton( fileTools );
|
---|
| 203 |
|
---|
| 204 |
|
---|
| 205 | // populate a menu with all actions
|
---|
| 206 |
|
---|
| 207 | <a href="qpopupmenu.html">QPopupMenu</a> * file = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
|
---|
| 208 | <a href="qmainwindow.html#menuBar">menuBar</a>()->insertItem( "&File", file );
|
---|
| 209 | fileNewAction-><a href="qaction.html#addTo">addTo</a>( file );
|
---|
| 210 | fileOpenAction-><a href="qaction.html#addTo">addTo</a>( file );
|
---|
| 211 | fileSaveAction-><a href="qaction.html#addTo">addTo</a>( file );
|
---|
| 212 | fileSaveAsAction-><a href="qaction.html#addTo">addTo</a>( file );
|
---|
| 213 | file-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
| 214 | filePrintAction-><a href="qaction.html#addTo">addTo</a>( file );
|
---|
| 215 | file-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
| 216 | fileCloseAction-><a href="qaction.html#addTo">addTo</a>( file );
|
---|
| 217 | fileQuitAction-><a href="qaction.html#addTo">addTo</a>( file );
|
---|
| 218 |
|
---|
| 219 |
|
---|
| 220 | <a href="qmainwindow.html#menuBar">menuBar</a>()->insertSeparator();
|
---|
| 221 |
|
---|
| 222 | // add a help menu
|
---|
| 223 |
|
---|
| 224 | <a href="qpopupmenu.html">QPopupMenu</a> * help = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
|
---|
| 225 | <a href="qmainwindow.html#menuBar">menuBar</a>()->insertItem( "&Help", help );
|
---|
| 226 | help-><a href="qmenudata.html#insertItem">insertItem</a>( "&About", this, SLOT(about()), Key_F1 );
|
---|
| 227 | help-><a href="qmenudata.html#insertItem">insertItem</a>( "About &Qt", this, SLOT(aboutQt()) );
|
---|
| 228 | help-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
| 229 | help-><a href="qmenudata.html#insertItem">insertItem</a>( "What's &This", this, SLOT(<a href="qmainwindow.html#whatsThis">whatsThis</a>()),
|
---|
| 230 | SHIFT+Key_F1 );
|
---|
| 231 |
|
---|
| 232 |
|
---|
| 233 | // create and define the central widget
|
---|
| 234 |
|
---|
| 235 | e = new <a href="qtextedit.html">QTextEdit</a>( this, "editor" );
|
---|
| 236 | e-><a href="qwidget.html#setFocus">setFocus</a>();
|
---|
| 237 | <a href="qmainwindow.html#setCentralWidget">setCentralWidget</a>( e );
|
---|
| 238 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( "Ready", 2000 );
|
---|
| 239 |
|
---|
| 240 | <a href="qwidget.html#resize">resize</a>( 450, 600 );
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 |
|
---|
| 244 | ApplicationWindow::~ApplicationWindow()
|
---|
| 245 | {
|
---|
| 246 | delete printer;
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 |
|
---|
| 250 |
|
---|
| 251 | void <a name="f376"></a>ApplicationWindow::newDoc()
|
---|
| 252 | {
|
---|
| 253 | ApplicationWindow *ed = new ApplicationWindow;
|
---|
| 254 | ed-><a href="qwidget.html#show">show</a>();
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | void <a name="f377"></a>ApplicationWindow::choose()
|
---|
| 258 | {
|
---|
| 259 | <a name="x1132"></a> <a href="qstring.html">QString</a> fn = QFileDialog::<a href="qfiledialog.html#getOpenFileName">getOpenFileName</a>( <a href="qstring.html#QString-null">QString::null</a>, QString::null,
|
---|
| 260 | this);
|
---|
| 261 | if ( !fn.<a href="qstring.html#isEmpty">isEmpty</a>() )
|
---|
| 262 | load( fn );
|
---|
| 263 | else
|
---|
| 264 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( "Loading aborted", 2000 );
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 |
|
---|
| 268 | void <a name="f378"></a>ApplicationWindow::load( const <a href="qstring.html">QString</a> &fileName )
|
---|
| 269 | {
|
---|
| 270 | <a href="qfile.html">QFile</a> f( fileName );
|
---|
| 271 | if ( !f.<a href="qfile.html#open">open</a>( <a href="qfile.html#open">IO_ReadOnly</a> ) )
|
---|
| 272 | return;
|
---|
| 273 |
|
---|
| 274 | <a href="qtextstream.html">QTextStream</a> ts( &f );
|
---|
| 275 | <a name="x1171"></a><a name="x1168"></a> e-><a href="qtextedit.html#setText">setText</a>( ts.<a href="qtextstream.html#read">read</a>() );
|
---|
| 276 | <a name="x1167"></a> e-><a href="qtextedit.html#setModified">setModified</a>( FALSE );
|
---|
| 277 | <a href="qwidget.html#setCaption">setCaption</a>( fileName );
|
---|
| 278 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( "Loaded document " + fileName, 2000 );
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 |
|
---|
| 282 | void <a name="f379"></a>ApplicationWindow::save()
|
---|
| 283 | {
|
---|
| 284 | if ( filename.isEmpty() ) {
|
---|
| 285 | saveAs();
|
---|
| 286 | return;
|
---|
| 287 | }
|
---|
| 288 |
|
---|
| 289 | <a name="x1170"></a> <a href="qstring.html">QString</a> text = e-><a href="qtextedit.html#text">text</a>();
|
---|
| 290 | <a href="qfile.html">QFile</a> f( filename );
|
---|
| 291 | if ( !f.<a href="qfile.html#open">open</a>( <a href="qfile.html#open">IO_WriteOnly</a> ) ) {
|
---|
| 292 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( QString("Could not write to %1").arg(filename),
|
---|
| 293 | 2000 );
|
---|
| 294 | return;
|
---|
| 295 | }
|
---|
| 296 |
|
---|
| 297 | <a href="qtextstream.html">QTextStream</a> t( &f );
|
---|
| 298 | t << text;
|
---|
| 299 | f.<a href="qfile.html#close">close</a>();
|
---|
| 300 |
|
---|
| 301 | e-><a href="qtextedit.html#setModified">setModified</a>( FALSE );
|
---|
| 302 |
|
---|
| 303 | <a href="qwidget.html#setCaption">setCaption</a>( filename );
|
---|
| 304 |
|
---|
| 305 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( QString( "File %1 saved" ).arg( filename ), 2000 );
|
---|
| 306 | }
|
---|
| 307 |
|
---|
| 308 |
|
---|
| 309 | void <a name="f380"></a>ApplicationWindow::saveAs()
|
---|
| 310 | {
|
---|
| 311 | <a name="x1133"></a> <a href="qstring.html">QString</a> fn = QFileDialog::<a href="qfiledialog.html#getSaveFileName">getSaveFileName</a>( QString::null, QString::null,
|
---|
| 312 | this );
|
---|
| 313 | if ( !fn.<a href="qstring.html#isEmpty">isEmpty</a>() ) {
|
---|
| 314 | filename = fn;
|
---|
| 315 | save();
|
---|
| 316 | } else {
|
---|
| 317 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( "Saving aborted", 2000 );
|
---|
| 318 | }
|
---|
| 319 | }
|
---|
| 320 |
|
---|
| 321 |
|
---|
| 322 | void <a name="f381"></a>ApplicationWindow::print()
|
---|
| 323 | {
|
---|
| 324 | <a name="x1150"></a> printer-><a href="qprinter.html#setFullPage">setFullPage</a>( TRUE );
|
---|
| 325 | <a name="x1151"></a> if ( printer-><a href="qprinter.html#setup">setup</a>(this) ) { // printer dialog
|
---|
| 326 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( "Printing..." );
|
---|
| 327 | <a href="qpainter.html">QPainter</a> p;
|
---|
| 328 | if( !p.<a href="qpainter.html#begin">begin</a>( printer ) ) { // paint on printer
|
---|
| 329 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( "Printing aborted", 2000 );
|
---|
| 330 | return;
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 | <a name="x1145"></a> <a href="qpaintdevicemetrics.html">QPaintDeviceMetrics</a> metrics( p.<a href="qpainter.html#device">device</a>() );
|
---|
| 334 | <a name="x1142"></a> int dpiy = metrics.<a href="qpaintdevicemetrics.html#logicalDpiY">logicalDpiY</a>();
|
---|
| 335 | int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins
|
---|
| 336 | <a name="x1143"></a><a name="x1141"></a> <a href="qrect.html">QRect</a> view( margin, margin, metrics.<a href="qpaintdevicemetrics.html#width">width</a>() - 2*margin, metrics.<a href="qpaintdevicemetrics.html#height">height</a>() - 2*margin );
|
---|
| 337 | <a name="x1163"></a> <a href="qsimplerichtext.html">QSimpleRichText</a> richText( QStyleSheet::<a href="qstylesheet.html#convertFromPlainText">convertFromPlainText</a>(e-><a href="qtextedit.html#text">text</a>()),
|
---|
| 338 | QFont(),
|
---|
| 339 | <a name="x1164"></a> e-><a href="qtextedit.html#context">context</a>(),
|
---|
| 340 | <a name="x1169"></a> e-><a href="qtextedit.html#styleSheet">styleSheet</a>(),
|
---|
| 341 | <a name="x1166"></a> e-><a href="qtextedit.html#mimeSourceFactory">mimeSourceFactory</a>(),
|
---|
| 342 | view.<a href="qrect.html#height">height</a>() );
|
---|
| 343 | <a name="x1160"></a> richText.<a href="qsimplerichtext.html#setWidth">setWidth</a>( &p, view.<a href="qrect.html#width">width</a>() );
|
---|
| 344 | int page = 1;
|
---|
| 345 | do {
|
---|
| 346 | <a name="x1158"></a> richText.<a href="qsimplerichtext.html#draw">draw</a>( &p, margin, margin, view, colorGroup() );
|
---|
| 347 | <a name="x1154"></a> view.<a href="qrect.html#moveBy">moveBy</a>( 0, view.<a href="qrect.html#height">height</a>() );
|
---|
| 348 | <a name="x1148"></a> p.<a href="qpainter.html#translate">translate</a>( 0 , -view.<a href="qrect.html#height">height</a>() );
|
---|
| 349 | <a name="x1155"></a><a name="x1147"></a> p.<a href="qpainter.html#drawText">drawText</a>( view.<a href="qrect.html#right">right</a>() - p.<a href="qpainter.html#fontMetrics">fontMetrics</a>().width( QString::<a href="qstring.html#number">number</a>( page ) ),
|
---|
| 350 | <a name="x1152"></a> view.<a href="qrect.html#bottom">bottom</a>() + p.<a href="qpainter.html#fontMetrics">fontMetrics</a>().ascent() + 5, QString::number( page ) );
|
---|
| 351 | <a name="x1159"></a> if ( view.<a href="qrect.html#top">top</a>() - margin >= richText.<a href="qsimplerichtext.html#height">height</a>() )
|
---|
| 352 | break;
|
---|
| 353 | <a name="x1149"></a> printer-><a href="qprinter.html#newPage">newPage</a>();
|
---|
| 354 | page++;
|
---|
| 355 | } while (TRUE);
|
---|
| 356 |
|
---|
| 357 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( "Printing completed", 2000 );
|
---|
| 358 | } else {
|
---|
| 359 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( "Printing aborted", 2000 );
|
---|
| 360 | }
|
---|
| 361 | }
|
---|
| 362 |
|
---|
| 363 | <a name="x1173"></a>void ApplicationWindow::<a href="qwidget.html#closeEvent">closeEvent</a>( <a href="qcloseevent.html">QCloseEvent</a>* ce )
|
---|
| 364 | {
|
---|
| 365 | <a name="x1165"></a> if ( !e-><a href="qtextedit.html#isModified">isModified</a>() ) {
|
---|
| 366 | <a name="x1128"></a> ce-><a href="qcloseevent.html#accept">accept</a>();
|
---|
| 367 | return;
|
---|
| 368 | }
|
---|
| 369 |
|
---|
| 370 | <a name="x1139"></a> switch( QMessageBox::<a href="qmessagebox.html#information">information</a>( this, "Qt Application Example",
|
---|
| 371 | "The document has been changed since "
|
---|
| 372 | "the last save.",
|
---|
| 373 | "Save Now", "Cancel", "Leave Anyway",
|
---|
| 374 | 0, 1 ) ) {
|
---|
| 375 | case 0:
|
---|
| 376 | save();
|
---|
| 377 | ce-><a href="qcloseevent.html#accept">accept</a>();
|
---|
| 378 | break;
|
---|
| 379 | case 1:
|
---|
| 380 | default: // just for sanity
|
---|
| 381 | <a name="x1129"></a> ce-><a href="qcloseevent.html#ignore">ignore</a>();
|
---|
| 382 | break;
|
---|
| 383 | case 2:
|
---|
| 384 | ce-><a href="qcloseevent.html#accept">accept</a>();
|
---|
| 385 | break;
|
---|
| 386 | }
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 |
|
---|
| 390 | void <a name="f382"></a>ApplicationWindow::about()
|
---|
| 391 | {
|
---|
| 392 | <a name="x1137"></a> QMessageBox::<a href="qmessagebox.html#about">about</a>( this, "Qt Application Example",
|
---|
| 393 | "This example demonstrates simple use of "
|
---|
| 394 | "QMainWindow,\nQMenuBar and QToolBar.");
|
---|
| 395 | }
|
---|
| 396 |
|
---|
| 397 |
|
---|
| 398 | void <a name="f383"></a>ApplicationWindow::aboutQt()
|
---|
| 399 | {
|
---|
| 400 | <a name="x1138"></a> QMessageBox::<a href="qmessagebox.html#aboutQt">aboutQt</a>( this, "Qt Application Example" );
|
---|
| 401 | }
|
---|
| 402 | </pre>
|
---|
| 403 |
|
---|
| 404 | <p> <hr>
|
---|
| 405 | <p> Main:
|
---|
| 406 | <p> <pre>/****************************************************************************
|
---|
| 407 | ** $Id: qaction-application-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
| 408 | **
|
---|
| 409 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
| 410 | **
|
---|
| 411 | ** This file is part of an example program for Qt. This example
|
---|
| 412 | ** program may be used, distributed and modified without limitation.
|
---|
| 413 | **
|
---|
| 414 | *****************************************************************************/
|
---|
| 415 |
|
---|
| 416 | #include <<a href="qapplication-h.html">qapplication.h</a>>
|
---|
| 417 | #include "application.h"
|
---|
| 418 |
|
---|
| 419 | int main( int argc, char ** argv ) {
|
---|
| 420 | <a href="qapplication.html">QApplication</a> a( argc, argv );
|
---|
| 421 | ApplicationWindow * mw = new ApplicationWindow();
|
---|
| 422 | mw-><a href="qwidget.html#setCaption">setCaption</a>( "Document 1" );
|
---|
| 423 | <a name="x1178"></a> mw-><a href="qwidget.html#show">show</a>();
|
---|
| 424 | <a name="x1179"></a> a.<a href="qobject.html#connect">connect</a>( &a, SIGNAL(<a href="qapplication.html#lastWindowClosed">lastWindowClosed</a>()), &a, SLOT(<a href="qapplication.html#quit">quit</a>()) );
|
---|
| 425 | return a.<a href="qapplication.html#exec">exec</a>();
|
---|
| 426 | }
|
---|
| 427 | </pre>
|
---|
| 428 |
|
---|
| 429 | <p>See also <a href="qaction-examples.html">QAction Examples</a>.
|
---|
| 430 |
|
---|
| 431 | <!-- eof -->
|
---|
| 432 | <p><address><hr><div align=center>
|
---|
| 433 | <table width=100% cellspacing=0 border=0><tr>
|
---|
| 434 | <td>Copyright © 2007
|
---|
| 435 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
| 436 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
| 437 | </table></div></address></body>
|
---|
| 438 | </html>
|
---|