Add an (experimental) QML view for the grid
Already works better than the C++ version.
This commit is contained in:
parent
b0185c136b
commit
719ef7ecaa
1 changed files with 175 additions and 0 deletions
175
src/qml/danbooruimageview.qml
Normal file
175
src/qml/danbooruimageview.qml
Normal file
|
@ -0,0 +1,175 @@
|
|||
/*
|
||||
* Copyright 2015 Luca Beltrame <lbeltrame@kde.org>
|
||||
*
|
||||
* 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 version 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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
|
||||
|
||||
KRun {
|
||||
id: runner
|
||||
}
|
||||
|
||||
signal downloadRequested(url url)
|
||||
|
||||
FileDialog {
|
||||
id: saveFileDialog
|
||||
title: "Select a file to save to"
|
||||
selectExisting: false
|
||||
nameFilters: [ "Image files (*.jpg *.png *.tiff *.gif)", "All files (*)" ]
|
||||
}
|
||||
|
||||
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
|
||||
hoverEnabled: true
|
||||
onClicked: {
|
||||
grid.currentIndex = index
|
||||
console.log(fileUrl)
|
||||
}
|
||||
|
||||
onEntered: {
|
||||
viewButton.visible = mouseArea.containsMouse ? true: false
|
||||
downloadButton.visible = mouseArea.containsMouse ? true: false
|
||||
}
|
||||
|
||||
onExited: {
|
||||
viewButton.visible = mouseArea.containsMouse ? true: false
|
||||
downloadButton.visible = mouseArea.containsMouse ? true: false
|
||||
}
|
||||
|
||||
Button {
|
||||
id: viewButton
|
||||
iconName: "view-preview"
|
||||
visible: false
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
|
||||
|
||||
|
||||
id: downloadButton
|
||||
iconName: "download"
|
||||
visible: false
|
||||
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: {
|
||||
console.log("AA" + pixItem.paintedHeight)
|
||||
rootObj.downloadRequested(fileUrl)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Text {
|
||||
id: sizeText
|
||||
text: i18n("File size: %1", KCoreAddons.Format.formatByteSize(fileSize))
|
||||
// anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
GridView {
|
||||
id: grid
|
||||
cellWidth: 230
|
||||
cellHeight: 230
|
||||
|
||||
flow: GridView.FlowLeftToRight
|
||||
anchors.fill: parent
|
||||
|
||||
model: danbooruModel
|
||||
delegate: viewDelegate
|
||||
focus: true
|
||||
Component.onCompleted: currentIndex = -1
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue