/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick
import QtQuick.Window
import Qt.labs.folderlistmodel
import Qt.labs.platform
Window {
id: rootvisible: truewidth: 1024; height: 600color: "black"
property inthighestZ: 0
property realdefaultSize: 200
property varcurrentFrame: undefined
property realsurfaceViewportRatio: 1.5FolderDialog {
id: folderDialogtitle: "Choose a folder with some images"folder: picturesLocationonAccepted: folderModel.folder=folder+"/"
}
Flickable {
id: flickanchors.fill: parentcontentWidth: width*surfaceViewportRatiocontentHeight: height*surfaceViewportRatioRepeater {
model: FolderListModel {
id: folderModelobjectName: "folderModel"showDirs: falsenameFilters: imageNameFilters
}
Rectangle {
id: photoFramewidth: image.width* (1+0.10*image.height/image.width)
height: image.height*1.10scale: defaultSize/Math.max(image.sourceSize.width, image.sourceSize.height)
Behavior on scale { NumberAnimation { duration: 200 } }
Behavior on x { NumberAnimation { duration: 200 } }
Behavior on y { NumberAnimation { duration: 200 } }
border.color: "black"border.width: 2smooth: trueantialiasing: trueComponent.onCompleted: {
x=Math.random() *root.width-width/2y=Math.random() *root.height-height/2rotation=Math.random() *13-6
}
Image {
id: imageanchors.centerIn: parentfillMode: Image.PreserveAspectFitsource: folderModel.folder+fileNameantialiasing: true
}
PinchArea {
anchors.fill: parentpinch.target: photoFramepinch.minimumRotation: -360pinch.maximumRotation: 360pinch.minimumScale: 0.1pinch.maximumScale: 10pinch.dragAxis: Pinch.XAndYAxisonPinchStarted: setFrameColor();
property realzRestore: 0onSmartZoom: {
if (pinch.scale>0) {
photoFrame.rotation=0;
photoFrame.scale=Math.min(root.width, root.height) /Math.max(image.sourceSize.width, image.sourceSize.height) *0.85photoFrame.x=flick.contentX+ (flick.width-photoFrame.width) /2photoFrame.y=flick.contentY+ (flick.height-photoFrame.height) /2zRestore=photoFrame.zphotoFrame.z= ++root.highestZ;
} else {
photoFrame.rotation=pinch.previousAnglephotoFrame.scale=pinch.previousScalephotoFrame.x=pinch.previousCenter.x-photoFrame.width/2photoFrame.y=pinch.previousCenter.y-photoFrame.height/2photoFrame.z=zRestore
--root.highestZ
}
}
MouseArea {
id: dragAreahoverEnabled: trueanchors.fill: parentdrag.target: photoFramescrollGestureEnabled: false// 2-finger-flick gesture should pass through to the FlickableonPressed: {
photoFrame.z= ++root.highestZ;
parent.setFrameColor();
}
onEntered: parent.setFrameColor();
onWheel: {
if (wheel.modifiers&Qt.ControlModifier) {
photoFrame.rotation+=wheel.angleDelta.y/120*5;
if (Math.abs(photoFrame.rotation) <4)
photoFrame.rotation=0;
} else {
photoFrame.rotation+=wheel.angleDelta.x/120;
if (Math.abs(photoFrame.rotation) <0.6)
photoFrame.rotation=0;
var scaleBefore = photoFrame.scale;
photoFrame.scale+=photoFrame.scale*wheel.angleDelta.y/120/10;
}
}
}
function setFrameColor() {
if (currentFrame)
currentFrame.border.color="black";
currentFrame=photoFrame;
currentFrame.border.color="red";
}
}
}
}
}
Rectangle {
id: verticalScrollDecoratoranchors.right: parent.rightanchors.margins: 2color: "cyan"border.color: "black"border.width: 1width: 5radius: 2antialiasing: trueheight: flick.height* (flick.height/flick.contentHeight) - (width-anchors.margins) *2y: (flick.contentY-flick.originY) * (flick.height/flick.contentHeight)
NumberAnimation on opacity { id: vfade; to: 0; duration: 500 }
onYChanged: { opacity=1.0; scrollFadeTimer.restart() }
}
Rectangle {
id: horizontalScrollDecoratoranchors.bottom: parent.bottomanchors.margins: 2color: "cyan"border.color: "black"border.width: 1height: 5radius: 2antialiasing: truewidth: flick.width* (flick.width/flick.contentWidth) - (height-anchors.margins) *2x: (flick.contentX-flick.originY) * (flick.width/flick.contentWidth)
NumberAnimation on opacity { id: hfade; to: 0; duration: 500 }
onXChanged: { opacity=1.0; scrollFadeTimer.restart() }
}
Timer { id: scrollFadeTimer; interval: 1000; onTriggered: { hfade.start(); vfade.start() } }
Image {
anchors.top: parent.topanchors.left: parent.leftanchors.margins: 10source: "resources/folder.png"MouseArea {
anchors.fill: parentanchors.margins: -10onClicked: folderDialog.open()
hoverEnabled: trueonPositionChanged: {
tooltip.visible=falsehoverTimer.start()
}
onExited: {
tooltip.visible=falsehoverTimer.stop()
}
Timer {
id: hoverTimerinterval: 1000onTriggered: {
tooltip.x=parent.mouseXtooltip.y=parent.mouseYtooltip.visible=true
}
}
Rectangle {
id: tooltipborder.color: "black"color: "beige"width: tooltipText.implicitWidth+8height: tooltipText.implicitHeight+8visible: falseText {
id: tooltipTextanchors.centerIn: parenttext: "Open an image directory ("+openShortcut.sequenceString+")"
}
}
}
Shortcut {
id: openShortcutsequence: StandardKey.OpenonActivated: folderDialog.open()
}
}
Text {
anchors.bottom: parent.bottomanchors.left: parent.leftanchors.right: parent.rightanchors.margins: 10color: "darkgrey"wrapMode: Text.WordWrapfont.pointSize: 8text: "On a touchscreen: use two fingers to zoom and rotate, one finger to drag\n"+"With a mouse: drag normally, use the vertical wheel to zoom, horizontal wheel to rotate, or hold Ctrl while using the vertical wheel to rotate"
}
Shortcut { sequence: StandardKey.Quit; onActivated: Qt.quit() }
Component.onCompleted: {
if (typeof contextInitialUrl!=='undefined') {
// Launched from C++ with context properties set.imageNameFilters=contextImageNameFilters;
picturesLocation=contextPicturesLocation;
if (contextInitialUrl=="")
folderDialog.open();
elsefolderModel.folder=contextInitialUrl+"/";
} else {
// Launched via QML viewer without context properties set.folderDialog.open();
}
}
property varimageNameFilters : ["*.png", "*.jpg", "*.gif"];
property stringpicturesLocation : "";
}