nicer tabbox

svn path=/trunk/kdebase/kwin/; revision=35151
This commit is contained in:
Matthias Ettrich 1999-11-26 22:10:25 +00:00
parent eed9205dd3
commit 49f894fa51
4 changed files with 102 additions and 22 deletions

View file

@ -357,7 +357,7 @@ void Client::manage( bool isMapped )
placementDone = TRUE; placementDone = TRUE;
} }
if ( !placementDone ) { if ( !placementDone ) {
workspace()->doPlacement( this ); workspace()->doPlacement( this );
placementDone = TRUE; placementDone = TRUE;
@ -378,6 +378,7 @@ void Client::manage( bool isMapped )
// ### TODO check XGetWMHints() for initial mapping state, icon, etc. pp. // ### TODO check XGetWMHints() for initial mapping state, icon, etc. pp.
// assume window wants to be visible on the current desktop // assume window wants to be visible on the current desktop
desk = KWM::desktop( win ); //workspace()->currentDesktop(); desk = KWM::desktop( win ); //workspace()->currentDesktop();
KWM::moveToDesktop( win, desk ); // compatibility
setMappingState( state ); setMappingState( state );
if ( state == NormalState && isOnDesktop( workspace()->currentDesktop() ) ) { if ( state == NormalState && isOnDesktop( workspace()->currentDesktop() ) ) {
show(); show();
@ -560,7 +561,7 @@ void Client::withdraw()
bool Client::configureRequest( XConfigureRequestEvent& e ) bool Client::configureRequest( XConfigureRequestEvent& e )
{ {
if ( isResize() ) if ( isResize() )
return TRUE; // we have better things to do right now return TRUE; // we have better things to do right now
if ( isShade() ) if ( isShade() )
setShade( FALSE ); setShade( FALSE );

View file

@ -31,6 +31,12 @@ static QPixmap* dis_menu_pix = 0;
static bool pixmaps_created = FALSE; static bool pixmaps_created = FALSE;
static void create_pixmaps();
QPixmap* kwin_get_menu_pix_hack()
{
create_pixmaps();
return menu_pix;
}
/** /**
* Pixmap creation routine that creates full pixmaps out of bitmaps * Pixmap creation routine that creates full pixmaps out of bitmaps

View file

@ -2,6 +2,8 @@
#include "workspace.h" #include "workspace.h"
#include "client.h" #include "client.h"
#include <qpainter.h> #include <qpainter.h>
#include <qlabel.h>
#include <qdrawutil.h>
const bool options_traverse_all = FALSE; // TODO const bool options_traverse_all = FALSE; // TODO
@ -39,20 +41,41 @@ void TabBox::reset()
f.setPointSize( 14 ); f.setPointSize( 14 );
setFont( f ); setFont( f );
wmax = 0;
// TODO icons etc.
setGeometry( qApp->desktop()->width()/4,
qApp->desktop()->height()/2-fontMetrics().height()*2,
qApp->desktop()->width()/2, fontMetrics().height()*4 );
if ( mode() == WindowsMode ) { if ( mode() == WindowsMode ) {
client = workspace()->activeClient(); client = workspace()->activeClient();
// todo build window list, consider options_traverse_all clients.clear();
Client* c = workspace()->nextClient( client );
Client* stop = c;
QFontMetrics fm( fontMetrics() );
int cw = 0;
while ( c ) {
// TODO consider options_traverse_all
if ( options_traverse_all ||c->isOnDesktop(workspace()->currentDesktop()) ) {
if ( client == c )
clients.prepend( c );
else
clients += c;
cw = fm.width( c->caption() ) + 40;
if ( cw > wmax )
wmax = cw;
}
c = workspace()->nextClient( c );
if ( c == stop )
break;
}
wmax = QMAX( wmax, int(clients.count())*20 );
} }
else { // DesktopMode else { // DesktopMode
desk = wspace->currentDesktop(); desk = workspace()->currentDesktop();
} }
int w = QMAX( wmax + 20, qApp->desktop()->width()/3 );
setGeometry( (qApp->desktop()->width()-w)/2,
qApp->desktop()->height()/2-fontMetrics().height()*2-10,
w, fontMetrics().height()*4 + 20 );
wmax = QMIN( wmax, width() - 12 );
} }
@ -77,16 +100,17 @@ void TabBox::nextPrev( bool next)
if (!options_traverse_all && client if (!options_traverse_all && client
&& !client->isOnDesktop(workspace()->currentDesktop())) && !client->isOnDesktop(workspace()->currentDesktop()))
client = 0; client = 0;
} }
else { // DesktopMode else { // DesktopMode
if ( next ) { if ( next ) {
desk++; desk++;
if ( desk > wspace->numberOfDesktops() ) if ( desk > workspace()->numberOfDesktops() )
desk = 1; desk = 1;
} else { } else {
desk--; desk--;
if ( desk < 1 ) if ( desk < 1 )
desk = wspace->numberOfDesktops(); desk = workspace()->numberOfDesktops();
} }
} }
@ -128,6 +152,14 @@ void TabBox::showEvent( QShowEvent* )
} }
/*!
hide the icon box if necessary
*/
void TabBox::hideEvent( QHideEvent* )
{
}
/*! /*!
Paints the tab box Paints the tab box
*/ */
@ -141,14 +173,17 @@ void TabBox::paintEvent( QPaintEvent* )
paintContents(); paintContents();
} }
/*! /*!
Paints the contents of the tab box. Used in paintEvent() and Paints the contents of the tab box. Used in paintEvent() and
whenever the contents changes. whenever the contents changes.
*/ */
void TabBox::paintContents() void TabBox::paintContents()
{ {
extern QPixmap* kwin_get_menu_pix_hack();
QPixmap* menu_pix = kwin_get_menu_pix_hack();
QPainter p( this ); QPainter p( this );
QRect r(6, 6, width()-12, height()-12 ); QRect r( 6, 6, width()-12, height()-32 );
p.fillRect( r, colorGroup().brush( QColorGroup::Background ) ); p.fillRect( r, colorGroup().brush( QColorGroup::Background ) );
if ( mode () == WindowsMode ) { if ( mode () == WindowsMode ) {
if ( currentClient() ) { if ( currentClient() ) {
@ -162,18 +197,54 @@ void TabBox::paintContents()
s += QString("(")+client->caption()+")"; s += QString("(")+client->caption()+")";
else else
s += client->caption(); s += client->caption();
if ( p.fontMetrics().width( s ) > r.width() ) int textw = fontMetrics().width( s );
p.drawText( r, AlignLeft, s ); r.setLeft( r.left() + (r.width() - textw)/2);
else
p.drawText( r, AlignCenter, s ); if ( !client->icon().isNull() ) {
int py = r.center().y() - 16;
r.setLeft( r.left() + 20 );
p.drawPixmap( r.left()-42, py, client->icon() );
}
p.drawText( r, AlignVCenter, s );
} }
else { else {
p.drawText( r, AlignCenter, "*** No Tasks ***" ); r.setBottom( r.bottom() + 20 );
p.drawText( r, AlignCenter, "*** No Tasks ***" );
}
int x = (width() - clients.count() * 20 )/2;
int y = height() - 26;
for ( ClientList::ConstIterator it = clients.begin(); it != clients.end(); ++it) {
if ( workspace()->hasClient( *it ) ) { // safety
if ( !(*it)->miniIcon().isNull() )
p.drawPixmap( x, y, (*it)->miniIcon() );
else if ( menu_pix )
p.drawPixmap( x, y, *menu_pix );
p.setPen( (*it)==currentClient()?
colorGroup().highlight():colorGroup().background() );
p.drawRect( x-2, y-2, 20, 20 );
x += 20;
}
} }
} else { // DesktopMode } else { // DesktopMode
QString s; p.drawText( r, AlignCenter, QString::number( desk ) );
s.setNum( desk ); int x = (width() - workspace()->numberOfDesktops() * 20 )/2;
p.drawText( r, AlignCenter, s ); int y = height() - 26;
QFont f( font() );
f.setPointSize( 12 );
f.setBold( FALSE );
p.setFont(f );
for ( int i = 1; i <= workspace()->numberOfDesktops(); i++ ) {
p.setPen( i == desk?
colorGroup().highlight():colorGroup().background() );
p.drawRect( x-2, y-2, 20, 20 );
qDrawWinPanel( &p, QRect( x, y, 16, 16), colorGroup(), FALSE,
&colorGroup().brush(QColorGroup::Base ) );
p.setPen( colorGroup().text() );
p.drawText( x, y, 16, 16, AlignCenter, QString::number(i) );
x += 20;
}
} }
} }

View file

@ -4,7 +4,7 @@
class Workspace; class Workspace;
class Client; class Client;
class QLabel;
typedef QValueList<Client*> ClientList; typedef QValueList<Client*> ClientList;
class TabBox : public QWidget class TabBox : public QWidget
@ -29,6 +29,7 @@ public:
protected: protected:
void paintEvent( QPaintEvent* ); void paintEvent( QPaintEvent* );
void showEvent( QShowEvent* ); void showEvent( QShowEvent* );
void hideEvent( QHideEvent* );
void paintContents(); void paintContents();
private: private:
@ -37,7 +38,8 @@ private:
Workspace* wspace; Workspace* wspace;
ClientList clients; ClientList clients;
int desk; int desk;
// QValueList <QLabel*> labels; QLabel* icon;
int wmax;
}; };