diff --git a/components/Document.h b/components/Document.h --- a/components/Document.h +++ b/components/Document.h @@ -100,6 +100,7 @@ QSize documentSize() const; QObject* document() const; virtual QObject* part() const; + QObject* impl() const; /** * Getter for property #currentIndex. diff --git a/components/Document.cpp b/components/Document.cpp --- a/components/Document.cpp +++ b/components/Document.cpp @@ -186,7 +186,16 @@ QObject* Document::part() const { - return d->impl->part(); + if(d->impl) { + return d->impl->part(); + } + + return nullptr; +} + +QObject* Document::impl() const +{ + return d->impl; } QObject* Document::document() const diff --git a/components/View.h b/components/View.h --- a/components/View.h +++ b/components/View.h @@ -62,6 +62,19 @@ */ Q_PROPERTY(float zoom READ zoom WRITE setZoom NOTIFY zoomChanged) + /** + * \property pageCacheEnabled + * \brief Enable or not rendering page caching. + * + * \note Depending on #document, this may have no effect. + * + * \default false. + * \get pageCache() const + * \set setPageCache() + * \notify pageCacheEnabledChanged() + */ + Q_PROPERTY(bool pageCacheEnabled READ pageCache WRITE setPageCache NOTIFY pageCacheEnabledChanged) + public: /** * Constructor. @@ -97,6 +110,17 @@ */ void setZoom(float newValue); + void setFillColor(const QColor &); + + /** + * Getter for property #pageCacheEnabled. + */ + bool pageCache() const; + /** + * Setter for property #pageCacheEnabled. + */ + void setPageCache(bool withCache); + Q_SIGNALS: /** * \brief Emitted when a link in the document is clicked. @@ -114,6 +138,10 @@ * Notify signal for property #zoom. */ void zoomChanged(); + /** + * Notify signal for property #pageCacheEnabled. + */ + void pageCacheEnabledChanged(); protected: /** diff --git a/components/View.cpp b/components/View.cpp --- a/components/View.cpp +++ b/components/View.cpp @@ -29,6 +29,7 @@ #include #include "Document.h" +#include "impl/DocumentImpl.h" #include #include @@ -37,7 +38,7 @@ class View::Private { public: - Private(View* qq) : q{qq}, document{nullptr}, canvas{nullptr} + Private(View* qq) : q{qq}, document{nullptr}, canvas{nullptr}, m_cache(false) { } void updateCanvas(); @@ -46,6 +47,7 @@ Document* document; QGraphicsWidget* canvas; + bool m_cache; QTimer updateTimer; }; @@ -53,6 +55,7 @@ View::View(QQuickItem* parent) : QQuickPaintedItem{parent}, d{new Private{this}} { + QQuickPaintedItem::setFillColor(QColor(232, 233, 234)); } View::~View() @@ -114,6 +117,33 @@ } } +void View::setFillColor(const QColor &color) +{ + if (d->document && d->document->impl()) + static_cast(d->document->impl())->setBackgroundColor(color); + QQuickPaintedItem::setFillColor(color); +} + +bool View::pageCache() const +{ + if (d->document && d->document->impl()) + return static_cast(d->document->impl())->pageCache(); + else + return d->m_cache; +} + +void View::setPageCache(bool withCache) +{ + d->m_cache = withCache; + if (pageCache() == withCache) + return; + + if (d->document && d->document->impl()) { + static_cast(d->document->impl())->setPageCache(withCache); + emit pageCacheEnabledChanged(); + } +} + void View::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) { if (d->canvas) { @@ -127,6 +157,8 @@ if(document && document->status() == DocumentStatus::Loaded) { canvas = document->canvas(); canvas->setGeometry(0, 0, q->width(), q->height()); + static_cast(document->impl())->setBackgroundColor(q->fillColor()); + static_cast(document->impl())->setPageCache(m_cache); q->update(); } else { canvas = nullptr; diff --git a/components/impl/DocumentImpl.h b/components/impl/DocumentImpl.h --- a/components/impl/DocumentImpl.h +++ b/components/impl/DocumentImpl.h @@ -24,6 +24,7 @@ #define CALLIGRA_COMPONENTS_DOCUMENTIMPL_H #include +#include #include "Global.h" class KoDocument; @@ -64,6 +65,10 @@ KoDocument* koDocument() const; virtual QObject* part() const = 0; + virtual void setBackgroundColor(const QColor &color); + virtual bool pageCache() const; + virtual void setPageCache(bool); + Q_SIGNALS: void documentSizeChanged(); void currentIndexChanged(); diff --git a/components/impl/DocumentImpl.cpp b/components/impl/DocumentImpl.cpp --- a/components/impl/DocumentImpl.cpp +++ b/components/impl/DocumentImpl.cpp @@ -120,6 +120,19 @@ d->finder = newFinder; } +void DocumentImpl::setBackgroundColor(const QColor &) +{ +} + +bool DocumentImpl::pageCache() const +{ + return false; +} + +void DocumentImpl::setPageCache(bool) +{ +} + void DocumentImpl::createAndSetCanvasController(KoCanvasBase* canvas) { auto controller = new ComponentsKoCanvasController{new KActionCollection{this}}; diff --git a/components/impl/TextDocumentImpl.h b/components/impl/TextDocumentImpl.h --- a/components/impl/TextDocumentImpl.h +++ b/components/impl/TextDocumentImpl.h @@ -41,6 +41,9 @@ virtual int indexCount() const; virtual QUrl urlAtPoint(QPoint point); virtual QObject* part() const; + virtual void setBackgroundColor(const QColor &color); + virtual bool pageCache() const; + virtual void setPageCache(bool withCache); private: class Private; diff --git a/components/impl/TextDocumentImpl.cpp b/components/impl/TextDocumentImpl.cpp --- a/components/impl/TextDocumentImpl.cpp +++ b/components/impl/TextDocumentImpl.cpp @@ -311,3 +311,23 @@ { return d->part; } + +void TextDocumentImpl::setBackgroundColor(const QColor &color) +{ + if (d->canvas) + d->canvas->setBackgroundColor(color); +} + +bool TextDocumentImpl::pageCache() const +{ + if (d->canvas) + return d->canvas->isCacheEnabled(); + else + return false; +} + +void TextDocumentImpl::setPageCache(bool withCache) +{ + if (d->canvas) + d->canvas->setCacheEnabled(withCache); +} diff --git a/words/part/KWCanvasBase.h b/words/part/KWCanvasBase.h --- a/words/part/KWCanvasBase.h +++ b/words/part/KWCanvasBase.h @@ -103,6 +103,7 @@ * of creating a new cache */ virtual void setCacheEnabled(bool enabled, int cacheSize = 50, qreal maxZoom = 2.0); + bool isCacheEnabled() const; /** * return whether annotations are shown in the canvas. diff --git a/words/part/KWCanvasBase.cpp b/words/part/KWCanvasBase.cpp --- a/words/part/KWCanvasBase.cpp +++ b/words/part/KWCanvasBase.cpp @@ -793,6 +793,11 @@ m_maxZoom = maxZoom; } +bool KWCanvasBase::isCacheEnabled() const +{ + return m_cacheEnabled && m_pageCacheManager; +} + QPoint KWCanvasBase::documentOffset() const { return m_documentOffset; diff --git a/words/part/KWCanvasItem.h b/words/part/KWCanvasItem.h --- a/words/part/KWCanvasItem.h +++ b/words/part/KWCanvasItem.h @@ -27,6 +27,7 @@ #include "words_export.h" #include +#include class QRect; class QPainter; @@ -88,6 +89,9 @@ virtual void setCursor(const QCursor &cursor); + QColor backgroundColor() const; + void setBackgroundColor(const QColor &color); + public Q_SLOTS: /** * sets the document offset in the scrollArea @@ -147,6 +151,9 @@ private Q_SLOTS: /// Called whenever there was a page added/removed or simply resized. void pageSetupChanged(); + +private: + QColor m_backgroundColor; }; #endif diff --git a/words/part/KWCanvasItem.cpp b/words/part/KWCanvasItem.cpp --- a/words/part/KWCanvasItem.cpp +++ b/words/part/KWCanvasItem.cpp @@ -45,8 +45,9 @@ KWCanvasItem::KWCanvasItem(const QString &viewMode, KWDocument *document) - : QGraphicsWidget(0), - KWCanvasBase(document, this) + : QGraphicsWidget(0) + , KWCanvasBase(document, this) + , m_backgroundColor(232, 233, 234) { setAttribute(Qt::WA_OpaquePaintEvent, true); setAttribute(Qt::WA_InputMethodEnabled, true); @@ -163,7 +164,9 @@ void KWCanvasItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) { - painter->fillRect(option->exposedRect, QColor::fromRgb(232, 233, 234)); + if (m_backgroundColor.alpha() > 0) { + painter->fillRect(option->exposedRect, m_backgroundColor); + } KWCanvasBase::paint(*painter, option->exposedRect); } @@ -171,3 +174,13 @@ { QGraphicsWidget::setCursor(cursor); } + +QColor KWCanvasItem::backgroundColor() const +{ + return m_backgroundColor; +} + +void KWCanvasItem::setBackgroundColor(const QColor &color) +{ + m_backgroundColor = color; +}