File indexing completed on 2024-05-12 04:19:39

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 DOCUMENTVIEW_H
0022 #define DOCUMENTVIEW_H
0023 
0024 #include <lib/gwenviewlib_export.h>
0025 
0026 // Qt
0027 #include <QGraphicsWidget>
0028 
0029 // KF
0030 
0031 // Local
0032 #include <lib/document/document.h>
0033 
0034 class QPropertyAnimation;
0035 class QUrl;
0036 
0037 namespace Gwenview
0038 {
0039 class AbstractRasterImageViewTool;
0040 class RasterImageView;
0041 
0042 struct DocumentViewPrivate;
0043 
0044 /**
0045  * This widget can display various documents, using an instance of
0046  * AbstractDocumentViewAdapter
0047  */
0048 class GWENVIEWLIB_EXPORT DocumentView : public QGraphicsWidget
0049 {
0050     Q_OBJECT
0051     Q_PROPERTY(qreal zoom READ zoom WRITE setZoom NOTIFY zoomChanged)
0052     Q_PROPERTY(bool zoomToFit READ zoomToFit WRITE setZoomToFit NOTIFY zoomToFitChanged)
0053     Q_PROPERTY(bool zoomToFill READ zoomToFill WRITE setZoomToFill NOTIFY zoomToFillChanged)
0054     Q_PROPERTY(QPoint position READ position WRITE setPosition NOTIFY positionChanged)
0055 public:
0056     static const int MaximumZoom;
0057     static const int AnimDuration;
0058 
0059     struct Setup {
0060         Setup()
0061             : valid(false)
0062             , zoomToFit(true)
0063             , zoomToFill(false)
0064             , zoom(0)
0065         {
0066         }
0067         bool valid : 1;
0068         bool zoomToFit : 1;
0069         bool zoomToFill : 1;
0070         qreal zoom;
0071         QPointF position;
0072     };
0073 
0074     enum AnimationMethod {
0075         NoAnimation,
0076         SoftwareAnimation,
0077 #ifndef QT_NO_OPENGL
0078         GLAnimation,
0079 #endif
0080     };
0081     enum BackgroundColorMode { Auto = 0, Light = 1, Neutral = 2, Dark = 3 };
0082     Q_ENUM(BackgroundColorMode)
0083 
0084     /**
0085      * Create a new view attached to scene. We need the scene to be able to
0086      * install scene event filters.
0087      */
0088     explicit DocumentView(QGraphicsScene *scene);
0089     ~DocumentView() override;
0090 
0091     Document::Ptr document() const;
0092 
0093     QUrl url() const;
0094 
0095     void openUrl(const QUrl &, const Setup &);
0096 
0097     Setup setup() const;
0098 
0099     /**
0100      * Tells the current adapter to load its config. Used when the user changed
0101      * the config while the view was visible.
0102      */
0103     void loadAdapterConfig();
0104 
0105     bool canZoom() const;
0106 
0107     qreal minimumZoom() const;
0108 
0109     qreal zoom() const;
0110 
0111     bool isCurrent() const;
0112 
0113     void setCurrent(bool);
0114 
0115     void setCompareMode(bool);
0116 
0117     bool zoomToFit() const;
0118 
0119     bool zoomToFill() const;
0120 
0121     QPoint position() const;
0122 
0123     /**
0124      * Returns the RasterImageView of the current adapter, if it has one
0125      */
0126     RasterImageView *imageView() const;
0127 
0128     AbstractRasterImageViewTool *currentTool() const;
0129 
0130     void moveTo(const QRect &);
0131     void moveToAnimated(const QRect &);
0132     QPropertyAnimation *fadeIn();
0133     void fadeOut();
0134 
0135     void setGeometry(const QRectF &rect) override;
0136 
0137     int sortKey() const;
0138     void setSortKey(int sortKey);
0139 
0140     bool isAnimated() const;
0141 
0142     /**
0143      * Sets the opacity on the installed QGraphicsOpacityEffect.
0144      * Use this instead of setOpacity().
0145      */
0146     void setGraphicsEffectOpacity(qreal opacity);
0147 
0148 public Q_SLOTS:
0149     void setZoom(qreal);
0150 
0151     void setZoomToFit(bool);
0152     void toggleZoomToFit();
0153 
0154     void setZoomToFill(bool);
0155     void toggleZoomToFill();
0156 
0157     void zoomActualSize();
0158 
0159     void toggleBirdEyeView();
0160 
0161     void setBackgroundColorMode(BackgroundColorMode colorMode);
0162 
0163     void setPosition(const QPoint &);
0164 
0165     void hideAndDeleteLater();
0166 
0167 Q_SIGNALS:
0168     /**
0169      * Emitted when the part has finished loading
0170      */
0171     void completed();
0172 
0173     void previousImageRequested();
0174 
0175     void nextImageRequested();
0176 
0177     void openUrlRequested(const QUrl &);
0178 
0179     void openDirUrlRequested(const QUrl &);
0180 
0181     void captionUpdateRequested(const QString &);
0182 
0183     void toggleFullScreenRequested();
0184 
0185     void videoFinished();
0186 
0187     void backgroundColorModeChanged(BackgroundColorMode);
0188 
0189     void minimumZoomChanged(qreal);
0190 
0191     void zoomChanged(qreal);
0192 
0193     void adapterChanged();
0194 
0195     void focused(Gwenview::DocumentView *);
0196 
0197     void zoomToFitChanged(bool);
0198 
0199     void zoomToFillChanged(bool);
0200 
0201     void positionChanged();
0202 
0203     void hudTrashClicked(Gwenview::DocumentView *);
0204     void hudDeselectClicked(Gwenview::DocumentView *);
0205 
0206     void fadeInFinished(Gwenview::DocumentView *);
0207 
0208     void contextMenuRequested();
0209 
0210     void currentToolChanged(AbstractRasterImageViewTool *);
0211 
0212     void isAnimatedChanged();
0213 
0214     /** Is emitted when the image loading took long enough that we start showing a loading indicator.
0215      * This happens after a time frame that is long enough that the user would wonder if anything is
0216      * happening at all.
0217      */
0218     void indicateLoadingToUser();
0219 
0220 protected:
0221     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
0222 
0223     void resizeEvent(QGraphicsSceneResizeEvent *event) override;
0224     void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
0225     void wheelEvent(QGraphicsSceneWheelEvent *event) override;
0226     void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
0227     bool sceneEventFilter(QGraphicsItem *, QEvent *) override;
0228     void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override;
0229     void dropEvent(QGraphicsSceneDragDropEvent *event) override;
0230 
0231 private Q_SLOTS:
0232     void finishOpenUrl();
0233     void slotCompleted();
0234     void slotLoadingFailed();
0235 
0236     void zoomContinuous(int delta, QPointF center = QPointF(-1, -1));
0237     void zoomIn(QPointF center = QPointF(-1, -1));
0238     void zoomOut(QPointF center = QPointF(-1, -1));
0239 
0240     void slotZoomChanged(qreal);
0241 
0242     void slotBusyChanged(const QUrl &, bool);
0243 
0244     void emitHudTrashClicked();
0245     void emitHudDeselectClicked();
0246     void emitFocused();
0247 
0248     void slotFadeInFinished();
0249 
0250     void dragThumbnailLoaded(const KFileItem &, const QPixmap &);
0251     void dragThumbnailLoadingFailed(const KFileItem &);
0252     void setPinchParameter(qint64 timeStamp);
0253     void zoomGesture(qreal newZoom, const QPoint &pos, qint64 timeStamp);
0254     void rotationsGesture(qreal);
0255     void swipeRight();
0256     void swipeLeft();
0257     void panGesture(const QPointF &delta);
0258     void startDragFromTouch(const QPoint &pos);
0259 
0260 private:
0261     friend struct DocumentViewPrivate;
0262     DocumentViewPrivate *const d;
0263 
0264     void createAdapterForDocument();
0265 };
0266 
0267 } // namespace
0268 
0269 #endif /* DOCUMENTVIEW_H */