1 // vim: set tabstop=4 shiftwidth=4 expandtab:
2 /*
3 Gwenview: an image viewer
4 Copyright 2008 Aurélien Gâteau <agateau@kde.org>
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
19 
20 */
21 #ifndef DOCUMENTVIEW_H
22 #define DOCUMENTVIEW_H
23 
24 #include <lib/gwenviewlib_export.h>
25 
26 // Qt
27 #include <QGraphicsWidget>
28 
29 // KF
30 
31 // Local
32 #include <lib/backgroundcolorwidget/backgroundcolorwidget.h>
33 #include <lib/document/document.h>
34 
35 class QPropertyAnimation;
36 class QUrl;
37 
38 namespace Gwenview
39 {
40 class AbstractRasterImageViewTool;
41 class RasterImageView;
42 
43 struct DocumentViewPrivate;
44 
45 /**
46  * This widget can display various documents, using an instance of
47  * AbstractDocumentViewAdapter
48  */
49 class GWENVIEWLIB_EXPORT DocumentView : public QGraphicsWidget
50 {
51     Q_OBJECT
52     Q_PROPERTY(qreal zoom READ zoom WRITE setZoom NOTIFY zoomChanged)
53     Q_PROPERTY(bool zoomToFit READ zoomToFit WRITE setZoomToFit NOTIFY zoomToFitChanged)
54     Q_PROPERTY(bool zoomToFill READ zoomToFill WRITE setZoomToFill NOTIFY zoomToFillChanged)
55     Q_PROPERTY(QPoint position READ position WRITE setPosition NOTIFY positionChanged)
56 public:
57     static const int MaximumZoom;
58     static const int AnimDuration;
59 
60     struct Setup {
SetupSetup61         Setup()
62             : valid(false)
63             , zoomToFit(true)
64             , zoomToFill(false)
65             , zoom(0)
66         {
67         }
68         bool valid : 1;
69         bool zoomToFit : 1;
70         bool zoomToFill : 1;
71         qreal zoom;
72         QPointF position;
73     };
74 
75     enum AnimationMethod {
76         NoAnimation,
77         SoftwareAnimation,
78 #ifndef QT_NO_OPENGL
79         GLAnimation,
80 #endif
81     };
82 
83     /**
84      * Create a new view attached to scene. We need the scene to be able to
85      * install scene event filters.
86      */
87     explicit DocumentView(QGraphicsScene *scene);
88     ~DocumentView() override;
89 
90     Document::Ptr document() const;
91 
92     QUrl url() const;
93 
94     void openUrl(const QUrl &, const Setup &);
95 
96     Setup setup() const;
97 
98     /**
99      * Tells the current adapter to load its config. Used when the user changed
100      * the config while the view was visible.
101      */
102     void loadAdapterConfig();
103 
104     bool canZoom() const;
105 
106     qreal minimumZoom() const;
107 
108     qreal zoom() const;
109 
110     bool isCurrent() const;
111 
112     void setCurrent(bool);
113 
114     void setCompareMode(bool);
115 
116     bool zoomToFit() const;
117 
118     bool zoomToFill() const;
119 
120     QPoint position() const;
121 
122     /**
123      * Returns the RasterImageView of the current adapter, if it has one
124      */
125     RasterImageView *imageView() const;
126 
127     AbstractRasterImageViewTool *currentTool() const;
128 
129     void moveTo(const QRect &);
130     void moveToAnimated(const QRect &);
131     QPropertyAnimation *fadeIn();
132     void fadeOut();
133 
134     void setGeometry(const QRectF &rect) override;
135 
136     int sortKey() const;
137     void setSortKey(int sortKey);
138 
139     bool isAnimated() const;
140 
141     /**
142      * Sets the opacity on the installed QGraphicsOpacityEffect.
143      * Use this instead of setOpacity().
144      */
145     void setGraphicsEffectOpacity(qreal opacity);
146 
147 public Q_SLOTS:
148     void setZoom(qreal);
149 
150     void setZoomToFit(bool);
151     void toggleZoomToFit();
152 
153     void setZoomToFill(bool);
154     void toggleZoomToFill();
155 
156     void zoomActualSize();
157 
158     void toggleBirdEyeView();
159 
160     void setBackgroundColorMode(BackgroundColorWidget::ColorMode colorMode);
161 
162     void setPosition(const QPoint &);
163 
164     void hideAndDeleteLater();
165 
166 Q_SIGNALS:
167     /**
168      * Emitted when the part has finished loading
169      */
170     void completed();
171 
172     void previousImageRequested();
173 
174     void nextImageRequested();
175 
176     void openUrlRequested(const QUrl &);
177 
178     void openDirUrlRequested(const QUrl &);
179 
180     void captionUpdateRequested(const QString &);
181 
182     void toggleFullScreenRequested();
183 
184     void videoFinished();
185 
186     void backgroundColorModeChanged(BackgroundColorWidget::ColorMode);
187 
188     void minimumZoomChanged(qreal);
189 
190     void zoomChanged(qreal);
191 
192     void adapterChanged();
193 
194     void focused(Gwenview::DocumentView *);
195 
196     void zoomToFitChanged(bool);
197 
198     void zoomToFillChanged(bool);
199 
200     void positionChanged();
201 
202     void hudTrashClicked(Gwenview::DocumentView *);
203     void hudDeselectClicked(Gwenview::DocumentView *);
204 
205     void fadeInFinished(Gwenview::DocumentView *);
206 
207     void contextMenuRequested();
208 
209     void currentToolChanged(AbstractRasterImageViewTool *);
210 
211     void isAnimatedChanged();
212 
213 protected:
214     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
215 
216     void resizeEvent(QGraphicsSceneResizeEvent *event) override;
217     void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
218     void wheelEvent(QGraphicsSceneWheelEvent *event) override;
219     void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
220     bool sceneEventFilter(QGraphicsItem *, QEvent *) override;
221     void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override;
222     void dropEvent(QGraphicsSceneDragDropEvent *event) override;
223 
224 private Q_SLOTS:
225     void finishOpenUrl();
226     void slotCompleted();
227     void slotLoadingFailed();
228 
229     void zoomIn(QPointF center = QPointF(-1, -1));
230     void zoomOut(QPointF center = QPointF(-1, -1));
231 
232     void slotZoomChanged(qreal);
233 
234     void slotBusyChanged(const QUrl &, bool);
235 
236     void emitHudTrashClicked();
237     void emitHudDeselectClicked();
238     void emitFocused();
239 
240     void slotFadeInFinished();
241 
242     void dragThumbnailLoaded(const KFileItem &, const QPixmap &);
243     void dragThumbnailLoadingFailed(const KFileItem &);
244     void setPinchParameter(qint64 timeStamp);
245     void zoomGesture(qreal newZoom, const QPoint &pos, qint64 timeStamp);
246     void rotationsGesture(qreal);
247     void swipeRight();
248     void swipeLeft();
249     void panGesture(const QPointF &delta);
250     void startDragFromTouch(const QPoint &pos);
251 
252 private:
253     friend struct DocumentViewPrivate;
254     DocumentViewPrivate *const d;
255 
256     void createAdapterForDocument();
257 };
258 
259 } // namespace
260 
261 #endif /* DOCUMENTVIEW_H */
262