NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxImagePreviewWidget.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxImagePreviewWidget.h"
13 
14 #include <QFile>
15 #include <QPicture>
16 #include <QVBoxLayout>
17 #include <QLabel>
18 
19 
20 namespace cx
21 {
23  FileWatcherWidget(parent, "image_preview_widget", "Image Preview"),
24  mDisplayLabel(new QLabel())
25 {
26  this->setToolTip("Preview of an image file");
27  mDisplayLabel->setAlignment(Qt::AlignCenter);
28 
29  QVBoxLayout* layout = new QVBoxLayout(this);
30  layout->setMargin(0);
31  layout->addWidget(mDisplayLabel);
32 
33 }
34 
36 {
37 }
38 
39 void ImagePreviewWidget::setSize(int width, int height)
40 {
41  mDisplayLabel->setFixedSize(width, height);
42 }
43 
44 void ImagePreviewWidget::previewFileSlot(const QString& absoluteFilePath)
45 {
46  QString imageText = "";
47  if(this->internalOpenNewFile(absoluteFilePath)){
48  QPixmap map;
49  map.load(absoluteFilePath);
50  mDisplayLabel->setPixmap(map.scaled(mDisplayLabel->width(), mDisplayLabel->height(), Qt::KeepAspectRatio));
51  }else{
52  imageText = "Image missing!";
53  }
54  mDisplayLabel->setText(imageText);
55  mCurrentFile->close();
56 
57 }
58 
59 } /* namespace cx */
cxImagePreviewWidget.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::FileWatcherWidget::internalOpenNewFile
bool internalOpenNewFile(const QString absoluteFilePath)
Definition: cxFileWatcherWidget.cpp:30
cx::ImagePreviewWidget::setSize
void setSize(int width, int height)
Definition: cxImagePreviewWidget.cpp:39
cx::FileWatcherWidget
Baseclass for widgets that should watch a file.
Definition: cxFileWatcherWidget.h:35
cx::FileWatcherWidget::mCurrentFile
boost::shared_ptr< QFile > mCurrentFile
Definition: cxFileWatcherWidget.h:51
cx::ImagePreviewWidget::previewFileSlot
virtual void previewFileSlot(const QString &absoluteFilePath)
Definition: cxImagePreviewWidget.cpp:44
cx::ImagePreviewWidget::~ImagePreviewWidget
virtual ~ImagePreviewWidget()
Definition: cxImagePreviewWidget.cpp:35
cx::ImagePreviewWidget::ImagePreviewWidget
ImagePreviewWidget(QWidget *parent)
Definition: cxImagePreviewWidget.cpp:22