From 43aa3afb8565a68ea22b2dd0074ff33642bbdf30 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 10 Oct 2011 17:15:05 +0200 Subject: [PATCH] WelcomeScreen: Use ListView instead of Repeater for news This reduces number of objects created on startup, and also allows us to simplify the logic a bit. Change-Id: I6c7c2c5e537ff9a1882e133551f89c056cbe4fe5 Reviewed-on: http://codereview.qt-project.org/6359 Sanity-Review: Qt Sanity Bot Reviewed-by: Daniel Molkentin --- .../welcomescreen/widgets/NewsListing.qml | 42 ++++++------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/share/qtcreator/welcomescreen/widgets/NewsListing.qml b/share/qtcreator/welcomescreen/widgets/NewsListing.qml index 864d54457e7..ae41df31afa 100644 --- a/share/qtcreator/welcomescreen/widgets/NewsListing.qml +++ b/share/qtcreator/welcomescreen/widgets/NewsListing.qml @@ -37,40 +37,29 @@ Item { id: root property int currentItem: 0 - property alias model: repeater.model - property alias itemCount: repeater.count + property alias model: view.model + property alias itemCount: view.count Timer { id: nextItemTimer repeat: true interval: 30*1000 - onTriggered: repeater.incrementIndex() + onTriggered: view.incrementCurrentIndex() } Timer { id: modelUpdateTimer repeat: false interval: 1000 - onTriggered: repeater.handleModelUpdate(); + onTriggered: view.handleModelUpdate(); } - Repeater { - id: repeater - function incrementIndex() { - repeater.itemAt(currentItem).active = false - currentItem = (currentItem+1) % repeater.count - repeater.itemAt(currentItem).active = true - } + ListView { + id: view function handleModelUpdate() { nextItemTimer.stop(); - currentItem = 0; - for (var i = 0; i < count; ++i) { - if (i != currentItem) - repeater.itemAt(i).active = false; - else - repeater.itemAt(i).active = true; - } + currentIndex = 0; nextItemTimer.start(); } @@ -78,21 +67,16 @@ Item { modelUpdateTimer.restart(); } - function handleItemRemoved(index, item) { - modelUpdateTimer.restart(); - } - - function handleItemAdded(index, item) { - modelUpdateTimer.restart(); - } - anchors.fill: parent + highlightMoveDuration: 1 // don't show any scrolling + keyNavigationWraps: true // start from 0 again if at end + interactive: false + onModelChanged: handleModelChanged() - onItemAdded: handleItemAdded(index, item) - onItemRemoved: handleItemRemoved(index, item) + delegate: Item { - property bool active: false id: delegateItem + property bool active: ListView.isCurrentItem opacity: 0 height: root.height width: root.width