TrackContentWidget: fixed background tile pixmap updating

The background tile pixmap used to draw the background of
TrackContentWidgets was only updated on size changes but not on
changes of zoom level in according editor. Fix this by updating
background pixmaps in trackContainerView::setPixelsPerTact().
This commit is contained in:
Tobias Doerffel
2009-12-07 01:38:17 +01:00
parent f82a25c3a2
commit d7ae99a5e8
3 changed files with 71 additions and 50 deletions

View File

@@ -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 )

View File

@@ -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<int>( 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<int>( 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 );
}

View File

@@ -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();
}
}