summaryrefslogtreecommitdiffabout
path: root/microkde/kdeui/ksqueezedtextlabel.cpp
Unidiff
Diffstat (limited to 'microkde/kdeui/ksqueezedtextlabel.cpp') (more/less context) (show whitespace changes)
-rw-r--r--microkde/kdeui/ksqueezedtextlabel.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/microkde/kdeui/ksqueezedtextlabel.cpp b/microkde/kdeui/ksqueezedtextlabel.cpp
index 37fa29a..e2c61fd 100644
--- a/microkde/kdeui/ksqueezedtextlabel.cpp
+++ b/microkde/kdeui/ksqueezedtextlabel.cpp
@@ -1,68 +1,71 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Ronny Standtke <Ronny.Standtke@gmx.de> 2 Copyright (C) 2000 Ronny Standtke <Ronny.Standtke@gmx.de>
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public 5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation. 6 License version 2 as published by the Free Software Foundation.
7 7
8 This library is distributed in the hope that it will be useful, 8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of 9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details. 11 Library General Public License for more details.
12 12
13 You should have received a copy of the GNU Library General Public License 13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to 14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA. 16 Boston, MA 02111-1307, USA.
17*/ 17*/
18 18
19#include "ksqueezedtextlabel.h" 19#include "ksqueezedtextlabel.h"
20#include <qtooltip.h> 20#include <qtooltip.h>
21//Added by qt3to4:
22#include <QResizeEvent>
23#include <QLabel>
21 24
22KSqueezedTextLabel::KSqueezedTextLabel( const QString &text , QWidget *parent, const char *name ) 25KSqueezedTextLabel::KSqueezedTextLabel( const QString &text , QWidget *parent, const char *name )
23 : QLabel ( parent, name ) { 26 : QLabel ( parent, name ) {
24 setSizePolicy(QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed )); 27 setSizePolicy(QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
25 fullText = text; 28 fullText = text;
26 squeezeTextToLabel(); 29 squeezeTextToLabel();
27} 30}
28 31
29KSqueezedTextLabel::KSqueezedTextLabel( QWidget *parent, const char *name ) 32KSqueezedTextLabel::KSqueezedTextLabel( QWidget *parent, const char *name )
30 : QLabel ( parent, name ) { 33 : QLabel ( parent, name ) {
31 setSizePolicy(QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed )); 34 setSizePolicy(QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
32} 35}
33 36
34void KSqueezedTextLabel::resizeEvent( QResizeEvent * ) { 37void KSqueezedTextLabel::resizeEvent( QResizeEvent * ) {
35 squeezeTextToLabel(); 38 squeezeTextToLabel();
36} 39}
37 40
38QSize KSqueezedTextLabel::minimumSizeHint() const 41QSize KSqueezedTextLabel::minimumSizeHint() const
39{ 42{
40 QSize sh = QLabel::minimumSizeHint(); 43 QSize sh = QLabel::minimumSizeHint();
41 sh.setWidth(-1); 44 sh.setWidth(-1);
42 return sh; 45 return sh;
43} 46}
44 47
45void KSqueezedTextLabel::setText( const QString &text ) { 48void KSqueezedTextLabel::setText( const QString &text ) {
46 fullText = text; 49 fullText = text;
47 squeezeTextToLabel(); 50 squeezeTextToLabel();
48} 51}
49 52
50void KSqueezedTextLabel::squeezeTextToLabel() { 53void KSqueezedTextLabel::squeezeTextToLabel() {
51 QFontMetrics fm(fontMetrics()); 54 QFontMetrics fm(fontMetrics());
52 int labelWidth = size().width(); 55 int labelWidth = size().width();
53 int textWidth = fm.width(fullText); 56 int textWidth = fm.width(fullText);
54 if (textWidth > labelWidth) { 57 if (textWidth > labelWidth) {
55 // start with the dots only 58 // start with the dots only
56 QString squeezedText = "..."; 59 QString squeezedText = "...";
57 int squeezedWidth = fm.width(squeezedText); 60 int squeezedWidth = fm.width(squeezedText);
58 61
59 // estimate how many letters we can add to the dots on both sides 62 // estimate how many letters we can add to the dots on both sides
60 int letters = fullText.length() * (labelWidth - squeezedWidth) / textWidth / 2; 63 int letters = fullText.length() * (labelWidth - squeezedWidth) / textWidth / 2;
61 if (labelWidth < squeezedWidth) letters=1; 64 if (labelWidth < squeezedWidth) letters=1;
62 squeezedText = fullText.left(letters) + "..." + fullText.right(letters); 65 squeezedText = fullText.left(letters) + "..." + fullText.right(letters);
63 squeezedWidth = fm.width(squeezedText); 66 squeezedWidth = fm.width(squeezedText);
64 67
65 if (squeezedWidth < labelWidth) { 68 if (squeezedWidth < labelWidth) {
66 // we estimated too short 69 // we estimated too short
67 // add letters while text < label 70 // add letters while text < label
68 do { 71 do {