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

kdeui

ksqueezedtextlabel.cpp
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2000 Ronny Standtke <Ronny.Standtke@gmx.de>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "ksqueezedtextlabel.h"
00020 #include "kstringhandler.h"
00021 #include <tqtooltip.h>
00022 
00023 KSqueezedTextLabel::KSqueezedTextLabel( const TQString &text , TQWidget *parent, const char *name )
00024  : TQLabel ( parent, name ) {
00025   setSizePolicy(TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ));
00026   fullText = text;
00027   squeezeTextToLabel();
00028 }
00029 
00030 KSqueezedTextLabel::KSqueezedTextLabel( TQWidget *parent, const char *name )
00031  : TQLabel ( parent, name ) {
00032   setSizePolicy(TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ));
00033 }
00034 
00035 void KSqueezedTextLabel::resizeEvent( TQResizeEvent * ) {
00036   squeezeTextToLabel();
00037 }
00038 
00039 TQSize KSqueezedTextLabel::minimumSizeHint() const
00040 {
00041   TQSize sh = TQLabel::minimumSizeHint();
00042   sh.setWidth(-1);
00043   return sh;
00044 }
00045 
00046 TQSize KSqueezedTextLabel::sizeHint() const
00047 {
00048   return TQSize(contentsRect().width(), TQLabel::sizeHint().height());
00049 }
00050 
00051 void KSqueezedTextLabel::setText( const TQString &text ) {
00052   fullText = text;
00053   squeezeTextToLabel();
00054 }
00055 
00056 void KSqueezedTextLabel::squeezeTextToLabel() {
00057   TQFontMetrics fm(fontMetrics());
00058   int labelWidth = size().width();
00059   int textWidth = fm.width(fullText);
00060   if (textWidth > labelWidth) {
00061     TQString squeezedText = KStringHandler::cPixelSqueeze(fullText, fm, labelWidth);
00062     TQLabel::setText(squeezedText);
00063 
00064     TQToolTip::remove( this );
00065     TQToolTip::add( this, fullText );
00066 
00067   } else {
00068     TQLabel::setText(fullText);
00069 
00070     TQToolTip::remove( this );
00071     TQToolTip::hide();
00072 
00073   }
00074 }
00075 
00076 void KSqueezedTextLabel::setAlignment( int alignment )
00077 {
00078   // save fullText and restore it
00079   TQString tmpFull(fullText);
00080   TQLabel::setAlignment(alignment);
00081   fullText = tmpFull;
00082 }
00083 
00084 void KSqueezedTextLabel::virtual_hook( int, void* )
00085 { /*BASE::virtual_hook( id, data );*/ }
00086 
00087 #include "ksqueezedtextlabel.moc"

kdeui

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

kdeui

Skip menu "kdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeui by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |