Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkScalarBarOverlay.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "QmitkScalarBarOverlay.h"
18 
19 #include "mitkColorProperty.h"
20 #include "mitkProperties.h"
21 #include "mitkPropertyList.h"
22 
23 #include <itkCommand.h>
24 
25 #include <QLayout>
26 
27 QmitkScalarBarOverlay::QmitkScalarBarOverlay(const char *id) : QmitkOverlay(id), m_ScalarBar(nullptr), m_ObserverTag(0)
28 {
31 }
32 
34 {
35  m_PropertyList->GetProperty(m_Id)->RemoveObserver(m_ObserverTag);
36  m_PropertyList = nullptr;
37 }
38 
40 {
41  if (pl.IsNull())
42  return;
43 
44  m_PropertyList = pl->Clone();
45 
46  if (m_PropertyList.IsNotNull())
47  {
48  this->SetupCallback(m_PropertyList->GetProperty(m_Id));
49 
50  this->GetProperties(pl);
51  this->SetScaleFactor();
52  }
53  else
54  {
55  MITK_DEBUG << "invalid propList";
56  }
57 }
58 
60 {
61  float scale = 2;
62  if (m_PropertyList.IsNull() || !m_PropertyList->GetFloatProperty(m_Id, scale))
63  {
64  MITK_DEBUG << "Property " << m_Id << " could not be found";
65  }
66 
67  if (m_ScalarBar != nullptr)
68  {
70  }
71 }
72 
74 {
75  if (pl.IsNull())
76  return;
77 
78  QPen pen = QPen();
79 
80  mitk::PropertyList::Pointer propertyList = pl;
81  QPalette palette = QPalette();
82 
83  // get the desired color of the textOverlays
85  dynamic_cast<mitk::ColorProperty *>(propertyList->GetProperty("overlay.color"));
86 
87  if (colorProp.IsNull())
88  {
89  MITK_DEBUG << "creating new colorProperty";
90  colorProp = mitk::ColorProperty::New(127.0, 196.0, 232.0);
91  }
92 
93  mitk::Color color = colorProp->GetColor();
94  pen.setColor(QColor(color[0], color[1], color[2], 255));
95  pen.setStyle(Qt::SolidLine);
96  pen.setCapStyle(Qt::FlatCap);
97  pen.setJoinStyle(Qt::MiterJoin);
98 
99  m_ScalarBar->SetPen(pen);
100 }
101 
103 {
104  if (m_ObservedProperty != prop && m_ObserverTag == 0)
105  {
106  if (prop.IsNotNull())
107  {
108  if (m_ObservedProperty.IsNotNull())
109  {
110  m_ObservedProperty->RemoveObserver(m_ObserverTag);
111  }
112 
113  typedef itk::SimpleMemberCommand<QmitkScalarBarOverlay> MemberCommandType;
114  MemberCommandType::Pointer propModifiedCommand;
115  propModifiedCommand = MemberCommandType::New();
116  propModifiedCommand->SetCallbackFunction(this, &QmitkScalarBarOverlay::SetScaleFactor);
117  m_ObserverTag = prop->AddObserver(itk::ModifiedEvent(), propModifiedCommand);
118  }
119 
120  m_ObservedProperty = prop;
121  }
122  else
123  {
124  MITK_DEBUG << "invalid property";
125  }
126 }
127 
129 {
130  return m_Widget->size();
131 }
itk::SmartPointer< Self > Pointer
void SetPen(const QPen &pen)
mitk::PropertyList::Pointer m_PropertyList
static Pointer New()
void SetupCallback(mitk::BaseProperty::Pointer prop)
void AddDropShadow(QWidget *widget)
Add drop shadow effect via QGraphicsEffect.
Abstract base class for all overlay-objects in MITK.
Definition: QmitkOverlay.h:53
#define MITK_DEBUG
Definition: mitkLogMacros.h:26
QmitkScalarBarOverlay(const char *id)
Default Constructor.
The ColorProperty class RGB color property.
QmitkScalarBar * m_ScalarBar
QWidget internally representing the TextOverlay.
QWidget * m_Widget
internal QWidget representing the overlay
Definition: QmitkOverlay.h:120
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
virtual void GenerateData(mitk::PropertyList::Pointer) override
Setup the QLabel with overlay specific information.
mitk::BaseProperty::Pointer m_ObservedProperty
virtual void SetScaleFactor(double scale)
virtual ~QmitkScalarBarOverlay()
Default Destructor.
void GetProperties(mitk::PropertyList::Pointer)
internal helper class to determine text-properties
const char * m_Id
ID of the overlay.
Definition: QmitkOverlay.h:111
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.