ReviewDelegate.qml 2.87 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 *   Copyright (C) 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library/Lesser General Public License
 *   version 2, or (at your option) any later version, as published by the
 *   Free Software Foundation
 *
 *   This program 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 Library/Lesser General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

20
import QtQuick 2.1
21
import QtQuick.Layouts 1.1
22
import QtQuick.Controls 2.1
23
import org.kde.discover 2.0
24
import org.kde.kirigami 2.0 as Kirigami
25

26
ColumnLayout
27
28
29
{
    id: item
    visible: model.shouldShow
30
31
    property bool compact: false
    property bool separator: true
32
    signal markUseful(bool useful)
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
33

34
35
36
37
38
39
    function usefulnessToString(favorable, total)
    {
        return total==0
                ? i18n("<em>Tell us about this review!</em>")
                : i18n("<em>%1 out of %2 people found this review useful</em>", favorable, total)
    }
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
40

41
42
    RowLayout {
        Layout.fillWidth: true
43
        Label {
44
            id: content
45
            Layout.fillWidth: true
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
46
            elide: Text.ElideRight
47
48
            readonly property string author: reviewer ? reviewer : i18n("unknown reviewer")
            text: summary ? i18n("<b>%1</b> by %2", summary, author) : i18n("Comment by %1", author)
49
        }
50
51
52
53
        Rating {
            id: rating
            rating: model.rating
            starSize: content.font.pointSize
54
        }
55
56
57
58
    }
    Label {
        Layout.fillWidth: true
        text: display
59
        maximumLineCount: item.compact ? 3 : undefined
60
61
62
        wrapMode: Text.Wrap
    }
    Label {
63
        visible: !item.compact
64
65
        text: usefulnessToString(usefulnessFavorable, usefulnessTotal)
    }
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
66

67
    Label {
68
        visible: !item.compact
69
70
71
72
73
74
75
76
77
78
79
80
        Layout.alignment: Qt.AlignRight
        text: {
            switch(usefulChoice) {
                case ReviewsModel.Yes:
                    i18n("<em>Useful? <a href='true'><b>Yes</b></a>/<a href='false'>No</a></em>")
                    break;
                case ReviewsModel.No:
                    i18n("<em>Useful? <a href='true'>Yes</a>/<a href='false'><b>No</b></a></em>")
                    break;
                default:
                    i18n("<em>Useful? <a href='true'>Yes</a>/<a href='false'>No</a></em>")
                    break;
81
82
            }
        }
83
84
        onLinkActivated: item.markUseful(link=='true')
    }
85
    Kirigami.Separator {
86
        visible: item.separator
87
        Layout.fillWidth: true
88
89
    }
}