1 /************************************************************************** 2 * This file is part of the Fraqtive program 3 * Copyright (C) 2004-2012 Michał Męciński 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 **************************************************************************/ 18 19 #ifndef IMAGEVIEW_H 20 #define IMAGEVIEW_H 21 22 #include <QWidget> 23 24 #include "abstractview.h" 25 #include "datastructures.h" 26 27 class FractalPresenter; 28 29 class ImageView : public QWidget, public AbstractView 30 { 31 Q_OBJECT 32 public: 33 ImageView( QWidget* parent, FractalPresenter* presenter ); 34 ~ImageView(); 35 36 public: 37 void setInteractive( bool interactive ); 38 image()39 QImage image() const { return m_image; } 40 41 public: // AbstractView implementation 42 void clearView(); 43 44 void transformView( const QTransform& transform ); 45 46 void initialUpdate( const FractalData* data ); 47 void partialUpdate( const FractalData* data ); 48 void fullUpdate( const FractalData* data ); 49 50 void setColorSettings( const Gradient& gradient, const QColor& backgroundColor, const ColorMapping& mapping ); 51 void setGradient( const Gradient& gradient ); 52 void setBackgroundColor( const QColor& color ); 53 void setColorMapping( const ColorMapping& mapping ); 54 55 void setViewSettings( const ViewSettings& settings ); 56 57 void setAnimationState( const AnimationState& state ); 58 59 protected: // overrides 60 void resizeEvent( QResizeEvent* e ); 61 void paintEvent( QPaintEvent* e ); 62 63 void mousePressEvent( QMouseEvent* e ); 64 void mouseMoveEvent( QMouseEvent* e ); 65 void mouseReleaseEvent( QMouseEvent* e ); 66 void mouseDoubleClickEvent( QMouseEvent* e ); 67 void wheelEvent( QWheelEvent* e ); 68 void leaveEvent( QEvent* e ); 69 70 void keyPressEvent( QKeyEvent* e ); 71 72 private: 73 void updateGradient(); 74 void updateBackground(); 75 void updateImage(); 76 77 void drawImage( const FractalData* data, const QRect& region ); 78 79 void calculateScale(); 80 81 QTransform worldTransform(); 82 83 private: 84 enum Tracking 85 { 86 NoTracking, 87 DragMove, 88 DragRotate, 89 DragZoomIn, 90 DragZoomOut, 91 RotateCenter, 92 ZoomCenter, 93 ZoomPoint 94 }; 95 96 private: 97 FractalPresenter* m_presenter; 98 99 bool m_interactive; 100 101 QImage m_image; 102 103 Gradient m_gradient; 104 QColor m_backgroundColor; 105 ColorMapping m_colorMapping; 106 107 ViewSettings m_settings; 108 109 AnimationState m_animationState; 110 111 QRgb* m_gradientCache; 112 113 QRect m_updatedRegion; 114 115 QTransform m_scale; 116 QTransform m_invScale; 117 118 Tracking m_tracking; 119 QPoint m_trackStart; 120 121 QTransform m_transform; 122 }; 123 124 #endif 125