summaryrefslogtreecommitdiff
path: root/libopie
authorzecke <zecke>2003-09-01 09:42:06 (UTC)
committer zecke <zecke>2003-09-01 09:42:06 (UTC)
commit45a479040238764f97eed267c74aed6cf27eece8 (patch) (unidiff)
treed589b1a89a2f6f9862822c03235630e987f9bcb6 /libopie
parent143807c9d438ee6f07e92e6009ec5633088c34f4 (diff)
downloadopie-45a479040238764f97eed267c74aed6cf27eece8.zip
opie-45a479040238764f97eed267c74aed6cf27eece8.tar.gz
opie-45a479040238764f97eed267c74aed6cf27eece8.tar.bz2
OSplitter the first BigScreen Extension widget is done
with a small example
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/big-screen/example/osplitter_example.cpp28
-rw-r--r--libopie/big-screen/example/osplitter_example.h20
-rw-r--r--libopie/big-screen/example/osplitter_example.obin0 -> 17276 bytes
-rw-r--r--libopie/big-screen/example/osplitter_example.pro13
-rw-r--r--libopie/big-screen/obigscreen_p.h20
-rw-r--r--libopie/big-screen/osplitter.cpp165
-rw-r--r--libopie/big-screen/osplitter.h22
7 files changed, 228 insertions, 40 deletions
diff --git a/libopie/big-screen/example/osplitter_example.cpp b/libopie/big-screen/example/osplitter_example.cpp
new file mode 100644
index 0000000..e337379
--- a/dev/null
+++ b/libopie/big-screen/example/osplitter_example.cpp
@@ -0,0 +1,28 @@
1#include <qdir.h>
2#include <qlayout.h>
3
4#include "../osplitter.h"
5
6#include <qpe/qpeapplication.h>
7#include <opie/oapplicationfactory.h>
8
9#include "osplitter_example.h"
10
11OPIE_EXPORT_APP( OApplicationFactory<OSplitterExample> )
12
13OSplitterExample::OSplitterExample( QWidget *w,const char* n,WFlags f )
14 : QWidget( w, n, f ){
15 QVBoxLayout * lay = new QVBoxLayout(this);
16 OSplitter * splitter = new OSplitter( Horizontal, this );
17 lay->addWidget( splitter );
18
19 OFileSelector *selector = new OFileSelector( splitter, OFileSelector::FileSelector,
20 OFileSelector::Normal, QDir::homeDirPath(),
21 QString::null );
22 splitter->addWidget( selector, "zoom", tr("Selector 1") );
23
24 selector = new OFileSelector( splitter, OFileSelector::FileSelector, OFileSelector::Normal,
25 QDir::homeDirPath(), QString::null );
26 splitter->addWidget( selector, "zoom", tr("Selector 2") );
27
28}
diff --git a/libopie/big-screen/example/osplitter_example.h b/libopie/big-screen/example/osplitter_example.h
new file mode 100644
index 0000000..ae8f120
--- a/dev/null
+++ b/libopie/big-screen/example/osplitter_example.h
@@ -0,0 +1,20 @@
1/*
2 * May be used, copied and modified wihtout any limitation
3 */
4
5#ifndef OSPlitter_EXAMPLE_H
6#define OSPlitter_EXAMPLE_H
7
8#include <qvbox.h>
9#include <opie/ofileselector.h>
10
11class OSplitterExample : public QWidget {
12 Q_OBJECT
13public:
14 static QString appName() { return QString::fromLatin1("osplitter_example"); }
15 OSplitterExample( QWidget *parent, const char* name, WFlags fl );
16
17};
18
19
20#endif
diff --git a/libopie/big-screen/example/osplitter_example.o b/libopie/big-screen/example/osplitter_example.o
new file mode 100644
index 0000000..e52d5d9
--- a/dev/null
+++ b/libopie/big-screen/example/osplitter_example.o
Binary files differ
diff --git a/libopie/big-screen/example/osplitter_example.pro b/libopie/big-screen/example/osplitter_example.pro
new file mode 100644
index 0000000..b12bf17
--- a/dev/null
+++ b/libopie/big-screen/example/osplitter_example.pro
@@ -0,0 +1,13 @@
1CONFIG = qt warn_on
2TEMPLATE = app
3TARGET = osplitter_example
4
5HEADERS = osplitter_example.h ../osplitter.h
6SOURCES = osplitter_example.cpp ../osplitter.cpp
7
8INCLUDEPATH += $(OPIEDIR)/include ../
9DEPENDSPATH += $(OPIEDIR)/include
10
11LIBS += -lqpe -lopie
12
13include ( $(OPIEDIR)/include.pro ) \ No newline at end of file
diff --git a/libopie/big-screen/obigscreen_p.h b/libopie/big-screen/obigscreen_p.h
new file mode 100644
index 0000000..ed256d9
--- a/dev/null
+++ b/libopie/big-screen/obigscreen_p.h
@@ -0,0 +1,20 @@
1#ifndef OPIE_BIG_SCREEN_PRIVATE
2#define OPIE_BIG_SCREEN_PRIVATE
3
4namespace Opie {
5
6struct OSplitterContainer {
7 bool operator==( const OSplitterContainer& o)const {
8 if (widget != o.widget ) return false;
9 if (icon != o.icon ) return false;
10 if (name != o.name ) return false;
11 return true;
12 }
13 QWidget* widget;
14 QString icon;
15 QString name;
16};
17
18}
19
20#endif
diff --git a/libopie/big-screen/osplitter.cpp b/libopie/big-screen/osplitter.cpp
index dcb5cc5..ce53ee1 100644
--- a/libopie/big-screen/osplitter.cpp
+++ b/libopie/big-screen/osplitter.cpp
@@ -34,13 +34,6 @@
34#include "osplitter.h" 34#include "osplitter.h"
35 35
36 36
37struct OSplitterContainer {
38 QWidget* widget;
39 const QString& icon
40 const QString& name;
41};
42
43
44/** 37/**
45 * 38 *
46 * This is the constructor of OSplitter 39 * This is the constructor of OSplitter
@@ -58,12 +51,15 @@ struct OSplitterContainer {
58 * @short single c'tor of the OSplitter 51 * @short single c'tor of the OSplitter
59 */ 52 */
60OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFlags fl ) 53OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFlags fl )
61 : QWidget( parent, name, fl ) 54 : QFrame( parent, name, fl )
62{ 55{
63 m_orient = orient; 56 m_orient = orient;
64 m_hbox = 0; 57 m_hbox = 0;
65 m_tabWidget = 0;
66 m_size_policy = 330; 58 m_size_policy = 330;
59 setFontPropagation( AllChildren );
60 setPalettePropagation( AllChildren );
61
62 m_tabWidget = new OTabWidget(this);
67} 63}
68 64
69 65
@@ -89,7 +85,9 @@ OSplitter::~OSplitter() {
89 */ 85 */
90void OSplitter::setSizeChange( int width_height ) { 86void OSplitter::setSizeChange( int width_height ) {
91 m_size_policy = width_height; 87 m_size_policy = width_height;
92 relayout(); 88 QSize sz(width(), height() );
89 QResizeEvent ev(sz, sz );
90 resizeEvent(&ev);
93} 91}
94 92
95/** 93/**
@@ -112,10 +110,10 @@ void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& lab
112 return; 110 return;
113 } 111 }
114#endif 112#endif
115 OSplitterContainer cont; 113 Opie::OSplitterContainer cont;
116 cont.widget = wid; 114 cont.widget = wid;
117 cont.icon =icon; 115 cont.icon =icon;
118 cont.label = label; 116 cont.name = label;
119 117
120 m_container.append( cont ); 118 m_container.append( cont );
121 119
@@ -127,31 +125,32 @@ void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& lab
127 125
128 126
129/** 127/**
130 * Removes the widget from the tab widgets. OSplitter drops ownership 128 * Removes the widget from the tab widgets if necessary.
131 * of this widget and the widget will be reparented to 0. 129 * OSplitter drops ownership of this widget and the widget
130 * will be reparented i tto 0.
132 * The widget will not be deleted. 131 * The widget will not be deleted.
133 * 132 *
134 * @param w The widget to be removed 133 * @param w The widget to be removed
135 */ 134 */
136void OSplitter::removeWidget( QWidget* w) { 135void OSplitter::removeWidget( QWidget* w) {
137 /* if not widget nor parent or parent not any of my master childs return */ 136 ContainerList::Iterator it;
138 if (!w && w->parent() && ( w->parent() != m_hbox || w->parent() != m_tabWidget ) ) 137 for ( it = m_container.begin(); it != m_container.end(); ++it )
138 if ( (*it).widget == w )
139 break;
140
141 if (it == m_container.end() )
139 return; 142 return;
140 143
144
141 /* only tab needs to be removed.. box recognizes it */ 145 /* only tab needs to be removed.. box recognizes it */
142 if ( !m_hbox ) 146 if ( !m_hbox )
143 removeFromTab( w ); 147 removeFromTab( w );
144 148
145 149
146 /* Find the widget, reparent it and remove it from our list */ 150 /* Find reparent it and remove it from our list */
147 ContainerList::Iterator it;
148 for ( it = m_container.begin(); it != m_container.end(); ++it )
149 if ( (*it).widget == w ) {
150 w.reparent( 0, w.getWFlags );
151 it = m_container.remove( it );
152 break;
153 }
154 151
152 w->reparent( 0, 0, QPoint(0, 0));
153 it = m_container.remove( it );
155 154
156} 155}
157 156
@@ -164,14 +163,15 @@ void OSplitter::removeWidget( QWidget* w) {
164 */ 163 */
165void OSplitter::setCurrentWidget( QWidget* w) { 164void OSplitter::setCurrentWidget( QWidget* w) {
166 if (m_tabWidget ) 165 if (m_tabWidget )
167 m_tabWidget->setCurrentWidget( w ); 166 m_tabWidget->setCurrentTab( w );
168 else 167// else
169 m_hbox->setFocus( w ); 168 // m_hbox->setFocus( w );
170 169
171} 170}
172 171
173/** 172/**
174 * This is an overloaded member function and only differs in the argument it takes. 173 * This is an overloaded member function and only differs in the
174 * argument it takes.
175 * Searches list of widgets for label. It'll pick the first label it finds 175 * Searches list of widgets for label. It'll pick the first label it finds
176 * 176 *
177 * @param label Label to look for. First match will be taken 177 * @param label Label to look for. First match will be taken
@@ -187,7 +187,7 @@ void OSplitter::setCurrentWidget( const QString& label ) {
187} 187}
188 188
189/** 189/**
190 * return the currently activated widget if in tab widget moud 190 * return the currently activated widget if in tab widget mode
191 * or null because all widgets are visible 191 * or null because all widgets are visible
192 */ 192 */
193QWidget* OSplitter::currentWidget() { 193QWidget* OSplitter::currentWidget() {
@@ -197,17 +197,122 @@ QWidget* OSplitter::currentWidget() {
197 return m_tabWidget->currentWidget(); 197 return m_tabWidget->currentWidget();
198} 198}
199 199
200 200#if 0
201/** 201/**
202 * @reimplented for internal reasons 202 * @reimplented for internal reasons
203 * returns the sizeHint of one of its sub widgets 203 * returns the sizeHint of one of its sub widgets
204 */ 204 */
205QSize OSplitter::sizeHint()const { 205QSize OSplitter::sizeHint()const {
206 if (m_hbox )
207 return m_hbox->sizeHint();
208 else
209 return m_tabWidget->sizeHint();
206} 210}
211#endif
207 212
208/** 213/**
209 * @reimplemented for internal reasons 214 * @reimplemented for internal reasons
210 */ 215 */
211void OSplitter::resizeEvent( QResizeEvent* res ) { 216void OSplitter::resizeEvent( QResizeEvent* res ) {
217 QFrame::resizeEvent( res );
218 /*
219 *
220 */
221// qWarning("Old size was width = %d height = %d", res->oldSize().width(), res->oldSize().height() );
222// qWarning("New size is width = %d height = %d", res->size().width(), res->size().height() );
223 if ( res->size().width() > m_size_policy &&
224 m_orient == Horizontal ) {
225 changeHBox();
226 }else if ( (res->size().width() <= m_size_policy &&
227 m_orient == Horizontal ) ||
228 (res->size().height() <= m_size_policy &&
229 m_orient == Vertical ) ) {
230 changeTab();
231 }else if ( res->size().height() > m_size_policy &&
232 m_size_policy == Vertical ) {
233 changeVBox();
234 }
235}
236
237
238void OSplitter::addToTab( const Opie::OSplitterContainer& con ) {
239 QWidget *wid = con.widget;
240// not needed widgetstack will reparent as well wid.reparent(m_tabWidget, wid->getWFlags(), QPoint(0, 0) );
241 m_tabWidget->addTab( wid, con.icon, con.name );
242}
243
244void OSplitter::addToBox( const Opie::OSplitterContainer& con ) {
245 QWidget* wid = con.widget;
246 wid->reparent(m_hbox, 0, QPoint(0, 0) );
247}
212 248
249void OSplitter::removeFromTab( QWidget* wid ) {
250 m_tabWidget->removePage( wid );
251}
252
253void OSplitter::changeTab() {
254 if (m_tabWidget ) {
255 m_tabWidget->setGeometry( frameRect() );
256 return;
257 }
258
259 qWarning(" New Tab Widget ");
260 /*
261 * and add all widgets this will reparent them
262 * delete m_hbox set it to 0
263 *
264 */
265 m_tabWidget = new OTabWidget( this );
266
267 for ( ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it ) {
268 qWarning("Widget is %s", (*it).name.latin1() );
269 addToTab( (*it) );
270 }
271
272 delete m_hbox;
273 m_hbox = 0;
274 m_tabWidget->setGeometry( frameRect() );
275 m_tabWidget->show();
276
277}
278
279void OSplitter::changeHBox() {
280 if (m_hbox ) {
281 m_hbox->setGeometry( frameRect() );
282 return;
283 }
284
285 qWarning("new HBox");
286 m_hbox = new QHBox( this );
287 commonChangeBox();
288 delete m_tabWidget;
289 m_tabWidget = 0;
290 m_hbox->setGeometry( frameRect() );
291 m_hbox->show();
292}
293
294void OSplitter::changeVBox() {
295 if (m_hbox ) {
296 m_hbox->setGeometry( frameRect() );
297 return;
298 }
299
300 qWarning("New VBOX");
301 m_hbox = new QVBox( this );
302
303 commonChangeBox();
304 delete m_tabWidget;
305 m_tabWidget = 0;
306 m_hbox->setGeometry( frameRect() );
307 m_hbox->show();
308}
309
310
311void OSplitter::commonChangeBox() {
312 for (ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it ) {
313 qWarning("Adding to box %s", (*it).name.latin1() );
314 addToBox( (*it) );
315 }
316 delete m_tabWidget;
317 m_tabWidget = 0;
213} 318}
diff --git a/libopie/big-screen/osplitter.h b/libopie/big-screen/osplitter.h
index 05849af..bc4f80b 100644
--- a/libopie/big-screen/osplitter.h
+++ b/libopie/big-screen/osplitter.h
@@ -31,15 +31,15 @@
31 31
32#include <qstring.h> 32#include <qstring.h>
33 33
34#include <qwidget.h> 34#include <qframe.h>
35#include <qvaluelist.h> 35#include <qvaluelist.h>
36 36
37#include "obigscreen_p.h"
37 38
38/* forward declarations */ 39/* forward declarations */
39class OTabWidget; 40class OTabWidget;
40class QHBox; 41class QHBox;
41struct OSplitterContainer; 42//template class QValueList<Opie::OSplitterContainer>;
42template class QValueList<OSplitterContainer>;
43 43
44 44
45/** 45/**
@@ -59,10 +59,10 @@ template class QValueList<OSplitterContainer>;
59 * @version 0.1 59 * @version 0.1
60 * @author zecke 60 * @author zecke
61 */ 61 */
62class OSplitter : public QWidget{ 62class OSplitter : public QFrame{
63 Q_OBJECT 63 Q_OBJECT
64public: 64public:
65 typedef QValueList<OSplitterContainer> ContainerList; 65 typedef QValueList<Opie::OSplitterContainer> ContainerList;
66 OSplitter( Qt::Orientation = Horizontal, QWidget *parent = 0, 66 OSplitter( Qt::Orientation = Horizontal, QWidget *parent = 0,
67 const char* name = 0, WFlags fl = 0 ); 67 const char* name = 0, WFlags fl = 0 );
68 ~OSplitter(); 68 ~OSplitter();
@@ -76,17 +76,19 @@ public:
76 void setCurrentWidget( const QString& label ); 76 void setCurrentWidget( const QString& label );
77 QWidget* currentWidget(); 77 QWidget* currentWidget();
78 78
79 QSize sizeHint()const; 79// QSize sizeHint()const;
80 80
81protected: 81protected:
82 void resizeEvent( QResizeEvent* ); 82 void resizeEvent( QResizeEvent* );
83 83
84private: 84private:
85 void relayout(); 85 void addToTab( const Opie::OSplitterContainer& );
86 void addToTab( const OSplitterContainer& ); 86 void addToBox( const Opie::OSplitterContainer& );
87 void addToBox( const OSplitterContainer& );
88 void removeFromTab( QWidget* ); 87 void removeFromTab( QWidget* );
89 void removeFromBox( QWidget* ); 88 void changeTab();
89 void changeHBox();
90 void changeVBox();
91 void commonChangeBox();
90 QHBox *m_hbox; 92 QHBox *m_hbox;
91 OTabWidget *m_tabWidget; 93 OTabWidget *m_tabWidget;
92 Orientation m_orient; 94 Orientation m_orient;