From ea318d1431c89e647598c510c4245c6571aa5f46 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 26 Jan 2012 23:32:43 -0600 Subject: Update to latest tqt3 automated conversion --- doc/html/qaction-application-example.html | 282 +++++++++++++++--------------- 1 file changed, 141 insertions(+), 141 deletions(-) (limited to 'doc/html/qaction-application-example.html') diff --git a/doc/html/qaction-application-example.html b/doc/html/qaction-application-example.html index 2709e8633..d028aa83c 100644 --- a/doc/html/qaction-application-example.html +++ b/doc/html/qaction-application-example.html @@ -33,7 +33,7 @@ body { background: #ffffff; color: black; }

-

The TQAction class provides a way of associating user input from different +

The TQAction class provides a way of associating user input from different user interface elements with abstract high level actions. This approach makes it easy to customize applications for different types of users.

This example program is just like the @@ -54,11 +54,11 @@ but uses TQAction to build the menu and the toolbar. #ifndef APPLICATION_H #define APPLICATION_H -#include <qmainwindow.h> +#include <ntqmainwindow.h> class TQTextEdit; -class ApplicationWindow: public TQMainWindow +class ApplicationWindow: public TQMainWindow { Q_OBJECT @@ -72,7 +72,7 @@ protected: private slots: void newDoc(); void choose(); - void load( const TQString &fileName ); + void load( const TQString &fileName ); void save(); void saveAs(); void print(); @@ -81,9 +81,9 @@ private slots: void aboutTQt(); private: - TQPrinter *printer; - TQTextEdit *e; - TQString filename; + TQPrinter *printer; + TQTextEdit *e; + TQString filename; }; @@ -104,26 +104,26 @@ private: #include "application.h" -#include <qimage.h> -#include <qpixmap.h> -#include <qtoolbar.h> -#include <qtoolbutton.h> -#include <qpopupmenu.h> -#include <qmenubar.h> -#include <qtextedit.h> -#include <qfile.h> -#include <qfiledialog.h> -#include <qstatusbar.h> -#include <qmessagebox.h> -#include <qprinter.h> -#include <qapplication.h> -#include <qaccel.h> -#include <qtextstream.h> -#include <qpainter.h> -#include <qpaintdevicemetrics.h> -#include <qwhatsthis.h> -#include <qaction.h> -#include <qsimplerichtext.h> +#include <ntqimage.h> +#include <ntqpixmap.h> +#include <ntqtoolbar.h> +#include <ntqtoolbutton.h> +#include <ntqpopupmenu.h> +#include <ntqmenubar.h> +#include <ntqtextedit.h> +#include <ntqfile.h> +#include <ntqfiledialog.h> +#include <ntqstatusbar.h> +#include <ntqmessagebox.h> +#include <ntqprinter.h> +#include <ntqapplication.h> +#include <ntqaccel.h> +#include <ntqtextstream.h> +#include <ntqpainter.h> +#include <ntqpaintdevicemetrics.h> +#include <ntqwhatsthis.h> +#include <ntqaction.h> +#include <ntqsimplerichtext.h> #include "filesave.xpm" #include "fileopen.xpm" @@ -131,113 +131,113 @@ private: ApplicationWindow::ApplicationWindow() - : TQMainWindow( 0, "example application main window", WDestructiveClose ) + : TQMainWindow( 0, "example application main window", WDestructiveClose ) { - printer = new TQPrinter( TQPrinter::HighResolution ); + printer = new TQPrinter( TQPrinter::HighResolution ); - TQAction * fileNewAction; - TQAction * fileOpenAction; - TQAction * fileSaveAction, * fileSaveAsAction, * filePrintAction; - TQAction * fileCloseAction, * fileQuitAction; + TQAction * fileNewAction; + TQAction * fileOpenAction; + TQAction * fileSaveAction, * fileSaveAsAction, * filePrintAction; + TQAction * fileCloseAction, * fileQuitAction; - fileNewAction = new TQAction( "&New", CTRL+Key_N, this, "new" ); - connect( fileNewAction, SIGNAL( activated() ) , this, + fileNewAction = new TQAction( "&New", CTRL+Key_N, this, "new" ); + connect( fileNewAction, SIGNAL( activated() ) , this, SLOT( newDoc() ) ); - fileOpenAction = new TQAction( TQPixmap( fileopen ), "&Open...", + fileOpenAction = new TQAction( TQPixmap( fileopen ), "&Open...", CTRL+Key_O, this, "open" ); - connect( fileOpenAction, SIGNAL( activated() ) , this, SLOT( choose() ) ); + connect( fileOpenAction, SIGNAL( activated() ) , this, SLOT( choose() ) ); const char * fileOpenText = "<p><img source=\"fileopen\"> " "Click this button to open a <em>new file</em>. <br>" "You can also select the <b>Open</b> command " "from the <b>File</b> menu.</p>"; TQMimeSourceFactory::defaultFactory()->setPixmap( "fileopen", - fileOpenAction->iconSet().pixmap() ); - fileOpenAction->setWhatsThis( fileOpenText ); + fileOpenAction->iconSet().pixmap() ); + fileOpenAction->setWhatsThis( fileOpenText ); - fileSaveAction = new TQAction( TQPixmap( filesave ), + fileSaveAction = new TQAction( TQPixmap( filesave ), "&Save", CTRL+Key_S, this, "save" ); - connect( fileSaveAction, SIGNAL( activated() ) , this, SLOT( save() ) ); + connect( fileSaveAction, SIGNAL( activated() ) , this, SLOT( save() ) ); const char * fileSaveText = "<p>Click this button to save the file you " "are editing. You will be prompted for a file name.\n" "You can also select the <b>Save</b> command " "from the <b>File</b> menu.</p>"; - fileSaveAction->setWhatsThis( fileSaveText ); + fileSaveAction->setWhatsThis( fileSaveText ); - fileSaveAsAction = new TQAction( "Save File As", "Save &As...", 0, this, + fileSaveAsAction = new TQAction( "Save File As", "Save &As...", 0, this, "save as" ); - connect( fileSaveAsAction, SIGNAL( activated() ) , this, + connect( fileSaveAsAction, SIGNAL( activated() ) , this, SLOT( saveAs() ) ); - fileSaveAsAction->setWhatsThis( fileSaveText ); + fileSaveAsAction->setWhatsThis( fileSaveText ); - filePrintAction = new TQAction( "Print File", TQPixmap( fileprint ), + filePrintAction = new TQAction( "Print File", TQPixmap( fileprint ), "&Print...", CTRL+Key_P, this, "print" ); - connect( filePrintAction, SIGNAL( activated() ) , this, + connect( filePrintAction, SIGNAL( activated() ) , this, SLOT( print() ) ); const char * filePrintText = "Click this button to print the file you " "are editing.\n You can also select the Print " "command from the File menu."; - filePrintAction->setWhatsThis( filePrintText ); + filePrintAction->setWhatsThis( filePrintText ); - fileCloseAction = new TQAction( "Close", "&Close", CTRL+Key_W, this, + fileCloseAction = new TQAction( "Close", "&Close", CTRL+Key_W, this, "close" ); - connect( fileCloseAction, SIGNAL( activated() ) , this, - SLOT( close() ) ); + connect( fileCloseAction, SIGNAL( activated() ) , this, + SLOT( close() ) ); - fileQuitAction = new TQAction( "Quit", "&Quit", CTRL+Key_Q, this, + fileQuitAction = new TQAction( "Quit", "&Quit", CTRL+Key_Q, this, "quit" ); - connect( fileQuitAction, SIGNAL( activated() ) , qApp, - SLOT( closeAllWindows() ) ); + connect( fileQuitAction, SIGNAL( activated() ) , qApp, + SLOT( closeAllWindows() ) ); // populate a tool bar with some actions - TQToolBar * fileTools = new TQToolBar( this, "file operations" ); - fileTools->setLabel( "File Operations" ); - fileOpenAction->addTo( fileTools ); - fileSaveAction->addTo( fileTools ); - filePrintAction->addTo( fileTools ); + TQToolBar * fileTools = new TQToolBar( this, "file operations" ); + fileTools->setLabel( "File Operations" ); + fileOpenAction->addTo( fileTools ); + fileSaveAction->addTo( fileTools ); + filePrintAction->addTo( fileTools ); (void)TQWhatsThis::whatsThisButton( fileTools ); // populate a menu with all actions - TQPopupMenu * file = new TQPopupMenu( this ); - menuBar()->insertItem( "&File", file ); - fileNewAction->addTo( file ); - fileOpenAction->addTo( file ); - fileSaveAction->addTo( file ); - fileSaveAsAction->addTo( file ); - file->insertSeparator(); - filePrintAction->addTo( file ); - file->insertSeparator(); - fileCloseAction->addTo( file ); - fileQuitAction->addTo( file ); + TQPopupMenu * file = new TQPopupMenu( this ); + menuBar()->insertItem( "&File", file ); + fileNewAction->addTo( file ); + fileOpenAction->addTo( file ); + fileSaveAction->addTo( file ); + fileSaveAsAction->addTo( file ); + file->insertSeparator(); + filePrintAction->addTo( file ); + file->insertSeparator(); + fileCloseAction->addTo( file ); + fileQuitAction->addTo( file ); - menuBar()->insertSeparator(); + menuBar()->insertSeparator(); // add a help menu - TQPopupMenu * help = new TQPopupMenu( this ); - menuBar()->insertItem( "&Help", help ); - help->insertItem( "&About", this, SLOT(about()), Key_F1 ); - help->insertItem( "About &TQt", this, SLOT(aboutTQt()) ); - help->insertSeparator(); - help->insertItem( "What's &This", this, SLOT(whatsThis()), + TQPopupMenu * help = new TQPopupMenu( this ); + menuBar()->insertItem( "&Help", help ); + help->insertItem( "&About", this, SLOT(about()), Key_F1 ); + help->insertItem( "About &TQt", this, SLOT(aboutTQt()) ); + help->insertSeparator(); + help->insertItem( "What's &This", this, SLOT(whatsThis()), SHIFT+Key_F1 ); // create and define the central widget - e = new TQTextEdit( this, "editor" ); - e->setFocus(); - setCentralWidget( e ); - statusBar()->message( "Ready", 2000 ); + e = new TQTextEdit( this, "editor" ); + e->setFocus(); + setCentralWidget( e ); + statusBar()->message( "Ready", 2000 ); - resize( 450, 600 ); + resize( 450, 600 ); } @@ -251,31 +251,31 @@ ApplicationWindow::~ApplicationWindow() void ApplicationWindow::newDoc() { ApplicationWindow *ed = new ApplicationWindow; - ed->show(); + ed->show(); } void ApplicationWindow::choose() { - TQString fn = TQFileDialog::getOpenFileName( TQString::null, TQString::null, + TQString fn = TQFileDialog::getOpenFileName( TQString::null, TQString::null, this); - if ( !fn.isEmpty() ) + if ( !fn.isEmpty() ) load( fn ); else - statusBar()->message( "Loading aborted", 2000 ); + statusBar()->message( "Loading aborted", 2000 ); } -void ApplicationWindow::load( const TQString &fileName ) +void ApplicationWindow::load( const TQString &fileName ) { - TQFile f( fileName ); - if ( !f.open( IO_ReadOnly ) ) + TQFile f( fileName ); + if ( !f.open( IO_ReadOnly ) ) return; - TQTextStream ts( &f ); - e->setText( ts.read() ); - e->setModified( FALSE ); - setCaption( fileName ); - statusBar()->message( "Loaded document " + fileName, 2000 ); + TQTextStream ts( &f ); + e->setText( ts.read() ); + e->setModified( FALSE ); + setCaption( fileName ); + statusBar()->message( "Loaded document " + fileName, 2000 ); } @@ -286,88 +286,88 @@ void ApplicationWindow::save() return; } - TQString text = e->text(); - TQFile f( filename ); - if ( !f.open( IO_WriteOnly ) ) { - statusBar()->message( TQString("Could not write to %1").arg(filename), + TQString text = e->text(); + TQFile f( filename ); + if ( !f.open( IO_WriteOnly ) ) { + statusBar()->message( TQString("Could not write to %1").arg(filename), 2000 ); return; } - TQTextStream t( &f ); + TQTextStream t( &f ); t << text; - f.close(); + f.close(); - e->setModified( FALSE ); + e->setModified( FALSE ); - setCaption( filename ); + setCaption( filename ); - statusBar()->message( TQString( "File %1 saved" ).arg( filename ), 2000 ); + statusBar()->message( TQString( "File %1 saved" ).arg( filename ), 2000 ); } void ApplicationWindow::saveAs() { - TQString fn = TQFileDialog::getSaveFileName( TQString::null, TQString::null, + TQString fn = TQFileDialog::getSaveFileName( TQString::null, TQString::null, this ); - if ( !fn.isEmpty() ) { + if ( !fn.isEmpty() ) { filename = fn; save(); } else { - statusBar()->message( "Saving aborted", 2000 ); + statusBar()->message( "Saving aborted", 2000 ); } } void ApplicationWindow::print() { - printer->setFullPage( TRUE ); - if ( printer->setup(this) ) { // printer dialog - statusBar()->message( "Printing..." ); - TQPainter p; - if( !p.begin( printer ) ) { // paint on printer - statusBar()->message( "Printing aborted", 2000 ); + printer->setFullPage( TRUE ); + if ( printer->setup(this) ) { // printer dialog + statusBar()->message( "Printing..." ); + TQPainter p; + if( !p.begin( printer ) ) { // paint on printer + statusBar()->message( "Printing aborted", 2000 ); return; } - TQPaintDeviceMetrics metrics( p.device() ); - int dpiy = metrics.logicalDpiY(); + TQPaintDeviceMetrics metrics( p.device() ); + int dpiy = metrics.logicalDpiY(); int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins - TQRect view( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin ); - TQSimpleRichText richText( TQStyleSheet::convertFromPlainText(e->text()), + TQRect view( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin ); + TQSimpleRichText richText( TQStyleSheet::convertFromPlainText(e->text()), TQFont(), - e->context(), - e->styleSheet(), - e->mimeSourceFactory(), - view.height() ); - richText.setWidth( &p, view.width() ); + e->context(), + e->styleSheet(), + e->mimeSourceFactory(), + view.height() ); + richText.setWidth( &p, view.width() ); int page = 1; do { - richText.draw( &p, margin, margin, view, colorGroup() ); - view.moveBy( 0, view.height() ); - p.translate( 0 , -view.height() ); - p.drawText( view.right() - p.fontMetrics().width( TQString::number( page ) ), - view.bottom() + p.fontMetrics().ascent() + 5, TQString::number( page ) ); - if ( view.top() - margin >= richText.height() ) + richText.draw( &p, margin, margin, view, colorGroup() ); + view.moveBy( 0, view.height() ); + p.translate( 0 , -view.height() ); + p.drawText( view.right() - p.fontMetrics().width( TQString::number( page ) ), + view.bottom() + p.fontMetrics().ascent() + 5, TQString::number( page ) ); + if ( view.top() - margin >= richText.height() ) break; - printer->newPage(); + printer->newPage(); page++; } while (TRUE); - statusBar()->message( "Printing completed", 2000 ); + statusBar()->message( "Printing completed", 2000 ); } else { - statusBar()->message( "Printing aborted", 2000 ); + statusBar()->message( "Printing aborted", 2000 ); } } -void ApplicationWindow::closeEvent( TQCloseEvent* ce ) +void ApplicationWindow::closeEvent( TQCloseEvent* ce ) { - if ( !e->isModified() ) { + if ( !e->isModified() ) { ce->accept(); return; } - switch( TQMessageBox::information( this, "TQt Application Example", + switch( TQMessageBox::information( this, "TQt Application Example", "The document has been changed since " "the last save.", "Save Now", "Cancel", "Leave Anyway", @@ -389,7 +389,7 @@ void ApplicationWindow::print() void ApplicationWindow::about() { - TQMessageBox::about( this, "TQt Application Example", + TQMessageBox::about( this, "TQt Application Example", "This example demonstrates simple use of " "TQMainWindow,\nTQMenuBar and TQToolBar."); } @@ -397,7 +397,7 @@ void ApplicationWindow::about() void ApplicationWindow::aboutTQt() { - TQMessageBox::aboutTQt( this, "TQt Application Example" ); + TQMessageBox::aboutTQt( this, "TQt Application Example" ); } @@ -413,16 +413,16 @@ void ApplicationWindow::aboutTQt() ** *****************************************************************************/ -#include <qapplication.h> +#include <ntqapplication.h> #include "application.h" int main( int argc, char ** argv ) { - TQApplication a( argc, argv ); + TQApplication a( argc, argv ); ApplicationWindow * mw = new ApplicationWindow(); - mw->setCaption( "Document 1" ); - mw->show(); - a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) ); - return a.exec(); + mw->setCaption( "Document 1" ); + mw->show(); + a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) ); + return a.exec(); } -- cgit v1.2.3