Commit 3d50fec1 authored by Marco Martin's avatar Marco Martin
Browse files

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
parent 8f5e86ce
......@@ -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 )
......
......@@ -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)
......@@ -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;
}
......
......@@ -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"
......
......@@ -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
......@@ -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();
......
......@@ -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;
};
......
module org.kde.okular
plugin okularplugin
/*
* 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
......@@ -19,7 +19,7 @@
#include "thumbnailitem.h"
ThumbnailItem::ThumbnailItem(QDeclarativeItem *parent)
ThumbnailItem::ThumbnailItem(QQuickItem *parent)
: PageItem(parent)
{
setIsThumbnail(true);
......
......@@ -28,7 +28,7 @@ class ThumbnailItem : public PageItem
public:
ThumbnailItem(QDeclarativeItem *parent=0);
ThumbnailItem(QQuickItem *parent=0);
~ThumbnailItem();
};
......
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