-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 | |||
@@ -43,4 +43,7 @@ | |||
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 |
@@ -62,4 +65,5 @@ OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFl | |||
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 | ||
@@ -73,4 +77,7 @@ OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFl | |||
73 | */ | 77 | */ |
74 | OSplitter::~OSplitter() { | 78 | OSplitter::~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; |
@@ -79,4 +86,42 @@ OSplitter::~OSplitter() { | |||
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 | */ | ||
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. |
82 | * If this size marked is crossed the splitter will relayout. | 127 | * If this size marked is crossed the splitter will relayout. |
@@ -99,4 +144,40 @@ void OSplitter::setSizeChange( int width_height ) { | |||
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 | */ | ||
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 |
102 | * at the end of either the Box or TabWidget. | 183 | * at the end of either the Box or TabWidget. |
@@ -125,8 +206,15 @@ void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& lab | |||
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 | ||
@@ -210,9 +298,11 @@ void OSplitter::setCurrentWidget( int tab ) { | |||
210 | * or null because all widgets are visible | 298 | * or null because all widgets are visible |
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 | } |
218 | 308 | ||
@@ -245,8 +335,10 @@ void OSplitter::resizeEvent( QResizeEvent* res ) { | |||
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 ) || |
@@ -257,14 +349,27 @@ void OSplitter::resizeEvent( QResizeEvent* res ) { | |||
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 | */ | ||
263 | void OSplitter::addToTab( const Opie::OSplitterContainer& con ) { | 361 | void 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 | */ | ||
269 | void OSplitter::addToBox( const Opie::OSplitterContainer& con ) { | 374 | void OSplitter::addToBox( const Opie::OSplitterContainer& con ) { |
270 | QWidget* wid = con.widget; | 375 | QWidget* wid = con.widget; |
@@ -272,9 +377,21 @@ void OSplitter::addToBox( const Opie::OSplitterContainer& con ) { | |||
272 | } | 377 | } |
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 ) { |
280 | m_tabWidget->setGeometry( frameRect() ); | 397 | m_tabWidget->setGeometry( frameRect() ); |
@@ -288,6 +405,12 @@ void OSplitter::changeTab() { | |||
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 | ||
@@ -297,6 +420,13 @@ void OSplitter::changeTab() { | |||
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(); |
@@ -304,4 +434,8 @@ void OSplitter::changeTab() { | |||
304 | } | 434 | } |
305 | 435 | ||
436 | /* | ||
437 | * changes over to a box | ||
438 | * this is recursive as well | ||
439 | */ | ||
306 | void OSplitter::changeHBox() { | 440 | void OSplitter::changeHBox() { |
307 | if (m_hbox ) { | 441 | if (m_hbox ) { |
@@ -313,8 +447,4 @@ void OSplitter::changeHBox() { | |||
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 | ||
@@ -329,17 +459,102 @@ void OSplitter::changeVBox() { | |||
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 | */ | ||
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() ); |
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 | */ | ||
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 | |||
@@ -34,4 +34,5 @@ | |||
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" |
@@ -68,13 +69,20 @@ public: | |||
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 | ||
80 | signals: | 88 | signals: |
@@ -84,4 +92,14 @@ signals: | |||
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); | ||
86 | public: | 104 | public: |
87 | // QSize sizeHint()const; | 105 | // QSize sizeHint()const; |
@@ -92,4 +110,8 @@ protected: | |||
92 | 110 | ||
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& ); |
95 | void addToBox( const Opie::OSplitterContainer& ); | 117 | void addToBox( const Opie::OSplitterContainer& ); |
@@ -101,8 +123,12 @@ private: | |||
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; |