当前位置:网站首页>QML picture preview
QML picture preview
2022-07-28 14:10:00 【Jeady5】
preview
Item{
id: img_preview
anchors.fill: parent
property var srcs: []
property int srcIndex: 0
M.View{
anchors.fill: parent
elevation: 1
MouseArea{
anchors.fill: parent
onWheel: {
// if(wheel.angleDelta.y > 0){
// preview_img.scaled += 0.1
// }else{
// preview_img.scaled -= 0.1
// }
}
}
Flickable{
id: flick_img
anchors.fill: parent
contentHeight: preview_img.height + preview_img_funcBar.height
contentWidth: preview_img.width
onContentXChanged: {
if(contentWidth < width){
contentX = preview_img.width / 2 - width / 2
}
}
Image{
id: preview_img
width: flick_img.width
horizontalAlignment: Image.AligdnHCenter
property real scaled: 1
property real widthBak: 0
property real heightBak: 0
onScaledChanged: {
width = widthBak * scaled
height = heightBak * scaled
flick_img.contentX = width / 2 - flick_img.width / 2
if(scaled <= 0)scaled = 0
}
source: img_preview.srcs[img_preview.srcIndex]
fillMode: Image.PreserveAspectFit
onStatusChanged: {
if(status == Image.Ready){
widthBak = width
heightBak = height
}
}
onSourceChanged: {
flick_img.contentY = 0
}
}
}
M.View{
id: preview_img_funcBar
width: parent.width - M.Units.dp(20)
height: M.Units.dp(60)
anchors.bottom: parent.bottom
anchors.bottomMargin: M.Units.dp(20)
anchors.horizontalCenter: parent.horizontalCenter
elevation: 1
radius: M.Units.dp(20)
backgroundColor: "#20ffffff"
Row{
anchors.horizontalCenter: parent.horizontalCenter
height: parent.height
spacing: M.Units.dp(20)
M.View{
width: M.Units.dp(40)
height: width
elevation: 1
radius: width / 2
anchors.verticalCenter: parent.verticalCenter
visible: img_preview.srcs.length>1
M.Icon{
width: parent.width / 2
height: width
anchors.centerIn: parent
source: "icon://av/skip_previous"
enabled: img_preview.srcIndex > 0
}
M.Ink{
anchors.fill: parent
circular: true
onClicked: {
if(img_preview.srcIndex > 0){
img_preview.srcIndex--
}else{
snackbar.info(" Already on the first page ")
}
}
}
}
M.Label{
anchors.verticalCenter: parent.verticalCenter
visible: img_preview.srcs.length > 1
text: "%1/%2".arg(img_preview.srcIndex+1).arg(img_preview.srcs.length)
}
M.View{
width: M.Units.dp(40)
height: width
elevation: 1
radius: width / 2
anchors.verticalCenter: parent.verticalCenter
visible: img_preview.srcs.length > 1
M.Icon{
width: parent.width / 2
height: width
anchors.centerIn: parent
source: "icon://av/skip_next"
enabled: img_preview.srcIndex < img_preview.srcs.length - 1
}
M.Ink{
anchors.fill: parent
circular: true
onClicked: {
if(img_preview.srcIndex < img_preview.srcs.length - 1){
img_preview.srcIndex++
}else{
snackbar.info(" It's the last page ")
}
}
}
}
M.View{
width: M.Units.dp(40)
height: width
elevation: 1
radius: width / 2
anchors.verticalCenter: parent.verticalCenter
M.Icon{
width: parent.width / 2
height: width
anchors.centerIn: parent
source: "icon://action/zoom_out"
}
M.Ink{
anchors.fill: parent
circular: true
onClicked: {
preview_img.scaled -= 0.1
}
}
}
M.View{
width: M.Units.dp(40)
height: width
elevation: 1
radius: width / 2
anchors.verticalCenter: parent.verticalCenter
M.Icon{
width: parent.width / 2
height: width
anchors.centerIn: parent
source: "icon://action/youtube_searched_for"
}
M.Ink{
anchors.fill: parent
circular: true
onClicked: {
preview_img.scaled = 1
}
}
}
M.View{
width: M.Units.dp(40)
height: width
elevation: 1
radius: width / 2
anchors.verticalCenter: parent.verticalCenter
M.Icon{
width: parent.width / 2
height: width
anchors.centerIn: parent
source: "icon://action/zoom_in"
}
M.Ink{
anchors.fill: parent
circular: true
onClicked: {
preview_img.scaled += 0.1
}
}
}
M.View{
width: M.Units.dp(40)
height: width
elevation: 1
radius: width / 2
anchors.verticalCenter: parent.verticalCenter
M.Icon{
width: parent.width / 2
height: width
anchors.centerIn: parent
source: "icon://content/clear"
}
M.Ink{
anchors.fill: parent
circular: true
onClicked: {
img_preview.visible = false
}
onWheel: {
console.log("on wheel ", wheel.angleDelta.y)
if(wheel.angleDelta.y > 0){
preview_img.scaled += 0.1
}else{
preview_img.scaled -= 0.1
}
}
}
}
}
}
}
function previewImage(imgs, idx){
img_preview.srcs = (imgs instanceof Array)? imgs: [imgs]
img_preview.srcIndex = (idx >= 0 && idx < img_preview.srcs.length)? idx: 0
preview_img.scaled = 1
img_preview.visible = true
}
}
边栏推荐
- a标签_文件下载(download属性)
- Verification code brute force cracking test [easy to understand]
- 【LVGL事件(Events)】事件在不同组件上的应用(一)
- 解决uniapp微信小程序canvas不能引入字体的问题
- Rust from introduction to mastery 01 introduction
- Security assurance is based on software life cycle -psp application
- R language ggplot2 visualization: visualize the scatter diagram and add text labels to the data points in the scatter diagram, using geom of ggrep package_ text_ The rep function avoids overlapping da
- Qt5开发从入门到精通——第一篇概述
- redis哨兵机制
- Long closed period private placement products reappearance industry insiders have different views
猜你喜欢

30 day question brushing plan (II)

Socket类关于TCP字符流编程的理解学习

作为一个程序员,如何高效的管理时间?

Chapter 6 support vector machine

每日一题——奖学金

Security assurance is based on software life cycle - networkpolicy application

Read how to deploy highly available k3s with external database

Diablo 4 ps4/ps5 beta has been added to the Playstation database

83. (cesium home) how the cesium example works

LeetCode 0142.环形链表 II
随机推荐
【Try to Hack】HFish蜜罐部署
Rolling update strategy of deployment.
redis哨兵机制
DXF读写:对齐尺寸标注文字居中、上方的位置计算
你真的了解esModule吗
安全保障基于软件全生命周期-Istio的授权机制
正则表达式
DXF读写:标注样式组码中文说明
Intersectionobserver
Algorithm --- different paths (kotlin)
leetcode-深度优先与广度优先遍历
第六章 支持向量机
浅谈WebSocket
Leetcode 105. construct binary tree from preorder and inorder traversal sequence & 106. construct binary tree from inorder and postorder traversal sequence
安全保障基于软件全生命周期-NetworkPolicy应用
走进音视频的世界——FLV视频封装格式
Master several common sorting - Select Sorting
Socket class understanding and learning about TCP character stream programming
leetcode(442)数组中重复的数据
Deploy application delivery services in kubernetes (Part 1)