author | zecke <zecke> | 2003-09-02 18:15:07 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-09-02 18:15:07 (UTC) |
commit | 3cf3fc001922a7ef34c7ff95751beb569809383b (patch) (unidiff) | |
tree | 4fb5fba6b8684b7a9a6cf88e3eb3e02068e73a52 /libopie/big-screen | |
parent | e87caebc920ad256d210eeb31aeb134318f0c104 (diff) | |
download | opie-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
-rw-r--r-- | libopie/big-screen/osplitter.cpp | 263 | ||||
-rw-r--r-- | libopie/big-screen/osplitter.h | 28 |
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 | |||
@@ -44,2 +44,5 @@ | |||
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 | * |
@@ -63,2 +66,3 @@ OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFl | |||
63 | m_tabWidget = 0; | 66 | m_tabWidget = 0; |
67 | m_parentTab = 0; | ||
64 | changeTab(); | 68 | changeTab(); |
@@ -74,2 +78,5 @@ OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFl | |||
74 | OSplitter::~OSplitter() { | 78 | OSplitter::~OSplitter() { |
79 | m_splitter.setAutoDelete( true ); | ||
80 | m_splitter.clear(); | ||
81 | |||
75 | delete m_hbox; | 82 | delete m_hbox; |
@@ -80,2 +87,40 @@ OSplitter::~OSplitter() { | |||
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 | */ | ||
95 | void 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 | */ | ||
104 | void OSplitter::setIconName( const QString& name ) { | ||
105 | m_icon = name; | ||
106 | } | ||
107 | |||
108 | |||
109 | /** | ||
110 | * returns the iconName | ||
111 | * @see setIconName | ||
112 | */ | ||
113 | QString OSplitter::iconName()const { | ||
114 | return m_icon; | ||
115 | } | ||
116 | |||
117 | /** | ||
118 | * returns the label set with setLabel | ||
119 | * @see setLabel | ||
120 | */ | ||
121 | QString 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. |
@@ -100,2 +145,38 @@ void OSplitter::setSizeChange( int width_height ) { | |||
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 | */ | ||
150 | void 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 | */ | ||
176 | void 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 |
@@ -126,6 +207,13 @@ void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& lab | |||
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 | } |
@@ -211,7 +299,9 @@ void OSplitter::setCurrentWidget( int tab ) { | |||
211 | */ | 299 | */ |
212 | QWidget* OSplitter::currentWidget() { | 300 | QWidget* 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 | } |
@@ -246,2 +336,3 @@ void OSplitter::resizeEvent( QResizeEvent* res ) { | |||
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() ); |
@@ -250,2 +341,3 @@ void OSplitter::resizeEvent( QResizeEvent* res ) { | |||
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 && |
@@ -258,6 +350,12 @@ void OSplitter::resizeEvent( QResizeEvent* res ) { | |||
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 | */ | ||
263 | void OSplitter::addToTab( const Opie::OSplitterContainer& con ) { | 361 | void OSplitter::addToTab( const Opie::OSplitterContainer& con ) { |
@@ -265,5 +363,12 @@ void OSplitter::addToTab( const Opie::OSplitterContainer& con ) { | |||
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 | */ | ||
269 | void OSplitter::addToBox( const Opie::OSplitterContainer& con ) { | 374 | void OSplitter::addToBox( const Opie::OSplitterContainer& con ) { |
@@ -273,7 +378,19 @@ void OSplitter::addToBox( const Opie::OSplitterContainer& con ) { | |||
273 | 378 | ||
379 | |||
380 | /* | ||
381 | * Removes a widget from the tab | ||
382 | */ | ||
274 | void OSplitter::removeFromTab( QWidget* wid ) { | 383 | void 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 | */ | ||
278 | void OSplitter::changeTab() { | 394 | void OSplitter::changeTab() { |
395 | /* if we're the owner of the tab widget */ | ||
279 | if (m_tabWidget ) { | 396 | if (m_tabWidget ) { |
@@ -289,4 +406,10 @@ void OSplitter::changeTab() { | |||
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*) ) ); |
@@ -298,4 +421,11 @@ void OSplitter::changeTab() { | |||
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() ); |
@@ -305,2 +435,6 @@ void OSplitter::changeTab() { | |||
305 | 435 | ||
436 | /* | ||
437 | * changes over to a box | ||
438 | * this is recursive as well | ||
439 | */ | ||
306 | void OSplitter::changeHBox() { | 440 | void OSplitter::changeHBox() { |
@@ -314,6 +448,2 @@ void OSplitter::changeHBox() { | |||
314 | commonChangeBox(); | 448 | commonChangeBox(); |
315 | delete m_tabWidget; | ||
316 | m_tabWidget = 0; | ||
317 | m_hbox->setGeometry( frameRect() ); | ||
318 | m_hbox->show(); | ||
319 | } | 449 | } |
@@ -330,11 +460,17 @@ void OSplitter::changeVBox() { | |||
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 | */ | ||
338 | void OSplitter::commonChangeBox() { | 470 | void 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() ); |
@@ -342,4 +478,83 @@ void OSplitter::commonChangeBox() { | |||
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 | */ | ||
502 | void 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 | ||
535 | void 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 | */ | ||
550 | bool 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 | |||
@@ -35,2 +35,3 @@ | |||
35 | #include <qvaluelist.h> | 35 | #include <qvaluelist.h> |
36 | #include <qlist.h> | ||
36 | 37 | ||
@@ -69,6 +70,13 @@ public: | |||
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 | ||
@@ -77,3 +85,3 @@ public: | |||
77 | void setCurrentWidget( int ); | 85 | void setCurrentWidget( int ); |
78 | QWidget* currentWidget(); | 86 | QWidget* currentWidget()const; |
79 | 87 | ||
@@ -85,2 +93,12 @@ signals: | |||
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); | ||
86 | public: | 104 | public: |
@@ -93,2 +111,6 @@ protected: | |||
93 | private: | 111 | private: |
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& ); |
@@ -102,2 +124,3 @@ private: | |||
102 | OTabWidget *m_tabWidget; | 124 | OTabWidget *m_tabWidget; |
125 | OTabWidget *m_parentTab; | ||
103 | Orientation m_orient; | 126 | Orientation m_orient; |
@@ -106,2 +129,5 @@ private: | |||
106 | ContainerList m_container; | 129 | ContainerList m_container; |
130 | QList<OSplitter> m_splitter; | ||
131 | |||
132 | QString m_icon, m_name; | ||
107 | 133 | ||