Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "QmitkTextOverlay.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 QmitkTextOverlay::QmitkTextOverlay( const char* id ):
00030 QmitkOverlay(id), m_Widget( NULL )
00031 {
00032 m_Widget = new QLabel();
00033 m_Widget->setStyleSheet("");
00034 }
00035
00036 QmitkTextOverlay::~QmitkTextOverlay()
00037 {
00038 m_Widget = NULL;
00039 }
00040
00041 void QmitkTextOverlay::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->GetTextProperties( pl );
00053 this->SetText();
00054 }
00055 else
00056 {
00057 MITK_ERROR << "invalid propList";
00058 }
00059
00060 }
00061
00062 void QmitkTextOverlay::SetText()
00063 {
00064 std::string text = "";
00065 if ( m_PropertyList.IsNull() || !m_PropertyList->GetStringProperty( m_Id, text ) )
00066 {
00067 MITK_WARN << "Property " << m_Id << " could not be found";
00068 }
00069 m_Widget->setText( text.c_str() );
00070 m_Widget->repaint();
00071 }
00072
00073
00074 void QmitkTextOverlay::GetTextProperties( mitk::PropertyList::Pointer pl )
00075 {
00076 if ( pl.IsNull() )
00077 return;
00078
00079 mitk::PropertyList::Pointer propertyList = pl;
00080 QPalette palette = QPalette();
00081 QFont font = QFont();
00082
00083
00084 mitk::ColorProperty::Pointer colorProp =
00085 dynamic_cast<mitk::ColorProperty*>( propertyList->GetProperty( "overlay.color" ) );
00086
00087 if ( colorProp.IsNull() )
00088 {
00089 MITK_ERROR << "creating new colorProperty";
00090 colorProp = mitk::ColorProperty::New( 127.0, 196.0, 232.0 );
00091 }
00092
00093 mitk::Color color = colorProp->GetColor();
00094 palette.setColor( QPalette::Foreground, QColor( color[0],color[1],color[2],255 ) );
00095 palette.setColor( QPalette::Window, Qt::transparent);
00096 m_Widget->setPalette( palette );
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 int fontSize = 0;
00113 if ( !propertyList->GetIntProperty( "overlay.fontSize", fontSize ) )
00114 {
00115 fontSize = 9.5;
00116 }
00117 font.setPointSize( fontSize );
00118
00119 bool useKerning = false;
00120 if ( !propertyList->GetBoolProperty( "overlay.kerning", useKerning ) )
00121 {
00122 useKerning = true;
00123 }
00124 font.setKerning( useKerning );
00125
00126 std::string fontFamily = "";
00127 if ( !propertyList->GetStringProperty( "overlay.fontFamily", fontFamily ) )
00128 {
00129 fontFamily = "Verdana";
00130 }
00131 font.setFamily( QString(fontFamily.c_str()) );
00132
00133 m_Widget->setFont( font );
00134
00135 }
00136
00137 QLabel* QmitkTextOverlay::GetWidget()
00138 {
00139 return m_Widget;
00140 }
00141
00142
00143 void QmitkTextOverlay::SetupCallback( mitk::BaseProperty::Pointer prop )
00144 {
00145 if ( prop.IsNotNull() )
00146 {
00147 typedef itk::SimpleMemberCommand< QmitkTextOverlay > MemberCommandType;
00148 MemberCommandType::Pointer propModifiedCommand;
00149 propModifiedCommand = MemberCommandType::New();
00150 propModifiedCommand->SetCallbackFunction( this, &QmitkTextOverlay::SetText );
00151 prop->AddObserver( itk::ModifiedEvent(), propModifiedCommand );
00152 }
00153 else
00154 {
00155 MITK_ERROR << "invalid property";
00156 }
00157 }
00158