summaryrefslogtreecommitdiff
path: root/examples/main-tab
Unidiff
Diffstat (limited to 'examples/main-tab') (more/less context) (ignore whitespace changes)
-rw-r--r--examples/main-tab/config.in4
-rw-r--r--examples/main-tab/example.pro17
-rw-r--r--examples/main-tab/opie-simple.control9
-rw-r--r--examples/main-tab/simple.cpp211
-rw-r--r--examples/main-tab/simple.h87
5 files changed, 328 insertions, 0 deletions
diff --git a/examples/main-tab/config.in b/examples/main-tab/config.in
new file mode 100644
index 0000000..da50c37
--- a/dev/null
+++ b/examples/main-tab/config.in
@@ -0,0 +1,4 @@
1CONFIG EXAMPLE_SIMPLE
2 boolean "Simple MainWindow with Central Widget Example"
3 default "n"
4 depends (LIBQPE || LIBQPE-X11 ) && EXAMPLES \ No newline at end of file
diff --git a/examples/main-tab/example.pro b/examples/main-tab/example.pro
new file mode 100644
index 0000000..3cafc20
--- a/dev/null
+++ b/examples/main-tab/example.pro
@@ -0,0 +1,17 @@
1CONFIG += qt warn_on quick-app
2
3
4TARGET = main-tab
5
6HEADERS = simple.h
7SOURCES = simple.cpp
8
9
10INCLUDEPATH += $(OPIEDIR)/include
11DEPENDPATH += $(OPIEDIR)/include
12
13
14# we now also include opie
15LIBS += -lqpe -lopie
16
17include ( $(OPIEDIR)/include.pro )
diff --git a/examples/main-tab/opie-simple.control b/examples/main-tab/opie-simple.control
new file mode 100644
index 0000000..8416ad2
--- a/dev/null
+++ b/examples/main-tab/opie-simple.control
@@ -0,0 +1,9 @@
1Package: opie-main-tab-example
2Files: bin/main-tab apps/Examples/main-tab.desktop
3Priority: optional
4Section: opie/applications
5Maintainer: Holger 'zecke' Freyther <zecke@handhelds.org>
6Architecture: arm
7Depends: task-opie-minimal, opie-pics
8Description: A simple example
9Version: $QPE_VERSION$EXTRAVERSION
diff --git a/examples/main-tab/simple.cpp b/examples/main-tab/simple.cpp
new file mode 100644
index 0000000..69dd00f
--- a/dev/null
+++ b/examples/main-tab/simple.cpp
@@ -0,0 +1,211 @@
1#include <qaction.h> // action
2#include <qmenubar.h> // menubar
3#include <qtoolbar.h> // toolbar
4#include <qlabel.h> // a label
5#include <qpushbutton.h> // the header file for the QPushButton
6#include <qlayout.h>
7
8#include <qpe/qpeapplication.h> // the QPEApplication
9#include <qpe/resource.h>
10#include <qpe/sound.h>
11
12#include <opie/oapplicationfactory.h> // a template + macro to save the main method and allow quick launching
13#include <opie/otabwidget.h>
14
15#include "simple.h"
16
17/*
18 * implementation of simple
19 */
20
21/*
22 * The factory is used for quicklaunching
23 * 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
24 *
25 * Depending on the global quick launch setting this will create
26 * either a main method or one for our component plugin system
27 */
28
29OPIE_EXPORT_APP( OApplicationFactory<MainWindow> )
30
31MainWindow::MainWindow(QWidget *parent, const char* name, WFlags fl )
32 : QMainWindow( parent, name, fl ) {
33 setCaption(tr("My MainWindow") );
34
35 initUI();
36
37
38 /*
39 * Tab widget as central
40 */
41 OTabWidget *tab = new OTabWidget(this);
42 connect(tab, SIGNAL(currentChanged(QWidget*) ),
43 this, SLOT( slotCurrentChanged( QWidget* ) ) );
44 setCentralWidget( tab );
45
46 Simple1 *simple1 = new Simple1( this );
47 tab->addTab( simple1, "new", tr("Simple1") );
48 tab->setCurrentTab( tr("Simple1") );
49
50 Simple2 *simple2 = new Simple2( this );
51 tab->addTab( simple2, "trash", tr("Simple2") );
52
53 m_oldCurrent = simple1;
54
55 connect(m_fire, SIGNAL(activated() ),
56 simple1, SLOT(slotFire() ) );
57}
58
59MainWindow::~MainWindow() {
60 // again nothing to delete because Qt takes care
61}
62
63
64void MainWindow::setDocument( const QString& /*str*/ ) {
65}
66void MainWindow::slotCurrentChanged( QWidget *wid) {
67 disconnect(m_fire, SIGNAL(activated() ),
68 m_oldCurrent, SLOT(slotFire() ) );
69 connect(m_fire, SIGNAL(activated() ),
70 wid, SLOT(slotFire() ) );
71
72 m_oldCurrent = wid;
73}
74
75void MainWindow::initUI() {
76
77 setToolBarsMovable( false );
78
79 QToolBar *menuBarHolder = new QToolBar( this );
80
81 menuBarHolder->setHorizontalStretchable( true );
82 QMenuBar *mb = new QMenuBar( menuBarHolder );
83 QToolBar *tb = new QToolBar( this );
84
85 QPopupMenu *fileMenu = new QPopupMenu( this );
86
87
88 QAction *a = new QAction( tr("Quit"), Resource::loadIconSet("quit_icon"),
89 QString::null, 0, this, "quit_action" );
90 /*
91 * Connect quit to the QApplication quit slot
92 */
93 connect(a, SIGNAL(activated() ),
94 qApp, SLOT(quit() ) );
95 a->addTo( fileMenu );
96
97 a = new QAction(tr("Fire"),
98 Resource::loadIconSet("new"),
99 QString::null, 0, this, "fire_button");
100
101 /* see the power? */
102 a->addTo( fileMenu );
103 a->addTo( tb );
104 m_fire = a;
105
106
107 mb->insertItem(tr("File"), fileMenu );
108
109}
110
111Simple1::Simple1( QWidget* parent, const char* name, WFlags fl )
112 : QWidget( parent, name, fl ) {
113
114 QVBoxLayout *layout = new QVBoxLayout( this );
115 layout->setSpacing( 8 );
116 layout->setMargin( 11 );
117
118
119 QLabel *lbl = new QLabel( this, "a name for the label" );
120 lbl->setText( tr("Click on the button or follow the white rabbit") );
121 layout->addWidget( lbl );
122
123
124 m_button = new QPushButton(this);
125
126
127 m_button->setText( tr("Fire", "translatable quit string" ) );
128 layout->addWidget( m_button );
129
130
131 connect( m_button, SIGNAL(clicked() ),
132 this, SLOT( slotFire() ) );
133}
134
135Simple1::~Simple1() {
136
137}
138
139void Simple1::slotFire() {
140 /*
141 * NOTE: Simple is now a child window of MainWindow
142 * close will hide() Simple and not delete it. But as
143 * the mainwindow is shown all children will be shown as well
144 */
145 close();
146}
147
148
149Simple2::Simple2( QWidget* parent, const char* name, WFlags fl )
150 : QWidget( parent, name, fl ) {
151
152 /*
153 * sets the caption of this toplevel widget
154 * put all translatable string into tr()
155 */
156 setCaption(tr("My Simple Application") );
157
158 /*
159 * A simple vertical layout
160 * either call layout->setAutoAdd( true )
161 * or use layout->addWidget( wid ) to add widgets
162 */
163 QVBoxLayout *layout = new QVBoxLayout( this );
164 layout->setSpacing( 8 );
165 layout->setMargin( 11 );
166
167 /*
168 * creates a label
169 * The first parameter is this widget so the Label is a child
170 * of us and will be deleted when we're deleted.
171 */
172 QLabel *lbl = new QLabel( this, "a name for the label" );
173 /*
174 * Resource will search hard for a Pixmap in $OPIEDIR/pics
175 * to find 'logo/opielogo' You need to pass the subdir
176 * but not the ending
177 */
178 lbl->setPixmap( Resource::loadPixmap("logo/opielogo") );
179 layout->addWidget( lbl );
180
181
182 /* creates a button as child of this widget */
183 m_button = new QPushButton(this);
184 /*
185 * another way to call tr. The first parameter is the string
186 * to translate and the second a hint to the translator
187 */
188 m_button->setText( tr("Fire", "translatable fire string" ) );
189 layout->addWidget( m_button );
190
191
192 connect( m_button, SIGNAL(clicked() ),
193 this, SLOT( slotQuit() ) );
194}
195
196
197Simple2::~Simple2() {
198
199}
200
201void Simple2::slotFire() {
202 /*
203 * We will fire up a sound
204 * Note that Sound will use Resource as well
205 * and we do not need to supply an ending
206 * sounds are found in $OPIEDIR/sounds
207 */
208 Sound snd("hit_target01");
209 snd.play();
210
211}
diff --git a/examples/main-tab/simple.h b/examples/main-tab/simple.h
new file mode 100644
index 0000000..e0e43c0
--- a/dev/null
+++ b/examples/main-tab/simple.h
@@ -0,0 +1,87 @@
1
2/*
3 * A Simple widget with a button to quit
4 *
5 */
6
7/*
8 * The below sequence is called a guard and guards
9 * against multiple inclusion of header files
10 * NOTE: you need to use unique names among the header files
11 */
12#ifndef QUIET_SIMPLE_DEMO_H
13#define QUIET_SIMPLE_DEMO_H
14
15
16
17
18#include <qmainwindow.h> // from this class we will inherit
19
20
21class QPushButton; // forward declaration to not include the header. This can save time when compiling
22class QAction;
23
24/*
25 * A mainwindow is a special QWidget it helps layouting
26 * toolbar, statusbar, menubar. Got dockable areas
27 * So in one sentence it is a MainWindow :)
28 */
29class MainWindow : public QMainWindow {
30 Q_OBJECT
31public:
32 static QString appName() { return QString::fromLatin1("main-tab"); }
33 MainWindow( QWidget* parent, const char* name, WFlags fl );
34 ~MainWindow();
35
36public slots:
37 void setDocument( const QString& );
38private slots:
39 void slotCurrentChanged( QWidget* wid );
40
41private:
42 void initUI();
43 QAction *m_fire;
44 QWidget* m_oldCurrent;
45};
46
47
48/*
49 * We will just reuse the two simple widgets for now
50 */
51class Simple1 : public QWidget {
52
53 Q_OBJECT
54public:
55
56 Simple1( QWidget* parent = 0, const char * name = 0, WFlags fl = 0 );
57 ~Simple1();
58
59
60public slots:
61 void slotFire();
62
63private:
64 /* my variable */
65 QPushButton* m_button;
66};
67
68class Simple2 : public QWidget {
69 Q_OBJECT
70public:
71
72 Simple2( QWidget* parent = 0, const char * name = 0, WFlags fl = 0 );
73 ~Simple2();
74
75
76
77public slots:
78 void slotFire();
79
80private:
81 /* my variable */
82 QPushButton* m_button;
83};
84
85
86
87#endif