-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhotoView.qml
133 lines (109 loc) · 4.13 KB
/
PhotoView.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import QtQuick 2.7
import QtQuick.Controls 1.4
Item {
anchors.fill: parent
CenteredGridView {
id: photoView
objectName: 'photoView'
clip: true
anchors.top: parent.top
anchors.left: parent.left
anchors.bottom: slider.top
anchors.right: parent.right
anchors.leftMargin: 20
anchors.rightMargin: 20
anchors.topMargin: 20
property int tagTextHeight: 20
idealCellHeight: slider.value + tagTextHeight/2
idealCellWidth: slider.value - tagTextHeight/2
focus: visible
signal tagClicked(string tag)
model: photoListModel
Connections {
target: photoListModel
onFilterChanged: photoView.currentIndex = -1
}
Binding {
target: photoView
property: "currentIndex"
value: stack.viewIndex
}
onCurrentIndexChanged: stack.viewIndex = currentIndex
delegate: Item {
// The delegate size is equal to the cell size
height: GridView.view.cellHeight
width: GridView.view.cellWidth
Item {
// The visible part is not. The height is as mentioned above,
// But the width is here set to the ideal width.
anchors.centerIn: parent
width: parent.GridView.view.idealCellWidth - 20
height: parent.height - photoView.tagTextHeight
BorderedImage {
id: img
asynchronous: true
fillMode: Image.PreserveAspectFit
width: parent.width
height: parent.height - 20
// This makes the image provider get a proper requestedSize
sourceSize.width: width
sourceSize.height: height
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
source: "image://thumbnails/" + thumbnail
borderWidth: 1
borderColor: "white"
rating: model.rating
}
Text {
function formatTagsList(strings, hovered) {
var linkformat = "<a href=\"%1\">%1</a>";
var hoveredlinkformat = "<a href=\"%1\"><b>%1</b></a>";
for(var i = 0; i < strings.length; i++) {
if (strings[i] === hovered)
strings[i] = hoveredlinkformat.arg(strings[i]);
else
strings[i] = linkformat.arg(strings[i]);
}
return strings.join(", ");
}
height: photoView.tagTextHeight
verticalAlignment: Text.AlignBottom
anchors.bottom: parent.bottom
color: "white"
linkColor: "white"
text: formatTagsList(shotwin.getTagsForPhoto(id), hoveredLink)
onLinkActivated: {
photoView.tagClicked(link)
stack.currentIndex = 0
}
}
MouseArea {
anchors.fill: img
hoverEnabled: true
onContainsMouseChanged: img.hovered = containsMouse
onClicked: photoView.currentIndex = index
onDoubleClicked: stack.currentIndex = 2
}
}
Keys.onReturnPressed: stack.currentIndex = 2
}
highlight: Item {
Rectangle {
anchors.centerIn: parent
width: photoView.idealCellWidth
height: photoView.idealCellHeight
color: Qt.lighter(container.color)
}
}
highlightFollowsCurrentItem: true
}
Slider {
id: slider
value: 200
minimumValue: 50
maximumValue: 300
anchors.bottom: parent.bottom
anchors.right: parent.right
}
}