Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change colors for SampleTrack #816

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions include/SampleBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <QtCore/QMutex>
#include <QtCore/QObject>
#include <QtCore/QRect>
#include <QColor>

#include <samplerate.h>

Expand Down Expand Up @@ -255,7 +256,16 @@ class EXPORT SampleBuffer : public QObject, public sharedObject

static QString tryToMakeRelative( const QString & _file );
static QString tryToMakeAbsolute( const QString & _file );


void setColor(QColor _new_color)
{
m_color = _new_color.rgb();
}

QColor getColor() const
{
return m_color;
}

public slots:
void setAudioFile( const QString & _audio_file );
Expand Down Expand Up @@ -307,7 +317,8 @@ public slots:
f_cnt_t getLoopedIndex( f_cnt_t _index, f_cnt_t _startf, f_cnt_t _endf ) const;
f_cnt_t getPingPongIndex( f_cnt_t _index, f_cnt_t _startf, f_cnt_t _endf ) const;


unsigned int m_color;

signals:
void sampleUpdated();

Expand Down
38 changes: 34 additions & 4 deletions include/SampleTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ class SampleTCO : public trackContentObject

virtual trackContentObjectView * createView( trackView * _tv );

inline unsigned int fgColor() const
{
return( m_fg_color );
}
inline static unsigned int defaultFgColor()
{
return qRgb( 128, 182, 175 );
}
inline unsigned int bgColor() const
{
return( m_bg_color );
}
inline static unsigned int defaultBgColor()
{
return qRgb( 128, 182, 175 );
}

public slots:
void setSampleBuffer( SampleBuffer* sb );
Expand All @@ -73,6 +89,8 @@ public slots:
private:
SampleBuffer* m_sampleBuffer;
BoolModel m_recordModel;
unsigned int m_fg_color;
unsigned int m_bg_color;


friend class SampleTCOView;
Expand All @@ -88,19 +106,31 @@ 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 );
virtual ~SampleTCOView();

QColor fgColor() const
{
return( m_tco->m_fg_color );
}
void setFgColor( QColor _new_color );

QColor bgColor() const
{
return( m_tco->m_bg_color );
}
void setBgColor( QColor _new_color );


public slots:
void updateSample();

protected slots:
void changeFgColor();
void changeBgColor();


protected:
virtual void contextMenuEvent( QContextMenuEvent * _cme );
Expand Down
4 changes: 4 additions & 0 deletions include/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class trackContentObjectView : public selectableObject, public ModelView

// theming qproperties
Q_PROPERTY( QColor fgColor READ fgColor WRITE setFgColor )
Q_PROPERTY( QColor bgColor READ bgColor WRITE setBgColor )
Q_PROPERTY( QColor textColor READ textColor WRITE setTextColor )

public:
Expand All @@ -193,8 +194,10 @@ class trackContentObjectView : public selectableObject, public ModelView
}
// qproperty access func
QColor fgColor() const;
QColor bgColor() const;
QColor textColor() const;
void setFgColor( const QColor & _c );
void setBgColor( const QColor & _c );
void setTextColor( const QColor & _c );

public slots:
Expand Down Expand Up @@ -257,6 +260,7 @@ protected slots:

// qproperty fields
QColor m_fgColor;
QColor m_bgColor;
QColor m_textColor;

inline void setInitialMousePos( QPoint pos )
Expand Down
6 changes: 5 additions & 1 deletion src/core/SampleBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,11 @@ void SampleBuffer::visualize( QPainter & _p, const QRect & _dr,
const int yb = h / 2 + _dr.y();
const float y_space = h*0.25f;
const int nb_frames = focus_on_range ? _to_frame - _from_frame : m_frames;


QColor c;
if (m_color) c = QColor(m_color);
else c = _p.pen().color();

if( nb_frames < 60000 )
{
_p.setRenderHint( QPainter::Antialiasing );
Expand Down
9 changes: 9 additions & 0 deletions src/core/track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ trackContentObjectView::trackContentObjectView( trackContentObject * _tco,
m_initialMouseGlobalPos( QPoint( 0, 0 ) ),
m_hint( NULL ),
m_fgColor( 0, 0, 0 ),
m_bgColor( 0, 0, 0 ),
m_textColor( 0, 0, 0 )
{
if( s_textFloat == NULL )
Expand Down Expand Up @@ -323,6 +324,10 @@ bool trackContentObjectView::fixedTCOs()
QColor trackContentObjectView::fgColor() const
{ return m_fgColor; }

//! \brief CSS theming qproperty access method
QColor trackContentObjectView::bgColor() const
{ return m_bgColor; }

//! \brief CSS theming qproperty access method
QColor trackContentObjectView::textColor() const
{ return m_textColor; }
Expand All @@ -331,6 +336,10 @@ QColor trackContentObjectView::textColor() const
void trackContentObjectView::setFgColor( const QColor & _c )
{ m_fgColor = QColor( _c ); }

//! \brief CSS theming qproperty access method
void trackContentObjectView::setBgColor( const QColor & _c )
{ m_bgColor = QColor( _c ); }

//! \brief CSS theming qproperty access method
void trackContentObjectView::setTextColor( const QColor & _c )
{ m_textColor = QColor( _c ); }
Expand Down
108 changes: 101 additions & 7 deletions src/tracks/SampleTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

#include <QtXml/QDomElement>
#include <QtGui/QColorDialog>
#include <QtGui/QDropEvent>
#include <QtGui/QMenu>
#include <QtGui/QLayout>
Expand All @@ -35,6 +36,7 @@
#include "gui_templates.h"
#include "SampleTrack.h"
#include "song.h"
#include "SongEditor.h"
#include "embed.h"
#include "engine.h"
#include "tooltip.h"
Expand All @@ -56,7 +58,9 @@ SampleTCO::SampleTCO( track * _track ) :
saveJournallingState( false );
setSampleFile( "" );
restoreJournallingState();

m_fg_color = defaultFgColor();
m_bg_color = defaultBgColor();

// we need to receive bpm-change-events, because then we have to
// change length of this TCO
connect( engine::getSong(), SIGNAL( tempoChanged( bpm_t ) ),
Expand Down Expand Up @@ -155,6 +159,9 @@ void SampleTCO::saveSettings( QDomDocument & _doc, QDomElement & _this )
_this.setAttribute( "data", m_sampleBuffer->toBase64( s ) );
}
// TODO: start- and end-frame
_this.setAttribute( "fg_color", m_fg_color );
_this.setAttribute( "bg_color", m_bg_color );

}


Expand All @@ -173,6 +180,15 @@ void SampleTCO::loadSettings( const QDomElement & _this )
}
changeLength( _this.attribute( "len" ).toInt() );
setMuted( _this.attribute( "muted" ).toInt() );

if( _this.attribute( "fg_color" ).toUInt() != 0 )
{
m_fg_color = _this.attribute( "fg_color" ).toUInt();
}
if( _this.attribute( "bg_color" ).toUInt() != 0 )
{
m_bg_color = _this.attribute( "bg_color" ).toUInt();
}
}


Expand Down Expand Up @@ -254,9 +270,12 @@ void SampleTCOView::contextMenuEvent( QContextMenuEvent * _cme )
contextMenu.addAction( embed::getIconPixmap( "muted" ),
tr( "Mute/unmute (<Ctrl> + middle click)" ),
m_tco, SLOT( toggleMute() ) );
contextMenu.addAction( embed::getIconPixmap( "record" ),
tr( "Set/clear record" ),
m_tco, SLOT( toggleRecord() ) );
contextMenu.addAction( embed::getIconPixmap( "colorize" ),
tr( "Change foreground color" ),
this, SLOT( changeFgColor() ) );
contextMenu.addAction( embed::getIconPixmap( "colorize" ),
tr( "Change background color" ),
this, SLOT( changeBgColor() ) );
constructContextMenu( &contextMenu );

contextMenu.exec( QCursor::pos() );
Expand Down Expand Up @@ -335,8 +354,9 @@ void SampleTCOView::mouseDoubleClickEvent( QMouseEvent * )
void SampleTCOView::paintEvent( QPaintEvent * _pe )
{
QPainter p( this );
const QColor styleColor = p.pen().brush().color();

QColor styleColor = p.pen().brush().color();
if (m_tco->m_bg_color != 0) styleColor = QColor( m_tco->m_bg_color );

QColor c;
if( !( m_tco->getTrack()->isMuted() || m_tco->isMuted() ) )
c = isSelected() ? QColor( 0, 0, 224 )
Expand All @@ -363,13 +383,14 @@ void SampleTCOView::paintEvent( QPaintEvent * _pe )
}
else
{
p.setPen( fgColor() );
p.setPen( m_tco->m_fg_color );
}
QRect r = QRect( 1, 1,
qMax( static_cast<int>( m_tco->sampleLength() *
pixelsPerTact() / DefaultTicksPerTact ), 1 ),
height() - 4 );
p.setClipRect( QRect( 1, 1, width() - 2, height() - 2 ) );
m_tco->m_sampleBuffer->setColor( m_tco->m_fg_color );
m_tco->m_sampleBuffer->visualize( p, r, _pe->rect() );
if( r.width() < width() - 1 )
{
Expand All @@ -396,8 +417,81 @@ void SampleTCOView::paintEvent( QPaintEvent * _pe )
}
}

void SampleTCOView::changeFgColor()
{
QColor _new_color = QColorDialog::getColor( m_tco->m_fg_color );
if( !_new_color.isValid() )
{
return;
}
if( isSelected() )
{
QVector<selectableObject *> selected =
engine::songEditor()->selectedObjects();
for( QVector<selectableObject *>::iterator it =
selected.begin();
it != selected.end(); ++it )
{
SampleTCOView * sample_tcov = dynamic_cast<SampleTCOView *>( *it );
if( sample_tcov )
{
sample_tcov->setFgColor( _new_color );
}
}
}
else
{
setFgColor( _new_color );
}
}

void SampleTCOView::changeBgColor()
{
QColor _new_color = QColorDialog::getColor( m_tco->m_bg_color );
if( !_new_color.isValid() )
{
return;
}
if( isSelected() )
{
QVector<selectableObject *> selected =
engine::songEditor()->selectedObjects();
for( QVector<selectableObject *>::iterator it =
selected.begin();
it != selected.end(); ++it )
{
SampleTCOView * sample_tcov = dynamic_cast<SampleTCOView *>( *it );
if( sample_tcov )
{
sample_tcov->setBgColor( _new_color );
}
}
}
else
{
setBgColor( _new_color );
}
}

void SampleTCOView::setFgColor( QColor _new_color )
{
if( _new_color.rgb() != m_tco->m_fg_color )
{
m_tco->m_fg_color = _new_color.rgb();
engine::getSong()->setModified();
update();
}
}

void SampleTCOView::setBgColor( QColor _new_color )
{
if( _new_color.rgb() != m_tco->m_bg_color )
{
m_tco->m_bg_color = _new_color.rgb();
engine::getSong()->setModified();
update();
}
}



Expand Down