author | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
commit | b9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff) | |
tree | 2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /microkde/kdeui/kguiitem.cpp | |
download | kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2 |
Initial revision
-rw-r--r-- | microkde/kdeui/kguiitem.cpp | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/microkde/kdeui/kguiitem.cpp b/microkde/kdeui/kguiitem.cpp new file mode 100644 index 0000000..828c5e6 --- a/dev/null +++ b/microkde/kdeui/kguiitem.cpp | |||
@@ -0,0 +1,205 @@ | |||
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., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | #include <qregexp.h> | ||
22 | #include <qstring.h> | ||
23 | #include <qiconset.h> | ||
24 | #include <qpixmap.h> | ||
25 | |||
26 | #include <assert.h> | ||
27 | //US #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 | QString m_text; | ||
61 | QString m_toolTip; | ||
62 | QString m_whatsThis; | ||
63 | QString m_statusText; | ||
64 | QString m_iconName; | ||
65 | QIconSet 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 QString &text, const QString &iconName, | ||
76 | const QString &toolTip, const QString &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 QString &text, const QIconSet &iconSet, | ||
86 | const QString &toolTip, const QString &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 | if ( d == rhs.d ) | ||
103 | return *this; | ||
104 | |||
105 | assert( rhs.d ); | ||
106 | |||
107 | delete d; | ||
108 | d = new KGuiItemPrivate( *rhs.d ); | ||
109 | |||
110 | return *this; | ||
111 | } | ||
112 | |||
113 | KGuiItem::~KGuiItem() { | ||
114 | delete d; | ||
115 | } | ||
116 | |||
117 | QString KGuiItem::text() const { | ||
118 | return d->m_text; | ||
119 | } | ||
120 | QString KGuiItem::plainText() const { | ||
121 | QString stripped( d->m_text ); | ||
122 | stripped.replace( QRegExp( "&(?!&)" ), QString::null ); | ||
123 | |||
124 | return stripped; | ||
125 | } | ||
126 | |||
127 | QIconSet KGuiItem::iconSet( KIcon::Group group, int size /*US, KInstance* instance */ ) const | ||
128 | { | ||
129 | if( d->m_hasIcon ) | ||
130 | { | ||
131 | if( !d->m_iconName.isEmpty()) | ||
132 | { | ||
133 | // some caching here would(?) come handy | ||
134 | //US return instance->iconLoader()->loadIconSet( d->m_iconName, group, size ); | ||
135 | return KGlobal::iconLoader()->loadIconSet( d->m_iconName); | ||
136 | // here is a little problem that with delayed icon loading | ||
137 | // we can't check if the icon really exists ... so what ... | ||
138 | // if( set.isNull() ) | ||
139 | // { | ||
140 | // d->m_hasIcon = false; | ||
141 | // return QIconSet(); | ||
142 | // } | ||
143 | // return set; | ||
144 | } | ||
145 | else | ||
146 | { | ||
147 | return d->m_iconSet; | ||
148 | } | ||
149 | } | ||
150 | else | ||
151 | return QIconSet(); | ||
152 | } | ||
153 | |||
154 | QString KGuiItem::iconName() const | ||
155 | { | ||
156 | return d->m_iconName; | ||
157 | } | ||
158 | |||
159 | QString KGuiItem::toolTip() const { | ||
160 | return d->m_toolTip; | ||
161 | } | ||
162 | QString KGuiItem::whatsThis() const { | ||
163 | return d->m_whatsThis; | ||
164 | } | ||
165 | |||
166 | bool KGuiItem::isEnabled() const | ||
167 | { | ||
168 | return d->m_enabled; | ||
169 | } | ||
170 | |||
171 | bool KGuiItem::hasIcon() const | ||
172 | { | ||
173 | return d->m_hasIcon; | ||
174 | } | ||
175 | |||
176 | void KGuiItem::setText( const QString &text ) { | ||
177 | d->m_text=text; | ||
178 | } | ||
179 | |||
180 | void KGuiItem::setIconSet( const QIconSet &iconset ) | ||
181 | { | ||
182 | d->m_iconSet = iconset; | ||
183 | d->m_iconName = QString::null; | ||
184 | d->m_hasIcon = !iconset.isNull(); | ||
185 | } | ||
186 | |||
187 | void KGuiItem::setIconName( const QString &iconName ) | ||
188 | { | ||
189 | d->m_iconName = iconName; | ||
190 | d->m_iconSet = QIconSet(); | ||
191 | d->m_hasIcon = !iconName.isEmpty(); | ||
192 | } | ||
193 | |||
194 | void KGuiItem::setToolTip( const QString &toolTip) { | ||
195 | d->m_toolTip = toolTip; | ||
196 | } | ||
197 | void KGuiItem::setWhatsThis( const QString &whatsThis ) { | ||
198 | d->m_whatsThis = whatsThis; | ||
199 | } | ||
200 | void KGuiItem::setEnabled( bool enabled ){ | ||
201 | d->m_enabled = enabled; | ||
202 | } | ||
203 | |||
204 | /* vim: et sw=4 | ||
205 | */ | ||