Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

simple.cpp

Go to the documentation of this file.
00001 #include <qlabel.h> // a label
00002 #include <qpushbutton.h> // the header file for the QPushButton
00003 #include <qlayout.h>
00004 
00005 #include <qpe/qpeapplication.h> // the QPEApplication
00006 
00007 #include <opie2/oapplicationfactory.h> // a template + macro to save the main method and allow quick launching
00008 
00009 #include "simple.h"
00010 
00011 /*
00012  * implementation of simple
00013  */
00014 
00015 /*
00016  * The factory is used for quicklaunching
00017  * It needs a constructor ( c'tor ) with at least QWidget, const char* and WFlags as parameter and a static QString appName() matching the TARGET of the .pro
00018  *
00019  * Depending on the global quick launch setting this will create
00020  * either a main method or one for our component plugin system
00021  */
00022 
00023 /* The OApplicationFactory is in Opie::Core */
00024 using namespace Opie::Core;
00025 OPIE_EXPORT_APP( OApplicationFactory<Simple> )
00026 
00027 Simple::Simple( QWidget* parent, const char* name,  WFlags fl )
00028     : QWidget( parent, name, fl ) {
00029 
00030     /*
00031      * sets the caption of this toplevel widget
00032      * put all translatable string into tr()
00033      */
00034     setCaption(tr("My Simple Application") );
00035 
00036     /*
00037      * A simple vertical layout
00038      * either call layout->setAutoAdd( true )
00039      * or use layout->addWidget( wid ) to add widgets
00040      */
00041     QVBoxLayout *layout = new QVBoxLayout( this );
00042     layout->setSpacing( 8 );
00043     layout->setMargin( 11 );
00044 
00045     /*
00046      * creates a label
00047      * The first parameter is this widget so the Label is a child
00048      * of us and will be deleted when we're deleted.
00049      */
00050     QLabel *lbl = new QLabel( this, "a name for the label" );
00051     lbl->setText( tr("Click on the button or follow the white rabbit") );
00052     layout->addWidget( lbl );
00053 
00054 
00055     /*  creates a button as child of this widget */
00056     m_button = new QPushButton(this);
00057     /*
00058      * another way to call tr. The first parameter is the string
00059      * to translate and the second a hint to the translator
00060      */
00061     m_button->setText( tr("Quit", "translatable quit string" ) );
00062     layout->addWidget( m_button );
00063 
00064     /*
00065      * Now we bring the action into it. The power of qt is the dynamic
00066      * signal and slots model
00067      * Usage is simple connect m_buttons clicked signal to  our
00068      * slotQuit slot.
00069      * We could also have connected a SIGNAL to a SIGNAL or the clicked
00070      * signal directly to qApp and SLOT(quit() )
00071      */
00072     connect( m_button, SIGNAL(clicked() ),
00073              this, SLOT( slotQuit() ) );
00074 }
00075 
00076 /*
00077  * Our destructor is empty because all child
00078  * widgets and layouts will be deleted by Qt.
00079  * Same applies to QObjects
00080  */
00081 Simple::~Simple() {
00082 
00083 }
00084 
00085 void Simple::slotQuit() {
00086     /*
00087      * we will close this window and Qt will recognize that
00088      * the last window was closed and initiate a shutdown
00089      */
00090     close();
00091 }

Generated on Sat Nov 5 16:15:58 2005 for OPIE by  doxygen 1.4.2