kguiitem.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 QString stripped( d->m_text );
00122 stripped.replace( QRegExp( "&(?!&)" ), QString::null );
00123
00124 return stripped;
00125 }
00126
00127 QIconSet KGuiItem::iconSet( KIcon::Group group, int size, KInstance* instance ) const
00128 {
00129 if( d->m_hasIcon )
00130 {
00131 if( !d->m_iconName.isEmpty())
00132 {
00133
00134 return instance->iconLoader()->loadIconSet( d->m_iconName, group, size );
00135
00136
00137
00138
00139
00140
00141
00142
00143 }
00144 else
00145 {
00146 return d->m_iconSet;
00147 }
00148 }
00149 else
00150 return QIconSet();
00151 }
00152
00153 QString KGuiItem::iconName() const
00154 {
00155 return d->m_iconName;
00156 }
00157
00158 QString KGuiItem::toolTip() const {
00159 return d->m_toolTip;
00160 }
00161 QString KGuiItem::whatsThis() const {
00162 return d->m_whatsThis;
00163 }
00164
00165 bool KGuiItem::isEnabled() const
00166 {
00167 return d->m_enabled;
00168 }
00169
00170 bool KGuiItem::hasIcon() const
00171 {
00172 return d->m_hasIcon;
00173 }
00174
00175 void KGuiItem::setText( const QString &text ) {
00176 d->m_text=text;
00177 }
00178
00179 void KGuiItem::setIconSet( const QIconSet &iconset )
00180 {
00181 d->m_iconSet = iconset;
00182 d->m_iconName = QString::null;
00183 d->m_hasIcon = !iconset.isNull();
00184 }
00185
00186 void KGuiItem::setIconName( const QString &iconName )
00187 {
00188 d->m_iconName = iconName;
00189 d->m_iconSet = QIconSet();
00190 d->m_hasIcon = !iconName.isEmpty();
00191 }
00192
00193 void KGuiItem::setToolTip( const QString &toolTip) {
00194 d->m_toolTip = toolTip;
00195 }
00196 void KGuiItem::setWhatsThis( const QString &whatsThis ) {
00197 d->m_whatsThis = whatsThis;
00198 }
00199 void KGuiItem::setEnabled( bool enabled ){
00200 d->m_enabled = enabled;
00201 }
00202
00203
00204
This file is part of the documentation for kdelibs Version 3.1.0.