diff options
author | Marius Bugge Monsen <mmonsen@trolltech.com> | 2009-12-10 14:41:23 +0100 |
---|---|---|
committer | Marius Bugge Monsen <mmonsen@trolltech.com> | 2009-12-10 14:41:23 +0100 |
commit | 2bcb6403dd2cb5ef4717551f44c9c4135ac17525 (patch) | |
tree | e858bf8814b9c1a14a9007fdf12343decc045854 | |
parent | 7ecb73c5ddf81d04f609462bbe8b9e740b59551a (diff) |
Add nonUniformList example to test list view with non-uniform items.
-rw-r--r-- | examples/examples.pro | 1 | ||||
-rw-r--r-- | examples/listModel/main.cpp | 2 | ||||
-rw-r--r-- | examples/nonUniformList/main.cpp | 66 | ||||
-rw-r--r-- | examples/nonUniformList/nonUniformList.pro | 5 |
4 files changed, 73 insertions, 1 deletions
diff --git a/examples/examples.pro b/examples/examples.pro index f6994f3..b967cd4 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -9,6 +9,7 @@ SUBDIRS = \ treeAdaptor \ gridView \ pathView \ + nonUniformList \ # iconList \ # spreadsheet \ diff --git a/examples/listModel/main.cpp b/examples/listModel/main.cpp index 397dba0..8476c40 100644 --- a/examples/listModel/main.cpp +++ b/examples/listModel/main.cpp @@ -35,7 +35,7 @@ public: { Q_UNUSED(option); Q_UNUSED(widget); - painter->fillRect(0, 0, size().width(), size().height(), Qt::green); + painter->fillRect(rect(), Qt::green); } }; diff --git a/examples/nonUniformList/main.cpp b/examples/nonUniformList/main.cpp new file mode 100644 index 0000000..cce625a --- /dev/null +++ b/examples/nonUniformList/main.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Itemviews NG project on Trolltech Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include <QtGui> +#include <qlistwidgetng.h> +#include <qlistdefaultmodel.h> +#include <qgraphicslistview.h> +#include <qlistcontroller.h> + +class Item : public QtGraphicsListViewItem +{ +public: + Item(int index, QtGraphicsListView *view) + : QtGraphicsListViewItem(index, view) {} + QSizeF sizeHint(Qt::SizeHint which = Qt::PreferredSize, const QSizeF &contraints = QSizeF()) const + { + QSizeF hint = QtGraphicsListViewItem::sizeHint(which, contraints); + if (index() & 9) + hint.setHeight(44); + else if (index() & 5) + hint.setHeight(33); + else if (index() & 3) + hint.setHeight(66); + else + hint.setHeight(qBound(20., hint.height(), 100.)); // #### ??? + qDebug() << "item height" << hint.height() << "index" << index(); + return hint; + } + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) + { + QtGraphicsListViewItem::paint(painter, option, widget); + painter->drawRect(boundingRect().adjusted(0, 0, -1, -1)); + } +}; + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QtListWidgetNG widget; + for (int i = 0; i < 100; ++i) + widget.defaultModel()->appendItem(new QtListDefaultItem(QString("list item %1").arg(i))); + widget.controller()->view()->setItemCreator(new QtGraphicsListViewItemCreator<Item>()); + widget.resize(QSize(240, 320)); + widget.show(); + return app.exec(); +} diff --git a/examples/nonUniformList/nonUniformList.pro b/examples/nonUniformList/nonUniformList.pro new file mode 100644 index 0000000..057387d --- /dev/null +++ b/examples/nonUniformList/nonUniformList.pro @@ -0,0 +1,5 @@ +TEMPLATE = app +TARGET = nonUniformList +include (../examples.pri) + +SOURCES += main.cpp |