• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
ksqueezedtextlabel.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2000 Ronny Standtke <Ronny.Standtke@gmx.de>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
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
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "ksqueezedtextlabel.h"
20 #include "kstringhandler.h"
21 #include <tqtooltip.h>
22 
23 KSqueezedTextLabel::KSqueezedTextLabel( const TQString &text , TQWidget *parent, const char *name )
24  : TQLabel ( parent, name ) {
25  setSizePolicy(TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ));
26  fullText = text;
27  squeezeTextToLabel();
28 }
29 
30 KSqueezedTextLabel::KSqueezedTextLabel( TQWidget *parent, const char *name )
31  : TQLabel ( parent, name ) {
32  setSizePolicy(TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ));
33 }
34 
35 void KSqueezedTextLabel::resizeEvent( TQResizeEvent * ) {
36  squeezeTextToLabel();
37 }
38 
39 TQSize KSqueezedTextLabel::minimumSizeHint() const
40 {
41  TQSize sh = TQLabel::minimumSizeHint();
42  sh.setWidth(-1);
43  return sh;
44 }
45 
46 TQSize KSqueezedTextLabel::sizeHint() const
47 {
48  return TQSize(contentsRect().width(), TQLabel::sizeHint().height());
49 }
50 
51 void KSqueezedTextLabel::setText( const TQString &text ) {
52  fullText = text;
53  squeezeTextToLabel();
54 }
55 
56 void KSqueezedTextLabel::squeezeTextToLabel() {
57  TQFontMetrics fm(fontMetrics());
58  int labelWidth = size().width();
59  int textWidth = fm.width(fullText);
60  if (textWidth > labelWidth) {
61  TQString squeezedText = KStringHandler::cPixelSqueeze(fullText, fm, labelWidth);
62  TQLabel::setText(squeezedText);
63 
64  TQToolTip::remove( this );
65  TQToolTip::add( this, fullText );
66 
67  } else {
68  TQLabel::setText(fullText);
69 
70  TQToolTip::remove( this );
71  TQToolTip::hide();
72 
73  }
74 }
75 
76 void KSqueezedTextLabel::setAlignment( int alignment )
77 {
78  // save fullText and restore it
79  TQString tmpFull(fullText);
80  TQLabel::setAlignment(alignment);
81  fullText = tmpFull;
82 }
83 
84 void KSqueezedTextLabel::virtual_hook( int, void* )
85 { /*BASE::virtual_hook( id, data );*/ }
86 
87 #include "ksqueezedtextlabel.moc"
KSqueezedTextLabel::resizeEvent
void resizeEvent(TQResizeEvent *)
used when widget is resized
Definition: ksqueezedtextlabel.cpp:35
KSqueezedTextLabel::squeezeTextToLabel
void squeezeTextToLabel()
does the dirty work
Definition: ksqueezedtextlabel.cpp:56
KStringHandler::cPixelSqueeze
static TQString cPixelSqueeze(const TQString &name, const TQFontMetrics &fontMetrics, uint maxPixels)
KSqueezedTextLabel::KSqueezedTextLabel
KSqueezedTextLabel(TQWidget *parent, const char *name=0)
Default constructor.
Definition: ksqueezedtextlabel.cpp:30
KSqueezedTextLabel::setAlignment
virtual void setAlignment(int)
Overridden for internal reasons; the API remains unaffected.
Definition: ksqueezedtextlabel.cpp:76

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.