File indexing completed on 2025-01-19 04:01:42

0001 // vim: set tabstop=4 shiftwidth=4 expandtab:
0002 /*
0003 Gwenview: an image viewer
0004 Copyright 2008 Aurélien Gâteau <agateau@kde.org>
0005 
0006 This program is free software; you can redistribute it and/or
0007 modify it under the terms of the GNU General Public License
0008 as published by the Free Software Foundation; either version 2
0009 of the License, or (at your option) any later version.
0010 
0011 This program is distributed in the hope that it will be useful,
0012 but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 GNU General Public License for more details.
0015 
0016 You should have received a copy of the GNU General Public License
0017 along with this program; if not, write to the Free Software
0018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
0019 
0020 */
0021 // Self
0022 #include "rasterimageviewadapter.h"
0023 
0024 // Local
0025 #include <lib/document/documentfactory.h>
0026 #include <lib/documentview/rasterimageview.h>
0027 #include <lib/gwenviewconfig.h>
0028 
0029 #include "alphabackgrounditem.h"
0030 
0031 // KF
0032 
0033 // Qt
0034 
0035 namespace Gwenview
0036 {
0037 //// RasterImageViewAdapter ////
0038 struct RasterImageViewAdapterPrivate {
0039     RasterImageViewAdapter *q = nullptr;
0040     RasterImageView *mView = nullptr;
0041 };
0042 
0043 RasterImageViewAdapter::RasterImageViewAdapter()
0044     : d(new RasterImageViewAdapterPrivate)
0045 {
0046     d->q = this;
0047     d->mView = new RasterImageView;
0048     connect(d->mView, &RasterImageView::zoomChanged, this, &RasterImageViewAdapter::zoomChanged);
0049     connect(d->mView, &RasterImageView::zoomToFitChanged, this, &RasterImageViewAdapter::zoomToFitChanged);
0050     connect(d->mView, &RasterImageView::zoomToFillChanged, this, &RasterImageViewAdapter::zoomToFillChanged);
0051     connect(d->mView, &RasterImageView::zoomInRequested, this, &RasterImageViewAdapter::zoomInRequested);
0052     connect(d->mView, &RasterImageView::zoomOutRequested, this, &RasterImageViewAdapter::zoomOutRequested);
0053     connect(d->mView, &RasterImageView::scrollPosChanged, this, &RasterImageViewAdapter::scrollPosChanged);
0054     connect(d->mView, &RasterImageView::completed, this, &RasterImageViewAdapter::completed);
0055     connect(d->mView, &RasterImageView::previousImageRequested, this, &RasterImageViewAdapter::previousImageRequested);
0056     connect(d->mView, &RasterImageView::nextImageRequested, this, &RasterImageViewAdapter::nextImageRequested);
0057     connect(d->mView, &RasterImageView::toggleFullScreenRequested, this, &RasterImageViewAdapter::toggleFullScreenRequested);
0058     setWidget(d->mView);
0059 }
0060 
0061 RasterImageViewAdapter::~RasterImageViewAdapter()
0062 {
0063     delete d;
0064 }
0065 
0066 QCursor RasterImageViewAdapter::cursor() const
0067 {
0068     return d->mView->cursor();
0069 }
0070 
0071 void RasterImageViewAdapter::setCursor(const QCursor &cursor)
0072 {
0073     d->mView->setCursor(cursor);
0074 }
0075 
0076 void RasterImageViewAdapter::setDocument(const Document::Ptr &doc)
0077 {
0078     d->mView->setDocument(doc);
0079 
0080     connect(doc.data(), &Document::loadingFailed, this, &RasterImageViewAdapter::slotLoadingFailed);
0081     if (doc->loadingState() == Document::LoadingFailed) {
0082         slotLoadingFailed();
0083     }
0084 }
0085 
0086 qreal RasterImageViewAdapter::zoom() const
0087 {
0088     return d->mView->zoom();
0089 }
0090 
0091 void RasterImageViewAdapter::setZoomToFit(bool on)
0092 {
0093     d->mView->setZoomToFit(on);
0094 }
0095 
0096 void RasterImageViewAdapter::setZoomToFill(bool on, const QPointF &center)
0097 {
0098     d->mView->setZoomToFill(on, center);
0099 }
0100 
0101 bool RasterImageViewAdapter::zoomToFit() const
0102 {
0103     return d->mView->zoomToFit();
0104 }
0105 
0106 bool RasterImageViewAdapter::zoomToFill() const
0107 {
0108     return d->mView->zoomToFill();
0109 }
0110 
0111 void RasterImageViewAdapter::setZoom(qreal zoom, const QPointF &center)
0112 {
0113     d->mView->setZoom(zoom, center);
0114 }
0115 
0116 qreal RasterImageViewAdapter::computeZoomToFit() const
0117 {
0118     return d->mView->computeZoomToFit();
0119 }
0120 
0121 qreal RasterImageViewAdapter::computeZoomToFill() const
0122 {
0123     return d->mView->computeZoomToFill();
0124 }
0125 
0126 Document::Ptr RasterImageViewAdapter::document() const
0127 {
0128     return d->mView->document();
0129 }
0130 
0131 void RasterImageViewAdapter::slotLoadingFailed()
0132 {
0133     d->mView->setDocument(Document::Ptr());
0134 }
0135 
0136 void RasterImageViewAdapter::loadConfig()
0137 {
0138     d->mView->backgroundItem()->setMode(GwenviewConfig::alphaBackgroundMode());
0139     d->mView->backgroundItem()->setColor(GwenviewConfig::alphaBackgroundColor());
0140     d->mView->setRenderingIntent(GwenviewConfig::renderingIntent());
0141     d->mView->setEnlargeSmallerImages(GwenviewConfig::enlargeSmallerImages());
0142     d->mView->resetMonitorICC();
0143 }
0144 
0145 RasterImageView *RasterImageViewAdapter::rasterImageView() const
0146 {
0147     return d->mView;
0148 }
0149 
0150 AbstractImageView *RasterImageViewAdapter::imageView() const
0151 {
0152     return d->mView;
0153 }
0154 
0155 QPointF RasterImageViewAdapter::scrollPos() const
0156 {
0157     return d->mView->scrollPos();
0158 }
0159 
0160 void RasterImageViewAdapter::setScrollPos(const QPointF &pos)
0161 {
0162     d->mView->setScrollPos(pos);
0163 }
0164 
0165 QRectF RasterImageViewAdapter::visibleDocumentRect() const
0166 {
0167     return QRectF(d->mView->imageOffset(), d->mView->visibleImageSize());
0168 }
0169 
0170 } // namespace
0171 
0172 #include "moc_rasterimageviewadapter.cpp"