Commit 5134a780 authored by camilo higuita's avatar camilo higuita

add document preview support for linux for now and refactor filepreviewer and some other fixes

parent ef385266
......@@ -18,8 +18,10 @@
<file alias="private/AudioPreview.qml">src/controls/private/AudioPreview.qml</file>
<file alias="private/ImagePreview.qml">src/controls/private/ImagePreview.qml</file>
<file alias="private/TextPreview.qml">src/controls/private/TextPreview.qml</file>
<file alias="private/VideoPreview.qml">src/controls/private/VideoPreview.qml</file>
<file alias="private/AccountsHelper.qml">src/controls/private/AccountsHelper.qml</file>
<file alias="private/VideoPreview.qml">src/controls/private/VideoPreview.qml</file>
<file alias="private/DocumentPreview.qml">src/controls/private/DocumentPreview.qml</file>
<file alias="private/DefaultPreview.qml">src/controls/private/DefaultPreview.qml</file>
<file alias="private/AccountsHelper.qml">src/controls/private/AccountsHelper.qml</file>
<file alias="Holder.qml">src/controls/Holder.qml</file>
<file alias="ListDelegate.qml">src/controls/ListDelegate.qml</file>
<file alias="ItemDelegate.qml">src/controls/ItemDelegate.qml</file>
......
......@@ -12,7 +12,7 @@ import "private"
Maui.Page
{
id: control
property url currentPath
onCurrentPathChanged: control.browserView.path = control.currentPath
......@@ -55,8 +55,7 @@ Maui.Page
signal itemRightEmblemClicked(int index)
signal rightClicked()
signal newBookmark(var paths)
signal newTag(var tag)
signal newTag(var tag)
Kirigami.Theme.colorSet: Kirigami.Theme.View
Kirigami.Theme.inherit: false
......@@ -197,7 +196,6 @@ Maui.Page
control.clean()
}
for(var i in urls)
Maui.FM.removeFile(urls[i])
......
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
......@@ -15,7 +14,6 @@ Maui.Dialog
property bool isFav : false
property bool isDir : false
property string mimetype : ""
property bool showInfo: true
property alias infoModel : _infoModel
......@@ -73,7 +71,7 @@ Maui.Dialog
}
]
footBar.rightContent: ToolButton
footBar.rightContent: ToolButton
{
icon.name: "documentinfo"
text: qsTr("Info")
......@@ -82,47 +80,7 @@ Maui.Dialog
checked: control.showInfo
onClicked: control.showInfo = !control.showInfo
}
Component
{
id: defaultPreview
Item
{
anchors.fill: parent
Kirigami.Icon
{
anchors.centerIn: parent
source:control.iteminfo.icon
height: Maui.Style.iconSizes.huge
width: height
}
}
}
Component
{
id: imagePreview
ImagePreview {}
}
Component
{
id: audioPreview
AudioPreview {}
}
Component
{
id: videoPreview
VideoPreview {}
}
Component
{
id: textPreview
TextPreview {}
}
ColumnLayout
{
anchors.fill: parent
......@@ -244,48 +202,82 @@ Maui.Dialog
if(previewLoader.item && previewLoader.item.player != null)
previewLoader.item.player.stop()
previewLoader.sourceComponent = null
previewLoader.source = ""
}
function show(path)
{
control.iteminfo = Maui.FM.getFileInfo(path)
control.initModel()
if(iteminfo.mime.indexOf("/"))
{
control.mimetype = iteminfo.mime.slice(0, iteminfo.mime.indexOf("/"))
}else
{
control.mimetype = ""
}
control.isDir = mimetype === "inode"
control.showInfo = control.mimetype === "audio" || control.mimetype === "image" || control.mimetype === "video" || control.mimetype === "text"? false : true
control.isDir = iteminfo.isdir == "true"
control.currentUrl = path
control.isFav = _tagsBar.list.contains("fav")
var component;
switch(mimetype)
var source;
switch(iteminfo.mime)
{
case "audio" :
component = audioPreview
case "audio/mpeg" :
case "audio/mp4" :
case "audio/flac" :
case "audio/ogg" :
case "audio/wav" :
source = "private/AudioPreview.qml"
break
case "video" :
component = videoPreview
case "video/mp4" :
case "video/x-matroska" :
case "video/webm" :
case "video/avi" :
case "video/flv" :
case "video/mpg" :
case "video/wmv" :
case "video/mov" :
case "video/ogg" :
case "video/mpeg" :
case "video/jpeg" :
source = "private/VideoPreview.qml"
break
case "text" :
component = textPreview
case "text/x-c++src" :
case "text/x-c++hdr" :
case "text/css" :
case "text/html" :
case "text/plain" :
case "text/richtext" :
case "text/scriptlet" :
case "text/x-vcard" :
case "text/x-go" :
case "text/x-cmake" :
case "text/x-qml" :
case "application/xml" :
case "application/javascript" :
case "application/json" :
case "application/pgp-keys" :
case "application/x-shellscript" :
case "application/x-kicad-project" :
source = "private/TextPreview.qml"
break
case "image" :
component = imagePreview
case "image/png" :
case "image/gif" :
case "image/jpeg" :
case "image/web" :
case "image/svg" :
case "image/svg+xml" :
source = "private/ImagePreview.qml"
break
case "inode" :
case "application/pdf":
case "application/rtf":
case "application/doc":
case "application/odf":
source = "private/DocumentPreview.qml"
break
case "inode/directory" :
default:
component = defaultPreview
source = "private/DefaultPreview.qml"
}
previewLoader.sourceComponent = component
console.log("previe mime", iteminfo.mime)
previewLoader.source = source
control.showInfo = source === "private/DefaultPreview.qml"
open()
}
......
......@@ -9,7 +9,9 @@ Flickable
{
id: flick
property alias image: img
property alias image: _imageLoader.item
property bool animated: false
property url source
signal rightClicked();
signal pressAndHold();
......@@ -112,14 +114,13 @@ Flickable
}
}
Image
Loader
{
id: img
id: _imageLoader
width: flick.contentWidth
height: flick.contentHeight
fillMode: Image.PreserveAspectFit
autoTransform: true
asynchronous: true
sourceComponent: control.animated ? _animatedImageComponent : _stillImageComponent
MouseArea
{
......@@ -176,6 +177,33 @@ Flickable
}
}
}
Component
{
id: _animatedImageComponent
AnimatedImage
{
fillMode: Image.PreserveAspectFit
autoTransform: true
asynchronous: true
source: control.source
onStatusChanged: playing = (status == AnimatedImage.Ready)
cache: true
}
}
Component
{
id: _stillImageComponent
Image
{
fillMode: Image.PreserveAspectFit
autoTransform: true
asynchronous: true
source: control.source
}
}
}
function fit()
......
......@@ -15,18 +15,13 @@ Maui.Page
{
anchors.fill: parent
Image
Kirigami.Icon
{
anchors.centerIn: parent
width: Math.min(parent.width, 200)
height: width
source: "qrc:/assets/cover.png"
sourceSize.width: width
sourceSize.height: height
asynchronous: true
source: iteminfo.icon
smooth: true
fillMode: Image.PerseveAspectRatio
cache: true
MediaPlayer
{
......@@ -63,6 +58,11 @@ Maui.Page
}
footBar.rightContent: Label
{
text: Maui.FM.formatTime((player.duration - player.position)/1000)
}
footBar.middleContent : Slider
{
id: _slider
......
......@@ -158,7 +158,7 @@ Maui.Page
keepEmblemOverlay : _listViewBrowser.keepEmblemOverlay
showThumbnails: _listViewBrowser.showPreviewThumbnails
rightEmblem: _listViewBrowser.rightEmblem
isSelected: if(selectionBar !== null) return selectionBar.contains(model.path)
isSelected: selectionBar ? selectionBar.contains(model.path) : false
leftEmblem: isSelected ? "emblem-select-remove" : "emblem-select-add"
draggable: true
......@@ -283,7 +283,7 @@ Maui.Page
keepEmblemOverlay: _gridViewBrowser.keepEmblemOverlay
showThumbnails: _gridViewBrowser.showPreviewThumbnails
rightEmblem: _gridViewBrowser.rightEmblem
isSelected: if(selectionBar) return selectionBar.contains(model.path)
isSelected: selectionBar ? selectionBar.contains(model.path) : false
leftEmblem: isSelected ? "emblem-select-remove" : "emblem-select-add"
draggable: true
......@@ -532,7 +532,7 @@ Maui.Page
keepEmblemOverlay : _millerListView.keepEmblemOverlay
showThumbnails: _millerListView.showPreviewThumbnails
rightEmblem: _millerListView.rightEmblem
isSelected: if(selectionBar) return selectionBar.contains(model.path)
isSelected: selectionBar ? selectionBar.contains(model.path) : false
leftEmblem: isSelected ? "emblem-select-remove" : "emblem-select-add"
draggable: true
......
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import org.kde.kirigami 2.7 as Kirigami
import org.kde.mauikit 1.0 as Maui
Item
{
anchors.fill: parent
Kirigami.Icon
{
anchors.centerIn: parent
source: iteminfo.icon
height: Maui.Style.iconSizes.huge
width: height
}
}
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import org.kde.mauikit 1.0 as Maui
import org.kde.kirigami 2.7 as Kirigami
import org.kde.okular 2.0 as Okular
Maui.Page
{
id: control
property int currentPage;
property int pageCount;
property var pagesModel;
title: documentItem.windowTitleForDocument
footBar.middleContent: [
ToolButton
{
icon.name: "go-previous"
enabled: documentItem.currentPage > 0
onClicked:
{
if(documentItem.currentPage - 1 > -1)
documentItem.currentPage --
}
},
ToolButton
{
icon.name: "go-next"
enabled: documentItem.pageCount > 1 && documentItem.currentPage + 1 < documentItem.pageCount
onClicked:
{
if(documentItem.currentPage +1 < documentItem.pageCount)
documentItem.currentPage ++
}
}
]
Okular.DocumentItem
{
id: documentItem
url : currentUrl
// onWindowTitleForDocumentChanged: {
// fileBrowserRoot.title = windowTitleForDocument
// }
onOpenedChanged: {
if(opened === true) {
// control.loadingCompleted(true);
// initialPageChange.start();
}
}
onCurrentPageChanged: {
if(control.currentPage !== currentPage) {
control.currentPage = currentPage;
}
}
}
ListView
{
id: imageBrowser
anchors.fill: parent;
model: documentItem.matchingPages
clip: true
currentIndex: control.currentPage
property int imageWidth: control.width + Kirigami.Units.largeSpacing
property int imageHeight: control.height
highlightMoveDuration: 0
orientation: ListView.Horizontal
snapMode: ListView.SnapOneItem
// This ensures that the current index is always up to date, which we need to ensure we can track the current page
// as required by the thumbnail navigator, and the resume-reading-from functionality
onMovementEnded:
{
var indexHere = indexAt(contentX + width / 2, contentY + height / 2);
if(currentIndex !== indexHere)
{
currentIndex = indexHere;
}
}
delegate: Flickable
{
id: flick
width: imageBrowser.imageWidth
height: imageBrowser.imageHeight
contentWidth: imageBrowser.imageWidth
contentHeight: imageBrowser.imageHeight
interactive: contentWidth > width || contentHeight > height
onInteractiveChanged: imageBrowser.interactive = !interactive;
z: interactive ? 1000 : 0
PinchArea {
width: Math.max(flick.contentWidth, flick.width)
height: Math.max(flick.contentHeight, flick.height)
property real initialWidth
property real initialHeight
onPinchStarted: {
initialWidth = flick.contentWidth
initialHeight = flick.contentHeight
}
onPinchUpdated: {
// adjust content pos due to drag
flick.contentX += pinch.previousCenter.x - pinch.center.x
flick.contentY += pinch.previousCenter.y - pinch.center.y
// resize content
flick.resizeContent(Math.max(imageBrowser.imageWidth, initialWidth * pinch.scale), Math.max(imageBrowser.imageHeight, initialHeight * pinch.scale), pinch.center)
}
onPinchFinished: {
// Move its content within bounds.
flick.returnToBounds();
}
Item {
Okular.PageItem {
id: page;
document: documentItem;
pageNumber: index;
anchors.centerIn: parent;
property real pageRatio: implicitWidth / implicitHeight
property bool sameOrientation: control.width / control.height > pageRatio
width: sameOrientation ? parent.height * pageRatio : parent.width
height: !sameOrientation ? parent.width / pageRatio : parent.height
}
implicitWidth: page.implicitWidth
implicitHeight: page.implicitHeight
width: flick.contentWidth
height: flick.contentHeight
MouseArea {
anchors.fill: parent
onDoubleClicked: {
abortToggleControls();
if (flick.interactive) {
flick.resizeContent(imageBrowser.imageWidth, imageBrowser.imageHeight, {x: imageBrowser.imageWidth/2, y: imageBrowser.imageHeight/2});
} else {
flick.resizeContent(imageBrowser.imageWidth * 2, imageBrowser.imageHeight * 2, {x: mouse.x, y: mouse.y});
}
}
}
}
}
}
}
// Component.onCompleted:
// {
// documentItem.url = currentUrl
// }
}
......@@ -8,18 +8,8 @@ Maui.ImageViewer
{
id: control
anchors.fill: parent
image.source: currentUrl
// Connections:
// {
// target: image
//
// onStatusChanged:
// {
// if(target.status === Image.Ready)
// infoModel.insert(0, {key:"Dimension", value: control.image.implicitWidth + " x " + control.image.implicitHeight})
// }
// }
source: currentUrl
animated: iteminfo.mime === "image/gif"
}
......
......@@ -86,6 +86,11 @@ Maui.Page
onClicked: player.playbackState === MediaPlayer.PlayingState ? player.pause() : player.play()
}
footBar.rightContent: Label
{
text: Maui.FM.formatTime((player.duration - player.position)/1000)
}
footBar.middleContent : Slider
{
id: _slider
......
......@@ -54,3 +54,4 @@ Holder 1.0 Holder.qml
ImageViewer 1.0 ImageViewer.qml
TabBar 1.0 TabBar.qml
TabButton 1.0 TabButton.qml
DocumentPreview 1.0 DocumentPreview.qml
......@@ -151,6 +151,7 @@ void MauiKit::registerTypes(const char *uri)
qmlRegisterType<DocumentHandler>(uri, 1, 0, "DocumentHandler");
qmlRegisterType<SyntaxHighlighterUtil>();
qmlRegisterType(componentUrl(QStringLiteral("Editor.qml")), uri, 1, 0, "Editor");
qmlRegisterType(componentUrl(QStringLiteral("private/DocumentPreview.qml")), uri, 1, 0, "DocumentPreview");
#ifdef STATIC_MAUIKIT
qmlRegisterType<KQuickSyntaxHighlighter>("org.kde.kquicksyntaxhighlighter", 0, 1, "KQuickSyntaxHighlighter");
......
......@@ -193,6 +193,21 @@ QString FMStatic::formatDate(const QString &dateStr, const QString &format, cons
return date.toString(format);
}
QString FMStatic::formatTime(const qint64 &value)
{
QString tStr;
if (value)
{
QTime time((value/3600)%60, (value/60)%60, value%60, (value*1000)%1000);
QString format = "mm:ss";
if (value > 3600)
format = "hh:mm:ss";
tStr = time.toString(format);
}
return tStr.isEmpty() ? "00:00" : tStr;
}
QString FMStatic::homePath()
{
return FMH::HomePath;
......
......@@ -22,8 +22,9 @@ public slots:
static bool cut(QUrl url, QUrl where);
static bool removeDir(const QUrl &path);
static QString formatSize(const int &size);
static QString formatDate(const QString &dateStr, const QString &format = QString("dd/MM/yyyy"), const QString &initFormat = QString());
static QString formatSize(const int &size);
static QString formatTime(const qint64 &value);
static QString formatDate(const QString &dateStr, const QString &format = QString("dd/MM/yyyy"), const QString &initFormat = QString());
static QString homePath();
static QUrl parentDir(const QUrl &path);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment