SMIL  1.0.4
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''
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
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 #include "MagnifyView.h"
40 #include "ColorPicker.h"
41 #include "Core/include/DBinary.h"
42 #include "Core/include/DCommon.h"
43 
44 class QwtPointSeriesData;
45 
46 class QImageGraphicsScene : public QGraphicsScene
47 {
48  Q_OBJECT
49 public:
50  QImageGraphicsScene(QObject *parent = 0);
51  void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
52  void mousePressEvent(QGraphicsSceneMouseEvent *event);
53  void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
54 signals:
55  void onMouseMove(QGraphicsSceneMouseEvent *event);
56  void onMousePress(QGraphicsSceneMouseEvent *event);
57  void onMouseRelease(QGraphicsSceneMouseEvent *event);
58 };
59 
60 class ImageViewerWidget : public QGraphicsView
61 {
62  Q_OBJECT
63 
64 public:
65  ImageViewerWidget(QWidget *parent = 0);
67 
68  virtual void mouseMoveEvent(QMouseEvent *event);
69  virtual void mousePressEvent(QMouseEvent *event);
70  virtual void mouseReleaseEvent(QMouseEvent *event);
71  virtual void wheelEvent(QWheelEvent *);
72  virtual void keyPressEvent(QKeyEvent *);
73  virtual void leaveEvent(QEvent *event);
74 
75  virtual void setLabelImage(bool val);
76  virtual void displayPixelValue(size_t, size_t, size_t)
77  {
78  }
79  virtual void displayMagnifyView(size_t, size_t, size_t)
80  {
81  }
82  virtual void displayMagnifyView()
83  {
84  displayMagnifyView(lastPixX, lastPixY, lastPixZ);
85  }
86  virtual void setCurSlice(int)
87  {
88  }
89  virtual void redrawImage()
90  {
91  }
92  virtual void createOverlayImage();
93  virtual void deleteOverlayImage();
94 
95  void setName(QString name);
96  void setImageSize(int w, int h, int d = 1);
97  void dataChanged();
98  virtual void clearOverlay();
99 
100  QStatusBar * statusBar;
101  QImage * qImage;
102  QVector<QImage *> qOverlayImage;
103  QImage::Format imageFormat;
104 
105  bool drawLabelized;
106  // Auto adjust range
107  bool autoRange;
108 
109  virtual void displayHistogram(bool = false)
110  {
111  }
112  virtual void displayProfile(bool = false)
113  {
114  }
115 
116  void linkViewer(ImageViewerWidget *viewer);
117  void unlinkViewer(ImageViewerWidget *viewer);
118 
119 protected:
120  QGridLayout *layout;
121 
122  QVector<QRgb> baseColorTable;
123  QVector<QRgb> rainbowColorTable;
124  QVector<QRgb> labelColorTable;
125  QVector<QRgb> overlayColorTable;
126  void initColorTables();
127  void updatePixmaps(QImage *image, QList<QGraphicsPixmapItem *> *pixmaps);
128 
129  double scaleFactor;
130  QImageGraphicsScene * imScene;
131  QList<QGraphicsPixmapItem *> imagePixmaps;
132  QList<QGraphicsPixmapItem *> overlayPixmaps;
133 
134  QLabel * valueLabel;
135  QLabel * hintLabel;
136  QTimer * hintTimer;
137  QTimer * iconTimer;
138  MagnifyView *magnView;
139 
140  size_t imWidth, imHeight, imDepth;
141  int lastPixX, lastPixY, lastPixZ;
142 
143  bool magnActivated;
144  bool valueLblActivated;
145 
146  void createActions();
147 
148  void updateTitle();
149  void displayHint(QString msg, int timerVal = 1000);
150 
151  QMap<QString, QAction *> actionMap;
152 
153  QString name;
154 
155  QSlider *slider;
156 
157  virtual void dropEvent(QDropEvent *)
158  {
159  }
160  void dragMoveEvent(QDragMoveEvent *de);
161  void dragEnterEvent(QDragEnterEvent *event);
162 
163  enum cursorMode { cursorMove, cursorDraw, cursorDrawLine, cursorDrawBox };
164  int cursorMode;
165  QGraphicsLineItem *line;
166 
167  QList<ImageViewerWidget *> linkedWidgets;
168 
169  ColorPicker *colorPicker;
170  QPen drawPen;
171  bool drawing;
172 
173  void scrollContentsBy(int dx, int dy);
174 public slots:
175  void load(const QString fileName);
176  void zoomIn();
177  void zoomOut();
178  void scale(double factor, bool absolute = true);
179  void sliderChanged(int newVal)
180  {
181  displayHint(QString::number(newVal) + "/" +
182  QString::number(slider->maximum()));
183  setCurSlice(newVal);
184  if (!qOverlayImage.isEmpty())
185  updatePixmaps(qOverlayImage[newVal], &overlayPixmaps);
186  }
187  virtual void overlayDataChanged(bool triggerEvents = true);
188  void updateIcon();
189  void showContextMenu(const QPoint &pos);
190  void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
191  void setCursorMode(const int &mode);
192  void setDrawPenColor(const QColor &color);
193  void showHelp();
194  void saveAs(const char *fileName = NULL);
195 
196 protected slots:
197  void setScrollBarPosition(int x, int y);
198 private slots:
199  void sceneMousePressEvent(QGraphicsSceneMouseEvent *event);
200  void sceneMouseMoveEvent(QGraphicsSceneMouseEvent *event);
201  void sceneMouseReleaseEvent(QGraphicsSceneMouseEvent *event);
202 
203 signals:
204  void onRescaled(double scaleFactor);
205  void onDataChanged();
206  void onKeyPressEvent(QKeyEvent *);
207  void onScrollBarPositionChanged(int dx, int dy);
208 };
209 
210 #endif // ImageViewerWidget_H
Definition: ColorPicker.h:99
Definition: ImageViewerWidget.h:61
Definition: MagnifyView.h:44
Definition: ImageViewerWidget.h:47