# kdeui Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kguiitem.cpp

    00001 /* This file is part of the KDE libraries
    00002     Copyright (C) 2001 Holger Freyther (freyher@yahoo.com)
    00003                   based on ideas from Martijn and Simon
    00004                   many thanks to Simon
    00005
    00006     This library is free software; you can redistribute it and/or
    00007     modify it under the terms of the GNU Library General Public
    00008     License version 2 as published by the Free Software Foundation.
    00009
    00010     This library is distributed in the hope that it will be useful,
    00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013     Library General Public License for more details.
    00014
    00015     You should have received a copy of the GNU Library General Public License
    00016     along with this library; see the file COPYING.LIB.  If not, write to
    00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018     Boston, MA 02111-1307, USA.
    00019 */
    00020
    00021 #include <qregexp.h>
    00022 #include <qstring.h>
    00023 #include <qiconset.h>
    00024 #include <qpixmap.h>
    00025
    00026 #include <assert.h>
    00027 #include <kiconloader.h>
    00028 #include <kdebug.h>
    00029
    00030 #include "kguiitem.h"
    00031
    00032 class KGuiItem::KGuiItemPrivate
    00033 {
    00034 public:
    00035     KGuiItemPrivate()
    00036     {
    00037         m_enabled = true;
    00038         m_hasIcon = false;
    00039     }
    00040
    00041     KGuiItemPrivate( const KGuiItemPrivate &rhs )
    00042     {
    00043         (*this ) = rhs;
    00044     }
    00045
    00046     KGuiItemPrivate &operator=( const KGuiItemPrivate &rhs )
    00047     {
    00048         m_text = rhs.m_text;
    00049         m_iconSet = rhs.m_iconSet;
    00050         m_iconName = rhs.m_iconName;
    00051         m_toolTip = rhs.m_toolTip;
    00052         m_whatsThis = rhs.m_whatsThis;
    00053         m_statusText = rhs.m_statusText;
    00054         m_enabled = rhs.m_enabled;
    00055         m_hasIcon = rhs.m_hasIcon;
    00056
    00057         return *this;
    00058     }
    00059
    00060     QString m_text;
    00061     QString m_toolTip;
    00062     QString m_whatsThis;
    00063     QString m_statusText;
    00064     QString m_iconName;
    00065     QIconSet m_iconSet;
    00066     bool m_hasIcon : 1;
    00067     bool m_enabled : 1;
    00068 };
    00069
    00070
    00071 KGuiItem::KGuiItem() {
    00072     d = new KGuiItemPrivate;
    00073 }
    00074
    00075 KGuiItem::KGuiItem( const QString &text,    const QString &iconName,
    00076                     const QString &toolTip, const QString &whatsThis )
    00077 {
    00078     d = new KGuiItemPrivate;
    00079     d->m_text = text;
    00080     d->m_toolTip =  toolTip;
    00081     d->m_whatsThis = whatsThis;
    00082     setIconName( iconName );
    00083 }
    00084
    00085 KGuiItem::KGuiItem( const QString &text,    const QIconSet &iconSet,
    00086                     const QString &toolTip, const QString &whatsThis )
    00087 {
    00088     d = new KGuiItemPrivate;
    00089     d->m_text = text;
    00090     d->m_toolTip =  toolTip;
    00091     d->m_whatsThis = whatsThis;
    00092     setIconSet( iconSet );
    00093 }
    00094
    00095 KGuiItem::KGuiItem( const KGuiItem &rhs )
    00096     : d( 0 )
    00097 {
    00098     (*this) = rhs;
    00099 }
    00100
    00101 KGuiItem &KGuiItem::operator=( const KGuiItem &rhs ) {
    00102     if ( d == rhs.d )
    00103         return *this;
    00104
    00105     assert( rhs.d );
    00106
    00107     delete d;
    00108     d = new KGuiItemPrivate( *rhs.d );
    00109
    00110     return *this;
    00111 }
    00112
    00113 KGuiItem::~KGuiItem() {
    00114     delete d;
    00115 }
    00116
    00117 QString KGuiItem::text() const {
    00118     return d->m_text;
    00119 }
    00120 QString KGuiItem::plainText() const {
    00121     int len = d->m_text.length();
    00122
    00123     if (len == 0)
    00124         return d->m_text;
    00125
    00126     //Can assume len >= 1 from now on.
    00127     QString stripped;
    00128
    00129     int resultLength = 0;
    00130     stripped.setLength(len);
    00131
    00132     const QChar* data    = d->m_text.unicode();
    00133     for (int pos = 0; pos < len; pos++)
    00134     {
    00135 #if QT_VERSION >= 0x030200
    00136         if (data[pos] != '&')
    00137             stripped[resultLength++] = data[pos];
    00138         else if (pos+1<len && data[pos+1]=='&')
    00139             stripped[resultLength++] = data[pos++];
    00140 #else
    00141         //We pass through any non-ampersand character,
    00142         //and any ampersand that's preceded by an ampersand
    00143         if (data[pos] != '&' || (pos >= 1 && data[pos-1] == '&') )
    00144             stripped[resultLength++] = data[pos];
    00145 #endif
    00146     }
    00147
    00148     stripped.truncate(resultLength);
    00149
    00150     return stripped;
    00151 }
    00152
    00153 QIconSet KGuiItem::iconSet( KIcon::Group group, int size, KInstance* instance ) const
    00154 {
    00155     if( d->m_hasIcon )
    00156     {
    00157         if( !d->m_iconName.isEmpty())
    00158         {
    00159 // some caching here would(?) come handy
    00160             return instance->iconLoader()->loadIconSet( d->m_iconName, group, size );
    00161 // here is a little problem that with delayed icon loading
    00162 // we can't check if the icon really exists ... so what ...
    00163 //            if( set.isNull() )
    00164 //            {
    00165 //                d->m_hasIcon = false;
    00166 //                return QIconSet();
    00167 //            }
    00168 //            return set;
    00169         }
    00170         else
    00171         {
    00172             return d->m_iconSet;
    00173         }
    00174     }
    00175     else
    00176         return QIconSet();
    00177 }
    00178
    00179 QString KGuiItem::iconName() const
    00180 {
    00181     return d->m_iconName;
    00182 }
    00183
    00184 QString KGuiItem::toolTip() const {
    00185     return d->m_toolTip;
    00186 }
    00187 QString KGuiItem::whatsThis() const {
    00188     return d->m_whatsThis;
    00189 }
    00190
    00191 bool KGuiItem::isEnabled() const
    00192 {
    00193     return d->m_enabled;
    00194 }
    00195
    00196 bool KGuiItem::hasIcon() const
    00197 {
    00198     return d->m_hasIcon;
    00199 }
    00200
    00201 void KGuiItem::setText( const QString &text ) {
    00202     d->m_text=text;
    00203 }
    00204
    00205 void KGuiItem::setIconSet( const QIconSet &iconset )
    00206 {
    00207     d->m_iconSet = iconset;
    00208     d->m_iconName = QString::null;
    00209     d->m_hasIcon = !iconset.isNull();
    00210 }
    00211
    00212 void KGuiItem::setIconName( const QString &iconName )
    00213 {
    00214     d->m_iconName = iconName;
    00215     d->m_iconSet = QIconSet();
    00216     d->m_hasIcon = !iconName.isEmpty();
    00217 }
    00218
    00219 void KGuiItem::setToolTip( const QString &toolTip) {
    00220     d->m_toolTip = toolTip;
    00221 }
    00222 void KGuiItem::setWhatsThis( const QString &whatsThis ) {
    00223     d->m_whatsThis = whatsThis;
    00224 }
    00225 void KGuiItem::setEnabled( bool enabled ){
    00226     d->m_enabled = enabled;
    00227 }
    00228
    00229 /* vim: et sw=4
    00230  */

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:56:52 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001