diff --git a/beclient.cpp b/beclient.cpp index 331a831025..fdf979703e 100644 --- a/beclient.cpp +++ b/beclient.cpp @@ -52,10 +52,6 @@ BeClient::BeClient( Workspace *ws, WId w, QWidget *parent, const char *name ) { create_pixmaps(); - QFont f = font(); - f.setBold( TRUE ); - setFont( f ); - QGridLayout* g = new QGridLayout( this, 0, 0, 2 ); g->addRowSpacing(1, 2); g->setRowStretch( 2, 10 ); @@ -75,6 +71,11 @@ BeClient::BeClient( Workspace *ws, WId w, QWidget *parent, const char *name ) hb->addStretch(); + aFrameGrp = makeColorGroup(options->color(Options::Frame, true)); + iFrameGrp = makeColorGroup(options->color(Options::Frame, false)); + aTitleGrp = makeColorGroup(options->color(Options::TitleBar, true)); + iTitleGrp = makeColorGroup(options->color(Options::TitleBar, false)); + } @@ -111,25 +112,27 @@ void BeClient::captionChange( const QString& ) void BeClient::paintEvent( QPaintEvent* ) { QPainter p( this ); - QRect bar ( 0, 0, titlebar->geometry().right()+1, titlebar->geometry().bottom() ); - qDrawWinPanel( &p, 0, bar.bottom()+2, width(), height() - bar.bottom()-2, colorGroup(), FALSE ); - qDrawWinPanel( &p, 2, bar.bottom()+4, width()-4, height() - bar.bottom()-6, colorGroup(), TRUE ); + QRect bar ( 0, 0, titlebar->geometry().right()+1, + titlebar->geometry().bottom() ); + qDrawWinPanel( &p, 0, bar.bottom()+2, width(), height() - bar.bottom()-2, + isActive() ? aFrameGrp : iFrameGrp, FALSE ); + qDrawWinPanel( &p, 2, bar.bottom()+4, width()-4, height() - bar.bottom()-6, + isActive() ? aFrameGrp : iFrameGrp, TRUE ); QRect t = titlebar->geometry(); bar.setBottom( bar.bottom() + 3 ); p.setClipRect( bar ); bar.setBottom( bar.bottom() + 2 ); - if ( isActive() ) { - QPalette pal( QColor(248,204,0) ); - qDrawWinPanel( &p, bar, pal.normal(), FALSE, &pal.brush(QPalette::Normal, QColorGroup::Background ) ); - } - else - qDrawWinPanel( &p, bar, colorGroup(), FALSE, &colorGroup().brush( QColorGroup::Background ) ); + qDrawWinPanel( &p, bar, isActive() ? aTitleGrp : iTitleGrp, FALSE, + isActive() ? &aTitleGrp.brush(QColorGroup::Background) : + &iTitleGrp.brush(QColorGroup::Background)); p.setClipping( FALSE ); p.drawPixmap( t.right() - 20, t.center().y()-8, *size_pix ); p.drawPixmap( t.left() +4, t.center().y()-miniIcon().height()/2, miniIcon() ); t.setLeft( t.left() + 20 +10); + p.setPen(options->color(Options::Font, isActive())); + p.setFont(options->font(isActive())); p.drawText( t, AlignLeft|AlignVCenter, caption() ); } @@ -211,3 +214,10 @@ void BeClient::mouseDoubleClickEvent( QMouseEvent * e ) setShade( !isShade() ); workspace()->requestFocus( this ); } + +QColorGroup BeClient::makeColorGroup(const QColor &bg, const QColor &fg) +{ + return(QColorGroup( fg, bg, bg.light(150), bg.dark(), + bg.dark(120), fg, + QApplication::palette().normal().base())); +} diff --git a/beclient.h b/beclient.h index 7437b0680e..de2f174288 100644 --- a/beclient.h +++ b/beclient.h @@ -1,6 +1,7 @@ #ifndef BECLIENT_H #define BECLIENT_H #include "client.h" +#include class QToolButton; class QLabel; class QSpacerItem; @@ -14,6 +15,7 @@ public: ~BeClient(); protected: + QColorGroup makeColorGroup(const QColor &bg, const QColor &fg=Qt::white); void resizeEvent( QResizeEvent* ); void paintEvent( QPaintEvent* ); void mousePressEvent( QMouseEvent * ); @@ -30,6 +32,7 @@ protected: private: QSpacerItem* titlebar; void doShape(); + QColorGroup aFrameGrp, iFrameGrp, aTitleGrp, iTitleGrp; }; diff --git a/options.cpp b/options.cpp index bd832db513..c1c5c10f97 100644 --- a/options.cpp +++ b/options.cpp @@ -1,7 +1,81 @@ #include "options.h" +#include +#include +#include +#include +// increment this when you add a color type (mosfet) +#define KWINCOLORS 8 Options::Options(){ + reload(); +} + +const QColor& Options::color(ColorType type, bool active) +{ + return(colors[type + (active ? 0 : KWINCOLORS)]); +} + +const QFont& Options::font(bool active) +{ + return(active ? activeFont : inactiveFont); +} + + +void Options::reload() +{ focusPolicy = ClickToFocus; resizeMode = Opaque; moveMode = Transparent;//HalfTransparent; + + QPalette pal = QApplication::palette(); + KConfig *config = KGlobal::config(); + config->setGroup("WM"); + + // normal colors + colors[Frame] = Qt::lightGray; + colors[Frame] = config->readColorEntry("frame", &colors[Frame]); + colors[Handle] = config->readColorEntry("handle", &colors[Frame]); + colors[ButtonBg] = config->readColorEntry("buttonBackground", + &colors[Frame]); + colors[ButtonBlend] = config->readColorEntry("buttonBlend", + &colors[ButtonBg]); + colors[TitleBar] = Qt::darkBlue; + colors[TitleBar] = config->readColorEntry("activeBackground", + &colors[TitleBar]); + colors[TitleBlend] = config->readColorEntry("activeBlend", + &colors[TitleBar]); + + colors[Font] = Qt::white; + colors[Font] = config->readColorEntry("activeForeground", &colors[Font]); + colors[ButtonFg] = Qt::lightGray; + colors[ButtonFg] = config->readColorEntry("buttonForeground", + &colors[ButtonFg]); + + // inactive + colors[Frame+KWINCOLORS] = colors[Frame]; + colors[Frame+KWINCOLORS] = + config->readColorEntry("inactiveFrame", &colors[Frame+KWINCOLORS]); + colors[Handle+KWINCOLORS] = + config->readColorEntry("inactiveHandle", &colors[Frame+KWINCOLORS]); + colors[TitleBar+KWINCOLORS] = Qt::darkGray; + colors[TitleBar+KWINCOLORS] = config-> + readColorEntry("inactiveBackground", &colors[TitleBar+KWINCOLORS]); + colors[TitleBlend+KWINCOLORS] = + config->readColorEntry("inactiveBlend", &colors[TitleBar+KWINCOLORS]); + colors[ButtonBg+KWINCOLORS] = + config->readColorEntry("inactiveButtonBackground", + &colors[Frame+KWINCOLORS]); + colors[ButtonBlend+KWINCOLORS] = + config->readColorEntry("inactiveButtonBlend", + &colors[ButtonBg+KWINCOLORS]); + + colors[Font+KWINCOLORS] = Qt::lightGray; + colors[Font+KWINCOLORS] = config->readColorEntry("inactiveForeground", + &colors[Font+KWINCOLORS]); + colors[ButtonFg+KWINCOLORS] = config-> + readColorEntry("inactiveButtonForeground", &colors[ButtonFg]); + + activeFont = QFont("Helvetica", 12, QFont::Bold); + activeFont = config->readFontEntry("activeFont", &activeFont); + inactiveFont = config->readFontEntry("inactiveFont", &activeFont); } diff --git a/options.h b/options.h index bb509ef1eb..dd6b2095a8 100644 --- a/options.h +++ b/options.h @@ -1,6 +1,8 @@ #ifndef OPTIONS_H #define OPTIONS_H +#include +#include class Options { public: @@ -33,15 +35,38 @@ public: FocusPolicy focusPolicy; enum MoveResizeMode { Transparent, Opaque, HalfTransparent }; - + + /** + * Basic color types that should be recognized by all decoration styles. + * Not all styles have to implement all the colors, but for the ones that + * are implemented you should retrieve them here. + */ + // increment KWINCOLORS in options.cpp if you add something (mosfet) + enum ColorType{TitleBar=0, TitleBlend, Font, ButtonFg, ButtonBg, + ButtonBlend, Frame, Handle}; + MoveResizeMode resizeMode; MoveResizeMode moveMode; bool focusPolicyIsReasonable() { - return focusPolicy == ClickToFocus || focusPolicy == FocusFollowsMouse; + return focusPolicy == ClickToFocus || focusPolicy == FocusFollowsMouse; } + /** + * Return the color for the given decoration. + */ + const QColor& color(ColorType type, bool active=true); + /** + * Return the active or inactive decoration font. + */ + const QFont& font(bool active=true); + // When restarting is implemented this should get called (mosfet). + void reload(); + Options(); +protected: + QFont activeFont, inactiveFont; + QColor colors[16]; }; extern Options* options; diff --git a/stdclient.cpp b/stdclient.cpp index 73503bf63d..09c2cdd1a4 100644 --- a/stdclient.cpp +++ b/stdclient.cpp @@ -7,6 +7,7 @@ #include #include #include "workspace.h" +#include "options.h" static const char * close_xpm[] = { @@ -190,9 +191,6 @@ StdClient::StdClient( Workspace *ws, WId w, QWidget *parent, const char *name ) { create_pixmaps(); - QFont f = font(); - f.setBold( TRUE ); - setFont( f ); QGridLayout* g = new QGridLayout( this, 0, 0, 2 ); g->setRowStretch( 1, 10 ); @@ -242,6 +240,10 @@ StdClient::StdClient( Workspace *ws, WId w, QWidget *parent, const char *name ) button[5]->setIconSet( *close_pix ); connect( button[5], SIGNAL( clicked() ), this, ( SLOT( closeWindow() ) ) ); + aFrameGrp = makeColorGroup(options->color(Options::Frame, true)); + iFrameGrp = makeColorGroup(options->color(Options::Frame, false)); + aTitleGrp = makeColorGroup(options->color(Options::TitleBar, true)); + iTitleGrp = makeColorGroup(options->color(Options::TitleBar, false)); } @@ -297,17 +299,18 @@ void StdClient::paintEvent( QPaintEvent* ) QRegion r = rect(); r = r.subtract( t ); p.setClipRegion( r ); - qDrawWinPanel( &p, rect(), colorGroup() ); + qDrawWinPanel( &p, rect(), isActive()? aFrameGrp : iFrameGrp ); p.setClipping( FALSE ); - p.fillRect( t, isActive()?darkBlue:gray ); + p.fillRect( t, options->color(Options::TitleBar, isActive())); qDrawShadePanel( &p, t.x(), t.y(), t.width(), t.height(), - colorGroup(), TRUE ); + isActive() ? aTitleGrp : iTitleGrp, TRUE ); t.setTop( 2 ); t.setLeft( t.left() + 4 ); t.setRight( t.right() - 2 ); - p.setPen( colorGroup().light() ); + p.setPen(options->color(Options::Font, isActive())); + p.setFont(options->font(isActive())); p.drawText( t, AlignLeft|AlignVCenter, caption() ); } @@ -332,3 +335,10 @@ void StdClient::iconChange() button[0]->setIconSet( miniIcon() ); button[0]->repaint( FALSE ); } + +QColorGroup StdClient::makeColorGroup(const QColor &bg, const QColor &fg) +{ + return(QColorGroup( fg, bg, bg.light(150), bg.dark(), + bg.dark(120), fg, + QApplication::palette().normal().base())); +} diff --git a/stdclient.h b/stdclient.h index 7b75757bec..9877e851ec 100644 --- a/stdclient.h +++ b/stdclient.h @@ -4,6 +4,7 @@ class QToolButton; class QLabel; class QSpacerItem; +class QColorGroup; class StdClient : public Client { @@ -11,14 +12,13 @@ class StdClient : public Client public: StdClient( Workspace *ws, WId w, QWidget *parent=0, const char *name=0 ); ~StdClient(); - protected: void resizeEvent( QResizeEvent* ); void paintEvent( QPaintEvent* ); void mouseDoubleClickEvent( QMouseEvent * ); - void init(); + QColorGroup makeColorGroup(const QColor &bg, const QColor &fg=Qt::white); void captionChange( const QString& name ); void iconChange(); void maximizeChange( bool ); @@ -27,6 +27,7 @@ protected: private: QToolButton* button[6]; QSpacerItem* titlebar; + QColorGroup aFrameGrp, iFrameGrp, aTitleGrp, iTitleGrp; };