~ubuntu-branches/ubuntu/vivid/qtdeclarative-opensource-src-gles/vivid

« back to all changes in this revision

Viewing changes to examples/quick/demos/rssnews/content/NewsDelegate.qml

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2014-10-29 07:54:05 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20141029075405-gq1uzomnw3but9g2
Tags: 5.3.2-0ubuntu1
Sync package with qtdeclarative-opensource-src - 5.3.2-3ubuntu1 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/****************************************************************************
2
2
**
3
 
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
 
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4
4
** Contact: http://www.qt-project.org/legal
5
5
**
6
 
** This file is part of the QtQml module of the Qt Toolkit.
7
 
**
8
 
** $QT_BEGIN_LICENSE:LGPL$
9
 
** Commercial License Usage
10
 
** Licensees holding valid commercial Qt licenses may use this file in
11
 
** accordance with the commercial license agreement provided with the
12
 
** Software or, alternatively, in accordance with the terms contained in
13
 
** a written agreement between you and Digia.  For licensing terms and
14
 
** conditions see http://qt.digia.com/licensing.  For further information
15
 
** use the contact form at http://qt.digia.com/contact-us.
16
 
**
17
 
** GNU Lesser General Public License Usage
18
 
** Alternatively, this file may be used under the terms of the GNU Lesser
19
 
** General Public License version 2.1 as published by the Free Software
20
 
** Foundation and appearing in the file LICENSE.LGPL included in the
21
 
** packaging of this file.  Please review the following information to
22
 
** ensure the GNU Lesser General Public License version 2.1 requirements
23
 
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
 
**
25
 
** In addition, as a special exception, Digia gives you certain additional
26
 
** rights.  These rights are described in the Digia Qt LGPL Exception
27
 
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28
 
**
29
 
** GNU General Public License Usage
30
 
** Alternatively, this file may be used under the terms of the GNU
31
 
** General Public License version 3.0 as published by the Free Software
32
 
** Foundation and appearing in the file LICENSE.GPL included in the
33
 
** packaging of this file.  Please review the following information to
34
 
** ensure the GNU General Public License version 3.0 requirements will be
35
 
** met: http://www.gnu.org/copyleft/gpl.html.
36
 
**
 
6
** This file is part of the examples of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:BSD$
 
9
** You may use this file under the terms of the BSD license as follows:
 
10
**
 
11
** "Redistribution and use in source and binary forms, with or without
 
12
** modification, are permitted provided that the following conditions are
 
13
** met:
 
14
**   * Redistributions of source code must retain the above copyright
 
15
**     notice, this list of conditions and the following disclaimer.
 
16
**   * Redistributions in binary form must reproduce the above copyright
 
17
**     notice, this list of conditions and the following disclaimer in
 
18
**     the documentation and/or other materials provided with the
 
19
**     distribution.
 
20
**   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
 
21
**     of its contributors may be used to endorse or promote products derived
 
22
**     from this software without specific prior written permission.
 
23
**
 
24
**
 
25
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
26
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
27
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
28
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
29
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
30
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
31
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
32
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
33
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
34
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
35
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37
36
**
38
37
** $QT_END_LICENSE$
39
38
**
40
39
****************************************************************************/
41
40
 
42
 
import QtQuick 2.0
 
41
import QtQuick 2.2
43
42
 
44
 
Item {
 
43
Column {
45
44
    id: delegate
46
 
    height: column.height + 40
47
45
    width: delegate.ListView.view.width
48
 
 
49
 
    Column {
50
 
        id: column
51
 
        x: 20; y: 20
52
 
        width: parent.width - 40
 
46
    spacing: 8
 
47
 
 
48
    // Returns a string representing how long ago an event occurred
 
49
    function timeSinceEvent(pubDate) {
 
50
        var result = pubDate;
 
51
 
 
52
        // We need to modify the pubDate read from the RSS feed
 
53
        // so the JavaScript Date object can interpret it
 
54
        var d = pubDate.replace(',','').split(' ');
 
55
        if (d.length != 6)
 
56
            return result;
 
57
 
 
58
        var date = new Date([d[0], d[2], d[1], d[3], d[4], 'GMT' + d[5]].join(' '));
 
59
 
 
60
        if (!isNaN(date.getDate())) {
 
61
            var age = new Date() - date;
 
62
            var minutes = Math.floor(Number(age) / 60000);
 
63
            if (minutes < 1440) {
 
64
                if (minutes < 2)
 
65
                    result = qsTr("Just now");
 
66
                else if (minutes < 60)
 
67
                    result = '' + minutes + ' ' + qsTr("minutes ago")
 
68
                else if (minutes < 120)
 
69
                    result = qsTr("1 hour ago");
 
70
                else
 
71
                    result = '' + Math.floor(minutes/60) + ' ' + qsTr("hours ago");
 
72
            }
 
73
            else {
 
74
                result = date.toDateString();
 
75
            }
 
76
        }
 
77
        return result;
 
78
    }
 
79
 
 
80
    Item { height: 8; width: delegate.width }
 
81
 
 
82
    Row {
 
83
        width: parent.width
 
84
        spacing: 8
 
85
 
 
86
        Column {
 
87
            Item {
 
88
                width: 4
 
89
                height: titleText.font.pixelSize / 4
 
90
            }
 
91
 
 
92
            Image {
 
93
                id: titleImage
 
94
                source: image
 
95
            }
 
96
        }
53
97
 
54
98
        Text {
55
99
            id: titleText
56
 
            text: title; width: parent.width; wrapMode: Text.WordWrap
57
 
            font { bold: true; family: "Helvetica"; pointSize: 16 }
58
 
        }
59
 
 
60
 
        Text {
61
 
            id: descriptionText
62
 
            width: parent.width; text: description
63
 
            wrapMode: Text.WordWrap; font.family: "Helvetica"
64
 
        }
65
 
    }
66
 
 
67
 
    Rectangle {
68
 
        width: parent.width; height: 1; color: "#cccccc"
69
 
        anchors.bottom: parent.bottom
 
100
 
 
101
            text: title
 
102
            width: delegate.width - titleImage.width
 
103
            wrapMode: Text.WordWrap
 
104
            font.pixelSize: 26
 
105
            font.bold: true
 
106
        }
 
107
    }
 
108
 
 
109
    Text {
 
110
        width: delegate.width
 
111
        font.pixelSize: 12
 
112
        textFormat: Text.RichText
 
113
        font.italic: true
 
114
        text: timeSinceEvent(pubDate) + " (<a href=\"" + link + "\">Link</a>)"
 
115
        onLinkActivated: {
 
116
            Qt.openUrlExternally(link)
 
117
        }
 
118
    }
 
119
 
 
120
    Text {
 
121
        id: descriptionText
 
122
 
 
123
        text: description
 
124
        width: parent.width
 
125
        wrapMode: Text.WordWrap
 
126
        font.pixelSize: 14
 
127
        textFormat: Text.StyledText
 
128
        horizontalAlignment: Qt.AlignLeft
70
129
    }
71
130
}