1 /* This file is part of the KDE libraries
2 Copyright (C) 2001 Holger Freyther (freyher@yahoo.com)
3 based on ideas from Martijn and Simon
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
18 Boston, MA 02110-1301, USA.
27 #include <kiconloader.h>
32 class KGuiItem::KGuiItemPrivate
41 KGuiItemPrivate( const KGuiItemPrivate
&rhs
)
46 KGuiItemPrivate
&operator=( const KGuiItemPrivate
&rhs
)
49 m_iconSet
= rhs
.m_iconSet
;
50 m_iconName
= rhs
.m_iconName
;
51 m_toolTip
= rhs
.m_toolTip
;
52 m_whatsThis
= rhs
.m_whatsThis
;
53 m_statusText
= rhs
.m_statusText
;
54 m_enabled
= rhs
.m_enabled
;
55 m_hasIcon
= rhs
.m_hasIcon
;
71 KGuiItem::KGuiItem() {
72 d
= new KGuiItemPrivate
;
75 KGuiItem::KGuiItem( const QString
&text
, const QString
&iconName
,
76 const QString
&toolTip
, const QString
&whatsThis
)
78 d
= new KGuiItemPrivate
;
80 d
->m_toolTip
= toolTip
;
81 d
->m_whatsThis
= whatsThis
;
82 setIconName( iconName
);
85 KGuiItem::KGuiItem( const QString
&text
, const QIconSet
&iconSet
,
86 const QString
&toolTip
, const QString
&whatsThis
)
88 d
= new KGuiItemPrivate
;
90 d
->m_toolTip
= toolTip
;
91 d
->m_whatsThis
= whatsThis
;
92 setIconSet( iconSet
);
95 KGuiItem::KGuiItem( const KGuiItem
&rhs
)
101 KGuiItem
&KGuiItem::operator=( const KGuiItem
&rhs
)
109 d
= new KGuiItemPrivate( *rhs
.d
);
114 KGuiItem::~KGuiItem()
119 QString
KGuiItem::text() const
125 QString
KGuiItem::plainText() const
127 const int len
= d
->m_text
.length();
132 //Can assume len >= 1 from now on.
135 int resultLength
= 0;
136 stripped
.setLength(len
);
138 const QChar
* data
= d
->m_text
.unicode();
139 for ( int pos
= 0; pos
< len
; ++pos
)
141 if ( data
[ pos
] != '&' )
142 stripped
[ resultLength
++ ] = data
[ pos
];
143 else if ( pos
+ 1 < len
&& data
[ pos
+ 1 ] == '&' )
144 stripped
[ resultLength
++ ] = data
[ pos
++ ];
147 stripped
.truncate(resultLength
);
152 QIconSet
KGuiItem::iconSet( KIcon::Group group
, int size
, KInstance
* instance
) const
156 if( !d
->m_iconName
.isEmpty())
158 // some caching here would(?) come handy
159 return instance
->iconLoader()->loadIconSet( d
->m_iconName
, group
, size
);
160 // here is a little problem that with delayed icon loading
161 // we can't check if the icon really exists ... so what ...
162 // if( set.isNull() )
164 // d->m_hasIcon = false;
165 // return QIconSet();
178 QString
KGuiItem::iconName() const
180 return d
->m_iconName
;
183 QString
KGuiItem::toolTip() const
188 QString
KGuiItem::whatsThis() const
190 return d
->m_whatsThis
;
193 bool KGuiItem::isEnabled() const
198 bool KGuiItem::hasIcon() const
203 void KGuiItem::setText( const QString
&text
) {
207 void KGuiItem::setIconSet( const QIconSet
&iconset
)
209 d
->m_iconSet
= iconset
;
210 d
->m_iconName
= QString::null
;
211 d
->m_hasIcon
= !iconset
.isNull();
214 void KGuiItem::setIconName( const QString
&iconName
)
216 d
->m_iconName
= iconName
;
217 d
->m_iconSet
= QIconSet();
218 d
->m_hasIcon
= !iconName
.isEmpty();
221 void KGuiItem::setToolTip( const QString
&toolTip
)
223 d
->m_toolTip
= toolTip
;
226 void KGuiItem::setWhatsThis( const QString
&whatsThis
)
228 d
->m_whatsThis
= whatsThis
;
231 void KGuiItem::setEnabled( bool enabled
)
233 d
->m_enabled
= enabled
;