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-icon | |
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-icon/config.in | 4 | ||||
-rw-r--r-- | examples/simple-icon/example.pro | 16 | ||||
-rw-r--r-- | examples/simple-icon/opie-simple.control | 9 | ||||
-rw-r--r-- | examples/simple-icon/simple.cpp | 100 | ||||
-rw-r--r-- | examples/simple-icon/simple.h | 58 |
5 files changed, 187 insertions, 0 deletions
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 @@ | |||
1 | CONFIG 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 | ||
2 | CONFIG += qt warn_on quick-app | ||
3 | TARGET = simple-icon | ||
4 | |||
5 | HEADERS = simple.h | ||
6 | |||
7 | SOURCES = simple.cpp | ||
8 | |||
9 | INCLUDEPATH += $(OPIEDIR)/include | ||
10 | DEPENDPATH += $(OPIEDIR)/include | ||
11 | |||
12 | |||
13 | |||
14 | LIBS += -lqpe | ||
15 | |||
16 | include ( $(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 @@ | |||
1 | Package: opie-simple-icon-example | ||
2 | Files: bin/simple-icon apps/Examples/simple-icon.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 icon example | ||
9 | Version: $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 | |||
25 | OPIE_EXPORT_APP( OApplicationFactory<Simple> ) | ||
26 | |||
27 | Simple::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 | */ | ||
86 | Simple::~Simple() { | ||
87 | |||
88 | } | ||
89 | |||
90 | void 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 | |||
19 | class 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 | */ | ||
26 | class Simple : public QWidget { | ||
27 | Q_OBJECT | ||
28 | public: | ||
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 | */ | ||
47 | private slots: | ||
48 | void slotQuit(); | ||
49 | |||
50 | private: | ||
51 | /* my variable */ | ||
52 | QPushButton* m_button; | ||
53 | }; | ||
54 | |||
55 | |||
56 | |||
57 | |||
58 | #endif | ||