From 56520431850cdb55a7e0347e497ea2d60536fe80 Mon Sep 17 00:00:00 2001 From: Vesa Date: Sat, 31 May 2014 01:47:59 +0300 Subject: [PATCH 1/3] AutomationEditor: improve zoom functionality - entire wheelevent code was written very... weirdly, I simplified it - fix bug with x zoom with mousewheel, no more getting stuck between 25/50 - ctrl+shift+mousewheel now zooms y-axis - ctrl+alt+mousewheel now changes quantization --- include/AutomationEditor.h | 22 +++++-- src/gui/AutomationEditor.cpp | 109 ++++++++++++++++++++++++----------- 2 files changed, 92 insertions(+), 39 deletions(-) diff --git a/include/AutomationEditor.h b/include/AutomationEditor.h index 9ff61bf25..2a39be6ff 100644 --- a/include/AutomationEditor.h +++ b/include/AutomationEditor.h @@ -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 - * + * * 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 #include @@ -50,6 +50,9 @@ 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 ) public: void setCurrentPattern( AutomationPattern * _new_pattern ); @@ -75,6 +78,13 @@ public: void setPauseIcon( bool pause ); + // qproperty access methods + QColor gridColor() const; + QColor graphColor() const; + QColor vertexColor() const; + void setGridColor( const QColor & c ); + void setGraphColor( const QColor & c ); + void setVertexColor( const QColor & c ); public slots: void update(); @@ -252,7 +262,9 @@ private: void drawAutomationPoint( QPainter & p, timeMap::iterator it ); bool inBBEditor(); - + QColor m_gridColor; + QColor m_graphColor; + QColor m_vertexColor; friend class engine; diff --git a/src/gui/AutomationEditor.cpp b/src/gui/AutomationEditor.cpp index 9c4536ca2..ab4c31457 100644 --- a/src/gui/AutomationEditor.cpp +++ b/src/gui/AutomationEditor.cpp @@ -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 * Copyright (c) 2008-2013 Paul Giblock @@ -98,7 +98,10 @@ 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 ) { connect( this, SIGNAL( currentPatternChanged() ), this, SLOT( updateAfterPatternChange() ), @@ -358,7 +361,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 +380,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 +457,7 @@ AutomationEditor::~AutomationEditor() { m_zoomingXModel.disconnect(); m_zoomingYModel.disconnect(); + m_quantizeModel.disconnect(); m_tensionModel->disconnect(); } @@ -502,6 +504,20 @@ 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; } +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; } @@ -1454,34 +1470,34 @@ 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 ) ) - { + x = xCoordOfTick( tick ); + x<=width(); + tick += quantization(), x = xCoordOfTick( tick ) ) + { p.setPen( QColor( 0x2F, 0x2F, 0x2F ) ); 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 ) ) - { + x = xCoordOfTick( tick ); + x<=width(); + tick += ticksPerBeat, x = xCoordOfTick( tick ) ) + { p.setPen( QColor( 0x5F, 0x5F, 0x5F ) ); 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 ) ); 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 ) { @@ -1743,10 +1759,12 @@ void AutomationEditor::drawLevelTick( QPainter & _p, int _tick, float _level, } _p.fillRect( x, y_start, rect_width, rect_height, current_color ); } + else { printf("not in range\n"); } + } @@ -1798,26 +1816,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 ) { From 310ac280091b6b330f7579bd81b6624381827536 Mon Sep 17 00:00:00 2001 From: Vesa Date: Sat, 31 May 2014 03:32:55 +0300 Subject: [PATCH 2/3] AutomationEditor: CSS stylability --- data/themes/default/style.css | 5 +++ include/AutomationEditor.h | 4 +++ src/gui/AutomationEditor.cpp | 64 ++++++++++++++++++++++------------- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/data/themes/default/style.css b/data/themes/default/style.css index d5c973e87..1794895b6 100644 --- a/data/themes/default/style.css +++ b/data/themes/default/style.css @@ -15,6 +15,11 @@ QMdiArea { AutomationEditor { background-color: rgb(0, 0, 0); + color: #e0e0e0; + qproperty-vertexColor: #ff77af; + qproperty-gridColor: #808080; + qproperty-graphColor: #cfd9ff; + qproperty-scaleColor: rgb( 32, 32, 32 ); } /* text box */ diff --git a/include/AutomationEditor.h b/include/AutomationEditor.h index 2a39be6ff..17d966037 100644 --- a/include/AutomationEditor.h +++ b/include/AutomationEditor.h @@ -53,6 +53,7 @@ class AutomationEditor : public QWidget, public JournallingObject 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 ); @@ -82,9 +83,11 @@ public: 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(); @@ -265,6 +268,7 @@ private: QColor m_gridColor; QColor m_graphColor; QColor m_vertexColor; + QColor m_scaleColor; friend class engine; diff --git a/src/gui/AutomationEditor.cpp b/src/gui/AutomationEditor.cpp index ab4c31457..17e8ba6e3 100644 --- a/src/gui/AutomationEditor.cpp +++ b/src/gui/AutomationEditor.cpp @@ -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() : @@ -101,7 +99,8 @@ AutomationEditor::AutomationEditor() : m_scrollBack( FALSE ), m_gridColor( 0,0,0 ), m_graphColor( 0,0,0 ), - m_vertexColor( 0,0,0 ) + m_vertexColor( 0,0,0 ), + m_scaleColor( 0,0,0 ) { connect( this, SIGNAL( currentPatternChanged() ), this, SLOT( updateAfterPatternChange() ), @@ -512,12 +511,16 @@ 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; } @@ -1366,13 +1369,12 @@ 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 + const int innerRadius = outerRadius - 1; + p.setBrush( QBrush( vertexColor().lighter( 200 ) ) ); + p.drawEllipse( x - outerRadius, y - outerRadius, outerRadius * 2, outerRadius * 2 ); + p.setBrush( QBrush( vertexColor() ) ); + p.drawEllipse( x - innerRadius, y - innerRadius, innerRadius * 2, innerRadius * 2 ); } @@ -1387,6 +1389,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() ) ); @@ -1396,7 +1404,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(); @@ -1413,11 +1421,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 ); @@ -1441,11 +1450,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 ); @@ -1459,6 +1469,7 @@ void AutomationEditor::paintEvent( QPaintEvent * _pe ) grid_height ); // draw vertical raster + QColor lineColor = QColor( gridColor() ); if( m_pattern ) { int tick, x; @@ -1474,7 +1485,8 @@ void AutomationEditor::paintEvent( QPaintEvent * _pe ) x<=width(); tick += quantization(), x = xCoordOfTick( tick ) ) { - p.setPen( QColor( 0x2F, 0x2F, 0x2F ) ); + lineColor.setAlpha( 80 ); + p.setPen( lineColor ); p.drawLine( x, grid_bottom, x, x_line_end ); } // Then beat grid @@ -1485,7 +1497,8 @@ void AutomationEditor::paintEvent( QPaintEvent * _pe ) x<=width(); tick += ticksPerBeat, x = xCoordOfTick( tick ) ) { - p.setPen( QColor( 0x5F, 0x5F, 0x5F ) ); + lineColor.setAlpha( 160 ); + p.setPen( lineColor ); p.drawLine( x, grid_bottom, x, x_line_end ); } // and finally bars @@ -1494,14 +1507,16 @@ void AutomationEditor::paintEvent( QPaintEvent * _pe ) 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 ); @@ -1522,11 +1537,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 @@ -1564,7 +1581,7 @@ void AutomationEditor::paintEvent( QPaintEvent * _pe ) if( time_map.size() > 0 ) { timeMap::iterator it = time_map.begin(); - p.setPen( QColor( 0xCF, 0xD9, 0xFF ) ); + p.setPen( graphColor() ); while( it+1 != time_map.end() ) { // skip this section if it occurs completely before the @@ -1633,7 +1650,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, From 7a19654ab9bb3cf962a86cf0218dfdb2ed07a948 Mon Sep 17 00:00:00 2001 From: Vesa Date: Sat, 31 May 2014 04:05:58 +0300 Subject: [PATCH 3/3] AutomationEditor - fix previous --- data/themes/default/style.css | 2 +- src/gui/AutomationEditor.cpp | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/data/themes/default/style.css b/data/themes/default/style.css index 1794895b6..239f08f97 100644 --- a/data/themes/default/style.css +++ b/data/themes/default/style.css @@ -18,7 +18,7 @@ AutomationEditor { color: #e0e0e0; qproperty-vertexColor: #ff77af; qproperty-gridColor: #808080; - qproperty-graphColor: #cfd9ff; + qproperty-graphColor: #99afff; qproperty-scaleColor: rgb( 32, 32, 32 ); } diff --git a/src/gui/AutomationEditor.cpp b/src/gui/AutomationEditor.cpp index 17e8ba6e3..2f1577793 100644 --- a/src/gui/AutomationEditor.cpp +++ b/src/gui/AutomationEditor.cpp @@ -1370,11 +1370,9 @@ inline void AutomationEditor::drawAutomationPoint( QPainter & p, timeMap::iterat int x = xCoordOfTick( it.key() ); int y = yCoordOfLevel( it.value() ); const int outerRadius = qBound( 2, ( m_ppt * quantization() ) / 576, 5 ); // man, getting this calculation right took forever - const int innerRadius = outerRadius - 1; - p.setBrush( QBrush( vertexColor().lighter( 200 ) ) ); - p.drawEllipse( x - outerRadius, y - outerRadius, outerRadius * 2, outerRadius * 2 ); + p.setPen( QPen( vertexColor().lighter( 200 ) ) ); p.setBrush( QBrush( vertexColor() ) ); - p.drawEllipse( x - innerRadius, y - innerRadius, innerRadius * 2, innerRadius * 2 ); + p.drawEllipse( x - outerRadius, y - outerRadius, outerRadius * 2, outerRadius * 2 ); } @@ -1580,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( graphColor() ); + timeMap::iterator it = time_map.begin(); while( it+1 != time_map.end() ) { // skip this section if it occurs completely before the @@ -1618,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 ); } @@ -1770,7 +1768,7 @@ 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 );