Licensing GPLv3
[quicknewsreader] / qml / QuickNewsReader / content / view / NewsDetail.qml
index 049de65..df41a47 100644 (file)
@@ -1,3 +1,21 @@
+/***
+** Copyright (C) 2012 Christophe CHAPUIS <chris.chapuis _at_ gmail _dot_ com>
+**
+** This package is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This package is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this package; if not, write to the Free Software
+** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+**
+***/
 import QtQuick 1.0
 //import QtWebKit 1.0
 
@@ -7,46 +25,74 @@ Item {
 
     function getNewsModelItem(prop)
     {
-        var newsIndex = listSourceModel[window.currentSourceIndex].currentPath[componentDepth-1]
-
-        if( typeof currentSource.listModels[componentDepth-1].get(newsIndex) != "undefined" )
-            if( typeof currentSource.listModels[componentDepth-1].get(newsIndex)[prop] != "undefined" )
-                return currentSource.listModels[componentDepth-1].get(newsIndex)[prop]
+        if( typeof currentSource.listModels[componentDepth-1] != "undefined" )
+            if( typeof currentSource.listModels[componentDepth-1][prop] != "undefined" )
+                return currentSource.listModels[componentDepth-1][prop]
 
         return ""
     }
 
-    property string urllink: getNewsModelItem('link')
-    property string htmlcontent: getNewsModelItem('detailedContent')
+    property string urllink: getNewsModelItem('urllink')
+    property string htmlcontent: getNewsModelItem('htmlcontent')
     property string title: getNewsModelItem('title')
     property string image: getNewsModelItem('image')
 
     VisualItemModel {
         id: itemModel
 
-        Column {
-            id: column
-            x: 10; y: 10
-            width: newsDetailRect.width - 20
+        Item {
+            x: 0; y: 0
+            width: newsDetailRect.width
+            height: column.height + 10
+
+            Column {
+                id: column
+                x: 10; y: 10
+                width: parent.width - 20
+
+                Row {
+                    spacing: 5
 
-            Row {
-                spacing: 5
+                    Image {
+                        id: detailImage
+                        source: image
+                    }
 
-                Image {
-                    id: detailImage
-                    source: image
+                    Text {
+                        anchors.verticalCenter: detailImage.verticalCenter
+                        text: title; width: column.width - detailImage.width - 10; wrapMode: Text.WordWrap
+                        font { bold: true; family: "Helvetica"; pointSize: 16 }
+                    }
                 }
 
                 Text {
-                    text: title; width: column.width - detailImage.width - 10; wrapMode: Text.WordWrap
-                    font { bold: true; family: "Helvetica"; pointSize: 16 }
+                    id: detailText
+                    text: htmlcontent; width: newsDetailRect.width - 20; wrapMode: Text.WordWrap
+                    horizontalAlignment: Text.AlignJustify;
+                    font.family: "Helvetica"
                 }
             }
 
-            Text {
-                id: detailText
-                text: htmlcontent; width: newsDetailRect.width - 20; wrapMode: Text.WordWrap
-                font.family: "Helvetica"
+            MouseArea {
+                anchors.fill: column
+
+                onClicked: {
+                    var currentSourceDepth = currentSource.listModels[componentDepth-1].sourceDepth
+
+                    if (listSourceModel[window.currentSourceIndex].listViews.length >= currentSourceDepth+1)
+                    {
+                        // here we remove everything in viewsModel after index "currentSourceDepth"
+                        while(window.windowViewsModel.count>currentSourceDepth+1)
+                            window.windowViewsModel.remove(window.windowViewsModel.count-1)
+
+                        var path = listSourceModel[window.currentSourceIndex].currentPath
+                        path[currentSourceDepth] = index
+                        listSourceModel[window.currentSourceIndex].currentPath = path.slice(0,currentSourceDepth+1)
+
+                        window.windowViewsModel.append({ component: listSourceModel[window.currentSourceIndex].listViews[currentSourceDepth].viewComponent,
+                                                         componentDepth: currentSourceDepth+1 })
+                    }
+                }
             }
         }
     }
@@ -56,14 +102,4 @@ Item {
         model: itemModel
     }
     ScrollBar { scrollArea: itemListView; height: itemListView.height; width: 8; anchors.right: itemListView.right }
-/*
-    WebView {
-        id: newsDetailWebView
-        anchors.fill: parent
-        html: htmlcontent
-        url: urllink
-        preferredWidth: window.width
-        preferredHeight: window.height
-    }
-*/
 }