diff --git a/Modules/Overlays/QmitkOverlay.cpp b/Modules/Overlays/QmitkOverlay.cpp index e6dc99b169..27f3cd7f30 100644 --- a/Modules/Overlays/QmitkOverlay.cpp +++ b/Modules/Overlays/QmitkOverlay.cpp @@ -1,57 +1,79 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2010-01-14 14:20:26 +0100 (Thu, 14 Jan 2010) $ Version: $Revision: 21047 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkOverlay.h" #include +#include -QmitkOverlay::QmitkOverlay( const char* id ): -QObject(), m_Id(id), m_Position(top_Left), m_Layer(-1) + +QmitkOverlay::QmitkOverlay( const char* id ) +:QObject() +, m_Id(id) +, m_Position(top_Left) +, m_Layer(-1) +, m_Widget(NULL) { - m_Widget = new QWidget(); } QmitkOverlay::~QmitkOverlay() { - + if (m_Widget) + { + m_Widget->deleteLater(); + m_Widget = NULL; + } } QmitkOverlay::DisplayPosition QmitkOverlay::GetPosition() { return m_Position; } void QmitkOverlay::SetPosition( DisplayPosition pos ) { m_Position = pos; } unsigned int QmitkOverlay::GetLayer() { return m_Layer; } void QmitkOverlay::SetLayer( unsigned int layer ) { m_Layer = layer; } QWidget* QmitkOverlay::GetWidget() { return m_Widget; -} \ No newline at end of file +} + +void QmitkOverlay::AddDropShadow( QWidget* widget ) +{ + QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect(widget); + effect->setOffset( QPointF( 1.0, 1.0 ) ); + effect->setBlurRadius( 0 ); + effect->setColor( Qt::black ); + + widget->setGraphicsEffect( effect ); +} + + + diff --git a/Modules/Overlays/QmitkOverlay.h b/Modules/Overlays/QmitkOverlay.h index 4aac959514..991a9a86f1 100644 --- a/Modules/Overlays/QmitkOverlay.h +++ b/Modules/Overlays/QmitkOverlay.h @@ -1,126 +1,130 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-28 17:19:30 +0200 (Thu, 28 May 2009) $ Version: $Revision: 17495 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKOVERLAY_H_HEADER_INCLUDED_C10DC4EB #define MITKOVERLAY_H_HEADER_INCLUDED_C10DC4EB // MITK #include "mitkCommon.h" #include "mitkPropertyList.h" // Qt #include #include "OverlaysExports.h" /** \brief Abstract base class for all overlay-objects in MITK This class is the basis for all classes representing objects that can be visualized as overlays in MITK. It encapsulates an ID, as well as a display-position and a layer. The ID is used to access mitkProperties in a PropertyList that holds information that is needed for the visualization, e.g. text for TextOverlays or scaleFactor for ScalarBarOverlays ... The display-position encodes where on the screen the overlay will be positioned at (see and USE the constants defined by DisplayPosition): \verbatim 0 - 1 - 2 | | | 3 - - 4 | | | 5 - 6 - 7 \endverbatim The layer is needed if several overlays shall be put in the same position. In this case the layer defines the order in which the objects are layouted. \ingroup Qmitk */ class Overlays_EXPORT QmitkOverlay : public QObject { Q_OBJECT public: /** \brief enumeration of all possible display positions */ enum DisplayPosition { top_Left = 0, top_Center = 1, top_Right = 2, middle_Left = 3, middle_Right = 4, bottom_Left = 5, bottom_Center = 6, bottom_Right = 7 }; /** * @brief Constructor with string ID **/ QmitkOverlay(const char* id); /** * @brief Default Destructor **/ virtual ~QmitkOverlay(); /** \brief setter for the display-position */ virtual void SetPosition( DisplayPosition ); /** \brief getter for the display-position */ virtual DisplayPosition GetPosition(); /** \brief setter for the layer */ virtual void SetLayer( unsigned int ); /** \brief getter for the layer */ virtual unsigned int GetLayer(); /** * \brief abstract method to internally setup the overlay */ virtual void GenerateData( mitk::PropertyList::Pointer /*pl*/ ) {}; /** * \brief returns the internally handled QWidget */ virtual QWidget* GetWidget(); - protected: + /** + \brief Add drop shadow effect via QGraphicsEffect + */ + void AddDropShadow( QWidget* widget ); + /** \brief ID of the overlay */ const char* m_Id; /** \brief position of the overlay */ DisplayPosition m_Position; /** \brief layer of the overlay */ unsigned int m_Layer; /** \brief internal QWidget representing the overlay */ QWidget* m_Widget; }; #endif /* MITKOVERLAY_H_HEADER_INCLUDED_C10DC4EB */ diff --git a/Modules/Overlays/QmitkScalarBar.cpp b/Modules/Overlays/QmitkScalarBar.cpp index fd1774e916..e7d25ac2d8 100644 --- a/Modules/Overlays/QmitkScalarBar.cpp +++ b/Modules/Overlays/QmitkScalarBar.cpp @@ -1,241 +1,240 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2010-01-14 14:20:26 +0100 (Thu, 14 Jan 2010) $ Version: $Revision: 21047 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkScalarBar.h" #include #include -QmitkScalarBar::QmitkScalarBar(QWidget* parent): -QWidget( parent, Qt::Tool | Qt::FramelessWindowHint ), m_Alignment(vertical), m_MainLine(NULL) +QmitkScalarBar::QmitkScalarBar(QWidget* parent) +: QWidget( parent, Qt::Tool | Qt::FramelessWindowHint ), m_Alignment(vertical), m_MainLine(NULL) { m_NumberOfSubDivisions = 7; this->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); this->SetupGeometry( m_Alignment ); this->setBackgroundRole(QPalette::Base); this->setAttribute( Qt::WA_TranslucentBackground, true ); this->setAutoFillBackground(false); // X11 specific attributes this->setAttribute( Qt::WA_X11NetWmWindowTypeUtility, true ); // mac-specific attributes: // making sure overlays are even visible if RenderWindow does not have the focus (not default for Qt::Tool on mac) this->setAttribute( Qt::WA_MacAlwaysShowToolWindow, true ); // testing something this->setAttribute( Qt::WA_MacShowFocusRect, false ); this->resize( 10,61 ); this->setFixedWidth( 10 ); this->setFixedHeight( 61 ); - m_Pen = QPen( Qt::red, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin ); } QmitkScalarBar::~QmitkScalarBar() { CleanUpLines(); } void QmitkScalarBar::SetupGeometry( alignment align ) { this->CleanUpLines(); switch ( align ) { case vertical : { //draw subdivision for ( unsigned int i=0; iheight()/(m_NumberOfSubDivisions-1)*i; if ( i==0 ) { // this is the first one -> move y 1 down to have this line completely drawn y = 1; } else if ( i==m_NumberOfSubDivisions-1 ) { // this is the last one -> move y 1 up to have this line completely drawn y = this->height() - 1; } m_SubDivisionLines.push_back( new QLine( QPoint(0,y), QPoint(width()-2,y) ) ); } //draw mainline if ( m_SubDivisionLines.size() > 0 ) { m_MainLine = new QLine( QPoint(width()-1,0), QPoint(width()-1,height()) ); } else { m_MainLine = new QLine( QPoint(0,0), QPoint(0,0) ); //do not draw the line } break; } case horizontal : { //draw subdivision for ( unsigned int i=0; iwidth()/(m_NumberOfSubDivisions-1)*i; if ( i==0 ) { x = 1; } else if ( i==m_NumberOfSubDivisions-1 ) { x = this->width() - 1; } m_SubDivisionLines.push_back( new QLine( QPoint(x,0), QPoint(x,height()) ) ); } //draw mainline if ( m_SubDivisionLines.size() > 0 ) { m_MainLine = new QLine( QPoint(0,height()/2), QPoint(width(),height()/2) ); } else { m_MainLine = new QLine( QPoint(0,0), QPoint(0,0) ); //do not draw the line } break; } } } void QmitkScalarBar::CleanUpLines() { foreach(QLine* line, m_SubDivisionLines) { delete line; //QLine is not a QObject line = NULL; } m_SubDivisionLines.clear(); if(m_MainLine != NULL) { delete m_MainLine; m_MainLine = NULL; } } void QmitkScalarBar::SetScaleFactor( double scale ) { m_ScaleFactor = scale; // Adopt the number of small, intersecting lines to the size of the widget. if ( this->parentWidget() != NULL && this->parentWidget()->parentWidget() != NULL ) { // If the widget is larger than 80% of the size of the parent -> reduce number by two (must not be smaller than 3) if ( this->height() > this->parentWidget()->parentWidget()->height()*0.7 && m_NumberOfSubDivisions >= 3 ) { m_NumberOfSubDivisions-=2; } // If the widget is smaller than 30% of the size of the parent -> increase number by two else if ( this->height() < this->parentWidget()->parentWidget()->height()*0.4 && ( m_NumberOfSubDivisions < 7 && m_NumberOfSubDivisions > 0 ) ) { m_NumberOfSubDivisions+=2; } if ( m_NumberOfSubDivisions == 1 ) { this->resize( 0, 0 ); this->setFixedWidth( 0 ); this->setFixedHeight( 0 ); } else { this->resize( 10, (m_NumberOfSubDivisions-1)*10/m_ScaleFactor ); this->setFixedWidth( 10 ); this->setFixedHeight( (m_NumberOfSubDivisions-1)*10/m_ScaleFactor ); this->SetupGeometry(m_Alignment); } if ( this->height() > this->parentWidget()->parentWidget()->height()*0.7 && m_NumberOfSubDivisions >= 3 ) SetScaleFactor( scale ); } } void QmitkScalarBar::SetNumberOfSubdivisions( unsigned int subs ) { m_NumberOfSubDivisions = subs; } unsigned int QmitkScalarBar::GetNumberOfSubdivisions() { return m_NumberOfSubDivisions; } void QmitkScalarBar::paintEvent(QPaintEvent* /*event*/) { if ( m_NumberOfSubDivisions > 1 ) { try { //QPainter shadowPainter( this ); //shadowPainter.setPen( QPen( QColor(0,0,0,255) ) ); //shadowPainter.setBrush( Qt::SolidPattern ); //shadowPainter.setRenderHint( QPainter::Antialiasing, true ); //shadowPainter.drawLine( m_VerticalLine->p1()+QPoint(1,1), m_VerticalLine->p2()+QPoint(1,1) ); //foreach( QLine* line, m_HorizontalLines ) //{ // shadowPainter.drawLine( line->p1()+QPoint(1,1), line->p2()+QPoint(1,1) ); //} QPainter painter(this); painter.setPen( m_Pen ); painter.setBrush( Qt::SolidPattern ); painter.setRenderHint( QPainter::Antialiasing, true ); painter.drawLine( m_MainLine->p1(), m_MainLine->p2() ); foreach( QLine* line, m_SubDivisionLines ) { painter.drawLine( line->p1(), line->p2() ); } } catch (...) { MITK_ERROR << "ScalarBar cannot be drawn."; } } } void QmitkScalarBar::SetAlignment( alignment align ) { m_Alignment = align; this->SetupGeometry( align ); } void QmitkScalarBar::SetPen( const QPen& pen ) { m_Pen = pen; -} \ No newline at end of file +} diff --git a/Modules/Overlays/QmitkScalarBarOverlay.cpp b/Modules/Overlays/QmitkScalarBarOverlay.cpp index 86e09978f1..78096ee01e 100644 --- a/Modules/Overlays/QmitkScalarBarOverlay.cpp +++ b/Modules/Overlays/QmitkScalarBarOverlay.cpp @@ -1,127 +1,120 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2010-01-14 14:20:26 +0100 (Thu, 14 Jan 2010) $ Version: $Revision: 21047 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkScalarBarOverlay.h" #include "mitkProperties.h" #include "mitkColorProperty.h" #include "mitkPropertyList.h" #include #include -QmitkScalarBarOverlay::QmitkScalarBarOverlay( const char* id ): -QmitkOverlay(id), m_Widget( NULL ), m_ObserverTag(0) +QmitkScalarBarOverlay::QmitkScalarBarOverlay( const char* id ) +:QmitkOverlay(id) +, m_ScalarBar( NULL ) +, m_ObserverTag(0) { - m_Widget = new QmitkScalarBar(); - m_Widget->setStyleSheet(""); + m_Widget = m_ScalarBar = new QmitkScalarBar(); + QmitkOverlay::AddDropShadow( m_ScalarBar ); } QmitkScalarBarOverlay::~QmitkScalarBarOverlay() { - m_Widget->deleteLater(); - m_Widget = NULL; - m_PropertyList->GetProperty( m_Id )->RemoveObserver(m_ObserverTag); } void QmitkScalarBarOverlay::GenerateData( mitk::PropertyList::Pointer pl ) { if ( pl.IsNull() ) return; m_PropertyList = pl; 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"; } - m_Widget->SetScaleFactor( scale ); + 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 = 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_Widget->SetPen( pen ); + m_ScalarBar->SetPen( pen ); } -QWidget* QmitkScalarBarOverlay::GetWidget() -{ - return m_Widget; -} - - void QmitkScalarBarOverlay::SetupCallback( mitk::BaseProperty::Pointer prop ) { if ( prop.IsNotNull() ) { typedef itk::SimpleMemberCommand< QmitkScalarBarOverlay > MemberCommandType; MemberCommandType::Pointer propModifiedCommand; propModifiedCommand = MemberCommandType::New(); propModifiedCommand->SetCallbackFunction( this, &QmitkScalarBarOverlay::SetScaleFactor ); m_ObserverTag = prop->AddObserver( itk::ModifiedEvent(), propModifiedCommand ); } else { MITK_DEBUG << "invalid property"; } } diff --git a/Modules/Overlays/QmitkScalarBarOverlay.h b/Modules/Overlays/QmitkScalarBarOverlay.h index cd22866bc4..600f63f451 100644 --- a/Modules/Overlays/QmitkScalarBarOverlay.h +++ b/Modules/Overlays/QmitkScalarBarOverlay.h @@ -1,96 +1,91 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-28 17:19:30 +0200 (Thu, 28 May 2009) $ Version: $Revision: 17495 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #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 * will show an empty string! */ virtual void GenerateData( mitk::PropertyList::Pointer ); - /** - * \brief returns the QLabel* that internally represents the TextOverlay - */ - virtual QWidget* GetWidget(); - 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 * 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_Widget; + QmitkScalarBar* m_ScalarBar; 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 b85b3ce006..2564b4794f 100644 --- a/Modules/Overlays/QmitkTextOverlay.cpp +++ b/Modules/Overlays/QmitkTextOverlay.cpp @@ -1,160 +1,148 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2010-01-14 14:20:26 +0100 (Thu, 14 Jan 2010) $ Version: $Revision: 21047 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkTextOverlay.h" #include "mitkProperties.h" #include "mitkColorProperty.h" #include "mitkPropertyList.h" #include -#include - - -QmitkTextOverlay::QmitkTextOverlay( const char* id ): -QmitkOverlay(id), m_Widget( NULL ), m_ObserverTag(0) +QmitkTextOverlay::QmitkTextOverlay( const char* id ) +: QmitkOverlay(id) +, m_ObserverTag(0) { - m_Widget = new QLabel(); - m_Widget->setStyleSheet(""); + m_Widget = m_Label = new QLabel(); + QmitkOverlay::AddDropShadow( m_Widget ); } QmitkTextOverlay::~QmitkTextOverlay() { - m_Widget->deleteLater(); - m_Widget = NULL; - 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->GetTextProperties( pl ); - this->SetText(); + this->UpdateFontProperties( pl ); + this->UpdateDisplayedTextFromProperties(); } else { MITK_ERROR << "invalid propList"; } } -void QmitkTextOverlay::SetText() +void QmitkTextOverlay::UpdateDisplayedTextFromProperties() { - std::string text = ""; + std::string text; if ( m_PropertyList.IsNull() || !m_PropertyList->GetStringProperty( m_Id, text ) ) { MITK_DEBUG << "Property " << m_Id << " could not be found"; } - m_Widget->setText( text.c_str() ); - m_Widget->repaint(); + m_Label->setText( text.c_str() ); + m_Label->repaint(); } -void QmitkTextOverlay::GetTextProperties( mitk::PropertyList::Pointer pl ) +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 = 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_Widget->setPalette( palette ); + 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_Widget->setWindowOpacity( 1 ); + // m_Label->setWindowOpacity( 1 ); //} //else //{ - // m_Widget->setWindowOpacity( opacityProperty->GetValue() ); + // 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_Widget->setFont( font ); - -} - -QLabel* QmitkTextOverlay::GetWidget() -{ - return m_Widget; + m_Label->setFont( font ); } - void QmitkTextOverlay::SetupCallback( mitk::BaseProperty::Pointer prop ) { if ( prop.IsNotNull() ) { typedef itk::SimpleMemberCommand< QmitkTextOverlay > MemberCommandType; MemberCommandType::Pointer propModifiedCommand; propModifiedCommand = MemberCommandType::New(); - propModifiedCommand->SetCallbackFunction( this, &QmitkTextOverlay::SetText ); + propModifiedCommand->SetCallbackFunction( this, &QmitkTextOverlay::UpdateDisplayedTextFromProperties ); m_ObserverTag = prop->AddObserver( itk::ModifiedEvent(), propModifiedCommand ); } else { MITK_DEBUG << "invalid property"; } } diff --git a/Modules/Overlays/QmitkTextOverlay.h b/Modules/Overlays/QmitkTextOverlay.h index 2f21812c89..078bff07aa 100644 --- a/Modules/Overlays/QmitkTextOverlay.h +++ b/Modules/Overlays/QmitkTextOverlay.h @@ -1,119 +1,115 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-28 17:19:30 +0200 (Thu, 28 May 2009) $ Version: $Revision: 17495 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKTEXTOVERLAY_H_HEADER_INCLUDED_C10DC4EB #define MITKTEXTOVERLAY_H_HEADER_INCLUDED_C10DC4EB -// MITK-Stuff +// 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 * 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) * * \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 * will show an empty string! */ void GenerateData( mitk::PropertyList::Pointer ); - /** - * \brief returns the QLabel* that internally represents the TextOverlay - */ - QLabel* GetWidget(); - 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 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 label using QFont and QPalette. + * The values of these properties are then attributed to the QLabel using QFont and QPalette. */ - void GetTextProperties( mitk::PropertyList::Pointer ); + void UpdateFontProperties( mitk::PropertyList::Pointer ); void SetupCallback( mitk::BaseProperty::Pointer prop ); - void SetText(); + void UpdateDisplayedTextFromProperties(); /** \brief QLabel internally representing the TextOverlay */ - QLabel* m_Widget; + QLabel* m_Label; mitk::PropertyList::Pointer m_PropertyList; unsigned long m_ObserverTag; }; #endif /* MITKTEXTOVERLAY_H_HEADER_INCLUDED_C10DC4EB */