aboutsummaryrefslogtreecommitdiffstats
path: root/doc/examples/contentplugin.qdoc
diff options
context:
space:
mode:
Diffstat (limited to 'doc/examples/contentplugin.qdoc')
-rw-r--r--doc/examples/contentplugin.qdoc110
1 files changed, 110 insertions, 0 deletions
diff --git a/doc/examples/contentplugin.qdoc b/doc/examples/contentplugin.qdoc
new file mode 100644
index 0000000..3671309
--- /dev/null
+++ b/doc/examples/contentplugin.qdoc
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Pelagicore AG
+** Contact: http://www.qt.io/ or http://www.pelagicore.com/
+**
+** This file is part of the QmlLive tool.
+**
+** $QT_BEGIN_LICENSE:GPL3-PELAGICORE$
+** Commercial License Usage
+** Licensees holding valid commercial Pelagicore Application Manager
+** 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
+** Pelagicore. For licensing terms and conditions, contact us at:
+** http://www.pelagicore.com.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3 requirements will be
+** met: http://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: GPL-3.0
+**
+****************************************************************************/
+/*!
+ \example contentplugin
+ \title ContentPlugin Example
+
+ \brief The ContentPlugin example demonstrates how to write a
+ Content Plugin for QmlLive
+
+ \image contentplugin-example.png Screenshot of the Plugin in Action
+
+ The Plugin written in this example displays Images like the
+ builtin Imageviewer in QmlLive, but it shows the content rotated
+ only works on *.png files.
+
+ We will start by reviewing the interface defined in \c
+ contentadapterinterface.h in the QmlLive source code. This
+ interface can be used to add a new ContentAdapter to QmlLive.
+ The ContentAdapter will be used to display any content you want
+ to be handled not directly by the LiveRuntime like displaying a image.
+
+ \snippet contentadapterinterface.h 0
+
+ The \c ContentAdapterInterface class declares four functions. The first
+ function \c canAdapt(const QUrl&) returns whether the plugin can display the
+ given file or directory.
+
+ The second function \c adapt(const QUrl& url, QDeclarativeContext* context)
+ returns a custom QUrl which will be used by QmlLive to display the given QUrl.
+ The returned QUrl always has to point to a qml file used to display the content.
+ To be able to control the returned qml File \c context can be used to set custom
+ Properties which will be exported to the qml File.
+
+ canPreview() and preview() are used for generating preview thumbnails.
+ We use the easiest implementation for this two methods.
+
+ \section1 MyContentAdapterPlugin
+
+ \snippet contentplugin/mycontentadapterplugin.h 0
+
+ The MyContentAdapterPlugin implements the interface to QmlLive. It subclasses
+ QObject and the needed \c ContentAdapterInterface.
+
+ \snippet contentplugin/mycontentadapterplugin.h 1
+
+ The \c Q_INTERFACES macro will be used to register the Plugin to Qt's Plugin
+ System.
+
+
+ To be called only for the right file type we have to overload the
+ \c canAdapt(const QUrl&) function. We only want to be loaded for *.png files.
+ That's why we check the file ending on the given url and return true when it's
+ an png file.
+
+ \snippet contentplugin/mycontentadapterplugin.cpp 0
+
+ If the plugin accepts the file \c adapt(const QUrl& url, QDeclarativeContext* context)
+ will be called. Here we export the path to the image to a special property in the
+ context to be able to access the fileName from within our qml File.
+ Afterwards we return a QUrl pointing to our qml File which is inside a ResourceFile.
+
+ \snippet contentplugin/mycontentadapterplugin.cpp 1
+
+ Now only the implementation of canPreview() and preview() are missing. Here we just
+ add some dummy implementation because we don't want to add this functionality.
+
+ \snippet contentplugin/mycontentadapterplugin.cpp 2
+
+ \section1 plugin.qml
+
+ The plugin.qml file is our ImageViewer. In it we create a \c Image Element and
+ set the source to our exported Property \c imageSource. The rotation Property
+ will be set to 180 to rotate the Image 180 degrees.
+
+ \snippet contentplugin/plugin.qml 0
+
+ \section1 The Resource File
+
+ Because we don't want to fiddle around with paths we include our qml File into
+ a Resource File. The most important thing in the Resource File is to use an
+ unused Prefix. Otherwise our file can't be found because QmlLive also uses
+ Resource Files. The best approach is to use the plugin name as prefix.
+*/