Quark  0.1
ImageViewerPanel.h++
Go to the documentation of this file.
1 
2 #ifndef __libquark_gui_ImageViewerPanel_hxx
3 #define __libquark_gui_ImageViewerPanel_hxx
4 
5 #include <quark/Quark.h++>
6 
7 #include <QLabel>
8 #include <QMouseEvent>
9 #include <QPixmap>
10 #include <QRubberBand>
11 
12 namespace quark {
13 namespace gui {
14 
21 class ImageViewerPanel : public QLabel
22 {
23  Q_OBJECT;
24 
25  public:
26 
28  ImageViewerPanel(QWidget *parent = NULL);
29 
31  virtual ~ImageViewerPanel();
32 
38  void setAllowSelection(bool allowSelection);
39 
43  QPixmap image() const
44  { return(_pixmap); }
45 
50  int imageWidth() const
51  { return(_pixmap.width()); }
52 
57  int imageHeight() const
58  { return(_pixmap.height()); }
59 
63  QRect selection() const;
64 
68  float scaleFactor() const
69  { return(_scaleFactor); }
70 
71  public slots:
72 
74  void setImage(QPixmap pixmap);
75 
80  void zoomIn();
81 
86  void zoomOut();
87 
91  void zoomToFit(const QRect &rect);
92 
94  void zoomReset();
95 
97  void rotateLeft();
98 
100  void rotateRight();
101 
103  void crop(const QRect &rect);
104 
106  void clearSelection();
107 
108  signals:
109 
111  void imageSizeChanged(QSize size);
112 
114  void zoomScaleChanged(float scale);
115 
116  protected:
117 
118  virtual void mousePressEvent(QMouseEvent *event);
119  virtual void mouseMoveEvent(QMouseEvent *event);
120 
121  private:
122 
123  void scaleImage();
124 
125  static const float ZOOM_FACTOR;
126 
127  QPixmap _pixmap;
128  float _scaleFactor;
129  QRubberBand *_selection;
130  QPoint _origin;
131  bool _allowSelection;
132 };
133 
134 } // namespace gui
135 } // namespace quark
136 
137 #endif // __libquark_gui_ImageViewerPanel_hxx
void zoomReset()
Resets the scale factor to 1.0.
QPixmap image() const
Returns the image that is currently displayed by the widget.
Definition: ImageViewerPanel.h++:43
void rotateRight()
Rotates the image 90 degrees clockwise.
void zoomScaleChanged(float scale)
Emitted when the zoom scale factor changes.
void zoomToFit(const QRect &rect)
Zooms the image so that it fits optimally within the given rectangle.
void zoomIn()
Zooms the image in.
void setImage(QPixmap pixmap)
Sets the image to be displayed by the widget.
A widget for displaying an image, with support for zooming, rotation, selection, and cropping...
Definition: ImageViewerPanel.h++:21
int imageHeight() const
Returns the height, in pixels, of the image that is currently displayed by the widget.
Definition: ImageViewerPanel.h++:57
int imageWidth() const
Returns the width, in pixels, of the image that is currently displayed by the widget.
Definition: ImageViewerPanel.h++:50
virtual void mousePressEvent(QMouseEvent *event)
void crop(const QRect &rect)
Crops the image to the specified region.
virtual void mouseMoveEvent(QMouseEvent *event)
void setAllowSelection(bool allowSelection)
Enables or disables selection.
Definition: BarChartView.h++:6
virtual ~ImageViewerPanel()
Destructor.
float scaleFactor() const
Returns the current scale factor.
Definition: ImageViewerPanel.h++:68
void clearSelection()
Clears the selection, if any.
QRect selection() const
Returns the current selection, or an empty rectangle if there is none.
void zoomOut()
Zooms the image out.
ImageViewerPanel(QWidget *parent=NULL)
Constructs a new ImageViewerPanel.
void rotateLeft()
Rotates the image 90 degrees counterclockwise.
void imageSizeChanged(QSize size)
Emitted when the size of the image changes.