From f10a38655bf056ce6293e1a6276dc4e950a2e143 Mon Sep 17 00:00:00 2001 From: Malte Starostik Date: Sat, 2 Mar 2002 16:03:29 +0000 Subject: [PATCH] Don't make the tabbox wider than the screen if some window has a too long title svn path=/trunk/kdebase/kwin/; revision=140220 --- tabbox.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/tabbox.cpp b/tabbox.cpp index 8384c3c2c9..0ac5bcedb0 100644 --- a/tabbox.cpp +++ b/tabbox.cpp @@ -18,6 +18,7 @@ Copyright (C) 1999, 2000 Matthias Ettrich #include #include #include +#include // specify externals before namespace @@ -99,7 +100,7 @@ void TabBox::reset() QRect r = desktop->screenGeometry(screen); - int w = QMAX( wmax + 20, r.width()/3 ); + int w = QMIN( QMAX( wmax + 20, r.width()/3 ), r.width() ); setGeometry( (r.width()-w)/2 + r.x(), r.height()/2-fontMetrics().height()*2-10 + r.y(), w, fontMetrics().height()*4 + 20 ); @@ -241,19 +242,25 @@ void TabBox::paintContents() p.fillRect( r, colorGroup().brush( QColorGroup::Background ) ); if ( mode () == WindowsMode ) { if ( currentClient() ) { + int textw, maxlen = client->caption().length(); + int icon = client->icon().isNull() ? 0 : 42; QString s; - if (!client->isOnDesktop(workspace()->currentDesktop())){ - s.append(": "); - } + do { + s = QString(); + if (!client->isOnDesktop(workspace()->currentDesktop())){ + s.append(": "); + } - if (client->isIconified()) - s += QString("(")+client->caption()+")"; - else - s += client->caption(); - int textw = fontMetrics().width( s ); + if (client->isIconified()) + s += QString("(")+KStringHandler::csqueeze(client->caption(), maxlen)+")"; + else + s += KStringHandler::csqueeze(client->caption(), maxlen); + textw = fontMetrics().width( s ); + maxlen--; + } while (textw > r.width() - icon); r.setLeft( r.left() + (r.width() - textw)/2); - if ( !client->icon().isNull() ) { + if ( icon ) { int py = r.center().y() - 16; r.setLeft( r.left() + 20 ); p.drawPixmap( r.left()-42, py, client->icon() );