X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fqml%2FMarketsTodayWidget.qml;h=7e34ce7d4a2118fa72caaabb30cd910853260457;hb=ffa4589fcca4c9a4fa235d00ba5f5ac5f8f51072;hp=e697b54a87b52212cb9a4aa4f1ad9c905675b19a;hpb=bdb5659b04bfe0b45aa8fbe15cb2d67cd5ac2f48;p=marketstoday diff --git a/src/qml/MarketsTodayWidget.qml b/src/qml/MarketsTodayWidget.qml index e697b54..7e34ce7 100644 --- a/src/qml/MarketsTodayWidget.qml +++ b/src/qml/MarketsTodayWidget.qml @@ -1,5 +1,5 @@ /* -@version: 0.1 +@version: 0.4 @author: Sudheer K. @license: GNU General Public License */ @@ -9,30 +9,39 @@ import Qt 4.7 import "Library" as Library import "Library/js/ISODate.js" as DateLib import "Library/js/DBUtility.js" as DBUtility +import "Library/js/CSVUtility.js" as CSVUtility import "Library/js/Common.js" as Common import "Library/js/CoreLogic.js" as CoreLib Item { - id: screen + id: mainPage signal showConfigInNewWindow + signal showStockDetails(string strSymbol) signal quoteRefreshStarted - signal quoteRefreshCompleted + signal quoteRefreshCompleted(bool success, string strMessage) + signal newsReloadCompleted(bool success, string strMessage) signal checkNetworkStatus property int itemHeight: 50 - property int componentWidth: screen.width + property int titleBarHeight: 60 + property int toolBarHeight: 40 + property int componentWidth: mainPage.width property int autoUpdateInterval: 300000 property bool updateWeekDaysOnly: false property bool updateOnSavedNetworksOnly: false + property bool isDesktopWidget: true + property string rssURL: "http://finance.yahoo.com/rss/topfinstories" property string lastUpdatedTimeStamp - property bool isDesktopWidget + property string selectedSymbol:"" - function reloadQuotes(){ + function reloadData(){ CoreLib.reloadQuotes(); + CoreLib.reloadNews(); } function initialize(){ + DBUtility.initialize(); CoreLib.initialize(); } @@ -48,13 +57,13 @@ Item { onTriggered: { if (!updateWeekDaysOnly){ logUtility.logMessage("Allowed to update all days of the week"); - //reloadQuotes(); - checkNetworkStatus(); + mainPage.reloadData(); + //checkNetworkStatus(); } else if (Common.isTodayAWeekDay()){ logUtility.logMessage("Today is a weekday"); - //reloadQuotes(); - checkNetworkStatus(); + mainPage.reloadData(); + //checkNetworkStatus(); } else{ logUtility.logMessage("Update not triggered: Today is not a weekday"); @@ -66,135 +75,361 @@ Item { id: stockQuoteDataModel } + ListModel { + id: newsDataModel + } + Rectangle { id: background anchors.fill: parent; color: "#343434" clip: true + Component.onCompleted: { + console.log("Rectangle Height = "+background.height); + } + Component { id: stockQuotesDelegate Item { - id: wrapper; width: componentWidth; height: itemHeight + id: wrapper; width: parent.width; height: itemHeight Item { - Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: wrapper.height - 2; width: wrapper.width; y: 1 } + anchors.fill: parent + Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: wrapper.height - 2; width: wrapper.width; y: 1 + Image{ + id: informationIcon + width: 32 + height: 32 + z: 10 + anchors {right: parent.right; rightMargin: 10; verticalCenter: parent.verticalCenter} + visible: false + source: "Library/images/information.png" + MouseArea{ + anchors.fill: parent; + onPressed: { + logUtility.logMessage("Image clicked"); + showStockDetails(symbol); + } + } + } + + MouseArea { + anchors.fill: parent + onPressed:{ + informationIcon.visible = true; + //console.log("Rectangle clicked"); + } + } + } Row { - x: 30;y: 15; - width: componentWidth - 40; + y: 15;//x: 30; + anchors {left: parent.left;leftMargin: 10;right: parent.right;rightMargin: 10} + //width: componentWidth; + height: parent.height spacing: 5 - Text { text: if (width >= 250) {stockName;} else {symbol;} width: parent.width * 35/100; font.pixelSize: 18; font.bold: true; elide: Text.ElideRight; color: "white"; style: Text.Raised; styleColor: "black" } - Text { text: lastTradedPrice; width: parent.width * 25/100; font.pixelSize: 18; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" } - Text { text: change; width: parent.width * 20/100; font.pixelSize: 18; elide: Text.ElideRight - color: if(change >= 0){"green";} else {"red";} - style: Text.Raised; styleColor: "black" } - Text { text: changePercentage; width: parent.width * 20/100; font.pixelSize: 18; elide: Text.ElideRight; - color: if(change >= 0){"green";} else {"red";} - style: Text.Raised; styleColor: "black" } + Text { text: symbol; width: parent.width * 25/100; font.pixelSize: 18; font.bold: true; verticalAlignment:Text.AlignVCenter; elide: Text.ElideRight; color: "white"; style: Text.Raised; styleColor: "black" } + Text { text: lastTradedPrice; width: parent.width * 25/100; font.pixelSize: 18; verticalAlignment:Text.AlignVCenter; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" } + Column { + y: -15; + width: parent.width * 20/100; height: parent.height + spacing: 2 + Text { text: change; font.pixelSize: 16; elide: Text.ElideRight + color: if(change >= 0){"green";} else {"red";} + style: Text.Raised; styleColor: "black" } + Text { text: changePercentage; font.pixelSize: 16; elide: Text.ElideRight; + color: if(change >= 0){"green";} else {"red";} + style: Text.Raised; styleColor: "black" } + } + Text { text: volume; width: parent.width * 30/100; font.pixelSize: 18; verticalAlignment:Text.AlignVCenter; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" } } } } } - Library.TitleBar { - id: titleBar; - width: parent.width; height: 60; - anchors.top: parent.top - title: "Markets Today"; - buttonType: ""; - } + Component { + id: newsDelegate - Rectangle{ - id: pathViewWrapper - width: parent.width - anchors.top: titleBar.bottom - anchors.bottom: footerText.top - color: "#343434" - - PathView { - id: stockQuotesView - anchors.fill: parent - flickDeceleration: 500 - //preferredHighlightBegin: 1/stockQuotesView.count - //preferredHighlightEnd: 1/stockQuotesView.count - //pathItemCount: count - focus: true - interactive: true - model: stockQuoteDataModel - delegate: stockQuotesDelegate - path: Path { - startX: width / 2 - startY: itemHeight/2 - PathLine { - x: width / 2 - y: stockQuotesView.count * itemHeight + itemHeight/2 + Item { + id: newsWrapper; width: componentWidth; height: itemHeight + Item { + anchors.fill: parent + Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: newsWrapper.height - 2; width: newsWrapper.width; y: 1 } + Text { + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.right: parent.right + text: title; font.pixelSize: 14 + font.bold: false; + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignLeft + elide: Text.ElideRight; + color: "white"; + style: Text.Raised; + styleColor: "black" } - } - Keys.onDownPressed: if (!moving && interactive) incrementCurrentIndex() - Keys.onUpPressed: if (!moving && interactive) decrementCurrentIndex() - - Connections { - target: screen - onQuoteRefreshCompleted:{ - stockQuotesView.currentIndex = 0; + MouseArea{ + anchors.fill: parent + onClicked: Qt.openUrlExternally(link); } } + } + } - Connections { - target: toolBar - onDownButtonClicked: { - if (!stockQuotesView.moving && stockQuotesView.interactive) - stockQuotesView.currentIndex = stockQuotesView.currentIndex + 1 - } - onUpButtonClicked: { - if (!stockQuotesView.moving && stockQuotesView.interactive) - stockQuotesView.currentIndex = stockQuotesView.currentIndex - 1 - } - } + Library.TitleBar { + id: titleBar + width: parent.width; height: mainPage.titleBarHeight + anchors.top: parent.top + title: "Markets Today" + buttonType: "" + displayMenuIcon: false + + onBackClicked: { + uiLoader.sourceComponent = stockQuotesUIComponent; + titleBar.buttonType = ""; + titleBar.displayMenu = false; + toolBar.displayIcons = true; } } - Rectangle{ - id: footerText + Loader { + id: uiLoader width: parent.width - height: 25 - color: "#343434" + anchors.top: titleBar.bottom anchors.bottom: toolBar.top - Text { - id: timeStamp - anchors.fill: parent - text: screen.lastUpdatedTimeStamp - horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter - width: parent.width; font.pixelSize: 12; elide: Text.ElideRight; - color: "#cccccc" - style: Text.Raised; styleColor: "black" - - Connections { - target: screen - onQuoteRefreshCompleted:{ - timeStamp.text = screen.lastUpdatedTimeStamp; - } - } - } + sourceComponent: stockQuotesUIComponent } Library.ToolBar { id:toolBar - width: parent.width; height: 40 + width: parent.width; height: mainPage.toolBarHeight anchors.bottom: parent.bottom opacity: 0.9 displayNavigation: true - onReloadButtonClicked: screen.reloadQuotes(); - onNewsButtonClicked: Qt.openUrlExternally("http://finance.yahoo.com"); + onReloadButtonClicked: mainPage.reloadData(); + onNewsButtonClicked: { + uiLoader.sourceComponent = newsComponent; + toolBar.displayIcons = true; + toolBar.targetContentType = "Stocks"; + } + + onStocksButtonClicked: { + uiLoader.sourceComponent = stockQuotesUIComponent; + toolBar.displayIcons = true; + toolBar.targetContentType = "News"; + } + + Connections { - target: screen + target: mainPage onQuoteRefreshStarted:{ if (!toolBar.updatePending) toolBar.updatePending = true; } onQuoteRefreshCompleted:{ toolBar.updatePending = false; - console.log(screen.lastUpdatedTimeStamp); + } + } + } + + Component { + id: stockQuotesUIComponent + Item { + Rectangle{ + id: pathViewWrapper + width: parent.width + anchors.top: parent.top + anchors.bottom: footerText.top + color: "#343434" + + PathView { + id: stockQuotesView + anchors.fill: parent + flickDeceleration: 500 + //preferredHighlightBegin: 1/stockQuotesView.count + //preferredHighlightEnd: 1/stockQuotesView.count + //pathItemCount: count + focus: true + interactive: true + model: stockQuoteDataModel + delegate: stockQuotesDelegate + path: Path { + startX: width / 2 + startY: itemHeight/2 + PathLine { + x: width / 2 + y: stockQuotesView.count * itemHeight + itemHeight/2 + } + } + Keys.onDownPressed: if (!moving && interactive) incrementCurrentIndex() + Keys.onUpPressed: if (!moving && interactive) decrementCurrentIndex() + + Connections { + target: mainPage + onQuoteRefreshCompleted:{ + stockQuotesView.currentIndex = 0; + } + } + + Connections { + target: toolBar + onDownButtonClicked: { + if (!stockQuotesView.moving && stockQuotesView.interactive) + stockQuotesView.currentIndex = stockQuotesView.currentIndex + 1 + } + onUpButtonClicked: { + if (!stockQuotesView.moving && stockQuotesView.interactive) + stockQuotesView.currentIndex = stockQuotesView.currentIndex - 1 + } + } + } + } + + Rectangle { + id: stockStatusMsgArea + height: 100 + color: "#343434" + anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15; + verticalCenter: parent.verticalCenter} + visible: false + + Text { + id: stockStatusText + anchors.fill: parent + text: "Loading quotes.." + horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter + width: parent.width; font.pixelSize: 16; elide: Text.ElideNone; + color: "#cccccc" + wrapMode: Text.WrapAtWordBoundaryOrAnywhere + style: Text.Raised; styleColor: "black" + + Connections { + target: mainPage + onQuoteRefreshCompleted: { + if (success){ + stockStatusMsgArea.visible = false; + pathViewWrapper.visible = true; + } + else{ + stockStatusText.text = strMessage; + pathViewWrapper.visible = false; + stockStatusMsgArea.visible = true; + } + } + } + } + } + + Rectangle{ + id: footerText + width: parent.width + height: 25 + color: "#343434" + anchors.bottom: parent.bottom + Text { + id: timeStamp + anchors.fill: parent + text: mainPage.lastUpdatedTimeStamp + horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter + width: parent.width; font.pixelSize: 12; elide: Text.ElideRight; + color: "#cccccc" + style: Text.Raised; styleColor: "black" + + Connections { + target: mainPage + onQuoteRefreshCompleted:{ + timeStamp.text = mainPage.lastUpdatedTimeStamp; + } + } + } + } + } + } + + Component { + id: newsComponent + Item { + Rectangle{ + id: newsViewArea + width: parent.width + anchors.top: parent.top + anchors.bottom: parent.bottom + color: "#343434" + + PathView { + id: newsView + anchors.fill: parent + flickDeceleration: 500 + focus: true + interactive: true + model: newsDataModel + delegate: newsDelegate + path: Path { + startX: width / 2 + startY: itemHeight/2 + PathLine { + x: width / 2 + y: newsView.count * itemHeight + itemHeight/2 + } + } + Keys.onDownPressed: if (!moving && interactive) incrementCurrentIndex() + Keys.onUpPressed: if (!moving && interactive) decrementCurrentIndex() + + Connections { + target: mainPage + onQuoteRefreshCompleted:{ + newsView.currentIndex = 0; + } + } + + Connections { + target: toolBar + onDownButtonClicked: { + if (!newsView.moving && newsView.interactive) + newsView.currentIndex = newsView.currentIndex + 1 + } + onUpButtonClicked: { + if (!newsView.moving && newsView.interactive) + newsView.currentIndex = newsView.currentIndex - 1 + } + } + } + } + + Rectangle { + id: newsStatusMsgArea + height: 100 + color: "#343434" + anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15; + verticalCenter: parent.verticalCenter} + visible: false + + Text { + id: newsStatusText + anchors.fill: parent + text: "Loading news.." + horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter + width: parent.width; font.pixelSize: 16; elide: Text.ElideNone; + color: "#cccccc" + wrapMode: Text.WrapAtWordBoundaryOrAnywhere + style: Text.Raised; styleColor: "black" + + Connections { + target: mainPage + onNewsReloadCompleted: { + if (success){ + newsStatusMsgArea.visible = false; + newsViewArea.visible = true; + } + else{ + newsStatusText.text = strMessage; + newsViewArea.visible = false; + newsStatusMsgArea.visible = true; + } + } + } + } } } }