668 } |
676 } |
669 |
677 |
670 /*! |
678 /*! |
671 * |
679 * |
672 */ |
680 */ |
673 QPixmap RadioFrequencyStripBase::drawPixmap( uint frequency, QList<FrequencyStrip::StationMarker> stations, RadioFrequencyItem* item ) |
681 QPixmap RadioFrequencyStripBase::drawPixmap( uint mainFrequency, QList<FrequencyStrip::StationMarker> stations, RadioFrequencyItem* item ) |
674 { |
682 { |
675 QPixmap pixmap( FrequencyStrip::PIXMAP_WIDTH, mItemHeight ); |
683 QPixmap pixmap( FrequencyStrip::PIXMAP_WIDTH, mItemHeight ); |
676 pixmap.fill( Qt::transparent ); |
684 pixmap.fill( Qt::transparent ); |
|
685 |
|
686 if ( mainFrequency == 0 ) { |
|
687 return pixmap; |
|
688 } |
|
689 |
677 QPainter painter( &pixmap ); |
690 QPainter painter( &pixmap ); |
678 QPen normalPen = painter.pen(); |
691 QPen normalPen = painter.pen(); |
679 QPen favoritePen = normalPen; |
692 QPen favoritePen = normalPen; |
680 normalPen.setColor( mForegroundColor ); |
693 normalPen.setColor( mForegroundColor ); |
681 painter.setPen( normalPen ); |
694 painter.setPen( normalPen ); |
682 |
695 |
683 if ( frequency == 0 ) { |
696 const uint frequencyIncrement = qMin( mFrequencyStepSize, FrequencyStrip::ONE_HUNDRED_KHZ ); |
684 painter.drawLine( makeTab( mSeparatorPos - 1 + FrequencyStrip::ROUNDER, mItemHeight ) ); |
697 const QString itemText = QString::number( mainFrequency / FrequencyStrip::ONE_HERTZ ); |
685 painter.drawLine( makeTab( mSeparatorPos + FrequencyStrip::ROUNDER, mItemHeight ) ); |
698 const uint startFrequency = mainFrequency - FrequencyStrip::HALF_HERTZ + frequencyIncrement; |
686 return pixmap; |
699 const uint endFrequency = mainFrequency + FrequencyStrip::HALF_HERTZ; |
687 } |
|
688 |
|
689 const QString itemText = QString::number( frequency / FrequencyStrip::ONE_HERTZ ); |
|
690 const uint startFrequency = frequency - FrequencyStrip::HALF_HERTZ; |
|
691 const uint endFrequency = startFrequency + FrequencyStrip::ONE_HERTZ; |
|
692 const uint roundedMin = int( qreal(mMinFrequency) / FrequencyStrip::ONE_HERTZ + FrequencyStrip::ROUNDER ); |
700 const uint roundedMin = int( qreal(mMinFrequency) / FrequencyStrip::ONE_HERTZ + FrequencyStrip::ROUNDER ); |
693 const uint freq = frequency / FrequencyStrip::ONE_HERTZ; |
701 const uint freq = mainFrequency / FrequencyStrip::ONE_HERTZ; |
694 const int diff = freq - roundedMin; |
702 const int diff = freq - roundedMin; |
695 const qreal startPixel = diff * FrequencyStrip::ITEM_WIDTH; |
703 const qreal startPixel = diff * FrequencyStrip::ITEM_WIDTH; |
696 qreal pixels = 0.0; |
704 qreal pixels = 0.0; |
697 const qreal leftOverlap = FrequencyStrip::PIXMAP_OVERLAP / 2; |
705 const qreal leftOverlap = FrequencyStrip::PIXMAP_OVERLAP / 2; |
698 |
706 |
699 for ( uint frequency = startFrequency; frequency <= endFrequency; frequency += mFrequencyStepSize ) { |
707 for ( uint loopFrequency = startFrequency; loopFrequency <= endFrequency; loopFrequency += frequencyIncrement ) { |
700 |
708 |
701 if ( frequency < mMinFrequency || frequency > mMaxFrequency ) { |
709 pixels = qreal( loopFrequency - startFrequency ) / FrequencyStrip::PIXEL_IN_HZ; |
702 continue; |
710 if ( loopFrequency % FrequencyStrip::ONE_HERTZ == 0 ) { |
703 } |
|
704 |
|
705 pixels = qreal( frequency - startFrequency ) / FrequencyStrip::PIXEL_IN_HZ; |
|
706 if ( frequency % FrequencyStrip::ONE_HERTZ == 0 ) { |
|
707 |
711 |
708 // Draw the high frequency tab and the frequency text for the even number |
712 // Draw the high frequency tab and the frequency text for the even number |
709 normalPen.setWidth( 3 ); |
713 normalPen.setWidth( 3 ); |
710 painter.setPen( normalPen ); |
714 painter.setPen( normalPen ); |
711 painter.drawLine( makeTab( pixels + leftOverlap - 1, FrequencyStrip::TAB_HEIGHT_BIG ) ); |
715 painter.drawLine( makeTab( pixels + leftOverlap - 1, FrequencyStrip::TAB_HEIGHT_BIG ) ); |
712 normalPen.setWidth( 1 ); |
716 normalPen.setWidth( 1 ); |
713 painter.setPen( normalPen ); |
717 painter.setPen( normalPen ); |
714 |
718 |
715 // Draw the frequency text and its 00 decimals |
719 // Draw the frequency text and its decimals |
716 painter.setFont( FrequencyStrip::DECIMAL_FONT ); |
720 painter.setFont( FrequencyStrip::DECIMAL_FONT ); |
717 const int decimalWidth = painter.fontMetrics().width( FrequencyStrip::DECIMAL_TEXT ); |
721 const int decimalWidth = painter.fontMetrics().width( FrequencyStrip::DECIMAL_TEXT ); |
718 const int decimalSpace = painter.fontMetrics().leftBearing( '.' ); |
722 const int decimalSpace = painter.fontMetrics().leftBearing( '.' ); |
719 painter.setFont( FrequencyStrip::FREQUENCY_FONT ); |
723 painter.setFont( FrequencyStrip::FREQUENCY_FONT ); |
720 const int frequencyWidth = painter.fontMetrics().width( itemText ); |
724 const int frequencyWidth = painter.fontMetrics().width( itemText ); |
721 const int textPosX = int( pixels + leftOverlap - ( frequencyWidth + decimalSpace + decimalWidth ) / 2 ); |
725 const int textPosX = int( pixels + leftOverlap - ( frequencyWidth + decimalSpace + decimalWidth ) / 2 ); |
722 painter.drawText( QPoint( textPosX, FrequencyStrip::FREQUENCY_TEXT_Y_POS ), itemText ); |
726 painter.drawText( QPoint( textPosX, FrequencyStrip::FREQUENCY_TEXT_Y_POS ), itemText ); |
723 painter.setFont( FrequencyStrip::DECIMAL_FONT ); |
727 painter.setFont( FrequencyStrip::DECIMAL_FONT ); |
724 painter.drawText( QPoint( textPosX + frequencyWidth + decimalSpace, FrequencyStrip::FREQUENCY_TEXT_Y_POS ), FrequencyStrip::DECIMAL_TEXT ); |
728 painter.drawText( QPoint( textPosX + frequencyWidth + decimalSpace, FrequencyStrip::FREQUENCY_TEXT_Y_POS ), FrequencyStrip::DECIMAL_TEXT ); |
725 |
729 |
726 } else if ( frequency % FrequencyStrip::ONE_TAB_IN_HZ == 0 ) { |
730 } else if ( loopFrequency % FrequencyStrip::ONE_TAB_IN_HZ == 0 ) { |
727 |
731 |
728 // Draw the low frequency tab for the uneven number |
732 // Draw the low frequency tab for the uneven number |
729 painter.drawLine( makeTab( pixels + leftOverlap, FrequencyStrip::TAB_HEIGHT_SMALL ) ); |
733 painter.drawLine( makeTab( pixels + leftOverlap, FrequencyStrip::TAB_HEIGHT_SMALL ) ); |
730 |
734 |
731 } |
735 } |
732 |
736 |
733 addFrequencyPos( int( startPixel + pixels + FrequencyStrip::ROUNDER ), frequency, item ); |
737 if ( ( loopFrequency - mMinFrequency ) % mFrequencyStepSize == 0 && loopFrequency >= mMinFrequency && loopFrequency <= mMaxFrequency ) { |
|
738 addFrequencyPos( int( startPixel + pixels + FrequencyStrip::ROUNDER ), loopFrequency, item ); |
|
739 } |
734 } |
740 } |
735 |
741 |
736 // Draw favorites and local stations |
742 // Draw favorites and local stations |
737 favoritePen.setColor( Qt::yellow ); |
743 favoritePen.setColor( Qt::yellow ); |
738 |
744 |
|
745 const int markerYPos = mItemHeight - 18; |
739 foreach ( const FrequencyStrip::StationMarker& station, stations ) { |
746 foreach ( const FrequencyStrip::StationMarker& station, stations ) { |
740 const uint frequency = station.mFrequency; |
747 const uint frequency = station.mFrequency; |
741 pixels = qreal( frequency - startFrequency ) / FrequencyStrip::PIXEL_IN_HZ; |
748 pixels = qreal( frequency - startFrequency ) / FrequencyStrip::PIXEL_IN_HZ; |
742 |
749 |
743 if ( station.mIsFavorite ) { |
750 if ( station.mIsFavorite ) { |
744 favoritePen.setWidth( FrequencyStrip::PEN_WIDTH_FAVORITE ); |
751 favoritePen.setWidth( FrequencyStrip::PEN_WIDTH_FAVORITE ); |
745 painter.setPen( favoritePen ); |
752 painter.setPen( favoritePen ); |
746 painter.drawEllipse( int( pixels + leftOverlap - 3 ), FrequencyStrip::STATION_MARKER_Y_POS - 3, 6, 6 ); |
753 painter.drawEllipse( int( pixels + leftOverlap - 3 ), markerYPos - 3, 6, 6 ); |
|
754 // painter.drawEllipse( int( pixels + leftOverlap - 3 ), FrequencyStrip::STATION_MARKER_Y_POS - 3, 6, 6 ); |
747 } else { |
755 } else { |
748 favoritePen.setWidth( 1 ); |
756 favoritePen.setWidth( 1 ); |
749 painter.setPen( favoritePen ); |
757 painter.setPen( favoritePen ); |
750 painter.drawEllipse( int( pixels + leftOverlap - 4 ), FrequencyStrip::STATION_MARKER_Y_POS - 4, 8, 8 ); |
758 painter.drawEllipse( int( pixels + leftOverlap - 4 ), markerYPos - 4, 8, 8 ); |
|
759 // painter.drawEllipse( int( pixels + leftOverlap - 4 ), FrequencyStrip::STATION_MARKER_Y_POS - 4, 8, 8 ); |
751 } |
760 } |
752 } |
761 } |
753 |
762 |
754 return pixmap; |
763 return pixmap; |
755 } |
764 } |