diff --git a/lib/documentview/svgviewadapter.cpp b/lib/documentview/svgviewadapter.cpp index ec989650..61d9d713 100644 --- a/lib/documentview/svgviewadapter.cpp +++ b/lib/documentview/svgviewadapter.cpp @@ -1,203 +1,209 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2008 Aurélien Gâteau 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 of the License, 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, Cambridge, MA 02110-1301, USA. */ // Self #include "svgviewadapter.h" // Qt #include #include #include #include #include #include // KDE // Local #include "document/documentfactory.h" #include #include #include namespace Gwenview { /// SvgImageView //// SvgImageView::SvgImageView(QGraphicsItem* parent) : AbstractImageView(parent) , mSvgItem(new QGraphicsSvgItem(this)) { } void SvgImageView::loadFromDocument() { Document::Ptr doc = document(); GV_RETURN_IF_FAIL(doc); if (doc->loadingState() < Document::Loaded) { connect(doc.data(), SIGNAL(loaded(QUrl)), SLOT(finishLoadFromDocument())); } else { QMetaObject::invokeMethod(this, "finishLoadFromDocument", Qt::QueuedConnection); } } void SvgImageView::finishLoadFromDocument() { QSvgRenderer* renderer = document()->svgRenderer(); GV_RETURN_IF_FAIL(renderer); mSvgItem->setSharedRenderer(renderer); if (zoomToFit()) { setZoom(computeZoomToFit(), QPointF(-1, -1), ForceUpdate); } else if (zoomToFill()) { setZoom(computeZoomToFill(), QPointF(-1, -1), ForceUpdate); } else { mSvgItem->setScale(zoom()); } applyPendingScrollPos(); completed(); } void SvgImageView::onZoomChanged() { mSvgItem->setScale(zoom()); adjustItemPos(); + update(); } void SvgImageView::onImageOffsetChanged() { adjustItemPos(); } void SvgImageView::onScrollPosChanged(const QPointF& /* oldPos */) { adjustItemPos(); } void SvgImageView::adjustItemPos() { mSvgItem->setPos(imageOffset() - scrollPos()); } //// SvgViewAdapter //// struct SvgViewAdapterPrivate { SvgImageView* mView; }; SvgViewAdapter::SvgViewAdapter() : d(new SvgViewAdapterPrivate) { d->mView = new SvgImageView; setWidget(d->mView); connect(d->mView, &SvgImageView::zoomChanged, this, &SvgViewAdapter::zoomChanged); connect(d->mView, &SvgImageView::zoomToFitChanged, this, &SvgViewAdapter::zoomToFitChanged); connect(d->mView, &SvgImageView::zoomToFillChanged, this, &SvgViewAdapter::zoomToFillChanged); connect(d->mView, &SvgImageView::zoomInRequested, this, &SvgViewAdapter::zoomInRequested); connect(d->mView, &SvgImageView::zoomOutRequested, this, &SvgViewAdapter::zoomOutRequested); connect(d->mView, &SvgImageView::scrollPosChanged, this, &SvgViewAdapter::scrollPosChanged); connect(d->mView, &SvgImageView::completed, this, &SvgViewAdapter::completed); connect(d->mView, &SvgImageView::previousImageRequested, this, &SvgViewAdapter::previousImageRequested); connect(d->mView, &SvgImageView::nextImageRequested, this, &SvgViewAdapter::nextImageRequested); connect(d->mView, &SvgImageView::toggleFullScreenRequested, this, &SvgViewAdapter::toggleFullScreenRequested); } SvgViewAdapter::~SvgViewAdapter() { delete d; } QCursor SvgViewAdapter::cursor() const { return widget()->cursor(); } void SvgViewAdapter::setCursor(const QCursor& cursor) { widget()->setCursor(cursor); } void SvgViewAdapter::setDocument(Document::Ptr doc) { d->mView->setDocument(doc); } Document::Ptr SvgViewAdapter::document() const { return d->mView->document(); } void SvgViewAdapter::loadConfig() { d->mView->setEnlargeSmallerImages(GwenviewConfig::enlargeSmallerImages()); } void SvgViewAdapter::setZoomToFit(bool on) { d->mView->setZoomToFit(on); } void SvgViewAdapter::setZoomToFill(bool on) { d->mView->setZoomToFill(on); } bool SvgViewAdapter::zoomToFit() const { return d->mView->zoomToFit(); } bool SvgViewAdapter::zoomToFill() const { return d->mView->zoomToFill(); } qreal SvgViewAdapter::zoom() const { return d->mView->zoom(); } void SvgViewAdapter::setZoom(qreal zoom, const QPointF& center) { d->mView->setZoom(zoom, center); } qreal SvgViewAdapter::computeZoomToFit() const { return d->mView->computeZoomToFit(); } qreal SvgViewAdapter::computeZoomToFill() const { return d->mView->computeZoomToFill(); } QPointF SvgViewAdapter::scrollPos() const { return d->mView->scrollPos(); } void SvgViewAdapter::setScrollPos(const QPointF& pos) { d->mView->setScrollPos(pos); } +QRectF SvgViewAdapter::visibleDocumentRect() const +{ + return QRectF(d->mView->imageOffset(), d->mView->visibleImageSize()); +} + } // namespace diff --git a/lib/documentview/svgviewadapter.h b/lib/documentview/svgviewadapter.h index b3c694f9..ad9104c0 100644 --- a/lib/documentview/svgviewadapter.h +++ b/lib/documentview/svgviewadapter.h @@ -1,113 +1,115 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2008 Aurélien Gâteau 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 of the License, 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, Cambridge, MA 02110-1301, USA. */ #ifndef SVGVIEWADAPTER_H #define SVGVIEWADAPTER_H #include // Qt #include // KDE // Local #include #include class QGraphicsSvgItem; namespace Gwenview { class SvgImageView : public AbstractImageView { Q_OBJECT public: SvgImageView(QGraphicsItem* parent = 0); protected: void loadFromDocument() Q_DECL_OVERRIDE; void onZoomChanged() Q_DECL_OVERRIDE; void onImageOffsetChanged() Q_DECL_OVERRIDE; void onScrollPosChanged(const QPointF& oldPos) Q_DECL_OVERRIDE; private Q_SLOTS: void finishLoadFromDocument(); private: QGraphicsSvgItem* mSvgItem; void adjustItemPos(); }; struct SvgViewAdapterPrivate; class GWENVIEWLIB_EXPORT SvgViewAdapter : public AbstractDocumentViewAdapter { Q_OBJECT public: SvgViewAdapter(); ~SvgViewAdapter(); virtual QCursor cursor() const Q_DECL_OVERRIDE; virtual void setCursor(const QCursor&) Q_DECL_OVERRIDE; virtual void setDocument(Document::Ptr) Q_DECL_OVERRIDE; virtual Document::Ptr document() const Q_DECL_OVERRIDE; virtual void loadConfig() Q_DECL_OVERRIDE; virtual MimeTypeUtils::Kind kind() const Q_DECL_OVERRIDE { return MimeTypeUtils::KIND_SVG_IMAGE; } virtual bool canZoom() const Q_DECL_OVERRIDE { return true; } virtual void setZoomToFit(bool) Q_DECL_OVERRIDE; virtual void setZoomToFill(bool) Q_DECL_OVERRIDE; virtual bool zoomToFit() const Q_DECL_OVERRIDE; virtual bool zoomToFill() const Q_DECL_OVERRIDE; virtual qreal zoom() const Q_DECL_OVERRIDE; virtual void setZoom(qreal /*zoom*/, const QPointF& /*center*/ = QPointF(-1, -1)) Q_DECL_OVERRIDE; virtual qreal computeZoomToFit() const Q_DECL_OVERRIDE; virtual qreal computeZoomToFill() const Q_DECL_OVERRIDE; virtual QPointF scrollPos() const Q_DECL_OVERRIDE; virtual void setScrollPos(const QPointF& pos) Q_DECL_OVERRIDE; + virtual QRectF visibleDocumentRect() const override; + private: SvgViewAdapterPrivate* const d; }; } // namespace #endif /* SVGVIEWADAPTER_H */