diff options
Diffstat (limited to 'doc/html/simple-application.html')
-rw-r--r-- | doc/html/simple-application.html | 94 |
1 files changed, 47 insertions, 47 deletions
diff --git a/doc/html/simple-application.html b/doc/html/simple-application.html index 8a92e7522..cb14ec9b9 100644 --- a/doc/html/simple-application.html +++ b/doc/html/simple-application.html @@ -34,7 +34,7 @@ body { background: #ffffff; color: black; } <p> -<p> This walkthrough shows simple use of <a href="ntqmainwindow.html">TQMainWindow</a>, <a href="ntqmenubar.html">TQMenuBar</a>, <a href="ntqpopupmenu.html">TQPopupMenu</a>, <a href="ntqtoolbar.html">TQToolBar</a> and <a href="ntqstatusbar.html">TQStatusBar</a> - classes that every +<p> This walkthrough shows simple use of <a href="tqmainwindow.html">TQMainWindow</a>, <a href="tqmenubar.html">TQMenuBar</a>, <a href="tqpopupmenu.html">TQPopupMenu</a>, <a href="tqtoolbar.html">TQToolBar</a> and <a href="tqstatusbar.html">TQStatusBar</a> - classes that every modern application window tends to use. (See also <a href="tutorial2.html">Tutorial #2</a>.) <p> It also illustrates some aspects of <a href="ntqwhatsthis.html">TQWhatsThis</a> (for simple help) and a typical <tt>main()</tt> using <a href="ntqapplication.html">TQApplication</a>. @@ -55,11 +55,11 @@ typical <tt>main()</tt> using <a href="ntqapplication.html">TQApplication</a>. #ifndef APPLICATION_H #define APPLICATION_H -#include <<a href="qmainwindow-h.html">ntqmainwindow.h</a>> +#include <<a href="tqmainwindow-h.html">tqmainwindow.h</a>> class TQTextEdit; -class ApplicationWindow: public <a href="ntqmainwindow.html">TQMainWindow</a> +class ApplicationWindow: public <a href="tqmainwindow.html">TQMainWindow</a> { <a href="metaobjects.html#TQ_OBJECT">TQ_OBJECT</a> @@ -91,7 +91,7 @@ private: #endif </pre> -<p> It declares a class that inherits <a href="ntqmainwindow.html">TQMainWindow</a>, with slots and private +<p> It declares a class that inherits <a href="tqmainwindow.html">TQMainWindow</a>, with slots and private variables. The class pre-declaration of <a href="tqtextedit.html">TQTextEdit</a> at the beginning (instead of an include) helps to speed up compilation. With this trick, <tt>make depend</tt> won't insist on recompiling every <tt>.cpp</tt> file that @@ -171,10 +171,10 @@ moved a program to a different location and wondered why icons were missing afterwards you will probably agree that it is a good idea to compile them into the binary. This is what we are doing here. <p> <pre> ApplicationWindow::ApplicationWindow() - : <a href="ntqmainwindow.html">TQMainWindow</a>( 0, "example application main window", WDestructiveClose | WGroupLeader ) + : <a href="tqmainwindow.html">TQMainWindow</a>( 0, "example application main window", WDestructiveClose | WGroupLeader ) { </pre> -<p> <em>ApplicationWindow</em> inherits <a href="ntqmainwindow.html">TQMainWindow</a>, the TQt class that provides +<p> <em>ApplicationWindow</em> inherits <a href="tqmainwindow.html">TQMainWindow</a>, the TQt class that provides typical application main windows, with menu bars, toolbars, etc. <p> <pre> printer = new <a href="ntqprinter.html">TQPrinter</a>( TQPrinter::HighResolution ); </pre> @@ -186,17 +186,17 @@ during one printing, the new setting will be the default next time. <p> For the sake of simplicity, our example only has a few commands in the toolbar. The above variables are used to hold an icon for each of them. -<p> <pre> <a href="ntqtoolbar.html">TQToolBar</a> * fileTools = new <a href="ntqtoolbar.html">TQToolBar</a>( this, "file operations" ); +<p> <pre> <a href="tqtoolbar.html">TQToolBar</a> * fileTools = new <a href="tqtoolbar.html">TQToolBar</a>( this, "file operations" ); </pre> <p> We create a toolbar in <em>this</em> window ... -<p> <pre> fileTools-><a href="ntqtoolbar.html#setLabel">setLabel</a>( "File Operations" ); +<p> <pre> fileTools-><a href="tqtoolbar.html#setLabel">setLabel</a>( "File Operations" ); </pre> <p> ... and define a title for it. When a user drags the toolbar out of its location and floats it over the desktop, the toolbar-window will show "File Operations" as caption. <p> <pre> openIcon = TQPixmap( fileopen ); TQToolButton * fileOpen - = new <a href="ntqtoolbutton.html">TQToolButton</a>( openIcon, "Open File", <a href="tqstring.html#TQString-null">TQString::null</a>, + = new <a href="tqtoolbutton.html">TQToolButton</a>( openIcon, "Open File", <a href="tqstring.html#TQString-null">TQString::null</a>, this, TQ_SLOT(choose()), fileTools, "open file" ); </pre> <p> Now we create the first tool button for the <em>fileTools</em> toolbar @@ -206,12 +206,12 @@ contains the definition of a pixmap called <em>fileopen</em>. We use this icon to illustrate our first tool button. <p> <pre> saveIcon = TQPixmap( filesave ); TQToolButton * fileSave - = new <a href="ntqtoolbutton.html">TQToolButton</a>( saveIcon, "Save File", TQString::null, + = new <a href="tqtoolbutton.html">TQToolButton</a>( saveIcon, "Save File", TQString::null, this, TQ_SLOT(save()), fileTools, "save file" ); printIcon = TQPixmap( fileprint ); TQToolButton * filePrint - = new <a href="ntqtoolbutton.html">TQToolButton</a>( printIcon, "Print File", TQString::null, + = new <a href="tqtoolbutton.html">TQToolButton</a>( printIcon, "Print File", TQString::null, this, TQ_SLOT(print()), fileTools, "print file" ); </pre> <p> In a similar way we create two more tool buttons in this toolbar, each with @@ -254,45 +254,45 @@ of pixmaps, therefore all we need to do is to add the help-text to the button. Be careful though: To invoke the rich-text elements in <tt>fileSaveText()</tt>, the entire string must be surrounded by <p> and </p>. In <tt>filePrintText()</tt>, we don't have rich-text elements, so this is not necessary. -<p> <pre> <a href="ntqpopupmenu.html">TQPopupMenu</a> * file = new <a href="ntqpopupmenu.html">TQPopupMenu</a>( this ); - <a href="ntqmainwindow.html#menuBar">menuBar</a>()->insertItem( "&File", file ); +<p> <pre> <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 ); </pre> -<p> Next we create a <a href="ntqpopupmenu.html">TQPopupMenu</a> for the <em>File</em> menu and +<p> Next we create a <a href="tqpopupmenu.html">TQPopupMenu</a> for the <em>File</em> menu and add it to the menu bar. With the ampersand in front of the letter F, we allow the user to use the shortcut <em>Alt+F</em> to pop up this menu. -<p> <pre> file-><a href="ntqmenudata.html#insertItem">insertItem</a>( "&New", this, TQ_SLOT(newDoc()), CTRL+Key_N ); +<p> <pre> file-><a href="tqmenudata.html#insertItem">insertItem</a>( "&New", this, TQ_SLOT(newDoc()), CTRL+Key_N ); </pre> <p> Its first entry is connected to the (yet to be implemented) slot <tt>newDoc()</tt>. When the user chooses this <em>New</em> entry (e.g. by typing the letter N as marked by the ampersand) or uses the <em>Ctrl+N</em> accelerator, a new editor-window will pop up. <p> <pre> int id; - id = file-><a href="ntqmenudata.html#insertItem">insertItem</a>( openIcon, "&Open...", + id = file-><a href="tqmenudata.html#insertItem">insertItem</a>( openIcon, "&Open...", this, TQ_SLOT(choose()), CTRL+Key_O ); - file-><a href="ntqmenudata.html#setWhatsThis">setWhatsThis</a>( id, fileOpenText ); + file-><a href="tqmenudata.html#setWhatsThis">setWhatsThis</a>( id, fileOpenText ); - id = file-><a href="ntqmenudata.html#insertItem">insertItem</a>( saveIcon, "&Save", + id = file-><a href="tqmenudata.html#insertItem">insertItem</a>( saveIcon, "&Save", this, TQ_SLOT(save()), CTRL+Key_S ); - file-><a href="ntqmenudata.html#setWhatsThis">setWhatsThis</a>( id, fileSaveText ); + file-><a href="tqmenudata.html#setWhatsThis">setWhatsThis</a>( id, fileSaveText ); - id = file-><a href="ntqmenudata.html#insertItem">insertItem</a>( "Save &As...", this, TQ_SLOT(saveAs()) ); - file-><a href="ntqmenudata.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 ); </pre> <p> We populate the <em>File</em> menu with three more commands (<em>Open</em>, <em>Save</em> and <em>Save As</em>), and set "What's This?" help for them. Note in particular that "What's This?" help and pixmaps are used in both the toolbar (above) -and the menu bar (here). (See <a href="ntqaction.html">TQAction</a> and the <tt>examples/action</tt> +and the menu bar (here). (See <a href="tqaction.html">TQAction</a> and the <tt>examples/action</tt> example for a shorter and easier approach.) -<p> <pre> file-><a href="ntqmenudata.html#insertSeparator">insertSeparator</a>(); +<p> <pre> file-><a href="tqmenudata.html#insertSeparator">insertSeparator</a>(); </pre> <p> Then we insert a separator, ... -<p> <pre> id = file-><a href="ntqmenudata.html#insertItem">insertItem</a>( printIcon, "&Print...", +<p> <pre> id = file-><a href="tqmenudata.html#insertItem">insertItem</a>( printIcon, "&Print...", this, TQ_SLOT(print()), CTRL+Key_P ); - file-><a href="ntqmenudata.html#setWhatsThis">setWhatsThis</a>( id, filePrintText ); + file-><a href="tqmenudata.html#setWhatsThis">setWhatsThis</a>( id, filePrintText ); - file-><a href="ntqmenudata.html#insertSeparator">insertSeparator</a>(); + file-><a href="tqmenudata.html#insertSeparator">insertSeparator</a>(); - file-><a href="ntqmenudata.html#insertItem">insertItem</a>( "&Close", this, TQ_SLOT(<a href="tqwidget.html#close">close</a>()), CTRL+Key_W ); - file-><a href="ntqmenudata.html#insertItem">insertItem</a>( "&Quit", tqApp, TQ_SLOT( <a href="ntqapplication.html#closeAllWindows">closeAllWindows</a>() ), CTRL+Key_Q ); + file-><a href="tqmenudata.html#insertItem">insertItem</a>( "&Close", this, TQ_SLOT(<a href="tqwidget.html#close">close</a>()), CTRL+Key_W ); + file-><a href="tqmenudata.html#insertItem">insertItem</a>( "&Quit", tqApp, TQ_SLOT( <a href="ntqapplication.html#closeAllWindows">closeAllWindows</a>() ), CTRL+Key_Q ); </pre> <p> ... the <em>Print</em> command with "What's This?" help, another separator and two more commands (<em>Close</em> and <em>Quit</em>) without "What's This?" and pixmaps. @@ -303,33 +303,33 @@ the <em>Quit</em> command affects the entire application. triggers a call to <a href="#closeEvent">closeEvent()</a> which we will implement later. <p> <a name="common_constructor"></a> -<pre> <a href="ntqmainwindow.html#menuBar">menuBar</a>()->insertSeparator(); +<pre> <a href="tqmainwindow.html#menuBar">menuBar</a>()->insertSeparator(); </pre> <p> Now that we have done the File menu we shift our focus back to the menu bar and insert a separator. From now on further menu bar entries will be aligned to the right if the windows system style requires it. -<p> <pre> <a href="ntqpopupmenu.html">TQPopupMenu</a> * help = new <a href="ntqpopupmenu.html">TQPopupMenu</a>( this ); - <a href="ntqmainwindow.html#menuBar">menuBar</a>()->insertItem( "&Help", help ); +<p> <pre> <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="ntqmenudata.html#insertItem">insertItem</a>( "&About", this, TQ_SLOT(about()), Key_F1 ); - help-><a href="ntqmenudata.html#insertItem">insertItem</a>( "About &TQt", this, TQ_SLOT(aboutTQt()) ); - help-><a href="ntqmenudata.html#insertSeparator">insertSeparator</a>(); - help-><a href="ntqmenudata.html#insertItem">insertItem</a>( "What's &This", this, TQ_SLOT(<a href="ntqmainwindow.html#whatsThis">whatsThis</a>()), SHIFT+Key_F1 ); + 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 ); </pre> <p> We create a <em>Help</em> menu, add it to the menu bar, and insert a few commands. Depending on the style it will appear on the right hand side of the menu bar or not. <p> <pre> e = new <a href="tqtextedit.html">TQTextEdit</a>( this, "editor" ); e-><a href="tqwidget.html#setFocus">setFocus</a>(); - <a href="ntqmainwindow.html#setCentralWidget">setCentralWidget</a>( e ); + <a href="tqmainwindow.html#setCentralWidget">setCentralWidget</a>( e ); </pre> <p> Now we create a simple text-editor, set the initial focus to it, and make it the window's central widget. -<p> <a href="ntqmainwindow.html#centralWidget">TQMainWindow::centralWidget</a>() is the heart of the entire application: +<p> <a href="tqmainwindow.html#centralWidget">TQMainWindow::centralWidget</a>() is the heart of the entire application: It's what menu bar, statusbar and toolbars are all arranged around. Since the central widget is a text editing widget, we can now reveal that our simple application is a text editor. :) -<p> <pre> <a href="ntqmainwindow.html#statusBar">statusBar</a>()->message( "Ready", 2000 ); +<p> <pre> <a href="tqmainwindow.html#statusBar">statusBar</a>()->message( "Ready", 2000 ); </pre> <p> We make the statusbar say "Ready" for two seconds at startup, just to tell the user that the window has finished initialization and can be @@ -369,7 +369,7 @@ new <em>ApplicationWindow</em> and shows it. if ( !fn.<a href="tqstring.html#isEmpty">isEmpty</a>() ) load( fn ); else - <a href="ntqmainwindow.html#statusBar">statusBar</a>()->message( "Loading aborted", 2000 ); + <a href="tqmainwindow.html#statusBar">statusBar</a>()->message( "Loading aborted", 2000 ); } </pre> <p> The <em>choose()</em> slot is connected to the <em>Open</em> menu item and @@ -386,7 +386,7 @@ error message in the statusbar. e-><a href="tqtextedit.html#setText">setText</a>( ts.<a href="tqtextstream.html#read">read</a>() ); e-><a href="tqtextedit.html#setModified">setModified</a>( FALSE ); <a href="tqwidget.html#setCaption">setCaption</a>( fileName ); - <a href="ntqmainwindow.html#statusBar">statusBar</a>()->message( "Loaded document " + fileName, 2000 ); + <a href="tqmainwindow.html#statusBar">statusBar</a>()->message( "Loaded document " + fileName, 2000 ); } </pre> <p> This function loads a file into the editor. When it's done, it sets the @@ -404,7 +404,7 @@ readable, nothing happens. <a href="tqstring.html">TQString</a> text = e-><a href="tqtextedit.html#text">text</a>(); <a href="ntqfile.html">TQFile</a> f( filename ); if ( !f.<a href="ntqfile.html#open">open</a>( <a href="ntqfile.html#open">IO_WriteOnly</a> ) ) { - <a href="ntqmainwindow.html#statusBar">statusBar</a>()->message( TQString("Could not write to %1").arg(filename), + <a href="tqmainwindow.html#statusBar">statusBar</a>()->message( TQString("Could not write to %1").arg(filename), 2000 ); return; } @@ -427,7 +427,7 @@ window without explicit saving, <a href="#closeEvent">ApplicationWindow::closeEv </pre> <p> It may be that the document was saved under a different name than the old caption suggests, so we set the window caption just to be sure. -<p> <pre> <a href="ntqmainwindow.html#statusBar">statusBar</a>()->message( TQString( "File %1 saved" ).arg( filename ), 2000 ); +<p> <pre> <a href="tqmainwindow.html#statusBar">statusBar</a>()->message( TQString( "File %1 saved" ).arg( filename ), 2000 ); } </pre> <p> With a message in the statusbar, we inform the user that the file @@ -441,7 +441,7 @@ was saved successfully. filename = fn; save(); } else { - <a href="ntqmainwindow.html#statusBar">statusBar</a>()->message( "Saving aborted", 2000 ); + <a href="tqmainwindow.html#statusBar">statusBar</a>()->message( "Saving aborted", 2000 ); } } </pre> @@ -452,10 +452,10 @@ and implicitly changes the window system caption to the new name. { printer-><a href="ntqprinter.html#setFullPage">setFullPage</a>( TRUE ); if ( printer-><a href="ntqprinter.html#setup">setup</a>(this) ) { // printer dialog - <a href="ntqmainwindow.html#statusBar">statusBar</a>()->message( "Printing..." ); + <a href="tqmainwindow.html#statusBar">statusBar</a>()->message( "Printing..." ); <a href="ntqpainter.html">TQPainter</a> p; if( !p.<a href="ntqpainter.html#begin">begin</a>( printer ) ) { // paint on printer - <a href="ntqmainwindow.html#statusBar">statusBar</a>()->message( "Printing aborted", 2000 ); + <a href="tqmainwindow.html#statusBar">statusBar</a>()->message( "Printing aborted", 2000 ); return; } @@ -483,9 +483,9 @@ and implicitly changes the window system caption to the new name. page++; } while (TRUE); - <a href="ntqmainwindow.html#statusBar">statusBar</a>()->message( "Printing completed", 2000 ); + <a href="tqmainwindow.html#statusBar">statusBar</a>()->message( "Printing completed", 2000 ); } else { - <a href="ntqmainwindow.html#statusBar">statusBar</a>()->message( "Printing aborted", 2000 ); + <a href="tqmainwindow.html#statusBar">statusBar</a>()->message( "Printing aborted", 2000 ); } } </pre> |