From dffaa6abe05178b29b5d5f1d69db07de266c8efa Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Thu, 16 Jan 2014 23:39:54 +0100 Subject: [PATCH 1/7] LmmsStyle: initial port of scrollbar drawing code from CusisStyle Colors still need to be made configurable via CSS and tuned for the default theme. --- include/lmms_style.h | 38 +++ src/gui/lmms_style.cpp | 585 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 622 insertions(+), 1 deletion(-) diff --git a/include/lmms_style.h b/include/lmms_style.h index 3cf0fe7e0..8786c3492 100644 --- a/include/lmms_style.h +++ b/include/lmms_style.h @@ -33,6 +33,34 @@ class lmmsStyle : public QPlastiqueStyle { public: + enum ColorRole + { + AutomationBarFill, + AutomationBarValue, + AutomationSelectedBarFill, + AutomationCrosshair, + PianoRollStepNote, + PianoRollSelectedNote, + PianoRollDefaultNote, + PianoRollFrozenNote, + PianoRollMutedNote, + PianoRollEditHandle, + PianoRollVolumeLevel, + PianoRollPanningLevel, + PianoRollSelectedLevel, + TimelineForecolor, + StandardGraphLine, + StandardGraphHandle, + StandardGraphHandleBorder, + StandardGraphCrosshair, + TextFloatForecolor, + TextFloatFill, + VisualizationLevelLow, + VisualizationLevelMid, + VisualizationLevelPeak, + NumColorRoles + }; + lmmsStyle(); virtual ~lmmsStyle() { @@ -40,6 +68,8 @@ public: virtual QPalette standardPalette( void ) const; + virtual void drawControl( ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const; + virtual void drawComplexControl( ComplexControl control, const QStyleOptionComplex * option, @@ -54,6 +84,14 @@ public: const QStyleOption * option = 0, const QWidget * widget = 0 ) const; + QSize sizeFromContents( ContentsType type, const QStyleOption* option, const QSize& size, const QWidget* widget ) const; + QRect subControlRect( ComplexControl control, const QStyleOptionComplex *option, SubControl subControl, const QWidget *widget ) const; + +private: + QImage colorizeXpm( const char * const * xpm, const QBrush& fill ) const; + void hoverColors( bool sunken, bool hover, bool active, QColor& color, QColor& blend ) const; + QColor m_colors[ lmmsStyle::NumColorRoles ]; + } ; #endif diff --git a/src/gui/lmms_style.cpp b/src/gui/lmms_style.cpp index 663454f9f..eb235e129 100644 --- a/src/gui/lmms_style.cpp +++ b/src/gui/lmms_style.cpp @@ -1,6 +1,6 @@ /* * lmms_style.cpp - the graphical style used by LMMS to create a consistent - * interface + * interface * * Copyright (c) 2007-2008 Tobias Doerffel * @@ -28,11 +28,192 @@ #include #include #include +#include #include #include "lmms_style.h" +const int BUTTON_LENGTH = 24; + +static const char * const s_scrollbarArrowUpXpm[] = { + "7 6 8 1", + " g None", + ". g #000000", + "+ g #101010", + "@ g #A0A0A0", + "# g #C0C0C0", + "$ g #FFFFFF", + "% g #808080", + "& g #202020", + "..+@+..", + "..#$#..", + ".%$$$%.", + "&$$$$$&", + "@$$$$$@", + "@#####@"}; + +static const char * const s_scrollbarArrowRightXpm[] = { + "6 7 8 1", + " c None", + ". c #A0A0A0", + "+ c #202020", + "@ c #000000", + "# c #C0C0C0", + "$ c #FFFFFF", + "% c #808080", + "& c #101010", + "..+@@@", + "#$$%@@", + "#$$$#&", + "#$$$$.", + "#$$$#&", + "#$$%@@", + "..+@@@"}; + +static const char * const s_scrollbarArrowDownXpm[] = { + "7 6 8 1", + " g None", + ". g #000000", + "+ g #101010", + "@ g #A0A0A0", + "# g #C0C0C0", + "$ g #FFFFFF", + "% g #808080", + "& g #202020", + "@#####@", + "@$$$$$@", + "&$$$$$&", + ".%$$$%.", + "..#$#..", + "..+@+.."}; + +static const char * const s_scrollbarArrowLeftXpm[] = { + "6 7 8 1", + " g None", + ". g #000000", + "+ g #202020", + "@ g #A0A0A0", + "# g #808080", + "$ g #FFFFFF", + "% g #C0C0C0", + "& g #101010", + "...+@@", + "..#$$%", + "&%$$$%", + "@$$$$%", + "&%$$$%", + "..#$$%", + "...+@@"}; + + + +QLinearGradient getGradient( const QColor & _col, const QRectF & _rect ) +{ + QLinearGradient g( _rect.topLeft(), _rect.bottomLeft() ); + + qreal hue = _col.hueF(); + qreal value = _col.valueF(); + qreal saturation = _col.saturationF(); + + QColor c = _col; + c.setHsvF( hue, 0.42 * saturation, 0.98 * value ); // TODO: pattern: 1.08 + g.setColorAt( 0, c ); + c.setHsvF( hue, 0.58 * saturation, 0.95 * value ); // TODO: pattern: 1.05 + g.setColorAt( 0.25, c ); + c.setHsvF( hue, 0.70 * saturation, 0.93 * value ); // TODO: pattern: 1.03 + g.setColorAt( 0.5, c ); + + c.setHsvF( hue, 0.95 * saturation, 0.9 * value ); + g.setColorAt( 0.501, c ); + c.setHsvF( hue * 0.95, 0.95 * saturation, 0.95 * value ); + g.setColorAt( 0.75, c ); + c.setHsvF( hue * 0.90, 0.95 * saturation, 1 * value ); + g.setColorAt( 1.0, c ); + + return g; +} + + + +QLinearGradient darken( const QLinearGradient & _gradient ) +{ + QGradientStops stops = _gradient.stops(); + for (int i = 0; i < stops.size(); ++i) { + QColor color = stops.at(i).second; + stops[i].second = color.lighter(133); + } + + QLinearGradient g = _gradient; + g.setStops(stops); + return g; +} + + + +void drawPath( QPainter *p, const QPainterPath &path, + const QColor &col, const QColor &borderCol, + bool dark = false ) +{ + const QRectF pathRect = path.boundingRect(); + + const QLinearGradient baseGradient = getGradient(col, pathRect); + const QLinearGradient darkGradient = darken(baseGradient); + + p->setOpacity(0.25); + + // glow + if (dark) + p->strokePath(path, QPen(darkGradient, 4)); + else + p->strokePath(path, QPen(baseGradient, 4)); + + p->setOpacity(1.0); + + // fill + if (dark) + p->fillPath(path, darkGradient); + else + p->fillPath(path, baseGradient); + + // TODO: Remove?? + /* + QLinearGradient g(pathRect.topLeft(), pathRect.topRight()); + g.setCoordinateMode(QGradient::ObjectBoundingMode); + + p->setOpacity(0.2); + p->fillPath(path, g);*/ + // END: Remove?? + + p->setOpacity(0.5); + + // highlight (bb) + if (dark) + p->strokePath(path, QPen(borderCol.lighter(133), 2)); + else + p->strokePath(path, QPen(borderCol, 2)); +} + + + +static QString getCacheKey( const QString & _key, + const QStyleOption * _option, const QSize & _size ) +{ + QString tmp; + const QStyleOptionComplex *complexOption = + qstyleoption_cast ( _option ); + tmp.sprintf( "%s,%d,%d,%d,%lld,%dx%d", + _key.toLatin1().constData(), + uint( _option->state ), + complexOption ? uint( complexOption->activeSubControls ) : uint( 0 ), + _option->direction, + _option->palette.cacheKey(), + _size.width(), + _size.height() ); + return tmp; +} + + lmmsStyle::lmmsStyle() : QPlastiqueStyle() { @@ -81,6 +262,194 @@ QPalette lmmsStyle::standardPalette( void ) const +void lmmsStyle::drawControl( ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const +{ + + switch( element ) + { + case CE_ScrollBarAddLine: + if( const QStyleOptionSlider * scrollBar = qstyleoption_cast( option ) ) + { + + bool horizontal = scrollBar->orientation == Qt::Horizontal; + bool isEnabled = scrollBar->state & State_Enabled; + bool sunken = scrollBar->state & State_Sunken; + bool hover = scrollBar->state & State_MouseOver; + + QString pixmapName = getCacheKey( QLatin1String( "ScrollBarAddLine" ), option, option->rect.size() ); + + QPixmap cache; + if( !QPixmapCache::find( pixmapName, cache ) ) + { + cache = QPixmap( option->rect.size() ); + QPainter cachePainter( &cache ); + + cache.fill( QColor( 48, 48, 48 ) ); + QColor sliderColor; + QColor blurColor; + hoverColors(sunken, hover, + scrollBar->activeSubControls & SC_ScrollBarAddLine && isEnabled, + sliderColor, blurColor); + + int scrollBarExtent = pixelMetric( PM_ScrollBarExtent, option, widget ); + cachePainter.setPen( QPen( sliderColor, 0 ) ); + if( horizontal ) + { + int r = cache.rect().right(); + cachePainter.fillRect(0, 2, BUTTON_LENGTH-2, + scrollBarExtent-4, sliderColor); + + cachePainter.drawLine( r, 4, r, scrollBarExtent - 5 ); + cachePainter.drawLine( r - 1, 3, r - 1, scrollBarExtent - 4 ); + + const QPointF points[4] = { + QPoint( r, 3 ), QPoint( r, scrollBarExtent - 4 ), + QPoint( r - 1, 2 ), QPoint( r - 1, scrollBarExtent - 3 )}; + + cachePainter.setPen( QPen( blurColor, 0 ) ); + cachePainter.drawPoints( points, 4 ); + + QImage arrow = colorizeXpm( s_scrollbarArrowRightXpm, option->palette.foreground().color() ); + if( ( scrollBar->activeSubControls & SC_ScrollBarAddLine ) && sunken ) + { + cachePainter.translate( 1, 1 ); + } + cachePainter.drawImage( cache.rect().center() - QPoint( 3, 3 ), arrow ); + } + else + { + int b = cache.rect().bottom(); + cachePainter.fillRect( 2, 0, scrollBarExtent - 4, BUTTON_LENGTH - 2, sliderColor ); + cachePainter.drawLine( 4, b, scrollBarExtent - 5, b ); + cachePainter.drawLine( 3, b - 1, scrollBarExtent - 4, b - 1 ); + + const QPointF points[4] = { + QPoint( 3, b ), QPoint( scrollBarExtent - 4, b ), + QPoint( 2, b - 1 ), QPoint( scrollBarExtent - 3, b - 1 )}; + + cachePainter.setPen( QPen( blurColor, 0 ) ); + cachePainter.drawPoints( points, 4 ); + + QImage arrow = colorizeXpm( s_scrollbarArrowDownXpm, option->palette.foreground().color() ); + if( ( scrollBar->activeSubControls & SC_ScrollBarAddLine ) && sunken ) + { + cachePainter.translate( 1, 1 ); + } + cachePainter.drawImage( cache.rect().center() - QPoint( 3, 3 ), arrow ); + } + QPixmapCache::insert( pixmapName, cache ); + } + painter->drawPixmap( option->rect.topLeft(), cache ); + + } + break; + + case CE_ScrollBarSubLine: + if(const QStyleOptionSlider *scrollBar = qstyleoption_cast( option ) ) + { + bool horizontal = scrollBar->orientation == Qt::Horizontal; + bool isEnabled = scrollBar->state & State_Enabled; + bool sunken = scrollBar->state & State_Sunken; + bool hover = scrollBar->state & State_MouseOver; + + QString pixmapName = getCacheKey( QLatin1String( "ScrollBarSubLine" ), option, option->rect.size() ); + QPixmap cache; + if( !QPixmapCache::find( pixmapName, cache ) ) + { + cache = QPixmap( option->rect.size() ); + QPainter cachePainter( &cache ); + + cache.fill( QColor( 48, 48, 48 ) ); // TODO: Fill with CSS background + QColor sliderColor; + QColor blurColor; + hoverColors(sunken, hover, + scrollBar->activeSubControls & SC_ScrollBarSubLine && isEnabled, + sliderColor, blurColor); + + int scrollBarExtent = pixelMetric( PM_ScrollBarExtent, option, widget ); + cachePainter.setPen( QPen( sliderColor, 0 ) ); + if( horizontal ) + { + cachePainter.fillRect( 2, 2, BUTTON_LENGTH - 2, scrollBarExtent - 4, sliderColor ); + cachePainter.drawLine( 0, 4, 0, scrollBarExtent - 5 ); + cachePainter.drawLine( 1, 3, 1, scrollBarExtent - 4 ); + + const QPointF points[4] = { + QPoint( 0, 3 ), QPoint( 0, scrollBarExtent - 4 ), + QPoint( 1, 2 ), QPoint( 1, scrollBarExtent - 3 )}; + + cachePainter.setPen( QPen( blurColor, 0 ) ); + cachePainter.drawPoints( points, 4 ); + + QImage arrow = colorizeXpm( s_scrollbarArrowLeftXpm, option->palette.foreground().color() ); + if( ( scrollBar->activeSubControls & SC_ScrollBarSubLine ) && sunken ) + { + cachePainter.translate( 1, 1 ); + } + cachePainter.drawImage( cache.rect().center() - QPoint( 3, 3 ), arrow ); + } + else + { + cachePainter.fillRect( 2, 2, scrollBarExtent - 4, BUTTON_LENGTH - 2, sliderColor ); + cachePainter.drawLine( 4, 0, scrollBarExtent - 5, 0 ); + cachePainter.drawLine( 3, 1, scrollBarExtent - 4, 1 ); + + const QPointF points[4] = { + QPoint( 3, 0 ), QPoint( scrollBarExtent - 4, 0 ), + QPoint( 2, 1 ), QPoint( scrollBarExtent - 3, 1 )}; + + cachePainter.setPen( QPen( blurColor, 0 ) ); + cachePainter.drawPoints( points, 4 ); + + QImage arrow = colorizeXpm( s_scrollbarArrowUpXpm, option->palette.foreground().color() ); + if( ( scrollBar->activeSubControls & SC_ScrollBarSubLine ) && sunken ) + { + cachePainter.translate( 1, 1 ); + } + cachePainter.drawImage( cache.rect().center() - QPoint( 3, 3 ), arrow ); + } + QPixmapCache::insert( pixmapName, cache ); + } + painter->drawPixmap( option->rect.topLeft(), cache ); + + } + break; + + case CE_ScrollBarSubPage: + case CE_ScrollBarAddPage: + break; + + case CE_ScrollBarSlider: + if( const QStyleOptionSlider* scrollBar = qstyleoption_cast( option ) ) + { + bool horizontal = scrollBar->orientation == Qt::Horizontal; + bool isEnabled = scrollBar->state & State_Enabled; + bool sunken = scrollBar->state & State_Sunken; + bool hover = scrollBar->state & State_MouseOver; + + QColor sliderColor, blendColor; + hoverColors( sunken, hover, (scrollBar->activeSubControls & SC_ScrollBarSlider) && isEnabled, sliderColor, blendColor); + + QRect rc = scrollBar->rect; + if( horizontal ) + { + painter->fillRect( rc.left(), rc.top() + 2, rc.width(), rc.height() - 4, sliderColor ); + } + else + { + painter->fillRect( rc.left() + 2, rc.top(), rc.width() - 4, rc.height(), sliderColor ); + } + } + break; + + default: + QPlastiqueStyle::drawControl( element, option, painter, widget ); + break; + } +} + + + void lmmsStyle::drawComplexControl( ComplexControl control, const QStyleOptionComplex * option, QPainter *painter, @@ -106,6 +475,12 @@ void lmmsStyle::drawComplexControl( ComplexControl control, return; } } + else if( control == CC_ScrollBar ) + { + QColor background = QColor( 48, 48, 48 ); + painter->fillRect( option->rect, background ); + + } QPlastiqueStyle::drawComplexControl( control, option, painter, widget ); } @@ -251,3 +626,211 @@ int lmmsStyle::pixelMetric( PixelMetric _metric, const QStyleOption * _option, } // QStyle::SH_TitleBar_NoBorder + +QSize lmmsStyle::sizeFromContents( ContentsType type, const QStyleOption* option, const QSize& size, const QWidget* widget ) const +{ + if( type == CT_ScrollBar ) + { + if( const QStyleOptionSlider * scrollBar = qstyleoption_cast( option ) ) + { + int scrollBarExtent = pixelMetric( PM_ScrollBarExtent, option, widget ); + int scrollBarSliderMinimum = pixelMetric( PM_ScrollBarSliderMin, option, widget ); + if( scrollBar->orientation == Qt::Horizontal ) + { + return QSize( BUTTON_LENGTH * 2 + scrollBarSliderMinimum, scrollBarExtent ); + } + else + { + return QSize( scrollBarExtent, BUTTON_LENGTH * 2 + scrollBarSliderMinimum ); + } + } + } + + return QPlastiqueStyle::sizeFromContents( type, option, size, widget ); +} + + +QRect lmmsStyle::subControlRect( ComplexControl control, const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const +{ + QRect rect = QPlastiqueStyle::subControlRect( control, option, subControl, widget ); + + switch( control ) + { + case CC_ScrollBar: + if( const QStyleOptionSlider* scrollBar = qstyleoption_cast( option ) ) + { + int scrollBarExtent = pixelMetric( PM_ScrollBarExtent, scrollBar, widget ); + int sliderMaxLength = ( + ( scrollBar->orientation == Qt::Horizontal ) ? + scrollBar->rect.width() : + scrollBar->rect.height() ) - + ( BUTTON_LENGTH * 2 + 6 ); + int sliderMinLength = pixelMetric( PM_ScrollBarSliderMin, scrollBar, widget ); + int sliderLength; + + // calculate slider length + if( scrollBar->maximum != scrollBar->minimum ) + { + uint valueRange = scrollBar->maximum - scrollBar->minimum; + sliderLength = ( scrollBar->pageStep * sliderMaxLength ) / + ( valueRange + scrollBar->pageStep ); + + if( sliderLength < sliderMinLength || valueRange > ( INT_MAX ) / 2 ) + { + sliderLength = sliderMinLength; + } + if( sliderLength > sliderMaxLength ) + { + sliderLength = sliderMaxLength; + } + } + else + { + sliderLength = sliderMaxLength; + } + + int sliderStart = BUTTON_LENGTH + 3 + sliderPositionFromValue( + scrollBar->minimum, + scrollBar->maximum, + scrollBar->sliderPosition, + sliderMaxLength - sliderLength, + scrollBar->upsideDown ); + + QRect scrollBarRect = scrollBar->rect; + + switch( subControl ) + { + case SC_ScrollBarSubLine: // top/left button + if( scrollBar->orientation == Qt::Horizontal ) + { + rect.setRect( scrollBarRect.left() + 2, scrollBarRect.top(), + BUTTON_LENGTH, scrollBarExtent ); + } + else + { + rect.setRect( scrollBarRect.left(), scrollBarRect.top() + 2, + scrollBarExtent, BUTTON_LENGTH ); + } + break; + + case SC_ScrollBarAddLine: // bottom/right button + if( scrollBar->orientation == Qt::Horizontal ) + { + rect.setRect( scrollBarRect.right() - 1 - BUTTON_LENGTH, + scrollBarRect.top(), BUTTON_LENGTH, scrollBarExtent ); + } + else + { + rect.setRect( scrollBarRect.left(), + scrollBarRect.bottom() - 1 - BUTTON_LENGTH, + scrollBarExtent, BUTTON_LENGTH ); + } + break; + + case SC_ScrollBarSubPage: + if( scrollBar->orientation == Qt::Horizontal ) + { + rect.setRect( scrollBarRect.left() + 2 + BUTTON_LENGTH, + scrollBarRect.top(), + sliderStart - ( scrollBarRect.left() + 2 + BUTTON_LENGTH ), + scrollBarExtent ); + } + else + { + rect.setRect( scrollBarRect.left(), + scrollBarRect.top() + 2 + BUTTON_LENGTH, scrollBarExtent, + sliderStart - ( scrollBarRect.left() + 2 + BUTTON_LENGTH ) ); + } + break; + + case SC_ScrollBarAddPage: + if( scrollBar->orientation == Qt::Horizontal ) + { + rect.setRect( sliderStart + sliderLength, 0, + sliderMaxLength - sliderStart - sliderLength, + scrollBarExtent ); + } + else + rect.setRect( 0, sliderStart + sliderLength, scrollBarExtent, + sliderMaxLength - sliderStart - sliderLength ); + break; + + case SC_ScrollBarGroove: + if( scrollBar->orientation == Qt::Horizontal ) + { + rect = scrollBarRect.adjusted( BUTTON_LENGTH, 0, -BUTTON_LENGTH, 0 ); + } + else + { + rect = scrollBarRect.adjusted( 0, BUTTON_LENGTH, 0, -BUTTON_LENGTH ); + } + break; + + case SC_ScrollBarSlider: + if( scrollBar->orientation == Qt::Horizontal ) + { + rect.setRect( sliderStart, 0, sliderLength, scrollBarExtent ); + } + else + { + rect.setRect( 0, sliderStart, scrollBarExtent, sliderLength ); + } + break; + + default: + break; + } + rect = visualRect( scrollBar->direction, scrollBarRect, rect ); + } + break; + + default: + break; + } + + return rect; +} + + + + +QImage lmmsStyle::colorizeXpm( const char * const * xpm, const QBrush& fill ) const +{ + QImage arrowXpm( xpm ); + QImage arrow( arrowXpm.size(), QImage::Format_ARGB32 ); + QPainter arrowPainter( &arrow ); + arrowPainter.fillRect( arrow.rect(), fill ); + arrowPainter.end(); + arrow.setAlphaChannel( arrowXpm ); + + return arrow; +} + + +void lmmsStyle::hoverColors( bool sunken, bool hover, bool active, QColor& color, QColor& blend ) const +{ + if( active ) + { + if( sunken ) + { + color = QColor( 75, 75, 75 ); + blend = QColor( 65, 65, 65 ); + } + else if( hover ) + { + color = QColor( 100, 100, 100 ); + blend = QColor( 75, 75, 75 ); + } + else + { + color = QColor( 21, 21, 21 ); + blend = QColor( 33, 33, 33 ); + } + } + else + { + color = QColor( 21, 21, 21 ); + blend = QColor( 33, 33, 33 ); + } +} + From bbe686e290dcc59d47792e2e9947346159ee732f Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Thu, 16 Jan 2014 23:45:33 +0100 Subject: [PATCH 2/7] LmmsStyle: adopted new coding style and renamed class --- include/{lmms_style.h => LmmsStyle.h} | 12 +++++------ src/core/main.cpp | 6 +++--- src/gui/FxMixerView.cpp | 1 - src/gui/{lmms_style.cpp => LmmsStyle.cpp} | 26 +++++++++++------------ 4 files changed, 22 insertions(+), 23 deletions(-) rename include/{lmms_style.h => LmmsStyle.h} (90%) rename src/gui/{lmms_style.cpp => LmmsStyle.cpp} (96%) diff --git a/include/lmms_style.h b/include/LmmsStyle.h similarity index 90% rename from include/lmms_style.h rename to include/LmmsStyle.h index 8786c3492..48c48d449 100644 --- a/include/lmms_style.h +++ b/include/LmmsStyle.h @@ -1,8 +1,8 @@ /* - * lmms_style.h - the graphical style used by LMMS to create a consistent + * LmmsStyle.h - the graphical style used by LMMS to create a consistent * interface * - * Copyright (c) 2007-2008 Tobias Doerffel + * Copyright (c) 2007-2014 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -30,7 +30,7 @@ #include -class lmmsStyle : public QPlastiqueStyle +class LmmsStyle : public QPlastiqueStyle { public: enum ColorRole @@ -61,8 +61,8 @@ public: NumColorRoles }; - lmmsStyle(); - virtual ~lmmsStyle() + LmmsStyle(); + virtual ~LmmsStyle() { } @@ -90,7 +90,7 @@ public: private: QImage colorizeXpm( const char * const * xpm, const QBrush& fill ) const; void hoverColors( bool sunken, bool hover, bool active, QColor& color, QColor& blend ) const; - QColor m_colors[ lmmsStyle::NumColorRoles ]; + QColor m_colors[ LmmsStyle::NumColorRoles ]; } ; diff --git a/src/core/main.cpp b/src/core/main.cpp index df7943389..346d76c0e 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -1,7 +1,7 @@ /* * main.cpp - just main.cpp which is starting up app... * - * Copyright (c) 2004-2013 Tobias Doerffel + * Copyright (c) 2004-2014 Tobias Doerffel * Copyright (c) 2012-2013 Paul Giblock

* * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net @@ -58,7 +58,7 @@ #include "config_mgr.h" #include "embed.h" #include "engine.h" -#include "lmms_style.h" +#include "LmmsStyle.h" #include "ImportFilter.h" #include "MainWindow.h" #include "ProjectRenderer.h" @@ -386,7 +386,7 @@ int main( int argc, char * * argv ) if( render_out.isEmpty() ) { // init style and palette - QApplication::setStyle( new lmmsStyle() ); + QApplication::setStyle( new LmmsStyle() ); // init splash screen - this is a bit difficult as we have a // semi-transparent splash-image therefore we first need to grab diff --git a/src/gui/FxMixerView.cpp b/src/gui/FxMixerView.cpp index 07825fa33..8d1b124e0 100644 --- a/src/gui/FxMixerView.cpp +++ b/src/gui/FxMixerView.cpp @@ -42,7 +42,6 @@ #include "gui_templates.h" #include "tooltip.h" #include "pixmap_button.h" -#include "lmms_style.h" diff --git a/src/gui/lmms_style.cpp b/src/gui/LmmsStyle.cpp similarity index 96% rename from src/gui/lmms_style.cpp rename to src/gui/LmmsStyle.cpp index eb235e129..16a244ea7 100644 --- a/src/gui/lmms_style.cpp +++ b/src/gui/LmmsStyle.cpp @@ -1,8 +1,8 @@ /* - * lmms_style.cpp - the graphical style used by LMMS to create a consistent + * LmmsStyle.cpp - the graphical style used by LMMS to create a consistent * interface * - * Copyright (c) 2007-2008 Tobias Doerffel + * Copyright (c) 2007-2014 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -31,7 +31,7 @@ #include #include -#include "lmms_style.h" +#include "LmmsStyle.h" const int BUTTON_LENGTH = 24; @@ -214,7 +214,7 @@ static QString getCacheKey( const QString & _key, } -lmmsStyle::lmmsStyle() : +LmmsStyle::LmmsStyle() : QPlastiqueStyle() { QFile file( "resources:style.css" ); @@ -227,7 +227,7 @@ lmmsStyle::lmmsStyle() : -QPalette lmmsStyle::standardPalette( void ) const +QPalette LmmsStyle::standardPalette( void ) const { QPalette pal = QPlastiqueStyle::standardPalette(); /* pal.setColor( QPalette::Background, QColor( 91, 101, 113 ) ); @@ -262,7 +262,7 @@ QPalette lmmsStyle::standardPalette( void ) const -void lmmsStyle::drawControl( ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const +void LmmsStyle::drawControl( ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { switch( element ) @@ -450,7 +450,7 @@ void lmmsStyle::drawControl( ControlElement element, const QStyleOption* option, -void lmmsStyle::drawComplexControl( ComplexControl control, +void LmmsStyle::drawComplexControl( ComplexControl control, const QStyleOptionComplex * option, QPainter *painter, const QWidget *widget ) const @@ -487,7 +487,7 @@ void lmmsStyle::drawComplexControl( ComplexControl control, -void lmmsStyle::drawPrimitive( PrimitiveElement element, +void LmmsStyle::drawPrimitive( PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { @@ -599,7 +599,7 @@ void lmmsStyle::drawPrimitive( PrimitiveElement element, } -int lmmsStyle::pixelMetric( PixelMetric _metric, const QStyleOption * _option, +int LmmsStyle::pixelMetric( PixelMetric _metric, const QStyleOption * _option, const QWidget * _widget ) const { switch( _metric ) @@ -627,7 +627,7 @@ int lmmsStyle::pixelMetric( PixelMetric _metric, const QStyleOption * _option, // QStyle::SH_TitleBar_NoBorder -QSize lmmsStyle::sizeFromContents( ContentsType type, const QStyleOption* option, const QSize& size, const QWidget* widget ) const +QSize LmmsStyle::sizeFromContents( ContentsType type, const QStyleOption* option, const QSize& size, const QWidget* widget ) const { if( type == CT_ScrollBar ) { @@ -650,7 +650,7 @@ QSize lmmsStyle::sizeFromContents( ContentsType type, const QStyleOption* option } -QRect lmmsStyle::subControlRect( ComplexControl control, const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const +QRect LmmsStyle::subControlRect( ComplexControl control, const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const { QRect rect = QPlastiqueStyle::subControlRect( control, option, subControl, widget ); @@ -794,7 +794,7 @@ QRect lmmsStyle::subControlRect( ComplexControl control, const QStyleOptionCompl -QImage lmmsStyle::colorizeXpm( const char * const * xpm, const QBrush& fill ) const +QImage LmmsStyle::colorizeXpm( const char * const * xpm, const QBrush& fill ) const { QImage arrowXpm( xpm ); QImage arrow( arrowXpm.size(), QImage::Format_ARGB32 ); @@ -807,7 +807,7 @@ QImage lmmsStyle::colorizeXpm( const char * const * xpm, const QBrush& fill ) co } -void lmmsStyle::hoverColors( bool sunken, bool hover, bool active, QColor& color, QColor& blend ) const +void LmmsStyle::hoverColors( bool sunken, bool hover, bool active, QColor& color, QColor& blend ) const { if( active ) { From a183fb25049645347af8c0448d09a9d37478f9ae Mon Sep 17 00:00:00 2001 From: Hannu Haahti Date: Fri, 17 Jan 2014 09:49:35 +0200 Subject: [PATCH 3/7] pitch automation in piano roll doesn't require first point to be 0 --- include/InlineAutomation.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/InlineAutomation.h b/include/InlineAutomation.h index 89f3e9164..70cefbec9 100644 --- a/include/InlineAutomation.h +++ b/include/InlineAutomation.h @@ -52,9 +52,7 @@ public: inline bool hasAutomation() const { return m_autoPattern != NULL && - !typeInfo::isEqual( - m_autoPattern->getTimeMap()[0], - defaultValue() ); + m_autoPattern->getTimeMap().isEmpty() == false; } AutomationPattern * automationPattern() From 3d0749ad67857acbdbfbc63d92ee5087a6895215 Mon Sep 17 00:00:00 2001 From: Hannu Haahti Date: Fri, 17 Jan 2014 09:50:30 +0200 Subject: [PATCH 4/7] points are shown in the correct scale --- src/gui/piano_roll.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/piano_roll.cpp b/src/gui/piano_roll.cpp index 1728b1c03..44f49e680 100644 --- a/src/gui/piano_roll.cpp +++ b/src/gui/piano_roll.cpp @@ -929,7 +929,7 @@ inline void pianoRoll::drawDetuningInfo( QPainter & _p, note * _n, int _x, const float level = it.value(); - int pos_y = (int)( middle_y - level * KEY_LINE_HEIGHT / 10 ); + int pos_y = (int)( middle_y - level * KEY_LINE_HEIGHT ); _p.drawLine( pos_x - 1, pos_y, pos_x + 1, pos_y ); _p.drawLine( pos_x, pos_y - 1, pos_x, pos_y + 1 ); From dfd57530320589d06d8ce44dd3901ab56cf35b8d Mon Sep 17 00:00:00 2001 From: Hannu Haahti Date: Fri, 17 Jan 2014 10:46:52 +0200 Subject: [PATCH 5/7] draw discrete and linear differently --- src/gui/piano_roll.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/gui/piano_roll.cpp b/src/gui/piano_roll.cpp index 44f49e680..39a12611b 100644 --- a/src/gui/piano_roll.cpp +++ b/src/gui/piano_roll.cpp @@ -917,6 +917,9 @@ inline void pianoRoll::drawDetuningInfo( QPainter & _p, note * _n, int _x, int middle_y = _y + KEY_LINE_HEIGHT / 2; _p.setPen( QColor( 0xFF, 0xDF, 0x20 ) ); + int old_x = 0; + int old_y = 0; + timeMap & map = _n->detuning()->automationPattern()->getTimeMap(); for( timeMap::ConstIterator it = map.begin(); it != map.end(); ++it ) { @@ -931,8 +934,26 @@ inline void pianoRoll::drawDetuningInfo( QPainter & _p, note * _n, int _x, int pos_y = (int)( middle_y - level * KEY_LINE_HEIGHT ); + if( old_x != 0 && old_y != 0 ) + { + switch( _n->detuning()->automationPattern()->progressionType() ) + { + case AutomationPattern::DiscreteProgression: + _p.drawLine( old_x, old_y, pos_x, old_y ); + _p.drawLine( pos_x, old_y, pos_x, pos_y ); + break; + case AutomationPattern::CubicHermiteProgression: /* TODO */ + case AutomationPattern::LinearProgression: + _p.drawLine( old_x, old_y, pos_x, pos_y ); + break; + } + } + _p.drawLine( pos_x - 1, pos_y, pos_x + 1, pos_y ); _p.drawLine( pos_x, pos_y - 1, pos_x, pos_y + 1 ); + + old_x = pos_x; + old_y = pos_y; } } From bad3ed60df5179004224645c8ba6375e79f02c35 Mon Sep 17 00:00:00 2001 From: Hannu Haahti Date: Fri, 17 Jan 2014 15:44:43 +0200 Subject: [PATCH 6/7] Prevent piano roll window from being resized to 0px height (http://sourceforge.net/p/lmms/patches/43/) --- src/gui/piano_roll.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/piano_roll.cpp b/src/gui/piano_roll.cpp index 39a12611b..6679120a1 100644 --- a/src/gui/piano_roll.cpp +++ b/src/gui/piano_roll.cpp @@ -618,7 +618,7 @@ pianoRoll::pianoRoll() : if( engine::mainWindow()->workspace() ) { engine::mainWindow()->workspace()->addSubWindow( this ); - parentWidget()->setMinimumWidth( tb_layout->minimumSize().width()+10 ); + parentWidget()->setMinimumSize( tb_layout->minimumSize().width()+10, 200 ); parentWidget()->resize( tb_layout->minimumSize().width()+10, INITIAL_PIANOROLL_HEIGHT ); parentWidget()->hide(); From 4b5b0fa4fa34de216b9853c61b1f7579e273d75c Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Fri, 17 Jan 2014 19:35:14 +0100 Subject: [PATCH 7/7] FxMixer, FxMixerView: cache maximum peak until next display update We lost short peaks because the display update rate usually is much lower than the number of audio buffers processed per second which lead to lost peaks. We mitigate this issue by caching the maximum peak value until the next display update where it is reset. --- src/core/FxMixer.cpp | 15 +++++++++++---- src/gui/FxMixerView.cpp | 9 +++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/core/FxMixer.cpp b/src/core/FxMixer.cpp index 864364cf5..ba76a78c5 100644 --- a/src/core/FxMixer.cpp +++ b/src/core/FxMixer.cpp @@ -123,10 +123,17 @@ void FxMixer::processChannel( fx_ch_t _ch, sampleFrame * _buf ) { m_fxChannels[_ch]->m_fxChain.startRunning(); m_fxChannels[_ch]->m_stillRunning = m_fxChannels[_ch]->m_fxChain.processAudioBuffer( _buf, f ); - m_fxChannels[_ch]->m_peakLeft = engine::mixer()->peakValueLeft( _buf, f ) * - m_fxChannels[_ch]->m_volumeModel.value(); - m_fxChannels[_ch]->m_peakRight = engine::mixer()->peakValueRight( _buf, f ) * - m_fxChannels[_ch]->m_volumeModel.value(); + float peakLeft = engine::mixer()->peakValueLeft( _buf, f ) * m_fxChannels[_ch]->m_volumeModel.value(); + float peakRight = engine::mixer()->peakValueRight( _buf, f ) * m_fxChannels[_ch]->m_volumeModel.value(); + + if( peakLeft > m_fxChannels[_ch]->m_peakLeft ) + { + m_fxChannels[_ch]->m_peakLeft = peakLeft; + } + if( peakRight > m_fxChannels[_ch]->m_peakRight ) + { + m_fxChannels[_ch]->m_peakRight = peakRight; + } } m_fxChannels[_ch]->m_used = true; } diff --git a/src/gui/FxMixerView.cpp b/src/gui/FxMixerView.cpp index 8d1b124e0..02d5fb178 100644 --- a/src/gui/FxMixerView.cpp +++ b/src/gui/FxMixerView.cpp @@ -340,17 +340,18 @@ void FxMixerView::updateFaders() const float fall_off = 1.2; if( m->m_fxChannels[i]->m_peakLeft > opl ) { - m_fxChannelViews[i].m_fader->setPeak_L( - m->m_fxChannels[i]->m_peakLeft ); + m_fxChannelViews[i].m_fader->setPeak_L( m->m_fxChannels[i]->m_peakLeft ); + m->m_fxChannels[i]->m_peakLeft = 0; } else { m_fxChannelViews[i].m_fader->setPeak_L( opl/fall_off ); } + if( m->m_fxChannels[i]->m_peakRight > opr ) { - m_fxChannelViews[i].m_fader->setPeak_R( - m->m_fxChannels[i]->m_peakRight ); + m_fxChannelViews[i].m_fader->setPeak_R( m->m_fxChannels[i]->m_peakRight ); + m->m_fxChannels[i]->m_peakRight = 0; } else {