Might as well make colorgroups static too. Also fixed a memleak

(pixmaps_created was never set to true).

svn path=/trunk/kdebase/kwin/; revision=30498
This commit is contained in:
Daniel M. Duley 1999-10-10 04:25:28 +00:00
parent 92e1e869b1
commit b844f223e2
4 changed files with 64 additions and 33 deletions

View file

@ -38,20 +38,40 @@ static const char * size_xpm[] = {
static QPixmap* size_pix = 0; static QPixmap* size_pix = 0;
static bool pixmaps_created = FALSE; static bool pixmaps_created = FALSE;
static QColorGroup *aFrameGrp = 0;
static QColorGroup *iFrameGrp = 0;
static QColorGroup *aTitleGrp = 0;
static QColorGroup *iTitleGrp = 0;
static bool colors_created = FALSE;
static void create_pixmaps() static void create_pixmaps()
{ {
if ( pixmaps_created ) if ( pixmaps_created )
return; return;
pixmaps_created = true;
size_pix = new QPixmap( size_xpm ); size_pix = new QPixmap( size_xpm );
} }
static void create_colorgroups()
{
if(colors_created)
return;
colors_created = true;
aFrameGrp = BeClient::makeColorGroup(options->
color(Options::Frame, true));
iFrameGrp = BeClient::makeColorGroup(options->
color(Options::Frame, false));
aTitleGrp = BeClient::makeColorGroup(options->
color(Options::TitleBar, true));
iTitleGrp = BeClient::makeColorGroup(options->
color(Options::TitleBar, false));
}
BeClient::BeClient( Workspace *ws, WId w, QWidget *parent, const char *name ) BeClient::BeClient( Workspace *ws, WId w, QWidget *parent, const char *name )
: Client( ws, w, parent, name, WResizeNoErase ) : Client( ws, w, parent, name, WResizeNoErase )
{ {
create_pixmaps(); create_pixmaps();
create_colorgroups();
QGridLayout* g = new QGridLayout( this, 0, 0, 2 ); QGridLayout* g = new QGridLayout( this, 0, 0, 2 );
g->addRowSpacing(1, 2); g->addRowSpacing(1, 2);
g->setRowStretch( 2, 10 ); g->setRowStretch( 2, 10 );
@ -70,12 +90,6 @@ BeClient::BeClient( Workspace *ws, WId w, QWidget *parent, const char *name )
hb->addItem( titlebar ); hb->addItem( titlebar );
hb->addStretch(); 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));
} }
@ -115,17 +129,17 @@ void BeClient::paintEvent( QPaintEvent* )
QRect bar ( 0, 0, titlebar->geometry().right()+1, QRect bar ( 0, 0, titlebar->geometry().right()+1,
titlebar->geometry().bottom() ); titlebar->geometry().bottom() );
qDrawWinPanel( &p, 0, bar.bottom()+2, width(), height() - bar.bottom()-2, qDrawWinPanel( &p, 0, bar.bottom()+2, width(), height() - bar.bottom()-2,
isActive() ? aFrameGrp : iFrameGrp, FALSE ); isActive() ? *aFrameGrp : *iFrameGrp, FALSE );
qDrawWinPanel( &p, 2, bar.bottom()+4, width()-4, height() - bar.bottom()-6, qDrawWinPanel( &p, 2, bar.bottom()+4, width()-4, height() - bar.bottom()-6,
isActive() ? aFrameGrp : iFrameGrp, TRUE ); isActive() ? *aFrameGrp : *iFrameGrp, TRUE );
QRect t = titlebar->geometry(); QRect t = titlebar->geometry();
bar.setBottom( bar.bottom() + 3 ); bar.setBottom( bar.bottom() + 3 );
p.setClipRect( bar ); p.setClipRect( bar );
bar.setBottom( bar.bottom() + 2 ); bar.setBottom( bar.bottom() + 2 );
qDrawWinPanel( &p, bar, isActive() ? aTitleGrp : iTitleGrp, FALSE, qDrawWinPanel( &p, bar, isActive() ? *aTitleGrp : *iTitleGrp, FALSE,
isActive() ? &aTitleGrp.brush(QColorGroup::Background) : isActive() ? &aTitleGrp->brush(QColorGroup::Background) :
&iTitleGrp.brush(QColorGroup::Background)); &iTitleGrp->brush(QColorGroup::Background));
p.setClipping( FALSE ); p.setClipping( FALSE );
p.drawPixmap( t.right() - 20, t.center().y()-8, *size_pix ); p.drawPixmap( t.right() - 20, t.center().y()-8, *size_pix );
@ -215,9 +229,9 @@ void BeClient::mouseDoubleClickEvent( QMouseEvent * e )
workspace()->requestFocus( this ); workspace()->requestFocus( this );
} }
QColorGroup BeClient::makeColorGroup(const QColor &bg, const QColor &fg) QColorGroup* BeClient::makeColorGroup(const QColor &bg, const QColor &fg)
{ {
return(QColorGroup( fg, bg, bg.light(150), bg.dark(), return(new QColorGroup( fg, bg, bg.light(150), bg.dark(),
bg.dark(120), fg, bg.dark(120), fg,
QApplication::palette().normal().base())); QApplication::palette().normal().base()));
} }

View file

@ -1,7 +1,6 @@
#ifndef BECLIENT_H #ifndef BECLIENT_H
#define BECLIENT_H #define BECLIENT_H
#include "client.h" #include "client.h"
#include <qpalette.h>
class QToolButton; class QToolButton;
class QLabel; class QLabel;
class QSpacerItem; class QSpacerItem;
@ -13,9 +12,10 @@ class BeClient : public Client
public: public:
BeClient( Workspace *ws, WId w, QWidget *parent=0, const char *name=0 ); BeClient( Workspace *ws, WId w, QWidget *parent=0, const char *name=0 );
~BeClient(); ~BeClient();
static QColorGroup* makeColorGroup(const QColor &bg,
const QColor &fg=Qt::white);
protected: protected:
QColorGroup makeColorGroup(const QColor &bg, const QColor &fg=Qt::white);
void resizeEvent( QResizeEvent* ); void resizeEvent( QResizeEvent* );
void paintEvent( QPaintEvent* ); void paintEvent( QPaintEvent* );
void mousePressEvent( QMouseEvent * ); void mousePressEvent( QMouseEvent * );
@ -32,7 +32,6 @@ protected:
private: private:
QSpacerItem* titlebar; QSpacerItem* titlebar;
void doShape(); void doShape();
QColorGroup aFrameGrp, iFrameGrp, aTitleGrp, iTitleGrp;
}; };

View file

@ -172,10 +172,32 @@ static QPixmap* pinup_pix = 0;
static QPixmap* pindown_pix = 0; static QPixmap* pindown_pix = 0;
static bool pixmaps_created = FALSE; static bool pixmaps_created = FALSE;
static QColorGroup *aFrameGrp = 0;
static QColorGroup *iFrameGrp = 0;
static QColorGroup *aTitleGrp = 0;
static QColorGroup *iTitleGrp = 0;
static bool colors_created = FALSE;
static void create_colorgroups()
{
if(colors_created)
return;
colors_created = true;
aFrameGrp = StdClient::makeColorGroup(options->
color(Options::Frame, true));
iFrameGrp = StdClient::makeColorGroup(options->
color(Options::Frame, false));
aTitleGrp = StdClient::makeColorGroup(options->
color(Options::TitleBar, true));
iTitleGrp = StdClient::makeColorGroup(options->
color(Options::TitleBar, false));
}
static void create_pixmaps() static void create_pixmaps()
{ {
if ( pixmaps_created ) if ( pixmaps_created )
return; return;
pixmaps_created = true;
close_pix = new QPixmap( close_xpm ); close_pix = new QPixmap( close_xpm );
maximize_pix = new QPixmap( maximize_xpm ); maximize_pix = new QPixmap( maximize_xpm );
minimize_pix = new QPixmap( minimize_xpm ); minimize_pix = new QPixmap( minimize_xpm );
@ -190,6 +212,7 @@ StdClient::StdClient( Workspace *ws, WId w, QWidget *parent, const char *name )
: Client( ws, w, parent, name, WResizeNoErase ) : Client( ws, w, parent, name, WResizeNoErase )
{ {
create_pixmaps(); create_pixmaps();
create_colorgroups();
QGridLayout* g = new QGridLayout( this, 0, 0, 2 ); QGridLayout* g = new QGridLayout( this, 0, 0, 2 );
@ -240,10 +263,6 @@ StdClient::StdClient( Workspace *ws, WId w, QWidget *parent, const char *name )
button[5]->setIconSet( *close_pix ); button[5]->setIconSet( *close_pix );
connect( button[5], SIGNAL( clicked() ), this, ( SLOT( closeWindow() ) ) ); 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));
} }
@ -299,11 +318,11 @@ void StdClient::paintEvent( QPaintEvent* )
QRegion r = rect(); QRegion r = rect();
r = r.subtract( t ); r = r.subtract( t );
p.setClipRegion( r ); p.setClipRegion( r );
qDrawWinPanel( &p, rect(), isActive()? aFrameGrp : iFrameGrp ); qDrawWinPanel( &p, rect(), isActive()? *aFrameGrp : *iFrameGrp );
p.setClipping( FALSE ); p.setClipping( FALSE );
p.fillRect( t, options->color(Options::TitleBar, isActive())); p.fillRect( t, options->color(Options::TitleBar, isActive()));
qDrawShadePanel( &p, t.x(), t.y(), t.width(), t.height(), qDrawShadePanel( &p, t.x(), t.y(), t.width(), t.height(),
isActive() ? aTitleGrp : iTitleGrp, TRUE ); isActive() ? *aTitleGrp : *iTitleGrp, TRUE );
t.setTop( 2 ); t.setTop( 2 );
t.setLeft( t.left() + 4 ); t.setLeft( t.left() + 4 );
@ -336,9 +355,9 @@ void StdClient::iconChange()
button[0]->repaint( FALSE ); button[0]->repaint( FALSE );
} }
QColorGroup StdClient::makeColorGroup(const QColor &bg, const QColor &fg) QColorGroup* StdClient::makeColorGroup(const QColor &bg, const QColor &fg)
{ {
return(QColorGroup( fg, bg, bg.light(150), bg.dark(), return(new QColorGroup( fg, bg, bg.light(150), bg.dark(),
bg.dark(120), fg, bg.dark(120), fg,
QApplication::palette().normal().base())); QApplication::palette().normal().base()));
} }

View file

@ -4,7 +4,6 @@
class QToolButton; class QToolButton;
class QLabel; class QLabel;
class QSpacerItem; class QSpacerItem;
class QColorGroup;
class StdClient : public Client class StdClient : public Client
{ {
@ -12,13 +11,14 @@ class StdClient : public Client
public: public:
StdClient( Workspace *ws, WId w, QWidget *parent=0, const char *name=0 ); StdClient( Workspace *ws, WId w, QWidget *parent=0, const char *name=0 );
~StdClient(); ~StdClient();
static QColorGroup* makeColorGroup(const QColor &bg,
const QColor &fg=Qt::white);
protected: protected:
void resizeEvent( QResizeEvent* ); void resizeEvent( QResizeEvent* );
void paintEvent( QPaintEvent* ); void paintEvent( QPaintEvent* );
void mouseDoubleClickEvent( QMouseEvent * ); void mouseDoubleClickEvent( QMouseEvent * );
void init(); void init();
QColorGroup makeColorGroup(const QColor &bg, const QColor &fg=Qt::white);
void captionChange( const QString& name ); void captionChange( const QString& name );
void iconChange(); void iconChange();
void maximizeChange( bool ); void maximizeChange( bool );
@ -27,7 +27,6 @@ protected:
private: private:
QToolButton* button[6]; QToolButton* button[6];
QSpacerItem* titlebar; QSpacerItem* titlebar;
QColorGroup aFrameGrp, iFrameGrp, aTitleGrp, iTitleGrp;
}; };