summaryrefslogtreecommitdiff
authorzecke <zecke>2003-09-02 18:15:07 (UTC)
committer zecke <zecke>2003-09-02 18:15:07 (UTC)
commit3cf3fc001922a7ef34c7ff95751beb569809383b (patch) (unidiff)
tree4fb5fba6b8684b7a9a6cf88e3eb3e02068e73a52
parente87caebc920ad256d210eeb31aeb134318f0c104 (diff)
downloadopie-3cf3fc001922a7ef34c7ff95751beb569809383b.zip
opie-3cf3fc001922a7ef34c7ff95751beb569809383b.tar.gz
opie-3cf3fc001922a7ef34c7ff95751beb569809383b.tar.bz2
Allow adding child Osplitters and sharing
the same OTabBar ( untested ) but the normal mode still works
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/big-screen/osplitter.cpp263
-rw-r--r--libopie/big-screen/osplitter.h28
2 files changed, 266 insertions, 25 deletions
diff --git a/libopie/big-screen/osplitter.cpp b/libopie/big-screen/osplitter.cpp
index 1cd0fd5..d06568f 100644
--- a/libopie/big-screen/osplitter.cpp
+++ b/libopie/big-screen/osplitter.cpp
@@ -39,12 +39,15 @@
39 * This is the constructor of OSplitter 39 * This is the constructor of OSplitter
40 * You might want to call setSizeChange to tell 40 * You might want to call setSizeChange to tell
41 * OSplitter to change its layout when a specefic 41 * OSplitter to change its layout when a specefic
42 * mark was crossed. OSplitter sets a default value. 42 * mark was crossed. OSplitter sets a default value.
43 * 43 *
44 * You cann add widget with addWidget to the OSplitter. 44 * You cann add widget with addWidget to the OSplitter.
45 * OSplitter supports also grouping of Splitters where they
46 * can share one OTabBar in small screen mode. This can be used
47 * for email clients like vies but see the example.
45 * 48 *
46 * @param orient The orientation wether to layout horizontal or vertical 49 * @param orient The orientation wether to layout horizontal or vertical
47 * @param parent The parent of this widget 50 * @param parent The parent of this widget
48 * @param name The name passed on to QObject 51 * @param name The name passed on to QObject
49 * @param fl Additional widgets flags passed to QWidget 52 * @param fl Additional widgets flags passed to QWidget
50 * 53 *
@@ -58,29 +61,71 @@ OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFl
58 m_size_policy = 330; 61 m_size_policy = 330;
59 setFontPropagation( AllChildren ); 62 setFontPropagation( AllChildren );
60 setPalettePropagation( AllChildren ); 63 setPalettePropagation( AllChildren );
61 64
62 /* start by default with the tab widget */ 65 /* start by default with the tab widget */
63 m_tabWidget = 0; 66 m_tabWidget = 0;
67 m_parentTab = 0;
64 changeTab(); 68 changeTab();
65 69
66} 70}
67 71
68 72
69/** 73/**
70 * Destructor destructs this object and cleans up. All child 74 * Destructor destructs this object and cleans up. All child
71 * widgets will be deleted 75 * widgets will be deleted
72 * @see addWidget 76 * @see addWidget
73 */ 77 */
74OSplitter::~OSplitter() { 78OSplitter::~OSplitter() {
79 m_splitter.setAutoDelete( true );
80 m_splitter.clear();
81
75 delete m_hbox; 82 delete m_hbox;
76 delete m_tabWidget; 83 delete m_tabWidget;
77} 84}
78 85
79 86
80/** 87/**
88 * Sets the label for the Splitter. This label will be used
89 * if a parent splitter is arranged as TabWidget but
90 * this splitter is in fullscreen mode. Then a tab with OSplitter::label()
91 * and iconName() gets added.
92 *
93 * @param name The name of the Label
94 */
95void OSplitter::setLabel( const QString& name ) {
96 m_name = name;
97}
98
99/**
100 * @see setLabel but this is for the icon retrieved by Resource
101 *
102 * @param name The name of the icon in example ( "zoom" )
103 */
104void OSplitter::setIconName( const QString& name ) {
105 m_icon = name;
106}
107
108
109/**
110 * returns the iconName
111 * @see setIconName
112 */
113QString OSplitter::iconName()const {
114 return m_icon;
115}
116
117/**
118 * returns the label set with setLabel
119 * @see setLabel
120 */
121QString OSplitter::label()const {
122 return m_name;
123}
124
125/**
81 * This function sets the size change policy of the splitter. 126 * This function sets the size change policy of the splitter.
82 * If this size marked is crossed the splitter will relayout. 127 * If this size marked is crossed the splitter will relayout.
83 * Note: that depending on the set Orientation it'll either look 128 * Note: that depending on the set Orientation it'll either look
84 * at the width or height. 129 * at the width or height.
85 * Note: If you want to from side to side view to tabbed view you need 130 * Note: If you want to from side to side view to tabbed view you need
86 * to make sure that the size you supply is not smaller than the minimum 131 * to make sure that the size you supply is not smaller than the minimum
@@ -95,12 +140,48 @@ void OSplitter::setSizeChange( int width_height ) {
95 QSize sz(width(), height() ); 140 QSize sz(width(), height() );
96 QResizeEvent ev(sz, sz ); 141 QResizeEvent ev(sz, sz );
97 resizeEvent(&ev); 142 resizeEvent(&ev);
98} 143}
99 144
100/** 145/**
146 * This functions allows to add another OSplitter and to share
147 * the OTabBar in small screen mode. The ownerships gets transfered.
148 * OSplitters are always added after normal widget items
149 */
150void OSplitter::addWidget( OSplitter* split ) {
151 m_splitter.append( split );
152
153 /*
154 * set tab widget
155 */
156 if (m_tabWidget )
157 split->setTabWidget( m_tabWidget );
158 else{
159 Opie::OSplitterContainer con;
160 con.widget =split;
161 addToBox( con );
162 }
163}
164
165/*
166 * If in a tab it should be removed
167 * and if in a hbox the reparent kills it too
168 */
169/**
170 * This removes the splitter again. You currently need to call this
171 * before you delete or otherwise you can get mem corruption
172 * or other weird behaviour.
173 * Owner ship gets transfered back to you it's current parent
174 * is 0
175 */
176void OSplitter::removeWidget( OSplitter* split) {
177 split->setTabWidget( 0 );
178 split->reparent( 0, 0, QPoint(0, 0) );
179}
180
181/**
101 * Adds a widget to the Splitter. The widgets gets inserted 182 * Adds a widget to the Splitter. The widgets gets inserted
102 * at the end of either the Box or TabWidget. 183 * at the end of either the Box or TabWidget.
103 * Ownership gets transfered and the widgets gets reparented. 184 * Ownership gets transfered and the widgets gets reparented.
104 * Note: icon and label is only available on small screensizes 185 * Note: icon and label is only available on small screensizes
105 * if size is smaller than the mark 186 * if size is smaller than the mark
106 * Warning: No null checking of the widget is done. Only on debug 187 * Warning: No null checking of the widget is done. Only on debug
@@ -121,16 +202,23 @@ void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& lab
121 cont.widget = wid; 202 cont.widget = wid;
122 cont.icon =icon; 203 cont.icon =icon;
123 cont.name = label; 204 cont.name = label;
124 205
125 m_container.append( cont ); 206 m_container.append( cont );
126 207
127 if (m_hbox ) 208 /*
128 addToBox( cont ); 209 *
129 else 210 */
130 addToTab( cont ); 211 if (!m_splitter.isEmpty() && (m_tabWidget || m_parentTab ) )
212 setTabWidget( m_parentTab );
213 else {
214 if (m_hbox )
215 addToBox( cont );
216 else
217 addToTab( cont );
218 }
131} 219}
132 220
133 221
134/** 222/**
135 * Removes the widget from the tab widgets if necessary. 223 * Removes the widget from the tab widgets if necessary.
136 * OSplitter drops ownership of this widget and the widget 224 * OSplitter drops ownership of this widget and the widget
@@ -206,17 +294,19 @@ void OSplitter::setCurrentWidget( int tab ) {
206} 294}
207 295
208/** 296/**
209 * return the currently activated widget if in tab widget mode 297 * return the currently activated widget if in tab widget mode
210 * or null because all widgets are visible 298 * or null because all widgets are visible
211 */ 299 */
212QWidget* OSplitter::currentWidget() { 300QWidget* OSplitter::currentWidget() const{
213 if ( m_hbox ) 301 if (m_tabWidget)
214 return 0l;
215 else
216 return m_tabWidget->currentWidget(); 302 return m_tabWidget->currentWidget();
303 else if (m_parentTab )
304 return m_parentTab->currentWidget();
305
306 return 0l;
217} 307}
218 308
219#if 0 309#if 0
220/** 310/**
221 * @reimplented for internal reasons 311 * @reimplented for internal reasons
222 * returns the sizeHint of one of its sub widgets 312 * returns the sizeHint of one of its sub widgets
@@ -241,105 +331,230 @@ QSize OSplitter::minimumSizeHint()const {
241void OSplitter::resizeEvent( QResizeEvent* res ) { 331void OSplitter::resizeEvent( QResizeEvent* res ) {
242 QFrame::resizeEvent( res ); 332 QFrame::resizeEvent( res );
243 /* 333 /*
244 * 334 *
245 */ 335 */
246// qWarning("Old size was width = %d height = %d", res->oldSize().width(), res->oldSize().height() ); 336// qWarning("Old size was width = %d height = %d", res->oldSize().width(), res->oldSize().height() );
337 bool mode = true;
247 qWarning("New size is width = %d height = %d", res->size().width(), res->size().height() ); 338 qWarning("New size is width = %d height = %d", res->size().width(), res->size().height() );
248 if ( res->size().width() > m_size_policy && 339 if ( res->size().width() > m_size_policy &&
249 m_orient == Horizontal ) { 340 m_orient == Horizontal ) {
250 changeHBox(); 341 changeHBox();
342 mode = false;
251 }else if ( (res->size().width() <= m_size_policy && 343 }else if ( (res->size().width() <= m_size_policy &&
252 m_orient == Horizontal ) || 344 m_orient == Horizontal ) ||
253 (res->size().height() <= m_size_policy && 345 (res->size().height() <= m_size_policy &&
254 m_orient == Vertical ) ) { 346 m_orient == Vertical ) ) {
255 changeTab(); 347 changeTab();
256 }else if ( res->size().height() > m_size_policy && 348 }else if ( res->size().height() > m_size_policy &&
257 m_size_policy == Vertical ) { 349 m_size_policy == Vertical ) {
258 changeVBox(); 350 changeVBox();
351 mode = false;
259 } 352 }
260}
261 353
354 emit sizeChanged(mode, m_orient );
355}
262 356
357/*
358 * Adds a container to a tab either the parent tab
359 * or our own
360 */
263void OSplitter::addToTab( const Opie::OSplitterContainer& con ) { 361void OSplitter::addToTab( const Opie::OSplitterContainer& con ) {
264 QWidget *wid = con.widget; 362 QWidget *wid = con.widget;
265// not needed widgetstack will reparent as well wid.reparent(m_tabWidget, wid->getWFlags(), QPoint(0, 0) ); 363// not needed widgetstack will reparent as well wid.reparent(m_tabWidget, wid->getWFlags(), QPoint(0, 0) );
266 m_tabWidget->addTab( wid, con.icon, con.name ); 364 if (m_parentTab )
365 m_parentTab->addTab( wid, con.icon, con.name );
366 else
367 m_tabWidget->addTab( wid, con.icon, con.name );
267} 368}
268 369
370
371/*
372 * adds a container to the box
373 */
269void OSplitter::addToBox( const Opie::OSplitterContainer& con ) { 374void OSplitter::addToBox( const Opie::OSplitterContainer& con ) {
270 QWidget* wid = con.widget; 375 QWidget* wid = con.widget;
271 wid->reparent(m_hbox, 0, QPoint(0, 0) ); 376 wid->reparent(m_hbox, 0, QPoint(0, 0) );
272} 377}
273 378
379
380/*
381 * Removes a widget from the tab
382 */
274void OSplitter::removeFromTab( QWidget* wid ) { 383void OSplitter::removeFromTab( QWidget* wid ) {
275 m_tabWidget->removePage( wid ); 384 if (m_parentTab )
385 m_parentTab->removePage( wid );
386 else
387 m_tabWidget->removePage( wid );
276} 388}
277 389
390/*
391 * switches over to a OTabWidget layout
392 * it is recursive
393 */
278void OSplitter::changeTab() { 394void OSplitter::changeTab() {
395 /* if we're the owner of the tab widget */
279 if (m_tabWidget ) { 396 if (m_tabWidget ) {
280 m_tabWidget->setGeometry( frameRect() ); 397 m_tabWidget->setGeometry( frameRect() );
281 return; 398 return;
282 } 399 }
283 400
284 qWarning(" New Tab Widget "); 401 qWarning(" New Tab Widget ");
285 /* 402 /*
286 * and add all widgets this will reparent them 403 * and add all widgets this will reparent them
287 * delete m_hbox set it to 0 404 * delete m_hbox set it to 0
288 * 405 *
289 */ 406 */
290 m_tabWidget = new OTabWidget( this ); 407 OTabWidget *tab;
291 connect(m_tabWidget, SIGNAL(currentChanged(QWidget*) ), 408 if ( m_parentTab ) {
409 tab = m_parentTab;
410 tab->removePage( this );
411 }else
412 tab = m_tabWidget = new OTabWidget( this );
413
414 connect(tab, SIGNAL(currentChanged(QWidget*) ),
292 this, SIGNAL(currentChanged(QWidget*) ) ); 415 this, SIGNAL(currentChanged(QWidget*) ) );
293 416
294 for ( ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it ) { 417 for ( ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it ) {
295 qWarning("Widget is %s", (*it).name.latin1() ); 418 qWarning("Widget is %s", (*it).name.latin1() );
296 addToTab( (*it) ); 419 addToTab( (*it) );
297 } 420 }
298 421
422 for ( OSplitter* split = m_splitter.first(); split; split = m_splitter.next() )
423 split->setTabWidget( tab );
424
425
299 delete m_hbox; 426 delete m_hbox;
300 m_hbox = 0; 427 m_hbox = 0;
428 if (!m_tabWidget )
429 return;
430
301 m_tabWidget->setGeometry( frameRect() ); 431 m_tabWidget->setGeometry( frameRect() );
302 m_tabWidget->show(); 432 m_tabWidget->show();
303 433
304} 434}
305 435
436/*
437 * changes over to a box
438 * this is recursive as well
439 */
306void OSplitter::changeHBox() { 440void OSplitter::changeHBox() {
307 if (m_hbox ) { 441 if (m_hbox ) {
308 m_hbox->setGeometry( frameRect() ); 442 m_hbox->setGeometry( frameRect() );
309 return; 443 return;
310 } 444 }
311 445
312 qWarning("new HBox"); 446 qWarning("new HBox");
313 m_hbox = new QHBox( this ); 447 m_hbox = new QHBox( this );
314 commonChangeBox(); 448 commonChangeBox();
315 delete m_tabWidget;
316 m_tabWidget = 0;
317 m_hbox->setGeometry( frameRect() );
318 m_hbox->show();
319} 449}
320 450
321void OSplitter::changeVBox() { 451void OSplitter::changeVBox() {
322 if (m_hbox ) { 452 if (m_hbox ) {
323 m_hbox->setGeometry( frameRect() ); 453 m_hbox->setGeometry( frameRect() );
324 return; 454 return;
325 } 455 }
326 456
327 qWarning("New VBOX"); 457 qWarning("New VBOX");
328 m_hbox = new QVBox( this ); 458 m_hbox = new QVBox( this );
329 459
330 commonChangeBox(); 460 commonChangeBox();
331 delete m_tabWidget;
332 m_tabWidget = 0;
333 m_hbox->setGeometry( frameRect() );
334 m_hbox->show();
335}
336 461
462}
337 463
464/*
465 * common box code
466 * first remove and add children
467 * the other splitters
468 * it is recursive as well due the call to setTabWidget
469 */
338void OSplitter::commonChangeBox() { 470void OSplitter::commonChangeBox() {
471
339 for (ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it ) { 472 for (ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it ) {
473 /* only if parent tab.. m_tabWidgets gets deleted and would do that as well */
474 if (m_parentTab )
475 removeFromTab( (*it).widget );
340 qWarning("Adding to box %s", (*it).name.latin1() ); 476 qWarning("Adding to box %s", (*it).name.latin1() );
341 addToBox( (*it) ); 477 addToBox( (*it) );
342 } 478 }
343 delete m_tabWidget; 479 for ( OSplitter* split = m_splitter.first(); split; split = m_splitter.next() ) {
344 m_tabWidget = 0; 480 /* tell them the world had changed */
481 split->setTabWidget( 0 );
482 Opie::OSplitterContainer con;
483 con.widget = split;
484 addToBox( con );
485 }
486
487
488
489 if (m_parentTab )
490 m_parentTab->addTab(this, iconName(), label() );
491 else {
492 m_hbox->setGeometry( frameRect() );
493 m_hbox->show();
494 delete m_tabWidget;
495 m_tabWidget = 0;
496 }
497}
498
499/*
500 * sets the tabwidget, removes tabs, and relayouts the widget
501 */
502void OSplitter::setTabWidget( OTabWidget* wid) {
503 /* clean up cause m_parentTab will not be available for us */
504 if ( m_parentTab ) {
505 if (m_hbox )
506 m_parentTab->removePage( this );
507 else if (!m_container.isEmpty() ){
508 ContainerList::Iterator it = m_container.begin();
509 for ( ; it != m_container.end(); ++it )
510 m_parentTab->removePage( (*it).widget );
511 }
512 }
513 /* the parent Splitter changed so either make us indepent or dep */
514
515 m_parentTab = wid;
516
517 QWidget *tab = m_tabWidget;
518 QWidget *box = m_hbox;
519 m_hbox = 0; m_tabWidget = 0;
520
521 if ( layoutMode() )
522 changeTab();
523 else if (m_orient == Horizontal )
524 changeHBox();
525 else
526 changeVBox();
527
528 /* our own crap is added and children from change* */
529 delete tab;
530 delete box;
531}
532
533
534#if 0
535void OSplitter::reparentAll() {
536 if (m_container.isEmpty() )
537 return;
538
539 ContainerList::Iterator it = m_container.begin();
540 for ( ; it != m_container.end(); ++it )
541 (*it).wid->reparent(0, 0, QPoint(0, 0) );
542
543
544}
545#endif
546
547/**
548 * @internal
549 */
550bool OSplitter::layoutMode()const {
551 if ( size().width() > m_size_policy &&
552 m_orient == Horizontal ) {
553 return false;
554 }else if ( size().height() > m_size_policy &&
555 m_size_policy == Vertical ) {
556 return false;
557 }
558
559 return true;
345} 560}
diff --git a/libopie/big-screen/osplitter.h b/libopie/big-screen/osplitter.h
index db69fc6..2bcde57 100644
--- a/libopie/big-screen/osplitter.h
+++ b/libopie/big-screen/osplitter.h
@@ -30,12 +30,13 @@
30#define OPIE_SPLITTER_H 30#define OPIE_SPLITTER_H
31 31
32#include <qstring.h> 32#include <qstring.h>
33 33
34#include <qframe.h> 34#include <qframe.h>
35#include <qvaluelist.h> 35#include <qvaluelist.h>
36#include <qlist.h>
36 37
37#include "obigscreen_p.h" 38#include "obigscreen_p.h"
38 39
39/* forward declarations */ 40/* forward declarations */
40class OTabWidget; 41class OTabWidget;
41class QHBox; 42class QHBox;
@@ -64,49 +65,74 @@ class OSplitter : public QFrame{
64public: 65public:
65 typedef QValueList<Opie::OSplitterContainer> ContainerList; 66 typedef QValueList<Opie::OSplitterContainer> ContainerList;
66 OSplitter( Qt::Orientation = Horizontal, QWidget *parent = 0, 67 OSplitter( Qt::Orientation = Horizontal, QWidget *parent = 0,
67 const char* name = 0, WFlags fl = 0 ); 68 const char* name = 0, WFlags fl = 0 );
68 ~OSplitter(); 69 ~OSplitter();
69 70
71 void setLabel( const QString& name );
72 void setIconName( const QString& name );
73 QString label()const;
74 QString iconName()const;
75
70 void setSizeChange( int width_height ); 76 void setSizeChange( int width_height );
71 77
78 void addWidget( OSplitter* splitter );
72 void addWidget( QWidget* wid, const QString& icon, const QString& label ); 79 void addWidget( QWidget* wid, const QString& icon, const QString& label );
73 void removeWidget( QWidget* ); 80 void removeWidget( QWidget* );
81 void removeWidget( OSplitter* );
74 82
75 void setCurrentWidget( QWidget* ); 83 void setCurrentWidget( QWidget* );
76 void setCurrentWidget( const QString& label ); 84 void setCurrentWidget( const QString& label );
77 void setCurrentWidget( int ); 85 void setCurrentWidget( int );
78 QWidget* currentWidget(); 86 QWidget* currentWidget()const;
79 87
80signals: 88signals:
81 /** 89 /**
82 * Emitted if in tab and comes directly from the tab widget 90 * Emitted if in tab and comes directly from the tab widget
83 * 91 *
84 */ 92 */
85 void currentChanged( QWidget* ); 93 void currentChanged( QWidget* );
94
95 /**
96 * emitted whenever a border is crossed
97 * true if in small screen mode
98 * false if in bigscreen
99 * this signal is emitted after the layout switch
100 * @param b The layout mode
101 * @param ori The orientation
102 */
103 void sizeChanged( bool b, Orientation ori);
86public: 104public:
87// QSize sizeHint()const; 105// QSize sizeHint()const;
88// QSize minimumSizeHint()const; 106// QSize minimumSizeHint()const;
89 107
90protected: 108protected:
91 void resizeEvent( QResizeEvent* ); 109 void resizeEvent( QResizeEvent* );
92 110
93private: 111private:
112 /* true if OTabMode */
113 bool layoutMode()const;
114// void reparentAll();
115 void setTabWidget( OTabWidget*);
94 void addToTab( const Opie::OSplitterContainer& ); 116 void addToTab( const Opie::OSplitterContainer& );
95 void addToBox( const Opie::OSplitterContainer& ); 117 void addToBox( const Opie::OSplitterContainer& );
96 void removeFromTab( QWidget* ); 118 void removeFromTab( QWidget* );
97 void changeTab(); 119 void changeTab();
98 void changeHBox(); 120 void changeHBox();
99 void changeVBox(); 121 void changeVBox();
100 void commonChangeBox(); 122 void commonChangeBox();
101 QHBox *m_hbox; 123 QHBox *m_hbox;
102 OTabWidget *m_tabWidget; 124 OTabWidget *m_tabWidget;
125 OTabWidget *m_parentTab;
103 Orientation m_orient; 126 Orientation m_orient;
104 int m_size_policy; 127 int m_size_policy;
105 128
106 ContainerList m_container; 129 ContainerList m_container;
130 QList<OSplitter> m_splitter;
131
132 QString m_icon, m_name;
107 133
108 struct Private; 134 struct Private;
109 Private *d; 135 Private *d;
110}; 136};
111 137
112 138