diff --git a/include/track.h b/include/track.h index 074a6dbb9..e53c425e7 100644 --- a/include/track.h +++ b/include/track.h @@ -232,6 +232,9 @@ public: trackContentWidget( trackView * _parent ); virtual ~trackContentWidget(); + /*! \brief Updates the background tile pixmap. */ + void updateBackground(); + void addTCOView( trackContentObjectView * _tcov ); void removeTCOView( trackContentObjectView * _tcov ); void removeTCOView( int _tco_num ) diff --git a/src/core/track.cpp b/src/core/track.cpp index c4cb7a2b3..95b0a2e4e 100644 --- a/src/core/track.cpp +++ b/src/core/track.cpp @@ -873,6 +873,8 @@ trackContentWidget::trackContentWidget( trackView * _parent ) : connect( _parent->getTrackContainerView(), SIGNAL( positionChanged( const midiTime & ) ), this, SLOT( changePosition( const midiTime & ) ) ); + + updateBackground(); } @@ -889,6 +891,60 @@ trackContentWidget::~trackContentWidget() +void trackContentWidget::updateBackground() +{ + const int tactsPerBar = 4; + const trackContainerView * tcv = m_trackView->getTrackContainerView(); + + // Assume even-pixels-per-tact. Makes sense, should be like this anyways + int ppt = static_cast( tcv->pixelsPerTact() ); + + int w = ppt * tactsPerBar; + int h = height(); + m_background = QPixmap( w * 2, height() ); + QPainter pmp( &m_background ); + + QLinearGradient grad( 0, 1, 0, h-2 ); + pmp.fillRect( 0, 0, 1, h, QColor( 96, 96, 96 ) ); + pmp.fillRect( 1, 0, w+1, h, QColor( 128, 128, 128 ) ); + grad.setColorAt( 0.0, QColor( 64, 64, 64 ) ); + grad.setColorAt( 0.3, QColor( 128, 128, 128 ) ); + grad.setColorAt( 0.5, QColor( 128, 128, 128 ) ); + grad.setColorAt( 0.95, QColor( 160, 160, 160 ) ); + pmp.fillRect( 0, 1, w, h-2, grad ); + + QLinearGradient grad2( 0,1, 0, h-2 ); + pmp.fillRect( w+1, 0, w , h, QColor( 96, 96, 96 ) ); + grad2.setColorAt( 0.0, QColor( 48, 48, 48 ) ); + grad2.setColorAt( 0.3, QColor( 96, 96, 96 ) ); + grad2.setColorAt( 0.5, QColor( 96, 96, 96 ) ); + grad2.setColorAt( 0.95, QColor( 120, 120, 120 ) ); + pmp.fillRect( w, 1, w , h-2, grad2 ); + + // draw vertical lines + pmp.setPen( QPen( QColor( 0, 0, 0, 112 ), 1 ) ); + for( float x = 0.5; x < w * 2; x += ppt ) + { + pmp.drawLine( QLineF( x, 1.0, x, h-2.0 ) ); + } + pmp.drawLine( 0, 1, w*2, 1 ); + + pmp.setPen( QPen( QColor( 255, 255, 255, 32 ), 1 ) ); + for( float x = 1.5; x < w * 2; x += ppt ) + { + pmp.drawLine( QLineF( x, 1.0, x, h-2.0 ) ); + } + pmp.drawLine( 0, h-2, w*2, h-2 ); + + pmp.end(); + + // Force redraw + update(); +} + + + + /*! \brief Adds a trackContentObjectView to this widget. * * Adds a(nother) trackContentObjectView to our list of views. We also @@ -1148,59 +1204,14 @@ void trackContentWidget::paintEvent( QPaintEvent * _pe ) -/*! \brief Resize the trackContentWidget +/*! \brief Updates the background tile pixmap on size changes. * - * \param _re the resize event to respond to + * \param resizeEvent the resize event to pass to base class */ -void trackContentWidget::resizeEvent( QResizeEvent * _re ) +void trackContentWidget::resizeEvent( QResizeEvent * resizeEvent ) { - const int tactsPerBar = 4; - const trackContainerView * tcv = m_trackView->getTrackContainerView(); - - // Assume even-pixels-per-tact. Makes sense, should be like this anyways - int ppt = static_cast( tcv->pixelsPerTact() ); - - int w = ppt * tactsPerBar; - int h = height(); - m_background = QPixmap( w * 2, height() ); - QPainter pmp( &m_background ); - - QLinearGradient grad( 0, 1, 0, h-2 ); - pmp.fillRect( 0, 0, 1, h, QColor( 96, 96, 96 ) ); - pmp.fillRect( 1, 0, w+1, h, QColor( 128, 128, 128 ) ); - grad.setColorAt( 0.0, QColor( 64, 64, 64 ) ); - grad.setColorAt( 0.3, QColor( 128, 128, 128 ) ); - grad.setColorAt( 0.5, QColor( 128, 128, 128 ) ); - grad.setColorAt( 0.95, QColor( 160, 160, 160 ) ); - pmp.fillRect( 0, 1, w, h-2, grad ); - - QLinearGradient grad2( 0,1, 0, h-2 ); - pmp.fillRect( w+1, 0, w , h, QColor( 96, 96, 96 ) ); - grad2.setColorAt( 0.0, QColor( 48, 48, 48 ) ); - grad2.setColorAt( 0.3, QColor( 96, 96, 96 ) ); - grad2.setColorAt( 0.5, QColor( 96, 96, 96 ) ); - grad2.setColorAt( 0.95, QColor( 120, 120, 120 ) ); - pmp.fillRect( w, 1, w , h-2, grad2 ); - - // draw vertical lines - pmp.setPen( QPen( QColor( 0, 0, 0, 112 ), 1 ) ); - for( float x = 0.5; x < w * 2; x += ppt ) - { - pmp.drawLine( QLineF( x, 1.0, x, h-2.0 ) ); - } - pmp.drawLine( 0, 1, w*2, 1 ); - - pmp.setPen( QPen( QColor( 255, 255, 255, 32 ), 1 ) ); - for( float x = 1.5; x < w * 2; x += ppt ) - { - pmp.drawLine( QLineF( x, 1.0, x, h-2.0 ) ); - } - pmp.drawLine( 0, h-2, w*2, h-2 ); - - pmp.end(); - - // Force redraw - update(); + updateBackground(); + QWidget::resizeEvent( resizeEvent ); } diff --git a/src/gui/track_container_view.cpp b/src/gui/track_container_view.cpp index e240f8b16..47e679f67 100644 --- a/src/gui/track_container_view.cpp +++ b/src/gui/track_container_view.cpp @@ -281,6 +281,13 @@ bool trackContainerView::allowRubberband() const void trackContainerView::setPixelsPerTact( int _ppt ) { m_ppt = _ppt; + + // tell all TrackContentWidgets to update their background tile pixmap + for( trackViewList::Iterator it = m_trackViews.begin(); + it != m_trackViews.end(); ++it ) + { + ( *it )->getTrackContentWidget()->updateBackground(); + } }