/usr/share/qt3/doc/html/mdi-example.html is in qt3-doc 3:3.3.8-b-8ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/mdi/mdi.doc:4 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>An MDI Application</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
<a href="index.html">
<font color="#004faf">Home</font></a>
| <a href="classes.html">
<font color="#004faf">All Classes</font></a>
| <a href="mainclasses.html">
<font color="#004faf">Main Classes</font></a>
| <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
| <a href="groups.html">
<font color="#004faf">Grouped Classes</font></a>
| <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>An MDI Application</h1>
<p>
This example program is just like the application example, except
that it provides a Multiple Document Interface (MDI).
<p> <hr>
<p> Header file:
<p> <pre>/****************************************************************************
** $Id: qt/application.h 3.3.8 edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
**
** This file is part of an example program for Qt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#ifndef APPLICATION_H
#define APPLICATION_H
#include <<a href="qmainwindow-h.html">qmainwindow.h</a>>
#include <<a href="qptrlist-h.html">qptrlist.h</a>>
class QTextEdit;
class QToolBar;
class QPopupMenu;
class QWorkspace;
class QPopupMenu;
class QMovie;
class MDIWindow: public <a href="qmainwindow.html">QMainWindow</a>
{
<a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
public:
MDIWindow( <a href="qwidget.html">QWidget</a>* parent, const char* name, int wflags );
~MDIWindow();
void load( const <a href="qstring.html">QString</a>& fn );
void save();
void saveAs();
void print( <a href="qprinter.html">QPrinter</a>* );
protected:
void closeEvent( <a href="qcloseevent.html">QCloseEvent</a> * );
signals:
void message(const <a href="qstring.html">QString</a>&, int );
private:
<a href="qtextedit.html">QTextEdit</a>* medit;
<a href="qmovie.html">QMovie</a> * mmovie;
<a href="qstring.html">QString</a> filename;
};
class ApplicationWindow: public <a href="qmainwindow.html">QMainWindow</a>
{
Q_OBJECT
public:
ApplicationWindow();
~ApplicationWindow();
protected:
void closeEvent( <a href="qcloseevent.html">QCloseEvent</a> * );
private slots:
MDIWindow* newDoc();
void load();
void save();
void saveAs();
void print();
void closeWindow();
void tileHorizontal();
void about();
void aboutQt();
void windowsMenuAboutToShow();
void windowsMenuActivated( int id );
private:
<a href="qprinter.html">QPrinter</a> *printer;
<a href="qworkspace.html">QWorkspace</a>* ws;
<a href="qtoolbar.html">QToolBar</a> *fileTools;
<a href="qpopupmenu.html">QPopupMenu</a>* windowsMenu;
};
#endif
</pre>
<p> <hr>
<p> Implementation:
<p> <pre>/****************************************************************************
** $Id: qt/application.cpp 3.3.8 edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
**
** This file is part of an example program for Qt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#include "application.h"
#include <<a href="qworkspace-h.html">qworkspace.h</a>>
#include <<a href="qimage-h.html">qimage.h</a>>
#include <<a href="qpixmap-h.html">qpixmap.h</a>>
#include <<a href="qtoolbar-h.html">qtoolbar.h</a>>
#include <<a href="qtoolbutton-h.html">qtoolbutton.h</a>>
#include <<a href="qpopupmenu-h.html">qpopupmenu.h</a>>
#include <<a href="qmenubar-h.html">qmenubar.h</a>>
#include <<a href="qmovie-h.html">qmovie.h</a>>
#include <<a href="qfile-h.html">qfile.h</a>>
#include <<a href="qfiledialog-h.html">qfiledialog.h</a>>
#include <<a href="qlabel-h.html">qlabel.h</a>>
#include <<a href="qstatusbar-h.html">qstatusbar.h</a>>
#include <<a href="qmessagebox-h.html">qmessagebox.h</a>>
#include <<a href="qprinter-h.html">qprinter.h</a>>
#include <<a href="qapplication-h.html">qapplication.h</a>>
#include <<a href="qpushbutton-h.html">qpushbutton.h</a>>
#include <<a href="qaccel-h.html">qaccel.h</a>>
#include <<a href="qtextstream-h.html">qtextstream.h</a>>
#include <<a href="qtextedit-h.html">qtextedit.h</a>>
#include <<a href="qpainter-h.html">qpainter.h</a>>
#include <<a href="qpaintdevicemetrics-h.html">qpaintdevicemetrics.h</a>>
#include <<a href="qwhatsthis-h.html">qwhatsthis.h</a>>
#include <<a href="qobjectlist-h.html">qobjectlist.h</a>>
#include <<a href="qvbox-h.html">qvbox.h</a>>
#include <<a href="qsimplerichtext-h.html">qsimplerichtext.h</a>>
#include "filesave.xpm"
#include "fileopen.xpm"
#include "fileprint.xpm"
const char * fileOpenText = "Click this button to open a <em>new file</em>. <br><br>"
"You can also select the <b>Open command</b> from the File menu.";
const char * fileSaveText = "Click this button to save the file you are "
"editing. You will be prompted for a file name.\n\n"
"You can also select the Save command from the File menu.\n\n"
"Note that implementing this function is left as an exercise for the reader.";
const char * filePrintText = "Click this button to print the file you "
"are editing.\n\n"
"You can also select the Print command from the File menu.";
<a name="f535"></a>ApplicationWindow::ApplicationWindow()
: <a href="qmainwindow.html">QMainWindow</a>( 0, "example application main window", WDestructiveClose )
{
int id;
<a href="qpixmap.html">QPixmap</a> openIcon, saveIcon;
fileTools = new <a href="qtoolbar.html">QToolBar</a>( this, "file operations" );
<a href="qmainwindow.html#addToolBar">addToolBar</a>( fileTools, tr( "File Operations" ), DockTop, TRUE );
openIcon = QPixmap( fileopen );
QToolButton * fileOpen
= new <a href="qtoolbutton.html">QToolButton</a>( openIcon, "Open File", <a href="qstring.html#QString-null">QString::null</a>,
this, SLOT(load()), fileTools, "open file" );
saveIcon = QPixmap( filesave );
QToolButton * fileSave
= new <a href="qtoolbutton.html">QToolButton</a>( saveIcon, "Save File", QString::null,
this, SLOT(save()), fileTools, "save file" );
#ifndef QT_NO_PRINTER
printer = new <a href="qprinter.html">QPrinter</a>( QPrinter::HighResolution );
<a href="qpixmap.html">QPixmap</a> printIcon;
printIcon = QPixmap( fileprint );
QToolButton * filePrint
= new <a href="qtoolbutton.html">QToolButton</a>( printIcon, "Print File", QString::null,
this, SLOT(print()), fileTools, "print file" );
<a name="x2075"></a> QWhatsThis::<a href="qwhatsthis.html#add">add</a>( filePrint, filePrintText );
#endif
(void)QWhatsThis::whatsThisButton( fileTools );
QWhatsThis::<a href="qwhatsthis.html#add">add</a>( fileOpen, fileOpenText );
QWhatsThis::<a href="qwhatsthis.html#add">add</a>( fileSave, fileSaveText );
<a href="qpopupmenu.html">QPopupMenu</a> * file = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
<a href="qmainwindow.html#menuBar">menuBar</a>()->insertItem( "&File", file );
file-><a href="qmenudata.html#insertItem">insertItem</a>( "&New", this, SLOT(newDoc()), CTRL+Key_N );
id = file-><a href="qmenudata.html#insertItem">insertItem</a>( openIcon, "&Open...",
this, SLOT(load()), CTRL+Key_O );
<a name="x2035"></a> file-><a href="qmenudata.html#setWhatsThis">setWhatsThis</a>( id, fileOpenText );
id = file-><a href="qmenudata.html#insertItem">insertItem</a>( saveIcon, "&Save",
this, SLOT(save()), CTRL+Key_S );
file-><a href="qmenudata.html#setWhatsThis">setWhatsThis</a>( id, fileSaveText );
id = file-><a href="qmenudata.html#insertItem">insertItem</a>( "Save &As...", this, SLOT(saveAs()) );
file-><a href="qmenudata.html#setWhatsThis">setWhatsThis</a>( id, fileSaveText );
#ifndef QT_NO_PRINTER
file-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
id = file-><a href="qmenudata.html#insertItem">insertItem</a>( printIcon, "&Print...",
this, SLOT(print()), CTRL+Key_P );
file-><a href="qmenudata.html#setWhatsThis">setWhatsThis</a>( id, filePrintText );
#endif
file-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
file-><a href="qmenudata.html#insertItem">insertItem</a>( "&Close", this, SLOT(closeWindow()), CTRL+Key_W );
<a name="x2020"></a> file-><a href="qmenudata.html#insertItem">insertItem</a>( "&Quit", qApp, SLOT( <a href="qapplication.html#closeAllWindows">closeAllWindows</a>() ), CTRL+Key_Q );
windowsMenu = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
<a name="x2049"></a> windowsMenu-><a href="qpopupmenu.html#setCheckable">setCheckable</a>( TRUE );
<a name="x2048"></a> <a href="qobject.html#connect">connect</a>( windowsMenu, SIGNAL( <a href="qpopupmenu.html#aboutToShow">aboutToShow</a>() ),
this, SLOT( windowsMenuAboutToShow() ) );
<a href="qmainwindow.html#menuBar">menuBar</a>()->insertItem( "&Windows", windowsMenu );
<a href="qmainwindow.html#menuBar">menuBar</a>()->insertSeparator();
<a href="qpopupmenu.html">QPopupMenu</a> * help = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
<a href="qmainwindow.html#menuBar">menuBar</a>()->insertItem( "&Help", help );
help-><a href="qmenudata.html#insertItem">insertItem</a>( "&About", this, SLOT(about()), Key_F1);
help-><a href="qmenudata.html#insertItem">insertItem</a>( "About &Qt", this, SLOT(aboutQt()));
help-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
help-><a href="qmenudata.html#insertItem">insertItem</a>( "What's &This", this, SLOT(<a href="qmainwindow.html#whatsThis">whatsThis</a>()), SHIFT+Key_F1);
<a href="qvbox.html">QVBox</a>* vb = new <a href="qvbox.html">QVBox</a>( this );
vb-><a href="qframe.html#setFrameStyle">setFrameStyle</a>( QFrame::StyledPanel | QFrame::Sunken );
ws = new <a href="qworkspace.html">QWorkspace</a>( vb );
<a name="x2092"></a> ws-><a href="qworkspace.html#setScrollBarsEnabled">setScrollBarsEnabled</a>( TRUE );
<a href="qmainwindow.html#setCentralWidget">setCentralWidget</a>( vb );
<a href="qmainwindow.html#statusBar">statusBar</a>()->message( "Ready", 2000 );
}
ApplicationWindow::~ApplicationWindow()
{
#ifndef QT_NO_PRINTER
delete printer;
#endif
}
MDIWindow* <a name="f536"></a>ApplicationWindow::newDoc()
{
MDIWindow* w = new MDIWindow( ws, 0, WDestructiveClose );
<a href="qobject.html#connect">connect</a>( w, SIGNAL( message(const <a href="qstring.html">QString</a>&, int) ), statusBar(), SLOT( message(const <a href="qstring.html">QString</a>&, int )) );
w-><a href="qwidget.html#setCaption">setCaption</a>("unnamed document");
<a name="x2085"></a> w-><a href="qwidget.html#setIcon">setIcon</a>( QPixmap("document.xpm") );
// show the very first window in maximized mode
<a name="x2094"></a> if ( ws-><a href="qworkspace.html#windowList">windowList</a>().isEmpty() )
<a name="x2087"></a> w-><a href="qwidget.html#showMaximized">showMaximized</a>();
else
w-><a href="qwidget.html#show">show</a>();
return w;
}
void <a name="f537"></a>ApplicationWindow::load()
{
<a href="qstring.html">QString</a> fn = QFileDialog::<a href="qfiledialog.html#getOpenFileName">getOpenFileName</a>( QString::null, QString::null, this );
if ( !fn.<a href="qstring.html#isEmpty">isEmpty</a>() ) {
MDIWindow* w = newDoc();
w->load( fn );
} else {
<a href="qmainwindow.html#statusBar">statusBar</a>()->message( "Loading aborted", 2000 );
}
}
void <a name="f538"></a>ApplicationWindow::save()
{
<a name="x2090"></a> MDIWindow* m = (MDIWindow*)ws-><a href="qworkspace.html#activeWindow">activeWindow</a>();
if ( m )
m->save();
}
void <a name="f539"></a>ApplicationWindow::saveAs()
{
MDIWindow* m = (MDIWindow*)ws-><a href="qworkspace.html#activeWindow">activeWindow</a>();
if ( m )
m->saveAs();
}
void <a name="f540"></a>ApplicationWindow::print()
{
#ifndef QT_NO_PRINTER
MDIWindow* m = (MDIWindow*)ws-><a href="qworkspace.html#activeWindow">activeWindow</a>();
if ( m )
m->print( printer );
#endif
}
void <a name="f541"></a>ApplicationWindow::closeWindow()
{
MDIWindow* m = (MDIWindow*)ws-><a href="qworkspace.html#activeWindow">activeWindow</a>();
if ( m )
<a name="x2076"></a> m-><a href="qwidget.html#close">close</a>();
}
void <a name="f542"></a>ApplicationWindow::about()
{
<a name="x2036"></a> QMessageBox::<a href="qmessagebox.html#about">about</a>( this, "Qt Application Example",
"This example demonstrates simple use of\n "
"Qt's Multiple Document Interface (MDI).");
}
void <a name="f543"></a>ApplicationWindow::aboutQt()
{
QMessageBox::<a href="qmessagebox.html#aboutQt">aboutQt</a>( this, "Qt Application Example" );
}
void <a name="f544"></a>ApplicationWindow::windowsMenuAboutToShow()
{
<a name="x2029"></a> windowsMenu-><a href="qmenudata.html#clear">clear</a>();
<a name="x2091"></a> int cascadeId = windowsMenu-><a href="qmenudata.html#insertItem">insertItem</a>("&Cascade", ws, SLOT(<a href="qworkspace.html#cascade">cascade</a>() ) );
<a name="x2093"></a> int tileId = windowsMenu-><a href="qmenudata.html#insertItem">insertItem</a>("&Tile", ws, SLOT(<a href="qworkspace.html#tile">tile</a>() ) );
int horTileId = windowsMenu-><a href="qmenudata.html#insertItem">insertItem</a>("Tile &Horizontally", this, SLOT(tileHorizontal() ) );
if ( ws-><a href="qworkspace.html#windowList">windowList</a>().isEmpty() ) {
<a name="x2033"></a> windowsMenu-><a href="qmenudata.html#setItemEnabled">setItemEnabled</a>( cascadeId, FALSE );
windowsMenu-><a href="qmenudata.html#setItemEnabled">setItemEnabled</a>( tileId, FALSE );
windowsMenu-><a href="qmenudata.html#setItemEnabled">setItemEnabled</a>( horTileId, FALSE );
}
windowsMenu-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
QWidgetList windows = ws-><a href="qworkspace.html#windowList">windowList</a>();
<a name="x2054"></a> for ( int i = 0; i < int(windows.count()); ++i ) {
<a name="x2053"></a> int id = windowsMenu-><a href="qmenudata.html#insertItem">insertItem</a>(windows.at(i)->caption(),
this, SLOT( windowsMenuActivated( int ) ) );
<a name="x2034"></a> windowsMenu-><a href="qmenudata.html#setItemParameter">setItemParameter</a>( id, i );
<a name="x2032"></a> windowsMenu-><a href="qmenudata.html#setItemChecked">setItemChecked</a>( id, ws-><a href="qworkspace.html#activeWindow">activeWindow</a>() == windows.at(i) );
}
}
void <a name="f545"></a>ApplicationWindow::windowsMenuActivated( int id )
{
<a href="qwidget.html">QWidget</a>* w = ws-><a href="qworkspace.html#windowList">windowList</a>().at( id );
if ( w )
<a name="x2088"></a> w-><a href="qwidget.html#showNormal">showNormal</a>();
<a name="x2084"></a> w-><a href="qwidget.html#setFocus">setFocus</a>();
}
void <a name="f546"></a>ApplicationWindow::tileHorizontal()
{
// primitive horizontal tiling
QWidgetList windows = ws-><a href="qworkspace.html#windowList">windowList</a>();
if ( !windows.count() )
return;
if (ws-><a href="qworkspace.html#activeWindow">activeWindow</a>())
ws-><a href="qworkspace.html#activeWindow">activeWindow</a>()->showNormal();
<a name="x2078"></a> int heightForEach = ws-><a href="qwidget.html#height">height</a>() / windows.count();
int y = 0;
for ( int i = 0; i < int(windows.count()); ++i ) {
<a href="qwidget.html">QWidget</a> *window = windows.at(i);
<a name="x2081"></a><a name="x2080"></a> int preferredHeight = window-><a href="qwidget.html#minimumHeight">minimumHeight</a>()+window-><a href="qwidget.html#parentWidget">parentWidget</a>()->baseSize().height();
int actHeight = QMAX(heightForEach, preferredHeight);
<a name="x2089"></a> window-><a href="qwidget.html#parentWidget">parentWidget</a>()->setGeometry( 0, y, ws-><a href="qwidget.html#width">width</a>(), actHeight );
y += actHeight;
}
}
<a name="x2077"></a>void ApplicationWindow::<a href="qwidget.html#closeEvent">closeEvent</a>( <a href="qcloseevent.html">QCloseEvent</a> *e )
{
QWidgetList windows = ws-><a href="qworkspace.html#windowList">windowList</a>();
if ( windows.count() ) {
for ( int i = 0; i < int(windows.count()); ++i ) {
<a href="qwidget.html">QWidget</a> *window = windows.at( i );
if ( !window-><a href="qwidget.html#close">close</a>() ) {
<a name="x2022"></a> e-><a href="qcloseevent.html#ignore">ignore</a>();
return;
}
}
}
QMainWindow::<a href="qwidget.html#closeEvent">closeEvent</a>( e );
}
<a name="f547"></a>MDIWindow::MDIWindow( <a href="qwidget.html">QWidget</a>* parent, const char* name, int wflags )
: <a href="qmainwindow.html">QMainWindow</a>( parent, name, wflags )
{
mmovie = 0;
medit = new <a href="qtextedit.html">QTextEdit</a>( this );
<a href="qwidget.html#setFocusProxy">setFocusProxy</a>( medit );
<a href="qmainwindow.html#setCentralWidget">setCentralWidget</a>( medit );
}
MDIWindow::~MDIWindow()
{
delete mmovie;
}
void MDIWindow::<a href="qwidget.html#closeEvent">closeEvent</a>( <a href="qcloseevent.html">QCloseEvent</a> *e )
{
<a name="x2069"></a> if ( medit-><a href="qtextedit.html#isModified">isModified</a>() ) {
switch( QMessageBox::<a href="qmessagebox.html#warning">warning</a>( this, "Save Changes",
<a href="qobject.html#tr">tr</a>("Save changes to %1?").arg( <a href="qwidget.html#caption">caption</a>() ),
<a href="qobject.html#tr">tr</a>("Yes"), tr("No"), tr("Cancel") ) ) {
case 0:
{
save();
if ( !filename.isEmpty() )
<a name="x2021"></a> e-><a href="qcloseevent.html#accept">accept</a>();
else
e-><a href="qcloseevent.html#ignore">ignore</a>();
}
break;
case 1:
e-><a href="qcloseevent.html#accept">accept</a>();
break;
default:
e-><a href="qcloseevent.html#ignore">ignore</a>();
break;
}
} else {
e-><a href="qcloseevent.html#accept">accept</a>();
}
}
void <a name="f548"></a>MDIWindow::load( const <a href="qstring.html">QString</a>& fn )
{
filename = fn;
<a href="qfile.html">QFile</a> f( filename );
if ( !f.<a href="qfile.html#open">open</a>( <a href="qfile.html#open">IO_ReadOnly</a> ) )
return;
<a name="x2064"></a> if(fn.<a href="qstring.html#contains">contains</a>(".gif")) {
<a href="qwidget.html">QWidget</a> * tmp=new <a href="qwidget.html">QWidget</a>(this);
<a href="qwidget.html#setFocusProxy">setFocusProxy</a>(tmp);
<a href="qmainwindow.html#setCentralWidget">setCentralWidget</a>(tmp);
<a name="x2079"></a> medit-><a href="qwidget.html#hide">hide</a>();
delete medit;
<a href="qmovie.html">QMovie</a> * qm=new <a href="qmovie.html">QMovie</a>(fn);
#ifdef Q_WS_QWS // temporary speed-test hack
<a name="x2039"></a> qm->setDisplayWidget(tmp);
#endif
<a name="x2082"></a> tmp-><a href="qwidget.html#setBackgroundMode">setBackgroundMode</a>(QWidget::NoBackground);
tmp-><a href="qwidget.html#show">show</a>();
mmovie=qm;
} else {
mmovie = 0;
<a href="qtextstream.html">QTextStream</a> t(&f);
<a name="x2074"></a> <a href="qstring.html">QString</a> s = t.<a href="qtextstream.html#read">read</a>();
medit-><a href="qtextedit.html#setText">setText</a>( s );
<a name="x2023"></a> f.<a href="qfile.html#close">close</a>();
}
<a href="qwidget.html#setCaption">setCaption</a>( filename );
emit message( QString("Loaded document %1").arg(filename), 2000 );
}
void <a name="f549"></a>MDIWindow::save()
{
if ( filename.isEmpty() ) {
saveAs();
return;
}
<a name="x2073"></a> <a href="qstring.html">QString</a> text = medit-><a href="qtextedit.html#text">text</a>();
<a href="qfile.html">QFile</a> f( filename );
if ( !f.<a href="qfile.html#open">open</a>( <a href="qfile.html#open">IO_WriteOnly</a> ) ) {
emit message( QString("Could not write to %1").arg(filename),
2000 );
return;
}
<a href="qtextstream.html">QTextStream</a> t( &f );
t << text;
f.<a href="qfile.html#close">close</a>();
<a href="qwidget.html#setCaption">setCaption</a>( filename );
emit message( QString( "File %1 saved" ).arg( filename ), 2000 );
}
void <a name="f550"></a>MDIWindow::saveAs()
{
<a href="qstring.html">QString</a> fn = QFileDialog::<a href="qfiledialog.html#getSaveFileName">getSaveFileName</a>( filename, QString::null, this );
if ( !fn.<a href="qstring.html#isEmpty">isEmpty</a>() ) {
filename = fn;
save();
} else {
emit message( "Saving aborted", 2000 );
}
}
void <a name="f551"></a>MDIWindow::print( <a href="qprinter.html">QPrinter</a>* printer)
{
#ifndef QT_NO_PRINTER
int pageNo = 1;
<a name="x2052"></a> if ( printer-><a href="qprinter.html#setup">setup</a>(this) ) { // printer dialog
<a name="x2051"></a> printer-><a href="qprinter.html#setFullPage">setFullPage</a>( TRUE );
emit message( "Printing...", 0 );
<a href="qpainter.html">QPainter</a> p;
if ( !p.<a href="qpainter.html#begin">begin</a>( printer ) )
return; // paint on printer
<a name="x2044"></a> <a href="qpaintdevicemetrics.html">QPaintDeviceMetrics</a> metrics( p.<a href="qpainter.html#device">device</a>() );
<a name="x2041"></a> int dpiy = metrics.<a href="qpaintdevicemetrics.html#logicalDpiY">logicalDpiY</a>();
int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins
<a name="x2042"></a><a name="x2040"></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 );
<a name="x2067"></a> <a href="qsimplerichtext.html">QSimpleRichText</a> richText( QStyleSheet::<a href="qstylesheet.html#convertFromPlainText">convertFromPlainText</a>(medit-><a href="qtextedit.html#text">text</a>()),
QFont(),
<a name="x2068"></a> medit-><a href="qtextedit.html#context">context</a>(),
<a name="x2072"></a> medit-><a href="qtextedit.html#styleSheet">styleSheet</a>(),
<a name="x2070"></a> medit-><a href="qtextedit.html#mimeSourceFactory">mimeSourceFactory</a>(),
view.<a href="qrect.html#height">height</a>() );
<a name="x2063"></a> richText.<a href="qsimplerichtext.html#setWidth">setWidth</a>( &p, view.<a href="qrect.html#width">width</a>() );
int page = 1;
do {
<a name="x2061"></a> richText.<a href="qsimplerichtext.html#draw">draw</a>( &p, margin, margin, view, colorGroup() );
<a name="x2057"></a> view.<a href="qrect.html#moveBy">moveBy</a>( 0, view.<a href="qrect.html#height">height</a>() );
p.<a href="qpainter.html#translate">translate</a>( 0 , -view.<a href="qrect.html#height">height</a>() );
<a name="x2066"></a><a name="x2046"></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 ) ),
view.<a href="qrect.html#bottom">bottom</a>() + p.<a href="qpainter.html#fontMetrics">fontMetrics</a>().ascent() + 5, QString::number( page ) );
<a name="x2062"></a> if ( view.<a href="qrect.html#top">top</a>() - margin >= richText.<a href="qsimplerichtext.html#height">height</a>() )
break;
<a href="qstring.html">QString</a> msg( "Printing (page " );
msg += QString::<a href="qstring.html#number">number</a>( ++pageNo );
msg += ")...";
emit message( msg, 0 );
<a name="x2050"></a> printer-><a href="qprinter.html#newPage">newPage</a>();
page++;
} while (TRUE);
}
#endif
}
</pre>
<p> <hr>
<p> Main:
<p> <pre>/****************************************************************************
** $Id: qt/main.cpp 3.3.8 edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
**
** This file is part of an example program for Qt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#include <<a href="qapplication-h.html">qapplication.h</a>>
#include "application.h"
int main( int argc, char ** argv ) {
<a href="qapplication.html">QApplication</a> a( argc, argv );
ApplicationWindow * mw = new ApplicationWindow();
a.<a href="qapplication.html#setMainWidget">setMainWidget</a>(mw);
mw-><a href="qwidget.html#setCaption">setCaption</a>( "Qt Example - Multiple Documents Interface (MDI)" );
mw-><a href="qwidget.html#show">show</a>();
<a name="x2097"></a><a name="x2096"></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>()) );
int res = a.<a href="qapplication.html#exec">exec</a>();
return res;
}
</pre>
<p>See also <a href="examples.html">Examples</a>.
<!-- eof -->
<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright © 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.8</div>
</table></div></address></body>
</html>
|