diff --git a/Modules/Overlays/QmitkScalarBarOverlay.cpp b/Modules/Overlays/QmitkScalarBarOverlay.cpp index 3e5dd4f2ed..f7192e94da 100644 --- a/Modules/Overlays/QmitkScalarBarOverlay.cpp +++ b/Modules/Overlays/QmitkScalarBarOverlay.cpp @@ -1,126 +1,135 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, +Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkScalarBarOverlay.h" #include "mitkProperties.h" #include "mitkColorProperty.h" #include "mitkPropertyList.h" #include #include -QmitkScalarBarOverlay::QmitkScalarBarOverlay( const char* id ) +QmitkScalarBarOverlay::QmitkScalarBarOverlay( const char* id ) :QmitkOverlay(id) , m_ScalarBar( NULL ) , m_ObserverTag(0) { m_Widget = m_ScalarBar = new QmitkScalarBar(); QmitkOverlay::AddDropShadow( m_ScalarBar ); } QmitkScalarBarOverlay::~QmitkScalarBarOverlay() { m_PropertyList->GetProperty( m_Id )->RemoveObserver(m_ObserverTag); m_PropertyList = NULL; } void QmitkScalarBarOverlay::GenerateData( mitk::PropertyList::Pointer pl ) { if ( pl.IsNull() ) return; m_PropertyList = pl->Clone(); if ( m_PropertyList.IsNotNull() ) { this->SetupCallback( m_PropertyList->GetProperty( m_Id ) ); this->GetProperties( pl ); this->SetScaleFactor(); } else { MITK_DEBUG << "invalid propList"; } } void QmitkScalarBarOverlay::SetScaleFactor() { float scale = 2; if ( m_PropertyList.IsNull() || !m_PropertyList->GetFloatProperty( m_Id, scale ) ) { MITK_DEBUG << "Property " << m_Id << " could not be found"; } if ( m_ScalarBar != NULL ) { m_ScalarBar->SetScaleFactor( scale ); } } void QmitkScalarBarOverlay::GetProperties( mitk::PropertyList::Pointer pl ) { if ( pl.IsNull() ) return; QPen pen = QPen(); mitk::PropertyList::Pointer propertyList = pl; QPalette palette = QPalette(); // get the desired color of the textOverlays - mitk::ColorProperty::Pointer colorProp = + mitk::ColorProperty::Pointer colorProp = dynamic_cast( propertyList->GetProperty( "overlay.color" ) ); if ( colorProp.IsNull() ) { MITK_DEBUG << "creating new colorProperty"; colorProp = mitk::ColorProperty::New( 127.0, 196.0, 232.0 ); } mitk::Color color = colorProp->GetColor(); pen.setColor( QColor( color[0],color[1],color[2],255 ) ); pen.setStyle( Qt::SolidLine ); pen.setCapStyle( Qt::FlatCap ); pen.setJoinStyle( Qt::MiterJoin ); m_ScalarBar->SetPen( pen ); } void QmitkScalarBarOverlay::SetupCallback( mitk::BaseProperty::Pointer prop ) { - if ( prop.IsNotNull() ) - { - prop->RemoveObserver(m_ObserverTag); - typedef itk::SimpleMemberCommand< QmitkScalarBarOverlay > MemberCommandType; - MemberCommandType::Pointer propModifiedCommand; - propModifiedCommand = MemberCommandType::New(); - propModifiedCommand->SetCallbackFunction( this, &QmitkScalarBarOverlay::SetScaleFactor ); - m_ObserverTag = prop->AddObserver( itk::ModifiedEvent(), propModifiedCommand ); + if ( m_ObservedProperty != prop && m_ObserverTag == 0 ) + { + if ( prop.IsNotNull() ) + { + if ( m_ObservedProperty.IsNotNull() ) + { + m_ObservedProperty->RemoveObserver( m_ObserverTag ); + } + + typedef itk::SimpleMemberCommand< QmitkScalarBarOverlay > MemberCommandType; + MemberCommandType::Pointer propModifiedCommand; + propModifiedCommand = MemberCommandType::New(); + propModifiedCommand->SetCallbackFunction( this, &QmitkScalarBarOverlay::SetScaleFactor ); + m_ObserverTag = prop->AddObserver( itk::ModifiedEvent(), propModifiedCommand ); + } + + m_ObservedProperty = prop; } else { MITK_DEBUG << "invalid property"; } } diff --git a/Modules/Overlays/QmitkScalarBarOverlay.h b/Modules/Overlays/QmitkScalarBarOverlay.h index cabf3229be..fe6cbf8954 100644 --- a/Modules/Overlays/QmitkScalarBarOverlay.h +++ b/Modules/Overlays/QmitkScalarBarOverlay.h @@ -1,90 +1,92 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, +Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKSCALARBAROVERLAY_H_HEADER_INCLUDED_C10DC4EB #define MITKSCALARBAROVERLAY_H_HEADER_INCLUDED_C10DC4EB #include "OverlaysExports.h" // MITK-Stuff #include "mitkCommon.h" #include "mitkPropertyList.h" #include "QmitkOverlay.h" #include /** \class QmitkScalarBarOverlay * \brief object representing a text that is drawn as an overlay * * \ingroup Qmitk */ class Overlays_EXPORT QmitkScalarBarOverlay : public QmitkOverlay { Q_OBJECT public: /** * @brief Default Constructor **/ QmitkScalarBarOverlay( const char* id ); /** * @brief Default Destructor **/ virtual ~QmitkScalarBarOverlay(); /** * \brief Setup the QLabel with overlay specific information * * First, this method sets text-overlay specific properties as described in the class docu above. * Secondly, the actual text of the label is set. - * - * \WARNING No error will be issued if the property containing the text is not found, the TextOverlay + * + * \WARNING No error will be issued if the property containing the text is not found, the TextOverlay * will show an empty string! */ virtual void GenerateData( mitk::PropertyList::Pointer ); protected: /** * \brief internal helper class to determine text-properties * - * This method is only used internally to apply the text specific properties that can be set + * This method is only used internally to apply the text specific properties that can be set * using a mitk::PropertyList. If a property cannot be found, a default value is used. * * The values of these properties are then attributed to the label using QFont and QPalette. - */ + */ void GetProperties( mitk::PropertyList::Pointer ); - + void SetupCallback( mitk::BaseProperty::Pointer prop ); - + void SetScaleFactor(); /** \brief QWidget internally representing the TextOverlay */ - QmitkScalarBar* m_ScalarBar; + QmitkScalarBar* m_ScalarBar; + + mitk::BaseProperty::Pointer m_ObservedProperty; mitk::PropertyList::Pointer m_PropertyList; unsigned long m_ObserverTag; }; #endif /* MITKSCALARBAROVERLAY_H_HEADER_INCLUDED_C10DC4EB */ diff --git a/Modules/Overlays/QmitkTextOverlay.cpp b/Modules/Overlays/QmitkTextOverlay.cpp index 6660f48dd1..59a8d8f074 100644 --- a/Modules/Overlays/QmitkTextOverlay.cpp +++ b/Modules/Overlays/QmitkTextOverlay.cpp @@ -1,149 +1,161 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, +Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkTextOverlay.h" #include "mitkProperties.h" #include "mitkColorProperty.h" #include "mitkPropertyList.h" #include QmitkTextOverlay::QmitkTextOverlay( const char* id ) : QmitkOverlay(id) +, m_ObservedProperty( NULL ) , m_ObserverTag(0) { m_Widget = m_Label = new QLabel(); QmitkOverlay::AddDropShadow( m_Widget ); } QmitkTextOverlay::~QmitkTextOverlay() { m_PropertyList->GetProperty( m_Id )->RemoveObserver(m_ObserverTag); } void QmitkTextOverlay::GenerateData( mitk::PropertyList::Pointer pl ) { if ( pl.IsNull() ) return; m_PropertyList = pl; if ( m_PropertyList.IsNotNull() ) { this->SetupCallback( m_PropertyList->GetProperty( m_Id ) ); this->UpdateFontProperties( pl ); this->UpdateDisplayedTextFromProperties(); } else { MITK_ERROR << "invalid propList"; } } void QmitkTextOverlay::UpdateDisplayedTextFromProperties() { std::string text; if ( m_PropertyList.IsNull() || !m_PropertyList->GetStringProperty( m_Id, text ) ) { MITK_DEBUG << "Property " << m_Id << " could not be found"; } - m_Label->setText( text.c_str() ); - m_Label->repaint(); + if ( text != m_Label->text().toStdString() ) + { + m_Label->setText( text.c_str() ); + m_Label->repaint(); + } } void QmitkTextOverlay::UpdateFontProperties( mitk::PropertyList::Pointer pl ) { if ( pl.IsNull() ) return; mitk::PropertyList::Pointer propertyList = pl; QPalette palette = QPalette(); QFont font = QFont(); // get the desired color of the textOverlays - mitk::ColorProperty::Pointer colorProp = + mitk::ColorProperty::Pointer colorProp = dynamic_cast( propertyList->GetProperty( "overlay.color" ) ); if ( colorProp.IsNull() ) { colorProp = mitk::ColorProperty::New( 127.0, 196.0, 232.0 ); } mitk::Color color = colorProp->GetColor(); palette.setColor( QPalette::Foreground, QColor( color[0],color[1],color[2],255 ) ); palette.setColor( QPalette::Window, Qt::transparent); m_Label->setPalette( palette ); // get the desired opacity of the overlays //mitk::FloatProperty::Pointer opacityProperty = // dynamic_cast( propertyList->GetProperty( "overlay.opacity" ) ); //if ( opacityProperty.IsNull() ) //{ // m_Label->setWindowOpacity( 1 ); - //} + //} //else //{ // m_Label->setWindowOpacity( opacityProperty->GetValue() ); //} - + //set the desired font-size of the overlays int fontSize = 0; if ( !propertyList->GetIntProperty( "overlay.fontSize", fontSize ) ) { fontSize = 9.5; - } + } font.setPointSize( fontSize ); bool useKerning = false; if ( !propertyList->GetBoolProperty( "overlay.kerning", useKerning ) ) { useKerning = true; } font.setKerning( useKerning ); std::string fontFamily = ""; if ( !propertyList->GetStringProperty( "overlay.fontFamily", fontFamily ) ) { fontFamily = "Verdana"; } font.setFamily( QString(fontFamily.c_str()) ); m_Label->setFont( font ); } void QmitkTextOverlay::SetupCallback( mitk::BaseProperty::Pointer prop ) { - if ( prop.IsNotNull() ) + if ( m_ObservedProperty != prop && m_ObserverTag == 0 ) { - prop->RemoveObserver(m_ObserverTag); - - typedef itk::SimpleMemberCommand< QmitkTextOverlay > MemberCommandType; - MemberCommandType::Pointer propModifiedCommand; - propModifiedCommand = MemberCommandType::New(); - propModifiedCommand->SetCallbackFunction( this, &QmitkTextOverlay::UpdateDisplayedTextFromProperties ); - m_ObserverTag = prop->AddObserver( itk::ModifiedEvent(), propModifiedCommand ); + if ( prop.IsNotNull() ) + { + if ( m_ObservedProperty.IsNotNull() ) + { + m_ObservedProperty->RemoveObserver( m_ObserverTag ); + } + + typedef itk::SimpleMemberCommand< QmitkTextOverlay > MemberCommandType; + MemberCommandType::Pointer propModifiedCommand; + propModifiedCommand = MemberCommandType::New(); + propModifiedCommand->SetCallbackFunction( this, &QmitkTextOverlay::UpdateDisplayedTextFromProperties ); + m_ObserverTag = prop->AddObserver( itk::ModifiedEvent(), propModifiedCommand ); + } + + m_ObservedProperty = prop; } else { MITK_DEBUG << "invalid property"; } } diff --git a/Modules/Overlays/QmitkTextOverlay.h b/Modules/Overlays/QmitkTextOverlay.h index 6d01ec1210..e81fe00a37 100644 --- a/Modules/Overlays/QmitkTextOverlay.h +++ b/Modules/Overlays/QmitkTextOverlay.h @@ -1,114 +1,116 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, +Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKTEXTOVERLAY_H_HEADER_INCLUDED_C10DC4EB #define MITKTEXTOVERLAY_H_HEADER_INCLUDED_C10DC4EB // MITK #include "mitkCommon.h" #include "mitkPropertyList.h" #include "QmitkOverlay.h" // Qt #include #include "OverlaysExports.h" /** \class QmitkTextOverlay * \brief object representing a text that is drawn as an overlay * * A QmitkTextOverlay is a text-specific implementation of QmitkOverlay. -* It can be used whenever a simple text is to be rendered as an overlay in +* It can be used whenever a simple text is to be rendered as an overlay in * a QmitkRenderWindow. * -* Instead of a QWidget (as in QmitkOverlay) a QmitkTextOverlay is internally +* Instead of a QWidget (as in QmitkOverlay) a QmitkTextOverlay is internally * represented by a QLabel. You can access it via GetWidget(). * * Calling GenerateData( mitk::PropertyList::Pointer ) will setup the textoverlay. -* This includes setting of the actual text (that must be stored in the property +* This includes setting of the actual text (that must be stored in the property * with the name that is given the overlay as ID). -* +* * e.g. mitk::StringProperty::Pointer nameProp = mitk::StringProperty::New( "overlay.text.patientName", "Max" ); * -- * QmitkTextOverlay* nameOverlay = new QmitkTextOverlay( "overlay.text.patientName" ); * -* In order to customize the look of the textoverlays, a number of additional properties can be set +* In order to customize the look of the textoverlays, a number of additional properties can be set * (default values in square brackets): -* +* * overlay.color : defines the text-color (mitk::ColorProperty) * overlay.fontSize : defines the fontSize of the text (mitk::IntProperty) * overlay.kerning : defines if kerning is to be used (mitk::BoolProperty) * overlay.fontFamily : defines the fon family that is to be used (mitk::StringProperty) * * \ingroup Qmitk */ class Overlays_EXPORT QmitkTextOverlay : public QmitkOverlay { public: /** * @brief Default Constructor **/ QmitkTextOverlay( const char* id ); /** * @brief Default Destructor **/ virtual ~QmitkTextOverlay(); /** * \brief Setup the QLabel with overlay specific information * * First, this method sets text-overlay specific properties as described in the class docu above. * Secondly, the actual text of the label is set. - * - * \WARNING No error will be issued if the property containing the text is not found, the TextOverlay + * + * \WARNING No error will be issued if the property containing the text is not found, the TextOverlay * will show an empty string! */ void GenerateData( mitk::PropertyList::Pointer ); protected: /** * \brief internal helper class to determine text-properties * - * This method is only used internally to apply the font specific properties that can be set + * This method is only used internally to apply the font specific properties that can be set * using a mitk::PropertyList. If a property cannot be found, a default value is used. * * The values of these properties are then attributed to the QLabel using QFont and QPalette. - */ + */ void UpdateFontProperties( mitk::PropertyList::Pointer ); - + void SetupCallback( mitk::BaseProperty::Pointer prop ); - + void UpdateDisplayedTextFromProperties(); /** \brief QLabel internally representing the TextOverlay */ - QLabel* m_Label; + QLabel* m_Label; mitk::PropertyList::Pointer m_PropertyList; + mitk::BaseProperty::Pointer m_ObservedProperty; + unsigned long m_ObserverTag; }; #endif /* MITKTEXTOVERLAY_H_HEADER_INCLUDED_C10DC4EB */