• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdeutils
  • Sitemap
  • Contact Us
 

klaptopdaemon

krichtextlabel.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2005 Waldo Bastian <bastian@kde.org>
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 "krichtextlabel.h"
00020 
00021 
00022 #include <q3stylesheet.h>
00023 #include <q3simplerichtext.h>
00024 //Added by qt3to4:
00025 #include <QLabel>
00026 
00027 #include <kglobalsettings.h>
00028 
00029 static QString qrichtextify( const QString& text )
00030 {
00031   if ( text.isEmpty() || text[0] == '<' )
00032     return text;
00033 
00034   QStringList lines = QStringList::split('\n', text);
00035   for(QStringList::Iterator it = lines.begin(); it != lines.end(); ++it)
00036   {
00037     *it = Q3StyleSheet::convertFromPlainText( *it, Q3StyleSheetItem::WhiteSpaceNormal );
00038   }
00039 
00040   return lines.join(QString::null); //krazy:exclude=nullstrassign for old broken gcc
00041 }
00042 
00043 KRichTextLabel::KRichTextLabel( const QString &text , QWidget *parent )
00044  : QLabel ( parent ) {
00045   m_defaultWidth = qMin(400, KGlobalSettings::desktopGeometry(this).width()*2/5);
00046   setWordWrap(true);
00047   setText(text);
00048 }
00049 
00050 KRichTextLabel::KRichTextLabel( QWidget *parent )
00051  : QLabel ( parent ) {
00052   m_defaultWidth = qMin(400, KGlobalSettings::desktopGeometry(this).width()*2/5);
00053   setWordWrap(true);
00054 }
00055 
00056 void KRichTextLabel::setDefaultWidth(int defaultWidth)
00057 {
00058   m_defaultWidth = defaultWidth;
00059   updateGeometry();
00060 }
00061 
00062 QSizePolicy KRichTextLabel::sizePolicy() const
00063 {
00064   return QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum, false);
00065 }
00066 
00067 QSize KRichTextLabel::minimumSizeHint() const
00068 {
00069   QString qt_text = qrichtextify( text() );
00070   int pref_width = 0;
00071   int pref_height = 0;
00072   Q3SimpleRichText rt(qt_text, font());
00073   pref_width = m_defaultWidth;
00074   rt.setWidth(pref_width);
00075   int used_width = rt.widthUsed();
00076   if (used_width <= pref_width)
00077   {
00078     while(true)
00079     {
00080       int new_width = (used_width * 9) / 10;
00081       rt.setWidth(new_width);
00082       int new_height = rt.height();
00083       if (new_height > pref_height)
00084         break;
00085       used_width = rt.widthUsed();
00086       if (used_width > new_width)
00087         break;
00088     }
00089     pref_width = used_width;
00090   }
00091   else
00092   {
00093     if (used_width > (pref_width *2))
00094       pref_width = pref_width *2;
00095     else
00096       pref_width = used_width;
00097   }
00098 
00099   return QSize(pref_width, rt.height());
00100 }
00101 
00102 QSize KRichTextLabel::sizeHint() const
00103 {
00104   return minimumSizeHint();
00105 }
00106 
00107 void KRichTextLabel::setText( const QString &text ) {
00108   QLabel::setText(text);
00109 }
00110 
00111 void KRichTextLabel::virtual_hook( int, void* )
00112 { /*BASE::virtual_hook( id, data );*/ }
00113 
00114 #include "krichtextlabel.moc"

klaptopdaemon

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

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdelirc
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • kjots
  • klaptopdaemon
  • kmilo
  • ksim
  • ktimer
  • kwallet
  • superkaramba
Generated for kdeutils 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