summaryrefslogtreecommitdiff
path: root/examples/simple
Side-by-side diff
Diffstat (limited to 'examples/simple') (more/less context) (ignore whitespace changes)
-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
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 @@
+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