author | zecke <zecke> | 2004-03-14 20:08:59 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-03-14 20:08:59 (UTC) |
commit | 0d79c003839718ae70b3b997162044abd5c26bf6 (patch) (unidiff) | |
tree | 19708b041da3a09df8f3b571cd634a846f4ad6d7 /examples/main-tab | |
parent | 05c8d999941989a97a581fb5822437034ec10fd7 (diff) | |
download | opie-0d79c003839718ae70b3b997162044abd5c26bf6.zip opie-0d79c003839718ae70b3b997162044abd5c26bf6.tar.gz opie-0d79c003839718ae70b3b997162044abd5c26bf6.tar.bz2 |
Update the Examples
-rw-r--r-- | examples/main-tab/config.in | 2 | ||||
-rw-r--r-- | examples/main-tab/example.pro | 2 | ||||
-rw-r--r-- | examples/main-tab/simple.cpp | 8 |
3 files changed, 7 insertions, 5 deletions
diff --git a/examples/main-tab/config.in b/examples/main-tab/config.in index e021d59..3a67bcb 100644 --- a/examples/main-tab/config.in +++ b/examples/main-tab/config.in | |||
@@ -1,4 +1,4 @@ | |||
1 | config MAIN_TAB_EXAMPLE | 1 | config MAIN_TAB_EXAMPLE |
2 | boolean "Mainwindow with OTabWidget example" | 2 | boolean "Mainwindow with OTabWidget example" |
3 | default "y" | 3 | default "y" |
4 | depends ( LIBQPE || LIBQPE-X11 ) && EXAMPLES && LIBOPIE | 4 | depends ( LIBQPE || LIBQPE-X11 ) && EXAMPLES && LIBOPIEUI2 |
diff --git a/examples/main-tab/example.pro b/examples/main-tab/example.pro index 3cafc20..87abf22 100644 --- a/examples/main-tab/example.pro +++ b/examples/main-tab/example.pro | |||
@@ -1,17 +1,17 @@ | |||
1 | CONFIG += qt warn_on quick-app | 1 | CONFIG += qt warn_on quick-app |
2 | 2 | ||
3 | 3 | ||
4 | TARGET = main-tab | 4 | TARGET = main-tab |
5 | 5 | ||
6 | HEADERS = simple.h | 6 | HEADERS = simple.h |
7 | SOURCES = simple.cpp | 7 | SOURCES = simple.cpp |
8 | 8 | ||
9 | 9 | ||
10 | INCLUDEPATH += $(OPIEDIR)/include | 10 | INCLUDEPATH += $(OPIEDIR)/include |
11 | DEPENDPATH += $(OPIEDIR)/include | 11 | DEPENDPATH += $(OPIEDIR)/include |
12 | 12 | ||
13 | 13 | ||
14 | # we now also include opie | 14 | # we now also include opie |
15 | LIBS += -lqpe -lopie | 15 | LIBS += -lqpe -lopieui2 |
16 | 16 | ||
17 | include ( $(OPIEDIR)/include.pro ) | 17 | include ( $(OPIEDIR)/include.pro ) |
diff --git a/examples/main-tab/simple.cpp b/examples/main-tab/simple.cpp index c5a6d5a..7edb557 100644 --- a/examples/main-tab/simple.cpp +++ b/examples/main-tab/simple.cpp | |||
@@ -1,211 +1,213 @@ | |||
1 | #include <qaction.h> // action | 1 | #include <qaction.h> // action |
2 | #include <qmenubar.h> // menubar | 2 | #include <qmenubar.h> // menubar |
3 | #include <qtoolbar.h> // toolbar | 3 | #include <qtoolbar.h> // toolbar |
4 | #include <qlabel.h> // a label | 4 | #include <qlabel.h> // a label |
5 | #include <qpushbutton.h> // the header file for the QPushButton | 5 | #include <qpushbutton.h> // the header file for the QPushButton |
6 | #include <qlayout.h> | 6 | #include <qlayout.h> |
7 | 7 | ||
8 | #include <qpe/qpeapplication.h> // the QPEApplication | 8 | #include <qpe/qpeapplication.h> // the QPEApplication |
9 | #include <qpe/resource.h> | 9 | #include <qpe/resource.h> |
10 | #include <qpe/sound.h> | 10 | #include <qpe/sound.h> |
11 | 11 | ||
12 | #include <opie/oapplicationfactory.h> // a template + macro to save the main method and allow quick launching | 12 | #include <opie2/oapplicationfactory.h> // a template + macro to save the main method and allow quick launching |
13 | #include <opie/otabwidget.h> | 13 | #include <opie2/otabwidget.h> |
14 | 14 | ||
15 | #include "simple.h" | 15 | #include "simple.h" |
16 | 16 | ||
17 | /* | 17 | /* |
18 | * implementation of simple | 18 | * implementation of simple |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | * The factory is used for quicklaunching | 22 | * The factory is used for quicklaunching |
23 | * 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 | 23 | * 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 |
24 | * | 24 | * |
25 | * Depending on the global quick launch setting this will create | 25 | * Depending on the global quick launch setting this will create |
26 | * either a main method or one for our component plugin system | 26 | * either a main method or one for our component plugin system |
27 | */ | 27 | */ |
28 | 28 | ||
29 | /* The OApplicationFactory is in the Opie::Core namespace */ | ||
30 | using namespace Opie::Core; | ||
29 | OPIE_EXPORT_APP( OApplicationFactory<MainWindow> ) | 31 | OPIE_EXPORT_APP( OApplicationFactory<MainWindow> ) |
30 | 32 | ||
31 | MainWindow::MainWindow(QWidget *parent, const char* name, WFlags fl ) | 33 | MainWindow::MainWindow(QWidget *parent, const char* name, WFlags fl ) |
32 | : QMainWindow( parent, name, fl ) { | 34 | : QMainWindow( parent, name, fl ) { |
33 | setCaption(tr("My MainWindow") ); | 35 | setCaption(tr("My MainWindow") ); |
34 | 36 | ||
35 | initUI(); | 37 | initUI(); |
36 | 38 | ||
37 | 39 | ||
38 | /* | 40 | /* |
39 | * Tab widget as central | 41 | * Tab widget as central |
40 | */ | 42 | */ |
41 | OTabWidget *tab = new OTabWidget(this); | 43 | Opie::Ui::OTabWidget *tab = new Opie::Ui::OTabWidget(this); |
42 | connect(tab, SIGNAL(currentChanged(QWidget*) ), | 44 | connect(tab, SIGNAL(currentChanged(QWidget*) ), |
43 | this, SLOT( slotCurrentChanged(QWidget*) ) ); | 45 | this, SLOT( slotCurrentChanged(QWidget*) ) ); |
44 | setCentralWidget( tab ); | 46 | setCentralWidget( tab ); |
45 | 47 | ||
46 | Simple1 *simple1 = new Simple1( this ); | 48 | Simple1 *simple1 = new Simple1( this ); |
47 | tab->addTab( simple1, "new", tr("Simple1") ); | 49 | tab->addTab( simple1, "new", tr("Simple1") ); |
48 | tab->setCurrentTab( tr("Simple1") ); | 50 | tab->setCurrentTab( tr("Simple1") ); |
49 | 51 | ||
50 | Simple2 *simple2 = new Simple2( this ); | 52 | Simple2 *simple2 = new Simple2( this ); |
51 | tab->addTab( simple2, "trash", tr("Simple2") ); | 53 | tab->addTab( simple2, "trash", tr("Simple2") ); |
52 | 54 | ||
53 | m_oldCurrent = simple1; | 55 | m_oldCurrent = simple1; |
54 | 56 | ||
55 | connect(m_fire, SIGNAL(activated() ), | 57 | connect(m_fire, SIGNAL(activated() ), |
56 | simple1, SLOT(slotFire() ) ); | 58 | simple1, SLOT(slotFire() ) ); |
57 | } | 59 | } |
58 | 60 | ||
59 | MainWindow::~MainWindow() { | 61 | MainWindow::~MainWindow() { |
60 | // again nothing to delete because Qt takes care | 62 | // again nothing to delete because Qt takes care |
61 | } | 63 | } |
62 | 64 | ||
63 | 65 | ||
64 | void MainWindow::setDocument( const QString& /*str*/ ) { | 66 | void MainWindow::setDocument( const QString& /*str*/ ) { |
65 | } | 67 | } |
66 | void MainWindow::slotCurrentChanged( QWidget *wid) { | 68 | void MainWindow::slotCurrentChanged( QWidget *wid) { |
67 | disconnect(m_fire, SIGNAL(activated() ), | 69 | disconnect(m_fire, SIGNAL(activated() ), |
68 | m_oldCurrent, SLOT(slotFire() ) ); | 70 | m_oldCurrent, SLOT(slotFire() ) ); |
69 | connect(m_fire, SIGNAL(activated() ), | 71 | connect(m_fire, SIGNAL(activated() ), |
70 | wid, SLOT(slotFire() ) ); | 72 | wid, SLOT(slotFire() ) ); |
71 | 73 | ||
72 | m_oldCurrent = wid; | 74 | m_oldCurrent = wid; |
73 | } | 75 | } |
74 | 76 | ||
75 | void MainWindow::initUI() { | 77 | void MainWindow::initUI() { |
76 | 78 | ||
77 | setToolBarsMovable( false ); | 79 | setToolBarsMovable( false ); |
78 | 80 | ||
79 | QToolBar *menuBarHolder = new QToolBar( this ); | 81 | QToolBar *menuBarHolder = new QToolBar( this ); |
80 | 82 | ||
81 | menuBarHolder->setHorizontalStretchable( true ); | 83 | menuBarHolder->setHorizontalStretchable( true ); |
82 | QMenuBar *mb = new QMenuBar( menuBarHolder ); | 84 | QMenuBar *mb = new QMenuBar( menuBarHolder ); |
83 | QToolBar *tb = new QToolBar( this ); | 85 | QToolBar *tb = new QToolBar( this ); |
84 | 86 | ||
85 | QPopupMenu *fileMenu = new QPopupMenu( this ); | 87 | QPopupMenu *fileMenu = new QPopupMenu( this ); |
86 | 88 | ||
87 | 89 | ||
88 | QAction *a = new QAction( tr("Quit"), Resource::loadIconSet("quit_icon"), | 90 | QAction *a = new QAction( tr("Quit"), Resource::loadIconSet("quit_icon"), |
89 | QString::null, 0, this, "quit_action" ); | 91 | QString::null, 0, this, "quit_action" ); |
90 | /* | 92 | /* |
91 | * Connect quit to the QApplication quit slot | 93 | * Connect quit to the QApplication quit slot |
92 | */ | 94 | */ |
93 | connect(a, SIGNAL(activated() ), | 95 | connect(a, SIGNAL(activated() ), |
94 | qApp, SLOT(quit() ) ); | 96 | qApp, SLOT(quit() ) ); |
95 | a->addTo( fileMenu ); | 97 | a->addTo( fileMenu ); |
96 | 98 | ||
97 | a = new QAction(tr("Fire"), | 99 | a = new QAction(tr("Fire"), |
98 | Resource::loadIconSet("new"), | 100 | Resource::loadIconSet("new"), |
99 | QString::null, 0, this, "fire_button"); | 101 | QString::null, 0, this, "fire_button"); |
100 | 102 | ||
101 | /* see the power? */ | 103 | /* see the power? */ |
102 | a->addTo( fileMenu ); | 104 | a->addTo( fileMenu ); |
103 | a->addTo( tb ); | 105 | a->addTo( tb ); |
104 | m_fire = a; | 106 | m_fire = a; |
105 | 107 | ||
106 | 108 | ||
107 | mb->insertItem(tr("File"), fileMenu ); | 109 | mb->insertItem(tr("File"), fileMenu ); |
108 | 110 | ||
109 | } | 111 | } |
110 | 112 | ||
111 | Simple1::Simple1( QWidget* parent, const char* name, WFlags fl ) | 113 | Simple1::Simple1( QWidget* parent, const char* name, WFlags fl ) |
112 | : QWidget( parent, name, fl ) { | 114 | : QWidget( parent, name, fl ) { |
113 | 115 | ||
114 | QVBoxLayout *layout = new QVBoxLayout( this ); | 116 | QVBoxLayout *layout = new QVBoxLayout( this ); |
115 | layout->setSpacing( 8 ); | 117 | layout->setSpacing( 8 ); |
116 | layout->setMargin( 11 ); | 118 | layout->setMargin( 11 ); |
117 | 119 | ||
118 | 120 | ||
119 | QLabel *lbl = new QLabel( this, "a name for the label" ); | 121 | QLabel *lbl = new QLabel( this, "a name for the label" ); |
120 | lbl->setText( tr("Click on the button or follow the white rabbit") ); | 122 | lbl->setText( tr("Click on the button or follow the white rabbit") ); |
121 | layout->addWidget( lbl ); | 123 | layout->addWidget( lbl ); |
122 | 124 | ||
123 | 125 | ||
124 | m_button = new QPushButton(this); | 126 | m_button = new QPushButton(this); |
125 | 127 | ||
126 | 128 | ||
127 | m_button->setText( tr("Fire", "translatable quit string" ) ); | 129 | m_button->setText( tr("Fire", "translatable quit string" ) ); |
128 | layout->addWidget( m_button ); | 130 | layout->addWidget( m_button ); |
129 | 131 | ||
130 | 132 | ||
131 | connect( m_button, SIGNAL(clicked() ), | 133 | connect( m_button, SIGNAL(clicked() ), |
132 | this, SLOT( slotFire() ) ); | 134 | this, SLOT( slotFire() ) ); |
133 | } | 135 | } |
134 | 136 | ||
135 | Simple1::~Simple1() { | 137 | Simple1::~Simple1() { |
136 | 138 | ||
137 | } | 139 | } |
138 | 140 | ||
139 | void Simple1::slotFire() { | 141 | void Simple1::slotFire() { |
140 | /* | 142 | /* |
141 | * NOTE: Simple is now a child window of MainWindow | 143 | * NOTE: Simple is now a child window of MainWindow |
142 | * close will hide() Simple and not delete it. But as | 144 | * close will hide() Simple and not delete it. But as |
143 | * the mainwindow is shown all children will be shown as well | 145 | * the mainwindow is shown all children will be shown as well |
144 | */ | 146 | */ |
145 | close(); | 147 | close(); |
146 | } | 148 | } |
147 | 149 | ||
148 | 150 | ||
149 | Simple2::Simple2( QWidget* parent, const char* name, WFlags fl ) | 151 | Simple2::Simple2( QWidget* parent, const char* name, WFlags fl ) |
150 | : QWidget( parent, name, fl ) { | 152 | : QWidget( parent, name, fl ) { |
151 | 153 | ||
152 | /* | 154 | /* |
153 | * sets the caption of this toplevel widget | 155 | * sets the caption of this toplevel widget |
154 | * put all translatable string into tr() | 156 | * put all translatable string into tr() |
155 | */ | 157 | */ |
156 | setCaption(tr("My Simple Application") ); | 158 | setCaption(tr("My Simple Application") ); |
157 | 159 | ||
158 | /* | 160 | /* |
159 | * A simple vertical layout | 161 | * A simple vertical layout |
160 | * either call layout->setAutoAdd( true ) | 162 | * either call layout->setAutoAdd( true ) |
161 | * or use layout->addWidget( wid ) to add widgets | 163 | * or use layout->addWidget( wid ) to add widgets |
162 | */ | 164 | */ |
163 | QVBoxLayout *layout = new QVBoxLayout( this ); | 165 | QVBoxLayout *layout = new QVBoxLayout( this ); |
164 | layout->setSpacing( 8 ); | 166 | layout->setSpacing( 8 ); |
165 | layout->setMargin( 11 ); | 167 | layout->setMargin( 11 ); |
166 | 168 | ||
167 | /* | 169 | /* |
168 | * creates a label | 170 | * creates a label |
169 | * The first parameter is this widget so the Label is a child | 171 | * The first parameter is this widget so the Label is a child |
170 | * of us and will be deleted when we're deleted. | 172 | * of us and will be deleted when we're deleted. |
171 | */ | 173 | */ |
172 | QLabel *lbl = new QLabel( this, "a name for the label" ); | 174 | QLabel *lbl = new QLabel( this, "a name for the label" ); |
173 | /* | 175 | /* |
174 | * Resource will search hard for a Pixmap in $OPIEDIR/pics | 176 | * Resource will search hard for a Pixmap in $OPIEDIR/pics |
175 | * to find 'logo/opielogo' You need to pass the subdir | 177 | * to find 'logo/opielogo' You need to pass the subdir |
176 | * but not the ending | 178 | * but not the ending |
177 | */ | 179 | */ |
178 | lbl->setPixmap( Resource::loadPixmap("logo/opielogo") ); | 180 | lbl->setPixmap( Resource::loadPixmap("logo/opielogo") ); |
179 | layout->addWidget( lbl ); | 181 | layout->addWidget( lbl ); |
180 | 182 | ||
181 | 183 | ||
182 | /* creates a button as child of this widget */ | 184 | /* creates a button as child of this widget */ |
183 | m_button = new QPushButton(this); | 185 | m_button = new QPushButton(this); |
184 | /* | 186 | /* |
185 | * another way to call tr. The first parameter is the string | 187 | * another way to call tr. The first parameter is the string |
186 | * to translate and the second a hint to the translator | 188 | * to translate and the second a hint to the translator |
187 | */ | 189 | */ |
188 | m_button->setText( tr("Fire", "translatable fire string" ) ); | 190 | m_button->setText( tr("Fire", "translatable fire string" ) ); |
189 | layout->addWidget( m_button ); | 191 | layout->addWidget( m_button ); |
190 | 192 | ||
191 | 193 | ||
192 | connect( m_button, SIGNAL(clicked() ), | 194 | connect( m_button, SIGNAL(clicked() ), |
193 | this, SLOT( slotQuit() ) ); | 195 | this, SLOT( slotQuit() ) ); |
194 | } | 196 | } |
195 | 197 | ||
196 | 198 | ||
197 | Simple2::~Simple2() { | 199 | Simple2::~Simple2() { |
198 | 200 | ||
199 | } | 201 | } |
200 | 202 | ||
201 | void Simple2::slotFire() { | 203 | void Simple2::slotFire() { |
202 | /* | 204 | /* |
203 | * We will fire up a sound | 205 | * We will fire up a sound |
204 | * Note that Sound will use Resource as well | 206 | * Note that Sound will use Resource as well |
205 | * and we do not need to supply an ending | 207 | * and we do not need to supply an ending |
206 | * sounds are found in $OPIEDIR/sounds | 208 | * sounds are found in $OPIEDIR/sounds |
207 | */ | 209 | */ |
208 | Sound snd("hit_target01"); | 210 | Sound snd("hit_target01"); |
209 | snd.play(); | 211 | snd.play(); |
210 | 212 | ||
211 | } | 213 | } |