Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "QmitkScalarBarOverlay.h"
14 
15 #include "mitkColorProperty.h"
16 #include "mitkProperties.h"
17 #include "mitkPropertyList.h"
18 
19 #include <itkCommand.h>
20 
21 #include <QLayout>
22 
23 QmitkScalarBarOverlay::QmitkScalarBarOverlay(const char *id) : QmitkOverlay(id), m_ScalarBar(nullptr), m_ObserverTag(0)
24 {
27 }
28 
30 {
31  m_PropertyList->GetProperty(m_Id)->RemoveObserver(m_ObserverTag);
32  m_PropertyList = nullptr;
33 }
34 
36 {
37  if (pl.IsNull())
38  return;
39 
40  m_PropertyList = pl->Clone();
41 
42  if (m_PropertyList.IsNotNull())
43  {
44  this->SetupCallback(m_PropertyList->GetProperty(m_Id));
45 
46  this->GetProperties(pl);
47  this->SetScaleFactor();
48  }
49  else
50  {
51  MITK_DEBUG << "invalid propList";
52  }
53 }
54 
56 {
57  float scale = 2;
58  if (m_PropertyList.IsNull() || !m_PropertyList->GetFloatProperty(m_Id, scale))
59  {
60  MITK_DEBUG << "Property " << m_Id << " could not be found";
61  }
62 
63  if (m_ScalarBar != nullptr)
64  {
66  }
67 }
68 
70 {
71  if (pl.IsNull())
72  return;
73 
74  QPen pen = QPen();
75 
76  mitk::PropertyList::Pointer propertyList = pl;
77  QPalette palette = QPalette();
78 
79  // get the desired color of the textOverlays
81  dynamic_cast<mitk::ColorProperty *>(propertyList->GetProperty("overlay.color"));
82 
83  if (colorProp.IsNull())
84  {
85  MITK_DEBUG << "creating new colorProperty";
86  colorProp = mitk::ColorProperty::New(127.0, 196.0, 232.0);
87  }
88 
89  mitk::Color color = colorProp->GetColor();
90  pen.setColor(QColor(color[0], color[1], color[2], 255));
91  pen.setStyle(Qt::SolidLine);
92  pen.setCapStyle(Qt::FlatCap);
93  pen.setJoinStyle(Qt::MiterJoin);
94 
95  m_ScalarBar->SetPen(pen);
96 }
97 
99 {
100  if (m_ObservedProperty != prop && m_ObserverTag == 0)
101  {
102  if (prop.IsNotNull())
103  {
104  if (m_ObservedProperty.IsNotNull())
105  {
106  m_ObservedProperty->RemoveObserver(m_ObserverTag);
107  }
108 
109  typedef itk::SimpleMemberCommand<QmitkScalarBarOverlay> MemberCommandType;
110  MemberCommandType::Pointer propModifiedCommand;
111  propModifiedCommand = MemberCommandType::New();
112  propModifiedCommand->SetCallbackFunction(this, &QmitkScalarBarOverlay::SetScaleFactor);
113  m_ObserverTag = prop->AddObserver(itk::ModifiedEvent(), propModifiedCommand);
114  }
115 
116  m_ObservedProperty = prop;
117  }
118  else
119  {
120  MITK_DEBUG << "invalid property";
121  }
122 }
123 
125 {
126  return m_Widget->size();
127 }
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:49
#define MITK_DEBUG
Definition: mitkLogMacros.h:22
QmitkScalarBarOverlay(const char *id)
Default Constructor.
The ColorProperty class RGB color property.
QmitkScalarBar * m_ScalarBar
QWidget internally representing the TextOverlay.
~QmitkScalarBarOverlay() override
Default Destructor.
QWidget * m_Widget
internal QWidget representing the overlay
Definition: QmitkOverlay.h:116
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
void GenerateData(mitk::PropertyList::Pointer) override
Setup the QLabel with overlay specific information.
mitk::BaseProperty::Pointer m_ObservedProperty
virtual void SetScaleFactor(double scale)
void GetProperties(mitk::PropertyList::Pointer)
internal helper class to determine text-properties
const char * m_Id
ID of the overlay.
Definition: QmitkOverlay.h:107