zimageview.h

Go to the documentation of this file.
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 ** \version $Id: zimageview.h 2624 2008-05-30 03:58:17Z edmanm $
00014 ** \brief Displays an image and allows zooming and panning
00015 */
00016 
00017 #ifndef ZIMAGEVIEW_H
00018 #define ZIMAGEVIEW_H
00019 
00020 #include <QImage>
00021 #include <QPixmap>
00022 #include <QWidget>
00023 
00024 
00025 class ZImageView : public QWidget
00026 {
00027   Q_OBJECT
00028 
00029 public:
00030   /** Default constructor. */
00031   ZImageView(QWidget *parent = 0);
00032   /** Sets the displayed image. */
00033   void setImage(QImage& pixmap);
00034   
00035 public slots:
00036   /** Resets the center zoom point back to the center of the viewport. */
00037   void resetZoomPoint();
00038   /** Sets the current zoom level to the given percent. */
00039   void zoom(float pct);
00040   /** Sets the current zoom level to the given percent and scrolls the window
00041    * to place the specified point in the middle. */
00042   void zoom(QPoint zoomAt, float pct);
00043   /** Zooms into the displayed image by 5% */
00044   void zoomIn();
00045   /** Zooms away from the displayed image by 5% */
00046   void zoomOut();
00047 
00048 protected:
00049   /** Virtual method to let subclasses paint on the image before it's scaled. */
00050   virtual void paintImage(QPainter *painter) { Q_UNUSED(painter); }
00051   /** Updates the viewport and repaints the displayed image. */
00052   virtual void paintEvent(QPaintEvent*);
00053   /** Handles the user pressing a mouse button. */
00054   virtual void mousePressEvent(QMouseEvent* e);
00055   /** Handles the user releasing a mouse button. */
00056   virtual void mouseReleaseEvent(QMouseEvent* e);
00057   /** Handles the user moving the mouse. */
00058   virtual void mouseMoveEvent(QMouseEvent* e);
00059   /** Handles the user double-clicking a mouse button. */
00060   virtual void mouseDoubleClickEvent(QMouseEvent *e);
00061   /** Handles the wheel events. */
00062   virtual void wheelEvent(QWheelEvent *e);
00063 
00064   /** Update the viewport.  This will set _view to a region that,
00065    *  when copied from the image and scaled to the screen size, will
00066    *  show what is expected.  The _view may be larger in one or more
00067    *  directions than the image, and you must deal with the 
00068    *  non-overlapping regions. */
00069   void updateViewport(int screendx=0, int screendy=0);
00070   /** Redraws the scaled image in the viewport. */
00071   void drawScaledImage();
00072   
00073 private:
00074   float _zoom;     /**< The current zoom level. */
00075   QImage _image;   /**< The displayed image. */
00076   float _padding;  /**< Amount of padding to use on the side of the image. */
00077   float _maxZoomFactor;  /**< Maximum amount to zoom into the image. */
00078 
00079   int  _mouseX;     /**< The x-coordinate of the current mouse position. */
00080   int  _mouseY;     /**< The y-coordinate of the current mouse position. */
00081   
00082   QRect _view;      /**< The displayed viewport. */
00083   float _desiredX;  /**< The X value we desire (???). */
00084   float _desiredY;  /**< The Y value we desire (???). */
00085 };
00086 
00087 #endif
00088 

Generated on Wed Dec 23 21:06:55 2009 for Vidalia by  doxygen 1.6.1