You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
597 lines
27 KiB
597 lines
27 KiB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<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 TQt. This example
|
|
** program may be used, distributed and modified without limitation.
|
|
**
|
|
*****************************************************************************/
|
|
|
|
#ifndef APPLICATION_H
|
|
#define APPLICATION_H
|
|
|
|
#include <<a href="tqmainwindow-h.html">tqmainwindow.h</a>>
|
|
#include <<a href="tqptrlist-h.html">tqptrlist.h</a>>
|
|
|
|
class TQTextEdit;
|
|
class TQToolBar;
|
|
class TQPopupMenu;
|
|
class TQWorkspace;
|
|
class TQPopupMenu;
|
|
class TQMovie;
|
|
|
|
class MDIWindow: public <a href="tqmainwindow.html">TQMainWindow</a>
|
|
{
|
|
<a href="metaobjects.html#TQ_OBJECT">TQ_OBJECT</a>
|
|
public:
|
|
MDIWindow( <a href="tqwidget.html">TQWidget</a>* parent, const char* name, int wflags );
|
|
~MDIWindow();
|
|
|
|
void load( const <a href="tqstring.html">TQString</a>& fn );
|
|
void save();
|
|
void saveAs();
|
|
void print( <a href="tqprinter.html">TQPrinter</a>* );
|
|
|
|
protected:
|
|
void closeEvent( <a href="tqcloseevent.html">TQCloseEvent</a> * );
|
|
|
|
signals:
|
|
void message(const <a href="tqstring.html">TQString</a>&, int );
|
|
|
|
private:
|
|
<a href="tqtextedit.html">TQTextEdit</a>* medit;
|
|
<a href="tqmovie.html">TQMovie</a> * mmovie;
|
|
<a href="tqstring.html">TQString</a> filename;
|
|
};
|
|
|
|
|
|
class ApplicationWindow: public <a href="tqmainwindow.html">TQMainWindow</a>
|
|
{
|
|
TQ_OBJECT
|
|
public:
|
|
ApplicationWindow();
|
|
~ApplicationWindow();
|
|
|
|
protected:
|
|
void closeEvent( <a href="tqcloseevent.html">TQCloseEvent</a> * );
|
|
|
|
private slots:
|
|
MDIWindow* newDoc();
|
|
void load();
|
|
void save();
|
|
void saveAs();
|
|
void print();
|
|
void closeWindow();
|
|
void tileHorizontal();
|
|
|
|
void about();
|
|
void aboutTQt();
|
|
|
|
void windowsMenuAboutToShow();
|
|
void windowsMenuActivated( int id );
|
|
|
|
private:
|
|
<a href="tqprinter.html">TQPrinter</a> *printer;
|
|
<a href="tqworkspace.html">TQWorkspace</a>* ws;
|
|
<a href="tqtoolbar.html">TQToolBar</a> *fileTools;
|
|
<a href="tqpopupmenu.html">TQPopupMenu</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 TQt. This example
|
|
** program may be used, distributed and modified without limitation.
|
|
**
|
|
*****************************************************************************/
|
|
|
|
#include "application.h"
|
|
#include <<a href="tqworkspace-h.html">tqworkspace.h</a>>
|
|
#include <<a href="tqimage-h.html">tqimage.h</a>>
|
|
#include <<a href="tqpixmap-h.html">tqpixmap.h</a>>
|
|
#include <<a href="tqtoolbar-h.html">tqtoolbar.h</a>>
|
|
#include <<a href="tqtoolbutton-h.html">tqtoolbutton.h</a>>
|
|
#include <<a href="tqpopupmenu-h.html">tqpopupmenu.h</a>>
|
|
#include <<a href="tqmenubar-h.html">tqmenubar.h</a>>
|
|
#include <<a href="tqmovie-h.html">tqmovie.h</a>>
|
|
#include <<a href="tqfile-h.html">tqfile.h</a>>
|
|
#include <<a href="tqfiledialog-h.html">tqfiledialog.h</a>>
|
|
#include <<a href="tqlabel-h.html">tqlabel.h</a>>
|
|
#include <<a href="tqstatusbar-h.html">tqstatusbar.h</a>>
|
|
#include <<a href="tqmessagebox-h.html">tqmessagebox.h</a>>
|
|
#include <<a href="tqprinter-h.html">tqprinter.h</a>>
|
|
#include <<a href="tqapplication-h.html">tqapplication.h</a>>
|
|
#include <<a href="tqpushbutton-h.html">tqpushbutton.h</a>>
|
|
#include <<a href="tqaccel-h.html">tqaccel.h</a>>
|
|
#include <<a href="tqtextstream-h.html">tqtextstream.h</a>>
|
|
#include <<a href="tqtextedit-h.html">tqtextedit.h</a>>
|
|
#include <<a href="tqpainter-h.html">tqpainter.h</a>>
|
|
#include <<a href="tqpaintdevicemetrics-h.html">tqpaintdevicemetrics.h</a>>
|
|
#include <<a href="tqwhatsthis-h.html">tqwhatsthis.h</a>>
|
|
#include <<a href="tqobjectlist-h.html">tqobjectlist.h</a>>
|
|
#include <<a href="tqvbox-h.html">tqvbox.h</a>>
|
|
#include <<a href="tqsimplerichtext-h.html">tqsimplerichtext.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="tqmainwindow.html">TQMainWindow</a>( 0, "example application main window", WDestructiveClose )
|
|
{
|
|
int id;
|
|
|
|
<a href="tqpixmap.html">TQPixmap</a> openIcon, saveIcon;
|
|
|
|
fileTools = new <a href="tqtoolbar.html">TQToolBar</a>( this, "file operations" );
|
|
<a href="tqmainwindow.html#addToolBar">addToolBar</a>( fileTools, tr( "File Operations" ), DockTop, TRUE );
|
|
|
|
openIcon = TQPixmap( fileopen );
|
|
TQToolButton * fileOpen
|
|
= new <a href="tqtoolbutton.html">TQToolButton</a>( openIcon, "Open File", <a href="tqstring.html#TQString-null">TQString::null</a>,
|
|
this, TQ_SLOT(load()), fileTools, "open file" );
|
|
|
|
saveIcon = TQPixmap( filesave );
|
|
TQToolButton * fileSave
|
|
= new <a href="tqtoolbutton.html">TQToolButton</a>( saveIcon, "Save File", TQString::null,
|
|
this, TQ_SLOT(save()), fileTools, "save file" );
|
|
|
|
#ifndef TQT_NO_PRINTER
|
|
printer = new <a href="tqprinter.html">TQPrinter</a>( TQPrinter::HighResolution );
|
|
<a href="tqpixmap.html">TQPixmap</a> printIcon;
|
|
|
|
printIcon = TQPixmap( fileprint );
|
|
TQToolButton * filePrint
|
|
= new <a href="tqtoolbutton.html">TQToolButton</a>( printIcon, "Print File", TQString::null,
|
|
this, TQ_SLOT(print()), fileTools, "print file" );
|
|
<a name="x2075"></a> TQWhatsThis::<a href="tqwhatsthis.html#add">add</a>( filePrint, filePrintText );
|
|
#endif
|
|
|
|
(void)TQWhatsThis::whatsThisButton( fileTools );
|
|
|
|
TQWhatsThis::<a href="tqwhatsthis.html#add">add</a>( fileOpen, fileOpenText );
|
|
TQWhatsThis::<a href="tqwhatsthis.html#add">add</a>( fileSave, fileSaveText );
|
|
|
|
<a href="tqpopupmenu.html">TQPopupMenu</a> * file = new <a href="tqpopupmenu.html">TQPopupMenu</a>( this );
|
|
<a href="tqmainwindow.html#menuBar">menuBar</a>()->insertItem( "&File", file );
|
|
|
|
file-><a href="tqmenudata.html#insertItem">insertItem</a>( "&New", this, TQ_SLOT(newDoc()), CTRL+Key_N );
|
|
|
|
id = file-><a href="tqmenudata.html#insertItem">insertItem</a>( openIcon, "&Open...",
|
|
this, TQ_SLOT(load()), CTRL+Key_O );
|
|
<a name="x2035"></a> file-><a href="tqmenudata.html#setWhatsThis">setWhatsThis</a>( id, fileOpenText );
|
|
|
|
id = file-><a href="tqmenudata.html#insertItem">insertItem</a>( saveIcon, "&Save",
|
|
this, TQ_SLOT(save()), CTRL+Key_S );
|
|
file-><a href="tqmenudata.html#setWhatsThis">setWhatsThis</a>( id, fileSaveText );
|
|
id = file-><a href="tqmenudata.html#insertItem">insertItem</a>( "Save &As...", this, TQ_SLOT(saveAs()) );
|
|
file-><a href="tqmenudata.html#setWhatsThis">setWhatsThis</a>( id, fileSaveText );
|
|
#ifndef TQT_NO_PRINTER
|
|
file-><a href="tqmenudata.html#insertSeparator">insertSeparator</a>();
|
|
id = file-><a href="tqmenudata.html#insertItem">insertItem</a>( printIcon, "&Print...",
|
|
this, TQ_SLOT(print()), CTRL+Key_P );
|
|
file-><a href="tqmenudata.html#setWhatsThis">setWhatsThis</a>( id, filePrintText );
|
|
#endif
|
|
file-><a href="tqmenudata.html#insertSeparator">insertSeparator</a>();
|
|
file-><a href="tqmenudata.html#insertItem">insertItem</a>( "&Close", this, TQ_SLOT(closeWindow()), CTRL+Key_W );
|
|
<a name="x2020"></a> file-><a href="tqmenudata.html#insertItem">insertItem</a>( "&Quit", tqApp, TQ_SLOT( <a href="tqapplication.html#closeAllWindows">closeAllWindows</a>() ), CTRL+Key_Q );
|
|
|
|
windowsMenu = new <a href="tqpopupmenu.html">TQPopupMenu</a>( this );
|
|
<a name="x2049"></a> windowsMenu-><a href="tqpopupmenu.html#setCheckable">setCheckable</a>( TRUE );
|
|
<a name="x2048"></a> <a href="tqobject.html#connect">connect</a>( windowsMenu, TQ_SIGNAL( <a href="tqpopupmenu.html#aboutToShow">aboutToShow</a>() ),
|
|
this, TQ_SLOT( windowsMenuAboutToShow() ) );
|
|
<a href="tqmainwindow.html#menuBar">menuBar</a>()->insertItem( "&Windows", windowsMenu );
|
|
|
|
<a href="tqmainwindow.html#menuBar">menuBar</a>()->insertSeparator();
|
|
<a href="tqpopupmenu.html">TQPopupMenu</a> * help = new <a href="tqpopupmenu.html">TQPopupMenu</a>( this );
|
|
<a href="tqmainwindow.html#menuBar">menuBar</a>()->insertItem( "&Help", help );
|
|
|
|
help-><a href="tqmenudata.html#insertItem">insertItem</a>( "&About", this, TQ_SLOT(about()), Key_F1);
|
|
help-><a href="tqmenudata.html#insertItem">insertItem</a>( "About &TQt", this, TQ_SLOT(aboutTQt()));
|
|
help-><a href="tqmenudata.html#insertSeparator">insertSeparator</a>();
|
|
help-><a href="tqmenudata.html#insertItem">insertItem</a>( "What's &This", this, TQ_SLOT(<a href="tqmainwindow.html#whatsThis">whatsThis</a>()), SHIFT+Key_F1);
|
|
|
|
<a href="tqvbox.html">TQVBox</a>* vb = new <a href="tqvbox.html">TQVBox</a>( this );
|
|
vb-><a href="tqframe.html#setFrameStyle">setFrameStyle</a>( TQFrame::StyledPanel | TQFrame::Sunken );
|
|
ws = new <a href="tqworkspace.html">TQWorkspace</a>( vb );
|
|
<a name="x2092"></a> ws-><a href="tqworkspace.html#setScrollBarsEnabled">setScrollBarsEnabled</a>( TRUE );
|
|
<a href="tqmainwindow.html#setCentralWidget">setCentralWidget</a>( vb );
|
|
|
|
<a href="tqmainwindow.html#statusBar">statusBar</a>()->message( "Ready", 2000 );
|
|
}
|
|
|
|
|
|
ApplicationWindow::~ApplicationWindow()
|
|
{
|
|
#ifndef TQT_NO_PRINTER
|
|
delete printer;
|
|
#endif
|
|
}
|
|
|
|
|
|
|
|
MDIWindow* <a name="f536"></a>ApplicationWindow::newDoc()
|
|
{
|
|
MDIWindow* w = new MDIWindow( ws, 0, WDestructiveClose );
|
|
<a href="tqobject.html#connect">connect</a>( w, TQ_SIGNAL( message(const <a href="tqstring.html">TQString</a>&, int) ), statusBar(), TQ_SLOT( message(const <a href="tqstring.html">TQString</a>&, int )) );
|
|
w-><a href="tqwidget.html#setCaption">setCaption</a>("unnamed document");
|
|
<a name="x2085"></a> w-><a href="tqwidget.html#setIcon">setIcon</a>( TQPixmap("document.xpm") );
|
|
// show the very first window in maximized mode
|
|
<a name="x2094"></a> if ( ws-><a href="tqworkspace.html#windowList">windowList</a>().isEmpty() )
|
|
<a name="x2087"></a> w-><a href="tqwidget.html#showMaximized">showMaximized</a>();
|
|
else
|
|
w-><a href="tqwidget.html#show">show</a>();
|
|
return w;
|
|
}
|
|
|
|
void <a name="f537"></a>ApplicationWindow::load()
|
|
{
|
|
<a href="tqstring.html">TQString</a> fn = TQFileDialog::<a href="tqfiledialog.html#getOpenFileName">getOpenFileName</a>( TQString::null, TQString::null, this );
|
|
if ( !fn.<a href="tqstring.html#isEmpty">isEmpty</a>() ) {
|
|
MDIWindow* w = newDoc();
|
|
w->load( fn );
|
|
} else {
|
|
<a href="tqmainwindow.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="tqworkspace.html#activeWindow">activeWindow</a>();
|
|
if ( m )
|
|
m->save();
|
|
}
|
|
|
|
|
|
void <a name="f539"></a>ApplicationWindow::saveAs()
|
|
{
|
|
MDIWindow* m = (MDIWindow*)ws-><a href="tqworkspace.html#activeWindow">activeWindow</a>();
|
|
if ( m )
|
|
m->saveAs();
|
|
}
|
|
|
|
|
|
void <a name="f540"></a>ApplicationWindow::print()
|
|
{
|
|
#ifndef TQT_NO_PRINTER
|
|
MDIWindow* m = (MDIWindow*)ws-><a href="tqworkspace.html#activeWindow">activeWindow</a>();
|
|
if ( m )
|
|
m->print( printer );
|
|
#endif
|
|
}
|
|
|
|
|
|
void <a name="f541"></a>ApplicationWindow::closeWindow()
|
|
{
|
|
MDIWindow* m = (MDIWindow*)ws-><a href="tqworkspace.html#activeWindow">activeWindow</a>();
|
|
if ( m )
|
|
<a name="x2076"></a> m-><a href="tqwidget.html#close">close</a>();
|
|
}
|
|
|
|
void <a name="f542"></a>ApplicationWindow::about()
|
|
{
|
|
<a name="x2036"></a> TQMessageBox::<a href="tqmessagebox.html#about">about</a>( this, "TQt Application Example",
|
|
"This example demonstrates simple use of\n "
|
|
"TQt's Multiple Document Interface (MDI).");
|
|
}
|
|
|
|
|
|
void <a name="f543"></a>ApplicationWindow::aboutTQt()
|
|
{
|
|
TQMessageBox::<a href="tqmessagebox.html#aboutTQt">aboutTQt</a>( this, "TQt Application Example" );
|
|
}
|
|
|
|
|
|
void <a name="f544"></a>ApplicationWindow::windowsMenuAboutToShow()
|
|
{
|
|
<a name="x2029"></a> windowsMenu-><a href="tqmenudata.html#clear">clear</a>();
|
|
<a name="x2091"></a> int cascadeId = windowsMenu-><a href="tqmenudata.html#insertItem">insertItem</a>("&Cascade", ws, TQ_SLOT(<a href="tqworkspace.html#cascade">cascade</a>() ) );
|
|
<a name="x2093"></a> int tileId = windowsMenu-><a href="tqmenudata.html#insertItem">insertItem</a>("&Tile", ws, TQ_SLOT(<a href="tqworkspace.html#tile">tile</a>() ) );
|
|
int horTileId = windowsMenu-><a href="tqmenudata.html#insertItem">insertItem</a>("Tile &Horizontally", this, TQ_SLOT(tileHorizontal() ) );
|
|
if ( ws-><a href="tqworkspace.html#windowList">windowList</a>().isEmpty() ) {
|
|
<a name="x2033"></a> windowsMenu-><a href="tqmenudata.html#setItemEnabled">setItemEnabled</a>( cascadeId, FALSE );
|
|
windowsMenu-><a href="tqmenudata.html#setItemEnabled">setItemEnabled</a>( tileId, FALSE );
|
|
windowsMenu-><a href="tqmenudata.html#setItemEnabled">setItemEnabled</a>( horTileId, FALSE );
|
|
}
|
|
windowsMenu-><a href="tqmenudata.html#insertSeparator">insertSeparator</a>();
|
|
TQWidgetList windows = ws-><a href="tqworkspace.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="tqmenudata.html#insertItem">insertItem</a>(windows.at(i)->caption(),
|
|
this, TQ_SLOT( windowsMenuActivated( int ) ) );
|
|
<a name="x2034"></a> windowsMenu-><a href="tqmenudata.html#setItemParameter">setItemParameter</a>( id, i );
|
|
<a name="x2032"></a> windowsMenu-><a href="tqmenudata.html#setItemChecked">setItemChecked</a>( id, ws-><a href="tqworkspace.html#activeWindow">activeWindow</a>() == windows.at(i) );
|
|
}
|
|
}
|
|
|
|
void <a name="f545"></a>ApplicationWindow::windowsMenuActivated( int id )
|
|
{
|
|
<a href="tqwidget.html">TQWidget</a>* w = ws-><a href="tqworkspace.html#windowList">windowList</a>().at( id );
|
|
if ( w )
|
|
<a name="x2088"></a> w-><a href="tqwidget.html#showNormal">showNormal</a>();
|
|
<a name="x2084"></a> w-><a href="tqwidget.html#setFocus">setFocus</a>();
|
|
}
|
|
|
|
void <a name="f546"></a>ApplicationWindow::tileHorizontal()
|
|
{
|
|
// primitive horizontal tiling
|
|
TQWidgetList windows = ws-><a href="tqworkspace.html#windowList">windowList</a>();
|
|
if ( !windows.count() )
|
|
return;
|
|
|
|
if (ws-><a href="tqworkspace.html#activeWindow">activeWindow</a>())
|
|
ws-><a href="tqworkspace.html#activeWindow">activeWindow</a>()->showNormal();
|
|
|
|
<a name="x2078"></a> int heightForEach = ws-><a href="tqwidget.html#height">height</a>() / windows.count();
|
|
int y = 0;
|
|
for ( int i = 0; i < int(windows.count()); ++i ) {
|
|
<a href="tqwidget.html">TQWidget</a> *window = windows.at(i);
|
|
<a name="x2081"></a><a name="x2080"></a> int preferredHeight = window-><a href="tqwidget.html#minimumHeight">minimumHeight</a>()+window-><a href="tqwidget.html#parentWidget">parentWidget</a>()->baseSize().height();
|
|
int actHeight = TQMAX(heightForEach, preferredHeight);
|
|
|
|
<a name="x2089"></a> window-><a href="tqwidget.html#parentWidget">parentWidget</a>()->setGeometry( 0, y, ws-><a href="tqwidget.html#width">width</a>(), actHeight );
|
|
y += actHeight;
|
|
}
|
|
}
|
|
|
|
<a name="x2077"></a>void ApplicationWindow::<a href="tqwidget.html#closeEvent">closeEvent</a>( <a href="tqcloseevent.html">TQCloseEvent</a> *e )
|
|
{
|
|
TQWidgetList windows = ws-><a href="tqworkspace.html#windowList">windowList</a>();
|
|
if ( windows.count() ) {
|
|
for ( int i = 0; i < int(windows.count()); ++i ) {
|
|
<a href="tqwidget.html">TQWidget</a> *window = windows.at( i );
|
|
if ( !window-><a href="tqwidget.html#close">close</a>() ) {
|
|
<a name="x2022"></a> e-><a href="tqcloseevent.html#ignore">ignore</a>();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
TQMainWindow::<a href="tqwidget.html#closeEvent">closeEvent</a>( e );
|
|
}
|
|
|
|
<a name="f547"></a>MDIWindow::MDIWindow( <a href="tqwidget.html">TQWidget</a>* parent, const char* name, int wflags )
|
|
: <a href="tqmainwindow.html">TQMainWindow</a>( parent, name, wflags )
|
|
{
|
|
mmovie = 0;
|
|
medit = new <a href="tqtextedit.html">TQTextEdit</a>( this );
|
|
<a href="tqwidget.html#setFocusProxy">setFocusProxy</a>( medit );
|
|
<a href="tqmainwindow.html#setCentralWidget">setCentralWidget</a>( medit );
|
|
}
|
|
|
|
MDIWindow::~MDIWindow()
|
|
{
|
|
delete mmovie;
|
|
}
|
|
|
|
void MDIWindow::<a href="tqwidget.html#closeEvent">closeEvent</a>( <a href="tqcloseevent.html">TQCloseEvent</a> *e )
|
|
{
|
|
<a name="x2069"></a> if ( medit-><a href="tqtextedit.html#isModified">isModified</a>() ) {
|
|
switch( TQMessageBox::<a href="tqmessagebox.html#warning">warning</a>( this, "Save Changes",
|
|
<a href="tqobject.html#tr">tr</a>("Save changes to %1?").arg( <a href="tqwidget.html#caption">caption</a>() ),
|
|
<a href="tqobject.html#tr">tr</a>("Yes"), tr("No"), tr("Cancel") ) ) {
|
|
case 0:
|
|
{
|
|
save();
|
|
if ( !filename.isEmpty() )
|
|
<a name="x2021"></a> e-><a href="tqcloseevent.html#accept">accept</a>();
|
|
else
|
|
e-><a href="tqcloseevent.html#ignore">ignore</a>();
|
|
}
|
|
break;
|
|
case 1:
|
|
e-><a href="tqcloseevent.html#accept">accept</a>();
|
|
break;
|
|
default:
|
|
e-><a href="tqcloseevent.html#ignore">ignore</a>();
|
|
break;
|
|
}
|
|
} else {
|
|
e-><a href="tqcloseevent.html#accept">accept</a>();
|
|
}
|
|
}
|
|
|
|
void <a name="f548"></a>MDIWindow::load( const <a href="tqstring.html">TQString</a>& fn )
|
|
{
|
|
filename = fn;
|
|
<a href="tqfile.html">TQFile</a> f( filename );
|
|
if ( !f.<a href="tqfile.html#open">open</a>( <a href="tqfile.html#open">IO_ReadOnly</a> ) )
|
|
return;
|
|
|
|
<a name="x2064"></a> if(fn.<a href="tqstring.html#contains">contains</a>(".gif")) {
|
|
<a href="tqwidget.html">TQWidget</a> * tmp=new <a href="tqwidget.html">TQWidget</a>(this);
|
|
<a href="tqwidget.html#setFocusProxy">setFocusProxy</a>(tmp);
|
|
<a href="tqmainwindow.html#setCentralWidget">setCentralWidget</a>(tmp);
|
|
<a name="x2079"></a> medit-><a href="tqwidget.html#hide">hide</a>();
|
|
delete medit;
|
|
<a href="tqmovie.html">TQMovie</a> * qm=new <a href="tqmovie.html">TQMovie</a>(fn);
|
|
<a name="x2082"></a> tmp-><a href="tqwidget.html#setBackgroundMode">setBackgroundMode</a>(TQWidget::NoBackground);
|
|
tmp-><a href="tqwidget.html#show">show</a>();
|
|
mmovie=qm;
|
|
} else {
|
|
mmovie = 0;
|
|
|
|
<a href="tqtextstream.html">TQTextStream</a> t(&f);
|
|
<a name="x2074"></a> <a href="tqstring.html">TQString</a> s = t.<a href="tqtextstream.html#read">read</a>();
|
|
medit-><a href="tqtextedit.html#setText">setText</a>( s );
|
|
<a name="x2023"></a> f.<a href="tqfile.html#close">close</a>();
|
|
|
|
|
|
}
|
|
<a href="tqwidget.html#setCaption">setCaption</a>( filename );
|
|
emit message( TQString("Loaded document %1").arg(filename), 2000 );
|
|
}
|
|
|
|
void <a name="f549"></a>MDIWindow::save()
|
|
{
|
|
if ( filename.isEmpty() ) {
|
|
saveAs();
|
|
return;
|
|
}
|
|
|
|
<a name="x2073"></a> <a href="tqstring.html">TQString</a> text = medit-><a href="tqtextedit.html#text">text</a>();
|
|
<a href="tqfile.html">TQFile</a> f( filename );
|
|
if ( !f.<a href="tqfile.html#open">open</a>( <a href="tqfile.html#open">IO_WriteOnly</a> ) ) {
|
|
emit message( TQString("Could not write to %1").arg(filename),
|
|
2000 );
|
|
return;
|
|
}
|
|
|
|
<a href="tqtextstream.html">TQTextStream</a> t( &f );
|
|
t << text;
|
|
f.<a href="tqfile.html#close">close</a>();
|
|
|
|
<a href="tqwidget.html#setCaption">setCaption</a>( filename );
|
|
|
|
emit message( TQString( "File %1 saved" ).arg( filename ), 2000 );
|
|
}
|
|
|
|
void <a name="f550"></a>MDIWindow::saveAs()
|
|
{
|
|
<a href="tqstring.html">TQString</a> fn = TQFileDialog::<a href="tqfiledialog.html#getSaveFileName">getSaveFileName</a>( filename, TQString::null, this );
|
|
if ( !fn.<a href="tqstring.html#isEmpty">isEmpty</a>() ) {
|
|
filename = fn;
|
|
save();
|
|
} else {
|
|
emit message( "Saving aborted", 2000 );
|
|
}
|
|
}
|
|
|
|
void <a name="f551"></a>MDIWindow::print( <a href="tqprinter.html">TQPrinter</a>* printer)
|
|
{
|
|
#ifndef TQT_NO_PRINTER
|
|
int pageNo = 1;
|
|
|
|
<a name="x2052"></a> if ( printer-><a href="tqprinter.html#setup">setup</a>(this) ) { // printer dialog
|
|
<a name="x2051"></a> printer-><a href="tqprinter.html#setFullPage">setFullPage</a>( TRUE );
|
|
emit message( "Printing...", 0 );
|
|
<a href="tqpainter.html">TQPainter</a> p;
|
|
if ( !p.<a href="tqpainter.html#begin">begin</a>( printer ) )
|
|
return; // paint on printer
|
|
<a name="x2044"></a> <a href="tqpaintdevicemetrics.html">TQPaintDeviceMetrics</a> metrics( p.<a href="tqpainter.html#device">device</a>() );
|
|
<a name="x2041"></a> int dpiy = metrics.<a href="tqpaintdevicemetrics.html#logicalDpiY">logicalDpiY</a>();
|
|
int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins
|
|
<a name="x2042"></a><a name="x2040"></a> <a href="tqrect.html">TQRect</a> view( margin, margin, metrics.<a href="tqpaintdevicemetrics.html#width">width</a>() - 2*margin, metrics.<a href="tqpaintdevicemetrics.html#height">height</a>() - 2*margin );
|
|
<a name="x2067"></a> <a href="tqsimplerichtext.html">TQSimpleRichText</a> richText( TQStyleSheet::<a href="tqstylesheet.html#convertFromPlainText">convertFromPlainText</a>(medit-><a href="tqtextedit.html#text">text</a>()),
|
|
TQFont(),
|
|
<a name="x2068"></a> medit-><a href="tqtextedit.html#context">context</a>(),
|
|
<a name="x2072"></a> medit-><a href="tqtextedit.html#styleSheet">styleSheet</a>(),
|
|
<a name="x2070"></a> medit-><a href="tqtextedit.html#mimeSourceFactory">mimeSourceFactory</a>(),
|
|
view.<a href="tqrect.html#height">height</a>() );
|
|
<a name="x2063"></a> richText.<a href="tqsimplerichtext.html#setWidth">setWidth</a>( &p, view.<a href="tqrect.html#width">width</a>() );
|
|
int page = 1;
|
|
do {
|
|
<a name="x2061"></a> richText.<a href="tqsimplerichtext.html#draw">draw</a>( &p, margin, margin, view, colorGroup() );
|
|
<a name="x2057"></a> view.<a href="tqrect.html#moveBy">moveBy</a>( 0, view.<a href="tqrect.html#height">height</a>() );
|
|
p.<a href="tqpainter.html#translate">translate</a>( 0 , -view.<a href="tqrect.html#height">height</a>() );
|
|
<a name="x2066"></a><a name="x2046"></a> p.<a href="tqpainter.html#drawText">drawText</a>( view.<a href="tqrect.html#right">right</a>() - p.<a href="tqpainter.html#fontMetrics">fontMetrics</a>().width( TQString::<a href="tqstring.html#number">number</a>( page ) ),
|
|
view.<a href="tqrect.html#bottom">bottom</a>() + p.<a href="tqpainter.html#fontMetrics">fontMetrics</a>().ascent() + 5, TQString::number( page ) );
|
|
<a name="x2062"></a> if ( view.<a href="tqrect.html#top">top</a>() - margin >= richText.<a href="tqsimplerichtext.html#height">height</a>() )
|
|
break;
|
|
<a href="tqstring.html">TQString</a> msg( "Printing (page " );
|
|
msg += TQString::<a href="tqstring.html#number">number</a>( ++pageNo );
|
|
msg += ")...";
|
|
emit message( msg, 0 );
|
|
<a name="x2050"></a> printer-><a href="tqprinter.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 TQt. This example
|
|
** program may be used, distributed and modified without limitation.
|
|
**
|
|
*****************************************************************************/
|
|
|
|
#include <<a href="tqapplication-h.html">tqapplication.h</a>>
|
|
#include "application.h"
|
|
|
|
int main( int argc, char ** argv ) {
|
|
<a href="tqapplication.html">TQApplication</a> a( argc, argv );
|
|
ApplicationWindow * mw = new ApplicationWindow();
|
|
a.<a href="tqapplication.html#setMainWidget">setMainWidget</a>(mw);
|
|
mw-><a href="tqwidget.html#setCaption">setCaption</a>( "TQt Example - Multiple Documents Interface (MDI)" );
|
|
mw-><a href="tqwidget.html#show">show</a>();
|
|
<a name="x2097"></a><a name="x2096"></a> a.<a href="tqobject.html#connect">connect</a>( &a, TQ_SIGNAL(<a href="tqapplication.html#lastWindowClosed">lastWindowClosed</a>()), &a, TQ_SLOT(<a href="tqapplication.html#quit">quit</a>()) );
|
|
int res = a.<a href="tqapplication.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>TQt 3.3.8</div>
|
|
</table></div></address></body>
|
|
</html>
|