summaryrefslogtreecommitdiff
authorzecke <zecke>2003-08-30 20:23:05 (UTC)
committer zecke <zecke>2003-08-30 20:23:05 (UTC)
commit4c3a1de5289631db05b86a07092f0a334608dcf6 (patch) (unidiff)
tree90caf9b05312013006dad0af7f039ed1c595842d
parentcc1e68e0b6e0677e0523382daeb12d60ba0b67c9 (diff)
downloadopie-4c3a1de5289631db05b86a07092f0a334608dcf6.zip
opie-4c3a1de5289631db05b86a07092f0a334608dcf6.tar.gz
opie-4c3a1de5289631db05b86a07092f0a334608dcf6.tar.bz2
Add four examples
#1 simple widget + OApplicationFactory + qmake usage explained #2 simple icons + usage of Resource and playing of sounds #3 simple main + Toolbar + MenuBar IconSets and QActions explained #4 main tab + Usage of OTabWidget and QSignals with parameters disconnect and connect TODO #5 PIM loading and viewing #6 PIM qcop + usage of QCOP BuildSystem integration
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--examples/COMMON_ERRORS38
-rw-r--r--examples/README28
-rw-r--r--examples/config.in.in1
-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
-rw-r--r--examples/simple-icon/config.in4
-rw-r--r--examples/simple-icon/example.pro16
-rw-r--r--examples/simple-icon/opie-simple.control9
-rw-r--r--examples/simple-icon/simple.cpp100
-rw-r--r--examples/simple-icon/simple.h58
-rw-r--r--examples/simple-main/config.in4
-rw-r--r--examples/simple-main/example.pro17
-rw-r--r--examples/simple-main/opie-simple.control9
-rw-r--r--examples/simple-main/simple.cpp218
-rw-r--r--examples/simple-main/simple.h81
-rw-r--r--examples/simple/config.in4
-rw-r--r--examples/simple/example.pro38
-rw-r--r--examples/simple/opie-simple.control9
-rw-r--r--examples/simple/simple.cpp89
-rw-r--r--examples/simple/simple.h66
23 files changed, 1117 insertions, 0 deletions
diff --git a/examples/COMMON_ERRORS b/examples/COMMON_ERRORS
new file mode 100644
index 0000000..d260868
--- a/dev/null
+++ b/examples/COMMON_ERRORS
@@ -0,0 +1,38 @@
1A List of common compile errors
2
3Error:
4/simple.o simple.cpp
5make: *** Keine Regel vorhanden, um das Target ».moc//moc_simple.cpp«,
6
7Answer: There is only a rule for ./moc/$PLATFORM/moc_simple.cpp your platform
8leading to a double slash. Set $PLATFORM and run qmake again
9
10Error:
11Assembler messages:
12FATAL: can't create .obj/obj/simple.o: Datei oder Verzeichnis nicht gefunden
13make: *** [.obj/obj/simple.o] Unterbrechung
14
15Answer: you forgot to run qmake after setting $PLATFORM
16
17
18Error:
19/obj/simple.o simple.cpp
20/home/ich/programming/opie/head/opie/include/opie/oapplicationfactory.h: In
21 member function `QWidget*
22 OApplicationFactory<Product>::createMainWindow(const QString&, QWidget*,
23 const char*, unsigned int) [with Product = MainWindow]':
24 /home/ich/programming/opie/head/qt-cvs/include/qvaluelist.h:27: instantiated from here
25 /home/ich/programming/opie/head/opie/include/opie/oapplicationfactory.h:100: error: '
26 class MainWindow' has no member named 'appName'
27 /home/ich/programming/opie/head/opie/include/opie/oapplicationfactory.h: In
28 member function `QStringList OApplicationFactory<Product>::applications()
29 const [with Product = MainWindow]':
30 /home/ich/programming/opie/head/qt-cvs/include/qvaluelist.h:27: instantiated from here
31 /home/ich/programming/opie/head/opie/include/opie/oapplicationfactory.h:108: error: '
32 class MainWindow' has no member named 'appName'
33 make: *** [.obj/obj/simple.o] Fehler 1
34
35Answer: gcc loves to spit out long compiler errors for template. the problem is that oapplication factory
36wants to call a static method called appName() on your widget. You need to add static QString appName()
37and return the name of the executable
38
diff --git a/examples/README b/examples/README
new file mode 100644
index 0000000..3003830
--- a/dev/null
+++ b/examples/README
@@ -0,0 +1,28 @@
1Hi newbie,
2this directory contains a set of examples for various
3API you may want to use. The examples go from simple
4to harder and must be understand as an extension
5of the examples from Qt in your source package.
6Be sure to look there at first and at their excelent
7tutorials as well.
8
9Note: that some files are found in apps/Examples to really
10show how to include apps properly.
11
12Note: to integrate your apps into the build
13 make clean-configs
14 put your application into a sourcedir
15 edit $OPIEDIR/packages
16 make
17
18
19
20 simple/ - Simple Widget with quit button
21 simple-icon - Simple Widget with loading resources and playing simple sound
22 simple-main - Simple QMainWindow usage with toolbar and actions
23 main-tab - QMainWindow with central tab widget
24 simple-pim - QMainWindow + QListView + PIM
25 big-pim - Usage of Opie PIM with BigScreen Extension
26
27Compile by setting your environment (QTDIR, QMAKESPEC, PATH, OPIEDIR )
28qmake -o Makefile example.pro \ No newline at end of file
diff --git a/examples/config.in.in b/examples/config.in.in
new file mode 100644
index 0000000..0a90517
--- a/dev/null
+++ b/examples/config.in.in
@@ -0,0 +1 @@
@sources@
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
diff --git a/examples/simple-icon/config.in b/examples/simple-icon/config.in
new file mode 100644
index 0000000..cd6a17a
--- a/dev/null
+++ b/examples/simple-icon/config.in
@@ -0,0 +1,4 @@
1CONFIG EXAMPLE_SIMPLE
2 boolean "Simple Icon Loading and Sound Example"
3 default "n"
4 depends (LIBQPE || LIBQPE-X11 ) && EXAMPLES \ No newline at end of file
diff --git a/examples/simple-icon/example.pro b/examples/simple-icon/example.pro
new file mode 100644
index 0000000..6505330
--- a/dev/null
+++ b/examples/simple-icon/example.pro
@@ -0,0 +1,16 @@
1# remember each example is based on the other
2CONFIG += qt warn_on quick-app
3TARGET = simple-icon
4
5HEADERS = simple.h
6
7SOURCES = simple.cpp
8
9INCLUDEPATH += $(OPIEDIR)/include
10DEPENDPATH += $(OPIEDIR)/include
11
12
13
14LIBS += -lqpe
15
16include ( $(OPIEDIR)/include.pro )
diff --git a/examples/simple-icon/opie-simple.control b/examples/simple-icon/opie-simple.control
new file mode 100644
index 0000000..87ae80e
--- a/dev/null
+++ b/examples/simple-icon/opie-simple.control
@@ -0,0 +1,9 @@
1Package: opie-simple-icon-example
2Files: bin/simple-icon apps/Examples/simple-icon.desktop
3Priority: optional
4Section: opie/applications
5Maintainer: Holger 'zecke' Freyther <zecke@handhelds.org>
6Architecture: arm
7Depends: task-opie-minimal, opie-pics
8Description: A simple icon example
9Version: $QPE_VERSION$EXTRAVERSION
diff --git a/examples/simple-icon/simple.cpp b/examples/simple-icon/simple.cpp
new file mode 100644
index 0000000..054ade8
--- a/dev/null
+++ b/examples/simple-icon/simple.cpp
@@ -0,0 +1,100 @@
1#include <qlabel.h> // a label
2#include <qpushbutton.h> // the header file for the QPushButton
3#include <qlayout.h>
4
5#include <qpe/qpeapplication.h> // the QPEApplication
6#include <qpe/resource.h> // for loading icon
7#include <qpe/sound.h> // for playing a sound
8
9#include <opie/oapplicationfactory.h> // a template + macro to save the main method and allow quick launching
10
11#include "simple.h"
12
13/*
14 * implementation of simple
15 */
16
17/*
18 * The factory is used for quicklaunching
19 * 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
20 *
21 * Depending on the global quick launch setting this will create
22 * either a main method or one for our component plugin system
23 */
24
25OPIE_EXPORT_APP( OApplicationFactory<Simple> )
26
27Simple::Simple( QWidget* parent, const char* name, WFlags fl )
28 : QWidget( parent, name, fl ) {
29
30 /*
31 * sets the caption of this toplevel widget
32 * put all translatable string into tr()
33 */
34 setCaption(tr("My Simple Application") );
35
36 /*
37 * A simple vertical layout
38 * either call layout->setAutoAdd( true )
39 * or use layout->addWidget( wid ) to add widgets
40 */
41 QVBoxLayout *layout = new QVBoxLayout( this );
42 layout->setSpacing( 8 );
43 layout->setMargin( 11 );
44
45 /*
46 * creates a label
47 * The first parameter is this widget so the Label is a child
48 * of us and will be deleted when we're deleted.
49 */
50 QLabel *lbl = new QLabel( this, "a name for the label" );
51 /*
52 * Resource will search hard for a Pixmap in $OPIEDIR/pics
53 * to find 'logo/opielogo' You need to pass the subdir
54 * but not the ending
55 */
56 lbl->setPixmap( Resource::loadPixmap("logo/opielogo") );
57 layout->addWidget( lbl );
58
59
60 /* creates a button as child of this widget */
61 m_button = new QPushButton(this);
62 /*
63 * another way to call tr. The first parameter is the string
64 * to translate and the second a hint to the translator
65 */
66 m_button->setText( tr("Fire", "translatable fire string" ) );
67 layout->addWidget( m_button );
68
69 /*
70 * Now we bring the action into it. The power of qt is the dynamic
71 * signal and slots model
72 * Usage is simple connect m_buttons clicked signal to our
73 * slotQuit slot.
74 * We could also have connected a SIGNAL to a SIGNAL or the clicked
75 * signal directly to qApp and SLOT(quit() )
76 */
77 connect( m_button, SIGNAL(clicked() ),
78 this, SLOT( slotQuit() ) );
79}
80
81/*
82 * Our destructor is empty because all child
83 * widgets and layouts will be deleted by Qt.
84 * Same applies to QObjects
85 */
86Simple::~Simple() {
87
88}
89
90void Simple::slotQuit() {
91 /*
92 * We will fire up a sound
93 * Note that Sound will use Resource as well
94 * and we do not need to supply an ending
95 * sounds are found in $OPIEDIR/sounds
96 */
97 Sound snd("hit_target01");
98 snd.play();
99
100}
diff --git a/examples/simple-icon/simple.h b/examples/simple-icon/simple.h
new file mode 100644
index 0000000..00965cd
--- a/dev/null
+++ b/examples/simple-icon/simple.h
@@ -0,0 +1,58 @@
1
2/*
3 * A Simple widget with a button to quit
4 * and Pixmaps and Sound
5 */
6
7/*
8 * The below sequence is called a guard and guards
9 * against multiple inclusion of header files
10 */
11#ifndef QUIET_SIMPLE_DEMO_H
12#define QUIET_SIMPLE_DEMO_H
13
14
15
16
17#include <qwidget.h> // from this class we will inherit
18
19class QPushButton; // forward declaration to not include the header. This can save time when compiling
20
21
22/*
23 * Simple inherits from QWidget
24 * Remeber each example is based on the other
25 */
26class Simple : public QWidget {
27 Q_OBJECT
28public:
29 /*
30 * C'tor for the Simple
31 * make sure to always have these three when you use
32 * the quicklaunch factory ( explained in the implementation )
33 */
34 Simple( QWidget* parent = 0, const char * name = 0, WFlags fl = 0 );
35 ~Simple();
36
37 /*
38 * appName is used by the Application factory.
39 * make sure the name matches the one of the executable
40 */
41 static QString appName() { return QString::fromLatin1("simple-icon"); }
42
43 /*
44 * use private slots: to mark your slots as such
45 * A slot can also be called as a normal method
46 */
47private slots:
48 void slotQuit();
49
50private:
51 /* my variable */
52 QPushButton* m_button;
53};
54
55
56
57
58#endif
diff --git a/examples/simple-main/config.in b/examples/simple-main/config.in
new file mode 100644
index 0000000..311e594
--- a/dev/null
+++ b/examples/simple-main/config.in
@@ -0,0 +1,4 @@
1CONFIG EXAMPLE_SIMPLE
2 boolean "Simple MainWindow Example"
3 default "n"
4 depends (LIBQPE || LIBQPE-X11 ) && EXAMPLES \ No newline at end of file
diff --git a/examples/simple-main/example.pro b/examples/simple-main/example.pro
new file mode 100644
index 0000000..2f5f10f
--- a/dev/null
+++ b/examples/simple-main/example.pro
@@ -0,0 +1,17 @@
1CONFIG += qt warn_on quick-app
2
3
4TARGET = simple-main
5
6HEADERS = simple.h
7SOURCES = simple.cpp
8
9
10INCLUDEPATH += $(OPIEDIR)/include
11DEPENDPATH += $(OPIEDIR)/include
12
13
14
15LIBS += -lqpe
16
17include ( $(OPIEDIR)/include.pro )
diff --git a/examples/simple-main/opie-simple.control b/examples/simple-main/opie-simple.control
new file mode 100644
index 0000000..63622d5
--- a/dev/null
+++ b/examples/simple-main/opie-simple.control
@@ -0,0 +1,9 @@
1Package: opie-simple-main-example
2Files: bin/simple-main apps/Examples/simple-main.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/simple-main/simple.cpp b/examples/simple-main/simple.cpp
new file mode 100644
index 0000000..8de911f
--- a/dev/null
+++ b/examples/simple-main/simple.cpp
@@ -0,0 +1,218 @@
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
11#include <opie/oapplicationfactory.h> // a template + macro to save the main method and allow quick launching
12
13#include "simple.h"
14
15/*
16 * implementation of simple
17 */
18
19/*
20 * The factory is used for quicklaunching
21 * 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
22 *
23 * Depending on the global quick launch setting this will create
24 * either a main method or one for our component plugin system
25 */
26
27OPIE_EXPORT_APP( OApplicationFactory<MainWindow> )
28
29MainWindow::MainWindow(QWidget *parent, const char* name, WFlags fl )
30 : QMainWindow( parent, name, fl ) {
31 setCaption(tr("My MainWindow") );
32 setIcon( Resource::loadPixmap("new") );
33 /*
34 * out mainwindow should have a menubar
35 * a toolbar, a mainwidget and use Resource
36 * to get the IconSets
37 */
38 /*
39 * we initialize the GUI in a different methid
40 */
41 initUI();
42
43 Simple *simple = new Simple( this );
44 setCentralWidget( simple );
45
46 /*
47 * If you use signal and slots do not include the parameter
48 * names inside
49 * so SIGNAL(fooBar(int) ) and NOT SIGNAL(fooBar(int foo) )
50 */
51 /*
52 * We connect the activation of our QAction
53 * to the slot connected to the firebutton
54 * We could also connect the signal to the clicked
55 * signal of the button
56 */
57 connect(m_fire, SIGNAL(activated() ),
58 simple, SLOT(slotFire() ) );
59}
60
61MainWindow::~MainWindow() {
62 // again nothing to delete because Qt takes care
63}
64
65/*
66 * set Document is a special function used by Document
67 * centric applications.
68 * In example if Opie receives a Todo via IrDa it uses
69 * setDocument via QCOP the IPC system to load the card
70 * Or If you decide to open a file in filemanager with textedit
71 * setDocument is called via IPC in textedit.
72 * Also any call to QPE/Application/xyz and xyz is currently not running
73 * leads to the start of xyz and delivering of the QCOP call
74 * But more on QCOP in the next application
75 */
76void MainWindow::setDocument( const QString& /*str*/ ) {
77 // in our case empty but you should see if it is a direct
78 // file request or if it is a DocLnk.
79 // A DocLnk is Link to an Document so you would end up
80 // opening the document behind the file you got
81}
82
83/*
84 * Two new concepts with this Method
85 * 1. QAction. An action can be grouped and emits
86 * an activated signal. Action a universal useable
87 * you can just plug/addTo in most Qt widgets. For example
88 * the same action can be plugged into a ToolBar, MenuBar,
89 * QPopupMenu and other widgets but you do not need to worry
90 * about it
91 *
92 * 2. an IconSet contains pixmaps and provides them scaled down, scaled up
93 * enabled and disabled. SO if you use QIConSet and the toolbar
94 * size changes to use big pixmaps you will not use upscaled icons
95 * but the right ones thanks to QIconSet and Resource
96 */
97
98void MainWindow::initUI() {
99/*
100 * We want to provde a File Menu with Quit as option
101 * and a Fire Toolbutton ( QAction )
102 * So we need two actions
103 * A toolbar and a popupMenu
104 */
105 setToolBarsMovable( false );
106 /*
107 *We don't want the static toolbar but share it with the
108 * toolbar on small screens
109 */
110 QToolBar *menuBarHolder = new QToolBar( this );
111 /* we allow the menubarholder to become bigger than
112 * the screen width and to offer a > for the additional items
113 */
114 menuBarHolder->setHorizontalStretchable( true );
115 QMenuBar *mb = new QMenuBar( menuBarHolder );
116 QToolBar *tb = new QToolBar( this );
117
118 QPopupMenu *fileMenu = new QPopupMenu( this );
119
120 /*
121 * we create our first action with the Text Quit
122 * a IconSet, no menu name, no acceleration ( keyboard shortcut ),
123 * with parent this, and name "quit_action"
124 */
125 /*
126 * Note if you want a picture out of the inline directory
127 * you musn't prefix inline/ inline means these pics are built in
128 * into libqpe so the name without ending and directory is enough
129 */
130 QAction *a = new QAction( tr("Quit"), Resource::loadIconSet("quit_icon"),
131 QString::null, 0, this, "quit_action" );
132 /*
133 * Connect quit to the QApplication quit slot
134 */
135 connect(a, SIGNAL(activated() ),
136 qApp, SLOT(quit() ) );
137 a->addTo( fileMenu );
138
139 a = new QAction(tr("Fire"),
140 Resource::loadIconSet("new"),
141 QString::null, 0, this, "fire_button");
142
143 /* see the power? */
144 a->addTo( fileMenu );
145 a->addTo( tb );
146 m_fire = a;
147
148
149 mb->insertItem(tr("File"), fileMenu );
150
151}
152
153Simple::Simple( QWidget* parent, const char* name, WFlags fl )
154 : QWidget( parent, name, fl ) {
155
156 /*
157 * sets the caption of this toplevel widget
158 * put all translatable string into tr()
159 */
160 setCaption(tr("My Simple Application") );
161
162 /*
163 * A simple vertical layout
164 * either call layout->setAutoAdd( true )
165 * or use layout->addWidget( wid ) to add widgets
166 */
167 QVBoxLayout *layout = new QVBoxLayout( this );
168 layout->setSpacing( 8 );
169 layout->setMargin( 11 );
170
171 /*
172 * creates a label
173 * The first parameter is this widget so the Label is a child
174 * of us and will be deleted when we're deleted.
175 */
176 QLabel *lbl = new QLabel( this, "a name for the label" );
177 lbl->setText( tr("Click on the button or follow the white rabbit") );
178 layout->addWidget( lbl );
179
180
181 /* creates a button as child of this widget */
182 m_button = new QPushButton(this);
183 /*
184 * another way to call tr. The first parameter is the string
185 * to translate and the second a hint to the translator
186 */
187 m_button->setText( tr("Fire", "translatable quit string" ) );
188 layout->addWidget( m_button );
189
190 /*
191 * Now we bring the action into it. The power of qt is the dynamic
192 * signal and slots model
193 * Usage is simple connect m_buttons clicked signal to our
194 * slotQuit slot.
195 * We could also have connected a SIGNAL to a SIGNAL or the clicked
196 * signal directly to qApp and SLOT(quit() )
197 */
198 connect( m_button, SIGNAL(clicked() ),
199 this, SLOT( slotFire() ) );
200}
201
202/*
203 * Our destructor is empty because all child
204 * widgets and layouts will be deleted by Qt.
205 * Same applies to QObjects
206 */
207Simple::~Simple() {
208
209}
210
211void Simple::slotFire() {
212 /*
213 * NOTE: Simple is now a child window of MainWindow
214 * close will hide() Simple and not delete it. But as
215 * the mainwindow is shown all children will be shown as well
216 */
217 close();
218}
diff --git a/examples/simple-main/simple.h b/examples/simple-main/simple.h
new file mode 100644
index 0000000..f75066e
--- a/dev/null
+++ b/examples/simple-main/simple.h
@@ -0,0 +1,81 @@
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("simple-main"); }
33 MainWindow( QWidget* parent, const char* name, WFlags fl );
34 ~MainWindow();
35
36public slots:
37 void setDocument( const QString& );
38
39private:
40 void initUI();
41 QAction *m_fire;
42};
43
44
45/*
46 * Simple inherits from QWidget
47 */
48class Simple : public QWidget {
49 /*
50 * Q_OBJECT must always be the first thing you include
51 * This is a macro and is responsible for the concepts of
52 * dynamic signal and slots and other MetaObjects as
53 * superClass(), inherits(), isA()...
54 * If you use multiple inheritance include the class derived
55 * from QObject first
56 */
57 Q_OBJECT
58public:
59 /*
60 * C'tor for the Simple
61 * make sure to always have these three when you use
62 * the quicklaunch factory ( explained in the implementation )
63 */
64 Simple( QWidget* parent = 0, const char * name = 0, WFlags fl = 0 );
65 ~Simple();
66
67 /*
68 * We now make it public because our mainwindow wants to call it
69 */
70public slots:
71 void slotFire();
72
73private:
74 /* my variable */
75 QPushButton* m_button;
76};
77
78
79
80
81#endif
diff --git a/examples/simple/config.in b/examples/simple/config.in
new file mode 100644
index 0000000..3a1b265
--- a/dev/null
+++ b/examples/simple/config.in
@@ -0,0 +1,4 @@
1CONFIG EXAMPLE_SIMPLE
2 boolean "Simple Example"
3 default "n"
4 depends (LIBQPE || LIBQPE-X11 ) && EXAMPLES \ No newline at end of file
diff --git a/examples/simple/example.pro b/examples/simple/example.pro
new file mode 100644
index 0000000..4c41b29
--- a/dev/null
+++ b/examples/simple/example.pro
@@ -0,0 +1,38 @@
1# '#' introduces a comment
2#CONFIG says the qmake buildsystem what to use
3#
4CONFIG += qt warn_on quick-app
5# qt = Use qt
6# warn_on = warnings are on
7# quick-app = Tell the buildsystem that the apps is quick-launchable
8#
9
10# Note if you do not supply quick-app you need to set
11# TEMPLATE = app or TEMPLATE = lib depending on if you want to build an executable or lib
12# and DESTDIR= $(OPIEDIR)/bin or $(OPIEDIR)/lib
13
14TARGET = simple
15# the name of the resulting object
16
17HEADERS = simple.h
18# A list header files
19
20
21SOURCES = simple.cpp
22# A list of source files
23
24INTERFACES =
25# list of ui files
26
27INCLUDEPATH += $(OPIEDIR)/include
28DEPENDPATH += $(OPIEDIR)/include
29
30
31
32LIBS += -lqpe
33# libs to link against
34
35#Important include the global include.pro just like below
36
37
38include ( $(OPIEDIR)/include.pro )
diff --git a/examples/simple/opie-simple.control b/examples/simple/opie-simple.control
new file mode 100644
index 0000000..5d5afec
--- a/dev/null
+++ b/examples/simple/opie-simple.control
@@ -0,0 +1,9 @@
1Package: opie-simple-example
2Files: bin/simple apps/Examples/simple.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/simple/simple.cpp b/examples/simple/simple.cpp
new file mode 100644
index 0000000..a0bc308
--- a/dev/null
+++ b/examples/simple/simple.cpp
@@ -0,0 +1,89 @@
1#include <qlabel.h> // a label
2#include <qpushbutton.h> // the header file for the QPushButton
3#include <qlayout.h>
4
5#include <qpe/qpeapplication.h> // the QPEApplication
6
7#include <opie/oapplicationfactory.h> // a template + macro to save the main method and allow quick launching
8
9#include "simple.h"
10
11/*
12 * implementation of simple
13 */
14
15/*
16 * The factory is used for quicklaunching
17 * 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
18 *
19 * Depending on the global quick launch setting this will create
20 * either a main method or one for our component plugin system
21 */
22
23OPIE_EXPORT_APP( OApplicationFactory<Simple> )
24
25Simple::Simple( QWidget* parent, const char* name, WFlags fl )
26 : QWidget( parent, name, fl ) {
27
28 /*
29 * sets the caption of this toplevel widget
30 * put all translatable string into tr()
31 */
32 setCaption(tr("My Simple Application") );
33
34 /*
35 * A simple vertical layout
36 * either call layout->setAutoAdd( true )
37 * or use layout->addWidget( wid ) to add widgets
38 */
39 QVBoxLayout *layout = new QVBoxLayout( this );
40 layout->setSpacing( 8 );
41 layout->setMargin( 11 );
42
43 /*
44 * creates a label
45 * The first parameter is this widget so the Label is a child
46 * of us and will be deleted when we're deleted.
47 */
48 QLabel *lbl = new QLabel( this, "a name for the label" );
49 lbl->setText( tr("Click on the button or follow the white rabbit") );
50 layout->addWidget( lbl );
51
52
53 /* creates a button as child of this widget */
54 m_button = new QPushButton(this);
55 /*
56 * another way to call tr. The first parameter is the string
57 * to translate and the second a hint to the translator
58 */
59 m_button->setText( tr("Quit", "translatable quit string" ) );
60 layout->addWidget( m_button );
61
62 /*
63 * Now we bring the action into it. The power of qt is the dynamic
64 * signal and slots model
65 * Usage is simple connect m_buttons clicked signal to our
66 * slotQuit slot.
67 * We could also have connected a SIGNAL to a SIGNAL or the clicked
68 * signal directly to qApp and SLOT(quit() )
69 */
70 connect( m_button, SIGNAL(clicked() ),
71 this, SLOT( slotQuit() ) );
72}
73
74/*
75 * Our destructor is empty because all child
76 * widgets and layouts will be deleted by Qt.
77 * Same applies to QObjects
78 */
79Simple::~Simple() {
80
81}
82
83void Simple::slotQuit() {
84 /*
85 * we will close this window and Qt will recognize that
86 * the last window was closed and initiate a shutdown
87 */
88 close();
89}
diff --git a/examples/simple/simple.h b/examples/simple/simple.h
new file mode 100644
index 0000000..63611bb
--- a/dev/null
+++ b/examples/simple/simple.h
@@ -0,0 +1,66 @@
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 <qwidget.h> // from this class we will inherit
19
20class QPushButton; // forward declaration to not include the header. This can save time when compiling
21
22
23/*
24 * Simple inherits from QWidget
25 */
26class Simple : public QWidget {
27 /*
28 * Q_OBJECT must always be the first thing you include
29 * This is a macro and is responsible for the concepts of
30 * dynamic signal and slots and other MetaObjects as
31 * superClass(), inherits(), isA()...
32 * If you use multiple inheritance include the class derived
33 * from QObject first
34 */
35 Q_OBJECT
36public:
37 /*
38 * C'tor for the Simple
39 * make sure to always have these three when you use
40 * the quicklaunch factory ( explained in the implementation )
41 */
42 Simple( QWidget* parent = 0, const char * name = 0, WFlags fl = 0 );
43 ~Simple();
44
45 /*
46 * appName is used by the Application factory.
47 * make sure the name matches the one of the executable
48 */
49 static QString appName() { return QString::fromLatin1("simple"); }
50
51 /*
52 * use private slots: to mark your slots as such
53 * A slot can also be called as a normal method
54 */
55private slots:
56 void slotQuit();
57
58private:
59 /* my variable */
60 QPushButton* m_button;
61};
62
63
64
65
66#endif