You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
230 lines
4.8 KiB
230 lines
4.8 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 2001 Holger Freyther (freyher@yahoo.com)
|
||
|
based on ideas from Martijn and Simon
|
||
|
many thanks to Simon
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License version 2 as published by the Free Software Foundation.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqregexp.h>
|
||
|
#include <tqstring.h>
|
||
|
#include <tqiconset.h>
|
||
|
#include <tqpixmap.h>
|
||
15 years ago
|
|
||
|
#include <assert.h>
|
||
|
#include <kiconloader.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
#include "kguiitem.h"
|
||
|
|
||
|
class KGuiItem::KGuiItemPrivate
|
||
|
{
|
||
|
public:
|
||
|
KGuiItemPrivate()
|
||
|
{
|
||
|
m_enabled = true;
|
||
|
m_hasIcon = false;
|
||
|
}
|
||
|
|
||
|
KGuiItemPrivate( const KGuiItemPrivate &rhs )
|
||
|
{
|
||
|
( *this ) = rhs;
|
||
|
}
|
||
|
|
||
|
KGuiItemPrivate &operator=( const KGuiItemPrivate &rhs )
|
||
|
{
|
||
|
m_text = rhs.m_text;
|
||
|
m_iconSet = rhs.m_iconSet;
|
||
|
m_iconName = rhs.m_iconName;
|
||
|
m_toolTip = rhs.m_toolTip;
|
||
|
m_whatsThis = rhs.m_whatsThis;
|
||
|
m_statusText = rhs.m_statusText;
|
||
|
m_enabled = rhs.m_enabled;
|
||
|
m_hasIcon = rhs.m_hasIcon;
|
||
|
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString m_text;
|
||
|
TQString m_toolTip;
|
||
|
TQString m_whatsThis;
|
||
|
TQString m_statusText;
|
||
|
TQString m_iconName;
|
||
|
TQIconSet m_iconSet;
|
||
15 years ago
|
bool m_hasIcon : 1;
|
||
|
bool m_enabled : 1;
|
||
|
};
|
||
|
|
||
|
|
||
|
KGuiItem::KGuiItem() {
|
||
|
d = new KGuiItemPrivate;
|
||
|
}
|
||
|
|
||
15 years ago
|
KGuiItem::KGuiItem( const TQString &text, const TQString &iconName,
|
||
|
const TQString &toolTip, const TQString &whatsThis )
|
||
15 years ago
|
{
|
||
|
d = new KGuiItemPrivate;
|
||
|
d->m_text = text;
|
||
|
d->m_toolTip = toolTip;
|
||
|
d->m_whatsThis = whatsThis;
|
||
|
setIconName( iconName );
|
||
|
}
|
||
|
|
||
15 years ago
|
KGuiItem::KGuiItem( const TQString &text, const TQIconSet &iconSet,
|
||
|
const TQString &toolTip, const TQString &whatsThis )
|
||
15 years ago
|
{
|
||
|
d = new KGuiItemPrivate;
|
||
|
d->m_text = text;
|
||
|
d->m_toolTip = toolTip;
|
||
|
d->m_whatsThis = whatsThis;
|
||
|
setIconSet( iconSet );
|
||
|
}
|
||
|
|
||
|
KGuiItem::KGuiItem( const KGuiItem &rhs )
|
||
|
: d( 0 )
|
||
|
{
|
||
|
( *this ) = rhs;
|
||
|
}
|
||
|
|
||
|
KGuiItem &KGuiItem::operator=( const KGuiItem &rhs )
|
||
|
{
|
||
|
if ( d == rhs.d )
|
||
|
return *this;
|
||
|
|
||
|
assert( rhs.d );
|
||
|
|
||
|
delete d;
|
||
|
d = new KGuiItemPrivate( *rhs.d );
|
||
|
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
|
KGuiItem::~KGuiItem()
|
||
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KGuiItem::text() const
|
||
15 years ago
|
{
|
||
|
return d->m_text;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQString KGuiItem::plainText() const
|
||
15 years ago
|
{
|
||
|
const int len = d->m_text.length();
|
||
|
|
||
|
if (len == 0)
|
||
|
return d->m_text;
|
||
|
|
||
|
//Can assume len >= 1 from now on.
|
||
15 years ago
|
TQString stripped;
|
||
15 years ago
|
|
||
|
int resultLength = 0;
|
||
|
stripped.setLength(len);
|
||
|
|
||
14 years ago
|
const TQChar* data = d->m_text.tqunicode();
|
||
15 years ago
|
for ( int pos = 0; pos < len; ++pos )
|
||
|
{
|
||
|
if ( data[ pos ] != '&' )
|
||
|
stripped[ resultLength++ ] = data[ pos ];
|
||
|
else if ( pos + 1 < len && data[ pos + 1 ] == '&' )
|
||
|
stripped[ resultLength++ ] = data[ pos++ ];
|
||
|
}
|
||
|
|
||
|
stripped.truncate(resultLength);
|
||
|
|
||
|
return stripped;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQIconSet KGuiItem::iconSet( KIcon::Group group, int size, KInstance* instance ) const
|
||
15 years ago
|
{
|
||
|
if( d->m_hasIcon )
|
||
|
{
|
||
|
if( !d->m_iconName.isEmpty())
|
||
|
{
|
||
|
// some caching here would(?) come handy
|
||
|
return instance->iconLoader()->loadIconSet( d->m_iconName, group, size, true, false );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return d->m_iconSet;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
15 years ago
|
return TQIconSet();
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQString KGuiItem::iconName() const
|
||
15 years ago
|
{
|
||
|
return d->m_iconName;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KGuiItem::toolTip() const
|
||
15 years ago
|
{
|
||
|
return d->m_toolTip;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KGuiItem::whatsThis() const
|
||
15 years ago
|
{
|
||
|
return d->m_whatsThis;
|
||
|
}
|
||
|
|
||
|
bool KGuiItem::isEnabled() const
|
||
|
{
|
||
|
return d->m_enabled;
|
||
|
}
|
||
|
|
||
|
bool KGuiItem::hasIcon() const
|
||
|
{
|
||
|
return d->m_hasIcon;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KGuiItem::setText( const TQString &text ) {
|
||
15 years ago
|
d->m_text=text;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KGuiItem::setIconSet( const TQIconSet &iconset )
|
||
15 years ago
|
{
|
||
|
d->m_iconSet = iconset;
|
||
15 years ago
|
d->m_iconName = TQString::null;
|
||
15 years ago
|
d->m_hasIcon = !iconset.isNull();
|
||
|
}
|
||
|
|
||
15 years ago
|
void KGuiItem::setIconName( const TQString &iconName )
|
||
15 years ago
|
{
|
||
|
d->m_iconName = iconName;
|
||
15 years ago
|
d->m_iconSet = TQIconSet();
|
||
15 years ago
|
d->m_hasIcon = !iconName.isEmpty();
|
||
|
}
|
||
|
|
||
15 years ago
|
void KGuiItem::setToolTip( const TQString &toolTip )
|
||
15 years ago
|
{
|
||
|
d->m_toolTip = toolTip;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KGuiItem::setWhatsThis( const TQString &whatsThis )
|
||
15 years ago
|
{
|
||
|
d->m_whatsThis = whatsThis;
|
||
|
}
|
||
|
|
||
|
void KGuiItem::setEnabled( bool enabled )
|
||
|
{
|
||
|
d->m_enabled = enabled;
|
||
|
}
|
||
|
|
||
|
// vim: set et sw=4:
|
||
|
|