summaryrefslogtreecommitdiff
Unidiff
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
@@ -42,6 +42,9 @@
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
@@ -61,6 +64,7 @@ OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFl
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}
@@ -72,12 +76,53 @@ OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFl
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
@@ -98,6 +143,42 @@ void OSplitter::setSizeChange( int width_height ) {
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.
@@ -124,10 +205,17 @@ void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& lab
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
@@ -209,11 +297,13 @@ void OSplitter::setCurrentWidget( int tab ) {
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
@@ -244,10 +334,12 @@ void OSplitter::resizeEvent( QResizeEvent* res ) {
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 &&
@@ -256,26 +348,51 @@ void OSplitter::resizeEvent( QResizeEvent* res ) {
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;
@@ -287,8 +404,14 @@ void OSplitter::changeTab() {
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 ) {
@@ -296,13 +419,24 @@ void OSplitter::changeTab() {
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() );
@@ -312,10 +446,6 @@ void OSplitter::changeHBox() {
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() {
@@ -328,18 +458,103 @@ void OSplitter::changeVBox() {
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
@@ -33,6 +33,7 @@
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
@@ -67,15 +68,22 @@ public:
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 /**
@@ -83,6 +91,16 @@ signals:
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;
@@ -91,6 +109,10 @@ protected:
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* );
@@ -100,10 +122,14 @@ private:
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;