summaryrefslogtreecommitdiff
path: root/examples/simple/simple.cpp
Unidiff
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 @@
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
7#include <opie/oapplicationfactory.h> // a template + macro to save the main method and allow quick launching
8
9#include "simple.h"
10
11/*
12 * implementation of simple
13 */
14
15/*
16 * The factory is used for quicklaunching
17 * 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
18 *
19 * Depending on the global quick launch setting this will create
20 * either a main method or one for our component plugin system
21 */
22
23OPIE_EXPORT_APP( OApplicationFactory<Simple> )
24
25Simple::Simple( QWidget* parent, const char* name, WFlags fl )
26 : QWidget( parent, name, fl ) {
27
28 /*
29 * sets the caption of this toplevel widget
30 * put all translatable string into tr()
31 */
32 setCaption(tr("My Simple Application") );
33
34 /*
35 * A simple vertical layout
36 * either call layout->setAutoAdd( true )
37 * or use layout->addWidget( wid ) to add widgets
38 */
39 QVBoxLayout *layout = new QVBoxLayout( this );
40 layout->setSpacing( 8 );
41 layout->setMargin( 11 );
42
43 /*
44 * creates a label
45 * The first parameter is this widget so the Label is a child
46 * of us and will be deleted when we're deleted.
47 */
48 QLabel *lbl = new QLabel( this, "a name for the label" );
49 lbl->setText( tr("Click on the button or follow the white rabbit") );
50 layout->addWidget( lbl );
51
52
53 /* creates a button as child of this widget */
54 m_button = new QPushButton(this);
55 /*
56 * another way to call tr. The first parameter is the string
57 * to translate and the second a hint to the translator
58 */
59 m_button->setText( tr("Quit", "translatable quit string" ) );
60 layout->addWidget( m_button );
61
62 /*
63 * Now we bring the action into it. The power of qt is the dynamic
64 * signal and slots model
65 * Usage is simple connect m_buttons clicked signal to our
66 * slotQuit slot.
67 * We could also have connected a SIGNAL to a SIGNAL or the clicked
68 * signal directly to qApp and SLOT(quit() )
69 */
70 connect( m_button, SIGNAL(clicked() ),
71 this, SLOT( slotQuit() ) );
72}
73
74/*
75 * Our destructor is empty because all child
76 * widgets and layouts will be deleted by Qt.
77 * Same applies to QObjects
78 */
79Simple::~Simple() {
80
81}
82
83void Simple::slotQuit() {
84 /*
85 * we will close this window and Qt will recognize that
86 * the last window was closed and initiate a shutdown
87 */
88 close();
89}