1/*********
2*
3* In the name of the Father, and of the Son, and of the Holy Spirit.
4*
5* This file is part of BibleTime's source code, http://www.bibletime.info/.
6*
7* Copyright 1999-2016 by the BibleTime developers.
8* The BibleTime source code is licensed under the GNU General Public License
9* version 2.0.
10*
11**********/
12
13import QtQuick 2.2
14
15Rectangle {
16    id: top
17
18    property alias model: listView.model
19    property alias currentIndex: listView.currentIndex
20    property real leftTextMargin: 10
21    property bool highlight: true
22
23    signal itemSelected(int index)
24
25    color: btStyle.textBackgroundColor
26
27    ListView {
28        id: listView
29
30        anchors.fill: parent
31        anchors.leftMargin: 3
32        anchors.rightMargin: 3
33        anchors.bottomMargin: 3
34        clip: true
35        highlightFollowsCurrentItem: true
36        currentIndex: 2
37
38        function selectItem(x, y) {
39            var index = listView.indexAt(x+contentX,y+contentY);
40            currentIndex = index;
41            top.itemSelected(index);
42        }
43
44        Rectangle {
45            id: scrollbar
46            anchors.right: listView.right
47            y: listView.visibleArea.yPosition * listView.height
48            width: btStyle.pixelsPerMillimeterX
49            height: listView.visibleArea.heightRatio * listView.height
50            color: btStyle.textColor
51            visible: listView.visibleArea.heightRatio < 0.99
52        }
53
54        delegate: Rectangle {
55            id: entry
56
57            property bool selected: ListView.isCurrentItem ? true : false
58            objectName: "entry"
59
60            color: (highlight && ListView.isCurrentItem) ? btStyle.textBackgroundHighlightColor : btStyle.textBackgroundColor
61            border.width: buttonMouseArea.pressed ? 5 :1
62            border.color: "darkgray"
63            width: parent.width
64            height: {
65                var pixel = btStyle.pixelsPerMillimeterY * 7;
66                var uiFont = btStyle.uiFontPointSize * 3.5;
67                return Math.max(pixel, uiFont);
68            }
69
70            Text {
71                id: entryText
72
73                anchors.fill: parent
74                anchors.leftMargin: leftTextMargin
75                anchors.rightMargin: 10
76                anchors.topMargin: 10
77                verticalAlignment: Text.AlignVCenter
78                text: model.text
79                font.pointSize: btStyle.uiFontPointSize
80                font.bold: highlight && entry.selected
81                color: btStyle.textColor
82            }
83        }
84
85        MouseArea {
86            id: buttonMouseArea
87
88            anchors.fill: listView
89            onPressed: {
90
91            }
92
93            onClicked: itemWasSelected()
94
95            function itemWasSelected() {
96                listView.selectItem(mouseX, mouseY);
97                itemSelected(currentIndex);
98            }
99        }
100    }
101}
102