summaryrefslogtreecommitdiff
path: root/libopie/big-screen/osplitter.cpp
Unidiff
Diffstat (limited to 'libopie/big-screen/osplitter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/big-screen/osplitter.cpp165
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
@@ -25,54 +25,50 @@
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include <qvaluelist.h> 29#include <qvaluelist.h>
30#include <qvbox.h> 30#include <qvbox.h>
31 31
32#include <opie/otabwidget.h> 32#include <opie/otabwidget.h>
33 33
34#include "osplitter.h" 34#include "osplitter.h"
35 35
36 36
37struct OSplitterContainer {
38 QWidget* widget;
39 const QString& icon
40 const QString& name;
41};
42
43
44/** 37/**
45 * 38 *
46 * This is the constructor of OSplitter 39 * This is the constructor of OSplitter
47 * You might want to call setSizeChange to tell 40 * You might want to call setSizeChange to tell
48 * OSplitter to change its layout when a specefic 41 * OSplitter to change its layout when a specefic
49 * mark was crossed. OSplitter sets a default value. 42 * mark was crossed. OSplitter sets a default value.
50 * 43 *
51 * You cann add widget with addWidget to the OSplitter. 44 * You cann add widget with addWidget to the OSplitter.
52 * 45 *
53 * @param orient The orientation wether to layout horizontal or vertical 46 * @param orient The orientation wether to layout horizontal or vertical
54 * @param parent The parent of this widget 47 * @param parent The parent of this widget
55 * @param name The name passed on to QObject 48 * @param name The name passed on to QObject
56 * @param fl Additional widgets flags passed to QWidget 49 * @param fl Additional widgets flags passed to QWidget
57 * 50 *
58 * @short single c'tor of the OSplitter 51 * @short single c'tor of the OSplitter
59 */ 52 */
60OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFlags fl ) 53OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFlags fl )
61 : QWidget( parent, name, fl ) 54 : QFrame( parent, name, fl )
62{ 55{
63 m_orient = orient; 56 m_orient = orient;
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}
68 64
69 65
70/** 66/**
71 * Destructor destructs this object and cleans up. All child 67 * Destructor destructs this object and cleans up. All child
72 * widgets will be deleted 68 * widgets will be deleted
73 * @see addWidget 69 * @see addWidget
74 */ 70 */
75OSplitter::~OSplitter() { 71OSplitter::~OSplitter() {
76 delete m_hbox; 72 delete m_hbox;
77 delete m_tabWidget; 73 delete m_tabWidget;
78} 74}
@@ -80,134 +76,243 @@ OSplitter::~OSplitter() {
80 76
81/** 77/**
82 * This function sets the size change policy of the splitter. 78 * This function sets the size change policy of the splitter.
83 * If this size marked is crossed the splitter will relayout. 79 * If this size marked is crossed the splitter will relayout.
84 * Note that depending on the set Orientation it'll either look 80 * Note that depending on the set Orientation it'll either look
85 * at the width or height. 81 * at the width or height.
86 * 82 *
87 * @param width_height The mark that will be watched. Interpreted depending on the Orientation of the Splitter. 83 * @param width_height The mark that will be watched. Interpreted depending on the Orientation of the Splitter.
88 * @return void 84 * @return void
89 */ 85 */
90void OSplitter::setSizeChange( int width_height ) { 86void 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}
94 92
95/** 93/**
96 * Adds a widget to the Splitter. The widgets gets inserted 94 * Adds a widget to the Splitter. The widgets gets inserted
97 * at the end of either the Box or TabWidget. 95 * at the end of either the Box or TabWidget.
98 * Ownership gets transfered and the widgets gets reparented. 96 * Ownership gets transfered and the widgets gets reparented.
99 * Note: icon and label is only available on small screensizes 97 * Note: icon and label is only available on small screensizes
100 * if size is smaller than the mark 98 * if size is smaller than the mark
101 * Warning: No null checking of the widget is done. Only on debug 99 * Warning: No null checking of the widget is done. Only on debug
102 * a message will be outputtet 100 * a message will be outputtet
103 * 101 *
104 * @param wid The widget which will be added 102 * @param wid The widget which will be added
105 * @param icon The icon of the possible Tab 103 * @param icon The icon of the possible Tab
106 * @param label The label of the possible Tab 104 * @param label The label of the possible Tab
107 */ 105 */
108void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& label ) { 106void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& label ) {
109#ifdef DEBUG 107#ifdef DEBUG
110 if (!wid ) { 108 if (!wid ) {
111 qWarning("Widget is not valid!"); 109 qWarning("Widget is not valid!");
112 return; 110 return;
113 } 111 }
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
120 m_container.append( cont ); 118 m_container.append( cont );
121 119
122 if (m_hbox ) 120 if (m_hbox )
123 addToBox( cont ); 121 addToBox( cont );
124 else 122 else
125 addToTab( cont ); 123 addToTab( cont );
126} 124}
127 125
128 126
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.
133 * 132 *
134 * @param w The widget to be removed 133 * @param w The widget to be removed
135 */ 134 */
136void OSplitter::removeWidget( QWidget* w) { 135void 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 */
142 if ( !m_hbox ) 146 if ( !m_hbox )
143 removeFromTab( w ); 147 removeFromTab( w );
144 148
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
156} 155}
157 156
158 157
159/** 158/**
160 * This method will give focus to the widget. If in a tabwidget 159 * This method will give focus to the widget. If in a tabwidget
161 * the tabbar will be changed 160 * the tabbar will be changed
162 * 161 *
163 * @param w The widget which will be set the current one 162 * @param w The widget which will be set the current one
164 */ 163 */
165void OSplitter::setCurrentWidget( QWidget* w) { 164void 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
171} 170}
172 171
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
176 * 176 *
177 * @param label Label to look for. First match will be taken 177 * @param label Label to look for. First match will be taken
178 */ 178 */
179void OSplitter::setCurrentWidget( const QString& label ) { 179void OSplitter::setCurrentWidget( const QString& label ) {
180 ContainerList::Iterator it; 180 ContainerList::Iterator it;
181 for (it = m_container.begin(); it != m_container.end(); ++it ) { 181 for (it = m_container.begin(); it != m_container.end(); ++it ) {
182 if ( (*it).name == label ) { 182 if ( (*it).name == label ) {
183 setCurrentWidget( (*it).widget ); 183 setCurrentWidget( (*it).widget );
184 break; 184 break;
185 } 185 }
186 } 186 }
187} 187}
188 188
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
192 */ 192 */
193QWidget* OSplitter::currentWidget() { 193QWidget* OSplitter::currentWidget() {
194 if ( m_hbox ) 194 if ( m_hbox )
195 return 0l; 195 return 0l;
196 else 196 else
197 return m_tabWidget->currentWidget(); 197 return m_tabWidget->currentWidget();
198} 198}
199 199
200 200#if 0
201/** 201/**
202 * @reimplented for internal reasons 202 * @reimplented for internal reasons
203 * returns the sizeHint of one of its sub widgets 203 * returns the sizeHint of one of its sub widgets
204 */ 204 */
205QSize OSplitter::sizeHint()const { 205QSize 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
208/** 213/**
209 * @reimplemented for internal reasons 214 * @reimplemented for internal reasons
210 */ 215 */
211void OSplitter::resizeEvent( QResizeEvent* res ) { 216void 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}
236
237
238void 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
244void OSplitter::addToBox( const Opie::OSplitterContainer& con ) {
245 QWidget* wid = con.widget;
246 wid->reparent(m_hbox, 0, QPoint(0, 0) );
247}
212 248
249void OSplitter::removeFromTab( QWidget* wid ) {
250 m_tabWidget->removePage( wid );
251}
252
253void 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
279void 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
294void 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
311void 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}