A QLabel with multiple hotspots, that can be clicked. More...
#include <qclickablelabel.h>
Signals | |
| void | mousePressed (const QString &hotspotName) |
| void | mousePressed (unsigned int hotspotIndex) |
| void | mouseReleased (const QString &hotspotName) |
| void | mouseReleased (unsigned int hotspotIndex) |
Public Member Functions | |
| QClickableLabel (QWidget *parent, Qt::WFlags f=0) | |
| QClickableLabel (const QString &text, QWidget *parent, Qt::WFlags f=0) | |
| virtual | ~QClickableLabel () |
| void | AddHotspot (const QString &name, const QRect position) |
| void | RemoveHotspot (const QString &name) |
| void | RemoveHotspot (unsigned int hotspotIndex) |
| void | RemoveAllHotspots () |
Protected Types | |
| typedef std::vector< QRect > | RectVectorType |
| typedef std::map< QString, unsigned int > | NameToIndexMapType |
| typedef std::map< unsigned int, QString > | IndexToNameMapType |
Protected Member Functions | |
| virtual void | mousePressEvent (QMouseEvent *e) |
| virtual void | mouseReleaseEvent (QMouseEvent *e) |
| unsigned int | matchingRect (const QPoint &p) |
| returns index == m_Hotspots.size() if nothing is hit | |
Protected Attributes | |
| RectVectorType | m_Hotspots |
| NameToIndexMapType | m_HotspotIndexForName |
| IndexToNameMapType | m_HotspotNameForIndex |
A QLabel with multiple hotspots, that can be clicked.
Specially useful in connection with a pixmap. Stretched images should be avoided, because the hotspots will not be adjusted in any way.
Definition at line 36 of file qclickablelabel.h.
typedef std::map< unsigned int, QString > QClickableLabel::IndexToNameMapType [protected] |
Definition at line 71 of file qclickablelabel.h.
typedef std::map< QString, unsigned int > QClickableLabel::NameToIndexMapType [protected] |
Definition at line 70 of file qclickablelabel.h.
typedef std::vector< QRect > QClickableLabel::RectVectorType [protected] |
Definition at line 67 of file qclickablelabel.h.
| QClickableLabel::QClickableLabel | ( | QWidget * | parent, |
| Qt::WFlags | f = 0 |
||
| ) |
Definition at line 24 of file qclickablelabel.cpp.
:QLabel(parent, f)
{
}
| QClickableLabel::QClickableLabel | ( | const QString & | text, |
| QWidget * | parent, | ||
| Qt::WFlags | f = 0 |
||
| ) |
Definition at line 31 of file qclickablelabel.cpp.
:QLabel(text, parent, f)
{
}
| QClickableLabel::~QClickableLabel | ( | ) | [virtual] |
Definition at line 38 of file qclickablelabel.cpp.
{
}
| void QClickableLabel::AddHotspot | ( | const QString & | name, |
| const QRect | position | ||
| ) |
Definition at line 43 of file qclickablelabel.cpp.
References m_HotspotIndexForName, m_HotspotNameForIndex, and m_Hotspots.
Referenced by QmitkStandardViews::QmitkStandardViews().
{
m_Hotspots.push_back( position );
m_HotspotIndexForName.insert( std::make_pair( name, (int)m_Hotspots.size()-1 ) );
m_HotspotNameForIndex.insert( std::make_pair( (int)m_Hotspots.size()-1, name ) );
}
| unsigned int QClickableLabel::matchingRect | ( | const QPoint & | p ) | [protected] |
returns index == m_Hotspots.size() if nothing is hit
Definition at line 99 of file qclickablelabel.cpp.
References m_Hotspots.
Referenced by mousePressEvent(), and mouseReleaseEvent().
{
unsigned int index(0);
for ( RectVectorType::iterator iter = m_Hotspots.begin();
iter != m_Hotspots.end();
++iter )
{
if ( iter->contains(p) )
{
return index;
}
++index;
}
return index;
}
| void QClickableLabel::mousePressed | ( | const QString & | hotspotName ) | [signal] |
Referenced by mouseReleaseEvent().
| void QClickableLabel::mousePressed | ( | unsigned int | hotspotIndex ) | [signal] |
| void QClickableLabel::mousePressEvent | ( | QMouseEvent * | e ) | [protected, virtual] |
Definition at line 79 of file qclickablelabel.cpp.
References m_HotspotNameForIndex, m_Hotspots, matchingRect(), and mouseReleased().
{
unsigned int index = matchingRect( e->pos() );
if ( index < m_Hotspots.size() )
{
emit mouseReleased( index );
emit mouseReleased( m_HotspotNameForIndex[index] );
}
}
| void QClickableLabel::mouseReleased | ( | unsigned int | hotspotIndex ) | [signal] |
| void QClickableLabel::mouseReleased | ( | const QString & | hotspotName ) | [signal] |
Referenced by mousePressEvent().
| void QClickableLabel::mouseReleaseEvent | ( | QMouseEvent * | e ) | [protected, virtual] |
Definition at line 89 of file qclickablelabel.cpp.
References m_HotspotNameForIndex, m_Hotspots, matchingRect(), and mousePressed().
{
unsigned int index = matchingRect( e->pos() );
if ( index < m_Hotspots.size() )
{
emit mousePressed( index );
emit mousePressed( m_HotspotNameForIndex[index] );
}
}
| void QClickableLabel::RemoveAllHotspots | ( | ) |
Definition at line 72 of file qclickablelabel.cpp.
References m_HotspotIndexForName, m_HotspotNameForIndex, and m_Hotspots.
{
m_Hotspots.clear();
m_HotspotIndexForName.clear();
m_HotspotNameForIndex.clear();
}
| void QClickableLabel::RemoveHotspot | ( | unsigned int | hotspotIndex ) |
Definition at line 61 of file qclickablelabel.cpp.
References m_HotspotIndexForName, m_HotspotNameForIndex, and m_Hotspots.
{
if ( hotspotIndex < m_Hotspots.size() )
{
m_Hotspots.erase( m_Hotspots.begin() + hotspotIndex );
QString name = m_HotspotNameForIndex[hotspotIndex];
m_HotspotNameForIndex.erase( hotspotIndex );
m_HotspotIndexForName.erase( name );
}
}
| void QClickableLabel::RemoveHotspot | ( | const QString & | name ) |
Definition at line 51 of file qclickablelabel.cpp.
References m_HotspotIndexForName.
{
NameToIndexMapType::iterator iter = m_HotspotIndexForName.find( name );
if ( iter != m_HotspotIndexForName.end() )
{
RemoveHotspot( iter->second );
}
}
Definition at line 72 of file qclickablelabel.h.
Referenced by AddHotspot(), RemoveAllHotspots(), and RemoveHotspot().
Definition at line 73 of file qclickablelabel.h.
Referenced by AddHotspot(), mousePressEvent(), mouseReleaseEvent(), RemoveAllHotspots(), and RemoveHotspot().
RectVectorType QClickableLabel::m_Hotspots [protected] |
Definition at line 68 of file qclickablelabel.h.
Referenced by AddHotspot(), matchingRect(), mousePressEvent(), mouseReleaseEvent(), RemoveAllHotspots(), and RemoveHotspot().
1.7.2