00001 /* 00002 Copyright © 2010 alexandre petitjean 00003 00004 This file is part of QExtend. 00005 00006 QExtend is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 any later version. 00010 00011 QExtend 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 QExtend. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 #ifndef QEXTEND_IMAGEVIEWER_H 00021 #define QEXTEND_IMAGEVIEWER_H 00022 00023 #include <QtGui/QImage> 00024 #include <QtGui/QLabel> 00025 #include <QtGui/QScrollArea> 00026 #include <QtGui/QWidget> 00027 00028 #include <QExtend/Core/qextend_global> 00029 00030 namespace QExtend { 00031 00032 00034 00036 00044 class QEXTEND_EXPORT ImageViewer : public QScrollArea 00045 { 00046 Q_OBJECT 00047 Q_PROPERTY(MouseInteractionMode mouseInteraction WRITE setMouseInteraction READ mouseInteraction) 00048 00049 public: 00050 00051 00053 00054 00056 enum MouseInteractionMode 00057 { 00058 NoInteraction, 00059 DragAndWheelzoom, 00060 DragToZoom 00061 }; 00062 00063 private: 00064 // This part from Qt 4.6 Image Viewer example 00065 double m_scaleFactor; 00066 void scaleImage(double factor); 00067 void adjustScrollBar(QScrollBar *scrollBar, double factor); 00068 00069 QLabel m_imageRender; 00070 MouseInteractionMode m_mouseInteraction; 00071 bool m_isDragging; 00072 QPointF m_previousPos; 00073 00074 protected: 00075 void mouseMoveEvent(QMouseEvent *event); 00076 void mousePressEvent(QMouseEvent *event); 00077 void mouseReleaseEvent(QMouseEvent *event); 00078 void wheelEvent(QWheelEvent *event); 00079 00080 public: 00081 00082 00084 00085 00087 00094 ImageViewer(QWidget *parent = 0); 00095 00096 00097 00099 00100 00102 00109 void loadImage(const QString &imagePath); 00110 00111 00113 00114 00116 00123 void loadImage(const QImage &image); 00124 00125 00127 00128 00130 00137 void loadImage(const QPixmap &pixmap); 00138 00139 00140 00142 00143 00145 00152 void setMouseInteraction(MouseInteractionMode interaction); 00153 00154 00156 00157 00159 00166 MouseInteractionMode mouseInteraction() const; 00167 }; 00168 } 00169 00170 #endif //QEXTEND_IMAGEVIEWER_H
© 2000-2024 - www.developpez.com