subtraction of already painted area: be fool and
[kdelibs.git] / kdeui / kguiitem.cpp
blobc01d2a80aadd0438e0351b2d2e657846c9a7b284
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
4 many thanks to 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.
21 #include <qregexp.h>
22 #include <qstring.h>
23 #include <qiconset.h>
24 #include <qpixmap.h>
26 #include <assert.h>
27 #include <kiconloader.h>
28 #include <kdebug.h>
30 #include "kguiitem.h"
32 class KGuiItem::KGuiItemPrivate
34 public:
35 KGuiItemPrivate()
37 m_enabled = true;
38 m_hasIcon = false;
41 KGuiItemPrivate( const KGuiItemPrivate &rhs )
43 ( *this ) = rhs;
46 KGuiItemPrivate &operator=( const KGuiItemPrivate &rhs )
48 m_text = rhs.m_text;
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;
57 return *this;
60 QString m_text;
61 QString m_toolTip;
62 QString m_whatsThis;
63 QString m_statusText;
64 QString m_iconName;
65 QIconSet m_iconSet;
66 bool m_hasIcon : 1;
67 bool m_enabled : 1;
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;
79 d->m_text = text;
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;
89 d->m_text = text;
90 d->m_toolTip = toolTip;
91 d->m_whatsThis = whatsThis;
92 setIconSet( iconSet );
95 KGuiItem::KGuiItem( const KGuiItem &rhs )
96 : d( 0 )
98 ( *this ) = rhs;
101 KGuiItem &KGuiItem::operator=( const KGuiItem &rhs )
103 if ( d == rhs.d )
104 return *this;
106 assert( rhs.d );
108 delete d;
109 d = new KGuiItemPrivate( *rhs.d );
111 return *this;
114 KGuiItem::~KGuiItem()
116 delete d;
119 QString KGuiItem::text() const
121 return d->m_text;
125 QString KGuiItem::plainText() const
127 const int len = d->m_text.length();
129 if (len == 0)
130 return d->m_text;
132 //Can assume len >= 1 from now on.
133 QString stripped;
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);
149 return stripped;
152 QIconSet KGuiItem::iconSet( KIcon::Group group, int size, KInstance* instance ) const
154 if( d->m_hasIcon )
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() )
163 // {
164 // d->m_hasIcon = false;
165 // return QIconSet();
166 // }
167 // return set;
169 else
171 return d->m_iconSet;
174 else
175 return QIconSet();
178 QString KGuiItem::iconName() const
180 return d->m_iconName;
183 QString KGuiItem::toolTip() const
185 return d->m_toolTip;
188 QString KGuiItem::whatsThis() const
190 return d->m_whatsThis;
193 bool KGuiItem::isEnabled() const
195 return d->m_enabled;
198 bool KGuiItem::hasIcon() const
200 return d->m_hasIcon;
203 void KGuiItem::setText( const QString &text ) {
204 d->m_text=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;
236 // vim: set et sw=4: