void KTickmarks_Widget::drawContents( QPainter* p ) { //kdDebug()<<"KTickmarks::drawContents( QPainter* "<<p<<" )"<<endl; bool left=false, right=false; if ( _pos&Arts::posLeft ) left=true; if ( _pos&Arts::posRight ) right=true; // Setting the font QFont font; font.setPixelSize( 8 /*font.pixelSize()/2*/ ); // Maybe this could be adjusted... p->setFont( font ); // Determining the size of the largest text (currently the text at the minimum-scale) QFontMetrics fontmetric( font ); QRect fontrect = fontmetric.boundingRect( QString::number( dbmin ) ); // Calculating stepsizes float _minstepcount = ( dbmax-dbmin )/minstep; float _minstep = minstep; // this value gets changed float _substepcount = ( dbmax-dbmin )/substep; float _substep = substep; // this value gets changed // Calculating minimum size of the widget int _minsize; // Shorcuts int w,h; QColor colornormal = colorGroup().foreground(); QColor colordiff = colorGroup().buttonText(); if ( _dir == Arts::BottomToTop || _dir == Arts::TopToBottom ) { p->translate( contentsRect().left(), contentsRect().bottom() ); // Calculating stepsizes for ( int i=1; _minstepcount*( fontrect.height()+4 ) > contentsRect().height(); i++ ) { _minstepcount = ( dbmax-dbmin ) / minstep / i; _minstep = minstep*i; } while ( _substepcount*2 > contentsRect().height() ) { _substepcount/=2; _substep*=2; } // Calculating minimum size of the widget _minsize=fontrect.width()+4; if ( left ) _minsize+=6; if ( right ) _minsize+=6; setMinimumWidth( _minsize + frameWidth() + 2 ); // setMaximumWidth( _minsize /*+6*/ ); w = contentsRect().width(); // Just a shortcut h=0; // Painting substep marks p->setPen( QPen( colordiff, 1 ) ); for ( float i=dbmax; i>=dbmin; i-=_substep ) { h = int( -contentsRect().height() * dbtondb( i ) ); if ( _dir==Arts::TopToBottom ) h = 1 - h; if ( left ) p->drawLine( 0, h, 3, h ); if ( right ) p->drawLine( w-3, h, w, h ); } // Painting step marks and texts p->setPen( QPen( colornormal, 1 ) ); for ( float i=0; i>=dbmin; i-=_minstep ) { h = int( -contentsRect().height() * dbtondb( i ) ); if ( _dir==Arts::TopToBottom ) h = 1 - h; if ( left ) p->drawLine( 0, h, 6, h ); p->drawText( ( w - (left)*6 - (right)*6 - fontrect.width() )/2 + (left)*6 , h-fontrect.height()/2, fontrect.width(), fontrect.height()+2, Qt::AlignRight|Qt::AlignTop, QString::number( i ) ); if ( right ) p->drawLine( w-6, h, w, h ); } for ( float i=_minstep; i<=dbmax; i+=_minstep ) { h = int( -contentsRect().height() * dbtondb( i ) ); if ( _dir==Arts::TopToBottom ) h = 1 - h; if ( left ) p->drawLine( 0, h, 6, h ); p->drawText( ( w - (left)*6 - (right)*6 - fontrect.width() )/2 + (left)*6 , h-fontrect.height()/2, fontrect.width(), fontrect.height()+2, Qt::AlignRight|Qt::AlignTop, QString::number( i ) ); if ( right ) p->drawLine( w-6, h, w, h ); } } else { //if ( _dir == Arts::LeftToRight || _dir == Arts::RightToLeft ) { // Calculating stepsizes for ( int i=1; _minstepcount*( fontrect.width()+4 ) > contentsRect().width(); i++ ) { _minstepcount = ( dbmax-dbmin ) / minstep / i; _minstep = minstep*i; } while ( _substepcount*2 > contentsRect().width() ) { _substepcount/=2; _substep*=2; } // Calculating minimum size of the widget _minsize=fontrect.height()+4; if ( left ) _minsize+=6; if ( right ) _minsize+=6; setMinimumHeight( _minsize + frameWidth() + 2 ); // setMaximumHeight( _minsize /*+6*/ ); w = 0; // Just a shortcut h = frameWidth() + contentsRect().height(); // Painting substep marks p->setPen( QPen( colordiff, 1 ) ); for ( float i=dbmax; i>=dbmin; i-=_substep ) { w = this->frameWidth()+ int( contentsRect().width() * dbtondb( i ) ); if ( _dir==Arts::RightToLeft ) w = 1 - w; if ( left ) p->drawLine( w, frameWidth(), w, frameWidth() + 3 ); if ( right ) p->drawLine( w, h-3, w, h ); } // Painting step marks and texts p->setPen( QPen( colornormal, 1 ) ); for ( float i=0; i>=dbmin; i-=_minstep ) { w = int( contentsRect().width() * dbtondb( i ) ); if ( _dir==Arts::RightToLeft ) w = 1 - w; if ( left ) p->drawLine( w, 0, w, 6 ); p->drawText( w - fontrect.width()/2 , ( h - (left)*6 - (right)*6 - fontrect.height() )/2 + (left)*6, fontrect.width(), fontrect.height()+2, Qt::AlignRight|Qt::AlignTop, QString::number( i ) ); if ( right ) p->drawLine( w, h-6, w, h ); } for ( float i=_minstep; i<=dbmax; i+=_minstep ) { h = int( -contentsRect().height() * dbtondb( i ) ); if ( _dir==Arts::RightToLeft ) w = 1 - w; if ( left ) p->drawLine( w, 0, w, 6 ); p->drawText( w - fontrect.width()/2 , ( h - (left)*6 - (right)*6 - fontrect.height() )/2 + (left)*6, fontrect.width(), fontrect.height()+2, Qt::AlignRight|Qt::AlignTop, QString::number( i ) ); if ( right ) p->drawLine( w, h-6, w, h ); } } }
QRectF rect( 0,0, QFontMetrics( small ).width( _valuestring ), QFontMetrics( small ).height() ); if ( dbtondb( a ) < 0.5 ) rect.translate( -QFontMetrics( small ).width( _valuestring ), 0 ); p.drawText( rect, Qt::AlignCenter, QString( _valuestring ).arg( a ) ); if ( a == 0.0 ) _nullclick = p.matrix().mapRect( rect ).toRect(); p.restore(); } p.restore(); // Draw highlight-line for the value p.save(); p.rotate( 300 * dbtondb( _value ) ); QPen linepen( palette().color( QPalette::HighlightedText ) ); linepen.setWidthF( 3 ); linepen.setCapStyle( Qt::RoundCap ); p.setPen( linepen ); p.drawLine( QPointF( 0,0 ), QPointF( radius*0.71,0 ) ); p.restore(); p.restore(); if ( _show_value ) { QString tmp = QString::number( _value ); if ( tmp.contains( "." ) ) tmp = _valuestring.arg( tmp.left( tmp.indexOf( "." ) + _precision + 1 ) ); else