• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdeui
 

kdeui

  • kdeui
kguiitem.cpp
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 <tqregexp.h>
22 #include <tqstring.h>
23 #include <tqiconset.h>
24 #include <tqpixmap.h>
25 
26 #include <assert.h>
27 #include <kiconloader.h>
28 #include <kdebug.h>
29 
30 #include "kguiitem.h"
31 
32 class KGuiItem::KGuiItemPrivate
33 {
34 public:
35  KGuiItemPrivate()
36  {
37  m_enabled = true;
38  m_hasIcon = false;
39  }
40 
41  KGuiItemPrivate( const KGuiItemPrivate &rhs )
42  {
43  ( *this ) = rhs;
44  }
45 
46  KGuiItemPrivate &operator=( const KGuiItemPrivate &rhs )
47  {
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;
56 
57  return *this;
58  }
59 
60  TQString m_text;
61  TQString m_toolTip;
62  TQString m_whatsThis;
63  TQString m_statusText;
64  TQString m_iconName;
65  TQIconSet m_iconSet;
66  bool m_hasIcon : 1;
67  bool m_enabled : 1;
68 };
69 
70 
71 KGuiItem::KGuiItem() {
72  d = new KGuiItemPrivate;
73 }
74 
75 KGuiItem::KGuiItem( const TQString &text, const TQString &iconName,
76  const TQString &toolTip, const TQString &whatsThis )
77 {
78  d = new KGuiItemPrivate;
79  d->m_text = text;
80  d->m_toolTip = toolTip;
81  d->m_whatsThis = whatsThis;
82  setIconName( iconName );
83 }
84 
85 KGuiItem::KGuiItem( const TQString &text, const TQIconSet &iconSet,
86  const TQString &toolTip, const TQString &whatsThis )
87 {
88  d = new KGuiItemPrivate;
89  d->m_text = text;
90  d->m_toolTip = toolTip;
91  d->m_whatsThis = whatsThis;
92  setIconSet( iconSet );
93 }
94 
95 KGuiItem::KGuiItem( const KGuiItem &rhs )
96  : d( 0 )
97 {
98  ( *this ) = rhs;
99 }
100 
101 KGuiItem &KGuiItem::operator=( const KGuiItem &rhs )
102 {
103  if ( d == rhs.d )
104  return *this;
105 
106  assert( rhs.d );
107 
108  delete d;
109  d = new KGuiItemPrivate( *rhs.d );
110 
111  return *this;
112 }
113 
114 KGuiItem::~KGuiItem()
115 {
116  delete d;
117 }
118 
119 TQString KGuiItem::text() const
120 {
121  return d->m_text;
122 }
123 
124 
125 TQString KGuiItem::plainText() const
126 {
127  const int len = d->m_text.length();
128 
129  if (len == 0)
130  return d->m_text;
131 
132  //Can assume len >= 1 from now on.
133  TQString stripped;
134 
135  int resultLength = 0;
136  stripped.setLength(len);
137 
138  const TQChar* data = d->m_text.unicode();
139  for ( int pos = 0; pos < len; ++pos )
140  {
141  if ( data[ pos ] != '&' )
142  stripped[ resultLength++ ] = data[ pos ];
143  else if ( pos + 1 < len && data[ pos + 1 ] == '&' )
144  stripped[ resultLength++ ] = data[ pos++ ];
145  }
146 
147  stripped.truncate(resultLength);
148 
149  return stripped;
150 }
151 
152 TQIconSet KGuiItem::iconSet( KIcon::Group group, int size, KInstance* instance ) const
153 {
154  if( d->m_hasIcon )
155  {
156  if( !d->m_iconName.isEmpty())
157  {
158 // some caching here would(?) come handy
159  return instance->iconLoader()->loadIconSet( d->m_iconName, group, size, true, false );
160  }
161  else
162  {
163  return d->m_iconSet;
164  }
165  }
166  else
167  return TQIconSet();
168 }
169 
170 TQString KGuiItem::iconName() const
171 {
172  return d->m_iconName;
173 }
174 
175 TQString KGuiItem::toolTip() const
176 {
177  return d->m_toolTip;
178 }
179 
180 TQString KGuiItem::whatsThis() const
181 {
182  return d->m_whatsThis;
183 }
184 
185 bool KGuiItem::isEnabled() const
186 {
187  return d->m_enabled;
188 }
189 
190 bool KGuiItem::hasIcon() const
191 {
192  return d->m_hasIcon;
193 }
194 
195 void KGuiItem::setText( const TQString &text ) {
196  d->m_text=text;
197 }
198 
199 void KGuiItem::setIconSet( const TQIconSet &iconset )
200 {
201  d->m_iconSet = iconset;
202  d->m_iconName = TQString::null;
203  d->m_hasIcon = !iconset.isNull();
204 }
205 
206 void KGuiItem::setIconName( const TQString &iconName )
207 {
208  d->m_iconName = iconName;
209  d->m_iconSet = TQIconSet();
210  d->m_hasIcon = !iconName.isEmpty();
211 }
212 
213 void KGuiItem::setToolTip( const TQString &toolTip )
214 {
215  d->m_toolTip = toolTip;
216 }
217 
218 void KGuiItem::setWhatsThis( const TQString &whatsThis )
219 {
220  d->m_whatsThis = whatsThis;
221 }
222 
223 void KGuiItem::setEnabled( bool enabled )
224 {
225  d->m_enabled = enabled;
226 }
227 
228 // vim: set et sw=4:
229 

kdeui

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

kdeui

Skip menu "kdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeui by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |