/* * Copyright 2015 Luca Beltrame * * This file is part of Danbooru Client. * * Danbooru Client is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Danbooru Client 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 General Public License * along with Danbooru Client. If not, see . */ import QtQuick 2.4 import QtQuick.Controls 1.3 import QtQuick.Dialogs 1.2 import org.kde.kquickcontrolsaddons 2.0 import org.kde.kcoreaddons 1.0 as KCoreAddons import org.kde.kio 1.0 import DanbooruClient 1.0 Rectangle { id: rootObj width: 500 height: 500 property bool poolMode: false; KRun { id: runner } signal downloadRequested(url url) signal fileInfo(url name, var tags) Component { // This is just for testing id: highlight Rectangle { width: grid.cellWidth; height: grid.cellHeight color: "lightsteelblue"; radius: 5 } } Component { id: viewDelegate Item { width: grid.cellWidth height: grid.cellHeight Column { id: postElement anchors.fill: parent QPixmapItem { id: pixItem pixmap: thumbPix anchors.horizontalCenter: parent.horizontalCenter smooth: true fillMode: QPixmapItem.PreserveAspectFit height: grid.cellHeight * 0.75 width: grid.cellWidth * 0.9 MouseArea { id: mouseArea anchors.fill: parent height: parent.height width: parent.width hoverEnabled: true onClicked: { grid.currentIndex = index rootObj.fileInfo(fileUrl, tags) } onEntered: { viewButton.opacity = 1 downloadButton.opacity = 1 } onExited: { viewButton.opacity = 0 downloadButton.opacity = 0 } Button { id: viewButton iconName: "view-preview" visible: opacity > 0 opacity: 0 anchors.top: parent.top anchors.left: parent.left anchors.topMargin: (pixItem.height - pixItem.paintedHeight) / 2 anchors.leftMargin: (pixItem.width - pixItem.paintedWidth) / 2 height: pixItem.height * 0.15 width: pixItem.height * 0.15 z: 1 onClicked: { runner.openUrl(fileUrl) } Behavior on opacity { NumberAnimation { duration: 200 } } } Button { id: downloadButton iconName: "download" visible: opacity > 0 opacity: 0 anchors.bottom: parent.bottom anchors.left: parent.left anchors.bottomMargin: (pixItem.height - pixItem.paintedHeight) / 2 anchors.leftMargin: (pixItem.width - pixItem.paintedWidth) / 2 height: pixItem.height * 0.15 width: pixItem.height * 0.15 z: 1 onClicked: { rootObj.downloadRequested(fileUrl) } Behavior on opacity { NumberAnimation { duration: 200 } } } } } Text { id: sizeText text: i18n("File size: %1", KCoreAddons.Format.formatByteSize(fileSize)) } Text { id: resolutionText text: i18n("Resolution: %1 x %2", resolution.width, resolution.height) } Text { id: ratingText text: { if (rating == DanbooruPost.Safe) { return i18n("Rating: %1", "Safe") } else if (rating == DanbooruPost.Questionable) { return i18n("Rating: %1", "Questionable") } else if (rating == DanbooruPost.Explicit) { return i18n("Rating: %1", "Explicit") } } } } } } ScrollView { id: scrollView anchors.fill: parent GridView { id: grid cellWidth: 230 cellHeight: 230 flow: GridView.FlowLeftToRight anchors.fill: parent clip: true highlight: highlight highlightFollowsCurrentItem: true highlightRangeMode: GridView.ApplyRange model: danbooruModel delegate: viewDelegate focus: true Component.onCompleted: { currentIndex = -1; forceActiveFocus()} onAtYEndChanged: { if (grid.atYEnd && danbooruModel.rowCount() > 0 && !rootObj.poolMode && infiniteScroll) { danbooruService.nextPostPage(); } } add: Transition { NumberAnimation { property: "opacity"; from: 0; to: 1; duration: 250} } } } }