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

tdeui

  • tdeui
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( TDEIcon::Group group, int size, TDEInstance* 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  {
168  return TQIconSet();
169  }
170 }
171 
172 TQString KGuiItem::iconName() const
173 {
174  return d->m_iconName;
175 }
176 
177 TQString KGuiItem::toolTip() const
178 {
179  return d->m_toolTip;
180 }
181 
182 TQString KGuiItem::whatsThis() const
183 {
184  return d->m_whatsThis;
185 }
186 
187 bool KGuiItem::isEnabled() const
188 {
189  return d->m_enabled;
190 }
191 
192 bool KGuiItem::hasIcon() const
193 {
194  return d->m_hasIcon;
195 }
196 
197 void KGuiItem::setText( const TQString &text ) {
198  d->m_text=text;
199 }
200 
201 void KGuiItem::setIconSet( const TQIconSet &iconset )
202 {
203  d->m_iconSet = iconset;
204  d->m_iconName = TQString::null;
205  d->m_hasIcon = !iconset.isNull();
206 }
207 
208 void KGuiItem::setIconName( const TQString &iconName )
209 {
210  d->m_iconName = iconName;
211  d->m_iconSet = TQIconSet();
212  d->m_hasIcon = !iconName.isEmpty();
213 }
214 
215 void KGuiItem::setToolTip( const TQString &toolTip )
216 {
217  d->m_toolTip = toolTip;
218 }
219 
220 void KGuiItem::setWhatsThis( const TQString &whatsThis )
221 {
222  d->m_whatsThis = whatsThis;
223 }
224 
225 void KGuiItem::setEnabled( bool enabled )
226 {
227  d->m_enabled = enabled;
228 }
KGuiItem
An abstract class for GUI data such as ToolTip and Icon.
Definition: kguiitem.h:39
KGuiItem::hasIcon
bool hasIcon() const
returns whether an icon is defined, doesn't tell if it really exists
Definition: kguiitem.cpp:192
TDEIconLoader::loadIconSet
TQIconSet loadIconSet(const TQString &name, TDEIcon::Group group, int size, bool canReturnNull, bool immediateExistenceCheck)
TDEIcon::Group
Group
TDEInstance
TDEInstance::iconLoader
TDEIconLoader * iconLoader() const
KNotifyClient::instance
TDEInstance * instance()
TDEStdAccel::whatsThis
TQString whatsThis(StdAccel id)

tdeui

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

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.1
This website is maintained by Timothy Pearson.