Warning, /maui/index-fm/src/widgets/previewer/FilePreviewer.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.14
0002 import QtQuick.Controls 2.14
0003 import QtQuick.Layouts 1.3
0004 
0005 import org.mauikit.controls 1.3 as Maui
0006 
0007 import org.mauikit.filebrowsing 1.3 as FB
0008 
0009 Item
0010 {
0011     id: control
0012 
0013     implicitHeight: 1000
0014     property url currentUrl: ""
0015 
0016     readonly property alias listView : _listView
0017     readonly property alias model : _model
0018     readonly property alias list: _list
0019     property alias currentIndex: _listView.currentIndex
0020 
0021     ListModel { id: infoModel }
0022 
0023     readonly property string title :  _listView.currentItem.title
0024 
0025     property bool isFav : false
0026     property bool isDir : false
0027     property bool showInfo: true
0028 
0029     readonly property bool ready : list.status.code === FB.PathStatus.READY
0030 
0031 
0032     ListView
0033     {
0034         id: _listView
0035         anchors.fill: parent
0036         orientation: ListView.Horizontal
0037         currentIndex: -1
0038         focus: true
0039         spacing: 0
0040 
0041 model: Maui.BaseModel
0042 {
0043     id: _model
0044     list: FB.FMList
0045     {
0046         id: _list
0047 
0048     }
0049 }
0050         interactive: Maui.Handy.hasTransientTouchInput
0051         boundsBehavior: Flickable.StopAtBounds
0052         boundsMovement: Flickable.StopAtBounds
0053 
0054         highlightFollowsCurrentItem: true
0055         highlightMoveDuration: 0
0056         highlightResizeDuration : 0
0057 
0058         snapMode: ListView.SnapOneItem
0059         cacheBuffer: width
0060         keyNavigationEnabled : true
0061         keyNavigationWraps : true
0062         onMovementEnded: currentIndex = indexAt(contentX, contentY)
0063 
0064         delegate: Item
0065         {
0066             id: _delegate
0067 
0068             height: ListView.view.height
0069             width: ListView.view.width
0070 
0071             readonly property bool isCurrentItem : ListView.isCurrentItem
0072 
0073            property url currentUrl: model.path
0074            property var iteminfo : model
0075 
0076            readonly property string title: model.label
0077 
0078             Loader
0079             {
0080                 id: previewLoader
0081                 asynchronous: true
0082                 active: _delegate.isCurrentItem
0083                 visible: !control.showInfo
0084                 anchors.fill: parent
0085                 onActiveChanged: if(active) show(currentUrl)
0086             }
0087 
0088             Loader
0089             {
0090                 anchors.fill: parent
0091                 visible: control.showInfo
0092                 active: _delegate.isCurrentItem
0093                 asynchronous: true
0094 
0095                 sourceComponent: Maui.ScrollColumn
0096                 {
0097                     spacing: Maui.Style.space.huge
0098 
0099                     Item
0100                     {
0101                         Layout.fillWidth: true
0102                         Layout.preferredHeight: 150
0103 
0104                         Maui.IconItem
0105                         {
0106                             height: parent.height * 0.9
0107                             width: height
0108                             anchors.centerIn: parent
0109                             iconSource: iteminfo.icon
0110                             imageSource: iteminfo.thumbnail
0111                             iconSizeHint: Maui.Style.iconSizes.large
0112                         }
0113                     }
0114 
0115                     Maui.SectionGroup
0116                     {
0117                         Layout.fillWidth: true
0118 
0119                         title: i18n("Details")
0120                         description: i18n("File information")
0121                         Repeater
0122                         {
0123                             model: infoModel
0124                             delegate:  Maui.SectionItem
0125                             {
0126                                 visible:  model.value ? true : false
0127                                 Layout.fillWidth: true
0128                                 label1.text: model.key
0129                                 label2.text: model.value
0130                                 label2.wrapMode: Text.Wrap
0131                             }
0132                         }
0133                     }
0134 
0135                     FileProperties
0136                     {
0137                         Layout.fillWidth: true
0138                         Layout.alignment: Qt.AlignCenter
0139                         url: control.currentUrl
0140                         spacing: parent.spacing
0141                     }
0142                 }
0143             }
0144 
0145             function show(path)
0146             {
0147                 console.log("ASKIGN TO PREVIEW FILE <<", path, iteminfo.mime)
0148                 initModel()
0149 
0150                 control.isDir = model.isdir == "true"
0151                 control.currentUrl = path
0152                 control.isFav = FB.Tagging.isFav(control.currentUrl)
0153 
0154                 var source = "DefaultPreview.qml"
0155                 if(FB.FM.checkFileType(FB.FMList.AUDIO, iteminfo.mime))
0156                 {
0157                     source = "AudioPreview.qml"
0158                 }else if(FB.FM.checkFileType(FB.FMList.VIDEO, iteminfo.mime))
0159                 {
0160                     source = "VideoPreview.qml"
0161                 }else if(FB.FM.checkFileType(FB.FMList.TEXT, iteminfo.mime))
0162                 {
0163                     source = "TextPreview.qml"
0164                 }else if(FB.FM.checkFileType(FB.FMList.IMAGE, iteminfo.mime))
0165                 {
0166                     source = "ImagePreview.qml"
0167                 }else if(FB.FM.checkFileType(FB.FMList.DOCUMENT, iteminfo.mime))
0168                 {
0169                     source = "DocumentPreview.qml"
0170                 }else if(FB.FM.checkFileType(FB.FMList.COMPRESSED, iteminfo.mime))
0171                 {
0172                     source = "CompressedPreview.qml"
0173                 }else if(FB.FM.checkFileType(FB.FMList.FONT, iteminfo.mime))
0174                 {
0175                     source = "FontPreviewer.qml"
0176                 }else
0177                 {
0178                     source = "DefaultPreview.qml"
0179                 }
0180 
0181                 console.log("previe mime", iteminfo.mime)
0182                 previewLoader.source = source
0183                 control.showInfo = (source === "DefaultPreview.qml")
0184             }
0185 
0186             function initModel()
0187             {
0188                 infoModel.clear()
0189                 infoModel.append({key: "Name", value: iteminfo.label})
0190                 infoModel.append({key: "Type", value: iteminfo.mime})
0191                 infoModel.append({key: "Date", value: Qt.formatDateTime(new Date(model.date), "d MMM yyyy")})
0192                 infoModel.append({key: "Modified", value: Qt.formatDateTime(new Date(model.modified), "d MMM yyyy")})
0193                 infoModel.append({key: "Last Read", value: Qt.formatDateTime(new Date(model.lastread), "d MMM yyyy")})
0194                 infoModel.append({key: "Owner", value: iteminfo.owner})
0195                 infoModel.append({key: "Group", value: iteminfo.group})
0196                 infoModel.append({key: "Size", value: Maui.Handy.formatSize(iteminfo.size)})
0197                 infoModel.append({key: "Symbolic Link", value: iteminfo.symlink})
0198                 infoModel.append({key: "Path", value: iteminfo.path})
0199                 infoModel.append({key: "Thumbnail", value: iteminfo.thumbnail})
0200                 infoModel.append({key: "Icon Name", value: iteminfo.icon})
0201             }
0202         }
0203     }
0204 
0205    function goPrevious()
0206    {
0207        _listView.decrementCurrentIndex()
0208    }
0209 
0210    function goNext()
0211    {
0212        _listView.incrementCurrentIndex()
0213    }
0214 
0215    function toggleInfo()
0216    {
0217        control.showInfo = !control.showInfo
0218    }
0219 
0220    property int _index
0221 
0222    function setData(model, index)
0223    {
0224        control.list.path = model.list.path
0225        control.list.hidden = model.list.hidden
0226        control.list.onlyDirs = model.list.onlyDirs
0227        control.list.foldersFirst = model.list.foldersFirst
0228        control.list.filters = model.list.filters
0229        control.list.filterType = model.list.filterType
0230        control.list.sortBy = model.list.sortBy
0231        control._index = index
0232 _timer.start()
0233 
0234 }
0235 
0236 Timer
0237 {
0238  id: _timer
0239 interval: 1500
0240 triggeredOnStart : false
0241  onTriggered:
0242  {
0243      control.currentIndex= control._index
0244  }
0245 }
0246 }