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

Method paintEvent

src/tracks/SampleTrack.cpp:478–573  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

476
477
478void SampleTCOView::paintEvent( QPaintEvent * pe )
479{
480 QPainter painter( this );
481
482 if( !needsUpdate() )
483 {
484 painter.drawPixmap( 0, 0, m_paintPixmap );
485 return;
486 }
487
488 setNeedsUpdate( false );
489
490 m_paintPixmap = m_paintPixmap.isNull() == true || m_paintPixmap.size() != size()
491 ? QPixmap( size() ) : m_paintPixmap;
492
493 QPainter p( &m_paintPixmap );
494
495 QLinearGradient lingrad( 0, 0, 0, height() );
496 QColor c;
497 bool muted = m_tco->getTrack()->isMuted() || m_tco->isMuted();
498
499 // state: selected, muted, normal
500 c = isSelected() ? selectedColor() : ( muted ? mutedBackgroundColor()
501 : painter.background().color() );
502
503 lingrad.setColorAt( 1, c.darker( 300 ) );
504 lingrad.setColorAt( 0, c );
505
506 // paint a black rectangle under the pattern to prevent glitches with transparent backgrounds
507 p.fillRect( rect(), QColor( 0, 0, 0 ) );
508
509 if( gradient() )
510 {
511 p.fillRect( rect(), lingrad );
512 }
513 else
514 {
515 p.fillRect( rect(), c );
516 }
517
518 p.setPen( !muted ? painter.pen().brush().color() : mutedColor() );
519
520 const int spacing = TCO_BORDER_WIDTH + 1;
521 const float ppt = fixedTCOs() ?
522 ( parentWidget()->width() - 2 * TCO_BORDER_WIDTH )
523 / (float) m_tco->length().getTact() :
524 pixelsPerTact();
525
526 float nom = Engine::getSong()->getTimeSigModel().getNumerator();
527 float den = Engine::getSong()->getTimeSigModel().getDenominator();
528 float ticksPerTact = DefaultTicksPerTact * nom / den;
529
530 QRect r = QRect( TCO_BORDER_WIDTH, spacing,
531 qMax( static_cast<int>( m_tco->sampleLength() * ppt / ticksPerTact ), 1 ), rect().bottom() - 2 * spacing );
532 m_tco->m_sampleBuffer->visualize( p, r, pe->rect() );
533
534 // disable antialiasing for borders, since its not needed
535 p.setRenderHint( QPainter::Antialiasing, false );

Callers

nothing calls this directly

Calls 15

sizeFunction · 0.85
fixedTCOsFunction · 0.85
getSongFunction · 0.85
QRectClass · 0.85
getIconPixmapFunction · 0.85
isNullMethod · 0.80
getTactMethod · 0.80
sampleLengthMethod · 0.80
visualizeMethod · 0.80
rightMethod · 0.80
QPixmapClass · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected