summaryrefslogtreecommitdiff
authorzecke <zecke>2003-08-30 20:23:05 (UTC)
committer zecke <zecke>2003-08-30 20:23:05 (UTC)
commit4c3a1de5289631db05b86a07092f0a334608dcf6 (patch) (side-by-side diff)
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) (show 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 @@
+A List of common compile errors
+
+Error:
+/simple.o simple.cpp
+make: *** Keine Regel vorhanden, um das Target ».moc//moc_simple.cpp«,
+
+Answer: There is only a rule for ./moc/$PLATFORM/moc_simple.cpp your platform
+leading to a double slash. Set $PLATFORM and run qmake again
+
+Error:
+Assembler messages:
+FATAL: can't create .obj/obj/simple.o: Datei oder Verzeichnis nicht gefunden
+make: *** [.obj/obj/simple.o] Unterbrechung
+
+Answer: you forgot to run qmake after setting $PLATFORM
+
+
+Error:
+/obj/simple.o simple.cpp
+/home/ich/programming/opie/head/opie/include/opie/oapplicationfactory.h: In
+ member function `QWidget*
+ OApplicationFactory<Product>::createMainWindow(const QString&, QWidget*,
+ const char*, unsigned int) [with Product = MainWindow]':
+ /home/ich/programming/opie/head/qt-cvs/include/qvaluelist.h:27: instantiated from here
+ /home/ich/programming/opie/head/opie/include/opie/oapplicationfactory.h:100: error: '
+ class MainWindow' has no member named 'appName'
+ /home/ich/programming/opie/head/opie/include/opie/oapplicationfactory.h: In
+ member function `QStringList OApplicationFactory<Product>::applications()
+ const [with Product = MainWindow]':
+ /home/ich/programming/opie/head/qt-cvs/include/qvaluelist.h:27: instantiated from here
+ /home/ich/programming/opie/head/opie/include/opie/oapplicationfactory.h:108: error: '
+ class MainWindow' has no member named 'appName'
+ make: *** [.obj/obj/simple.o] Fehler 1
+
+Answer: gcc loves to spit out long compiler errors for template. the problem is that oapplication factory
+wants to call a static method called appName() on your widget. You need to add static QString appName()
+and return the name of the executable
+
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 @@
+Hi newbie,
+this directory contains a set of examples for various
+API you may want to use. The examples go from simple
+to harder and must be understand as an extension
+of the examples from Qt in your source package.
+Be sure to look there at first and at their excelent
+tutorials as well.
+
+Note: that some files are found in apps/Examples to really
+show how to include apps properly.
+
+Note: to integrate your apps into the build
+ make clean-configs
+ put your application into a sourcedir
+ edit $OPIEDIR/packages
+ make
+
+
+
+simple/ - Simple Widget with quit button
+simple-icon - Simple Widget with loading resources and playing simple sound
+simple-main - Simple QMainWindow usage with toolbar and actions
+main-tab - QMainWindow with central tab widget
+simple-pim - QMainWindow + QListView + PIM
+big-pim - Usage of Opie PIM with BigScreen Extension
+
+Compile by setting your environment (QTDIR, QMAKESPEC, PATH, OPIEDIR )
+qmake -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 @@
+CONFIG EXAMPLE_SIMPLE
+ boolean "Simple MainWindow with Central Widget Example"
+ default "n"
+ 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 @@
+CONFIG += qt warn_on quick-app
+
+
+TARGET = main-tab
+
+HEADERS = simple.h
+SOURCES = simple.cpp
+
+
+INCLUDEPATH += $(OPIEDIR)/include
+DEPENDPATH += $(OPIEDIR)/include
+
+
+# we now also include opie
+LIBS += -lqpe -lopie
+
+include ( $(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 @@
+Package: opie-main-tab-example
+Files: bin/main-tab apps/Examples/main-tab.desktop
+Priority: optional
+Section: opie/applications
+Maintainer: Holger 'zecke' Freyther <zecke@handhelds.org>
+Architecture: arm
+Depends: task-opie-minimal, opie-pics
+Description: A simple example
+Version: $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 @@
+#include <qaction.h> // action
+#include <qmenubar.h> // menubar
+#include <qtoolbar.h> // toolbar
+#include <qlabel.h> // a label
+#include <qpushbutton.h> // the header file for the QPushButton
+#include <qlayout.h>
+
+#include <qpe/qpeapplication.h> // the QPEApplication
+#include <qpe/resource.h>
+#include <qpe/sound.h>
+
+#include <opie/oapplicationfactory.h> // a template + macro to save the main method and allow quick launching
+#include <opie/otabwidget.h>
+
+#include "simple.h"
+
+/*
+ * implementation of simple
+ */
+
+/*
+ * The factory is used for quicklaunching
+ * 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
+ *
+ * Depending on the global quick launch setting this will create
+ * either a main method or one for our component plugin system
+ */
+
+OPIE_EXPORT_APP( OApplicationFactory<MainWindow> )
+
+MainWindow::MainWindow(QWidget *parent, const char* name, WFlags fl )
+ : QMainWindow( parent, name, fl ) {
+ setCaption(tr("My MainWindow") );
+
+ initUI();
+
+
+ /*
+ * Tab widget as central
+ */
+ OTabWidget *tab = new OTabWidget(this);
+ connect(tab, SIGNAL(currentChanged(QWidget*) ),
+ this, SLOT( slotCurrentChanged( QWidget* ) ) );
+ setCentralWidget( tab );
+
+ Simple1 *simple1 = new Simple1( this );
+ tab->addTab( simple1, "new", tr("Simple1") );
+ tab->setCurrentTab( tr("Simple1") );
+
+ Simple2 *simple2 = new Simple2( this );
+ tab->addTab( simple2, "trash", tr("Simple2") );
+
+ m_oldCurrent = simple1;
+
+ connect(m_fire, SIGNAL(activated() ),
+ simple1, SLOT(slotFire() ) );
+}
+
+MainWindow::~MainWindow() {
+ // again nothing to delete because Qt takes care
+}
+
+
+void MainWindow::setDocument( const QString& /*str*/ ) {
+}
+void MainWindow::slotCurrentChanged( QWidget *wid) {
+ disconnect(m_fire, SIGNAL(activated() ),
+ m_oldCurrent, SLOT(slotFire() ) );
+ connect(m_fire, SIGNAL(activated() ),
+ wid, SLOT(slotFire() ) );
+
+ m_oldCurrent = wid;
+}
+
+void MainWindow::initUI() {
+
+ setToolBarsMovable( false );
+
+ QToolBar *menuBarHolder = new QToolBar( this );
+
+ menuBarHolder->setHorizontalStretchable( true );
+ QMenuBar *mb = new QMenuBar( menuBarHolder );
+ QToolBar *tb = new QToolBar( this );
+
+ QPopupMenu *fileMenu = new QPopupMenu( this );
+
+
+ QAction *a = new QAction( tr("Quit"), Resource::loadIconSet("quit_icon"),
+ QString::null, 0, this, "quit_action" );
+ /*
+ * Connect quit to the QApplication quit slot
+ */
+ connect(a, SIGNAL(activated() ),
+ qApp, SLOT(quit() ) );
+ a->addTo( fileMenu );
+
+ a = new QAction(tr("Fire"),
+ Resource::loadIconSet("new"),
+ QString::null, 0, this, "fire_button");
+
+ /* see the power? */
+ a->addTo( fileMenu );
+ a->addTo( tb );
+ m_fire = a;
+
+
+ mb->insertItem(tr("File"), fileMenu );
+
+}
+
+Simple1::Simple1( QWidget* parent, const char* name, WFlags fl )
+ : QWidget( parent, name, fl ) {
+
+ QVBoxLayout *layout = new QVBoxLayout( this );
+ layout->setSpacing( 8 );
+ layout->setMargin( 11 );
+
+
+ QLabel *lbl = new QLabel( this, "a name for the label" );
+ lbl->setText( tr("Click on the button or follow the white rabbit") );
+ layout->addWidget( lbl );
+
+
+ m_button = new QPushButton(this);
+
+
+ m_button->setText( tr("Fire", "translatable quit string" ) );
+ layout->addWidget( m_button );
+
+
+ connect( m_button, SIGNAL(clicked() ),
+ this, SLOT( slotFire() ) );
+}
+
+Simple1::~Simple1() {
+
+}
+
+void Simple1::slotFire() {
+ /*
+ * NOTE: Simple is now a child window of MainWindow
+ * close will hide() Simple and not delete it. But as
+ * the mainwindow is shown all children will be shown as well
+ */
+ close();
+}
+
+
+Simple2::Simple2( QWidget* parent, const char* name, WFlags fl )
+ : QWidget( parent, name, fl ) {
+
+ /*
+ * sets the caption of this toplevel widget
+ * put all translatable string into tr()
+ */
+ setCaption(tr("My Simple Application") );
+
+ /*
+ * A simple vertical layout
+ * either call layout->setAutoAdd( true )
+ * or use layout->addWidget( wid ) to add widgets
+ */
+ QVBoxLayout *layout = new QVBoxLayout( this );
+ layout->setSpacing( 8 );
+ layout->setMargin( 11 );
+
+ /*
+ * creates a label
+ * The first parameter is this widget so the Label is a child
+ * of us and will be deleted when we're deleted.
+ */
+ QLabel *lbl = new QLabel( this, "a name for the label" );
+ /*
+ * Resource will search hard for a Pixmap in $OPIEDIR/pics
+ * to find 'logo/opielogo' You need to pass the subdir
+ * but not the ending
+ */
+ lbl->setPixmap( Resource::loadPixmap("logo/opielogo") );
+ layout->addWidget( lbl );
+
+
+ /* creates a button as child of this widget */
+ m_button = new QPushButton(this);
+ /*
+ * another way to call tr. The first parameter is the string
+ * to translate and the second a hint to the translator
+ */
+ m_button->setText( tr("Fire", "translatable fire string" ) );
+ layout->addWidget( m_button );
+
+
+ connect( m_button, SIGNAL(clicked() ),
+ this, SLOT( slotQuit() ) );
+}
+
+
+Simple2::~Simple2() {
+
+}
+
+void Simple2::slotFire() {
+ /*
+ * We will fire up a sound
+ * Note that Sound will use Resource as well
+ * and we do not need to supply an ending
+ * sounds are found in $OPIEDIR/sounds
+ */
+ Sound snd("hit_target01");
+ snd.play();
+
+}
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 @@
+
+/*
+ * A Simple widget with a button to quit
+ *
+ */
+
+/*
+ * The below sequence is called a guard and guards
+ * against multiple inclusion of header files
+ * NOTE: you need to use unique names among the header files
+ */
+#ifndef QUIET_SIMPLE_DEMO_H
+#define QUIET_SIMPLE_DEMO_H
+
+
+
+
+#include <qmainwindow.h> // from this class we will inherit
+
+
+class QPushButton; // forward declaration to not include the header. This can save time when compiling
+class QAction;
+
+/*
+ * A mainwindow is a special QWidget it helps layouting
+ * toolbar, statusbar, menubar. Got dockable areas
+ * So in one sentence it is a MainWindow :)
+ */
+class MainWindow : public QMainWindow {
+ Q_OBJECT
+public:
+ static QString appName() { return QString::fromLatin1("main-tab"); }
+ MainWindow( QWidget* parent, const char* name, WFlags fl );
+ ~MainWindow();
+
+public slots:
+ void setDocument( const QString& );
+private slots:
+ void slotCurrentChanged( QWidget* wid );
+
+private:
+ void initUI();
+ QAction *m_fire;
+ QWidget* m_oldCurrent;
+};
+
+
+/*
+ * We will just reuse the two simple widgets for now
+ */
+class Simple1 : public QWidget {
+
+ Q_OBJECT
+public:
+
+ Simple1( QWidget* parent = 0, const char * name = 0, WFlags fl = 0 );
+ ~Simple1();
+
+
+public slots:
+ void slotFire();
+
+private:
+ /* my variable */
+ QPushButton* m_button;
+};
+
+class Simple2 : public QWidget {
+ Q_OBJECT
+public:
+
+ Simple2( QWidget* parent = 0, const char * name = 0, WFlags fl = 0 );
+ ~Simple2();
+
+
+
+public slots:
+ void slotFire();
+
+private:
+ /* my variable */
+ QPushButton* m_button;
+};
+
+
+
+#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 @@
+CONFIG EXAMPLE_SIMPLE
+ boolean "Simple Icon Loading and Sound Example"
+ default "n"
+ 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 @@
+# remember each example is based on the other
+CONFIG += qt warn_on quick-app
+TARGET = simple-icon
+
+HEADERS = simple.h
+
+SOURCES = simple.cpp
+
+INCLUDEPATH += $(OPIEDIR)/include
+DEPENDPATH += $(OPIEDIR)/include
+
+
+
+LIBS += -lqpe
+
+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 @@
+Package: opie-simple-icon-example
+Files: bin/simple-icon apps/Examples/simple-icon.desktop
+Priority: optional
+Section: opie/applications
+Maintainer: Holger 'zecke' Freyther <zecke@handhelds.org>
+Architecture: arm
+Depends: task-opie-minimal, opie-pics
+Description: A simple icon example
+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 @@
+#include <qlabel.h> // a label
+#include <qpushbutton.h> // the header file for the QPushButton
+#include <qlayout.h>
+
+#include <qpe/qpeapplication.h> // the QPEApplication
+#include <qpe/resource.h> // for loading icon
+#include <qpe/sound.h> // for playing a sound
+
+#include <opie/oapplicationfactory.h> // a template + macro to save the main method and allow quick launching
+
+#include "simple.h"
+
+/*
+ * implementation of simple
+ */
+
+/*
+ * The factory is used for quicklaunching
+ * 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
+ *
+ * Depending on the global quick launch setting this will create
+ * either a main method or one for our component plugin system
+ */
+
+OPIE_EXPORT_APP( OApplicationFactory<Simple> )
+
+Simple::Simple( QWidget* parent, const char* name, WFlags fl )
+ : QWidget( parent, name, fl ) {
+
+ /*
+ * sets the caption of this toplevel widget
+ * put all translatable string into tr()
+ */
+ setCaption(tr("My Simple Application") );
+
+ /*
+ * A simple vertical layout
+ * either call layout->setAutoAdd( true )
+ * or use layout->addWidget( wid ) to add widgets
+ */
+ QVBoxLayout *layout = new QVBoxLayout( this );
+ layout->setSpacing( 8 );
+ layout->setMargin( 11 );
+
+ /*
+ * creates a label
+ * The first parameter is this widget so the Label is a child
+ * of us and will be deleted when we're deleted.
+ */
+ QLabel *lbl = new QLabel( this, "a name for the label" );
+ /*
+ * Resource will search hard for a Pixmap in $OPIEDIR/pics
+ * to find 'logo/opielogo' You need to pass the subdir
+ * but not the ending
+ */
+ lbl->setPixmap( Resource::loadPixmap("logo/opielogo") );
+ layout->addWidget( lbl );
+
+
+ /* creates a button as child of this widget */
+ m_button = new QPushButton(this);
+ /*
+ * another way to call tr. The first parameter is the string
+ * to translate and the second a hint to the translator
+ */
+ m_button->setText( tr("Fire", "translatable fire string" ) );
+ layout->addWidget( m_button );
+
+ /*
+ * Now we bring the action into it. The power of qt is the dynamic
+ * signal and slots model
+ * Usage is simple connect m_buttons clicked signal to our
+ * slotQuit slot.
+ * We could also have connected a SIGNAL to a SIGNAL or the clicked
+ * signal directly to qApp and SLOT(quit() )
+ */
+ connect( m_button, SIGNAL(clicked() ),
+ this, SLOT( slotQuit() ) );
+}
+
+/*
+ * Our destructor is empty because all child
+ * widgets and layouts will be deleted by Qt.
+ * Same applies to QObjects
+ */
+Simple::~Simple() {
+
+}
+
+void Simple::slotQuit() {
+ /*
+ * We will fire up a sound
+ * Note that Sound will use Resource as well
+ * and we do not need to supply an ending
+ * sounds are found in $OPIEDIR/sounds
+ */
+ Sound snd("hit_target01");
+ snd.play();
+
+}
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 @@
+
+/*
+ * A Simple widget with a button to quit
+ * and Pixmaps and Sound
+ */
+
+/*
+ * The below sequence is called a guard and guards
+ * against multiple inclusion of header files
+ */
+#ifndef QUIET_SIMPLE_DEMO_H
+#define QUIET_SIMPLE_DEMO_H
+
+
+
+
+#include <qwidget.h> // from this class we will inherit
+
+class QPushButton; // forward declaration to not include the header. This can save time when compiling
+
+
+/*
+ * Simple inherits from QWidget
+ * Remeber each example is based on the other
+ */
+class Simple : public QWidget {
+ Q_OBJECT
+public:
+ /*
+ * C'tor for the Simple
+ * make sure to always have these three when you use
+ * the quicklaunch factory ( explained in the implementation )
+ */
+ Simple( QWidget* parent = 0, const char * name = 0, WFlags fl = 0 );
+ ~Simple();
+
+ /*
+ * appName is used by the Application factory.
+ * make sure the name matches the one of the executable
+ */
+ static QString appName() { return QString::fromLatin1("simple-icon"); }
+
+ /*
+ * use private slots: to mark your slots as such
+ * A slot can also be called as a normal method
+ */
+private slots:
+ void slotQuit();
+
+private:
+ /* my variable */
+ QPushButton* m_button;
+};
+
+
+
+
+#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 @@
+CONFIG EXAMPLE_SIMPLE
+ boolean "Simple MainWindow Example"
+ default "n"
+ 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 @@
+CONFIG += qt warn_on quick-app
+
+
+TARGET = simple-main
+
+HEADERS = simple.h
+SOURCES = simple.cpp
+
+
+INCLUDEPATH += $(OPIEDIR)/include
+DEPENDPATH += $(OPIEDIR)/include
+
+
+
+LIBS += -lqpe
+
+include ( $(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 @@
+Package: opie-simple-main-example
+Files: bin/simple-main apps/Examples/simple-main.desktop
+Priority: optional
+Section: opie/applications
+Maintainer: Holger 'zecke' Freyther <zecke@handhelds.org>
+Architecture: arm
+Depends: task-opie-minimal, opie-pics
+Description: A simple example
+Version: $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 @@
+#include <qaction.h> // action
+#include <qmenubar.h> // menubar
+#include <qtoolbar.h> // toolbar
+#include <qlabel.h> // a label
+#include <qpushbutton.h> // the header file for the QPushButton
+#include <qlayout.h>
+
+#include <qpe/qpeapplication.h> // the QPEApplication
+#include <qpe/resource.h>
+
+#include <opie/oapplicationfactory.h> // a template + macro to save the main method and allow quick launching
+
+#include "simple.h"
+
+/*
+ * implementation of simple
+ */
+
+/*
+ * The factory is used for quicklaunching
+ * 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
+ *
+ * Depending on the global quick launch setting this will create
+ * either a main method or one for our component plugin system
+ */
+
+OPIE_EXPORT_APP( OApplicationFactory<MainWindow> )
+
+MainWindow::MainWindow(QWidget *parent, const char* name, WFlags fl )
+ : QMainWindow( parent, name, fl ) {
+ setCaption(tr("My MainWindow") );
+ setIcon( Resource::loadPixmap("new") );
+ /*
+ * out mainwindow should have a menubar
+ * a toolbar, a mainwidget and use Resource
+ * to get the IconSets
+ */
+ /*
+ * we initialize the GUI in a different methid
+ */
+ initUI();
+
+ Simple *simple = new Simple( this );
+ setCentralWidget( simple );
+
+ /*
+ * If you use signal and slots do not include the parameter
+ * names inside
+ * so SIGNAL(fooBar(int) ) and NOT SIGNAL(fooBar(int foo) )
+ */
+ /*
+ * We connect the activation of our QAction
+ * to the slot connected to the firebutton
+ * We could also connect the signal to the clicked
+ * signal of the button
+ */
+ connect(m_fire, SIGNAL(activated() ),
+ simple, SLOT(slotFire() ) );
+}
+
+MainWindow::~MainWindow() {
+ // again nothing to delete because Qt takes care
+}
+
+/*
+ * set Document is a special function used by Document
+ * centric applications.
+ * In example if Opie receives a Todo via IrDa it uses
+ * setDocument via QCOP the IPC system to load the card
+ * Or If you decide to open a file in filemanager with textedit
+ * setDocument is called via IPC in textedit.
+ * Also any call to QPE/Application/xyz and xyz is currently not running
+ * leads to the start of xyz and delivering of the QCOP call
+ * But more on QCOP in the next application
+ */
+void MainWindow::setDocument( const QString& /*str*/ ) {
+ // in our case empty but you should see if it is a direct
+ // file request or if it is a DocLnk.
+ // A DocLnk is Link to an Document so you would end up
+ // opening the document behind the file you got
+}
+
+/*
+ * Two new concepts with this Method
+ * 1. QAction. An action can be grouped and emits
+ * an activated signal. Action a universal useable
+ * you can just plug/addTo in most Qt widgets. For example
+ * the same action can be plugged into a ToolBar, MenuBar,
+ * QPopupMenu and other widgets but you do not need to worry
+ * about it
+ *
+ * 2. an IconSet contains pixmaps and provides them scaled down, scaled up
+ * enabled and disabled. SO if you use QIConSet and the toolbar
+ * size changes to use big pixmaps you will not use upscaled icons
+ * but the right ones thanks to QIconSet and Resource
+ */
+
+void MainWindow::initUI() {
+/*
+ * We want to provde a File Menu with Quit as option
+ * and a Fire Toolbutton ( QAction )
+ * So we need two actions
+ * A toolbar and a popupMenu
+ */
+ setToolBarsMovable( false );
+ /*
+ *We don't want the static toolbar but share it with the
+ * toolbar on small screens
+ */
+ QToolBar *menuBarHolder = new QToolBar( this );
+ /* we allow the menubarholder to become bigger than
+ * the screen width and to offer a > for the additional items
+ */
+ menuBarHolder->setHorizontalStretchable( true );
+ QMenuBar *mb = new QMenuBar( menuBarHolder );
+ QToolBar *tb = new QToolBar( this );
+
+ QPopupMenu *fileMenu = new QPopupMenu( this );
+
+ /*
+ * we create our first action with the Text Quit
+ * a IconSet, no menu name, no acceleration ( keyboard shortcut ),
+ * with parent this, and name "quit_action"
+ */
+ /*
+ * Note if you want a picture out of the inline directory
+ * you musn't prefix inline/ inline means these pics are built in
+ * into libqpe so the name without ending and directory is enough
+ */
+ QAction *a = new QAction( tr("Quit"), Resource::loadIconSet("quit_icon"),
+ QString::null, 0, this, "quit_action" );
+ /*
+ * Connect quit to the QApplication quit slot
+ */
+ connect(a, SIGNAL(activated() ),
+ qApp, SLOT(quit() ) );
+ a->addTo( fileMenu );
+
+ a = new QAction(tr("Fire"),
+ Resource::loadIconSet("new"),
+ QString::null, 0, this, "fire_button");
+
+ /* see the power? */
+ a->addTo( fileMenu );
+ a->addTo( tb );
+ m_fire = a;
+
+
+ mb->insertItem(tr("File"), fileMenu );
+
+}
+
+Simple::Simple( QWidget* parent, const char* name, WFlags fl )
+ : QWidget( parent, name, fl ) {
+
+ /*
+ * sets the caption of this toplevel widget
+ * put all translatable string into tr()
+ */
+ setCaption(tr("My Simple Application") );
+
+ /*
+ * A simple vertical layout
+ * either call layout->setAutoAdd( true )
+ * or use layout->addWidget( wid ) to add widgets
+ */
+ QVBoxLayout *layout = new QVBoxLayout( this );
+ layout->setSpacing( 8 );
+ layout->setMargin( 11 );
+
+ /*
+ * creates a label
+ * The first parameter is this widget so the Label is a child
+ * of us and will be deleted when we're deleted.
+ */
+ QLabel *lbl = new QLabel( this, "a name for the label" );
+ lbl->setText( tr("Click on the button or follow the white rabbit") );
+ layout->addWidget( lbl );
+
+
+ /* creates a button as child of this widget */
+ m_button = new QPushButton(this);
+ /*
+ * another way to call tr. The first parameter is the string
+ * to translate and the second a hint to the translator
+ */
+ m_button->setText( tr("Fire", "translatable quit string" ) );
+ layout->addWidget( m_button );
+
+ /*
+ * Now we bring the action into it. The power of qt is the dynamic
+ * signal and slots model
+ * Usage is simple connect m_buttons clicked signal to our
+ * slotQuit slot.
+ * We could also have connected a SIGNAL to a SIGNAL or the clicked
+ * signal directly to qApp and SLOT(quit() )
+ */
+ connect( m_button, SIGNAL(clicked() ),
+ this, SLOT( slotFire() ) );
+}
+
+/*
+ * Our destructor is empty because all child
+ * widgets and layouts will be deleted by Qt.
+ * Same applies to QObjects
+ */
+Simple::~Simple() {
+
+}
+
+void Simple::slotFire() {
+ /*
+ * NOTE: Simple is now a child window of MainWindow
+ * close will hide() Simple and not delete it. But as
+ * the mainwindow is shown all children will be shown as well
+ */
+ close();
+}
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 @@
+
+/*
+ * A Simple widget with a button to quit
+ *
+ */
+
+/*
+ * The below sequence is called a guard and guards
+ * against multiple inclusion of header files
+ * NOTE: you need to use unique names among the header files
+ */
+#ifndef QUIET_SIMPLE_DEMO_H
+#define QUIET_SIMPLE_DEMO_H
+
+
+
+
+#include <qmainwindow.h> // from this class we will inherit
+
+
+class QPushButton; // forward declaration to not include the header. This can save time when compiling
+class QAction;
+
+/*
+ * A mainwindow is a special QWidget it helps layouting
+ * toolbar, statusbar, menubar. Got dockable areas
+ * So in one sentence it is a MainWindow :)
+ */
+class MainWindow : public QMainWindow {
+ Q_OBJECT
+public:
+ static QString appName() { return QString::fromLatin1("simple-main"); }
+ MainWindow( QWidget* parent, const char* name, WFlags fl );
+ ~MainWindow();
+
+public slots:
+ void setDocument( const QString& );
+
+private:
+ void initUI();
+ QAction *m_fire;
+};
+
+
+/*
+ * Simple inherits from QWidget
+ */
+class Simple : public QWidget {
+ /*
+ * Q_OBJECT must always be the first thing you include
+ * This is a macro and is responsible for the concepts of
+ * dynamic signal and slots and other MetaObjects as
+ * superClass(), inherits(), isA()...
+ * If you use multiple inheritance include the class derived
+ * from QObject first
+ */
+ Q_OBJECT
+public:
+ /*
+ * C'tor for the Simple
+ * make sure to always have these three when you use
+ * the quicklaunch factory ( explained in the implementation )
+ */
+ Simple( QWidget* parent = 0, const char * name = 0, WFlags fl = 0 );
+ ~Simple();
+
+ /*
+ * We now make it public because our mainwindow wants to call it
+ */
+public slots:
+ void slotFire();
+
+private:
+ /* my variable */
+ QPushButton* m_button;
+};
+
+
+
+
+#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 @@
+CONFIG EXAMPLE_SIMPLE
+ boolean "Simple Example"
+ default "n"
+ 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 @@
+# '#' introduces a comment
+#CONFIG says the qmake buildsystem what to use
+#
+CONFIG += qt warn_on quick-app
+# qt = Use qt
+# warn_on = warnings are on
+# quick-app = Tell the buildsystem that the apps is quick-launchable
+#
+
+# Note if you do not supply quick-app you need to set
+# TEMPLATE = app or TEMPLATE = lib depending on if you want to build an executable or lib
+# and DESTDIR= $(OPIEDIR)/bin or $(OPIEDIR)/lib
+
+TARGET = simple
+# the name of the resulting object
+
+HEADERS = simple.h
+# A list header files
+
+
+SOURCES = simple.cpp
+# A list of source files
+
+INTERFACES =
+# list of ui files
+
+INCLUDEPATH += $(OPIEDIR)/include
+DEPENDPATH += $(OPIEDIR)/include
+
+
+
+LIBS += -lqpe
+# libs to link against
+
+#Important include the global include.pro just like below
+
+
+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 @@
+Package: opie-simple-example
+Files: bin/simple apps/Examples/simple.desktop
+Priority: optional
+Section: opie/applications
+Maintainer: Holger 'zecke' Freyther <zecke@handhelds.org>
+Architecture: arm
+Depends: task-opie-minimal, opie-pics
+Description: A simple example
+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 @@
+#include <qlabel.h> // a label
+#include <qpushbutton.h> // the header file for the QPushButton
+#include <qlayout.h>
+
+#include <qpe/qpeapplication.h> // the QPEApplication
+
+#include <opie/oapplicationfactory.h> // a template + macro to save the main method and allow quick launching
+
+#include "simple.h"
+
+/*
+ * implementation of simple
+ */
+
+/*
+ * The factory is used for quicklaunching
+ * 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
+ *
+ * Depending on the global quick launch setting this will create
+ * either a main method or one for our component plugin system
+ */
+
+OPIE_EXPORT_APP( OApplicationFactory<Simple> )
+
+Simple::Simple( QWidget* parent, const char* name, WFlags fl )
+ : QWidget( parent, name, fl ) {
+
+ /*
+ * sets the caption of this toplevel widget
+ * put all translatable string into tr()
+ */
+ setCaption(tr("My Simple Application") );
+
+ /*
+ * A simple vertical layout
+ * either call layout->setAutoAdd( true )
+ * or use layout->addWidget( wid ) to add widgets
+ */
+ QVBoxLayout *layout = new QVBoxLayout( this );
+ layout->setSpacing( 8 );
+ layout->setMargin( 11 );
+
+ /*
+ * creates a label
+ * The first parameter is this widget so the Label is a child
+ * of us and will be deleted when we're deleted.
+ */
+ QLabel *lbl = new QLabel( this, "a name for the label" );
+ lbl->setText( tr("Click on the button or follow the white rabbit") );
+ layout->addWidget( lbl );
+
+
+ /* creates a button as child of this widget */
+ m_button = new QPushButton(this);
+ /*
+ * another way to call tr. The first parameter is the string
+ * to translate and the second a hint to the translator
+ */
+ m_button->setText( tr("Quit", "translatable quit string" ) );
+ layout->addWidget( m_button );
+
+ /*
+ * Now we bring the action into it. The power of qt is the dynamic
+ * signal and slots model
+ * Usage is simple connect m_buttons clicked signal to our
+ * slotQuit slot.
+ * We could also have connected a SIGNAL to a SIGNAL or the clicked
+ * signal directly to qApp and SLOT(quit() )
+ */
+ connect( m_button, SIGNAL(clicked() ),
+ this, SLOT( slotQuit() ) );
+}
+
+/*
+ * Our destructor is empty because all child
+ * widgets and layouts will be deleted by Qt.
+ * Same applies to QObjects
+ */
+Simple::~Simple() {
+
+}
+
+void Simple::slotQuit() {
+ /*
+ * we will close this window and Qt will recognize that
+ * the last window was closed and initiate a shutdown
+ */
+ close();
+}
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 @@
+
+/*
+ * A Simple widget with a button to quit
+ *
+ */
+
+/*
+ * The below sequence is called a guard and guards
+ * against multiple inclusion of header files
+ * NOTE: you need to use unique names among the header files
+ */
+#ifndef QUIET_SIMPLE_DEMO_H
+#define QUIET_SIMPLE_DEMO_H
+
+
+
+
+#include <qwidget.h> // from this class we will inherit
+
+class QPushButton; // forward declaration to not include the header. This can save time when compiling
+
+
+/*
+ * Simple inherits from QWidget
+ */
+class Simple : public QWidget {
+ /*
+ * Q_OBJECT must always be the first thing you include
+ * This is a macro and is responsible for the concepts of
+ * dynamic signal and slots and other MetaObjects as
+ * superClass(), inherits(), isA()...
+ * If you use multiple inheritance include the class derived
+ * from QObject first
+ */
+ Q_OBJECT
+public:
+ /*
+ * C'tor for the Simple
+ * make sure to always have these three when you use
+ * the quicklaunch factory ( explained in the implementation )
+ */
+ Simple( QWidget* parent = 0, const char * name = 0, WFlags fl = 0 );
+ ~Simple();
+
+ /*
+ * appName is used by the Application factory.
+ * make sure the name matches the one of the executable
+ */
+ static QString appName() { return QString::fromLatin1("simple"); }
+
+ /*
+ * use private slots: to mark your slots as such
+ * A slot can also be called as a normal method
+ */
+private slots:
+ void slotQuit();
+
+private:
+ /* my variable */
+ QPushButton* m_button;
+};
+
+
+
+
+#endif