3 #include <QGraphicsSceneMouseEvent> 4 #include <QGraphicsView> 16 m_controller =
nullptr;
17 for (
size_t i = 0; i < views.size(); ++i) {
19 views[i]->hideControls();
20 getScene(i)->installEventFilter(
this);
21 views[i]->setViewNumber(i);
25 layout =
new QGridLayout(
this);
26 layout->setVerticalSpacing(0);
27 layout->setHorizontalSpacing(0);
30 QPalette p(palette());
32 setAutoFillBackground(
true);
41 view->setViewBgColor(color);
57 for (
size_t axis = 0; axis < 4; ++axis) {
65 void ImageViewer::updateViews() {
66 COMMENT(
"ImageViewer::updateViews", 2);
74 for (
size_t axis = 0; axis < 4; ++axis) {
80 void ImageViewer::changeImage() {
81 COMMENT(
"ImageViewer::changeImage", 2);
84 if (img->
tools.empty()) {
89 for (
size_t axis = 0; axis < 4; ++axis) {
95 views[axis]->setRange(0, img->
depth(axis) - 1);
97 views[axis]->showControls();
99 views[axis]->hideControls();
109 for (
size_t axis = 0; axis < 4; ++axis) {
113 QRectF r = m_controller->
getPixmapItem(axis)->boundingRect();
115 QGraphicsView *view = views[axis]->graphicsView();
116 view->fitInView(m_controller->
getPixmapItem(axis), Qt::KeepAspectRatio);
123 void ImageViewer::setLayoutType(
Layout layout) {
130 setHorizontalLayout();
140 void ImageViewer::getNewLayout() {
142 layout->removeWidget(view);
147 void ImageViewer::setGridLayout() {
150 layout->addWidget(views[0], 0, 0);
151 layout->addWidget(views[1], 0, 1);
152 layout->addWidget(views[2], 1, 0);
153 layout->addWidget(views[3], 1, 1);
158 void ImageViewer::setHorizontalLayout() {
159 COMMENT(
"Set horizontal layout.", 0)
161 layout->addWidget(views[0], 0, 0);
162 layout->addWidget(views[1], 0, 1);
163 layout->addWidget(views[2], 0, 2);
164 layout->addWidget(views[3], 0, 3);
169 void ImageViewer::setVerticalLayout() {
170 COMMENT(
"Set vertical layout.", 0)
172 layout->addWidget(views[0], 0, 0);
173 layout->addWidget(views[1], 1, 0);
174 layout->addWidget(views[2], 2, 0);
175 layout->addWidget(views[3], 3, 0);
180 void ImageViewer::hideViews() {
187 void ImageViewer::showViews() {
194 void ImageViewer::setViewMode(
Views view) {
203 void ImageViewer::sliceChanged(
size_t axis,
size_t slice) {
215 QGraphicsSceneMouseEvent *mouseEvt =
dynamic_cast<QGraphicsSceneMouseEvent *
>(evt);
217 for (
size_t scn = 1; scn < views.size(); ++scn) {
218 if (obj == views[scn]->scene()) {
224 QPointF scnPos = mouseEvt->scenePos();
225 if (mouseEvt->type() == QEvent::GraphicsSceneMouseMove) {
227 if (dragging && (timer.elapsed() > 25)) {
238 }
else if (mouseEvt->type() == QEvent::GraphicsSceneMousePress) {
240 if (mouseEvt->button() == Qt::LeftButton) {
248 }
else if (mouseEvt->type() == QEvent::GraphicsSceneMouseRelease) {
249 if (mouseEvt->button() == Qt::LeftButton) {
258 return (QWidget::eventFilter(obj, evt));
262 if (axis > views.size()) {
263 throw std::out_of_range(
BIAL_ERROR(QString(
"Invalid axis, expected < %1.").arg(views.size()).toStdString()));
265 return (views[axis]->scene());
void mouseClicked(QPointF pt, Qt::MouseButtons buttons, size_t axis)
void setOverlayPen(const QPen &overlayPen)
void mouseReleased(QPointF pt, Qt::MouseButtons buttons, size_t axis)
Tool * currentTool()
currentTool returns the current Tool.
bool eventFilter(QObject *obj, QEvent *evt)
ImageViewer(QWidget *parent=0)
#define BIAL_ERROR(exp)
Use BIAL_ERROR to compose runtime error messages. Note that ERROR generates a string, instead of a stream, because it is better to throw an exception, rather than exiting the program. This way, the exception may be threated by a higher level program, like an user IDE.
DisplayFormat * currentFormat()
currentFormat returns the modality of current image.
The GuiImage class is a bridge to the Bial::Image data structure to the QImage data structure...
void setViewBgColor(const QColor &color)
void setCurrentSlice(size_t view, size_t slice)
setCurrentSlice is called by the imageViewer when the slider or the spinbox have theis values updated...
Content: Commonly used macros, types, static variables and functions. Description: Some macros used...
void rotate90(size_t view)
rotate90 rotates a view in 90 degrees.
void dropImage(const QString &filePath)
Controller * controller() const
void flipH(size_t view)
flipH mirrors the current view on X axis.
size_t depth(size_t view)
depth is the number of slices of the view.
void mouseDragged(QPointF pt, Qt::MouseButtons buttons, size_t axis)
Image< D > Background(const Image< D > &img)
Segments the darker clusters of the image, supposedly belonging to the background.
void dropFolder(const QString &folderPath)
The Controller class is one of the most important classes of the User Interface, and is responsible t...
GraphicsScene * getScene(size_t axis)
void flipV(size_t view)
flipV mirrors the current view on Y axis.
void resizeEvent(QResizeEvent *)
QPointF getIntersection(size_t view)
QGraphicsPixmapItem * getLabelItem(size_t view)
getLabelItem returns the LabelItem of the view.
QGraphicsPixmapItem * getPixmapItem(size_t view)
getPixmapItem returns the PixmapItem of the view.
GuiImage * currentImage()
currentImage
void currentImageChanged()
This signal is emmited every time the current image changes.
size_t currentSlice(size_t view)
currentSlice is the view's current slice.
QVector< Tool * > tools
tools is a vector containing the image tools.
void setOverlay(bool overlay)
void mouseMoved(QPointF pt, size_t axis)
void setController(Controller *value)
void imageUpdated()
This signal is emmited every time the current image is updated.