PixGrid.qml 7.35 KB
Newer Older
Camilo Higuita's avatar
Camilo Higuita committed
1
import QtQuick.Controls 2.2
2
import QtQuick.Layouts 1.3
Camilo Higuita's avatar
Camilo Higuita committed
3
import QtQuick 2.9
4

Camilo Higuita's avatar
Camilo Higuita committed
5
import org.kde.kirigami 2.0 as Kirigami
6
import org.kde.mauikit 1.0 as Maui
7
8
import PixModel 1.0
import GalleryList 1.0
9
10
import FMList 1.0

11
12
import "../widgets/views/Viewer/Viewer.js" as VIEWER
import "../widgets/views/Pix.js" as PIX
13
import "../widgets"
14

Camilo Higuita's avatar
Camilo Higuita committed
15
Maui.Page
Camilo Higuita's avatar
Camilo Higuita committed
16
{
Camilo Higuita's avatar
Camilo Higuita committed
17
18
19
    id: gridPage

    /*props*/
Camilo Higuita's avatar
Camilo Higuita committed
20
    property int itemSize : isMobile ? iconSizes.huge * 1.5 : iconSizes.enormous
21
    property int itemSpacing: isMobile ? space.medium : space.big
22
    property int itemRadius : unit * 6
23
24
    property bool showLabels : Maui.FM.loadSettings("SHOW_LABELS", "GRID", !isMobile) === "true" ? true : false
    property bool fitPreviews : Maui.FM.loadSettings("PREVIEWS_FIT", "GRID", false) === "false" ?  false : true
25

Camilo Higuita's avatar
Camilo Higuita committed
26
    property alias grid: grid
27
    property alias holder: holder
Camilo higuita's avatar
Camilo higuita committed
28
    property alias list : pixList
Camilo higuita's avatar
Camilo higuita committed
29
    property alias model: pixModel
30
    property alias menu : _picMenu
Camilo Higuita's avatar
Camilo Higuita committed
31
32

    /*signals*/
33
    signal picClicked(int index)
Camilo higuita's avatar
Camilo higuita committed
34
35
    floatingBar: true
    footBarOverlap: true
36
    headBar.drawBorder: false
Camilo higuita's avatar
Camilo higuita committed
37

38
    Maui.Holder
39
    {
Camilo higuita's avatar
Camilo higuita committed
40
        id: holder
41
42
43
        visible: grid.count === 0
    }

Camilo higuita's avatar
Camilo higuita committed
44
    Maui.Menu
45
    {
46
        id: gridMenu
47

Camilo higuita's avatar
Camilo higuita committed
48
        Maui.MenuItem
49
        {
50
51
            checkable: true
            checked: fitPreviews
Camilo higuita's avatar
Camilo higuita committed
52
            text: qsTr( "Fit previews")
53
54
55
            onTriggered:
            {
                fitPreviews = !fitPreviews
56
                Maui.FM.saveSettings("PREVIEWS_FIT", fitPreviews, "GRID")
camilo higuita's avatar
camilo higuita committed
57
58
            }
        }
59

Camilo higuita's avatar
Camilo higuita committed
60
        Maui.MenuItem
camilo higuita's avatar
camilo higuita committed
61
        {
62
63
64
            checkable: true
            checked: showLabels
            text: qsTr("Show labels")
camilo higuita's avatar
camilo higuita committed
65
66
67
            onTriggered:
            {
                showLabels = !showLabels
68
                Maui.FM.saveSettings("SHOW_LABELS", showLabels, "GRID")
69
70
            }
        }
71
72
    }

73
74
75
    PixMenu
    {
        id: _picMenu
76
        index: grid.currentIndex
77
78
    }

79
    headBarTitle: grid.count+" "+qsTr("images")
Camilo Higuita's avatar
Camilo Higuita committed
80

Camilo higuita's avatar
Camilo higuita committed
81
82
83
    headBar.rightContent:[
        Maui.ToolButton
        {
Camilo higuita's avatar
Camilo higuita committed
84
            iconName: "item-select"
Camilo higuita's avatar
Camilo higuita committed
85
86
            onClicked: selectionMode = !selectionMode
            iconColor: selectionMode ? highlightColor : textColor
Camilo higuita's avatar
Camilo higuita committed
87

Camilo higuita's avatar
Camilo higuita committed
88
89
        },
        Maui.ToolButton
Camilo higuita's avatar
Camilo higuita committed
90
91
92
        {
            id: menuBtn
            iconName: "overflow-menu"
Camilo higuita's avatar
Camilo higuita committed
93
            onClicked: gridMenu.popup()
Camilo higuita's avatar
Camilo higuita committed
94
        }
Camilo higuita's avatar
Camilo higuita committed
95
    ]
Camilo higuita's avatar
Camilo higuita committed
96

Camilo higuita's avatar
Camilo higuita committed
97
98
99
100
    headBar.leftContent: [
        Maui.ToolButton
        {
            iconName: "view-sort"
101
102
103
104
105
106
107
108
109
110
            onClicked: sortMenu.popup()

            Maui.Menu
            {
                id: sortMenu

                Maui.MenuItem
                {
                    text: qsTr("Title")
                    checkable: true
Camilo higuita's avatar
Camilo higuita committed
111
112
                    checked: pixList.sortBy === GalleryList.TITLE
                    onTriggered: pixList.sortBy = GalleryList.TITLE
113
114
115
116
117
118
                }

                Maui.MenuItem
                {
                    text: qsTr("Add date")
                    checkable: true
Camilo higuita's avatar
Camilo higuita committed
119
120
                    checked: pixList.sortBy === GalleryList.ADDDATE
                    onTriggered: pixList.sortBy = GalleryList.ADDDATE
121
122
123
124
125
126
                }

                Maui.MenuItem
                {
                    text: qsTr("Creation date")
                    checkable: true
Camilo higuita's avatar
Camilo higuita committed
127
128
                    checked: pixList.sortBy === GalleryList.DATE
                    onTriggered: pixList.sortBy = GalleryList.DATE
129
130
                }

Camilo higuita's avatar
Camilo higuita committed
131
132
133
134
135
136
137
138
//                Maui.MenuItem
//                {
//                    text: qsTr("Place")
//                    checkable: true
//                    checked: pixList.sortBy === FMList.PLACE
//                    onTriggered: pixList.sortBy = FMList.PLACE
//                }

139
140
                Maui.MenuItem
                {
Camilo higuita's avatar
Camilo higuita committed
141
                    text: qsTr("Format")
142
                    checkable: true
Camilo higuita's avatar
Camilo higuita committed
143
144
                    checked: pixList.sortBy === GalleryList.FORMAT
                    onTriggered: pixList.sortBy = GalleryList.FORMAT
145
146
147
148
                }

                Maui.MenuItem
                {
Camilo higuita's avatar
Camilo higuita committed
149
                    text: qsTr("Size")
150
                    checkable: true
Camilo higuita's avatar
Camilo higuita committed
151
152
                    checked: pixList.sortBy === GalleryList.SIZE
                    onTriggered: pixList.sortBy = GalleryList.SIZE
153
154
155
156
                }

                Maui.MenuItem
                {
Camilo higuita's avatar
Camilo higuita committed
157
                    text: qsTr("Favorites")
158
                    checkable: true
Camilo higuita's avatar
Camilo higuita committed
159
160
                    checked: pixList.sortBy === GalleryList.FAV
                    onTriggered: pixList.sortBy = GalleryList.FAV
161
162
                }
            }
Camilo higuita's avatar
Camilo higuita committed
163
164
        }
    ]
Camilo higuita's avatar
Camilo higuita committed
165

166
167
    footBar.colorScheme.backgroundColor: accentColor
    footBar.colorScheme.textColor: altColorText
168
    footBar.visible: false
Camilo higuita's avatar
Camilo higuita committed
169
170
171
    footBar.middleContent: [
        Maui.ToolButton
        {
172
            iconName: "zoom-in"
Camilo higuita's avatar
Camilo higuita committed
173
174
175
176
177
            iconColor: altColorText
            onClicked: zoomIn()
        },
        Maui.ToolButton
        {
178
            iconName: "zoom-out"
Camilo higuita's avatar
Camilo higuita committed
179
180
181
182
            iconColor: altColorText
            onClicked: zoomOut()
        }
    ]
Camilo higuita's avatar
Camilo higuita committed
183

184
185
186
    Component
    {
        id: gridDelegate
187

188
        PixPic
Camilo Higuita's avatar
Camilo Higuita committed
189
190
        {
            id: delegate
191
192
            picSize : itemSize
            picRadius : itemRadius
193
            fit: fitPreviews
camilo higuita's avatar
camilo higuita committed
194
            showLabel: gridPage.showLabels
195
196
            height: grid.cellHeight * 0.9
            width: grid.cellWidth * 0.8
197
            showEmblem: selectionMode
198

Camilo Higuita's avatar
Camilo Higuita committed
199
200
201
            Connections
            {
                target: delegate
202
                onClicked:
Camilo Higuita's avatar
Camilo Higuita committed
203
204
                {
                    grid.currentIndex = index
205
                    if(selectionMode)
Camilo higuita's avatar
Camilo higuita committed
206
                        PIX.selectItem(pixList.get(index))
207
                    else if(isMobile)
208
                        openPic(index)
Camilo Higuita's avatar
Camilo Higuita committed
209
                }
210

camilo higuita's avatar
camilo higuita committed
211
212
                onDoubleClicked:
                {
213
                    grid.currentIndex = index
214
215
                    if(!isMobile)
                        openPic(index)
camilo higuita's avatar
camilo higuita committed
216
                }
217

Camilo Higuita's avatar
updates    
Camilo Higuita committed
218
219
220
                onPressAndHold:
                {
                    grid.currentIndex = index
221
                    _picMenu.popup()
Camilo Higuita's avatar
updates    
Camilo Higuita committed
222
                }
camilo higuita's avatar
camilo higuita committed
223

Camilo Higuita's avatar
updates    
Camilo Higuita committed
224
225
226
                onRightClicked:
                {
                    grid.currentIndex = index
227
                    _picMenu.popup()
Camilo Higuita's avatar
updates    
Camilo Higuita committed
228
229
230
231
                }
                onEmblemClicked:
                {
                    grid.currentIndex = index
232
                    var item = pixList.get(index)
233
                    PIX.selectItem(item)
Camilo Higuita's avatar
updates    
Camilo Higuita committed
234
                }
Camilo Higuita's avatar
Camilo Higuita committed
235
236
            }
        }
237
238
    }

Camilo higuita's avatar
Camilo higuita committed
239
240
241
242
243
244
245
246
247
248
249
    PixModel
    {
        id: pixModel
        list: pixList
    }

    GalleryList
    {
        id: pixList
    }

250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
    Maui.GridView
    {
        id: grid
        height: parent.height
        width: parent.width
        adaptContent: true
        itemSize: gridPage.itemSize
        spacing: itemSpacing
        cellWidth: itemSize
        cellHeight: itemSize

        //        highlightMoveDuration: 0
        //        highlightFollowsCurrentItem: true
        //        highlight: Rectangle
        //        {
        //            width: itemSize + itemSpacing
        //            height: itemSize + itemSpacing
        //            color: highlightColor
        //            radius: 4
        //        }

Camilo higuita's avatar
Camilo higuita committed
271
        model: pixModel
272
        delegate: gridDelegate
Camilo Higuita's avatar
Camilo Higuita committed
273
    }
Camilo Higuita's avatar
Camilo Higuita committed
274

275
276
    function openPic(index)
    {
Camilo higuita's avatar
Camilo higuita committed
277
        VIEWER.open(pixList, index)
278
    }
Camilo higuita's avatar
Camilo higuita committed
279
280
281
282

    function zoomIn()
    {
        itemSize = itemSize + 20
Camilo higuita's avatar
Camilo higuita committed
283
        refreshGrid()
Camilo higuita's avatar
Camilo higuita committed
284
285
286
287
288
    }

    function zoomOut()
    {
        itemSize = itemSize - 20
Camilo higuita's avatar
Camilo higuita committed
289
        refreshGrid()
Camilo higuita's avatar
Camilo higuita committed
290
291
292
293
    }

    function refreshGrid()
    {
Camilo higuita's avatar
Camilo higuita committed
294
        grid.adaptGrid()
Camilo higuita's avatar
Camilo higuita committed
295
    }
Camilo Higuita's avatar
Camilo Higuita committed
296
}