00001 /**************************************************************** 00002 * Vidalia is distributed under the following license: 00003 * 00004 * Copyright (C) 2006-2007, Matt Edman, Justin Hipple 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 ****************************************************************/ 00021 00022 /** 00023 * \file zimageview.h 00024 * \version $Id: zimageview.h 1599 2007-01-20 03:57:54Z edmanm $ 00025 * \brief Displays an image and allows zooming and panning 00026 */ 00027 00028 #ifndef ZIMAGEVIEW_H 00029 #define ZIMAGEVIEW_H 00030 00031 #include <QImage> 00032 #include <QPixmap> 00033 #include <QWidget> 00034 00035 00036 class ZImageView : public QWidget 00037 { 00038 Q_OBJECT 00039 00040 public: 00041 /** Default constructor. */ 00042 ZImageView(QWidget *parent = 0); 00043 /** Sets the displayed image. */ 00044 void setImage(QImage& pixmap); 00045 00046 public slots: 00047 /** Resets the center zoom point back to the center of the viewport. */ 00048 void resetZoomPoint(); 00049 /** Sets the current zoom level to the given percent. */ 00050 void zoom(float pct); 00051 /** Sets the current zoom level to the given percent and scrolls the window 00052 * to place the specified point in the middle. */ 00053 void zoom(QPoint zoomAt, float pct); 00054 /** Zooms into the displayed image by 5% */ 00055 void zoomIn(); 00056 /** Zooms away from the displayed image by 5% */ 00057 void zoomOut(); 00058 00059 protected: 00060 /** Virtual method to let subclasses paint on the image before it's scaled. */ 00061 virtual void paintImage(QPainter *painter) { Q_UNUSED(painter); } 00062 /** Updates the viewport and repaints the displayed image. */ 00063 virtual void paintEvent(QPaintEvent*); 00064 /** Handles the user pressing a mouse button. */ 00065 virtual void mousePressEvent(QMouseEvent* e); 00066 /** Handles the user releasing a mouse button. */ 00067 virtual void mouseReleaseEvent(QMouseEvent* e); 00068 /** Handles the user moving the mouse. */ 00069 virtual void mouseMoveEvent(QMouseEvent* e); 00070 /** Handles the user double-clicking a mouse button. */ 00071 virtual void mouseDoubleClickEvent(QMouseEvent *e); 00072 00073 /** Update the viewport. This will set _view to a region that, 00074 * when copied from the image and scaled to the screen size, will 00075 * show what is expected. The _view may be larger in one or more 00076 * directions than the image, and you must deal with the 00077 * non-overlapping regions. */ 00078 void updateViewport(int screendx=0, int screendy=0); 00079 /** Redraws the scaled image in the viewport. */ 00080 void drawScaledImage(); 00081 00082 private: 00083 float _zoom; /**< The current zoom level. */ 00084 QImage _image; /**< The displayed image. */ 00085 float _padding; /**< Amount of padding to use on the side of the image. */ 00086 float _maxZoomFactor; /**< Maximum amount to zoom into the image. */ 00087 00088 int _mouseX; /**< The x-coordinate of the current mouse position. */ 00089 int _mouseY; /**< The y-coordinate of the current mouse position. */ 00090 00091 QRect _view; /**< The displayed viewport. */ 00092 float _desiredX; /**< The X value we desire (???). */ 00093 float _desiredY; /**< The Y value we desire (???). */ 00094 }; 00095 00096 #endif 00097