diff --git a/data/themes/default/style.css b/data/themes/default/style.css index adc1547c19f..5104346526a 100644 --- a/data/themes/default/style.css +++ b/data/themes/default/style.css @@ -115,7 +115,7 @@ PianoRoll { qproperty-noteColor: rgb( 119, 199, 216 ); qproperty-noteBorderRadiusX: 5; qproperty-noteBorderRadiusY: 2; - qproperty-selectedNoteColor: rgb( 0, 64, 192 ); + qproperty-selectedNoteColor: rgb( 0, 125, 255 ); qproperty-barColor: #4afd85; qproperty-markedSemitoneColor: rgba( 40, 40, 40, 200 ); /* Text on the white piano keys */ @@ -537,31 +537,37 @@ TrackContainerView QLabel /* Patterns */ +/* common pattern colors */ +TrackContentObjectView { + qproperty-mutedColor: rgb( 128, 128, 128 ); + qproperty-mutedBackgroundColor: rgb( 80, 80, 80 ); + qproperty-selectedColor: rgb( 0, 125, 255 ); + qproperty-textColor: rgb( 255, 255, 255 ); + qproperty-textShadowColor: rgb( 0, 0, 0 ); + qproperty-gradient: false; +} + /* instrument pattern */ PatternView { - color: rgb( 119, 199, 216 ); - qproperty-fgColor: rgb( 187, 227, 236 ); - qproperty-textColor: rgb( 255, 255, 255 ); + background-color: rgb( 119, 199, 216 ); + color: rgb( 187, 227, 236 ); } /* sample track pattern */ SampleTCOView { - color: rgb( 74, 253, 133 ); - qproperty-fgColor: rgb( 187, 227, 236 ); - qproperty-textColor: rgb( 255, 60, 60 ); + background-color: rgb( 74, 253, 133 ); + color: rgb( 187, 227, 236 ); } /* automation pattern */ AutomationPatternView { - color: #99afff; - qproperty-fgColor: rgb( 204, 215, 255 ); - qproperty-textColor: rgb( 255, 255, 255 ); + background-color: #99afff; + color: rgb( 204, 215, 255 ); } /* bb-pattern */ BBTCOView { - color: rgb( 128, 182, 175 ); /* default colour for bb-tracks, used when the colour hasn't been defined by the user */ - qproperty-textColor: rgb( 255, 255, 255 ); + background-color: rgb( 128, 182, 175 ); /* default colour for bb-tracks */ } /* Plugins */ diff --git a/include/AutomationPatternView.h b/include/AutomationPatternView.h index 714eaed5350..b06b35895f0 100644 --- a/include/AutomationPatternView.h +++ b/include/AutomationPatternView.h @@ -25,6 +25,8 @@ #ifndef AUTOMATION_PATTERN_VIEW_H #define AUTOMATION_PATTERN_VIEW_H +#include + #include "Track.h" class AutomationPattern; @@ -34,9 +36,6 @@ class AutomationPatternView : public TrackContentObjectView { Q_OBJECT -// theming qproperties - Q_PROPERTY( QColor fgColor READ fgColor WRITE setFgColor ) - Q_PROPERTY( QColor textColor READ textColor WRITE setTextColor ) public: AutomationPatternView( AutomationPattern * _pat, TrackView * _parent ); @@ -74,6 +73,8 @@ protected slots: QPixmap m_paintPixmap; bool m_needsUpdate; + QStaticText m_staticTextName; + static QPixmap * s_pat_rec; void scaleTimemapToFit( float oldMin, float oldMax ); diff --git a/include/BBTrack.h b/include/BBTrack.h index b822c8e2be6..93c4c86f5df 100644 --- a/include/BBTrack.h +++ b/include/BBTrack.h @@ -29,6 +29,7 @@ #include #include +#include #include "Track.h" @@ -97,6 +98,8 @@ class BBTCOView : public TrackContentObjectView } void setColor( QColor _new_color ); +public slots: + virtual void update(); protected slots: void openInBBEditor(); @@ -108,13 +111,21 @@ protected slots: protected: void paintEvent( QPaintEvent * ); + void resizeEvent( QResizeEvent * re ) + { + m_needsUpdate = true; + TrackContentObjectView::resizeEvent( re ); + } void mouseDoubleClickEvent( QMouseEvent * _me ); virtual void constructContextMenu( QMenu * ); private: BBTCO * m_bbTCO; - + QPixmap m_paintPixmap; + bool m_needsUpdate; + + QStaticText m_staticTextName; } ; diff --git a/include/Pattern.h b/include/Pattern.h index ce6702fbb3c..f89506fd063 100644 --- a/include/Pattern.h +++ b/include/Pattern.h @@ -31,6 +31,7 @@ #include #include #include +#include #include "Note.h" @@ -159,9 +160,6 @@ class PatternView : public TrackContentObjectView { Q_OBJECT -// theming qproperties - Q_PROPERTY( QColor fgColor READ fgColor WRITE setFgColor ) - Q_PROPERTY( QColor textColor READ textColor WRITE setTextColor ) public: PatternView( Pattern* pattern, TrackView* parent ); virtual ~PatternView(); @@ -200,6 +198,8 @@ protected slots: Pattern* m_pat; QPixmap m_paintPixmap; bool m_needsUpdate; + + QStaticText m_staticTextName; } ; diff --git a/include/SampleTrack.h b/include/SampleTrack.h index c8b17b1481e..120f5f9b431 100644 --- a/include/SampleTrack.h +++ b/include/SampleTrack.h @@ -88,10 +88,6 @@ public slots: class SampleTCOView : public TrackContentObjectView { Q_OBJECT - -// theming qproperties - Q_PROPERTY( QColor fgColor READ fgColor WRITE setFgColor ) - Q_PROPERTY( QColor textColor READ textColor WRITE setTextColor ) public: SampleTCOView( SampleTCO * _tco, TrackView * _tv ); @@ -100,6 +96,8 @@ class SampleTCOView : public TrackContentObjectView public slots: void updateSample(); + virtual void update(); + protected: @@ -109,10 +107,17 @@ public slots: virtual void dropEvent( QDropEvent * _de ); virtual void mouseDoubleClickEvent( QMouseEvent * ); virtual void paintEvent( QPaintEvent * ); + virtual void resizeEvent( QResizeEvent * re ) + { + m_needsUpdate = true; + TrackContentObjectView::resizeEvent( re ); + } private: SampleTCO * m_tco; + QPixmap m_paintPixmap; + bool m_needsUpdate; } ; diff --git a/include/Track.h b/include/Track.h index 4afc670764e..8977ebe0a48 100644 --- a/include/Track.h +++ b/include/Track.h @@ -191,8 +191,12 @@ class TrackContentObjectView : public selectableObject, public ModelView Q_OBJECT // theming qproperties - Q_PROPERTY( QColor fgColor READ fgColor WRITE setFgColor ) + Q_PROPERTY( QColor mutedColor READ mutedColor WRITE setMutedColor ) + Q_PROPERTY( QColor mutedBackgroundColor READ mutedBackgroundColor WRITE setMutedBackgroundColor ) + Q_PROPERTY( QColor selectedColor READ selectedColor WRITE setSelectedColor ) Q_PROPERTY( QColor textColor READ textColor WRITE setTextColor ) + Q_PROPERTY( QColor textShadowColor READ textShadowColor WRITE setTextShadowColor ) + Q_PROPERTY( bool gradient READ gradient WRITE setGradient ) public: TrackContentObjectView( TrackContentObject * tco, TrackView * tv ); @@ -205,10 +209,18 @@ class TrackContentObjectView : public selectableObject, public ModelView return m_tco; } // qproperty access func - QColor fgColor() const; + QColor mutedColor() const; + QColor mutedBackgroundColor() const; + QColor selectedColor() const; QColor textColor() const; - void setFgColor( const QColor & c ); + QColor textShadowColor() const; + bool gradient() const; + void setMutedColor( const QColor & c ); + void setMutedBackgroundColor( const QColor & c ); + void setSelectedColor( const QColor & c ); void setTextColor( const QColor & c ); + void setTextShadowColor( const QColor & c ); + void setGradient( const bool & b ); public slots: virtual bool close(); @@ -267,8 +279,12 @@ protected slots: MidiTime m_oldTime;// used for undo/redo while mouse-button is pressed // qproperty fields - QColor m_fgColor; + QColor m_mutedColor; + QColor m_mutedBackgroundColor; + QColor m_selectedColor; QColor m_textColor; + QColor m_textShadowColor; + bool m_gradient; inline void setInitialMousePos( QPoint pos ) { diff --git a/src/core/SampleBuffer.cpp b/src/core/SampleBuffer.cpp index e44b246e548..7040babcba0 100644 --- a/src/core/SampleBuffer.cpp +++ b/src/core/SampleBuffer.cpp @@ -903,9 +903,7 @@ void SampleBuffer::visualize( QPainter & _p, const QRect & _dr, const bool focus_on_range = _to_frame <= m_frames && 0 <= _from_frame && _from_frame < _to_frame; -// _p.setClipRect( _clip ); -// _p.setPen( QColor( 0x22, 0xFF, 0x44 ) ); - //_p.setPen( QColor( 64, 224, 160 ) ); + //_p.setClipRect( _clip ); const int w = _dr.width(); const int h = _dr.height(); diff --git a/src/core/Track.cpp b/src/core/Track.cpp index 05d3750a5ff..9bd1e22df3d 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -251,8 +251,12 @@ TrackContentObjectView::TrackContentObjectView( TrackContentObject * tco, m_initialMousePos( QPoint( 0, 0 ) ), m_initialMouseGlobalPos( QPoint( 0, 0 ) ), m_hint( NULL ), - m_fgColor( 0, 0, 0 ), - m_textColor( 0, 0, 0 ) + m_mutedColor( 0, 0, 0 ), + m_mutedBackgroundColor( 0, 0, 0 ), + m_selectedColor( 0, 0, 0 ), + m_textColor( 0, 0, 0 ), + m_textShadowColor( 0, 0, 0 ), + m_gradient( true ) { if( s_textFloat == NULL ) { @@ -264,10 +268,10 @@ TrackContentObjectView::TrackContentObjectView( TrackContentObject * tco, setAttribute( Qt::WA_DeleteOnClose, true ); setFocusPolicy( Qt::StrongFocus ); setCursor( QCursor( embed::getIconPixmap( "hand" ), 3, 3 ) ); - move( 0, 1 ); + move( 0, 0 ); show(); - setFixedHeight( tv->getTrackContentWidget()->height() - 2 ); + setFixedHeight( tv->getTrackContentWidget()->height() - 1); setAcceptDrops( true ); setMouseTracking( true ); @@ -319,21 +323,43 @@ bool TrackContentObjectView::fixedTCOs() // qproperty access functions, to be inherited & used by TCOviews //! \brief CSS theming qproperty access method -QColor TrackContentObjectView::fgColor() const -{ return m_fgColor; } +QColor TrackContentObjectView::mutedColor() const +{ return m_mutedColor; } + +QColor TrackContentObjectView::mutedBackgroundColor() const +{ return m_mutedBackgroundColor; } + +QColor TrackContentObjectView::selectedColor() const +{ return m_selectedColor; } -//! \brief CSS theming qproperty access method QColor TrackContentObjectView::textColor() const { return m_textColor; } -//! \brief CSS theming qproperty access method -void TrackContentObjectView::setFgColor( const QColor & c ) -{ m_fgColor = QColor( c ); } +QColor TrackContentObjectView::textShadowColor() const +{ return m_textShadowColor; } + +bool TrackContentObjectView::gradient() const +{ return m_gradient; } //! \brief CSS theming qproperty access method +void TrackContentObjectView::setMutedColor( const QColor & c ) +{ m_mutedColor = QColor( c ); } + +void TrackContentObjectView::setMutedBackgroundColor( const QColor & c ) +{ m_mutedBackgroundColor = QColor( c ); } + +void TrackContentObjectView::setSelectedColor( const QColor & c ) +{ m_selectedColor = QColor( c ); } + void TrackContentObjectView::setTextColor( const QColor & c ) { m_textColor = QColor( c ); } +void TrackContentObjectView::setTextShadowColor( const QColor & c ) +{ m_textShadowColor = QColor( c ); } + +void TrackContentObjectView::setGradient( const bool & b ) +{ m_gradient = b; } + /*! \brief Close a trackContentObjectView * @@ -1047,11 +1073,8 @@ void TrackContentWidget::updateBackground() pmp.fillRect( w, 0, w , h, lighterColor() ); // draw lines - pmp.setPen( QPen( gridColor(), 1 ) ); - // horizontal line - pmp.drawLine( 0, h-1, w*2, h-1 ); - // vertical lines + pmp.setPen( QPen( gridColor(), 1 ) ); for( float x = 0; x < w * 2; x += ppt ) { pmp.drawLine( QLineF( x, 0.0, x, h ) ); @@ -1062,6 +1085,10 @@ void TrackContentWidget::updateBackground() { pmp.drawLine( QLineF( x, 0.0, x, h ) ); } + + // horizontal line + pmp.setPen( QPen( gridColor(), 1 ) ); + pmp.drawLine( 0, h-1, w*2, h-1 ); pmp.end(); @@ -1122,7 +1149,7 @@ void TrackContentWidget::update() for( tcoViewVector::iterator it = m_tcoViews.begin(); it != m_tcoViews.end(); ++it ) { - ( *it )->setFixedHeight( height() - 2 ); + ( *it )->setFixedHeight( height() - 1 ); ( *it )->update(); } QWidget::update(); diff --git a/src/gui/AutomationPatternView.cpp b/src/gui/AutomationPatternView.cpp index e92b5eb71af..56d9a5449d2 100644 --- a/src/gui/AutomationPatternView.cpp +++ b/src/gui/AutomationPatternView.cpp @@ -21,12 +21,12 @@ * Boston, MA 02110-1301 USA. * */ +#include "AutomationPatternView.h" #include #include #include -#include "AutomationPatternView.h" #include "AutomationEditor.h" #include "AutomationPattern.h" #include "embed.h" @@ -54,7 +54,6 @@ AutomationPatternView::AutomationPatternView( AutomationPattern * _pattern, this, SLOT( update() ) ); setAttribute( Qt::WA_OpaquePaintEvent, true ); - setFixedHeight( parentWidget()->height() - 2 ); ToolTip::add( this, tr( "double-click to open this pattern in " "automation editor" ) ); @@ -245,82 +244,66 @@ void AutomationPatternView::mouseDoubleClickEvent( QMouseEvent * me ) void AutomationPatternView::paintEvent( QPaintEvent * ) { - if( m_needsUpdate == false ) + QPainter painter( this ); + + if( !m_needsUpdate ) { - QPainter p( this ); - p.drawPixmap( 0, 0, m_paintPixmap ); + painter.drawPixmap( 0, 0, m_paintPixmap ); return; } - QPainter _p( this ); - const QColor styleColor = _p.pen().brush().color(); - m_needsUpdate = false; - if( m_paintPixmap.isNull() == true || m_paintPixmap.size() != size() ) - { - m_paintPixmap = QPixmap( size() ); - } + m_paintPixmap = m_paintPixmap.isNull() == true || m_paintPixmap.size() != size() + ? QPixmap( size() ) : m_paintPixmap; QPainter p( &m_paintPixmap ); QLinearGradient lingrad( 0, 0, 0, height() ); QColor c; - - if( !( m_pat->getTrack()->isMuted() || m_pat->isMuted() ) ) - c = styleColor; - else - c = QColor( 80, 80, 80 ); - - if( isSelected() == true ) - { - c.setRgb( qMax( c.red() - 128, 0 ), qMax( c.green() - 128, 0 ), 255 ); - } + bool muted = m_pat->getTrack()->isMuted() || m_pat->isMuted(); + bool current = gui->automationEditor()->currentPattern() == m_pat; + + // state: selected, muted, normal + c = isSelected() ? selectedColor() : ( muted ? mutedBackgroundColor() + : painter.background().color() ); lingrad.setColorAt( 1, c.darker( 300 ) ); lingrad.setColorAt( 0, c ); - - p.setBrush( lingrad ); - if( gui->automationEditor()->currentPattern() == m_pat ) - p.setPen( c.lighter( 160 ) ); + + if( gradient() ) + { + p.fillRect( rect(), lingrad ); + } else - p.setPen( c.lighter( 130 ) ); - p.drawRect( 1, 1, width()-3, height()-3 ); - - + { + p.fillRect( rect(), c ); + } + const float ppt = fixedTCOs() ? ( parentWidget()->width() - 2 * TCO_BORDER_WIDTH ) / (float) m_pat->length().getTact() : pixelsPerTact(); const int x_base = TCO_BORDER_WIDTH; - p.setPen( c.darker( 300 ) ); - - for( tact_t t = 1; t < m_pat->length().getTact(); ++t ) - { - const int tx = x_base + static_cast( ppt * t ) - 1; - if( tx < ( width() - TCO_BORDER_WIDTH*2 ) ) - { - p.drawLine( tx, TCO_BORDER_WIDTH, tx, 5 ); - p.drawLine( tx, height() - ( 4 + 2 * TCO_BORDER_WIDTH ), - tx, height() - 2 * TCO_BORDER_WIDTH ); - } - } - + const float min = m_pat->firstObject()->minValue(); const float max = m_pat->firstObject()->maxValue(); const float y_scale = max - min; - const float h = ( height() - 2*TCO_BORDER_WIDTH ) / y_scale; + const float h = ( height() - 2 * TCO_BORDER_WIDTH ) / y_scale; p.translate( 0.0f, max * height() / y_scale - TCO_BORDER_WIDTH ); p.scale( 1.0f, -h ); QLinearGradient lin2grad( 0, min, 0, max ); + QColor col; + + col = !muted ? painter.pen().brush().color() : mutedColor(); - lin2grad.setColorAt( 1, fgColor().lighter( 150 ) ); - lin2grad.setColorAt( 0.5, fgColor() ); - lin2grad.setColorAt( 0, fgColor().darker( 150 ) ); + lin2grad.setColorAt( 1, col.lighter( 150 ) ); + lin2grad.setColorAt( 0.5, col ); + lin2grad.setColorAt( 0, col.darker( 150 ) ); for( AutomationPattern::timeMap::const_iterator it = m_pat->getTimeMap().begin(); @@ -332,67 +315,102 @@ void AutomationPatternView::paintEvent( QPaintEvent * ) MidiTime::ticksPerTact(); const float x2 = (float)( width() - TCO_BORDER_WIDTH ); if( x1 > ( width() - TCO_BORDER_WIDTH ) ) break; - - p.fillRect( QRectF( x1, 0.0f, x2-x1, it.value() ), - lin2grad ); + if( gradient() ) + { + p.fillRect( QRectF( x1, 0.0f, x2 - x1, it.value() ), lin2grad ); + } + else + { + p.fillRect( QRectF( x1, 0.0f, x2 - x1, it.value() ), col ); + } break; } float *values = m_pat->valuesAfter( it.key() ); - for( int i = it.key(); i < (it+1).key(); i++ ) + for( int i = it.key(); i < (it + 1).key(); i++ ) { float value = values[i - it.key()]; const float x1 = x_base + i * ppt / MidiTime::ticksPerTact(); - const float x2 = x_base + (i+1) * ppt / + const float x2 = x_base + (i + 1) * ppt / MidiTime::ticksPerTact(); if( x1 > ( width() - TCO_BORDER_WIDTH ) ) break; - p.fillRect( QRectF( x1, 0.0f, x2-x1, value ), - lin2grad ); + if( gradient() ) + { + p.fillRect( QRectF( x1, 0.0f, x2 - x1, value ), lin2grad ); + } + else + { + p.fillRect( QRectF( x1, 0.0f, x2 - x1, value ), col ); + } } delete [] values; } p.resetMatrix(); + + // bar lines + const int lineSize = 3; + p.setPen( c.darker( 300 ) ); + + for( tact_t t = 1; t < m_pat->length().getTact(); ++t ) + { + const int tx = x_base + static_cast( ppt * t ) - 2; + if( tx < ( width() - TCO_BORDER_WIDTH * 2 ) ) + { + p.drawLine( tx, TCO_BORDER_WIDTH, tx, TCO_BORDER_WIDTH + lineSize ); + p.drawLine( tx, rect().bottom() - ( lineSize + TCO_BORDER_WIDTH ), + tx, rect().bottom() - TCO_BORDER_WIDTH ); + } + } // recording icon for when recording automation if( m_pat->isRecording() ) { p.drawPixmap( 4, 14, *s_pat_rec ); } - - // outer edge - p.setBrush( QBrush() ); - if( gui->automationEditor()->currentPattern() == m_pat ) - p.setPen( c.lighter( 130 ) ); - else - p.setPen( c.darker( 300 ) ); - p.drawRect( 0, 0, width()-1, height()-1 ); - + // pattern name - p.setFont( pointSize<8>( p.font() ) ); - - QColor text_color = ( m_pat->isMuted() || m_pat->getTrack()->isMuted() ) - ? QColor( 30, 30, 30 ) - : textColor(); - - p.setPen( QColor( 0, 0, 0 ) ); - p.drawText( 4, p.fontMetrics().height()+1, m_pat->name() ); - p.setPen( text_color ); - p.drawText( 3, p.fontMetrics().height(), m_pat->name() ); - + p.setRenderHint( QPainter::TextAntialiasing ); + + if( m_staticTextName.text() != m_pat->name() ) + { + m_staticTextName.setText( m_pat->name() ); + } + + QFont font; + font.setHintingPreference( QFont::PreferFullHinting ); + font.setPointSize( 8 ); + p.setFont( font ); + + const int textTop = TCO_BORDER_WIDTH + 1; + const int textLeft = TCO_BORDER_WIDTH + 1; + + p.setPen( textShadowColor() ); + p.drawStaticText( textLeft + 1, textTop + 1, m_staticTextName ); + p.setPen( textColor() ); + p.drawStaticText( textLeft, textTop, m_staticTextName ); + + // inner border + p.setPen( c.lighter( current ? 160 : 130 ) ); + p.drawRect( 1, 1, rect().right() - TCO_BORDER_WIDTH, + rect().bottom() - TCO_BORDER_WIDTH ); + + // outer border + p.setPen( current? c.lighter( 130 ) : c.darker( 300 ) ); + p.drawRect( 0, 0, rect().right(), rect().bottom() ); + + // draw the 'muted' pixmap only if the pattern was manualy muted if( m_pat->isMuted() ) { p.drawPixmap( 3, p.fontMetrics().height() + 1, embed::getIconPixmap( "muted", 16, 16 ) ); } - p.end(); - _p.drawPixmap( 0, 0, m_paintPixmap ); - + painter.drawPixmap( 0, 0, m_paintPixmap ); } diff --git a/src/tracks/BBTrack.cpp b/src/tracks/BBTrack.cpp index 45210b05f4e..bf50a157220 100644 --- a/src/tracks/BBTrack.cpp +++ b/src/tracks/BBTrack.cpp @@ -21,6 +21,7 @@ * Boston, MA 02110-1301 USA. * */ +#include "BBTrack.h" #include #include @@ -28,7 +29,6 @@ #include #include "BBEditor.h" -#include "BBTrack.h" #include "BBTrackContainer.h" #include "embed.h" #include "Engine.h" @@ -159,23 +159,32 @@ TrackContentObjectView * BBTCO::createView( TrackView * _tv ) +BBTCOView::BBTCOView( TrackContentObject * _tco, TrackView * _tv ) : + TrackContentObjectView( _tco, _tv ), + m_bbTCO( dynamic_cast( _tco ) ), + m_paintPixmap(), + m_needsUpdate( true ) +{ + connect( m_bbTCO, SIGNAL( dataChanged() ), + this, SLOT( update() ) ); + setStyle( QApplication::style() ); +} - -BBTCOView::BBTCOView( TrackContentObject * _tco, TrackView * _tv ) : - TrackContentObjectView( _tco, _tv ), - m_bbTCO( dynamic_cast( _tco ) ) +BBTCOView::~BBTCOView() { } -BBTCOView::~BBTCOView() +void BBTCOView::update() { + m_needsUpdate = true; + TrackContentObjectView::update(); } @@ -215,64 +224,101 @@ void BBTCOView::mouseDoubleClickEvent( QMouseEvent * ) void BBTCOView::paintEvent( QPaintEvent * ) { - QPainter p( this ); + QPainter painter( this ); - QColor col; - if( m_bbTCO->getTrack()->isMuted() || m_bbTCO->isMuted() ) + if( !m_needsUpdate ) { - col = QColor( 160, 160, 160 ); + painter.drawPixmap( 0, 0, m_paintPixmap ); + return; } - else if ( m_bbTCO->m_useStyleColor ) + + m_needsUpdate = false; + + m_paintPixmap = m_paintPixmap.isNull() == true || m_paintPixmap.size() != size() + ? QPixmap( size() ) : m_paintPixmap; + + QPainter p( &m_paintPixmap ); + + QLinearGradient lingrad( 0, 0, 0, height() ); + QColor c; + bool muted = m_bbTCO->getTrack()->isMuted() || m_bbTCO->isMuted(); + + // state: selected, muted, default, user selected + c = isSelected() ? selectedColor() : ( muted ? mutedBackgroundColor() + : ( m_bbTCO->m_useStyleColor ? painter.background().color() + : m_bbTCO->colorObj() ) ); + + lingrad.setColorAt( 0, c.light( 130 ) ); + lingrad.setColorAt( 1, c.light( 70 ) ); + + if( gradient() ) { - col = p.pen().brush().color(); + p.fillRect( rect(), lingrad ); } else { - col = m_bbTCO->colorObj(); + p.fillRect( rect(), c ); } - - if( isSelected() == true ) - { - col.setRgb( qMax( col.red() - 128, 0 ), qMax( col.green() - 128, 0 ), 255 ); - } - - QLinearGradient lingrad( 0, 0, 0, height() ); - lingrad.setColorAt( 0, col.light( 130 ) ); - lingrad.setColorAt( 1, col.light( 70 ) ); - p.fillRect( rect(), lingrad ); + + // bar lines + static int lineSize = 3; tact_t t = Engine::getBBTrackContainer()->lengthOfBB( m_bbTCO->bbTrackIndex() ); if( m_bbTCO->length() > MidiTime::ticksPerTact() && t > 0 ) { for( int x = static_cast( t * pixelsPerTact() ); - x < width()-2; + x < width() - 2; x += static_cast( t * pixelsPerTact() ) ) { - p.setPen( col.light( 80 ) ); - p.drawLine( x, 1, x, 5 ); - p.setPen( col.light( 120 ) ); - p.drawLine( x, height() - 6, x, height() - 2 ); + p.setPen( c.light( 80 ) ); + p.drawLine( x, TCO_BORDER_WIDTH, x, TCO_BORDER_WIDTH + lineSize ); + p.setPen( c.light( 120 ) ); + p.drawLine( x, rect().bottom() - ( TCO_BORDER_WIDTH + lineSize ), + x, rect().bottom() - TCO_BORDER_WIDTH ); } } - p.setPen( col.lighter( 130 ) ); - p.drawRect( 1, 1, rect().right()-2, rect().bottom()-2 ); + // pattern name + p.setRenderHint( QPainter::TextAntialiasing ); - p.setPen( col.darker( 300 ) ); - p.drawRect( 0, 0, rect().right(), rect().bottom() ); + if( m_staticTextName.text() != m_bbTCO->name() ) + { + m_staticTextName.setText( m_bbTCO->name() ); + } - p.setFont( pointSize<8>( p.font() ) ); - - p.setPen( QColor( 0, 0, 0 ) ); - p.drawText( 4, p.fontMetrics().height()+1, m_bbTCO->name() ); + QFont font; + font.setHintingPreference( QFont::PreferFullHinting ); + font.setPointSize( 8 ); + p.setFont( font ); + + const int textTop = TCO_BORDER_WIDTH + 1; + const int textLeft = TCO_BORDER_WIDTH + 1; + + p.setPen( textShadowColor() ); + p.drawStaticText( textLeft + 1, textTop + 1, m_staticTextName ); p.setPen( textColor() ); - p.drawText( 3, p.fontMetrics().height(), m_bbTCO->name() ); + p.drawStaticText( textLeft, textTop, m_staticTextName ); + + // inner border + p.setPen( c.lighter( 130 ) ); + p.drawRect( 1, 1, rect().right() - TCO_BORDER_WIDTH, + rect().bottom() - TCO_BORDER_WIDTH ); + + // outer border + p.setPen( c.darker( 300 ) ); + p.drawRect( 0, 0, rect().right(), rect().bottom() ); + // draw the 'muted' pixmap only if the pattern was manualy muted if( m_bbTCO->isMuted() ) { p.drawPixmap( 3, p.fontMetrics().height() + 1, embed::getIconPixmap( "muted", 16, 16 ) ); } + + p.end(); + + painter.drawPixmap( 0, 0, m_paintPixmap ); + } diff --git a/src/tracks/Pattern.cpp b/src/tracks/Pattern.cpp index c32d6a2cadb..496da60a3aa 100644 --- a/src/tracks/Pattern.cpp +++ b/src/tracks/Pattern.cpp @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA. * */ +#include "Pattern.h" #include #include @@ -33,7 +34,6 @@ #include #include -#include "Pattern.h" #include "InstrumentTrack.h" #include "templates.h" #include "gui_templates.h" @@ -703,8 +703,6 @@ PatternView::PatternView( Pattern* pattern, TrackView* parent ) : "step_btn_off_light" ) ); } - setFixedHeight( parentWidget()->height() - 2 ); - ToolTip::add( this, tr( "use mouse wheel to set velocity of a step" ) ); setStyle( QApplication::style() ); @@ -946,96 +944,53 @@ void PatternView::wheelEvent( QWheelEvent * _we ) void PatternView::paintEvent( QPaintEvent * ) { - if( m_needsUpdate == false ) + QPainter painter( this ); + + if( !m_needsUpdate ) { - QPainter p( this ); - p.drawPixmap( 0, 0, m_paintPixmap ); + painter.drawPixmap( 0, 0, m_paintPixmap ); return; } - QPainter _p( this ); - const QColor styleColor = _p.pen().brush().color(); - - m_pat->changeLength( m_pat->length() ); - m_needsUpdate = false; - if( m_paintPixmap.isNull() == true || m_paintPixmap.size() != size() ) - { - m_paintPixmap = QPixmap( size() ); - } + m_paintPixmap = m_paintPixmap.isNull() == true || m_paintPixmap.size() != size() + ? QPixmap( size() ) : m_paintPixmap; QPainter p( &m_paintPixmap ); QLinearGradient lingrad( 0, 0, 0, height() ); - QColor c; - if(( m_pat->m_patternType != Pattern::BeatPattern ) && - !( m_pat->getTrack()->isMuted() || m_pat->isMuted() )) + bool muted = m_pat->getTrack()->isMuted() || m_pat->isMuted(); + bool current = gui->pianoRoll()->currentPattern() == m_pat; + bool beatPattern = m_pat->m_patternType == Pattern::BeatPattern; + + // state: selected, muted, normal + c = isSelected() ? selectedColor() : ( ( !muted && !beatPattern ) + ? painter.background().color() : mutedBackgroundColor() ); + + // invert the gradient for the background in the B&B editor + lingrad.setColorAt( beatPattern ? 0 : 1, c.darker( 300 ) ); + lingrad.setColorAt( beatPattern ? 1 : 0, c ); + + if( gradient() ) { - c = styleColor; + p.fillRect( rect(), lingrad ); } else { - c = QColor( 80, 80, 80 ); + p.fillRect( rect(), c ); } - - if( isSelected() == true ) - { - c.setRgb( qMax( c.red() - 128, 0 ), qMax( c.green() - 128, 0 ), 255 ); - } - - if( m_pat->m_patternType != Pattern::BeatPattern ) - { - lingrad.setColorAt( 1, c.darker( 300 ) ); - lingrad.setColorAt( 0, c ); - } - else - { - lingrad.setColorAt( 0, c.darker( 300 ) ); - lingrad.setColorAt( 1, c ); - } - - p.setBrush( lingrad ); - if( gui->pianoRoll()->currentPattern() == m_pat && m_pat->m_patternType != Pattern::BeatPattern ) - p.setPen( c.lighter( 130 ) ); - else - p.setPen( c.darker( 300 ) ); - p.drawRect( QRect( 0, 0, width() - 1, height() - 1 ) ); - - p.setBrush( QBrush() ); - if( m_pat->m_patternType != Pattern::BeatPattern ) - { - if( gui->pianoRoll()->currentPattern() == m_pat ) - p.setPen( c.lighter( 160 ) ); - else - p.setPen( c.lighter( 130 ) ); - p.drawRect( QRect( 1, 1, width() - 3, height() - 3 ) ); - } - + const float ppt = fixedTCOs() ? ( parentWidget()->width() - 2 * TCO_BORDER_WIDTH ) / (float) m_pat->length().getTact() : ( width() - 2 * TCO_BORDER_WIDTH ) / (float) m_pat->length().getTact(); - const int x_base = TCO_BORDER_WIDTH; - p.setPen( c.darker( 300 ) ); - - for( tact_t t = 1; t < m_pat->length().getTact(); ++t ) - { - p.drawLine( x_base + static_cast( ppt * t ) - 1, - TCO_BORDER_WIDTH, x_base + static_cast( - ppt * t ) - 1, 5 ); - p.drawLine( x_base + static_cast( ppt * t ) - 1, - height() - ( 4 + 2 * TCO_BORDER_WIDTH ), - x_base + static_cast( ppt * t ) - 1, - height() - 2 * TCO_BORDER_WIDTH ); - } - -// melody pattern paint event - + + // melody pattern paint event if( m_pat->m_patternType == Pattern::MelodyPattern ) { if( m_pat->m_notes.size() > 0 ) @@ -1077,15 +1032,7 @@ void PatternView::paintEvent( QPaintEvent * ) const int max_ht = height() - 1 - TCO_BORDER_WIDTH; // set colour based on mute status - if( m_pat->getTrack()->isMuted() || - m_pat->isMuted() ) - { - p.setPen( QColor( 160, 160, 160 ) ); - } - else - { - p.setPen( fgColor() ); - } + p.setPen( muted ? mutedColor() : painter.pen().brush().color() ); // scan through all the notes and draw them on the pattern for( NoteVector::Iterator it = @@ -1122,12 +1069,10 @@ void PatternView::paintEvent( QPaintEvent * ) } } } - } - -// beat pattern paint event + } - else if( m_pat->m_patternType == Pattern::BeatPattern && - ( fixedTCOs() || ppt >= 96 + // beat pattern paint event + else if( beatPattern && ( fixedTCOs() || ppt >= 96 || m_pat->m_steps != MidiTime::stepsPerTact() ) ) { QPixmap stepon; @@ -1193,21 +1138,61 @@ void PatternView::paintEvent( QPaintEvent * ) } } // end for loop } + + // bar lines + const int lineSize = 3; + p.setPen( c.darker( 300 ) ); - p.setFont( pointSize<8>( p.font() ) ); + for( tact_t t = 1; t < m_pat->length().getTact(); ++t ) + { + p.drawLine( x_base + static_cast( ppt * t ) - 1, + TCO_BORDER_WIDTH, x_base + static_cast( + ppt * t ) - 1, TCO_BORDER_WIDTH + lineSize ); + p.drawLine( x_base + static_cast( ppt * t ) - 1, + rect().bottom() - ( lineSize + TCO_BORDER_WIDTH ), + x_base + static_cast( ppt * t ) - 1, + rect().bottom() - TCO_BORDER_WIDTH ); + } - QColor text_color = ( m_pat->isMuted() || m_pat->getTrack()->isMuted() ) - ? QColor( 30, 30, 30 ) - : textColor(); + // pattern name + p.setRenderHint( QPainter::TextAntialiasing ); + + bool isDefaultName = m_pat->name() == m_pat->instrumentTrack()->name(); + + if( !isDefaultName && m_staticTextName.text() != m_pat->name() ) + { + m_staticTextName.setText( m_pat->name() ); + } + + QFont font; + font.setHintingPreference( QFont::PreferFullHinting ); + font.setPointSize( 8 ); + p.setFont( font ); + + const int textTop = TCO_BORDER_WIDTH + 1; + const int textLeft = TCO_BORDER_WIDTH + 1; + + if( !isDefaultName ) + { + p.setPen( textShadowColor() ); + p.drawStaticText( textLeft + 1, textTop + 1, m_staticTextName ); + p.setPen( textColor() ); + p.drawStaticText( textLeft, textTop, m_staticTextName ); + } - if( m_pat->name() != m_pat->instrumentTrack()->name() ) + // inner border + if( !beatPattern ) { - p.setPen( QColor( 0, 0, 0 ) ); - p.drawText( 4, p.fontMetrics().height()+1, m_pat->name() ); - p.setPen( text_color ); - p.drawText( 3, p.fontMetrics().height(), m_pat->name() ); + p.setPen( c.lighter( current ? 160 : 130 ) ); + p.drawRect( 1, 1, rect().right() - TCO_BORDER_WIDTH, + rect().bottom() - TCO_BORDER_WIDTH ); } + + // outer border + p.setPen( ( current && !beatPattern ) ? c.lighter( 130 ) : c.darker( 300 ) ); + p.drawRect( 0, 0, rect().right(), rect().bottom() ); + // draw the 'muted' pixmap only if the pattern was manualy muted if( m_pat->isMuted() ) { p.drawPixmap( 3, p.fontMetrics().height() + 1, @@ -1216,7 +1201,7 @@ void PatternView::paintEvent( QPaintEvent * ) p.end(); - _p.drawPixmap( 0, 0, m_paintPixmap ); + painter.drawPixmap( 0, 0, m_paintPixmap ); } diff --git a/src/tracks/SampleTrack.cpp b/src/tracks/SampleTrack.cpp index 2f64fd7ef2d..f07f6445f7c 100644 --- a/src/tracks/SampleTrack.cpp +++ b/src/tracks/SampleTrack.cpp @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA. * */ +#include "SampleTrack.h" #include #include @@ -33,7 +34,6 @@ #include #include "gui_templates.h" -#include "SampleTrack.h" #include "Song.h" #include "embed.h" #include "Engine.h" @@ -200,15 +200,11 @@ TrackContentObjectView * SampleTCO::createView( TrackView * _tv ) - - - - - - SampleTCOView::SampleTCOView( SampleTCO * _tco, TrackView * _tv ) : TrackContentObjectView( _tco, _tv ), - m_tco( _tco ) + m_tco( _tco ), + m_paintPixmap(), + m_needsUpdate( true ) { // update UI and tooltip updateSample(); @@ -230,6 +226,15 @@ SampleTCOView::~SampleTCOView() +void SampleTCOView::update() +{ + m_needsUpdate = true; + TrackContentObjectView::update(); +} + + + + void SampleTCOView::updateSample() { update(); @@ -273,9 +278,9 @@ void SampleTCOView::contextMenuEvent( QContextMenuEvent * _cme ) "Ctrl"), #endif m_tco, SLOT( toggleMute() ) ); - contextMenu.addAction( embed::getIconPixmap( "record" ), + /*contextMenu.addAction( embed::getIconPixmap( "record" ), tr( "Set/clear record" ), - m_tco, SLOT( toggleRecord() ) ); + m_tco, SLOT( toggleRecord() ) );*/ constructContextMenu( &contextMenu ); contextMenu.exec( QCursor::pos() ); @@ -351,77 +356,96 @@ void SampleTCOView::mouseDoubleClickEvent( QMouseEvent * ) -void SampleTCOView::paintEvent( QPaintEvent * _pe ) +void SampleTCOView::paintEvent( QPaintEvent * pe ) { - QPainter p( this ); - const QColor styleColor = p.pen().brush().color(); + QPainter painter( this ); - QColor c; - if( !( m_tco->getTrack()->isMuted() || m_tco->isMuted() ) ) + if( !m_needsUpdate ) { - c = styleColor; - } - else - { - c = QColor( 80, 80, 80 ); - } - - if( isSelected() == true ) - { - c.setRgb( qMax( c.red() - 128, 0 ), qMax( c.green() - 128, 0 ), 255 ); + painter.drawPixmap( 0, 0, m_paintPixmap ); + return; } - QLinearGradient grad( 0, 0, 0, height() ); - - grad.setColorAt( 1, c.darker( 300 ) ); - grad.setColorAt( 0, c ); - - p.setBrush( grad ); - p.setPen( c.lighter( 160 ) ); - p.drawRect( 1, 1, width()-3, height()-3 ); + m_needsUpdate = false; - p.setBrush( QBrush() ); - p.setPen( c.darker( 300 ) ); - p.drawRect( 0, 0, width()-1, height()-1 ); + m_paintPixmap = m_paintPixmap.isNull() == true || m_paintPixmap.size() != size() + ? QPixmap( size() ) : m_paintPixmap; + QPainter p( &m_paintPixmap ); - if( m_tco->getTrack()->isMuted() || m_tco->isMuted() ) + QLinearGradient lingrad( 0, 0, 0, height() ); + QColor c; + bool muted = m_tco->getTrack()->isMuted() || m_tco->isMuted(); + + // state: selected, muted, normal + c = isSelected() ? selectedColor() : ( muted ? mutedBackgroundColor() + : painter.background().color() ); + + lingrad.setColorAt( 1, c.darker( 300 ) ); + lingrad.setColorAt( 0, c ); + + if( gradient() ) { - p.setPen( QColor( 128, 128, 128 ) ); + p.fillRect( rect(), lingrad ); } else { - p.setPen( fgColor() ); + p.fillRect( rect(), c ); } - QRect r = QRect( 1, 1, + + p.setPen( !muted ? painter.pen().brush().color() : mutedColor() ); + + const int spacing = TCO_BORDER_WIDTH + 1; + + QRect r = QRect( TCO_BORDER_WIDTH, spacing, qMax( static_cast( m_tco->sampleLength() * pixelsPerTact() / DefaultTicksPerTact ), 1 ), - height() - 4 ); - p.setClipRect( QRect( 1, 1, width() - 2, height() - 2 ) ); - m_tco->m_sampleBuffer->visualize( p, r, _pe->rect() ); + rect().bottom() - 2 * spacing ); + m_tco->m_sampleBuffer->visualize( p, r, pe->rect() ); + + // disable antialiasing for borders, since its not needed + p.setRenderHint( QPainter::Antialiasing, false ); + if( r.width() < width() - 1 ) { - p.drawLine( r.x() + r.width(), r.y() + r.height() / 2, - width() - 2, r.y() + r.height() / 2 ); + p.drawLine( r.x(), r.y() + r.height() / 2, + rect().right() - TCO_BORDER_WIDTH, r.y() + r.height() / 2 ); } - p.translate( 0, 0 ); + // inner border + p.setPen( c.lighter( 160 ) ); + p.drawRect( 1, 1, rect().right() - TCO_BORDER_WIDTH, + rect().bottom() - TCO_BORDER_WIDTH ); + + // outer border + p.setPen( c.darker( 300 ) ); + p.drawRect( 0, 0, rect().right(), rect().bottom() ); + + // draw the 'muted' pixmap only if the pattern was manualy muted if( m_tco->isMuted() ) { - p.drawPixmap( 3, 8, embed::getIconPixmap( "muted", 16, 16 ) ); + p.drawPixmap( 3, p.fontMetrics().height() + 1, + embed::getIconPixmap( "muted", 16, 16 ) ); } - if( m_tco->isRecord() ) + + // recording sample tracks is not possible at the moment + + /* if( m_tco->isRecord() ) { p.setFont( pointSize<7>( p.font() ) ); - p.setPen( QColor( 0, 0, 0 ) ); + p.setPen( textShadowColor() ); p.drawText( 10, p.fontMetrics().height()+1, "Rec" ); p.setPen( textColor() ); p.drawText( 9, p.fontMetrics().height(), "Rec" ); p.setBrush( QBrush( textColor() ) ); p.drawEllipse( 4, 5, 4, 4 ); - } + }*/ + + p.end(); + + painter.drawPixmap( 0, 0, m_paintPixmap ); }