Merge pull request #792 from diizy/autoeditor

AutomationEditor: improve zoom, CSS
This commit is contained in:
Tobias Doerffel
2014-05-31 12:46:43 +02:00
3 changed files with 142 additions and 64 deletions

View File

@@ -15,6 +15,11 @@ QMdiArea {
AutomationEditor {
background-color: rgb(0, 0, 0);
color: #e0e0e0;
qproperty-vertexColor: #ff77af;
qproperty-gridColor: #808080;
qproperty-graphColor: #99afff;
qproperty-scaleColor: rgb( 32, 32, 32 );
}
/* text box */

View File

@@ -1,9 +1,9 @@
/*
* AutomationEditor.h - declaration of class AutomationEditor which is a window
* where you can edit dynamic values in an easy way
* where you can edit dynamic values in an easy way
*
* Copyright (c) 2006-2008 Javier Serrano Polo <jasp00/at/users.sourceforge.net>
*
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
@@ -23,8 +23,8 @@
*
*/
#ifndef _AUTOMATION_EDITOR_H
#define _AUTOMATION_EDITOR_H
#ifndef AUTOMATION_EDITOR_H
#define AUTOMATION_EDITOR_H
#include <QtCore/QMutex>
#include <QtGui/QWidget>
@@ -50,6 +50,10 @@ class toolButton;
class AutomationEditor : public QWidget, public JournallingObject
{
Q_OBJECT
Q_PROPERTY( QColor gridColor READ gridColor WRITE setGridColor )
Q_PROPERTY( QColor graphColor READ graphColor WRITE setGraphColor )
Q_PROPERTY( QColor vertexColor READ vertexColor WRITE setVertexColor )
Q_PROPERTY( QColor scaleColor READ scaleColor WRITE setScaleColor )
public:
void setCurrentPattern( AutomationPattern * _new_pattern );
@@ -75,6 +79,15 @@ public:
void setPauseIcon( bool pause );
// qproperty access methods
QColor gridColor() const;
QColor graphColor() const;
QColor vertexColor() const;
QColor scaleColor() const;
void setGridColor( const QColor & c );
void setGraphColor( const QColor & c );
void setVertexColor( const QColor & c );
void setScaleColor( const QColor & c );
public slots:
void update();
@@ -252,7 +265,10 @@ private:
void drawAutomationPoint( QPainter & p, timeMap::iterator it );
bool inBBEditor();
QColor m_gridColor;
QColor m_graphColor;
QColor m_vertexColor;
QColor m_scaleColor;
friend class engine;

View File

@@ -1,6 +1,6 @@
/*
* AutomationEditor.cpp - implementation of AutomationEditor which is used for
* actual setting of dynamic values
* actual setting of dynamic values
*
* Copyright (c) 2008-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2008-2013 Paul Giblock <pgib/at/users.sourceforge.net>
@@ -71,8 +71,6 @@ QPixmap * AutomationEditor::s_toolSelect = NULL;
QPixmap * AutomationEditor::s_toolMove = NULL;
const QColor DRAGGABLE_PIN_COLOR = QColor( 0xFF, 0x00, 0x00 );
const QColor DRAGGABLE_PIN_BORDER_COLOR = QColor( 0xFF, 0xFF, 0xFF );
AutomationEditor::AutomationEditor() :
@@ -98,7 +96,11 @@ AutomationEditor::AutomationEditor() :
m_y_delta( DEFAULT_Y_DELTA ),
m_y_auto( TRUE ),
m_editMode( DRAW ),
m_scrollBack( FALSE )
m_scrollBack( FALSE ),
m_gridColor( 0,0,0 ),
m_graphColor( 0,0,0 ),
m_vertexColor( 0,0,0 ),
m_scaleColor( 0,0,0 )
{
connect( this, SIGNAL( currentPatternChanged() ),
this, SLOT( updateAfterPatternChange() ),
@@ -358,7 +360,7 @@ AutomationEditor::AutomationEditor() :
m_zoomingYComboBox->setFixedSize( 80, 22 );
m_zoomingYModel.addItem( "Auto" );
for( int i = 0; i < 6; ++i )
for( int i = 0; i < 7; ++i )
{
m_zoomingYModel.addItem( QString::number( 25 << i ) + "%" );
}
@@ -377,15 +379,13 @@ AutomationEditor::AutomationEditor() :
m_quantizeComboBox = new comboBox( m_toolBar );
m_quantizeComboBox->setFixedSize( 60, 22 );
// TODO: leak
ComboBoxModel * quantize_model = new ComboBoxModel( /* this */ );
for( int i = 0; i < 7; ++i )
{
quantize_model->addItem( "1/" + QString::number( 1 << i ) );
m_quantizeModel.addItem( "1/" + QString::number( 1 << i ) );
}
quantize_model->setValue( quantize_model->findText( "1/16" ) );
m_quantizeModel.setValue( m_quantizeModel.findText( "1/16" ) );
m_quantizeComboBox->setModel( quantize_model );
m_quantizeComboBox->setModel( &m_quantizeModel );
tb_layout->addSpacing( 5 );
@@ -456,6 +456,7 @@ AutomationEditor::~AutomationEditor()
{
m_zoomingXModel.disconnect();
m_zoomingYModel.disconnect();
m_quantizeModel.disconnect();
m_tensionModel->disconnect();
}
@@ -502,6 +503,24 @@ void AutomationEditor::setPauseIcon( bool pause )
}
}
// qproperty access methods
QColor AutomationEditor::gridColor() const
{ return m_gridColor; }
QColor AutomationEditor::graphColor() const
{ return m_graphColor; }
QColor AutomationEditor::vertexColor() const
{ return m_vertexColor; }
QColor AutomationEditor::scaleColor() const
{ return m_scaleColor; }
void AutomationEditor::setGridColor( const QColor & c )
{ m_gridColor = c; }
void AutomationEditor::setGraphColor( const QColor & c )
{ m_graphColor = c; }
void AutomationEditor::setVertexColor( const QColor & c )
{ m_vertexColor = c; }
void AutomationEditor::setScaleColor( const QColor & c )
{ m_scaleColor = c; }
@@ -1350,13 +1369,10 @@ inline void AutomationEditor::drawAutomationPoint( QPainter & p, timeMap::iterat
{
int x = xCoordOfTick( it.key() );
int y = yCoordOfLevel( it.value() );
int outerRadius = qMin( 8, m_ppt/quantization() );
int innerRadius = qMax( 0, outerRadius-2 );
p.setBrush( QBrush( DRAGGABLE_PIN_BORDER_COLOR ) );
p.drawEllipse( x-outerRadius/2, y-outerRadius/2, outerRadius, outerRadius );
p.setBrush( QBrush( DRAGGABLE_PIN_COLOR ) );
p.drawEllipse( x-innerRadius/2, y-innerRadius/2, innerRadius, innerRadius );
p.setBrush( QBrush() );
const int outerRadius = qBound( 2, ( m_ppt * quantization() ) / 576, 5 ); // man, getting this calculation right took forever
p.setPen( QPen( vertexColor().lighter( 200 ) ) );
p.setBrush( QBrush( vertexColor() ) );
p.drawEllipse( x - outerRadius, y - outerRadius, outerRadius * 2, outerRadius * 2 );
}
@@ -1371,6 +1387,12 @@ void AutomationEditor::paintEvent( QPaintEvent * _pe )
QPainter p( this );
style()->drawPrimitive( QStyle::PE_Widget, &opt, &p, this );
// get foregrounf color
QColor fgColor = p.pen().brush().color();
// get background color and fill background
QColor bgColor = p.background().color();
p.fillRect( 0, 0, width(), height(), bgColor );
// set font-size to 8
p.setFont( pointSize<8>( p.font() ) );
@@ -1380,7 +1402,7 @@ void AutomationEditor::paintEvent( QPaintEvent * _pe )
int grid_bottom = height() - SCROLLBAR_SIZE - 1;
p.fillRect( 0, TOP_MARGIN, VALUES_WIDTH, height() - TOP_MARGIN,
QColor( 0x33, 0x33, 0x33 ) );
scaleColor() );
// print value numbers
int font_height = p.fontMetrics().height();
@@ -1397,11 +1419,12 @@ void AutomationEditor::paintEvent( QPaintEvent * _pe )
{
const QString & label = m_pattern->firstObject()
->displayValue( level[i] );
p.setPen( QColor( 240, 240, 240 ) );
p.setPen( QApplication::palette().color( QPalette::Active,
QPalette::Shadow ) );
p.drawText( 1, y[i] - font_height + 1,
VALUES_WIDTH - 10, 2 * font_height,
text_flags, label );
p.setPen( QColor( 0, 0, 0 ) );
p.setPen( fgColor );
p.drawText( 0, y[i] - font_height,
VALUES_WIDTH - 10, 2 * font_height,
text_flags, label );
@@ -1425,11 +1448,12 @@ void AutomationEditor::paintEvent( QPaintEvent * _pe )
const QString & label = m_pattern->firstObject()
->displayValue( level );
y = yCoordOfLevel( level );
p.setPen( QColor( 240, 240, 240 ) );
p.setPen( QApplication::palette().color( QPalette::Active,
QPalette::Shadow ) );
p.drawText( 1, y - font_height + 1,
VALUES_WIDTH - 10, 2 * font_height,
text_flags, label );
p.setPen( QColor( 0, 0, 0 ) );
p.setPen( fgColor );
p.drawText( 0, y - font_height,
VALUES_WIDTH - 10, 2 * font_height,
text_flags, label );
@@ -1443,6 +1467,7 @@ void AutomationEditor::paintEvent( QPaintEvent * _pe )
grid_height );
// draw vertical raster
QColor lineColor = QColor( gridColor() );
if( m_pattern )
{
int tick, x;
@@ -1454,38 +1479,42 @@ void AutomationEditor::paintEvent( QPaintEvent * _pe )
// exotic denominators (e.g. 7/11 time), which are allowed ATM.
// First quantization grid...
for( tick = m_currentPosition - m_currentPosition % quantization(),
x = xCoordOfTick( tick );
x<=width();
tick += quantization(), x = xCoordOfTick( tick ) )
{
p.setPen( QColor( 0x2F, 0x2F, 0x2F ) );
x = xCoordOfTick( tick );
x<=width();
tick += quantization(), x = xCoordOfTick( tick ) )
{
lineColor.setAlpha( 80 );
p.setPen( lineColor );
p.drawLine( x, grid_bottom, x, x_line_end );
}
// Then beat grid
int ticksPerBeat = DefaultTicksPerTact /
// Then beat grid
int ticksPerBeat = DefaultTicksPerTact /
engine::getSong()->getTimeSigModel().getDenominator();
for( tick = m_currentPosition - m_currentPosition % ticksPerBeat,
x = xCoordOfTick( tick );
x<=width();
tick += ticksPerBeat, x = xCoordOfTick( tick ) )
{
p.setPen( QColor( 0x5F, 0x5F, 0x5F ) );
x = xCoordOfTick( tick );
x<=width();
tick += ticksPerBeat, x = xCoordOfTick( tick ) )
{
lineColor.setAlpha( 160 );
p.setPen( lineColor );
p.drawLine( x, grid_bottom, x, x_line_end );
}
// and finally bars
for( tick = m_currentPosition - m_currentPosition % MidiTime::ticksPerTact(),
x = xCoordOfTick( tick );
x<=width();
tick += MidiTime::ticksPerTact(), x = xCoordOfTick( tick ) )
x = xCoordOfTick( tick );
x<=width();
tick += MidiTime::ticksPerTact(), x = xCoordOfTick( tick ) )
{
p.setPen( QColor( 0x7F, 0x7F, 0x7F ) );
lineColor.setAlpha( 255 );
p.setPen( lineColor );
p.drawLine( x, grid_bottom, x, x_line_end );
}
/// \todo move this horizontal line drawing code into the same loop as the value ticks?
if( m_y_auto )
{
QPen pen( QColor( 0x4F, 0x4F, 0x4F ) );
lineColor.setAlpha( 160 );
QPen pen( lineColor );
p.setPen( pen );
p.drawLine( VALUES_WIDTH, grid_bottom, width(),
grid_bottom );
@@ -1506,11 +1535,13 @@ void AutomationEditor::paintEvent( QPaintEvent * _pe )
y = yCoordOfLevel( (float)level );
if( level % 5 == 0 )
{
p.setPen( QColor( 0x4F, 0x4F, 0x4F ) );
lineColor.setAlpha( 160 );
p.setPen( lineColor );
}
else
{
p.setPen( QColor( 0x3F, 0x3F, 0x3F ) );
lineColor.setAlpha( 80 );
p.setPen( lineColor );
}
// draw level line
@@ -1547,8 +1578,7 @@ void AutomationEditor::paintEvent( QPaintEvent * _pe )
//Don't bother doing/rendering anything if there is no automation points
if( time_map.size() > 0 )
{
timeMap::iterator it = time_map.begin();
p.setPen( QColor( 0xCF, 0xD9, 0xFF ) );
timeMap::iterator it = time_map.begin();
while( it+1 != time_map.end() )
{
// skip this section if it occurs completely before the
@@ -1585,10 +1615,11 @@ void AutomationEditor::paintEvent( QPaintEvent * _pe )
{
is_selected = TRUE;
}
float *values = m_pattern->valuesAfter( it.key() );
for( int i = 0; i < (it+1).key() - it.key(); i++ )
{
drawLevelTick( p, it.key() + i, values[i],
is_selected );
}
@@ -1617,7 +1648,8 @@ void AutomationEditor::paintEvent( QPaintEvent * _pe )
QFont f = p.font();
f.setBold( TRUE );
p.setFont( pointSize<14>( f ) );
p.setPen( QColor( 74, 253, 133 ) );
p.setPen( QApplication::palette().color( QPalette::Active,
QPalette::BrightText ) );
p.drawText( VALUES_WIDTH + 20, TOP_MARGIN + 40,
width() - VALUES_WIDTH - 20 - SCROLLBAR_SIZE,
grid_height - 40, Qt::TextWordWrap,
@@ -1736,17 +1768,19 @@ void AutomationEditor::drawLevelTick( QPainter & _p, int _tick, float _level,
rect_height = (int)( _level * m_y_delta );
}
QColor current_color( 0x9F, 0xAF, 0xFF );
QColor current_color( graphColor() );
if( _is_selected == TRUE )
{
current_color.setRgb( 0x00, 0x40, 0xC0 );
}
_p.fillRect( x, y_start, rect_width, rect_height, current_color );
}
else
{
printf("not in range\n");
}
}
@@ -1798,26 +1832,49 @@ void AutomationEditor::resizeEvent( QResizeEvent * )
void AutomationEditor::wheelEvent( QWheelEvent * _we )
{
_we->accept();
if( _we->modifiers() & Qt::ControlModifier )
if( _we->modifiers() & Qt::ControlModifier && _we->modifiers() & Qt::ShiftModifier )
{
int y = m_zoomingYModel.value();
if( _we->delta() > 0 )
{
m_ppt = qMin( m_ppt * 2, m_y_delta *
DEFAULT_STEPS_PER_TACT * 8 );
y++;
}
else if( m_ppt >= 72 )
if( _we->delta() < 0 )
{
m_ppt /= 2;
y--;
}
// update combobox with zooming-factor
m_zoomingXComboBox->model()->setValue(
m_zoomingXComboBox->model()->findText( QString::number(
qRound( m_ppt * 100 /
DEFAULT_PPT ) ) +"%" ) );
// update timeline
m_timeLine->setPixelsPerTact( m_ppt );
y = qBound( 0, y, m_zoomingYModel.size() - 1 );
m_zoomingYModel.setValue( y );
}
else if( _we->modifiers() & Qt::ControlModifier && _we->modifiers() & Qt::AltModifier )
{
int q = m_quantizeModel.value();
if( _we->delta() > 0 )
{
q--;
}
if( _we->delta() < 0 )
{
q++;
}
q = qBound( 0, q, m_quantizeModel.size() - 1 );
m_quantizeModel.setValue( q );
update();
}
else if( _we->modifiers() & Qt::ControlModifier )
{
int x = m_zoomingXModel.value();
if( _we->delta() > 0 )
{
x++;
}
if( _we->delta() < 0 )
{
x--;
}
x = qBound( 0, x, m_zoomingXModel.size() - 1 );
m_zoomingXModel.setValue( x );
}
else if( _we->modifiers() & Qt::ShiftModifier
|| _we->orientation() == Qt::Horizontal )
{