Initial implementation of LmmsPalette (doesn't work yet)

This commit is contained in:
Vesa
2014-04-10 10:51:06 +03:00
parent b32e602af5
commit 43cb962ae1
3 changed files with 87 additions and 35 deletions

View File

@@ -677,17 +677,17 @@ 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: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}
/* palette information */
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;
}

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,11 +24,58 @@
*/
#ifndef _LMMS_STYLE_H
#define _LMMS_STYLE_H
#ifndef LMMS_STYLE_H
#define LMMS_STYLE_H
#include <QtGui/QPlastiqueStyle>
#define ACCESSMET( read, write ) \
QColor read () \
{ return m_##read ; } \
void write ( const QColor & _c ) \
{ m_##read = QColor( _c ); }
class 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 );
virtual ~LmmsPalette() {};
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 )
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;
};
class LmmsStyle : public QPlastiqueStyle
{
@@ -81,7 +128,7 @@ 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;

View File

@@ -30,6 +30,7 @@
#include <QtGui/QPainter>
#include <QtGui/QPixmapCache>
#include <QtGui/QStyleOption>
#include <QWidget>
#include "LmmsStyle.h"
@@ -195,6 +196,14 @@ void drawPath( QPainter *p, const QPainterPath &path,
}
LmmsPalette::LmmsPalette( QWidget * _parent ) : QWidget( _parent )
{
setStyle( QApplication::style() );
}
LmmsStyle::LmmsStyle() :
QPlastiqueStyle()
{
@@ -210,11 +219,11 @@ LmmsStyle::LmmsStyle() :
QPalette LmmsStyle::standardPalette( void ) const
{
LmmsPalette * lmmspal = new LmmsPalette( NULL );
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 ) );
@@ -225,23 +234,19 @@ QPalette LmmsStyle::standardPalette( void ) const
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 LmmsPalette */
/* 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 ) ) ); };
}
pal.setColor( QPalette::Background, lmmspal->background() );
pal.setColor( QPalette::WindowText, lmmspal->windowText() );
pal.setColor( QPalette::Base, lmmspal->base() );
pal.setColor( QPalette::ButtonText, lmmspal->buttonText() );
pal.setColor( QPalette::BrightText, lmmspal->brightText() );
pal.setColor( QPalette::Text, lmmspal->text() );
pal.setColor( QPalette::Button, lmmspal->button() );
pal.setColor( QPalette::Shadow, lmmspal->shadow() );
pal.setColor( QPalette::Highlight, lmmspal->highlight() );
pal.setColor( QPalette::HighlightedText, lmmspal->highlightedText() );
return( pal );
}