sexy toolwindows (at least in standard style)

svn path=/trunk/kdebase/kwin/; revision=56329
This commit is contained in:
Matthias Ettrich 2000-07-12 12:46:58 +00:00
parent 99211a9236
commit d226e9cd0e
6 changed files with 168 additions and 30 deletions

View file

@ -315,6 +315,10 @@ inline int Client::desktop() const
return desk;
}
inline bool Client::isSticky() const
{
return is_sticky;
}
/*!
Returns whether the client is on visible or iconified on the virtual
desktop \a d. This is always TRUE for sticky clients.
@ -344,10 +348,6 @@ inline bool Client::isMaximized() const
return !geom_restore.isNull();
}
inline bool Client::isSticky() const
{
return is_sticky;
}
inline bool Client::staysOnTop() const
{

View file

@ -36,8 +36,11 @@ const QColor& Options::color(ColorType type, bool active)
return(colors[type + (active ? 0 : KWINCOLORS)]);
}
const QFont& Options::font(bool active)
const QFont& Options::font(bool active, bool small)
{
if ( small )
return(active ? activeFontSmall : inactiveFontSmall);
else
return(active ? activeFont : inactiveFont);
}
@ -119,6 +122,10 @@ void Options::reload()
activeFont = config->readFontEntry("activeFont", &activeFont);
inactiveFont = config->readFontEntry("inactiveFont", &activeFont);
activeFontSmall = QFont("Helvetica", 10, QFont::Bold);
activeFontSmall = config->readFontEntry("activeFontSmall", &activeFontSmall);
inactiveFontSmall = config->readFontEntry("inactiveFontSmall", &activeFontSmall);
int i;
for(i=0; i < KWINCOLORS*2; ++i){
if(cg[i]){

View file

@ -133,7 +133,7 @@ public:
/**
* Return the active or inactive decoration font.
*/
const QFont& font(bool active=true);
const QFont& font(bool active=true, bool small = false);
/**
* whether we animate the shading of windows to titlebar or not
@ -207,7 +207,7 @@ signals:
void resetClients();
protected:
QFont activeFont, inactiveFont;
QFont activeFont, inactiveFont, activeFontSmall, inactiveFontSmall;
QColor colors[KWINCOLORS*2];
QColorGroup *cg[KWINCOLORS*2];

View file

@ -14,6 +14,7 @@ Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
#include <qbitmap.h>
#include <kdrawutil.h>
#include <qdatetime.h>
#include <qimage.h>
#include "workspace.h"
#include "options.h"
@ -169,6 +170,8 @@ void StdClient::slotReset()
button[5]->setIconSet(isActive() ? *close_pix : *dis_close_pix);
if (button[6])
button[6]->setIconSet( *question_mark_pix );
setFont(options->font(isActive() ));
}
@ -176,6 +179,7 @@ StdClient::StdClient( Workspace *ws, WId w, QWidget *parent, const char *name )
: Client( ws, w, parent, name, WResizeNoErase )
{
create_pixmaps();
setFont(options->font(isActive() ));
connect(options, SIGNAL(resetClients()), this, SLOT(slotReset()));
QGridLayout* g = new QGridLayout( this, 0, 0, 2 );
@ -405,4 +409,106 @@ void StdClient::maxButtonClicked( int button )
}
}
StdToolClient::StdToolClient( Workspace *ws, WId w, QWidget *parent, const char *name )
: Client( ws, w, parent, name )
{
connect(options, SIGNAL(resetClients()), this, SLOT(slotReset()));
setFont(options->font(isActive(), true ));
QGridLayout* g = new QGridLayout( this, 0, 0, 2 );
g->setRowStretch( 1, 10 );
g->addWidget( windowWrapper(), 1, 1 );
g->addItem( new QSpacerItem( 0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding ) );
g->addColSpacing(0, 1);
g->addColSpacing(2, 1);
g->addRowSpacing(2, 2);
closeBtn = new QToolButton( this );
connect( closeBtn, SIGNAL( clicked() ), this, ( SLOT( closeWindow() ) ) );
closeBtn->setFixedSize( 13, 13);
slotReset();
QHBoxLayout* hb = new QHBoxLayout;
g->addLayout( hb, 0, 1 );
int fh = fontMetrics().lineSpacing()+2;
titlebar = new QSpacerItem(10, fh, QSizePolicy::Expanding,
QSizePolicy::Minimum );
hb->addItem( titlebar );
hb->addWidget( closeBtn );
}
StdToolClient::~StdToolClient()
{
}
void StdToolClient::resizeEvent( QResizeEvent* e )
{
Client::resizeEvent( e );
QRegion r = rect();
QRect t = titlebar->geometry();
t.setTop( 0 );
r = r.subtract( QRect(0, 0, width(), 1) );
r = r.subtract (QRect( 0, 0, 1, t.height() ) );
r = r.subtract (QRect( width()-1, 0, 1, t.height() ) );
setMask( r );
}
void StdToolClient::paintEvent( QPaintEvent* )
{
QPainter p( this );
QRect t = titlebar->geometry();
QRect r = rect();
qDrawWinPanel( &p, r, colorGroup() );
r.setTop( t.bottom()+1 );
qDrawWinPanel( &p, r, colorGroup() );
p.fillRect( QRect( QPoint(t.topLeft() ), QPoint( width() - t.left(), t.bottom() ) ),
options->color(Options::TitleBar, isActive()));
p.setPen( options->color(Options::TitleBar, isActive()).light() );
t.setLeft( t.left() + 4 );
t.setRight( t.right() - 2 );
p.setPen(options->color(Options::Font, isActive()));
p.setFont(options->font(isActive(), true));
p.drawText( t, AlignLeft|AlignVCenter|SingleLine, caption() );
}
void StdToolClient::mouseDoubleClickEvent( QMouseEvent * e )
{
if ( titlebar->geometry().contains( e->pos() ) )
workspace()->performWindowOperation( this, options->operationTitlebarDblClick() );
workspace()->requestFocus( this );
}
void StdToolClient::init()
{
}
void StdToolClient::captionChange( const QString& )
{
repaint( titlebar->geometry(), FALSE );
}
void StdToolClient::activeChange( bool on )
{
Client::activeChange(on);
}
void StdToolClient::slotReset()
{
create_pixmaps();
QImage img = close_pix->convertToImage();
img = img.smoothScale( 12, 12 );
QPixmap pm;
pm.convertFromImage( img );
closeBtn->setPixmap( pm );
setFont(options->font(isActive(), true ));
}
#include "stdclient.moc"

View file

@ -38,6 +38,28 @@ private:
QSpacerItem* titlebar;
};
class StdToolClient : public Client
{
Q_OBJECT
public:
StdToolClient( Workspace *ws, WId w, QWidget *parent=0, const char *name=0 );
~StdToolClient();
protected:
void resizeEvent( QResizeEvent* );
void paintEvent( QPaintEvent* );
void mouseDoubleClickEvent( QMouseEvent * );
void init();
void captionChange( const QString& name );
void activeChange( bool );
private slots:
void slotReset();
private:
QToolButton* closeBtn;
QSpacerItem* titlebar;
};
/*

View file

@ -153,7 +153,8 @@ Client* Workspace::clientFactory( WId w )
return new NoBorderClient( this, w );
switch ( ni.windowType() ) {
case NET::Desktop: {
case NET::Desktop:
{
XLowerWindow( qt_xdisplay(), w );
Client * c = new NoBorderClient( this, w);
c->setSticky( TRUE );
@ -161,17 +162,19 @@ Client* Workspace::clientFactory( WId w )
return c;
}
case NET::Toolbar:
return new StdToolClient( this, w); // TODO use mgr.allocateClient...
case NET::Menu:
case NET::Dock: {
case NET::Dock:
{
Client * c = new NoBorderClient( this, w);
c->setSticky( TRUE );
return c;
}
case NET::Toolbar: {
Client * c = new NoBorderClient( this, w);
return c;
}
case NET::Override:
return new NoBorderClient( this, w);
default:
break;