void timeLine::paintEvent( QPaintEvent * ) { QPainter p( this ); QColor bg_color = QApplication::palette().color( QPalette::Active, QPalette::Background ); QLinearGradient g( 0, 0, 0, height() ); g.setColorAt( 0, bg_color.lighter( 150 ) ); g.setColorAt( 1, bg_color.darker( 150 ) ); p.fillRect( 0, 0, width(), height(), g ); p.setClipRect( m_xOffset, 0, width() - m_xOffset, height() ); p.setPen( QColor( 0, 0, 0 ) ); p.setOpacity( loopPointsEnabled() ? 0.9 : 0.2 ); p.drawPixmap( markerX( loopBegin() )+2, 2, *s_loopPointPixmap ); p.drawPixmap( markerX( loopEnd() )+2, 2, *s_loopPointPixmap ); p.setOpacity( 1.0 ); tact_t tact_num = m_begin.getTact(); int x = m_xOffset + s_posMarkerPixmap->width() / 2 - ( ( static_cast<Sint32>( m_begin * m_ppt ) / midiTime::ticksPerTact() ) % static_cast<int>( m_ppt ) ); QColor adas = engine::getLmmsStyle()->color( LmmsStyle::TimelineForecolor ); p.setPen( adas ); for( int i = 0; x + i * m_ppt < width(); ++i ) { const int cx = x + qRound( i * m_ppt ); p.drawLine( cx, 5, cx, height() - 6 ); ++tact_num; if( ( tact_num - 1 ) % qMax( 1, qRound( 1.0f / 3.0f * midiTime::ticksPerTact() / m_ppt ) ) == 0 ) { const QString s = QString::number( tact_num ); p.drawText( cx + qRound( ( m_ppt - p.fontMetrics(). width( s ) ) / 2 ), height() - p.fontMetrics().height() / 2, s ); } } p.setOpacity( 0.6 ); p.drawPixmap( m_posMarkerX, height() - s_posMarkerPixmap->height(), *s_posMarkerPixmap ); }
void TimeLineWidget::updatePosition( const MidiTime & ) { const int new_x = markerX( m_pos ); if( new_x != m_posMarkerX ) { m_posMarkerX = new_x; m_changedPosition = true; emit positionChanged( m_pos ); update(); } }
void TimeLineWidget::paintEvent( QPaintEvent * ) { QPainter p( this ); // Draw background p.fillRect( 0, 0, width(), height(), p.background() ); // Clip so that we only draw everything starting from the offset p.setClipRect( m_xOffset, 0, width() - m_xOffset, height() ); // Draw the loop rectangle int const & loopRectMargin = getLoopRectangleVerticalPadding(); int const loopRectHeight = this->height() - 2 * loopRectMargin; int const loopStart = markerX( loopBegin() ) + 8; int const loopEndR = markerX( loopEnd() ) + 9; int const loopRectWidth = loopEndR - loopStart; bool const loopPointsActive = loopPointsEnabled(); // Draw the main rectangle (inner fill only) QRect outerRectangle( loopStart, loopRectMargin, loopRectWidth - 1, loopRectHeight - 1 ); p.fillRect( outerRectangle, loopPointsActive ? getActiveLoopBrush() : getInactiveLoopBrush()); // Draw the bar lines and numbers // Activate hinting on the font QFont font = p.font(); font.setHintingPreference( QFont::PreferFullHinting ); p.setFont(font); int const fontAscent = p.fontMetrics().ascent(); int const fontHeight = p.fontMetrics().height(); QColor const & barLineColor = getBarLineColor(); QColor const & barNumberColor = getBarNumberColor(); tact_t barNumber = m_begin.getTact(); int const x = m_xOffset + s_posMarkerPixmap->width() / 2 - ( ( static_cast<int>( m_begin * m_ppt ) / MidiTime::ticksPerTact() ) % static_cast<int>( m_ppt ) ); for( int i = 0; x + i * m_ppt < width(); ++i ) { ++barNumber; if( ( barNumber - 1 ) % qMax( 1, qRound( 1.0f / 3.0f * MidiTime::ticksPerTact() / m_ppt ) ) == 0 ) { const int cx = x + qRound( i * m_ppt ); p.setPen( barLineColor ); p.drawLine( cx, 5, cx, height() - 6 ); const QString s = QString::number( barNumber ); p.setPen( barNumberColor ); p.drawText( cx + 5, ((height() - fontHeight) / 2) + fontAscent, s ); } } // Draw the main rectangle (outer border) p.setPen( loopPointsActive ? getActiveLoopColor() : getInactiveLoopColor() ); p.setBrush( Qt::NoBrush ); p.drawRect( outerRectangle ); // Draw the inner border outline (no fill) QRect innerRectangle = outerRectangle.adjusted( 1, 1, -1, -1 ); p.setPen( loopPointsActive ? getActiveLoopInnerColor() : getInactiveLoopInnerColor() ); p.setBrush( Qt::NoBrush ); p.drawRect( innerRectangle ); // Draw the position marker p.setOpacity( 0.6 ); p.drawPixmap( m_posMarkerX, height() - s_posMarkerPixmap->height(), *s_posMarkerPixmap ); }