#include <QmitkScalarBar.h>
Public Types | |
enum | alignment { vertical = 0, horizontal = 1 } |
Public Member Functions | |
QmitkScalarBar (QWidget *parent=0) | |
Default Constructor. | |
virtual | ~QmitkScalarBar () |
Default Destructor. | |
virtual void | SetScaleFactor (double scale) |
virtual void | SetAlignment (alignment align) |
void | SetPen (const QPen &pen) |
void | SetNumberOfSubdivisions (unsigned int subs) |
unsigned int | GetNumberOfSubdivisions () |
Protected Member Functions | |
void | paintEvent (QPaintEvent *event) |
void | SetupGeometry (alignment align) |
Protected Attributes | |
alignment | m_Alignment |
double | m_ScaleFactor |
QLine * | m_VerticalLine |
std::vector< QLine * > | m_HorizontalLines |
QPen | m_Pen |
unsigned int | m_NumberOfSubDivisions |
Definition at line 30 of file QmitkScalarBar.h.
Definition at line 35 of file QmitkScalarBar.h.
{ vertical = 0, horizontal = 1 };
QmitkScalarBar::QmitkScalarBar | ( | QWidget * | parent = 0 ) |
Default Constructor.
Definition at line 23 of file QmitkScalarBar.cpp.
References m_Alignment, m_NumberOfSubDivisions, m_Pen, and SetupGeometry().
: QWidget( parent, Qt::Tool | Qt::FramelessWindowHint ), m_Alignment(vertical) { 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( 20,60 ); this->setFixedWidth( 20 ); this->setFixedHeight( 60 ); m_Pen = QPen( Qt::red, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin ); }
QmitkScalarBar::~QmitkScalarBar | ( | ) | [virtual] |
unsigned int QmitkScalarBar::GetNumberOfSubdivisions | ( | ) |
Definition at line 150 of file QmitkScalarBar.cpp.
References m_NumberOfSubDivisions.
{ return m_NumberOfSubDivisions; }
void QmitkScalarBar::paintEvent | ( | QPaintEvent * | event ) | [protected] |
Definition at line 156 of file QmitkScalarBar.cpp.
References m_HorizontalLines, m_NumberOfSubDivisions, m_Pen, m_VerticalLine, and MITK_ERROR.
{ if ( m_NumberOfSubDivisions > 1 ) { try { QPainter painter(this); painter.setPen( m_Pen ); painter.setBrush( Qt::SolidPattern ); painter.setRenderHint( QPainter::Antialiasing, true ); painter.drawLine( m_VerticalLine->p1(), m_VerticalLine->p2() ); foreach( QLine* line, m_HorizontalLines ) { painter.drawLine( line->p1(), line->p2() ); } } catch (...) { MITK_ERROR << "ScalarBar cannot be drawn."; } } }
void QmitkScalarBar::SetAlignment | ( | alignment | align ) | [virtual] |
Definition at line 182 of file QmitkScalarBar.cpp.
References m_Alignment, and SetupGeometry().
{ m_Alignment = align; this->SetupGeometry( align ); }
void QmitkScalarBar::SetNumberOfSubdivisions | ( | unsigned int | subs ) |
Definition at line 145 of file QmitkScalarBar.cpp.
References m_NumberOfSubDivisions.
{ m_NumberOfSubDivisions = subs; }
void QmitkScalarBar::SetPen | ( | const QPen & | pen ) |
Definition at line 188 of file QmitkScalarBar.cpp.
References m_Pen.
Referenced by QmitkScalarBarOverlay::GetProperties().
{ m_Pen = pen; }
void QmitkScalarBar::SetScaleFactor | ( | double | scale ) | [virtual] |
Definition at line 107 of file QmitkScalarBar.cpp.
References m_Alignment, m_NumberOfSubDivisions, m_ScaleFactor, and SetupGeometry().
Referenced by QmitkScalarBarOverlay::SetScaleFactor().
{ 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( 20, (m_NumberOfSubDivisions-1)*10/m_ScaleFactor ); this->setFixedWidth( 20 ); 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::SetupGeometry | ( | alignment | align ) | [protected] |
Definition at line 56 of file QmitkScalarBar.cpp.
References horizontal, m_HorizontalLines, m_NumberOfSubDivisions, m_VerticalLine, and vertical.
Referenced by QmitkScalarBar(), SetAlignment(), and SetScaleFactor().
{ m_HorizontalLines.clear(); switch ( align ) { case vertical : { for ( unsigned int i=0; i<m_NumberOfSubDivisions; ++i ) { int y = this->height()/(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_HorizontalLines.push_back( new QLine( QPoint(0,y), QPoint(width(),y) ) ); } if ( m_HorizontalLines.size() > 0 ) m_VerticalLine = new QLine( QPoint(width()/2,0), QPoint(width()/2,height()) ); break; } case horizontal : { for ( unsigned int i=0; i<m_NumberOfSubDivisions; ++i ) { int x = this->width()/(m_NumberOfSubDivisions-1)*i; if ( i==0 ) { x = 1; } else if ( i==m_NumberOfSubDivisions-1 ) { x = this->width() - 1; } m_HorizontalLines.push_back( new QLine( QPoint(x,0), QPoint(x,height()) ) ); } if ( m_HorizontalLines.size() > 0 ) m_VerticalLine = new QLine( QPoint(0,height()/2), QPoint(width(),height()/2) ); break; } } }
alignment QmitkScalarBar::m_Alignment [protected] |
Definition at line 69 of file QmitkScalarBar.h.
Referenced by QmitkScalarBar(), SetAlignment(), and SetScaleFactor().
std::vector<QLine*> QmitkScalarBar::m_HorizontalLines [protected] |
Definition at line 75 of file QmitkScalarBar.h.
Referenced by paintEvent(), and SetupGeometry().
unsigned int QmitkScalarBar::m_NumberOfSubDivisions [protected] |
Definition at line 79 of file QmitkScalarBar.h.
Referenced by GetNumberOfSubdivisions(), paintEvent(), QmitkScalarBar(), SetNumberOfSubdivisions(), SetScaleFactor(), and SetupGeometry().
QPen QmitkScalarBar::m_Pen [protected] |
Definition at line 77 of file QmitkScalarBar.h.
Referenced by paintEvent(), QmitkScalarBar(), and SetPen().
double QmitkScalarBar::m_ScaleFactor [protected] |
Definition at line 71 of file QmitkScalarBar.h.
Referenced by SetScaleFactor().
QLine* QmitkScalarBar::m_VerticalLine [protected] |
Definition at line 73 of file QmitkScalarBar.h.
Referenced by paintEvent(), and SetupGeometry().