author | drw <drw> | 2005-06-15 22:39:20 (UTC) |
---|---|---|
committer | drw <drw> | 2005-06-15 22:39:20 (UTC) |
commit | e0205bac48b9d23af9feb48004c24fcf7a5e8200 (patch) (unidiff) | |
tree | 2faa077192fd0bfc4fc409f0513cc0e82113fa9e /examples/simple-main | |
parent | d2474c8e654d223b85b6200ce09fabd3a40af8e3 (diff) | |
download | opie-e0205bac48b9d23af9feb48004c24fcf7a5e8200.zip opie-e0205bac48b9d23af9feb48004c24fcf7a5e8200.tar.gz opie-e0205bac48b9d23af9feb48004c24fcf7a5e8200.tar.bz2 |
Resource -> OResource
-rw-r--r-- | examples/simple-main/config.in | 2 | ||||
-rw-r--r-- | examples/simple-main/opie-simple.control | 2 | ||||
-rw-r--r-- | examples/simple-main/simple.cpp | 8 |
3 files changed, 6 insertions, 6 deletions
diff --git a/examples/simple-main/config.in b/examples/simple-main/config.in index 57cf603..bc509ea 100644 --- a/examples/simple-main/config.in +++ b/examples/simple-main/config.in | |||
@@ -1,4 +1,4 @@ | |||
1 | config SIMPLE_MAIN | 1 | config SIMPLE_MAIN |
2 | boolean "Simple Mainwindow with Actions buttons and iconsets" | 2 | boolean "Simple Mainwindow with Actions buttons and iconsets" |
3 | default "y" | 3 | default "y" |
4 | depends ( LIBQPE || LIBQPE-X11 ) && EXAMPLES | 4 | depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && EXAMPLES |
diff --git a/examples/simple-main/opie-simple.control b/examples/simple-main/opie-simple.control index 331b2f4..3cde394 100644 --- a/examples/simple-main/opie-simple.control +++ b/examples/simple-main/opie-simple.control | |||
@@ -1,9 +1,9 @@ | |||
1 | Package: opie-simple-main-example | 1 | Package: opie-simple-main-example |
2 | Files: bin/simple-main apps/Examples/simple-main.desktop | 2 | Files: bin/simple-main apps/Examples/simple-main.desktop |
3 | Priority: optional | 3 | Priority: optional |
4 | Section: opie/examples | 4 | Section: opie/examples |
5 | Maintainer: Holger 'zecke' Freyther <zecke@handhelds.org> | 5 | Maintainer: Holger 'zecke' Freyther <zecke@handhelds.org> |
6 | Architecture: arm | 6 | Architecture: arm |
7 | Depends: task-opie-minimal, opie-pics | 7 | Depends: task-opie-minimal, libopiecore2, opie-pics |
8 | Description: A simple example | 8 | Description: A simple example |
9 | Version: $QPE_VERSION$EXTRAVERSION | 9 | Version: $QPE_VERSION$EXTRAVERSION |
diff --git a/examples/simple-main/simple.cpp b/examples/simple-main/simple.cpp index cf00cc6..b227a1f 100644 --- a/examples/simple-main/simple.cpp +++ b/examples/simple-main/simple.cpp | |||
@@ -1,219 +1,219 @@ | |||
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> | ||
10 | 9 | ||
11 | #include <opie2/oapplicationfactory.h> // a template + macro to save the main method and allow quick launching | 10 | #include <opie2/oapplicationfactory.h> // a template + macro to save the main method and allow quick launching |
11 | #include <opie2/oresource.h> | ||
12 | 12 | ||
13 | #include "simple.h" | 13 | #include "simple.h" |
14 | 14 | ||
15 | /* | 15 | /* |
16 | * implementation of simple | 16 | * implementation of simple |
17 | */ | 17 | */ |
18 | 18 | ||
19 | /* | 19 | /* |
20 | * The factory is used for quicklaunching | 20 | * The factory is used for quicklaunching |
21 | * 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 | 21 | * 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 |
22 | * | 22 | * |
23 | * Depending on the global quick launch setting this will create | 23 | * Depending on the global quick launch setting this will create |
24 | * either a main method or one for our component plugin system | 24 | * either a main method or one for our component plugin system |
25 | */ | 25 | */ |
26 | 26 | ||
27 | using namespace Opie::Core; | 27 | using namespace Opie::Core; |
28 | OPIE_EXPORT_APP( OApplicationFactory<MainWindow> ) | 28 | OPIE_EXPORT_APP( OApplicationFactory<MainWindow> ) |
29 | 29 | ||
30 | MainWindow::MainWindow(QWidget *parent, const char* name, WFlags fl ) | 30 | MainWindow::MainWindow(QWidget *parent, const char* name, WFlags fl ) |
31 | : QMainWindow( parent, name, fl ) { | 31 | : QMainWindow( parent, name, fl ) { |
32 | setCaption(tr("My MainWindow") ); | 32 | setCaption(tr("My MainWindow") ); |
33 | setIcon( Resource::loadPixmap("new") ); | 33 | setIcon( Opie::Core::OResource::loadPixmap("new", Opie::Core::OResource::SmallIcon) ); |
34 | /* | 34 | /* |
35 | * out mainwindow should have a menubar | 35 | * out mainwindow should have a menubar |
36 | * a toolbar, a mainwidget and use Resource | 36 | * a toolbar, a mainwidget and use Resource |
37 | * to get the IconSets | 37 | * to get the IconSets |
38 | */ | 38 | */ |
39 | /* | 39 | /* |
40 | * we initialize the GUI in a different methid | 40 | * we initialize the GUI in a different methid |
41 | */ | 41 | */ |
42 | initUI(); | 42 | initUI(); |
43 | 43 | ||
44 | Simple *simple = new Simple( this ); | 44 | Simple *simple = new Simple( this ); |
45 | setCentralWidget( simple ); | 45 | setCentralWidget( simple ); |
46 | 46 | ||
47 | /* | 47 | /* |
48 | * If you use signal and slots do not include the parameter | 48 | * If you use signal and slots do not include the parameter |
49 | * names inside | 49 | * names inside |
50 | * so SIGNAL(fooBar(int) ) and NOT SIGNAL(fooBar(int foo) ) | 50 | * so SIGNAL(fooBar(int) ) and NOT SIGNAL(fooBar(int foo) ) |
51 | */ | 51 | */ |
52 | /* | 52 | /* |
53 | * We connect the activation of our QAction | 53 | * We connect the activation of our QAction |
54 | * to the slot connected to the firebutton | 54 | * to the slot connected to the firebutton |
55 | * We could also connect the signal to the clicked | 55 | * We could also connect the signal to the clicked |
56 | * signal of the button | 56 | * signal of the button |
57 | */ | 57 | */ |
58 | connect(m_fire, SIGNAL(activated() ), | 58 | connect(m_fire, SIGNAL(activated() ), |
59 | simple, SLOT(slotFire() ) ); | 59 | simple, SLOT(slotFire() ) ); |
60 | } | 60 | } |
61 | 61 | ||
62 | MainWindow::~MainWindow() { | 62 | MainWindow::~MainWindow() { |
63 | // again nothing to delete because Qt takes care | 63 | // again nothing to delete because Qt takes care |
64 | } | 64 | } |
65 | 65 | ||
66 | /* | 66 | /* |
67 | * set Document is a special function used by Document | 67 | * set Document is a special function used by Document |
68 | * centric applications. | 68 | * centric applications. |
69 | * In example if Opie receives a Todo via IrDa it uses | 69 | * In example if Opie receives a Todo via IrDa it uses |
70 | * setDocument via QCOP the IPC system to load the card | 70 | * setDocument via QCOP the IPC system to load the card |
71 | * Or If you decide to open a file in filemanager with textedit | 71 | * Or If you decide to open a file in filemanager with textedit |
72 | * setDocument is called via IPC in textedit. | 72 | * setDocument is called via IPC in textedit. |
73 | * Also any call to QPE/Application/xyz and xyz is currently not running | 73 | * Also any call to QPE/Application/xyz and xyz is currently not running |
74 | * leads to the start of xyz and delivering of the QCOP call | 74 | * leads to the start of xyz and delivering of the QCOP call |
75 | * But more on QCOP in the next application | 75 | * But more on QCOP in the next application |
76 | */ | 76 | */ |
77 | void MainWindow::setDocument( const QString& /*str*/ ) { | 77 | void MainWindow::setDocument( const QString& /*str*/ ) { |
78 | // in our case empty but you should see if it is a direct | 78 | // in our case empty but you should see if it is a direct |
79 | // file request or if it is a DocLnk. | 79 | // file request or if it is a DocLnk. |
80 | // A DocLnk is Link to an Document so you would end up | 80 | // A DocLnk is Link to an Document so you would end up |
81 | // opening the document behind the file you got | 81 | // opening the document behind the file you got |
82 | } | 82 | } |
83 | 83 | ||
84 | /* | 84 | /* |
85 | * Two new concepts with this Method | 85 | * Two new concepts with this Method |
86 | * 1. QAction. An action can be grouped and emits | 86 | * 1. QAction. An action can be grouped and emits |
87 | * an activated signal. Action a universal useable | 87 | * an activated signal. Action a universal useable |
88 | * you can just plug/addTo in most Qt widgets. For example | 88 | * you can just plug/addTo in most Qt widgets. For example |
89 | * the same action can be plugged into a ToolBar, MenuBar, | 89 | * the same action can be plugged into a ToolBar, MenuBar, |
90 | * QPopupMenu and other widgets but you do not need to worry | 90 | * QPopupMenu and other widgets but you do not need to worry |
91 | * about it | 91 | * about it |
92 | * | 92 | * |
93 | * 2. an IconSet contains pixmaps and provides them scaled down, scaled up | 93 | * 2. an IconSet contains pixmaps and provides them scaled down, scaled up |
94 | * enabled and disabled. SO if you use QIConSet and the toolbar | 94 | * enabled and disabled. SO if you use QIConSet and the toolbar |
95 | * size changes to use big pixmaps you will not use upscaled icons | 95 | * size changes to use big pixmaps you will not use upscaled icons |
96 | * but the right ones thanks to QIconSet and Resource | 96 | * but the right ones thanks to QIconSet and Resource |
97 | */ | 97 | */ |
98 | 98 | ||
99 | void MainWindow::initUI() { | 99 | void MainWindow::initUI() { |
100 | /* | 100 | /* |
101 | * We want to provde a File Menu with Quit as option | 101 | * We want to provde a File Menu with Quit as option |
102 | * and a Fire Toolbutton ( QAction ) | 102 | * and a Fire Toolbutton ( QAction ) |
103 | * So we need two actions | 103 | * So we need two actions |
104 | * A toolbar and a popupMenu | 104 | * A toolbar and a popupMenu |
105 | */ | 105 | */ |
106 | setToolBarsMovable( false ); | 106 | setToolBarsMovable( false ); |
107 | /* | 107 | /* |
108 | *We don't want the static toolbar but share it with the | 108 | *We don't want the static toolbar but share it with the |
109 | * toolbar on small screens | 109 | * toolbar on small screens |
110 | */ | 110 | */ |
111 | QToolBar *menuBarHolder = new QToolBar( this ); | 111 | QToolBar *menuBarHolder = new QToolBar( this ); |
112 | /* we allow the menubarholder to become bigger than | 112 | /* we allow the menubarholder to become bigger than |
113 | * the screen width and to offer a > for the additional items | 113 | * the screen width and to offer a > for the additional items |
114 | */ | 114 | */ |
115 | menuBarHolder->setHorizontalStretchable( true ); | 115 | menuBarHolder->setHorizontalStretchable( true ); |
116 | QMenuBar *mb = new QMenuBar( menuBarHolder ); | 116 | QMenuBar *mb = new QMenuBar( menuBarHolder ); |
117 | QToolBar *tb = new QToolBar( this ); | 117 | QToolBar *tb = new QToolBar( this ); |
118 | 118 | ||
119 | QPopupMenu *fileMenu = new QPopupMenu( this ); | 119 | QPopupMenu *fileMenu = new QPopupMenu( this ); |
120 | 120 | ||
121 | /* | 121 | /* |
122 | * we create our first action with the Text Quit | 122 | * we create our first action with the Text Quit |
123 | * a IconSet, no menu name, no acceleration ( keyboard shortcut ), | 123 | * a IconSet, no menu name, no acceleration ( keyboard shortcut ), |
124 | * with parent this, and name "quit_action" | 124 | * with parent this, and name "quit_action" |
125 | */ | 125 | */ |
126 | /* | 126 | /* |
127 | * Note if you want a picture out of the inline directory | 127 | * Note if you want a picture out of the inline directory |
128 | * you musn't prefix inline/ inline means these pics are built in | 128 | * you musn't prefix inline/ inline means these pics are built in |
129 | * into libqpe so the name without ending and directory is enough | 129 | * into libqpe so the name without ending and directory is enough |
130 | */ | 130 | */ |
131 | QAction *a = new QAction( tr("Quit"), Resource::loadIconSet("quit_icon"), | 131 | QAction *a = new QAction( tr("Quit"), Opie::Core::OResource::loadPixmap("quit_icon", Opie::Core::OResource::SmallIcon), |
132 | QString::null, 0, this, "quit_action" ); | 132 | QString::null, 0, this, "quit_action" ); |
133 | /* | 133 | /* |
134 | * Connect quit to the QApplication quit slot | 134 | * Connect quit to the QApplication quit slot |
135 | */ | 135 | */ |
136 | connect(a, SIGNAL(activated() ), | 136 | connect(a, SIGNAL(activated() ), |
137 | qApp, SLOT(quit() ) ); | 137 | qApp, SLOT(quit() ) ); |
138 | a->addTo( fileMenu ); | 138 | a->addTo( fileMenu ); |
139 | 139 | ||
140 | a = new QAction(tr("Fire"), | 140 | a = new QAction(tr("Fire"), |
141 | Resource::loadIconSet("new"), | 141 | Opie::Core::OResource::loadPixmap("new", Opie::Core::OResource::SmallIcon), |
142 | QString::null, 0, this, "fire_button"); | 142 | QString::null, 0, this, "fire_button"); |
143 | 143 | ||
144 | /* see the power? */ | 144 | /* see the power? */ |
145 | a->addTo( fileMenu ); | 145 | a->addTo( fileMenu ); |
146 | a->addTo( tb ); | 146 | a->addTo( tb ); |
147 | m_fire = a; | 147 | m_fire = a; |
148 | 148 | ||
149 | 149 | ||
150 | mb->insertItem(tr("File"), fileMenu ); | 150 | mb->insertItem(tr("File"), fileMenu ); |
151 | 151 | ||
152 | } | 152 | } |
153 | 153 | ||
154 | Simple::Simple( QWidget* parent, const char* name, WFlags fl ) | 154 | Simple::Simple( QWidget* parent, const char* name, WFlags fl ) |
155 | : QWidget( parent, name, fl ) { | 155 | : QWidget( parent, name, fl ) { |
156 | 156 | ||
157 | /* | 157 | /* |
158 | * sets the caption of this toplevel widget | 158 | * sets the caption of this toplevel widget |
159 | * put all translatable string into tr() | 159 | * put all translatable string into tr() |
160 | */ | 160 | */ |
161 | setCaption(tr("My Simple Application") ); | 161 | setCaption(tr("My Simple Application") ); |
162 | 162 | ||
163 | /* | 163 | /* |
164 | * A simple vertical layout | 164 | * A simple vertical layout |
165 | * either call layout->setAutoAdd( true ) | 165 | * either call layout->setAutoAdd( true ) |
166 | * or use layout->addWidget( wid ) to add widgets | 166 | * or use layout->addWidget( wid ) to add widgets |
167 | */ | 167 | */ |
168 | QVBoxLayout *layout = new QVBoxLayout( this ); | 168 | QVBoxLayout *layout = new QVBoxLayout( this ); |
169 | layout->setSpacing( 8 ); | 169 | layout->setSpacing( 8 ); |
170 | layout->setMargin( 11 ); | 170 | layout->setMargin( 11 ); |
171 | 171 | ||
172 | /* | 172 | /* |
173 | * creates a label | 173 | * creates a label |
174 | * The first parameter is this widget so the Label is a child | 174 | * The first parameter is this widget so the Label is a child |
175 | * of us and will be deleted when we're deleted. | 175 | * of us and will be deleted when we're deleted. |
176 | */ | 176 | */ |
177 | QLabel *lbl = new QLabel( this, "a name for the label" ); | 177 | QLabel *lbl = new QLabel( this, "a name for the label" ); |
178 | lbl->setText( tr("Click on the button or follow the white rabbit") ); | 178 | lbl->setText( tr("Click on the button or follow the white rabbit") ); |
179 | layout->addWidget( lbl ); | 179 | layout->addWidget( lbl ); |
180 | 180 | ||
181 | 181 | ||
182 | /* creates a button as child of this widget */ | 182 | /* creates a button as child of this widget */ |
183 | m_button = new QPushButton(this); | 183 | m_button = new QPushButton(this); |
184 | /* | 184 | /* |
185 | * another way to call tr. The first parameter is the string | 185 | * another way to call tr. The first parameter is the string |
186 | * to translate and the second a hint to the translator | 186 | * to translate and the second a hint to the translator |
187 | */ | 187 | */ |
188 | m_button->setText( tr("Fire", "translatable quit string" ) ); | 188 | m_button->setText( tr("Fire", "translatable quit string" ) ); |
189 | layout->addWidget( m_button ); | 189 | layout->addWidget( m_button ); |
190 | 190 | ||
191 | /* | 191 | /* |
192 | * Now we bring the action into it. The power of qt is the dynamic | 192 | * Now we bring the action into it. The power of qt is the dynamic |
193 | * signal and slots model | 193 | * signal and slots model |
194 | * Usage is simple connect m_buttons clicked signal to our | 194 | * Usage is simple connect m_buttons clicked signal to our |
195 | * slotQuit slot. | 195 | * slotQuit slot. |
196 | * We could also have connected a SIGNAL to a SIGNAL or the clicked | 196 | * We could also have connected a SIGNAL to a SIGNAL or the clicked |
197 | * signal directly to qApp and SLOT(quit() ) | 197 | * signal directly to qApp and SLOT(quit() ) |
198 | */ | 198 | */ |
199 | connect( m_button, SIGNAL(clicked() ), | 199 | connect( m_button, SIGNAL(clicked() ), |
200 | this, SLOT( slotFire() ) ); | 200 | this, SLOT( slotFire() ) ); |
201 | } | 201 | } |
202 | 202 | ||
203 | /* | 203 | /* |
204 | * Our destructor is empty because all child | 204 | * Our destructor is empty because all child |
205 | * widgets and layouts will be deleted by Qt. | 205 | * widgets and layouts will be deleted by Qt. |
206 | * Same applies to QObjects | 206 | * Same applies to QObjects |
207 | */ | 207 | */ |
208 | Simple::~Simple() { | 208 | Simple::~Simple() { |
209 | 209 | ||
210 | } | 210 | } |
211 | 211 | ||
212 | void Simple::slotFire() { | 212 | void Simple::slotFire() { |
213 | /* | 213 | /* |
214 | * NOTE: Simple is now a child window of MainWindow | 214 | * NOTE: Simple is now a child window of MainWindow |
215 | * close will hide() Simple and not delete it. But as | 215 | * close will hide() Simple and not delete it. But as |
216 | * the mainwindow is shown all children will be shown as well | 216 | * the mainwindow is shown all children will be shown as well |
217 | */ | 217 | */ |
218 | close(); | 218 | close(); |
219 | } | 219 | } |