MCPcopy Create free account
hub / github.com/LMMS/lmms / paintEvent

Method paintEvent

src/gui/PianoView.cpp:776–894  ·  view source on GitHub ↗

! \brief Paint the piano display view in response to an event * * This method draws the piano and the 'root note' base. It draws * the base first, then all the white keys, then all the black keys. * * \todo Is there supposed to be a parameter given here? */

Source from the content-addressed store, hash-verified

774 * \todo Is there supposed to be a parameter given here?
775 */
776void PianoView::paintEvent( QPaintEvent * )
777{
778 QPainter p( this );
779
780 // set smaller font for printing number of every octave
781 p.setFont( pointSize<LABEL_TEXT_SIZE>( p.font() ) );
782
783
784 // draw bar above the keyboard (there will be the labels
785 // for all C's)
786 p.fillRect( QRect( 0, 1, width(), PIANO_BASE-2 ), p.background() );
787
788 // draw the line above the keyboard
789 p.setPen( Qt::black );
790 p.drawLine( 0, 0, width(), 0 );
791 p.drawLine( 0, PIANO_BASE-1, width(), PIANO_BASE-1 );
792
793 p.setPen( Qt::white );
794
795 const int base_key = ( m_piano != NULL ) ?
796 m_piano->instrumentTrack()->baseNoteModel()->value() : 0;
797
798 QColor baseKeyColor = QApplication::palette().color( QPalette::Active,
799 QPalette::BrightText );
800 if( Piano::isWhiteKey( base_key ) )
801 {
802 p.fillRect( QRect( getKeyX( base_key ), 1, PW_WHITE_KEY_WIDTH-1,
803 PIANO_BASE-2 ), baseKeyColor );
804 }
805 else
806 {
807 p.fillRect( QRect( getKeyX( base_key ) + 1, 1,
808 PW_BLACK_KEY_WIDTH - 1, PIANO_BASE - 2 ), baseKeyColor);
809 }
810
811
812 int cur_key = m_startKey;
813
814 // draw all white keys...
815 for( int x = 0; x < width(); )
816 {
817 while( Piano::isBlackKey( cur_key ) )
818 {
819 ++cur_key;
820 }
821
822 // draw pressed or not pressed key, depending on state of
823 // current key
824 if( m_piano && m_piano->isKeyPressed( cur_key ) )
825 {
826 p.drawPixmap( x, PIANO_BASE, *s_whiteKeyPressedPm );
827 }
828 else
829 {
830 p.drawPixmap( x, PIANO_BASE, *s_whiteKeyPm );
831 }
832
833 x += PW_WHITE_KEY_WIDTH;

Callers

nothing calls this directly

Calls 7

QRectClass · 0.85
drawLineMethod · 0.80
instrumentTrackMethod · 0.80
isKeyPressedMethod · 0.80
QStringClass · 0.50
valueMethod · 0.45
colorMethod · 0.45

Tested by

no test coverage detected