Merge pull request #592 from diizy/palette

LmmsPalette
This commit is contained in:
Tobias Doerffel
2014-04-11 23:53:18 +02:00
6 changed files with 220 additions and 51 deletions

View File

@@ -677,17 +677,18 @@ MonstroView knob {
qproperty-lineWidth: 2.5;
}
/* palette information - each colour definition must be on a single line, and the line must begin with "palette:", with no leading whitespace
* colour codes MUST be of the form #RRGGBB */
/* palette information */
palette:background {color: #5b6571}
palette:windowtext {color: #f0f0f0}
palette:base {color: #808080}
palette:text {color: #e0e0e0}
palette:button {color: #c9c9c9}
palette:shadow {color: #000000}
palette:buttontext {color: #000000}
palette:brighttext {color: #4afd85}
palette:highlight {color: #202020}
palette:highlightedtext {color: #ffffff}
LmmsPalette {
qproperty-background: #5b6571;
qproperty-windowText: #f0f0f0;
qproperty-base: #808080;
qproperty-text: #e0e0e0;
qproperty-button: #c9c9c9;
qproperty-shadow: #000;
qproperty-buttonText: #000;
qproperty-brightText: #4afd85;
qproperty-highlight: #202020;
qproperty-highlightedText: #ffffff;
}

87
include/LmmsPalette.h Normal file
View File

@@ -0,0 +1,87 @@
/*
* LmmsPalette.h - dummy class for fetching palette qproperties from CSS
*
*
* Copyright (c) 2007-2014 Vesa Kivimäki <contact/dot/diizy/at/nbl/dot/fi>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include <QtGui/QWidget>
#include "export.h"
#ifndef LMMSPALETTE_H
#define LMMSPALETTE_H
class EXPORT LmmsPalette : public QWidget
{
Q_OBJECT
Q_PROPERTY( QColor background READ background WRITE setBackground )
Q_PROPERTY( QColor windowText READ windowText WRITE setWindowText )
Q_PROPERTY( QColor base READ base WRITE setBase )
Q_PROPERTY( QColor text READ text WRITE setText )
Q_PROPERTY( QColor button READ button WRITE setButton )
Q_PROPERTY( QColor shadow READ shadow WRITE setShadow )
Q_PROPERTY( QColor buttonText READ buttonText WRITE setButtonText )
Q_PROPERTY( QColor brightText READ brightText WRITE setBrightText )
Q_PROPERTY( QColor highlight READ highlight WRITE setHighlight )
Q_PROPERTY( QColor highlightedText READ highlightedText WRITE setHighlightedText )
public:
LmmsPalette( QWidget * parent, QStyle * stylearg );
virtual ~LmmsPalette();
#define ACCESSMET( read, write ) \
QColor read () const; \
void write ( const QColor & c ); \
ACCESSMET( background, setBackground )
ACCESSMET( windowText, setWindowText )
ACCESSMET( base, setBase )
ACCESSMET( text, setText )
ACCESSMET( button, setButton )
ACCESSMET( shadow, setShadow )
ACCESSMET( buttonText, setButtonText )
ACCESSMET( brightText, setBrightText )
ACCESSMET( highlight, setHighlight )
ACCESSMET( highlightedText, setHighlightedText )
#undef ACCESSMET
QPalette palette() const;
private:
QColor m_background;
QColor m_windowText;
QColor m_base;
QColor m_text;
QColor m_button;
QColor m_shadow;
QColor m_buttonText;
QColor m_brightText;
QColor m_highlight;
QColor m_highlightedText;
};
#endif

View File

@@ -3,7 +3,7 @@
* interface
*
* Copyright (c) 2007-2014 Tobias Doerffel <tobydox/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
@@ -24,12 +24,13 @@
*/
#ifndef _LMMS_STYLE_H
#define _LMMS_STYLE_H
#ifndef LMMS_STYLE_H
#define LMMS_STYLE_H
#include <QtGui/QPlastiqueStyle>
class LmmsStyle : public QPlastiqueStyle
{
public:
@@ -81,17 +82,19 @@ public:
const QWidget *widget = 0 ) const;
virtual int pixelMetric( PixelMetric metric,
const QStyleOption * option = 0,
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;
static QPalette * s_palette;
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

View File

@@ -65,6 +65,7 @@
#include "ProjectRenderer.h"
#include "DataFile.h"
#include "song.h"
#include "LmmsPalette.h"
static inline QString baseName( const QString & _file )
{
@@ -389,7 +390,17 @@ int main( int argc, char * * argv )
if( render_out.isEmpty() )
{
// init style and palette
QApplication::setStyle( new LmmsStyle() );
LmmsStyle * lmmsstyle = new LmmsStyle();
QApplication::setStyle( lmmsstyle );
LmmsPalette * lmmspal = new LmmsPalette( NULL, lmmsstyle );
lmmspal->show(); // necessary to get properties
lmmspal->hide();
QPalette lpal = lmmspal->palette();
QApplication::setPalette( lpal );
LmmsStyle::s_palette = &lpal;
// show splash screen
QSplashScreen splashScreen( embed::getIconPixmap( "splash" ) );

95
src/gui/LmmsPalette.cpp Normal file
View File

@@ -0,0 +1,95 @@
/*
* LmmsPalette.cpp - dummy class for fetching palette qproperties from CSS
*
*
* Copyright (c) 2007-2014 Vesa Kivimäki <contact/dot/diizy/at/nbl/dot/fi>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include <QApplication>
#include <QStyle>
#include "LmmsPalette.h"
#include "LmmsStyle.h"
LmmsPalette::LmmsPalette( QWidget * parent, QStyle * stylearg ) :
QWidget( parent ),
/* sane defaults in case fetching from stylesheet fails*/
m_background( 91, 101, 113 ),
m_windowText( 240, 240, 240 ),
m_base( 128, 128, 128 ),
m_text( 224, 224, 224 ),
m_button( 201, 201, 201 ),
m_shadow( 0,0,0 ),
m_buttonText( 0,0,0 ),
m_brightText( 74, 253, 133 ),
m_highlight( 100, 100, 100 ),
m_highlightedText( 255, 255, 255 )
{
setStyle( stylearg );
stylearg->polish( this );
}
LmmsPalette::~LmmsPalette()
{
}
#define ACCESSMET( read, write ) \
QColor LmmsPalette:: read () const \
{ return m_##read ; } \
void LmmsPalette:: write ( const QColor & c ) \
{ m_##read = QColor( c ); }
ACCESSMET( background, setBackground )
ACCESSMET( windowText, setWindowText )
ACCESSMET( base, setBase )
ACCESSMET( text, setText )
ACCESSMET( button, setButton )
ACCESSMET( shadow, setShadow )
ACCESSMET( buttonText, setButtonText )
ACCESSMET( brightText, setBrightText )
ACCESSMET( highlight, setHighlight )
ACCESSMET( highlightedText, setHighlightedText )
QPalette LmmsPalette::palette() const
{
QPalette pal = QApplication::style()->standardPalette();
pal.setColor( QPalette::Background, background() );
pal.setColor( QPalette::WindowText, windowText() );
pal.setColor( QPalette::Base, base() );
pal.setColor( QPalette::ButtonText, buttonText() );
pal.setColor( QPalette::BrightText, brightText() );
pal.setColor( QPalette::Text, text() );
pal.setColor( QPalette::Button, button() );
pal.setColor( QPalette::Shadow, shadow() );
pal.setColor( QPalette::Highlight, highlight() );
pal.setColor( QPalette::HighlightedText, highlightedText() );
return pal;
}
#include "moc_LmmsPalette.cxx"

View File

@@ -32,7 +32,7 @@
#include <QtGui/QStyleOption>
#include "LmmsStyle.h"
#include "LmmsPalette.h"
const int BUTTON_LENGTH = 24;
@@ -106,7 +106,7 @@ static const char * const s_scrollbarArrowLeftXpm[] = {
"..#$$%",
"...+@@"};
QPalette * LmmsStyle::s_palette = NULL;
QLinearGradient getGradient( const QColor & _col, const QRectF & _rect )
{
@@ -195,6 +195,7 @@ void drawPath( QPainter *p, const QPainterPath &path,
}
LmmsStyle::LmmsStyle() :
QPlastiqueStyle()
{
@@ -202,7 +203,7 @@ LmmsStyle::LmmsStyle() :
file.open( QIODevice::ReadOnly );
qApp->setStyleSheet( file.readAll() );
qApp->setPalette( standardPalette() );
if( s_palette != NULL ) { qApp->setPalette( *s_palette ); }
}
@@ -210,39 +211,10 @@ LmmsStyle::LmmsStyle() :
QPalette LmmsStyle::standardPalette( void ) const
{
if( s_palette != NULL) { return * s_palette; }
QPalette pal = QPlastiqueStyle::standardPalette();
/* sane defaults in case fetching from stylesheet fails*/
pal.setColor( QPalette::Background, QColor( 91, 101, 113 ) );
pal.setColor( QPalette::WindowText, QColor( 240, 240, 240 ) );
pal.setColor( QPalette::Base, QColor( 128, 128, 128 ) );
pal.setColor( QPalette::Text, QColor( 224, 224, 224 ) );
pal.setColor( QPalette::Button, QColor( 201, 201, 201 ) );
pal.setColor( QPalette::Shadow, QColor( 0, 0, 0 ) );
pal.setColor( QPalette::ButtonText, QColor( 0, 0, 0 ) );
pal.setColor( QPalette::BrightText, QColor( 74, 253, 133 ) );
pal.setColor( QPalette::Highlight, QColor( 100, 100, 100 ) );
pal.setColor( QPalette::HighlightedText, QColor( 255, 255, 255 ) );
/* fetch from stylesheet using regexp */
QStringList paletteData = qApp->styleSheet().split( '\n' ).filter( QRegExp( "^palette:*" ) );
foreach( QString s, paletteData )
{
if (s.contains(":background")) { pal.setColor( QPalette::Background, QColor( s.mid( s.indexOf("#"), 7 ) ) ); }
else if (s.contains(":windowtext")) { pal.setColor( QPalette::WindowText, QColor( s.mid( s.indexOf("#"), 7 ) ) ); }
else if (s.contains(":base")) { pal.setColor( QPalette::Base, QColor( s.mid( s.indexOf("#"), 7 ) ) ); }
else if (s.contains(":buttontext")) { pal.setColor( QPalette::ButtonText, QColor( s.mid( s.indexOf("#"), 7 ) ) ); }
else if (s.contains(":brighttext")) { pal.setColor( QPalette::BrightText, QColor( s.mid( s.indexOf("#"), 7 ) ) ); }
else if (s.contains(":text")) { pal.setColor( QPalette::Text, QColor( s.mid( s.indexOf("#"), 7 ) ) ); }
else if (s.contains(":button")) { pal.setColor( QPalette::Button, QColor( s.mid( s.indexOf("#"), 7 ) ) ); }
else if (s.contains(":shadow")) { pal.setColor( QPalette::Shadow, QColor( s.mid( s.indexOf("#"), 7 ) ) ); }
else if (s.contains(":highlightedtext")) { pal.setColor( QPalette::HighlightedText, QColor( s.mid( s.indexOf("#"), 7 ) ) ); }
else if (s.contains(":highlight")) { pal.setColor( QPalette::Highlight, QColor( s.mid( s.indexOf("#"), 7 ) ) ); };
}
return( pal );
}