summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Martin <notmart@gmail.com>2014-12-02 19:41:16 (GMT)
committerMarco Martin <notmart@gmail.com>2014-12-02 19:41:16 (GMT)
commit3d50fec102acd5d902bf40029fe20084ad7ecc5e (patch)
tree9e8725d3b4f88e6e49191502abdcaa06f274f866
parent8f5e86cec558c17514ad821ae3ed3bf7a60a24c5 (diff)
initial port of QML components to QtQuick2
this is an initial port of the qml component set of okular to qtquick2 it's straightforward, except pageitem that right now is a qquickpainteditem, that works fine, but a bit slower than generating and uploading the textures by hand (that may be an eventual future port) the okular active application is still missing, but the components can be used from anywhere in qml REVIEW:121326
-rw-r--r--CMakeLists.txt4
-rw-r--r--active/components/CMakeLists.txt19
-rw-r--r--active/components/documentitem.cpp10
-rw-r--r--active/components/okularplugin.cpp9
-rw-r--r--active/components/okularplugin.h7
-rw-r--r--active/components/pageitem.cpp19
-rw-r--r--active/components/pageitem.h16
-rw-r--r--active/components/qmldir1
-rw-r--r--active/components/test.qml50
-rw-r--r--active/components/thumbnailitem.cpp2
-rw-r--r--active/components/thumbnailitem.h2
11 files changed, 93 insertions, 46 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d56c02e..b5ef9e7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,7 +20,7 @@ include(KDECMakeSettings)
include(ECMAddTests)
-find_package(Qt5 CONFIG REQUIRED COMPONENTS Core DBus Test Widgets PrintSupport Svg)
+find_package(Qt5 CONFIG REQUIRED COMPONENTS Core DBus Test Widgets PrintSupport Svg Qml Quick)
find_package(KF5 REQUIRED COMPONENTS
Activities
Archive
@@ -64,7 +64,7 @@ add_definitions(-DTRANSLATION_DOMAIN="okular")
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${PHONON_INCLUDES} core/synctex ${ZLIB_INCLUDE_DIR})
message("TODO: when core compiles add subdirs")
-#add_subdirectory( active )
+add_subdirectory( active )
add_subdirectory( ui )
add_subdirectory( shell )
add_subdirectory( generators )
diff --git a/active/components/CMakeLists.txt b/active/components/CMakeLists.txt
index 07eac9b..291648e 100644
--- a/active/components/CMakeLists.txt
+++ b/active/components/CMakeLists.txt
@@ -17,25 +17,22 @@ set(okular_SRCS
documentitem.cpp
thumbnailitem.cpp
)
-
+
kconfig_add_kcfg_files (okular_SRCS ${CMAKE_SOURCE_DIR}/conf/settings.kcfgc )
qt4_automoc(${okular_SRCS})
kde4_add_library(okularplugin SHARED ${okular_SRCS})
target_link_libraries(okularplugin
- ${QT_QTCORE_LIBRARY}
- ${QT_QTGUI_LIBRARY}
- ${QT_QTDECLARATIVE_LIBRARY}
- ${QT_QTXML_LIBRARY}
- ${KDE4_KDECORE_LIBRARY}
- ${KDE4_KDEUI_LIBRARY}
- ${KDE4_KIO_LIBRARY}
- ${QIMAGEBLITZ_LIBRARIES}
+ Qt5::Quick
+ Qt5::Qml
+ Qt5::Core
+ Qt5::Xml
+ Qt5::Svg
okularcore
)
-install(TARGETS okularplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/okular)
-install(FILES qmldir DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/okular)
+install(TARGETS okularplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/okular)
+install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/okular)
#add_subdirectory(test)
diff --git a/active/components/documentitem.cpp b/active/components/documentitem.cpp
index c8f7ee4..6e185ef 100644
--- a/active/components/documentitem.cpp
+++ b/active/components/documentitem.cpp
@@ -19,7 +19,8 @@
#include "documentitem.h"
-#include <QtDeclarative/qdeclarative.h>
+#include <QtQml>
+#include <QMimeDatabase>
#include <core/document_p.h>
#include <core/page.h>
@@ -56,7 +57,8 @@ void DocumentItem::setPath(const QString &path)
{
//TODO: remote urls
//TODO: password
- m_document->openDocument(path, KUrl(path), db.mimeTypeForUrl(KUrl(path)));
+ QMimeDatabase db;
+ m_document->openDocument(path, KUrl(path), db.mimeTypeForUrl(QUrl(path)));
m_tocModel->fill(m_document->documentSynopsis());
m_tocModel->setCurrentViewport(m_document->viewport());
@@ -132,7 +134,7 @@ QList<int> DocumentItem::bookmarkedPages() const
QList<int> list;
QSet<int> pages;
foreach (const KBookmark &bookmark, m_document->bookmarkManager()->bookmarks()) {
- Okular::DocumentViewport viewport(bookmark.url().htmlRef());
+ Okular::DocumentViewport viewport(bookmark.url().fragment());
pages << viewport.pageNumber;
}
list = pages.toList();
@@ -144,7 +146,7 @@ QStringList DocumentItem::bookmarks() const
{
QStringList list;
foreach(const KBookmark &bookmark, m_document->bookmarkManager()->bookmarks()) {
- list << bookmark.url().prettyUrl();
+ list << bookmark.url().toString();
}
return list;
}
diff --git a/active/components/okularplugin.cpp b/active/components/okularplugin.cpp
index a7cbff1..3d81e93 100644
--- a/active/components/okularplugin.cpp
+++ b/active/components/okularplugin.cpp
@@ -23,8 +23,7 @@
#include "pageitem.h"
#include "thumbnailitem.h"
-#include <QtDeclarative/qdeclarative.h>
-#include <QtDeclarative/QDeclarativeEngine>
+#include <QtQml/QQmlEngine>
#include <KGlobalSettings>
#include <KLocale>
@@ -34,9 +33,9 @@ void OkularPlugin::registerTypes(const char *uri)
Q_ASSERT(uri == QLatin1String("org.kde.okular"));
//KF5 port: remove this line and define TRANSLATION_DOMAIN in CMakeLists.txt instead
//KLocale::global()->insertCatalog("org.kde.okular");
- qmlRegisterType<DocumentItem>(uri, 0, 1, "DocumentItem");
- qmlRegisterType<PageItem>(uri, 0, 1, "PageItem");
- qmlRegisterType<ThumbnailItem>(uri, 0, 1, "ThumbnailItem");
+ qmlRegisterType<DocumentItem>(uri, 2, 0, "DocumentItem");
+ qmlRegisterType<PageItem>(uri, 2, 0, "PageItem");
+ qmlRegisterType<ThumbnailItem>(uri, 2, 0, "ThumbnailItem");
}
#include "okularplugin.moc"
diff --git a/active/components/okularplugin.h b/active/components/okularplugin.h
index c229c53..43df82b 100644
--- a/active/components/okularplugin.h
+++ b/active/components/okularplugin.h
@@ -20,17 +20,16 @@
#ifndef OKULARPLUGIN
#define OKULARPLUGIN
-#include <QDeclarativeExtensionPlugin>
+#include <QQmlExtensionPlugin>
-class OkularPlugin : public QDeclarativeExtensionPlugin
+class OkularPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public:
void registerTypes(const char *uri);
};
-Q_EXPORT_PLUGIN2(okularplugin, OkularPlugin)
-
#endif
diff --git a/active/components/pageitem.cpp b/active/components/pageitem.cpp
index f9d48f0..d4f475e 100644
--- a/active/components/pageitem.cpp
+++ b/active/components/pageitem.cpp
@@ -35,8 +35,8 @@
#define REDRAW_TIMEOUT 250
-PageItem::PageItem(QDeclarativeItem *parent)
- : QDeclarativeItem(parent),
+PageItem::PageItem(QQuickItem *parent)
+ : QQuickPaintedItem(parent),
Okular::View( QString::fromLatin1( "PageView" ) ),
m_page(0),
m_smooth(false),
@@ -44,7 +44,7 @@ PageItem::PageItem(QDeclarativeItem *parent)
m_bookmarked(false),
m_isThumbnail(false)
{
- setFlag(QGraphicsItem::ItemHasNoContents, false);
+ setFlag(QQuickItem::ItemHasContents, true);
m_viewPort.rePos.enabled = true;
@@ -59,7 +59,7 @@ PageItem::~PageItem()
{
}
-void PageItem::setFlickable(QDeclarativeItem *flickable)
+void PageItem::setFlickable(QQuickItem *flickable)
{
if (m_flickable.data() == flickable) {
return;
@@ -92,7 +92,7 @@ void PageItem::setFlickable(QDeclarativeItem *flickable)
emit flickableChanged();
}
-QDeclarativeItem *PageItem::flickable() const
+QQuickItem *PageItem::flickable() const
{
return m_flickable.data();
}
@@ -205,7 +205,7 @@ QStringList PageItem::bookmarks() const
{
QStringList list;
foreach(const KBookmark &bookmark, m_documentItem.data()->document()->bookmarkManager()->bookmarks(m_viewPort.pageNumber)) {
- list << bookmark.url().prettyUrl();
+ list << bookmark.url().toString();
}
return list;
}
@@ -287,16 +287,15 @@ void PageItem::geometryChanged(const QRectF &newGeometry,
m_redrawTimer->start();
}
- QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
+ QQuickItem::geometryChanged(newGeometry, oldGeometry);
//Why aren't they automatically emuitted?
emit widthChanged();
emit heightChanged();
}
-void PageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+void PageItem::paint(QPainter *painter)
{
if (!m_documentItem || !m_page) {
- QDeclarativeItem::paint(painter, option, widget);
return;
}
@@ -317,7 +316,7 @@ void PageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
m_intentionalDraw = false;
}
const int flags = PagePainter::Accessibility | PagePainter::Highlights | PagePainter::Annotations;
- PagePainter::paintPageOnPainter(painter, m_page, observer, flags, width(), height(), option->exposedRect.toRect());
+ PagePainter::paintPageOnPainter(painter, m_page, observer, flags, width(), height(), QRect(QPoint(0,0), contentsSize()));
if (setAA) {
painter->restore();
diff --git a/active/components/pageitem.h b/active/components/pageitem.h
index 932bde3..8bb5820 100644
--- a/active/components/pageitem.h
+++ b/active/components/pageitem.h
@@ -20,7 +20,7 @@
#ifndef QPAGEITEM_H
#define QPAGEITEM_H
-#include <QDeclarativeItem>
+#include <QQuickPaintedItem>
#include <core/document.h>
#include <core/view.h>
@@ -34,14 +34,14 @@ namespace Okular {
class Page;
}
-class PageItem : public QDeclarativeItem, public Okular::View
+class PageItem : public QQuickPaintedItem, public Okular::View
{
Q_OBJECT
/**
* If this page is in a Flickable, assign it in this property, to make goToBookmark work
*/
- Q_PROPERTY(QDeclarativeItem *flickable READ flickable WRITE setFlickable NOTIFY flickableChanged)
+ Q_PROPERTY(QQuickItem *flickable READ flickable WRITE setFlickable NOTIFY flickableChanged)
/**
* The document this page belongs to
@@ -82,11 +82,11 @@ class PageItem : public QDeclarativeItem, public Okular::View
public:
- PageItem(QDeclarativeItem *parent=0);
+ PageItem(QQuickItem *parent=0);
~PageItem();
- void setFlickable(QDeclarativeItem *flickable);
- QDeclarativeItem *flickable() const;
+ void setFlickable(QQuickItem *flickable);
+ QQuickItem *flickable() const;
int implicitWidth() const;
int implicitHeight() const;
@@ -134,7 +134,7 @@ public:
*/
Q_INVOKABLE void removeBookmark(const QString &bookmark);
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ void paint(QPainter *painter);
void geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry);
@@ -167,7 +167,7 @@ private:
bool m_isThumbnail;
QWeakPointer<DocumentItem> m_documentItem;
QTimer *m_redrawTimer;
- QWeakPointer <QDeclarativeItem> m_flickable;
+ QWeakPointer <QQuickItem> m_flickable;
Okular::DocumentViewport m_viewPort;
};
diff --git a/active/components/qmldir b/active/components/qmldir
index d62e2ae..4d3cc27 100644
--- a/active/components/qmldir
+++ b/active/components/qmldir
@@ -1,2 +1,3 @@
+module org.kde.okular
plugin okularplugin
diff --git a/active/components/test.qml b/active/components/test.qml
new file mode 100644
index 0000000..fc996f8
--- /dev/null
+++ b/active/components/test.qml
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2012 by Marco Martin <mart@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details
+ *
+ * You should have received a copy of the GNU 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.
+ */
+
+import QtQuick 2.2
+import QtQuick.Controls 1.0
+import org.kde.okular 2.0 as Okular
+
+Item {
+ width: 500
+ height: 600
+ Okular.DocumentItem {
+ id: docItem
+ path: "pageitem.cpp"
+ }
+ Okular.PageItem {
+ id: page
+ anchors.fill: parent
+ document: docItem
+ }
+ Row {
+ anchors {
+ bottom: parent.bottom
+ right: parent.right
+ }
+ Button {
+ text: "prev"
+ onClicked: page.pageNumber--
+ }
+ Button {
+ text: "next"
+ onClicked: page.pageNumber++
+ }
+ }
+} \ No newline at end of file
diff --git a/active/components/thumbnailitem.cpp b/active/components/thumbnailitem.cpp
index e56170c..bc2eff9 100644
--- a/active/components/thumbnailitem.cpp
+++ b/active/components/thumbnailitem.cpp
@@ -19,7 +19,7 @@
#include "thumbnailitem.h"
-ThumbnailItem::ThumbnailItem(QDeclarativeItem *parent)
+ThumbnailItem::ThumbnailItem(QQuickItem *parent)
: PageItem(parent)
{
setIsThumbnail(true);
diff --git a/active/components/thumbnailitem.h b/active/components/thumbnailitem.h
index ad3a341..6dd24aa 100644
--- a/active/components/thumbnailitem.h
+++ b/active/components/thumbnailitem.h
@@ -28,7 +28,7 @@ class ThumbnailItem : public PageItem
public:
- ThumbnailItem(QDeclarativeItem *parent=0);
+ ThumbnailItem(QQuickItem *parent=0);
~ThumbnailItem();
};