FotoSHOCK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
QPreview.h
1 /*
2  * Copyright 2011, 2012 Lukas Jirkovsky
3  *
4  * This file is part of FotoSHOCK.
5  *
6  * FotoSHOCK is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, version 3 of the License.
9  *
10  * FotoSHOCK 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 FotoSHOCK. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef QPREVIEW_H
20 #define QPREVIEW_H
21 
22 #include "MipMap.hpp"
23 
24 #include <QGLWidget>
25 
26 class QPreview : public QGLWidget {
27 Q_OBJECT
28  public:
29  QPreview(FotoSHOCKcore::MipMap* mipmap, QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0);
30  virtual ~QPreview();
31  virtual QSize sizeHint() const;
32  public slots:
33  void changeZoom(int zoom);
34  void zoomIn();
35  void zoomOut();
36  void fitWindow();
37  void forceRedraw();
38  signals:
39  void zoomChanged(int zoom);
40  void ROIchanged(unsigned int x, unsigned int y, unsigned int sizeX, unsigned int sizeY, const int mipmapLevel);
41  protected:
42  virtual void initializeGL();
43  virtual void paintGL();
44  virtual void resizeGL (int w, int h);
45 
46  virtual void mousePressEvent(QMouseEvent* event);
47  virtual void mouseReleaseEvent(QMouseEvent* event);
48  virtual void mouseMoveEvent(QMouseEvent* event);
49  private:
50  void updateUsedTiles(unsigned int width, unsigned int height);
51  inline void updateViewportOffset(unsigned int width, unsigned int height);
52  void loadTextures();
53 
54  // current scale in %, where 100% is the original size, 200% is two times bigger
55  unsigned int m_zoom;
56  // zoom relative to the current mipmap level
57  float m_levelZoom;
58  // mipmap associated with the preview
59  FotoSHOCKcore::MipMap* m_mipmap;
60  // mipmap level corresponding to the current zoom
61  int m_mipmapLevel;
62  // tile extent for the curent mipmap level
63  unsigned int m_tileExtent;
64  // tile extent scaled for the display
65  unsigned int m_tileExtentScaled;
66  unsigned int m_numOfTilesHoriz;
67 
68  // format and type of the data in the mipmap
69  /*GLenum m_format;
70  GLenum m_type;*/
71  // all textures for the current mipmap level
72  // only the visible ones + 1 one more is actually loaded
73  // free them using glDeleteTextures
74  GLuint* m_textures;
75  size_t m_texturesSize;
76 
77  // true if the viewport is moved
78  bool m_move;
79  // position where the move started
80  int startX;
81  int startY;
82  // current upper left corner of the viewport
83  // absolute value
84  int x;
85  int y;
86  // offset of a viewport, used to center the image on the widget
87  int xViewportOffset;
88  int yViewportOffset;
89 
90  unsigned int startTileVert;
91  unsigned int endTileVert;
92  unsigned int startTileHoriz;
93  unsigned int endTileHoriz;
94  // offset from the upper left corner
95  unsigned int xOffset;
96  unsigned int yOffset;
97 };
98 
99 #endif