From d226e9cd0e0f07bcd8680c8fcfe4bfe77464ee15 Mon Sep 17 00:00:00 2001 From: Matthias Ettrich Date: Wed, 12 Jul 2000 12:46:58 +0000 Subject: [PATCH] sexy toolwindows (at least in standard style) svn path=/trunk/kdebase/kwin/; revision=56329 --- client.h | 10 ++--- options.cpp | 11 ++++- options.h | 6 +-- stdclient.cpp | 112 ++++++++++++++++++++++++++++++++++++++++++++++++-- stdclient.h | 24 ++++++++++- workspace.cpp | 35 ++++++++-------- 6 files changed, 168 insertions(+), 30 deletions(-) diff --git a/client.h b/client.h index 779bb8ac85..ed1b07947a 100644 --- a/client.h +++ b/client.h @@ -166,7 +166,7 @@ public slots: void toggleSticky(); void contextHelp(); void autoRaise(); - + protected: void paintEvent( QPaintEvent * ); void mousePressEvent( QMouseEvent * ); @@ -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 { diff --git a/options.cpp b/options.cpp index 5acc9d74e9..21714287c1 100644 --- a/options.cpp +++ b/options.cpp @@ -36,9 +36,12 @@ 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) { - return(active ? activeFont : inactiveFont); + if ( small ) + return(active ? activeFontSmall : inactiveFontSmall); + else + return(active ? activeFont : inactiveFont); } const QColorGroup& Options::colorGroup(ColorType type, bool active) @@ -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]){ diff --git a/options.h b/options.h index d62016d3c7..0575cc28fa 100644 --- a/options.h +++ b/options.h @@ -66,7 +66,7 @@ public: whether autoraise is enabled FocusFollowsMouse mode or not. */ bool autoRaise; - + /** autoraise interval */ @@ -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]; diff --git a/stdclient.cpp b/stdclient.cpp index 1e6d9d71a8..8573148537 100644 --- a/stdclient.cpp +++ b/stdclient.cpp @@ -14,6 +14,7 @@ Copyright (C) 1999, 2000 Matthias Ettrich #include #include #include +#include #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 ); @@ -368,7 +372,7 @@ void StdClient::iconChange() } -/*! +/*! Indicates that the menu button has been clicked. One press shows the window operation menu, a double click closes the window. */ @@ -378,8 +382,8 @@ void StdClient::menuButtonPressed() static StdClient* tc = 0; if ( !t ) t = new QTime; - - if ( tc != this || t->elapsed() > QApplication::doubleClickInterval() ) + + if ( tc != this || t->elapsed() > QApplication::doubleClickInterval() ) button[0]->setPopup( workspace()->clientPopup( this ) ); else { button[0]->setPopup( 0 ); @@ -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" diff --git a/stdclient.h b/stdclient.h index e8351e63a9..cc67a0a8a2 100644 --- a/stdclient.h +++ b/stdclient.h @@ -1,6 +1,6 @@ /***************************************************************** kwin - the KDE window manager - + Copyright (C) 1999, 2000 Matthias Ettrich ******************************************************************/ #ifndef STDCLIENT_H @@ -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; +}; + /* diff --git a/workspace.cpp b/workspace.cpp index 6f215cd2f9..aad982d261 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -153,25 +153,28 @@ Client* Workspace::clientFactory( WId w ) return new NoBorderClient( this, w ); switch ( ni.windowType() ) { - case NET::Desktop: { - XLowerWindow( qt_xdisplay(), w ); - Client * c = new NoBorderClient( this, w); - c->setSticky( TRUE ); - setDesktopClient( c ); - return c; - } + case NET::Desktop: + { + XLowerWindow( qt_xdisplay(), w ); + Client * c = new NoBorderClient( this, w); + c->setSticky( TRUE ); + setDesktopClient( c ); + return c; + } + case NET::Toolbar: + return new StdToolClient( this, w); // TODO use mgr.allocateClient... + case NET::Menu: - case NET::Dock: { - Client * c = new NoBorderClient( this, w); - c->setSticky( TRUE ); - return c; - } + 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;