Vidalia 0.3.1
ZImageView.h
Go to the documentation of this file.
1/*
2** This file is part of Vidalia, and is subject to the license terms in the
3** LICENSE file, found in the top level directory of this distribution. If you
4** did not receive the LICENSE file with this file, you may obtain it from the
5** Vidalia source package distributed by the Vidalia Project at
6** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7** including this file, may be copied, modified, propagated, or distributed
8** except according to the terms described in the LICENSE file.
9*/
10
11/*
12** \file ZImageView.h
13** \brief Displays an image and allows zooming and panning
14*/
15
16#ifndef ZIMAGEVIEW_H
17#define ZIMAGEVIEW_H
18
19#include <QImage>
20#include <QPixmap>
21#include <QWidget>
22
23
24class ZImageView : public QWidget
25{
26 Q_OBJECT
27
28public:
29 /** Default constructor. */
30 ZImageView(QWidget *parent = 0);
31 /** Sets the displayed image. */
32 void setImage(QImage& pixmap);
33
34public slots:
35 /** Resets the center zoom point back to the center of the viewport. */
36 void resetZoomPoint();
37 /** Sets the current zoom level to the given percent. */
38 void zoom(float pct);
39 /** Sets the current zoom level to the given percent and scrolls the window
40 * to place the specified point in the middle. */
41 void zoom(QPoint zoomAt, float pct);
42 /** Zooms into the displayed image by 5% */
43 void zoomIn();
44 /** Zooms away from the displayed image by 5% */
45 void zoomOut();
46
47protected:
48 /** Virtual method to let subclasses paint on the image before it's scaled. */
49 virtual void paintImage(QPainter *painter) { Q_UNUSED(painter); }
50 /** Updates the viewport and repaints the displayed image. */
51 virtual void paintEvent(QPaintEvent*);
52 /** Handles the user pressing a mouse button. */
53 virtual void mousePressEvent(QMouseEvent* e);
54 /** Handles the user releasing a mouse button. */
55 virtual void mouseReleaseEvent(QMouseEvent* e);
56 /** Handles the user moving the mouse. */
57 virtual void mouseMoveEvent(QMouseEvent* e);
58 /** Handles the user double-clicking a mouse button. */
59 virtual void mouseDoubleClickEvent(QMouseEvent *e);
60 /** Handles the wheel events. */
61 virtual void wheelEvent(QWheelEvent *e);
62
63 /** Update the viewport. This will set _view to a region that,
64 * when copied from the image and scaled to the screen size, will
65 * show what is expected. The _view may be larger in one or more
66 * directions than the image, and you must deal with the
67 * non-overlapping regions. */
68 void updateViewport(int screendx=0, int screendy=0);
69 /** Redraws the scaled image in the viewport. */
70 void drawScaledImage();
71
72private:
73 float _zoom; /**< The current zoom level. */
74 QImage _image; /**< The displayed image. */
75 float _padding; /**< Amount of padding to use on the side of the image. */
76 float _maxZoomFactor; /**< Maximum amount to zoom into the image. */
77
78 int _mouseX; /**< The x-coordinate of the current mouse position. */
79 int _mouseY; /**< The y-coordinate of the current mouse position. */
80
81 QRect _view; /**< The displayed viewport. */
82 float _desiredX; /**< The X value we desire (???). */
83 float _desiredY; /**< The Y value we desire (???). */
84};
85
86#endif
87
QRect _view
Definition: ZImageView.h:81
float _zoom
Definition: ZImageView.h:73
ZImageView(QWidget *parent=0)
Definition: ZImageView.cpp:33
virtual void mouseReleaseEvent(QMouseEvent *e)
Definition: ZImageView.cpp:320
void zoom(float pct)
Definition: ZImageView.cpp:288
int _mouseX
Definition: ZImageView.h:78
float _maxZoomFactor
Definition: ZImageView.h:76
float _padding
Definition: ZImageView.h:75
void zoomIn()
Definition: ZImageView.cpp:296
QImage _image
Definition: ZImageView.h:74
void setImage(QImage &pixmap)
Definition: ZImageView.cpp:51
float _desiredY
Definition: ZImageView.h:83
virtual void mouseDoubleClickEvent(QMouseEvent *e)
Definition: ZImageView.cpp:332
virtual void mousePressEvent(QMouseEvent *e)
Definition: ZImageView.cpp:310
virtual void mouseMoveEvent(QMouseEvent *e)
Definition: ZImageView.cpp:351
void resetZoomPoint()
Definition: ZImageView.cpp:260
void updateViewport(int screendx=0, int screendy=0)
Definition: ZImageView.cpp:155
void drawScaledImage()
Definition: ZImageView.cpp:64
void zoomOut()
Definition: ZImageView.cpp:303
int _mouseY
Definition: ZImageView.h:79
virtual void wheelEvent(QWheelEvent *e)
Definition: ZImageView.cpp:366
virtual void paintImage(QPainter *painter)
Definition: ZImageView.h:49
float _desiredX
Definition: ZImageView.h:82
virtual void paintEvent(QPaintEvent *)
Definition: ZImageView.cpp:270