author | zecke <zecke> | 2003-08-30 20:23:05 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-08-30 20:23:05 (UTC) |
commit | 4c3a1de5289631db05b86a07092f0a334608dcf6 (patch) (unidiff) | |
tree | 90caf9b05312013006dad0af7f039ed1c595842d /examples/simple | |
parent | cc1e68e0b6e0677e0523382daeb12d60ba0b67c9 (diff) | |
download | opie-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
-rw-r--r-- | examples/simple/config.in | 4 | ||||
-rw-r--r-- | examples/simple/example.pro | 38 | ||||
-rw-r--r-- | examples/simple/opie-simple.control | 9 | ||||
-rw-r--r-- | examples/simple/simple.cpp | 89 | ||||
-rw-r--r-- | examples/simple/simple.h | 66 |
5 files changed, 206 insertions, 0 deletions
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 @@ | |||
1 | CONFIG 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 | # | ||
4 | CONFIG += 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 | |||
14 | TARGET = simple | ||
15 | # the name of the resulting object | ||
16 | |||
17 | HEADERS = simple.h | ||
18 | # A list header files | ||
19 | |||
20 | |||
21 | SOURCES = simple.cpp | ||
22 | # A list of source files | ||
23 | |||
24 | INTERFACES = | ||
25 | # list of ui files | ||
26 | |||
27 | INCLUDEPATH += $(OPIEDIR)/include | ||
28 | DEPENDPATH += $(OPIEDIR)/include | ||
29 | |||
30 | |||
31 | |||
32 | LIBS += -lqpe | ||
33 | # libs to link against | ||
34 | |||
35 | #Important include the global include.pro just like below | ||
36 | |||
37 | |||
38 | include ( $(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 @@ | |||
1 | Package: opie-simple-example | ||
2 | Files: bin/simple apps/Examples/simple.desktop | ||
3 | Priority: optional | ||
4 | Section: opie/applications | ||
5 | Maintainer: Holger 'zecke' Freyther <zecke@handhelds.org> | ||
6 | Architecture: arm | ||
7 | Depends: task-opie-minimal, opie-pics | ||
8 | Description: A simple example | ||
9 | Version: $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 | |||
23 | OPIE_EXPORT_APP( OApplicationFactory<Simple> ) | ||
24 | |||
25 | Simple::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 | */ | ||
79 | Simple::~Simple() { | ||
80 | |||
81 | } | ||
82 | |||
83 | void 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 | |||
20 | class QPushButton; // forward declaration to not include the header. This can save time when compiling | ||
21 | |||
22 | |||
23 | /* | ||
24 | * Simple inherits from QWidget | ||
25 | */ | ||
26 | class 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 | ||
36 | public: | ||
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 | */ | ||
55 | private slots: | ||
56 | void slotQuit(); | ||
57 | |||
58 | private: | ||
59 | /* my variable */ | ||
60 | QPushButton* m_button; | ||
61 | }; | ||
62 | |||
63 | |||
64 | |||
65 | |||
66 | #endif | ||