-rw-r--r-- | libopie2/examples/opieui/olistviewdemo/.cvsignore | 8 | ||||
-rw-r--r-- | libopie2/examples/opieui/olistviewdemo/main.cpp | 26 | ||||
-rw-r--r-- | libopie2/examples/opieui/olistviewdemo/olistviewdemo.cpp | 54 | ||||
-rw-r--r-- | libopie2/examples/opieui/olistviewdemo/olistviewdemo.h | 51 | ||||
-rw-r--r-- | libopie2/examples/opieui/olistviewdemo/olistviewdemo.pro (copied from libopie2/examples/opieui/oversatileviewdemo/opieui.pro) | 8 | ||||
-rw-r--r-- | libopie2/examples/opieui/opieui.pro | 3 | ||||
-rw-r--r-- | libopie2/examples/opieui/oversatileviewdemo/oversatileviewdemo.pro (renamed from libopie2/examples/opieui/oversatileviewdemo/opieui.pro) | 0 | ||||
-rw-r--r-- | libopie2/opieui/olistview.cpp | 109 | ||||
-rw-r--r-- | libopie2/opieui/olistview.h | 177 |
9 files changed, 380 insertions, 56 deletions
diff --git a/libopie2/examples/opieui/olistviewdemo/.cvsignore b/libopie2/examples/opieui/olistviewdemo/.cvsignore new file mode 100644 index 0000000..1317f7e --- a/dev/null +++ b/libopie2/examples/opieui/olistviewdemo/.cvsignore | |||
@@ -0,0 +1,8 @@ | |||
1 | Makefile* | ||
2 | moc* | ||
3 | *moc | ||
4 | *.o | ||
5 | ~* | ||
6 | moc | ||
7 | obj | ||
8 | |||
diff --git a/libopie2/examples/opieui/olistviewdemo/main.cpp b/libopie2/examples/opieui/olistviewdemo/main.cpp new file mode 100644 index 0000000..a93f361 --- a/dev/null +++ b/libopie2/examples/opieui/olistviewdemo/main.cpp | |||
@@ -0,0 +1,26 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Opie Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | **********************************************************************/ | ||
15 | |||
16 | #include "olistviewdemo.h" | ||
17 | #include <opie2/oapplication.h> | ||
18 | |||
19 | int main( int argc, char **argv ) | ||
20 | { | ||
21 | OApplication a( argc, argv, "OListViewDemo" ); | ||
22 | OListViewDemo e; | ||
23 | a.showMainWidget(&e); | ||
24 | return a.exec(); | ||
25 | } | ||
26 | |||
diff --git a/libopie2/examples/opieui/olistviewdemo/olistviewdemo.cpp b/libopie2/examples/opieui/olistviewdemo/olistviewdemo.cpp new file mode 100644 index 0000000..31bda9d --- a/dev/null +++ b/libopie2/examples/opieui/olistviewdemo/olistviewdemo.cpp | |||
@@ -0,0 +1,54 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | |||
4 | Copyright (C) 2003 Michael 'Mickey' Lauer | ||
5 | <mickey@tm.informatik.uni-frankfurt.de> | ||
6 | =. | ||
7 | .=l. | ||
8 | .>+-= | ||
9 | _;:, .> :=|. This program is free software; you can | ||
10 | .> <`_, > . <= redistribute it and/or modify it under | ||
11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
12 | .="- .-=="i, .._ License as published by the Free Software | ||
13 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
14 | ._= =} : or (at your option) any later version. | ||
15 | .%`+i> _;_. | ||
16 | .i_,=:_. -<s. This program is distributed in the hope that | ||
17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
18 | : .. .:, . . . without even the implied warranty of | ||
19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
21 | ..}^=.= = ; Library General Public License for more | ||
22 | ++= -. .` .: details. | ||
23 | : = ...= . :.=- | ||
24 | -. .:....=;==+<; You should have received a copy of the GNU | ||
25 | -_. . . )=. = Library General Public License along with | ||
26 | -- :-=` this library; see the file COPYING.LIB. | ||
27 | If not, write to the Free Software Foundation, | ||
28 | Inc., 59 Temple Place - Suite 330, | ||
29 | Boston, MA 02111-1307, USA. | ||
30 | |||
31 | */ | ||
32 | |||
33 | #include "olistviewdemo.h" | ||
34 | #include <opie2/olistview.h> | ||
35 | |||
36 | #include <qstring.h> | ||
37 | #include <qpixmap.h> | ||
38 | #include <qlistview.h> | ||
39 | |||
40 | OListViewDemo::OListViewDemo( QWidget* parent, const char* name, WFlags f ) | ||
41 | :QVBox( parent, name, f ) | ||
42 | { | ||
43 | lv = new ONamedListView( this ); | ||
44 | lv->addColumns( QStringList::split( ' ', "Column1 Column2 Column3 Column4" ) ); | ||
45 | |||
46 | ONamedListViewItem* item = new ONamedListViewItem( lv, QStringList::split( ' ', "Text1 Text2 Text3 Text4" ) ); | ||
47 | item->setText( "Column2", "ModifiedText" ); | ||
48 | item->setText( "Column5", "ThisColumnDoesNotExits" ); | ||
49 | } | ||
50 | |||
51 | OListViewDemo::~OListViewDemo() | ||
52 | { | ||
53 | } | ||
54 | |||
diff --git a/libopie2/examples/opieui/olistviewdemo/olistviewdemo.h b/libopie2/examples/opieui/olistviewdemo/olistviewdemo.h new file mode 100644 index 0000000..8a5986a --- a/dev/null +++ b/libopie2/examples/opieui/olistviewdemo/olistviewdemo.h | |||
@@ -0,0 +1,51 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | |||
4 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | ||
5 | =. | ||
6 | .=l. | ||
7 | .>+-= | ||
8 | _;:, .> :=|. This program is free software; you can | ||
9 | .> <`_, > . <= redistribute it and/or modify it under | ||
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
11 | .="- .-=="i, .._ License as published by the Free Software | ||
12 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
13 | ._= =} : or (at your option) any later version. | ||
14 | .%`+i> _;_. | ||
15 | .i_,=:_. -<s. This program is distributed in the hope that | ||
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
17 | : .. .:, . . . without even the implied warranty of | ||
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
20 | ..}^=.= = ; Library General Public License for more | ||
21 | ++= -. .` .: details. | ||
22 | : = ...= . :.=- | ||
23 | -. .:....=;==+<; You should have received a copy of the GNU | ||
24 | -_. . . )=. = Library General Public License along with | ||
25 | -- :-=` this library; see the file COPYING.LIB. | ||
26 | If not, write to the Free Software Foundation, | ||
27 | Inc., 59 Temple Place - Suite 330, | ||
28 | Boston, MA 02111-1307, USA. | ||
29 | |||
30 | */ | ||
31 | |||
32 | #ifndef OLISTVIEWDEMO_H | ||
33 | #define OLISTVIEWDEMO_H | ||
34 | |||
35 | #include <qvbox.h> | ||
36 | #include <opie2/olistview.h> | ||
37 | |||
38 | class OListViewDemo: public QVBox | ||
39 | { | ||
40 | Q_OBJECT | ||
41 | |||
42 | public: | ||
43 | OListViewDemo( QWidget* parent=0, const char* name=0, WFlags f=0 ); | ||
44 | virtual ~OListViewDemo(); | ||
45 | |||
46 | private: | ||
47 | ONamedListView* lv; | ||
48 | |||
49 | }; | ||
50 | |||
51 | #endif | ||
diff --git a/libopie2/examples/opieui/oversatileviewdemo/opieui.pro b/libopie2/examples/opieui/olistviewdemo/olistviewdemo.pro index 8ad5fc9..aabe733 100644 --- a/libopie2/examples/opieui/oversatileviewdemo/opieui.pro +++ b/libopie2/examples/opieui/olistviewdemo/olistviewdemo.pro | |||
@@ -1,17 +1,15 @@ | |||
1 | TEMPLATE = app | 1 | TEMPLATE = app |
2 | CONFIG = qt warn_on debug | 2 | CONFIG = qt warn_on debug |
3 | HEADERS = opieuidemo.h \ | 3 | HEADERS = olistviewdemo.h |
4 | oversatileviewdemo.h | 4 | SOURCES = olistviewdemo.cpp \ |
5 | SOURCES = opieuidemo.cpp \ | ||
6 | oversatileviewdemo.cpp \ | ||
7 | main.cpp | 5 | main.cpp |
8 | INCLUDEPATH += $(OPIEDIR)/include | 6 | INCLUDEPATH += $(OPIEDIR)/include |
9 | DEPENDPATH += $(OPIEDIR)/include | 7 | DEPENDPATH += $(OPIEDIR)/include |
10 | LIBS += -lopieui2 -lopiecore2 | 8 | LIBS += -lopieui2 -lopiecore2 |
11 | TARGET = opieuidemo | 9 | TARGET = olistviewdemo |
12 | MOC_DIR = moc | 10 | MOC_DIR = moc |
13 | OBJECTS_DIR = obj | 11 | OBJECTS_DIR = obj |
14 | 12 | ||
15 | include ( $(OPIEDIR)/include.pro ) | 13 | include ( $(OPIEDIR)/include.pro ) |
16 | 14 | ||
17 | 15 | ||
diff --git a/libopie2/examples/opieui/opieui.pro b/libopie2/examples/opieui/opieui.pro new file mode 100644 index 0000000..b52f013 --- a/dev/null +++ b/libopie2/examples/opieui/opieui.pro | |||
@@ -0,0 +1,3 @@ | |||
1 | TEMPLATE = subdirs | ||
2 | SUBDIRS = olistviewdemo oversatileviewdemo | ||
3 | |||
diff --git a/libopie2/examples/opieui/oversatileviewdemo/opieui.pro b/libopie2/examples/opieui/oversatileviewdemo/oversatileviewdemo.pro index 8ad5fc9..8ad5fc9 100644 --- a/libopie2/examples/opieui/oversatileviewdemo/opieui.pro +++ b/libopie2/examples/opieui/oversatileviewdemo/oversatileviewdemo.pro | |||
diff --git a/libopie2/opieui/olistview.cpp b/libopie2/opieui/olistview.cpp index 2b2f09a..8f97cc6 100644 --- a/libopie2/opieui/olistview.cpp +++ b/libopie2/opieui/olistview.cpp | |||
@@ -213,81 +213,92 @@ QDataStream& operator>>( QDataStream& s, OListView& lv ) | |||
213 | *======================================================================================*/ | 213 | *======================================================================================*/ |
214 | 214 | ||
215 | OListViewItem::OListViewItem(QListView *parent) | 215 | OListViewItem::OListViewItem(QListView *parent) |
216 | : QListViewItem(parent) | 216 | : QListViewItem(parent) |
217 | { | 217 | { |
218 | init(); | 218 | init(); |
219 | } | 219 | } |
220 | 220 | ||
221 | |||
221 | OListViewItem::OListViewItem(QListViewItem *parent) | 222 | OListViewItem::OListViewItem(QListViewItem *parent) |
222 | : QListViewItem(parent) | 223 | : QListViewItem(parent) |
223 | { | 224 | { |
224 | init(); | 225 | init(); |
225 | } | 226 | } |
226 | 227 | ||
228 | |||
227 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) | 229 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) |
228 | : QListViewItem(parent, after) | 230 | : QListViewItem(parent, after) |
229 | { | 231 | { |
230 | init(); | 232 | init(); |
231 | } | 233 | } |
232 | 234 | ||
235 | |||
233 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) | 236 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) |
234 | : QListViewItem(parent, after) | 237 | : QListViewItem(parent, after) |
235 | { | 238 | { |
236 | init(); | 239 | init(); |
237 | } | 240 | } |
238 | 241 | ||
242 | |||
239 | OListViewItem::OListViewItem(QListView *parent, | 243 | OListViewItem::OListViewItem(QListView *parent, |
240 | QString label1, QString label2, QString label3, QString label4, | 244 | QString label1, QString label2, QString label3, QString label4, |
241 | QString label5, QString label6, QString label7, QString label8) | 245 | QString label5, QString label6, QString label7, QString label8) |
242 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) | 246 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) |
243 | { | 247 | { |
244 | init(); | 248 | init(); |
245 | } | 249 | } |
246 | 250 | ||
251 | |||
247 | OListViewItem::OListViewItem(QListViewItem *parent, | 252 | OListViewItem::OListViewItem(QListViewItem *parent, |
248 | QString label1, QString label2, QString label3, QString label4, | 253 | QString label1, QString label2, QString label3, QString label4, |
249 | QString label5, QString label6, QString label7, QString label8) | 254 | QString label5, QString label6, QString label7, QString label8) |
250 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) | 255 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) |
251 | { | 256 | { |
252 | init(); | 257 | init(); |
253 | } | 258 | } |
254 | 259 | ||
260 | |||
255 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, | 261 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, |
256 | QString label1, QString label2, QString label3, QString label4, | 262 | QString label1, QString label2, QString label3, QString label4, |
257 | QString label5, QString label6, QString label7, QString label8) | 263 | QString label5, QString label6, QString label7, QString label8) |
258 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) | 264 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) |
259 | { | 265 | { |
260 | init(); | 266 | init(); |
261 | } | 267 | } |
262 | 268 | ||
269 | |||
263 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, | 270 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, |
264 | QString label1, QString label2, QString label3, QString label4, | 271 | QString label1, QString label2, QString label3, QString label4, |
265 | QString label5, QString label6, QString label7, QString label8) | 272 | QString label5, QString label6, QString label7, QString label8) |
266 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) | 273 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) |
267 | { | 274 | { |
268 | init(); | 275 | init(); |
269 | } | 276 | } |
270 | 277 | ||
278 | |||
271 | OListViewItem::~OListViewItem() | 279 | OListViewItem::~OListViewItem() |
272 | { | 280 | { |
273 | } | 281 | } |
274 | 282 | ||
283 | |||
275 | void OListViewItem::init() | 284 | void OListViewItem::init() |
276 | { | 285 | { |
277 | m_known = false; | 286 | m_known = false; |
278 | } | 287 | } |
279 | 288 | ||
289 | |||
280 | const QColor &OListViewItem::backgroundColor() | 290 | const QColor &OListViewItem::backgroundColor() |
281 | { | 291 | { |
282 | return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : | 292 | return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : |
283 | listView()->viewport()->colorGroup().base(); | 293 | listView()->viewport()->colorGroup().base(); |
284 | } | 294 | } |
285 | 295 | ||
296 | |||
286 | bool OListViewItem::isAlternate() | 297 | bool OListViewItem::isAlternate() |
287 | { | 298 | { |
288 | OListView *lv = static_cast<OListView*>( listView() ); | 299 | OListView *lv = static_cast<OListView*>( listView() ); |
289 | 300 | ||
290 | // check if the item above is an OListViewItem | 301 | // check if the item above is an OListViewItem |
291 | OListViewItem *above = static_cast<OListViewItem*>( itemAbove() ); | 302 | OListViewItem *above = static_cast<OListViewItem*>( itemAbove() ); |
292 | /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/ | 303 | /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/ |
293 | 304 | ||
@@ -321,16 +332,17 @@ bool OListViewItem::isAlternate() | |||
321 | item->m_known = true; | 332 | item->m_known = true; |
322 | item = static_cast<OListViewItem *>(item->nextSibling()); | 333 | item = static_cast<OListViewItem *>(item->nextSibling()); |
323 | /* if (!item.inherits( "OListViewItem" ) ) break; */ | 334 | /* if (!item.inherits( "OListViewItem" ) ) break; */ |
324 | } | 335 | } |
325 | } | 336 | } |
326 | return m_odd; | 337 | return m_odd; |
327 | } | 338 | } |
328 | 339 | ||
340 | |||
329 | void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) | 341 | void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) |
330 | { | 342 | { |
331 | QColorGroup _cg = cg; | 343 | QColorGroup _cg = cg; |
332 | const QPixmap *pm = listView()->viewport()->backgroundPixmap(); | 344 | const QPixmap *pm = listView()->viewport()->backgroundPixmap(); |
333 | if (pm && !pm->isNull()) | 345 | if (pm && !pm->isNull()) |
334 | { | 346 | { |
335 | _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); | 347 | _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); |
336 | p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); | 348 | p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); |
@@ -343,21 +355,23 @@ void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, in | |||
343 | 355 | ||
344 | //FIXME: Use styling here! | 356 | //FIXME: Use styling here! |
345 | 357 | ||
346 | const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); | 358 | const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); |
347 | p->setPen( pen ); | 359 | p->setPen( pen ); |
348 | p->drawLine( width-1, 0, width-1, height() ); | 360 | p->drawLine( width-1, 0, width-1, height() ); |
349 | } | 361 | } |
350 | 362 | ||
363 | |||
351 | OListViewItem* OListViewItem::childFactory() | 364 | OListViewItem* OListViewItem::childFactory() |
352 | { | 365 | { |
353 | return new OListViewItem( this ); | 366 | return new OListViewItem( this ); |
354 | } | 367 | } |
355 | 368 | ||
369 | |||
356 | #ifndef QT_NO_DATASTREAM | 370 | #ifndef QT_NO_DATASTREAM |
357 | void OListViewItem::serializeTo( QDataStream& s ) const | 371 | void OListViewItem::serializeTo( QDataStream& s ) const |
358 | { | 372 | { |
359 | #warning Caution... the binary format is still under construction... | 373 | #warning Caution... the binary format is still under construction... |
360 | qDebug( "storing OListViewItem..." ); | 374 | qDebug( "storing OListViewItem..." ); |
361 | 375 | ||
362 | // store item text | 376 | // store item text |
363 | for ( int i = 0; i < listView()->columns(); ++i ) | 377 | for ( int i = 0; i < listView()->columns(); ++i ) |
@@ -380,16 +394,18 @@ void OListViewItem::serializeTo( QDataStream& s ) const | |||
380 | for ( int i = 0; i < items; ++i ) | 394 | for ( int i = 0; i < items; ++i ) |
381 | { | 395 | { |
382 | s << *static_cast<OListViewItem*>( item ); | 396 | s << *static_cast<OListViewItem*>( item ); |
383 | item = item->nextSibling(); | 397 | item = item->nextSibling(); |
384 | } | 398 | } |
385 | 399 | ||
386 | qDebug( "OListviewItem stored." ); | 400 | qDebug( "OListviewItem stored." ); |
387 | } | 401 | } |
402 | |||
403 | |||
388 | void OListViewItem::serializeFrom( QDataStream& s ) | 404 | void OListViewItem::serializeFrom( QDataStream& s ) |
389 | { | 405 | { |
390 | #warning Caution... the binary format is still under construction... | 406 | #warning Caution... the binary format is still under construction... |
391 | qDebug( "loading OListViewItem..." ); | 407 | qDebug( "loading OListViewItem..." ); |
392 | 408 | ||
393 | for ( int i = 0; i < listView()->columns(); ++i ) | 409 | for ( int i = 0; i < listView()->columns(); ++i ) |
394 | { | 410 | { |
395 | QString coltext; | 411 | QString coltext; |
@@ -406,18 +422,111 @@ void OListViewItem::serializeFrom( QDataStream& s ) | |||
406 | { | 422 | { |
407 | OListViewItem* item = childFactory(); | 423 | OListViewItem* item = childFactory(); |
408 | s >> (*item); | 424 | s >> (*item); |
409 | } | 425 | } |
410 | 426 | ||
411 | qDebug( "OListViewItem loaded." ); | 427 | qDebug( "OListViewItem loaded." ); |
412 | } | 428 | } |
413 | 429 | ||
430 | |||
414 | QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) | 431 | QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) |
415 | { | 432 | { |
416 | lvi.serializeTo( s ); | 433 | lvi.serializeTo( s ); |
417 | } | 434 | } |
418 | 435 | ||
436 | |||
419 | QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) | 437 | QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) |
420 | { | 438 | { |
421 | lvi.serializeFrom( s ); | 439 | lvi.serializeFrom( s ); |
422 | } | 440 | } |
423 | #endif // QT_NO_DATASTREAM | 441 | #endif // QT_NO_DATASTREAM |
442 | |||
443 | |||
444 | /*====================================================================================== | ||
445 | * ONamedListView | ||
446 | *======================================================================================*/ | ||
447 | |||
448 | ONamedListView::ONamedListView( QWidget *parent, const char *name ) | ||
449 | :OListView( parent, name ) | ||
450 | { | ||
451 | } | ||
452 | |||
453 | |||
454 | ONamedListView::~ONamedListView() | ||
455 | { | ||
456 | } | ||
457 | |||
458 | |||
459 | void ONamedListView::addColumns( const QStringList& columns ) | ||
460 | { | ||
461 | for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it ) | ||
462 | { | ||
463 | qDebug( "adding column %s", (const char*) *it ); | ||
464 | addColumn( *it ); | ||
465 | } | ||
466 | } | ||
467 | |||
468 | |||
469 | /*====================================================================================== | ||
470 | * ONamedListViewItem | ||
471 | *======================================================================================*/ | ||
472 | |||
473 | ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts ) | ||
474 | :OListViewItem( parent ) | ||
475 | { | ||
476 | setText( texts ); | ||
477 | } | ||
478 | |||
479 | |||
480 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts ) | ||
481 | :OListViewItem( parent ) | ||
482 | { | ||
483 | setText( texts ); | ||
484 | } | ||
485 | |||
486 | |||
487 | ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ) | ||
488 | :OListViewItem( parent, after ) | ||
489 | { | ||
490 | setText( texts ); | ||
491 | } | ||
492 | |||
493 | |||
494 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ) | ||
495 | :OListViewItem( parent, after ) | ||
496 | { | ||
497 | setText( texts ); | ||
498 | } | ||
499 | |||
500 | |||
501 | ONamedListViewItem::~ONamedListViewItem() | ||
502 | { | ||
503 | } | ||
504 | |||
505 | |||
506 | void ONamedListViewItem::setText( const QStringList& texts ) | ||
507 | { | ||
508 | int col = 0; | ||
509 | for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it ) | ||
510 | { | ||
511 | qDebug( "setting column %d = text %s", col, (const char*) *it ); | ||
512 | OListViewItem::setText( col++, *it ); | ||
513 | } | ||
514 | |||
515 | } | ||
516 | |||
517 | |||
518 | void ONamedListViewItem::setText( const QString& column, const QString& text ) | ||
519 | { | ||
520 | //FIXME: If used excessively, this will slow down performance of updates | ||
521 | //FIXME: because of the linear search over all column texts. | ||
522 | //FIXME: I will optimize later by using a hash map. | ||
523 | for ( int i = 0; i < listView()->columns(); ++i ) | ||
524 | { | ||
525 | if ( listView()->columnText( i ) == column ) | ||
526 | { | ||
527 | OListViewItem::setText( i, text ); | ||
528 | return; | ||
529 | } | ||
530 | } | ||
531 | qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column ); | ||
532 | } | ||
diff --git a/libopie2/opieui/olistview.h b/libopie2/opieui/olistview.h index b62e278..99770bf 100644 --- a/libopie2/opieui/olistview.h +++ b/libopie2/opieui/olistview.h | |||
@@ -33,135 +33,127 @@ | |||
33 | 33 | ||
34 | #include <qcolor.h> | 34 | #include <qcolor.h> |
35 | #include <qlistview.h> | 35 | #include <qlistview.h> |
36 | #include <qpen.h> | 36 | #include <qpen.h> |
37 | #include <qdatastream.h> | 37 | #include <qdatastream.h> |
38 | 38 | ||
39 | class OListViewItem; | 39 | class OListViewItem; |
40 | 40 | ||
41 | /*====================================================================================== | ||
42 | * OListView | ||
43 | *======================================================================================*/ | ||
44 | |||
41 | /** | 45 | /** |
46 | * @brief A list/tree widget. | ||
47 | * | ||
42 | * A @ref QListView variant featuring visual and functional enhancements | 48 | * A @ref QListView variant featuring visual and functional enhancements |
43 | * like an alternate background for odd rows, an autostretch mode | 49 | * like an alternate background for odd rows, an autostretch mode |
44 | * for the width of the widget ( >= Qt 3 only ) and persistence capabilities. | 50 | * for the width of the widget ( >= Qt 3 only ) and persistence capabilities. |
45 | * | 51 | * |
46 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 52 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
47 | * @short OListView list/tree widget. | ||
48 | */ | 53 | */ |
49 | class OListView: public QListView | 54 | class OListView: public QListView |
50 | { | 55 | { |
51 | public: | 56 | public: |
52 | /** | 57 | /** |
53 | * Constructor. | 58 | * Constructor. |
54 | * | 59 | * |
55 | * The parameters @p parent and @p name are handled by | 60 | * The parameters @a parent and @a name are handled by |
56 | * @ref QListView, as usual. | 61 | * @ref QListView, as usual. |
57 | */ | 62 | */ |
58 | OListView ( QWidget *parent = 0, const char *name = 0 ); | 63 | OListView( QWidget* parent = 0, const char* name = 0 ); |
59 | |||
60 | /** | 64 | /** |
61 | * Destructor. | 65 | * Destructor. |
62 | */ | 66 | */ |
63 | virtual ~OListView(); | 67 | virtual ~OListView(); |
64 | |||
65 | /** | 68 | /** |
66 | * Let the last column fit exactly all the available width. | 69 | * Let the last column fit exactly all the available width. |
67 | */ | 70 | */ |
68 | void setFullWidth( bool fullWidth ); | 71 | void setFullWidth( bool fullWidth ); |
69 | |||
70 | /** | 72 | /** |
71 | * Returns whether the last column is set to fit the available width. | 73 | * Returns whether the last column is set to fit the available width. |
72 | */ | 74 | */ |
73 | bool fullWidth() const; | 75 | bool fullWidth() const; |
74 | |||
75 | /** | 76 | /** |
76 | * Reimplemented for full width support | 77 | * Reimplemented for full width support |
77 | */ | 78 | */ |
78 | virtual int addColumn( const QString& label, int width = -1 ); | 79 | virtual int addColumn( const QString& label, int width = -1 ); |
79 | |||
80 | /** | 80 | /** |
81 | * Reimplemented for full width support | 81 | * Reimplemented for full width support |
82 | */ | 82 | */ |
83 | virtual int addColumn( const QIconSet& iconset, const QString& label, int width = -1 ); | 83 | virtual int addColumn( const QIconSet& iconset, const QString& label, int width = -1 ); |
84 | |||
85 | /** | 84 | /** |
86 | * Reimplemented for full width support | 85 | * Reimplemented for full width support |
87 | */ | 86 | */ |
88 | virtual void removeColumn(int index); | 87 | virtual void removeColumn(int index); |
89 | |||
90 | /** | 88 | /** |
91 | * sets the alternate background background color. | 89 | * Set the alternate background background @a color. |
90 | * Set to an invalid color to disable alternate colors. | ||
92 | * This only has an effect if the items are OListViewItems | 91 | * This only has an effect if the items are OListViewItems |
93 | * | ||
94 | * @param c the color to use for every other item. Set to an invalid | ||
95 | * color to disable alternate colors. | ||
96 | */ | 92 | */ |
97 | void setAlternateBackground( const QColor &c ); | 93 | void setAlternateBackground( const QColor& color ); |
98 | |||
99 | /** | 94 | /** |
100 | * sets the column separator pen. | 95 | * Sets the column separator @a pen. |
101 | * | ||
102 | * @param p the pen used to draw the column separator. | ||
103 | */ | 96 | */ |
104 | void setColumnSeparator( const QPen &p ); | 97 | void setColumnSeparator( const QPen& pen ); |
105 | 98 | ||
106 | /** | 99 | /** |
107 | * @return the alternate background color | 100 | * @returns the alternate background color |
108 | */ | 101 | */ |
109 | const QColor& alternateBackground() const; | 102 | const QColor& alternateBackground() const; |
110 | |||
111 | /** | 103 | /** |
112 | * @return the column separator pen | 104 | * @return the column separator pen |
113 | */ | 105 | */ |
114 | const QPen& columnSeparator() const; | 106 | const QPen& columnSeparator() const; |
115 | |||
116 | /** | 107 | /** |
117 | * create a list view item as child of this object | 108 | * Create a list view item as child of this object |
118 | * @return the new object | 109 | * @returns the new object |
119 | */ | 110 | */ |
120 | virtual OListViewItem* childFactory(); | 111 | virtual OListViewItem* childFactory(); |
121 | |||
122 | #ifndef QT_NO_DATASTREAM | 112 | #ifndef QT_NO_DATASTREAM |
123 | /** | 113 | /** |
124 | * serialize this object to a @ref QDataStream | 114 | * Serialize this object to @ref QDataStream @a stream |
125 | * @param s the stream used to serialize this object. | ||
126 | */ | 115 | */ |
127 | virtual void serializeTo( QDataStream& s ) const; | 116 | virtual void serializeTo( QDataStream& stream ) const; |
128 | |||
129 | /** | 117 | /** |
130 | * serialize this object from a @ref QDataStream | 118 | * Serialize this object from a @ref QDataStream @a stream |
131 | * @param s the stream used to serialize this object. | ||
132 | */ | 119 | */ |
133 | virtual void serializeFrom( QDataStream& s ); | 120 | virtual void serializeFrom( QDataStream& s ); |
134 | #endif | 121 | #endif |
135 | 122 | ||
136 | private: | 123 | private: |
137 | QColor m_alternateBackground; | 124 | QColor m_alternateBackground; |
138 | bool m_fullWidth; | 125 | bool m_fullWidth; |
139 | QPen m_columnSeparator; | 126 | QPen m_columnSeparator; |
140 | }; | 127 | }; |
141 | 128 | ||
142 | #ifndef QT_NO_DATASTREAM | 129 | #ifndef QT_NO_DATASTREAM |
143 | /** | 130 | /** |
144 | * \relates QListView | 131 | * @relates OListView |
145 | * Writes a listview to the stream and returns a reference to the stream. | 132 | * Writes @a listview to the @a stream and returns a reference to the stream. |
146 | */ | 133 | */ |
147 | QDataStream& operator<<( QDataStream& s, const OListView& lv ); | 134 | QDataStream& operator<<( QDataStream& stream, const OListView& listview ); |
148 | /** | 135 | /** |
149 | * \relates QListView | 136 | * @relates OListView |
150 | * Reads a listview from the stream and returns a reference to the stream. | 137 | * Reads @a listview from the @a stream and returns a reference to the stream. |
151 | */ | 138 | */ |
152 | QDataStream& operator>>( QDataStream& s, OListView& lv ); | 139 | QDataStream& operator>>( QDataStream& stream, OListView& listview ); |
153 | #endif // QT_NO_DATASTREAM | 140 | #endif // QT_NO_DATASTREAM |
154 | 141 | ||
155 | //****************************** OListViewItem ****************************************************************** | 142 | /*====================================================================================== |
143 | * OListViewItem | ||
144 | *======================================================================================*/ | ||
156 | 145 | ||
157 | class OListViewItem: public QListViewItem | 146 | class OListViewItem: public QListViewItem |
158 | { | 147 | { |
159 | public: | 148 | public: |
149 | /** | ||
150 | * Constructors. | ||
151 | */ | ||
160 | OListViewItem( QListView * parent ); | 152 | OListViewItem( QListView * parent ); |
161 | OListViewItem( QListViewItem * parent ); | 153 | OListViewItem( QListViewItem * parent ); |
162 | OListViewItem( QListView * parent, QListViewItem * after ); | 154 | OListViewItem( QListView * parent, QListViewItem * after ); |
163 | OListViewItem( QListViewItem * parent, QListViewItem * after ); | 155 | OListViewItem( QListViewItem * parent, QListViewItem * after ); |
164 | 156 | ||
165 | OListViewItem( QListView * parent, | 157 | OListViewItem( QListView * parent, |
166 | QString, QString = QString::null, | 158 | QString, QString = QString::null, |
167 | QString = QString::null, QString = QString::null, | 159 | QString = QString::null, QString = QString::null, |
@@ -180,30 +172,43 @@ class OListViewItem: public QListViewItem | |||
180 | QString = QString::null, QString = QString::null, | 172 | QString = QString::null, QString = QString::null, |
181 | QString = QString::null, QString = QString::null ); | 173 | QString = QString::null, QString = QString::null ); |
182 | 174 | ||
183 | OListViewItem( QListViewItem * parent, QListViewItem * after, | 175 | OListViewItem( QListViewItem * parent, QListViewItem * after, |
184 | QString, QString = QString::null, | 176 | QString, QString = QString::null, |
185 | QString = QString::null, QString = QString::null, | 177 | QString = QString::null, QString = QString::null, |
186 | QString = QString::null, QString = QString::null, | 178 | QString = QString::null, QString = QString::null, |
187 | QString = QString::null, QString = QString::null ); | 179 | QString = QString::null, QString = QString::null ); |
188 | 180 | /** | |
181 | * Destructor. | ||
182 | */ | ||
189 | virtual ~OListViewItem(); | 183 | virtual ~OListViewItem(); |
190 | 184 | /** | |
185 | * @returns the background color of the list item. | ||
186 | */ | ||
191 | const QColor& backgroundColor(); | 187 | const QColor& backgroundColor(); |
188 | /** | ||
189 | * @returns true, if the item is at an odd position and | ||
190 | * thus have to be painted with the alternate background color. | ||
191 | */ | ||
192 | bool isAlternate(); | 192 | bool isAlternate(); |
193 | /** | ||
194 | * @note: Reimplemented for internal purposes - the API is not affected | ||
195 | * | ||
196 | */ | ||
193 | void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); | 197 | void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); |
198 | /** | ||
199 | * Perform object initialization. | ||
200 | */ | ||
194 | void init(); | 201 | void init(); |
195 | |||
196 | /** | 202 | /** |
197 | * create a list view item as child of this object | 203 | * create a list view item as child of this object |
198 | * @return the new object | 204 | * @returns the new object |
199 | */ | 205 | */ |
200 | virtual OListViewItem* childFactory(); | 206 | virtual OListViewItem* childFactory(); |
201 | |||
202 | #ifndef QT_NO_DATASTREAM | 207 | #ifndef QT_NO_DATASTREAM |
203 | /** | 208 | /** |
204 | * serialize this object to or from a @ref QDataStream | 209 | * serialize this object to or from a @ref QDataStream |
205 | * @param s the stream used to serialize this object. | 210 | * @param s the stream used to serialize this object. |
206 | */ | 211 | */ |
207 | virtual void serializeTo( QDataStream& s ) const; | 212 | virtual void serializeTo( QDataStream& s ) const; |
208 | 213 | ||
209 | /** | 214 | /** |
@@ -215,21 +220,91 @@ class OListViewItem: public QListViewItem | |||
215 | 220 | ||
216 | private: | 221 | private: |
217 | bool m_known; | 222 | bool m_known; |
218 | bool m_odd; | 223 | bool m_odd; |
219 | }; | 224 | }; |
220 | 225 | ||
221 | #ifndef QT_NO_DATASTREAM | 226 | #ifndef QT_NO_DATASTREAM |
222 | /** | 227 | /** |
223 | * \relates QListViewItem | 228 | * @relates QListViewItem |
224 | * Writes a listview item and all subitems recursively to the stream | 229 | * Writes listview @a item and all subitems recursively to @a stream |
225 | * and returns a reference to the stream. | 230 | * and returns a reference to the stream. |
226 | */ | 231 | */ |
227 | QDataStream& operator<<( QDataStream &s, const OListViewItem& lvi ); | 232 | QDataStream& operator<<( QDataStream& stream, const OListViewItem& item ); |
228 | /** | 233 | /** |
229 | * \relates QListViewItem | 234 | * @relates QListViewItem |
230 | * Reads a listview item from the stream and returns a reference to the stream. | 235 | * Reads listview @a item from @a stream and returns a reference to the stream. |
231 | */ | 236 | */ |
232 | QDataStream& operator>>( QDataStream &s, OListViewItem& lvi ); | 237 | QDataStream& operator>>( QDataStream& stream, OListViewItem& item ); |
233 | #endif // QT_NO_DATASTREAM | 238 | #endif // QT_NO_DATASTREAM |
234 | 239 | ||
240 | /*====================================================================================== | ||
241 | * ONamedListView | ||
242 | *======================================================================================*/ | ||
243 | |||
244 | /** | ||
245 | * @brief An OListView variant with named columns. | ||
246 | * | ||
247 | * This class provides a higher-level interface to the columns in an OListView. | ||
248 | * | ||
249 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | ||
250 | */ | ||
251 | class ONamedListView: public OListView | ||
252 | { | ||
253 | public: | ||
254 | /** | ||
255 | * Constructor. | ||
256 | * | ||
257 | * The parameters @a parent and @a name are handled by | ||
258 | * @ref OListView, as usual. | ||
259 | */ | ||
260 | ONamedListView( QWidget* parent = 0, const char* name = 0 ); | ||
261 | /** | ||
262 | * Destructor. | ||
263 | */ | ||
264 | virtual ~ONamedListView(); | ||
265 | /** | ||
266 | * Add a number of @a columns to the listview. | ||
267 | */ | ||
268 | virtual void addColumns( const QStringList& columns ); | ||
269 | }; | ||
270 | |||
271 | /*====================================================================================== | ||
272 | * ONamedListViewItem | ||
273 | *======================================================================================*/ | ||
274 | |||
275 | /** | ||
276 | * @brief An OListView variant with named columns. | ||
277 | * | ||
278 | * This class provides a higher-level interface to the columns in an OListViewItem. | ||
279 | * | ||
280 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | ||
281 | */ | ||
282 | class ONamedListViewItem: public OListViewItem | ||
283 | { | ||
284 | public: | ||
285 | /** | ||
286 | * Constructor. Accepts the same parameters as a @ref OListViewItem, | ||
287 | * plus a @ref QStringList which holds an arbitrary number of @a texts. | ||
288 | */ | ||
289 | ONamedListViewItem( QListView* parent, const QStringList& texts ); | ||
290 | ONamedListViewItem( QListViewItem* parent, const QStringList& texts ); | ||
291 | ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ); | ||
292 | ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ); | ||
293 | /** | ||
294 | * Destructor. | ||
295 | */ | ||
296 | virtual ~ONamedListViewItem(); | ||
297 | /** | ||
298 | * Sets the text in column @a column to @a text. | ||
299 | * This method differs from @ref QListViewItem::setText() in that it | ||
300 | * accepts a string as column indicator instead of an int. | ||
301 | */ | ||
302 | virtual void setText( const QString& column, const QString& text ); | ||
303 | /** | ||
304 | * Sets a number of @a texts for this item. | ||
305 | */ | ||
306 | virtual void setText( const QStringList& texts ); | ||
307 | }; | ||
308 | |||
309 | |||
235 | #endif // OLISTVIEW_H | 310 | #endif // OLISTVIEW_H |