summaryrefslogtreecommitdiff
path: root/examples/simple/simple.cpp
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 /examples/simple/simple.cpp
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 (limited to 'examples/simple/simple.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--examples/simple/simple.cpp89
1 files changed, 89 insertions, 0 deletions
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();
+}