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

KDEUI

  • sources
  • kde-4.12
  • kdelibs
  • 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 
30 class KGuiItem::KGuiItemPrivate
31 {
32 public:
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 
69 KGuiItem::KGuiItem() {
70  d = new KGuiItemPrivate;
71 }
72 
73 KGuiItem::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 
83 KGuiItem::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 
93 KGuiItem::KGuiItem( const KGuiItem &rhs )
94  : d( 0 )
95 {
96  ( *this ) = rhs;
97 }
98 
99 KGuiItem &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 
112 KGuiItem::~KGuiItem()
113 {
114  delete d;
115 }
116 
117 QString KGuiItem::text() const
118 {
119  return d->m_text;
120 }
121 
122 
123 QString 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 
151 KIcon 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
165 QIcon 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 
179 QString KGuiItem::iconName() const
180 {
181  return d->m_iconName;
182 }
183 
184 QString KGuiItem::toolTip() const
185 {
186  return d->m_toolTip;
187 }
188 
189 QString KGuiItem::whatsThis() const
190 {
191  return d->m_whatsThis;
192 }
193 
194 bool KGuiItem::isEnabled() const
195 {
196  return d->m_enabled;
197 }
198 
199 bool KGuiItem::hasIcon() const
200 {
201  return d->m_hasIcon;
202 }
203 
204 void KGuiItem::setText( const QString &text )
205 {
206  d->m_text = text;
207 }
208 
209 void KGuiItem::setIcon( const KIcon &icon )
210 {
211  d->m_icon = icon;
212  d->m_iconName.clear();
213  d->m_hasIcon = !icon.isNull();
214 }
215 
216 void KGuiItem::setIconName( const QString &iconName )
217 {
218  d->m_iconName = iconName;
219  d->m_icon = KIcon();
220  d->m_hasIcon = !iconName.isEmpty();
221 }
222 
223 void KGuiItem::setToolTip( const QString &toolTip )
224 {
225  d->m_toolTip = toolTip;
226 }
227 
228 void KGuiItem::setWhatsThis( const QString &whatsThis )
229 {
230  d->m_whatsThis = whatsThis;
231 }
232 
233 void KGuiItem::setEnabled( bool enabled )
234 {
235  d->m_enabled = enabled;
236 }
237 
238 // vim: set et sw=4:
KGuiItem::whatsThis
QString whatsThis() const
Definition: kguiitem.cpp:189
KGuiItem::hasIcon
bool hasIcon() const
Definition: kguiitem.cpp:199
kdebug.h
KIconLoader::global
static KIconLoader * global()
Returns the global icon loader initialized with the global KComponentData.
kiconloader.h
QString
KGuiItem::toolTip
QString toolTip() const
Definition: kguiitem.cpp:184
KGuiItem::KGuiItem
KGuiItem()
Definition: kguiitem.cpp:69
KGuiItem::setText
void setText(const QString &text)
Definition: kguiitem.cpp:204
KGuiItem::~KGuiItem
~KGuiItem()
Definition: kguiitem.cpp:112
KGuiItem::icon
KIcon icon() const
Definition: kguiitem.cpp:151
KGuiItem::setToolTip
void setToolTip(const QString &tooltip)
Definition: kguiitem.cpp:223
KGuiItem
An abstract class for GUI data such as ToolTip and Icon.
Definition: kguiitem.h:36
KGuiItem::iconSet
QIcon iconSet(KIconLoader::Group=KIconLoader::Small, int size=0) const
Definition: kguiitem.cpp:165
KGuiItem::plainText
QString plainText() const
Definition: kguiitem.cpp:123
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:40
KGuiItem::setEnabled
void setEnabled(bool enable)
Definition: kguiitem.cpp:233
KGuiItem::iconName
QString iconName() const
Definition: kguiitem.cpp:179
KGuiItem::setIconName
void setIconName(const QString &iconName)
Definition: kguiitem.cpp:216
KStandardShortcut::whatsThis
QString whatsThis(StandardShortcut)
What's This button.
Definition: kstandardshortcut.cpp:276
KIconLoader::Group
Group
The group of the icon.
Definition: kiconloader.h:127
KComponentData::isValid
bool isValid() const
KGlobal::mainComponent
const KComponentData & mainComponent()
KGuiItem::setWhatsThis
void setWhatsThis(const QString &whatsThis)
Definition: kguiitem.cpp:228
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
KGuiItem::setIcon
void setIcon(const KIcon &iconset)
Definition: kguiitem.cpp:209
KGuiItem::operator=
KGuiItem & operator=(const KGuiItem &rhs)
Definition: kguiitem.cpp:99
KGuiItem::text
QString text() const
Definition: kguiitem.cpp:117
kcomponentdata.h
kicon.h
kguiitem.h
KGuiItem::isEnabled
bool isEnabled() const
Definition: kguiitem.cpp:194
KIconLoader
Iconloader for KDE.
Definition: kiconloader.h:77
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:49:14 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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