• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

korganizer

koalternatelabel.cpp

Go to the documentation of this file.
00001 /*
00002   This file is part of KOrganizer.
00003   Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004   Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00005 
00006   This program is free software; you can redistribute it and/or modify
00007   it under the terms of the GNU General Public License as published by
00008   the Free Software Foundation; either version 2 of the License, or
00009   (at your option) any later version.
00010 
00011   This program is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014   GNU General Public License for more details.
00015 
00016   You should have received a copy of the GNU General Public License along
00017   with this program; if not, write to the Free Software Foundation, Inc.,
00018   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020   As a special exception, permission is given to link this program
00021   with any edition of Qt, and distribute the resulting executable,
00022   without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include "koalternatelabel.h"
00026 
00027 #include "koalternatelabel.moc"
00028 
00029 KOAlternateLabel::KOAlternateLabel(const QString &shortlabel, const QString &longlabel,
00030     const QString &extensivelabel, QWidget *parent )
00031   : QLabel( parent ), mTextTypeFixed( false ), mShortText( shortlabel ),
00032     mLongText( longlabel ), mExtensiveText( extensivelabel )
00033 {
00034   setSizePolicy(QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
00035   if (mExtensiveText.isEmpty()) mExtensiveText = mLongText;
00036   squeezeTextToLabel();
00037 }
00038 
00039 KOAlternateLabel::~KOAlternateLabel()
00040 {
00041 }
00042 
00043 void KOAlternateLabel::useShortText()
00044 {
00045   mTextTypeFixed = true;
00046   QLabel::setText( mShortText );
00047   setToolTip( mExtensiveText );
00048 }
00049 
00050 void KOAlternateLabel::useLongText()
00051 {
00052   mTextTypeFixed = true;
00053   QLabel::setText( mLongText );
00054   this->setToolTip( mExtensiveText );
00055 }
00056 
00057 void KOAlternateLabel::useExtensiveText()
00058 {
00059   mTextTypeFixed = true;
00060   QLabel::setText( mExtensiveText );
00061   this->setToolTip("");
00062 }
00063 
00064 void KOAlternateLabel::useDefaultText()
00065 {
00066   mTextTypeFixed = false;
00067   squeezeTextToLabel();
00068 }
00069 
00070 void KOAlternateLabel::squeezeTextToLabel()
00071 {
00072   if (mTextTypeFixed) return;
00073 
00074   QFontMetrics fm(fontMetrics());
00075   int labelWidth = size().width();
00076   int textWidth = fm.width(mLongText);
00077   int longTextWidth = fm.width(mExtensiveText);
00078   if (longTextWidth <= labelWidth) {
00079     QLabel::setText( mExtensiveText );
00080     this->setToolTip("");
00081   } else if (textWidth <= labelWidth) {
00082     QLabel::setText( mLongText );
00083     this->setToolTip( mExtensiveText );
00084   } else {
00085     QLabel::setText( mShortText );
00086     this->setToolTip( mExtensiveText );
00087   }
00088 }
00089 
00090 void KOAlternateLabel::resizeEvent( QResizeEvent * )
00091 {
00092   squeezeTextToLabel();
00093 }
00094 
00095 QSize KOAlternateLabel::minimumSizeHint() const
00096 {
00097   QSize sh = QLabel::minimumSizeHint();
00098   sh.setWidth(-1);
00099   return sh;
00100 }
00101 
00102 void KOAlternateLabel::setText( const QString &text ) {
00103   mLongText = text;
00104   squeezeTextToLabel();
00105 }
00106 

korganizer

Skip menu "korganizer"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal