• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • kdeui
  • util
kguiitem.cpp
Go to the documentation of this file.
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
5
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.
9
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.
14
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 Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "kguiitem.h"
22
23#include <kiconloader.h> // TODO remove
24#include <kdebug.h>
25#include <kicon.h>
26#include <kcomponentdata.h>
27
28#include <assert.h>
29
30class KGuiItem::KGuiItemPrivate
31{
32public:
33 KGuiItemPrivate()
34 {
35 m_enabled = true;
36 m_hasIcon = false;
37 }
38
39 KGuiItemPrivate( const KGuiItemPrivate &rhs )
40 {
41 ( *this ) = rhs;
42 }
43
44 KGuiItemPrivate &operator=( const KGuiItemPrivate &rhs )
45 {
46 m_text = rhs.m_text;
47 m_icon = rhs.m_icon;
48 m_iconName = rhs.m_iconName;
49 m_toolTip = rhs.m_toolTip;
50 m_whatsThis = rhs.m_whatsThis;
51 m_statusText = rhs.m_statusText;
52 m_enabled = rhs.m_enabled;
53 m_hasIcon = rhs.m_hasIcon;
54
55 return *this;
56 }
57
58 QString m_text;
59 QString m_toolTip;
60 QString m_whatsThis;
61 QString m_statusText;
62 QString m_iconName;
63 KIcon m_icon;
64 bool m_hasIcon : 1;
65 bool m_enabled : 1;
66};
67
68
69KGuiItem::KGuiItem() {
70 d = new KGuiItemPrivate;
71}
72
73KGuiItem::KGuiItem( const QString &text, const QString &iconName,
74 const QString &toolTip, const QString &whatsThis )
75{
76 d = new KGuiItemPrivate;
77 d->m_text = text;
78 d->m_toolTip = toolTip;
79 d->m_whatsThis = whatsThis;
80 setIconName( iconName );
81}
82
83KGuiItem::KGuiItem( const QString &text, const KIcon &icon,
84 const QString &toolTip, const QString &whatsThis )
85{
86 d = new KGuiItemPrivate;
87 d->m_text = text;
88 d->m_toolTip = toolTip;
89 d->m_whatsThis = whatsThis;
90 setIcon( icon );
91}
92
93KGuiItem::KGuiItem( const KGuiItem &rhs )
94 : d( 0 )
95{
96 ( *this ) = rhs;
97}
98
99KGuiItem &KGuiItem::operator=( const KGuiItem &rhs )
100{
101 if ( d == rhs.d )
102 return *this;
103
104 assert( rhs.d );
105
106 delete d;
107 d = new KGuiItemPrivate( *rhs.d );
108
109 return *this;
110}
111
112KGuiItem::~KGuiItem()
113{
114 delete d;
115}
116
117QString KGuiItem::text() const
118{
119 return d->m_text;
120}
121
122
123QString KGuiItem::plainText() const
124{
125 const int len = d->m_text.length();
126
127 if (len == 0)
128 return d->m_text;
129
130 //Can assume len >= 1 from now on.
131 QString stripped;
132
133 int resultLength = 0;
134 stripped.resize(len);
135
136 const QChar* data = d->m_text.unicode();
137 for ( int pos = 0; pos < len; ++pos )
138 {
139 if ( data[ pos ] != '&' )
140 stripped[ resultLength++ ] = data[ pos ];
141 else if ( pos + 1 < len && data[ pos + 1 ] == '&' )
142 stripped[ resultLength++ ] = data[ pos++ ];
143 }
144
145 stripped.truncate(resultLength);
146
147 return stripped;
148}
149
150
151KIcon KGuiItem::icon( ) const
152{
153 if (d->m_hasIcon) {
154 if (!d->m_iconName.isEmpty()) {
155 return KIcon(d->m_iconName, KGlobal::mainComponent().isValid() ? KIconLoader::global() : 0);
156 } else {
157 return d->m_icon;
158 }
159 }
160 return KIcon();
161}
162
163// deprecated
164#ifndef KDE_NO_DEPRECATED
165QIcon KGuiItem::iconSet( KIconLoader::Group group, int size ) const
166{
167 if (d->m_hasIcon && KGlobal::mainComponent().isValid()) {
168 if( !d->m_iconName.isEmpty()) {
169 KIconLoader* iconLoader = KIconLoader::global();
170 return iconLoader->loadIconSet( d->m_iconName, group, size );
171 } else {
172 return d->m_icon;
173 }
174 } else
175 return QIcon();
176}
177#endif
178
179QString KGuiItem::iconName() const
180{
181 return d->m_iconName;
182}
183
184QString KGuiItem::toolTip() const
185{
186 return d->m_toolTip;
187}
188
189QString KGuiItem::whatsThis() const
190{
191 return d->m_whatsThis;
192}
193
194bool KGuiItem::isEnabled() const
195{
196 return d->m_enabled;
197}
198
199bool KGuiItem::hasIcon() const
200{
201 return d->m_hasIcon;
202}
203
204void KGuiItem::setText( const QString &text )
205{
206 d->m_text = text;
207}
208
209void KGuiItem::setIcon( const KIcon &icon )
210{
211 d->m_icon = icon;
212 d->m_iconName.clear();
213 d->m_hasIcon = !icon.isNull();
214}
215
216void KGuiItem::setIconName( const QString &iconName )
217{
218 d->m_iconName = iconName;
219 d->m_icon = KIcon();
220 d->m_hasIcon = !iconName.isEmpty();
221}
222
223void KGuiItem::setToolTip( const QString &toolTip )
224{
225 d->m_toolTip = toolTip;
226}
227
228void KGuiItem::setWhatsThis( const QString &whatsThis )
229{
230 d->m_whatsThis = whatsThis;
231}
232
233void KGuiItem::setEnabled( bool enabled )
234{
235 d->m_enabled = enabled;
236}
237
238// vim: set et sw=4:
KComponentData::isValid
bool isValid() const
KGuiItem
An abstract class for GUI data such as ToolTip and Icon.
Definition: kguiitem.h:37
KGuiItem::icon
KIcon icon() const
Definition: kguiitem.cpp:151
KGuiItem::operator=
KGuiItem & operator=(const KGuiItem &rhs)
Definition: kguiitem.cpp:99
KGuiItem::hasIcon
bool hasIcon() const
Definition: kguiitem.cpp:199
KGuiItem::toolTip
QString toolTip() const
Definition: kguiitem.cpp:184
KGuiItem::whatsThis
QString whatsThis() const
Definition: kguiitem.cpp:189
KGuiItem::text
QString text() const
Definition: kguiitem.cpp:117
KGuiItem::setWhatsThis
void setWhatsThis(const QString &whatsThis)
Definition: kguiitem.cpp:228
KGuiItem::iconSet
QIcon iconSet(KIconLoader::Group=KIconLoader::Small, int size=0) const
Definition: kguiitem.cpp:165
KGuiItem::isEnabled
bool isEnabled() const
Definition: kguiitem.cpp:194
KGuiItem::KGuiItem
KGuiItem()
Definition: kguiitem.cpp:69
KGuiItem::setToolTip
void setToolTip(const QString &tooltip)
Definition: kguiitem.cpp:223
KGuiItem::iconName
QString iconName() const
Definition: kguiitem.cpp:179
KGuiItem::setText
void setText(const QString &text)
Definition: kguiitem.cpp:204
KGuiItem::setEnabled
void setEnabled(bool enable)
Definition: kguiitem.cpp:233
KGuiItem::setIcon
void setIcon(const KIcon &iconset)
Definition: kguiitem.cpp:209
KGuiItem::plainText
QString plainText() const
Definition: kguiitem.cpp:123
KGuiItem::~KGuiItem
~KGuiItem()
Definition: kguiitem.cpp:112
KGuiItem::setIconName
void setIconName(const QString &iconName)
Definition: kguiitem.cpp:216
KIconLoader
Iconloader for KDE.
Definition: kiconloader.h:78
KIconLoader::Group
Group
The group of the icon.
Definition: kiconloader.h:127
KIconLoader::loadIconSet
QIcon loadIconSet(const QString &name, KIconLoader::Group group, int size=0, bool canReturnNull=false)
Creates an icon set, that will do on-demand loading of the icon.
Definition: kiconloader.cpp:1506
KIconLoader::global
static KIconLoader * global()
Returns the global icon loader initialized with the global KComponentData.
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:41
kcomponentdata.h
kdebug.h
kguiitem.h
kicon.h
kiconloader.h
KGlobal::mainComponent
const KComponentData & mainComponent()
group
group
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal