Vidalia 0.2.12
|
00001 /* 00002 ** This file is part of Vidalia, and is subject to the license terms in the 00003 ** LICENSE file, found in the top level directory of this distribution. If you 00004 ** did not receive the LICENSE file with this file, you may obtain it from the 00005 ** Vidalia source package distributed by the Vidalia Project at 00006 ** http://www.vidalia-project.net/. No part of Vidalia, including this file, 00007 ** may be copied, modified, propagated, or distributed except according to the 00008 ** terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file ZImageView.h 00013 ** \brief Displays an image and allows zooming and panning 00014 */ 00015 00016 #ifndef ZIMAGEVIEW_H 00017 #define ZIMAGEVIEW_H 00018 00019 #include <QImage> 00020 #include <QPixmap> 00021 #include <QWidget> 00022 00023 00024 class ZImageView : public QWidget 00025 { 00026 Q_OBJECT 00027 00028 public: 00029 /** Default constructor. */ 00030 ZImageView(QWidget *parent = 0); 00031 /** Sets the displayed image. */ 00032 void setImage(QImage& pixmap); 00033 00034 public slots: 00035 /** Resets the center zoom point back to the center of the viewport. */ 00036 void resetZoomPoint(); 00037 /** Sets the current zoom level to the given percent. */ 00038 void zoom(float pct); 00039 /** Sets the current zoom level to the given percent and scrolls the window 00040 * to place the specified point in the middle. */ 00041 void zoom(QPoint zoomAt, float pct); 00042 /** Zooms into the displayed image by 5% */ 00043 void zoomIn(); 00044 /** Zooms away from the displayed image by 5% */ 00045 void zoomOut(); 00046 00047 protected: 00048 /** Virtual method to let subclasses paint on the image before it's scaled. */ 00049 virtual void paintImage(QPainter *painter) { Q_UNUSED(painter); } 00050 /** Updates the viewport and repaints the displayed image. */ 00051 virtual void paintEvent(QPaintEvent*); 00052 /** Handles the user pressing a mouse button. */ 00053 virtual void mousePressEvent(QMouseEvent* e); 00054 /** Handles the user releasing a mouse button. */ 00055 virtual void mouseReleaseEvent(QMouseEvent* e); 00056 /** Handles the user moving the mouse. */ 00057 virtual void mouseMoveEvent(QMouseEvent* e); 00058 /** Handles the user double-clicking a mouse button. */ 00059 virtual void mouseDoubleClickEvent(QMouseEvent *e); 00060 /** Handles the wheel events. */ 00061 virtual void wheelEvent(QWheelEvent *e); 00062 00063 /** Update the viewport. This will set _view to a region that, 00064 * when copied from the image and scaled to the screen size, will 00065 * show what is expected. The _view may be larger in one or more 00066 * directions than the image, and you must deal with the 00067 * non-overlapping regions. */ 00068 void updateViewport(int screendx=0, int screendy=0); 00069 /** Redraws the scaled image in the viewport. */ 00070 void drawScaledImage(); 00071 00072 private: 00073 float _zoom; /**< The current zoom level. */ 00074 QImage _image; /**< The displayed image. */ 00075 float _padding; /**< Amount of padding to use on the side of the image. */ 00076 float _maxZoomFactor; /**< Maximum amount to zoom into the image. */ 00077 00078 int _mouseX; /**< The x-coordinate of the current mouse position. */ 00079 int _mouseY; /**< The y-coordinate of the current mouse position. */ 00080 00081 QRect _view; /**< The displayed viewport. */ 00082 float _desiredX; /**< The X value we desire (???). */ 00083 float _desiredY; /**< The Y value we desire (???). */ 00084 }; 00085 00086 #endif 00087