object representing a text that is drawn as an overlay More...
#include <QmitkTextOverlay.h>
Public Member Functions | |
QmitkTextOverlay (const char *id) | |
Default Constructor. | |
virtual | ~QmitkTextOverlay () |
Default Destructor. | |
void | GenerateData (mitk::PropertyList::Pointer) |
Setup the QLabel with overlay specific information. | |
QLabel * | GetWidget () |
returns the QLabel* that internally represents the TextOverlay | |
Protected Member Functions | |
void | GetTextProperties (mitk::PropertyList::Pointer) |
internal helper class to determine text-properties | |
void | SetupCallback (mitk::BaseProperty::Pointer prop) |
void | SetText () |
Protected Attributes | |
QLabel * | m_Widget |
QLabel internally representing the TextOverlay. | |
mitk::PropertyList::Pointer | m_PropertyList |
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 a QmitkRenderWindow.
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 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 (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)
Definition at line 62 of file QmitkTextOverlay.h.
QmitkTextOverlay::QmitkTextOverlay | ( | const char * | id ) |
Default Constructor.
Definition at line 29 of file QmitkTextOverlay.cpp.
References m_Widget.
: QmitkOverlay(id), m_Widget( NULL ) { m_Widget = new QLabel(); m_Widget->setStyleSheet(""); }
QmitkTextOverlay::~QmitkTextOverlay | ( | ) | [virtual] |
Default Destructor.
Definition at line 36 of file QmitkTextOverlay.cpp.
References m_Widget.
{ m_Widget = NULL; }
void QmitkTextOverlay::GenerateData | ( | mitk::PropertyList::Pointer | pl ) | [virtual] |
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.
No error will be issued if the property containing the text is not found, the TextOverlay will show an empty string!
Reimplemented from QmitkOverlay.
Definition at line 41 of file QmitkTextOverlay.cpp.
References GetTextProperties(), QmitkOverlay::m_Id, m_PropertyList, MITK_ERROR, SetText(), and SetupCallback().
{ if ( pl.IsNull() ) return; m_PropertyList = pl; if ( m_PropertyList.IsNotNull() ) { this->SetupCallback( m_PropertyList->GetProperty( m_Id ) ); this->GetTextProperties( pl ); this->SetText(); } else { MITK_ERROR << "invalid propList"; } }
void QmitkTextOverlay::GetTextProperties | ( | mitk::PropertyList::Pointer | pl ) | [protected] |
internal helper class to determine text-properties
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.
Definition at line 74 of file QmitkTextOverlay.cpp.
References m_Widget, MITK_ERROR, and mitk::ColorProperty::New().
Referenced by GenerateData().
{ 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 = dynamic_cast<mitk::ColorProperty*>( propertyList->GetProperty( "overlay.color" ) ); if ( colorProp.IsNull() ) { MITK_ERROR << "creating new colorProperty"; 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_Widget->setPalette( palette ); // get the desired opacity of the overlays //mitk::FloatProperty::Pointer opacityProperty = // dynamic_cast<mitk::FloatProperty*>( propertyList->GetProperty( "overlay.opacity" ) ); //if ( opacityProperty.IsNull() ) //{ // m_Widget->setWindowOpacity( 1 ); //} //else //{ // m_Widget->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_Widget->setFont( font ); }
QLabel * QmitkTextOverlay::GetWidget | ( | ) | [virtual] |
returns the QLabel* that internally represents the TextOverlay
Reimplemented from QmitkOverlay.
Definition at line 137 of file QmitkTextOverlay.cpp.
References m_Widget.
{ return m_Widget; }
void QmitkTextOverlay::SetText | ( | ) | [protected] |
Definition at line 62 of file QmitkTextOverlay.cpp.
References QmitkOverlay::m_Id, m_PropertyList, m_Widget, and MITK_WARN.
Referenced by GenerateData(), and SetupCallback().
{ std::string text = ""; if ( m_PropertyList.IsNull() || !m_PropertyList->GetStringProperty( m_Id, text ) ) { MITK_WARN << "Property " << m_Id << " could not be found"; } m_Widget->setText( text.c_str() ); m_Widget->repaint(); }
void QmitkTextOverlay::SetupCallback | ( | mitk::BaseProperty::Pointer | prop ) | [protected] |
Definition at line 143 of file QmitkTextOverlay.cpp.
References MITK_ERROR, and SetText().
Referenced by GenerateData().
{ if ( prop.IsNotNull() ) { typedef itk::SimpleMemberCommand< QmitkTextOverlay > MemberCommandType; MemberCommandType::Pointer propModifiedCommand; propModifiedCommand = MemberCommandType::New(); propModifiedCommand->SetCallbackFunction( this, &QmitkTextOverlay::SetText ); prop->AddObserver( itk::ModifiedEvent(), propModifiedCommand ); } else { MITK_ERROR << "invalid property"; } }
Definition at line 111 of file QmitkTextOverlay.h.
Referenced by GenerateData(), and SetText().
QLabel* QmitkTextOverlay::m_Widget [protected] |
QLabel internally representing the TextOverlay.
Reimplemented from QmitkOverlay.
Definition at line 109 of file QmitkTextOverlay.h.
Referenced by GetTextProperties(), GetWidget(), QmitkTextOverlay(), SetText(), and ~QmitkTextOverlay().