Skip to content

Commit

Permalink
Partially migrate common settings to Track.cpp, fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuukumar committed Jul 13, 2020
1 parent 22299d4 commit c6e8368
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 44 deletions.
25 changes: 1 addition & 24 deletions include/Pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,6 @@ class LMMS_EXPORT Pattern : public TrackContentObject
{
return "pattern";
}

unsigned int color() const
{
return( m_color.rgb() );
}

QColor colorObj() const
{
return m_color;
}

void setColor( const QColor & c )
{
m_color = QColor( c );
}

void setUseStyleColor( bool b )
{
m_useStyleColor = b;
}

inline InstrumentTrack * instrumentTrack() const
{
Expand Down Expand Up @@ -167,9 +147,6 @@ protected slots:

Pattern * adjacentPatternByOffset(int offset) const;

QColor m_color;
bool m_useStyleColor;

friend class PatternView;
friend class BBTrackContainerView;

Expand Down Expand Up @@ -208,7 +185,7 @@ class PatternView : public TrackContentObjectView

QColor color() const
{
return( m_pat->m_color );
return( m_pat->color() );
}
void setColor( QColor _new_color );

Expand Down
32 changes: 32 additions & 0 deletions include/Track.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,36 @@ class LMMS_EXPORT TrackContentObject : public Model, public JournallingObject
{
return m_autoResize;
}

unsigned int color() const
{
return( m_color.rgb() );
}

QColor colorObj() const
{
return m_color;
}

void setColor( const QColor & c )
{
m_color = QColor( c );
}

void setColorRgb( const unsigned int & c )
{
m_color.setRgb( c );
}

void setUseStyleColor( bool b )
{
m_useStyleColor = b;
}

bool useStyleColor()
{
return m_useStyleColor;
}

virtual void movePosition( const MidiTime & pos );
virtual void changeLength( const MidiTime & length );
Expand Down Expand Up @@ -195,6 +225,8 @@ public slots:
bool m_selectViewOnCreate;

QColor m_bgcolor;
QColor m_color;
bool m_useStyleColor;

friend class TrackContentObjectView;

Expand Down
10 changes: 9 additions & 1 deletion src/core/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ TrackContentObject::TrackContentObject( Track * track ) :
m_startPosition(),
m_length(),
m_mutedModel( false, this, tr( "Mute" ) ),
m_selectViewOnCreate( false )
m_selectViewOnCreate( false ),
m_color( 128, 128, 128 ),
m_useStyleColor( false )
{
if( getTrack() )
{
Expand Down Expand Up @@ -2406,6 +2408,12 @@ void Track::loadSettings( const QDomElement & element )
*/
TrackContentObject * Track::addTCO( TrackContentObject * tco )
{
if ( m_trackContentObjects.size() >= 1 )
{
tco->setColor( m_trackContentObjects[0]->colorObj() );
tco->setUseStyleColor( m_trackContentObjects[0]->useStyleColor() );
}

m_trackContentObjects.push_back( tco );

emit trackContentObjectAdded( tco );
Expand Down
37 changes: 18 additions & 19 deletions src/tracks/Pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ Pattern::Pattern( InstrumentTrack * _instrument_track ) :
TrackContentObject( _instrument_track ),
m_instrumentTrack( _instrument_track ),
m_patternType( BeatPattern ),
m_steps( MidiTime::stepsPerBar() ),
m_color( 128, 128, 128 ),
m_useStyleColor( true )
m_steps( MidiTime::stepsPerBar() )
{
setName( _instrument_track->name() );
if( _instrument_track->trackContainer()
Expand All @@ -78,9 +76,7 @@ Pattern::Pattern( const Pattern& other ) :
TrackContentObject( other.m_instrumentTrack ),
m_instrumentTrack( other.m_instrumentTrack ),
m_patternType( other.m_patternType ),
m_steps( other.m_steps ),
m_color( 128, 128, 128 ),
m_useStyleColor( true )
m_steps( other.m_steps )
{
for( NoteVector::ConstIterator it = other.m_notes.begin(); it != other.m_notes.end(); ++it )
{
Expand Down Expand Up @@ -364,8 +360,8 @@ void Pattern::saveSettings( QDomDocument & _doc, QDomElement & _this )
{
_this.setAttribute( "type", m_patternType );
_this.setAttribute( "name", name() );
_this.setAttribute( "stylecolor", m_useStyleColor );
_this.setAttribute( "color", m_color.rgb() );
_this.setAttribute( "stylecolor", useStyleColor() );
_this.setAttribute( "color", color() );
// as the target of copied/dragged pattern is always an existing
// pattern, we must not store actual position, instead we store -1
// which tells loadSettings() not to mess around with position
Expand Down Expand Up @@ -400,8 +396,8 @@ void Pattern::loadSettings( const QDomElement & _this )

if( _this.hasAttribute( "stylecolor" ) )
{
m_useStyleColor = _this.attribute( "stylecolor" ).toInt();
m_color.setRgb( _this.attribute( "color" ).toUInt() );
setUseStyleColor( _this.attribute( "stylecolor" ).toInt() );
setColorRgb( _this.attribute( "color" ).toUInt() );
}

if( _this.attribute( "pos" ).toInt() >= 0 )
Expand Down Expand Up @@ -688,17 +684,17 @@ void PatternView::setColor( QColor new_color )
if( new_color.rgb() != m_pat->color() )
{
m_pat->setColor( new_color );
m_pat->m_useStyleColor = false;
m_pat->setUseStyleColor( false );
Engine::getSong()->setModified();
update();
}
}

void PatternView::trackColorReset()
{
if( ! m_pat->m_useStyleColor )
if( ! m_pat->useStyleColor() )
{
m_pat->m_useStyleColor = true;
m_pat->setUseStyleColor( true );
Engine::getSong()->setModified();
update();
}
Expand Down Expand Up @@ -922,12 +918,15 @@ void PatternView::paintEvent( QPaintEvent * )
bool beatPattern = m_pat->m_patternType == Pattern::BeatPattern;

// state: selected, normal, beat pattern, muted
/*QColor c = isSelected() ? selectedColor() : ( ( !muted && !beatPattern )
? painter.background().color() : ( beatPattern
? BBPatternBackground() : mutedBackgroundColor() ) );*/
QColor c = isSelected() ? selectedColor() : ( muted ? mutedBackgroundColor()
: ( m_pat->m_useStyleColor ? painter.background().color()
: m_pat->colorObj() ) );
/*QColor c = isSelected() ? selectedColor() : ( ( !muted && !m_pat->useStyleColor() )
? painter.background().color() : ( m_pat->useStyleColor()
? m_pat->colorObj() : mutedBackgroundColor() ) );*/
/*QColor c = isSelected() ? selectedColor() : ( muted ? mutedBackgroundColor()
: ( m_pat->useStyleColor() ? painter.background().color()
: m_pat->colorObj() ) );*/
QColor c = isSelected() ? selectedColor() : ( muted
? mutedBackgroundColor() : ( m_pat->useStyleColor()
? m_pat->colorObj() : painter.background().color() ) );

// invert the gradient for the background in the B&B editor
QLinearGradient lingrad( 0, 0, 0, height() );
Expand Down

0 comments on commit c6e8368

Please sign in to comment.