diff --git a/qmlUiKirigami/ImageViewer.qml b/qmlUiKirigami/ImageViewer.qml --- a/qmlUiKirigami/ImageViewer.qml +++ b/qmlUiKirigami/ImageViewer.qml @@ -45,6 +45,11 @@ id: mimeDB } + Koko.ImageDocument { + id: imageDoc + path: listView.currentItem.currentImageSource + } + Kirigami.ContextDrawer { id: contextDrawer title: i18n("Edit image") @@ -152,7 +157,7 @@ delegate: Flickable { id: flick - property alias currentImageSource: image.source + property string currentImageSource: model.imageurl property alias image: image width: imageWidth height: imageHeight @@ -241,16 +246,12 @@ } } - Image { + KQA.QImageItem { id: image width: flick.contentWidth height: flick.contentHeight - source: model.imageurl fillMode: Image.PreserveAspectFit - asynchronous: true - autoTransform: true - sourceSize.width: imageWidth * 2 - sourceSize.height: imageHeight * 2 + image: imageDoc.visualImage Timer { id: doubleClickTimer interval: 150 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -66,6 +66,7 @@ notificationmanager.cpp types.cpp roles.cpp + imagedocument.cpp ) add_library (kokoqmlplugin SHARED ${qml_plugin_SRCS}) diff --git a/src/imagedocument.h b/src/imagedocument.h new file mode 100644 --- /dev/null +++ b/src/imagedocument.h @@ -0,0 +1,48 @@ +/* + * Copyright 2017 by Atul Sharma + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef IMAGEDOCUMENT_H +#define IMAGEDOCUMENT_H + +#include + +class ImageDocument : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged) + Q_PROPERTY(QImage visualImage READ visualImage NOTIFY visualImageChanged) +public: + ImageDocument(); + ~ImageDocument(); + + QString path(); + void setPath( QString &url); + + QImage visualImage(); + +signals: + void pathChanged(const QString &url); + void visualImageChanged(); + +private: + QString m_path; + QImage *m_image; +}; + +#endif diff --git a/src/imagedocument.cpp b/src/imagedocument.cpp new file mode 100644 --- /dev/null +++ b/src/imagedocument.cpp @@ -0,0 +1,58 @@ +/* + * Copyright 2017 by Atul Sharma + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "imagedocument.h" +#include +#include + +ImageDocument::ImageDocument() +{ + m_image = new QImage(); + connect( this, &ImageDocument::pathChanged, + this, [this] (const QString &url) { + delete m_image; + /** Since the url passed by the model in the ImageViewer.qml contains 'file://' prefix */ + QString location = QUrl( url).path(); + m_image = new QImage( location); + emit visualImageChanged(); + }); +} + +ImageDocument::~ImageDocument() +{ + delete m_image; +} + +QString ImageDocument::path() +{ + return m_path; +} + +void ImageDocument::setPath(QString& url) +{ + m_path = url; + emit pathChanged( url); +} + +QImage ImageDocument::visualImage() +{ + return *m_image; +} + +#include "moc_imagedocument.cpp" diff --git a/src/qmlplugins.cpp b/src/qmlplugins.cpp --- a/src/qmlplugins.cpp +++ b/src/qmlplugins.cpp @@ -32,6 +32,7 @@ #include "notificationmanager.h" #include "types.h" #include "roles.h" +#include "imagedocument.h" #include @@ -50,6 +51,7 @@ qmlRegisterType (uri, 0, 1, "SortModel"); qmlRegisterType (uri, 0, 1, "FileInfo"); qmlRegisterType (uri, 0, 1, "ImageListModel"); + qmlRegisterType (uri, 0, 1, "ImageDocument"); qmlRegisterType (uri, 0, 1, "NotificationManager"); qmlRegisterUncreatableType(uri, 0, 1, "Types", "Cannot instantiate the Types class"); qmlRegisterUncreatableType(uri, 0, 1, "Roles", "Cannot instantiate the Roles class");