CustusX  22.04-rc5
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 */
bool internalOpenNewFile(const QString absoluteFilePath)
virtual void previewFileSlot(const QString &absoluteFilePath)
boost::shared_ptr< QFile > mCurrentFile
ImagePreviewWidget(QWidget *parent)
Baseclass for widgets that should watch a file.
void setSize(int width, int height)
Namespace for all CustusX production code.