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 #include <qpe/sound.h> // for playing a sound 00007 00008 #include <opie2/oapplicationfactory.h> // a template + macro to save the main method and allow quick launching 00009 #include <opie2/oresource.h> // for loading icon 00010 #include "simple.h" 00011 00012 /* 00013 * implementation of simple 00014 */ 00015 00016 /* 00017 * The factory is used for quicklaunching 00018 * 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 00019 * 00020 * Depending on the global quick launch setting this will create 00021 * either a main method or one for our component plugin system 00022 */ 00023 using namespace Opie::Core; 00024 OPIE_EXPORT_APP( OApplicationFactory<Simple> ) 00025 00026 Simple::Simple( QWidget* parent, const char* name, WFlags fl ) 00027 : QWidget( parent, name, fl ) { 00028 00029 /* 00030 * sets the caption of this toplevel widget 00031 * put all translatable string into tr() 00032 */ 00033 setCaption(tr("My Simple Application") ); 00034 00035 /* 00036 * A simple vertical layout 00037 * either call layout->setAutoAdd( true ) 00038 * or use layout->addWidget( wid ) to add widgets 00039 */ 00040 QVBoxLayout *layout = new QVBoxLayout( this ); 00041 layout->setSpacing( 8 ); 00042 layout->setMargin( 11 ); 00043 00044 /* 00045 * creates a label 00046 * The first parameter is this widget so the Label is a child 00047 * of us and will be deleted when we're deleted. 00048 */ 00049 QLabel *lbl = new QLabel( this, "a name for the label" ); 00050 /* 00051 * Resource will search hard for a Pixmap in $OPIEDIR/pics 00052 * to find 'logo/opielogo' You need to pass the subdir 00053 * but not the ending 00054 */ 00055 lbl->setPixmap( Opie::Core::OResource::loadPixmap("logo/opielogo", Opie::Core::OResource::SmallIcon) ); 00056 layout->addWidget( lbl ); 00057 00058 00059 /* creates a button as child of this widget */ 00060 m_button = new QPushButton(this); 00061 /* 00062 * another way to call tr. The first parameter is the string 00063 * to translate and the second a hint to the translator 00064 */ 00065 m_button->setText( tr("Fire", "translatable fire string" ) ); 00066 layout->addWidget( m_button ); 00067 00068 /* 00069 * Now we bring the action into it. The power of qt is the dynamic 00070 * signal and slots model 00071 * Usage is simple connect m_buttons clicked signal to our 00072 * slotQuit slot. 00073 * We could also have connected a SIGNAL to a SIGNAL or the clicked 00074 * signal directly to qApp and SLOT(quit() ) 00075 */ 00076 connect( m_button, SIGNAL(clicked() ), 00077 this, SLOT( slotQuit() ) ); 00078 } 00079 00080 /* 00081 * Our destructor is empty because all child 00082 * widgets and layouts will be deleted by Qt. 00083 * Same applies to QObjects 00084 */ 00085 Simple::~Simple() { 00086 00087 } 00088 00089 void Simple::slotQuit() { 00090 /* 00091 * We will fire up a sound 00092 * Note that Sound will use Resource as well 00093 * and we do not need to supply an ending 00094 * sounds are found in $OPIEDIR/sounds 00095 */ 00096 Sound snd("hit_target01"); 00097 snd.play(); 00098 00099 }
1.4.2