00001 #include <qaction.h>
00002 #include <qmenubar.h>
00003 #include <qtoolbar.h>
00004 #include <qlabel.h>
00005 #include <qpushbutton.h>
00006 #include <qlayout.h>
00007
00008 #include <qpe/qpeapplication.h>
00009 #include <qpe/sound.h>
00010
00011 #include <opie2/oapplicationfactory.h>
00012 #include <opie2/oresource.h>
00013 #include <opie2/otabwidget.h>
00014
00015 #include "simple.h"
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 using namespace Opie::Core;
00031 OPIE_EXPORT_APP( OApplicationFactory<MainWindow> )
00032
00033 MainWindow::MainWindow(QWidget *parent, const char* name, WFlags fl )
00034 : QMainWindow( parent, name, fl ) {
00035 setCaption(tr("My MainWindow") );
00036
00037 initUI();
00038
00039
00040
00041
00042
00043 Opie::Ui::OTabWidget *tab = new Opie::Ui::OTabWidget(this);
00044 connect(tab, SIGNAL(currentChanged(QWidget*) ),
00045 this, SLOT( slotCurrentChanged(QWidget*) ) );
00046 setCentralWidget( tab );
00047
00048 Simple1 *simple1 = new Simple1( this );
00049 tab->addTab( simple1, "new", tr("Simple1") );
00050 tab->setCurrentTab( tr("Simple1") );
00051
00052 Simple2 *simple2 = new Simple2( this );
00053 tab->addTab( simple2, "trash", tr("Simple2") );
00054
00055 m_oldCurrent = simple1;
00056
00057 connect(m_fire, SIGNAL(activated() ),
00058 simple1, SLOT(slotFire() ) );
00059 }
00060
00061 MainWindow::~MainWindow() {
00062
00063 }
00064
00065
00066 void MainWindow::setDocument( const QString& ) {
00067 }
00068 void MainWindow::slotCurrentChanged( QWidget *wid) {
00069 disconnect(m_fire, SIGNAL(activated() ),
00070 m_oldCurrent, SLOT(slotFire() ) );
00071 connect(m_fire, SIGNAL(activated() ),
00072 wid, SLOT(slotFire() ) );
00073
00074 m_oldCurrent = wid;
00075 }
00076
00077 void MainWindow::initUI() {
00078
00079 setToolBarsMovable( false );
00080
00081 QToolBar *menuBarHolder = new QToolBar( this );
00082
00083 menuBarHolder->setHorizontalStretchable( true );
00084 QMenuBar *mb = new QMenuBar( menuBarHolder );
00085 QToolBar *tb = new QToolBar( this );
00086
00087 QPopupMenu *fileMenu = new QPopupMenu( this );
00088
00089
00090 QAction *a = new QAction( tr("Quit"), Opie::Core::OResource::loadPixmap("quit_icon", Opie::Core::OResource::SmallIcon),
00091 QString::null, 0, this, "quit_action" );
00092
00093
00094
00095 connect(a, SIGNAL(activated() ),
00096 qApp, SLOT(quit() ) );
00097 a->addTo( fileMenu );
00098
00099 a = new QAction(tr("Fire"), Opie::Core::OResource::loadPixmap("new", Opie::Core::OResource::SmallIcon),
00100 QString::null, 0, this, "fire_button");
00101
00102
00103 a->addTo( fileMenu );
00104 a->addTo( tb );
00105 m_fire = a;
00106
00107
00108 mb->insertItem(tr("File"), fileMenu );
00109
00110 }
00111
00112 Simple1::Simple1( QWidget* parent, const char* name, WFlags fl )
00113 : QWidget( parent, name, fl ) {
00114
00115 QVBoxLayout *layout = new QVBoxLayout( this );
00116 layout->setSpacing( 8 );
00117 layout->setMargin( 11 );
00118
00119
00120 QLabel *lbl = new QLabel( this, "a name for the label" );
00121 lbl->setText( tr("Click on the button or follow the white rabbit") );
00122 layout->addWidget( lbl );
00123
00124
00125 m_button = new QPushButton(this);
00126
00127
00128 m_button->setText( tr("Fire", "translatable quit string" ) );
00129 layout->addWidget( m_button );
00130
00131
00132 connect( m_button, SIGNAL(clicked() ),
00133 this, SLOT( slotFire() ) );
00134 }
00135
00136 Simple1::~Simple1() {
00137
00138 }
00139
00140 void Simple1::slotFire() {
00141
00142
00143
00144
00145
00146 close();
00147 }
00148
00149
00150 Simple2::Simple2( QWidget* parent, const char* name, WFlags fl )
00151 : QWidget( parent, name, fl ) {
00152
00153
00154
00155
00156
00157 setCaption(tr("My Simple Application") );
00158
00159
00160
00161
00162
00163
00164 QVBoxLayout *layout = new QVBoxLayout( this );
00165 layout->setSpacing( 8 );
00166 layout->setMargin( 11 );
00167
00168
00169
00170
00171
00172
00173 QLabel *lbl = new QLabel( this, "a name for the label" );
00174
00175
00176
00177
00178
00179 lbl->setPixmap( Opie::Core::OResource::loadPixmap("logo/opielogo", Opie::Core::OResource::SmallIcon) );
00180 layout->addWidget( lbl );
00181
00182
00183
00184 m_button = new QPushButton(this);
00185
00186
00187
00188
00189 m_button->setText( tr("Fire", "translatable fire string" ) );
00190 layout->addWidget( m_button );
00191
00192
00193 connect( m_button, SIGNAL(clicked() ),
00194 this, SLOT( slotQuit() ) );
00195 }
00196
00197
00198 Simple2::~Simple2() {
00199
00200 }
00201
00202 void Simple2::slotFire() {
00203
00204
00205
00206
00207
00208
00209 Sound snd("hit_target01");
00210 snd.play();
00211
00212 }