00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date: 2010-01-14 14:20:26 +0100 (Thu, 14 Jan 2010) $ 00006 Version: $Revision: 21047 $ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #include "QmitkScalarBarOverlay.h" 00019 00020 #include "mitkProperties.h" 00021 #include "mitkColorProperty.h" 00022 #include "mitkPropertyList.h" 00023 00024 #include <itkCommand.h> 00025 00026 #include <QLayout> 00027 00028 00029 QmitkScalarBarOverlay::QmitkScalarBarOverlay( const char* id ): 00030 QmitkOverlay(id), m_Widget( NULL ) 00031 { 00032 m_Widget = new QmitkScalarBar(); 00033 m_Widget->setStyleSheet(""); 00034 } 00035 00036 QmitkScalarBarOverlay::~QmitkScalarBarOverlay() 00037 { 00038 m_Widget = NULL; 00039 } 00040 00041 void QmitkScalarBarOverlay::GenerateData( mitk::PropertyList::Pointer pl ) 00042 { 00043 if ( pl.IsNull() ) 00044 return; 00045 00046 m_PropertyList = pl; 00047 00048 if ( m_PropertyList.IsNotNull() ) 00049 { 00050 this->SetupCallback( m_PropertyList->GetProperty( m_Id ) ); 00051 00052 this->GetProperties( pl ); 00053 this->SetScaleFactor(); 00054 } 00055 else 00056 { 00057 MITK_ERROR << "invalid propList"; 00058 } 00059 00060 } 00061 00062 void QmitkScalarBarOverlay::SetScaleFactor() 00063 { 00064 float scale = 2; 00065 if ( m_PropertyList.IsNull() || !m_PropertyList->GetFloatProperty( m_Id, scale ) ) 00066 { 00067 MITK_WARN << "Property " << m_Id << " could not be found"; 00068 } 00069 m_Widget->SetScaleFactor( scale ); 00070 } 00071 00072 00073 void QmitkScalarBarOverlay::GetProperties( mitk::PropertyList::Pointer pl ) 00074 { 00075 if ( pl.IsNull() ) 00076 return; 00077 00078 QPen pen = QPen(); 00079 00080 00081 mitk::PropertyList::Pointer propertyList = pl; 00082 QPalette palette = QPalette(); 00083 00084 // get the desired color of the textOverlays 00085 mitk::ColorProperty::Pointer colorProp = 00086 dynamic_cast<mitk::ColorProperty*>( propertyList->GetProperty( "overlay.color" ) ); 00087 00088 if ( colorProp.IsNull() ) 00089 { 00090 MITK_ERROR << "creating new colorProperty"; 00091 colorProp = mitk::ColorProperty::New( 127.0, 196.0, 232.0 ); 00092 } 00093 00094 mitk::Color color = colorProp->GetColor(); 00095 pen.setColor( QColor( color[0],color[1],color[2],255 ) ); 00096 pen.setStyle( Qt::SolidLine ); 00097 pen.setCapStyle( Qt::FlatCap ); 00098 pen.setJoinStyle( Qt::MiterJoin ); 00099 00100 m_Widget->SetPen( pen ); 00101 } 00102 00103 QWidget* QmitkScalarBarOverlay::GetWidget() 00104 { 00105 return m_Widget; 00106 } 00107 00108 00109 void QmitkScalarBarOverlay::SetupCallback( mitk::BaseProperty::Pointer prop ) 00110 { 00111 if ( prop.IsNotNull() ) 00112 { 00113 typedef itk::SimpleMemberCommand< QmitkScalarBarOverlay > MemberCommandType; 00114 MemberCommandType::Pointer propModifiedCommand; 00115 propModifiedCommand = MemberCommandType::New(); 00116 propModifiedCommand->SetCallbackFunction( this, &QmitkScalarBarOverlay::SetScaleFactor ); 00117 prop->AddObserver( itk::ModifiedEvent(), propModifiedCommand ); 00118 } 00119 else 00120 { 00121 MITK_ERROR << "invalid property"; 00122 } 00123 } 00124