File indexing completed on 2025-03-09 04:00:57
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 #ifndef ABSTRACTDOCUMENTVIEWADAPTER_H 0022 #define ABSTRACTDOCUMENTVIEWADAPTER_H 0023 0024 #include <lib/gwenviewlib_export.h> 0025 0026 // Qt 0027 #include <QObject> 0028 #include <QPoint> 0029 0030 // KF 0031 0032 // Local 0033 #include <lib/document/document.h> 0034 0035 class QCursor; 0036 class QGraphicsWidget; 0037 class QRectF; 0038 0039 namespace Gwenview 0040 { 0041 class AbstractImageView; 0042 class RasterImageView; 0043 0044 /** 0045 * Classes inherit from this class so that they can be used inside the 0046 * DocumentPanel. 0047 */ 0048 class GWENVIEWLIB_EXPORT AbstractDocumentViewAdapter : public QObject 0049 { 0050 Q_OBJECT 0051 public: 0052 AbstractDocumentViewAdapter(); 0053 ~AbstractDocumentViewAdapter() override; 0054 0055 QGraphicsWidget *widget() const 0056 { 0057 return mWidget; 0058 } 0059 0060 virtual MimeTypeUtils::Kind kind() const = 0; 0061 0062 virtual AbstractImageView *imageView() const 0063 { 0064 return nullptr; 0065 } 0066 0067 virtual RasterImageView *rasterImageView() const 0068 { 0069 return nullptr; 0070 } 0071 0072 virtual QCursor cursor() const; 0073 0074 virtual void setCursor(const QCursor &); 0075 0076 /** 0077 * @defgroup zooming functions 0078 * @{ 0079 */ 0080 virtual bool canZoom() const 0081 { 0082 return false; 0083 } 0084 0085 // Implementation must emit zoomToFitChanged() 0086 virtual void setZoomToFit(bool) 0087 { 0088 } 0089 0090 virtual bool zoomToFit() const 0091 { 0092 return false; 0093 } 0094 0095 // Implementation must emit zoomToFillChanged() 0096 virtual void setZoomToFill(bool /*on*/, const QPointF & /*center*/ = QPointF(-1, -1)) 0097 { 0098 } 0099 0100 virtual bool zoomToFill() const 0101 { 0102 return false; 0103 } 0104 0105 virtual qreal zoom() const 0106 { 0107 return 0; 0108 } 0109 0110 virtual void setZoom(qreal /*zoom*/, const QPointF & /*center*/ = QPointF(-1, -1)) 0111 { 0112 } 0113 0114 virtual qreal computeZoomToFit() const 0115 { 0116 return 1.; 0117 } 0118 0119 virtual qreal computeZoomToFill() const 0120 { 0121 return 1.; 0122 } 0123 /** @} */ 0124 0125 virtual Document::Ptr document() const = 0; 0126 virtual void setDocument(const Document::Ptr &) = 0; 0127 0128 virtual void loadConfig() 0129 { 0130 } 0131 0132 virtual QPointF scrollPos() const 0133 { 0134 return QPointF(0, 0); 0135 } 0136 virtual void setScrollPos(const QPointF & /*pos*/) 0137 { 0138 } 0139 0140 /** 0141 * Rectangle within the item which is actually used to show the document. 0142 * In item coordinates. 0143 */ 0144 virtual QRectF visibleDocumentRect() const; 0145 0146 protected: 0147 void setWidget(QGraphicsWidget *widget) 0148 { 0149 mWidget = widget; 0150 } 0151 0152 Q_SIGNALS: 0153 /** 0154 * @addgroup zooming functions 0155 * @{ 0156 */ 0157 void zoomChanged(qreal); 0158 0159 void zoomToFitChanged(bool); 0160 0161 void zoomToFillChanged(bool); 0162 0163 void zoomInRequested(const QPointF &); 0164 0165 void zoomOutRequested(const QPointF &); 0166 /** @} */ 0167 0168 void scrollPosChanged(); 0169 0170 /** 0171 * Emitted when the adapter is done showing the document for the first time 0172 */ 0173 void completed(); 0174 0175 void previousImageRequested(); 0176 0177 void nextImageRequested(); 0178 0179 void toggleFullScreenRequested(); 0180 0181 private: 0182 QGraphicsWidget *mWidget = nullptr; 0183 }; 0184 0185 /** 0186 * An empty adapter, used when no document is displayed 0187 */ 0188 class EmptyAdapter : public AbstractDocumentViewAdapter 0189 { 0190 Q_OBJECT 0191 public: 0192 EmptyAdapter(); 0193 MimeTypeUtils::Kind kind() const override 0194 { 0195 return MimeTypeUtils::KIND_UNKNOWN; 0196 } 0197 Document::Ptr document() const override 0198 { 0199 return {}; 0200 } 0201 void setDocument(const Document::Ptr &) override 0202 { 0203 } 0204 }; 0205 0206 } // namespace 0207 0208 #endif /* ABSTRACTDOCUMENTVIEWADAPTER_H */