Warning, /maui/pix/src/widgets/views/Viewer/Viewer.qml is written in an unsupported language. File is not indexed.

0001 // Copyright 2018-2020 Camilo Higuita <milo.h@aol.com>
0002 // Copyright 2018-2020 Nitrux Latinoamericana S.C.
0003 //
0004 // SPDX-License-Identifier: GPL-3.0-or-later
0005 
0006 import QtQuick 2.14
0007 import QtQml 2.14
0008 import QtQuick.Controls 2.14
0009 
0010 import org.mauikit.controls 1.3 as Maui
0011 import org.mauikit.imagetools 1.0 as IT
0012 
0013 import org.maui.pix 1.0
0014 
0015 import "../../"
0016 
0017 Item
0018 {
0019     id: control
0020 
0021     property bool autoSaveTransformation : false
0022     property real picContrast : 0
0023     property real picBrightness : 0
0024     property real picSaturation : 0
0025     property real picHue : 0
0026     property real picLightness : 0
0027     property alias model : viewerList.model
0028 
0029     property alias count : viewerList.count
0030     property alias currentIndex : viewerList.currentIndex
0031     property alias currentItem: viewerList.currentItem
0032 
0033     clip: false
0034     focus: true
0035 
0036     function forceActiveFocus()
0037     {
0038         viewerList.forceActiveFocus()
0039     }
0040 
0041     ListView
0042     {
0043         id: viewerList
0044         height: parent.height
0045         width: parent.width
0046         orientation: ListView.Horizontal
0047 
0048         Binding on currentIndex
0049         {
0050             value: currentPicIndex
0051             restoreMode: Binding.RestoreBindingOrValue
0052         }
0053 
0054         focus: true
0055         interactive: Maui.Handy.isTouch
0056         cacheBuffer: width * 3
0057 
0058         snapMode: ListView.SnapOneItem
0059         boundsBehavior: Flickable.StopAtBounds
0060 
0061         preferredHighlightBegin: 0
0062         preferredHighlightEnd: width
0063 
0064         highlightRangeMode: ListView.StrictlyEnforceRange
0065         highlightMoveDuration: 0
0066         highlightFollowsCurrentItem: true
0067         highlightResizeDuration: 0
0068         highlightMoveVelocity: -1
0069         highlightResizeVelocity: -1
0070 
0071         maximumFlickVelocity: 4 * (viewerList.orientation === Qt.Horizontal ? width : height)
0072 
0073         Keys.onPressed: (event) =>
0074                         {
0075                             if((event.key == Qt.Key_Right))
0076                             {
0077                                 next()
0078                             }
0079 
0080                             if((event.key == Qt.Key_Left))
0081                             {
0082                                 previous()
0083                             }
0084                         }
0085 
0086         onCurrentIndexChanged: viewerList.forceActiveFocus()
0087 
0088         onMovementEnded:
0089         {
0090             const index = indexAt(contentX, contentY)
0091             if(index !== currentPicIndex)
0092                 view(index)
0093         }
0094 
0095         delegate: Loader
0096         {
0097             height: ListView.view.height
0098             width: ListView.view.width
0099             //            active : ListView.isCurrentItem
0100             asynchronous: true
0101 
0102             sourceComponent: model.format === "gif" || model.format === "avif" ? _animatedImgComponent : _imgComponent
0103 
0104             Component
0105             {
0106                 id: _animatedImgComponent
0107                 Maui.AnimatedImageViewer
0108                 {
0109                     source: model.url
0110                 }
0111             }
0112 
0113             Component
0114             {
0115                 id: _imgComponent
0116                 IT.ImageViewer
0117                 {
0118                     id: _imgV
0119                     source: model.url
0120                     image.autoTransform: true}
0121             }
0122         }
0123     }
0124 
0125     MouseArea
0126     {
0127         enabled: viewerSettings.previewBarVisible && galleryRoll.rollList.count > 1
0128         anchors.fill: parent
0129         onPressed: (mouse) =>
0130         {
0131             galleryRollBg.visible = !galleryRollBg.visible
0132             mouse.accepted = false
0133         }
0134         propagateComposedEvents: true
0135         preventStealing: false
0136     }
0137 
0138     Maui.BaseModel
0139     {
0140         id: _defaultModel
0141         list: GalleryList {}
0142     }
0143 
0144     function appendPics(pics)
0145     {
0146         model = _defaultModel
0147 
0148         if(pics.length > 0)
0149             for(var i in pics)
0150                 _defaultModel.list.append(pics[i])
0151 
0152     }
0153 }