SMIL  0.9.1
ImageViewerWidget.h
1 /*
2  * Copyright (c) 2011-2016, Matthieu FAESSEL and ARMINES
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 
30 #ifndef ImageViewerWidget_H
31 #define ImageViewerWidget_H
32 
33 #include <QGraphicsScene>
34 #include <QGraphicsView>
35 #include <QStatusBar>
36 #include <QSlider>
37 #include <QGridLayout>
38 
39 
40 #include "MagnifyView.h"
41 #include "ColorPicker.h"
42 #include "Core/include/DBinary.h"
43 #include "Core/include/DCommon.h"
44 
45 class QwtPointSeriesData;
46 
47 class QImageGraphicsScene : public QGraphicsScene
48 {
49  Q_OBJECT
50 public:
51  QImageGraphicsScene(QObject *parent=0);
52  void mouseMoveEvent (QGraphicsSceneMouseEvent *event);
53  void mousePressEvent (QGraphicsSceneMouseEvent *event);
54  void mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
55 signals:
56  void onMouseMove(QGraphicsSceneMouseEvent* event);
57  void onMousePress(QGraphicsSceneMouseEvent* event);
58  void onMouseRelease(QGraphicsSceneMouseEvent* event);
59 };
60 
61 
62 class ImageViewerWidget : public QGraphicsView
63 {
64  Q_OBJECT
65 
66 public:
67  ImageViewerWidget(QWidget *parent=0);
69 
70  virtual void mouseMoveEvent ( QMouseEvent * event );
71  virtual void mousePressEvent ( QMouseEvent * event );
72  virtual void mouseReleaseEvent ( QMouseEvent * event );
73  virtual void wheelEvent( QWheelEvent* );
74  virtual void keyPressEvent(QKeyEvent *);
75  virtual void leaveEvent (QEvent *event);
76 
77  virtual void setLabelImage(bool val);
78  virtual void displayPixelValue(size_t, size_t, size_t) {}
79  virtual void displayMagnifyView(size_t, size_t, size_t) {}
80  virtual void displayMagnifyView() { displayMagnifyView(lastPixX, lastPixY, lastPixZ); }
81  virtual void setCurSlice(int) {}
82  virtual void redrawImage() {}
83  virtual void createOverlayImage();
84  virtual void deleteOverlayImage();
85 
86  void setName(QString name);
87  void setImageSize(int w, int h, int d=1);
88  void dataChanged();
89  virtual void clearOverlay();
90 
91  QStatusBar *statusBar;
92  QImage *qImage;
93  QVector<QImage*> qOverlayImage;
94  QImage::Format imageFormat;
95 
96  bool drawLabelized;
97  // Auto adjust range
98  bool autoRange;
99 
100  virtual void displayHistogram(bool = false) {}
101  virtual void displayProfile(bool = false) {}
102 
103  void linkViewer(ImageViewerWidget *viewer);
104  void unlinkViewer(ImageViewerWidget *viewer);
105 protected:
106  QGridLayout *layout;
107 
108  QVector<QRgb> baseColorTable;
109  QVector<QRgb> rainbowColorTable;
110  QVector<QRgb> labelColorTable;
111  QVector<QRgb> overlayColorTable;
112  void initColorTables();
113  void updatePixmaps(QImage *image, QList<QGraphicsPixmapItem*> *pixmaps);
114 
115  double scaleFactor;
116  QImageGraphicsScene *imScene;
117  QList<QGraphicsPixmapItem*> imagePixmaps;
118  QList<QGraphicsPixmapItem*> overlayPixmaps;
119 
120  QLabel *valueLabel;
121  QLabel *hintLabel;
122  QTimer *hintTimer;
123  QTimer *iconTimer;
124  MagnifyView *magnView;
125 
126  size_t imWidth, imHeight, imDepth;
127  int lastPixX, lastPixY, lastPixZ;
128 
129  bool magnActivated;
130  bool valueLblActivated;
131 
132  void createActions();
133 
134  void updateTitle();
135  void displayHint(QString msg, int timerVal=1000);
136 
137  QMap<QString, QAction*> actionMap;
138 
139  QString name;
140 
141  QSlider *slider;
142 
143  virtual void dropEvent(QDropEvent *) {}
144  void dragMoveEvent(QDragMoveEvent *de);
145  void dragEnterEvent(QDragEnterEvent *event);
146 
147  enum cursorMode { cursorMove, cursorDraw, cursorDrawLine, cursorDrawBox};
148  int cursorMode;
149  QGraphicsLineItem *line;
150 
151  QList<ImageViewerWidget*> linkedWidgets;
152 
153  ColorPicker *colorPicker;
154  QPen drawPen;
155  bool drawing;
156 
157  void scrollContentsBy(int dx, int dy);
158 public slots:
159  void load(const QString fileName);
160  void zoomIn();
161  void zoomOut();
162  void scale(double factor, bool absolute=true);
163  void sliderChanged(int newVal)
164  {
165  displayHint(QString::number(newVal) + "/" + QString::number(slider->maximum()));
166  setCurSlice(newVal);
167  if (!qOverlayImage.isEmpty())
168  updatePixmaps(qOverlayImage[newVal], &overlayPixmaps);
169  }
170  virtual void overlayDataChanged(bool triggerEvents=true);
171  void updateIcon();
172  void showContextMenu(const QPoint& pos);
173  void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
174  void setCursorMode(const int &mode);
175  void setDrawPenColor(const QColor &color);
176  void showHelp();
177  void saveAs(const char *fileName=NULL);
178 
179 protected slots:
180  void setScrollBarPosition(int x, int y);
181 private slots:
182  void sceneMousePressEvent ( QGraphicsSceneMouseEvent * event );
183  void sceneMouseMoveEvent ( QGraphicsSceneMouseEvent * event );
184  void sceneMouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
185 
186 signals:
187  void onRescaled(double scaleFactor);
188  void onDataChanged();
189  void onKeyPressEvent(QKeyEvent *);
190  void onScrollBarPositionChanged(int dx, int dy);
191 };
192 
193 
194 
195 
196 #endif // ImageViewerWidget_H
Definition: MagnifyView.h:43
RES_T scale(Image< T > &imIn, double cx, double cy, Image< T > &imOut)
Scale image If imIn has the size (W,H), the size of imOut will be (W*cx, H*cy).
Definition: DImageTransform.hpp:344
Definition: ColorPicker.h:98
Definition: ImageViewerWidget.h:47
Definition: ImageViewerWidget.h:62