Track: make the song editor background CSS-stylable with qproperties

This commit is contained in:
Vesa
2014-04-05 14:55:11 +03:00
parent bd691e6d68
commit 3bcffcdf5b
3 changed files with 122 additions and 7 deletions

View File

@@ -245,6 +245,18 @@ nStateButton {
min-width: 26px;
}
/* track background colors */
trackContentWidget {
qproperty-darkerColor1: rgb( 50, 50, 50 );
qproperty-darkerColor2: rgb( 20, 20, 20 );
qproperty-darkerColor3: rgb( 15, 15, 15 );
qproperty-lighterColor1: rgb( 50, 50, 50 );
qproperty-lighterColor2: rgb( 40, 40, 40 );
qproperty-lighterColor3: rgb( 30, 30, 30 );
qproperty-gradMidPoint: 0.33;
}
/* gear button in tracks */
trackOperationsWidget > QPushButton {

View File

@@ -29,6 +29,7 @@
#include <QtCore/QVector>
#include <QtCore/QList>
#include <QtGui/QWidget>
#include <QColor>
#include "lmms_basics.h"
#include "MidiTime.h"
@@ -236,6 +237,18 @@ private:
class trackContentWidget : public QWidget, public JournallingObject
{
Q_OBJECT
// qproperties for track background gradients
Q_PROPERTY( QColor darkerColor1 READ darkerColor1 WRITE setDarkerColor1 )
Q_PROPERTY( QColor darkerColor2 READ darkerColor2 WRITE setDarkerColor2 )
Q_PROPERTY( QColor darkerColor3 READ darkerColor3 WRITE setDarkerColor3 )
Q_PROPERTY( QColor lighterColor1 READ lighterColor1 WRITE setLighterColor1 )
Q_PROPERTY( QColor lighterColor2 READ lighterColor2 WRITE setLighterColor2 )
Q_PROPERTY( QColor lighterColor3 READ lighterColor3 WRITE setLighterColor3 )
Q_PROPERTY( float gradMidPoint READ gradMidPoint WRITE setGradMidPoint )
public:
trackContentWidget( trackView * _parent );
virtual ~trackContentWidget();
@@ -255,6 +268,28 @@ public:
MidiTime endPosition( const MidiTime & _pos_start );
// qproperty access methods
QColor darkerColor1() const;
QColor darkerColor2() const;
QColor darkerColor3() const;
QColor lighterColor1() const;
QColor lighterColor2() const;
QColor lighterColor3() const;
float gradMidPoint() const;
void setDarkerColor1( const QColor & _c );
void setDarkerColor2( const QColor & _c );
void setDarkerColor3( const QColor & _c );
void setLighterColor1( const QColor & _c );
void setLighterColor2( const QColor & _c );
void setLighterColor3( const QColor & _c );
void setGradMidPoint( float _g );
public slots:
void update();
void changePosition( const MidiTime & _new_pos = MidiTime( -1 ) );
@@ -295,6 +330,14 @@ private:
QPixmap m_background;
// qproperty fields
QColor * m_darkerColor1;
QColor * m_darkerColor2;
QColor * m_darkerColor3;
QColor * m_lighterColor1;
QColor * m_lighterColor2;
QColor * m_lighterColor3;
float m_gradMidPoint;
} ;

View File

@@ -817,7 +817,14 @@ void trackContentObjectView::setAutoResizeEnabled( bool _e )
*/
trackContentWidget::trackContentWidget( trackView * _parent ) :
QWidget( _parent ),
m_trackView( _parent )
m_trackView( _parent ),
m_darkerColor1( NULL ),
m_darkerColor2( NULL ),
m_darkerColor3( NULL ),
m_lighterColor1( NULL ),
m_lighterColor2( NULL ),
m_lighterColor3( NULL ),
m_gradMidPoint( 0.0f )
{
setAcceptDrops( true );
@@ -825,6 +832,16 @@ trackContentWidget::trackContentWidget( trackView * _parent ) :
SIGNAL( positionChanged( const MidiTime & ) ),
this, SLOT( changePosition( const MidiTime & ) ) );
//initialize qproperties
setDarkerColor1( QColor( 0, 0, 0 ) );
setDarkerColor2( QColor( 0, 0, 0 ) );
setDarkerColor3( QColor( 0, 0, 0 ) );
setLighterColor1( QColor( 0, 0, 0 ) );
setLighterColor2( QColor( 0, 0, 0 ) );
setLighterColor3( QColor( 0, 0, 0 ) );
setStyle( QApplication::style() );
updateBackground();
}
@@ -856,15 +873,15 @@ void trackContentWidget::updateBackground()
QPainter pmp( &m_background );
QLinearGradient grad( 0,0, 0, h );
grad.setColorAt( 0.0, QColor( 50, 50, 50 ) );
grad.setColorAt( 0.33, QColor( 20, 20, 20 ) );
grad.setColorAt( 1.0, QColor( 15, 15, 15 ) );
grad.setColorAt( 0.0, darkerColor1() );
grad.setColorAt( gradMidPoint(), darkerColor2() );
grad.setColorAt( 1.0, darkerColor3() );
pmp.fillRect( 0, 0, w, h, grad );
QLinearGradient grad2( 0,0, 0, h );
grad2.setColorAt( 0.0, QColor( 50, 50, 50 ) );
grad2.setColorAt( 0.33, QColor( 40, 40, 40 ) );
grad2.setColorAt( 1.0, QColor( 30, 30, 30 ) );
grad2.setColorAt( 0.0, lighterColor1() );
grad2.setColorAt( gradMidPoint(), lighterColor2() );
grad2.setColorAt( 1.0, lighterColor3() );
pmp.fillRect( w, 0, w , h, grad2 );
// draw lines
@@ -1195,6 +1212,49 @@ MidiTime trackContentWidget::endPosition( const MidiTime & _pos_start )
}
// qproperty access methods
QColor trackContentWidget::darkerColor1() const
{ if( m_darkerColor1 ) return *m_darkerColor1; else return QColor( 0, 0, 0 ); }
QColor trackContentWidget::darkerColor2() const
{ if( m_darkerColor2 ) return *m_darkerColor2; else return QColor( 0, 0, 0 ); }
QColor trackContentWidget::darkerColor3() const
{ if( m_darkerColor3 ) return *m_darkerColor3; else return QColor( 0, 0, 0 ); }
QColor trackContentWidget::lighterColor1() const
{ if( m_lighterColor1 ) return *m_lighterColor1; else return QColor( 0, 0, 0 ); }
QColor trackContentWidget::lighterColor2() const
{ if( m_lighterColor2 ) return *m_lighterColor2; else return QColor( 0, 0, 0 ); }
QColor trackContentWidget::lighterColor3() const
{ if( m_lighterColor3 ) return *m_lighterColor3; else return QColor( 0, 0, 0 ); }
void trackContentWidget::setDarkerColor1( const QColor & _c )
{ if( m_darkerColor1 ) *m_darkerColor1 = _c; else m_darkerColor1 = new QColor( _c ); }
void trackContentWidget::setDarkerColor2( const QColor & _c )
{ if( m_darkerColor2 ) *m_darkerColor2 = _c; else m_darkerColor2 = new QColor( _c ); }
void trackContentWidget::setDarkerColor3( const QColor & _c )
{ if( m_darkerColor3 ) *m_darkerColor3 = _c; else m_darkerColor3 = new QColor( _c ); }
void trackContentWidget::setLighterColor1( const QColor & _c )
{ if( m_lighterColor1 ) *m_lighterColor1 = _c; else m_lighterColor1 = new QColor( _c ); }
void trackContentWidget::setLighterColor2( const QColor & _c )
{ if( m_lighterColor2 ) *m_lighterColor2 = _c; else m_lighterColor2 = new QColor( _c ); }
void trackContentWidget::setLighterColor3( const QColor & _c )
{ if( m_lighterColor3 ) *m_lighterColor3 = _c; else m_lighterColor3 = new QColor( _c ); }
float trackContentWidget::gradMidPoint() const
{ return m_gradMidPoint; }
void trackContentWidget::setGradMidPoint( float _g )
{ m_gradMidPoint = _g; }