2 Gwenview: an image viewer
3 Copyright 2007 Aurélien Gâteau <aurelien.gateau@free.fr>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <lib/gwenviewlib_export.h>
26 #include <QAbstractScrollArea>
29 #include <lib/document/document.h>
33 class AbstractImageViewTool
;
35 class ImageViewPrivate
;
36 class GWENVIEWLIB_EXPORT ImageView
: public QAbstractScrollArea
{
39 enum AlphaBackgroundMode
{
40 AlphaBackgroundCheckBoard
,
44 ImageView(QWidget
* parent
);
48 * Defines the tool to display on the view. if @p tool is 0, fallback to
52 void setCurrentTool(AbstractImageViewTool
* tool
);
53 AbstractImageViewTool
* currentTool() const;
56 * This is the tool which the view will fallback to if one calls
59 void setDefaultTool(AbstractImageViewTool
*);
60 AbstractImageViewTool
* defaultTool() const;
62 void setAlphaBackgroundMode(AlphaBackgroundMode mode
);
64 void setAlphaBackgroundColor(const QColor
& color
);
66 void setEnlargeSmallerImages(bool value
);
68 void setDocument(Document::Ptr document
);
70 Document::Ptr
document() const;
73 * Change zoom level, making sure the point at @p center stays at the
74 * same position after zooming, if possible.
75 * @param zoom the zoom level
76 * @param center the center point, in viewport coordinates
78 void setZoom(qreal zoom
, const QPoint
& center
= QPoint(-1, -1));
82 bool zoomToFit() const;
84 QPoint
imageOffset() const;
86 QPoint
mapToViewport(const QPoint
& src
) const;
87 QPoint
mapToImage(const QPoint
& src
) const;
89 QRect
mapToViewport(const QRect
& src
) const;
90 QRect
mapToImage(const QRect
& src
) const;
92 QPointF
mapToViewportF(const QPointF
& src
) const;
93 QPointF
mapToImageF(const QPointF
& src
) const;
95 QRectF
mapToViewportF(const QRectF
& src
) const;
96 QRectF
mapToImageF(const QRectF
& src
) const;
98 qreal
computeZoomToFit() const;
99 qreal
computeZoomToFitWidth() const;
100 qreal
computeZoomToFitHeight() const;
103 void zoomChanged(qreal
);
106 void setZoomToFit(bool on
);
109 virtual void paintEvent(QPaintEvent
*);
111 virtual void resizeEvent(QResizeEvent
*);
113 virtual void scrollContentsBy(int dx
, int dy
);
115 virtual void showEvent(QShowEvent
*);
116 virtual void hideEvent(QHideEvent
*);
118 virtual void mousePressEvent(QMouseEvent
*);
119 virtual void mouseMoveEvent(QMouseEvent
*);
120 virtual void mouseReleaseEvent(QMouseEvent
*);
121 virtual void wheelEvent(QWheelEvent
*);
122 virtual void keyPressEvent(QKeyEvent
*);
123 virtual void keyReleaseEvent(QKeyEvent
*);
126 void slotDocumentMetaInfoLoaded();
127 void slotDocumentIsAnimatedUpdated();
130 * This method performs the necessary adjustments to get the view ready to
131 * display the document set with setDocument(). It needs to be postponed
132 * because setDocument() can be called with a document which has not been
133 * loaded yet and whose size is unknown.
135 void finishSetDocument();
136 void updateFromScaler(int left
, int top
, const QImage
& image
);
137 void updateImageRect(const QRect
&);
140 void updateScrollBars();
142 ImageViewPrivate
* const d
;
147 #endif /* IMAGEVIEW_H */