From 39f1e4f2dbe9cfe4b642d3b397c1e0718fcf0741 Mon Sep 17 00:00:00 2001 From: con Date: Wed, 29 Jun 2011 18:09:01 +0200 Subject: [PATCH] Show news from the start and cycle through them. Change-Id: I0f783148ea3e42ac4f9728a0f32c0452c041b387 Reviewed-on: http://codereview.qt.nokia.com/942 Reviewed-by: Qt Sanity Bot Reviewed-by: Daniel Molkentin --- .../qtcreator/welcomescreen/welcomescreen.qml | 1 - .../widgets/FeaturedAndNewsListing.qml | 2 +- .../welcomescreen/widgets/NewsListing.qml | 86 ++++++++++++++++--- 3 files changed, 73 insertions(+), 16 deletions(-) diff --git a/share/qtcreator/welcomescreen/welcomescreen.qml b/share/qtcreator/welcomescreen/welcomescreen.qml index 77a33ee8b9c..3383f9c85bc 100644 --- a/share/qtcreator/welcomescreen/welcomescreen.qml +++ b/share/qtcreator/welcomescreen/welcomescreen.qml @@ -58,7 +58,6 @@ Image { anchors.fill: parent anchors.margins: 4 } - } TabWidget { diff --git a/share/qtcreator/welcomescreen/widgets/FeaturedAndNewsListing.qml b/share/qtcreator/welcomescreen/widgets/FeaturedAndNewsListing.qml index f9a37d425b7..d6694c945a5 100644 --- a/share/qtcreator/welcomescreen/widgets/FeaturedAndNewsListing.qml +++ b/share/qtcreator/welcomescreen/widgets/FeaturedAndNewsListing.qml @@ -16,7 +16,7 @@ Item { ListModel { id: tempNewsModel - ListElement { title: "Loading news sources..."; description: "Loading..." ; blogIcon: ""; blogName: ""; link: "" } + ListElement { title: ""; description: "Loading news sources..." ; blogIcon: ""; blogName: ""; link: "" } } NewsListing { diff --git a/share/qtcreator/welcomescreen/widgets/NewsListing.qml b/share/qtcreator/welcomescreen/widgets/NewsListing.qml index a756ef7fc3b..14fa94030ee 100644 --- a/share/qtcreator/welcomescreen/widgets/NewsListing.qml +++ b/share/qtcreator/welcomescreen/widgets/NewsListing.qml @@ -1,4 +1,4 @@ -import Qt 4.7 +import QtQuick 1.1 import "../components/" as Components Item { @@ -15,6 +15,13 @@ Item { onTriggered: repeater.incrementIndex() } + Timer { + id: modelUpdateTimer + repeat: false + interval: 1000 + onTriggered: repeater.handleModelUpdate(); + } + Repeater { id: repeater function incrementIndex() { @@ -23,17 +30,34 @@ Item { repeater.itemAt(currentItem).active = true } + function handleModelUpdate() { + timer.stop(); + currentItem = 0; + for (var i = 0; i < count; ++i) { + if (i != currentItem) + repeater.itemAt(i).active = false; + else + repeater.itemAt(i).active = true; + } + timer.start(); + } + function handleModelChanged() { - if (timer.running) - timer.stop(); - currentItem = 0 - //FIXME: this doesn't work - repeater.itemAt(currentItem).active = true - timer.start() + modelUpdateTimer.restart(); + } + + function handleItemRemoved(index, item) { + modelUpdateTimer.restart(); + } + + function handleItemAdded(index, item) { + modelUpdateTimer.restart(); } anchors.fill: parent onModelChanged: handleModelChanged() + onItemAdded: handleItemAdded(index, item) + onItemRemoved: handleItemRemoved(index, item) delegate: Item { property bool active: false id: delegateItem @@ -44,12 +68,30 @@ Item { spacing: 10 width: parent.width id: column - Text { id: heading1; text: title; font.bold: true; wrapMode: Text.WrapAtWordBoundaryOrAnywhere; textFormat: Text.RichText; width: parent.width-icon.width-5 } + Text { + id: heading1; + text: title; + font.bold: true; + wrapMode: Text.WrapAtWordBoundaryOrAnywhere; + textFormat: Text.RichText; + width: parent.width-icon.width-5 + } Row { spacing: 5 width: parent.width - Image { id: icon; source: blogIcon; asynchronous: true } - Text { id: heading2; text: blogName; font.italic: true; wrapMode: Text.WrapAtWordBoundaryOrAnywhere; textFormat: Text.RichText; width: parent.width-icon.width-5 } + Image { + id: icon; + source: blogIcon; + asynchronous: true + } + Text { + id: heading2; + text: blogName; + font.italic: true; + wrapMode: Text.WrapAtWordBoundaryOrAnywhere; + textFormat: Text.RichText; + width: parent.width-icon.width-5 + } } Text { id: text; @@ -58,16 +100,31 @@ Item { textFormat: Text.RichText width: parent.width-10 } - Text { visible: link !== ""; id: readmore; text: qsTr("Click to read more..."); font.italic: true; wrapMode: Text.WrapAtWordBoundaryOrAnywhere; textFormat: Text.RichText } + Text { visible: link !== ""; + id: readmore; + text: qsTr("Click to read more..."); + font.italic: true; + wrapMode: Text.WrapAtWordBoundaryOrAnywhere; + textFormat: Text.RichText + } + } + Components.QStyleItem { + id: styleItem; + cursor: "pointinghandcursor"; + anchors.fill: column + } + MouseArea { + anchors.fill: column; + onClicked: Qt.openUrlExternally(link); + hoverEnabled: true; + id: mouseArea } - Components.QStyleItem { id: styleItem; cursor: "pointinghandcursor"; anchors.fill: column } - MouseArea { anchors.fill: column; onClicked: Qt.openUrlExternally(link); hoverEnabled: true; id: mouseArea } StateGroup { id: activeState states: [ State { name: "active"; when: delegateItem.active; PropertyChanges { target: delegateItem; opacity: 1 } } ] transitions: [ - Transition { from: ""; to: "active"; reversible: true; NumberAnimation { target: delegateItem; property: "opacity"; duration: 200 } } + Transition { from: ""; to: "active"; reversible: true; NumberAnimation { target: delegateItem; property: "opacity"; duration: 1000 } } ] } @@ -76,6 +133,7 @@ Item { State { name: "hovered"; when: mouseArea.containsMouse; PropertyChanges { target: text; color: "#074C1C" } } ] + } } }