From 4c3a1de5289631db05b86a07092f0a334608dcf6 Mon Sep 17 00:00:00 2001 From: zecke Date: Sat, 30 Aug 2003 20:23:05 +0000 Subject: 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 --- (limited to 'examples/simple-icon') 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 +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 // a label +#include // the header file for the QPushButton +#include + +#include // the QPEApplication +#include // for loading icon +#include // for playing a sound + +#include // 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( 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 // 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 -- cgit v0.9.0.2