Diffstat (limited to 'libopie/big-screen/osplitter.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie/big-screen/osplitter.cpp | 165 |
1 files changed, 135 insertions, 30 deletions
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 | |||
@@ -36,9 +36,2 @@ | |||
36 | 36 | ||
37 | struct OSplitterContainer { | ||
38 | QWidget* widget; | ||
39 | const QString& icon | ||
40 | const QString& name; | ||
41 | }; | ||
42 | |||
43 | |||
44 | /** | 37 | /** |
@@ -60,3 +53,3 @@ struct OSplitterContainer { | |||
60 | OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFlags fl ) | 53 | OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFlags fl ) |
61 | : QWidget( parent, name, fl ) | 54 | : QFrame( parent, name, fl ) |
62 | { | 55 | { |
@@ -64,4 +57,7 @@ OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFl | |||
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 | } |
@@ -91,3 +87,5 @@ void 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 | } |
@@ -114,6 +112,6 @@ void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& lab | |||
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 | ||
@@ -129,4 +127,5 @@ void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& lab | |||
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. |
@@ -136,6 +135,11 @@ void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& lab | |||
136 | void OSplitter::removeWidget( QWidget* w) { | 135 | void 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 */ |
@@ -145,11 +149,6 @@ void OSplitter::removeWidget( QWidget* w) { | |||
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 | ||
@@ -166,5 +165,5 @@ void 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 | ||
@@ -173,3 +172,4 @@ void OSplitter::setCurrentWidget( QWidget* w) { | |||
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 |
@@ -189,3 +189,3 @@ void OSplitter::setCurrentWidget( const QString& label ) { | |||
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 |
@@ -199,3 +199,3 @@ QWidget* OSplitter::currentWidget() { | |||
199 | 199 | ||
200 | 200 | #if 0 | |
201 | /** | 201 | /** |
@@ -205,3 +205,8 @@ QWidget* OSplitter::currentWidget() { | |||
205 | QSize OSplitter::sizeHint()const { | 205 | QSize 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 | ||
@@ -211,3 +216,103 @@ QSize OSplitter::sizeHint()const { | |||
211 | void OSplitter::resizeEvent( QResizeEvent* res ) { | 216 | void 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 | } | ||
212 | 236 | ||
237 | |||
238 | void 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 | |||
244 | void OSplitter::addToBox( const Opie::OSplitterContainer& con ) { | ||
245 | QWidget* wid = con.widget; | ||
246 | wid->reparent(m_hbox, 0, QPoint(0, 0) ); | ||
247 | } | ||
248 | |||
249 | void OSplitter::removeFromTab( QWidget* wid ) { | ||
250 | m_tabWidget->removePage( wid ); | ||
251 | } | ||
252 | |||
253 | void 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 | |||
279 | void 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 | |||
294 | void 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 | |||
311 | void 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 | } |