Diffstat (limited to 'pwmanager/pwmanager/commentbox.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | pwmanager/pwmanager/commentbox.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/pwmanager/pwmanager/commentbox.cpp b/pwmanager/pwmanager/commentbox.cpp index 4a76f36..e2d2d2b 100644 --- a/pwmanager/pwmanager/commentbox.cpp +++ b/pwmanager/pwmanager/commentbox.cpp | |||
@@ -1,281 +1,281 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include "commentbox.h" | 20 | #include "commentbox.h" |
21 | #include "pwmexception.h" | 21 | #include "pwmexception.h" |
22 | #include "htmlgen.h" | 22 | #include "htmlgen.h" |
23 | 23 | ||
24 | #include <klocale.h> | 24 | #include <klocale.h> |
25 | 25 | ||
26 | #ifndef PWM_EMBEDDED | 26 | #ifndef PWM_EMBEDDED |
27 | #include <khtml_part.h> | 27 | #include <khtml_part.h> |
28 | #include <khtmlview.h> | 28 | #include <khtmlview.h> |
29 | #include <qtextedit.h> | 29 | #include <qtextedit.h> |
30 | #else | 30 | #else |
31 | #include <qmultilineedit.h> | 31 | #include <qmultilineedit.h> |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | 34 | ||
35 | 35 | ||
36 | #ifndef PWM_EMBEDDED | 36 | #ifndef PWM_EMBEDDED |
37 | CommentBox::CommentBox(QWidget *_parentWidget) | 37 | CommentBox::CommentBox(QWidget *_parentWidget) |
38 | { | 38 | { |
39 | PWM_ASSERT(_parentWidget); | 39 | PWM_ASSERT(_parentWidget); |
40 | parentWidget = _parentWidget; | 40 | parentWidget = _parentWidget; |
41 | textDta = 0; | 41 | textDta = 0; |
42 | htmlDta = 0; | 42 | htmlDta = 0; |
43 | mode = mode_notSet; | 43 | mode = mode_notSet; |
44 | } | 44 | } |
45 | 45 | ||
46 | CommentBox::~CommentBox() | 46 | CommentBox::~CommentBox() |
47 | { | 47 | { |
48 | clearText(); | 48 | clearText(); |
49 | clearHtml(); | 49 | clearHtml(); |
50 | } | 50 | } |
51 | 51 | ||
52 | void CommentBox::clear() | 52 | void CommentBox::clear() |
53 | { | 53 | { |
54 | clearText(); | 54 | clearText(); |
55 | clearHtml(); | 55 | clearHtml(); |
56 | mode = mode_notSet; | 56 | mode = mode_notSet; |
57 | this->hide(); | 57 | this->hide(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CommentBox::clearText() | 60 | void CommentBox::clearText() |
61 | { | 61 | { |
62 | delete_ifnot_null(textDta); | 62 | delete_ifnot_null(textDta); |
63 | } | 63 | } |
64 | 64 | ||
65 | void CommentBox::clearHtml() | 65 | void CommentBox::clearHtml() |
66 | { | 66 | { |
67 | delete_ifnot_null(htmlDta); | 67 | delete_ifnot_null(htmlDta); |
68 | } | 68 | } |
69 | 69 | ||
70 | void CommentBox::setText(const QString &text) | 70 | void CommentBox::setText(const QString &text) |
71 | { | 71 | { |
72 | switchTo(mode_text); | 72 | switchTo(mode_text); |
73 | PWM_ASSERT(textDta); | 73 | PWM_ASSERT(textDta); |
74 | textDta->setText(i18n("Comment") + ": " + text); | 74 | textDta->setText( text); |
75 | if (!textDta->isVisible()) | 75 | if (!textDta->isVisible()) |
76 | textDta->show(); | 76 | textDta->show(); |
77 | } | 77 | } |
78 | 78 | ||
79 | bool CommentBox::getText(QString *text) | 79 | bool CommentBox::getText(QString *text) |
80 | { | 80 | { |
81 | if (mode != mode_text) | 81 | if (mode != mode_text) |
82 | return false; | 82 | return false; |
83 | PWM_ASSERT(text); | 83 | PWM_ASSERT(text); |
84 | if (!textDta) { | 84 | if (!textDta) { |
85 | *text = ""; | 85 | *text = ""; |
86 | return true; | 86 | return true; |
87 | } | 87 | } |
88 | *text = textDta->text(); | 88 | *text = textDta->text(); |
89 | return true; | 89 | return true; |
90 | } | 90 | } |
91 | 91 | ||
92 | void CommentBox::setHtml(QString code) | 92 | void CommentBox::setHtml(QString code) |
93 | { | 93 | { |
94 | switchTo(mode_html); | 94 | switchTo(mode_html); |
95 | PWM_ASSERT(htmlDta); | 95 | PWM_ASSERT(htmlDta); |
96 | if (!HtmlGen::replaceSSDummy(&code)) | 96 | if (!HtmlGen::replaceSSDummy(&code)) |
97 | printWarn("CommentBox::setHtml(): replaceSSDummy() failed!"); | 97 | printWarn("CommentBox::setHtml(): replaceSSDummy() failed!"); |
98 | htmlDta->begin(); | 98 | htmlDta->begin(); |
99 | htmlDta->write(code); | 99 | htmlDta->write(code); |
100 | htmlDta->end(); | 100 | htmlDta->end(); |
101 | htmlDta->show(); | 101 | htmlDta->show(); |
102 | } | 102 | } |
103 | 103 | ||
104 | void CommentBox::setContent(const QString &dta) | 104 | void CommentBox::setContent(const QString &dta) |
105 | { | 105 | { |
106 | // if there's no data, hide the comment-box | 106 | // if there's no data, hide the comment-box |
107 | if (dta.isEmpty()) { | 107 | if (dta.isEmpty()) { |
108 | clear(); | 108 | clear(); |
109 | return; | 109 | return; |
110 | } | 110 | } |
111 | if (HtmlGen::isHtml(dta)) { | 111 | if (HtmlGen::isHtml(dta)) { |
112 | setHtml(dta); | 112 | setHtml(dta); |
113 | return; | 113 | return; |
114 | } | 114 | } |
115 | // we assume it's plain text | 115 | // we assume it's plain text |
116 | setText(dta); | 116 | setText(dta); |
117 | } | 117 | } |
118 | 118 | ||
119 | void CommentBox::switchTo(commentBoxMode newMode) | 119 | void CommentBox::switchTo(commentBoxMode newMode) |
120 | { | 120 | { |
121 | if (newMode == mode) | 121 | if (newMode == mode) |
122 | return; | 122 | return; |
123 | 123 | ||
124 | // cleanup old mode | 124 | // cleanup old mode |
125 | switch (mode) { | 125 | switch (mode) { |
126 | case mode_text: | 126 | case mode_text: |
127 | clearText(); | 127 | clearText(); |
128 | break; | 128 | break; |
129 | case mode_html: | 129 | case mode_html: |
130 | clearHtml(); | 130 | clearHtml(); |
131 | break; | 131 | break; |
132 | default: | 132 | default: |
133 | break; | 133 | break; |
134 | } | 134 | } |
135 | 135 | ||
136 | // setup new mode | 136 | // setup new mode |
137 | switch (newMode) { | 137 | switch (newMode) { |
138 | case mode_text: | 138 | case mode_text: |
139 | textDta = new QTextEdit(parentWidget); | 139 | textDta = new QTextEdit(parentWidget); |
140 | textDta->setTextFormat(Qt::PlainText); | 140 | textDta->setTextFormat(Qt::PlainText); |
141 | textDta->setReadOnly(true); | 141 | textDta->setReadOnly(true); |
142 | textDta->show(); | 142 | textDta->show(); |
143 | break; | 143 | break; |
144 | case mode_html: | 144 | case mode_html: |
145 | htmlDta = new KHTMLPart(parentWidget, 0, | 145 | htmlDta = new KHTMLPart(parentWidget, 0, |
146 | parentWidget); | 146 | parentWidget); |
147 | htmlDta->show(); | 147 | htmlDta->show(); |
148 | break; | 148 | break; |
149 | default: | 149 | default: |
150 | BUG(); | 150 | BUG(); |
151 | break; | 151 | break; |
152 | } | 152 | } |
153 | 153 | ||
154 | mode = newMode; | 154 | mode = newMode; |
155 | } | 155 | } |
156 | 156 | ||
157 | void CommentBox::show() | 157 | void CommentBox::show() |
158 | { | 158 | { |
159 | switch (mode) { | 159 | switch (mode) { |
160 | case mode_text: | 160 | case mode_text: |
161 | PWM_ASSERT(textDta); | 161 | PWM_ASSERT(textDta); |
162 | textDta->show(); | 162 | textDta->show(); |
163 | break; | 163 | break; |
164 | case mode_html: | 164 | case mode_html: |
165 | PWM_ASSERT(htmlDta); | 165 | PWM_ASSERT(htmlDta); |
166 | htmlDta->show(); | 166 | htmlDta->show(); |
167 | break; | 167 | break; |
168 | default: | 168 | default: |
169 | break; | 169 | break; |
170 | } | 170 | } |
171 | 171 | ||
172 | } | 172 | } |
173 | 173 | ||
174 | void CommentBox::hide() | 174 | void CommentBox::hide() |
175 | { | 175 | { |
176 | switch (mode) { | 176 | switch (mode) { |
177 | case mode_text: | 177 | case mode_text: |
178 | PWM_ASSERT(textDta); | 178 | PWM_ASSERT(textDta); |
179 | textDta->hide(); | 179 | textDta->hide(); |
180 | break; | 180 | break; |
181 | case mode_html: | 181 | case mode_html: |
182 | PWM_ASSERT(htmlDta); | 182 | PWM_ASSERT(htmlDta); |
183 | htmlDta->hide(); | 183 | htmlDta->hide(); |
184 | break; | 184 | break; |
185 | default: | 185 | default: |
186 | break; | 186 | break; |
187 | } | 187 | } |
188 | } | 188 | } |
189 | 189 | ||
190 | void CommentBox::resize(const QSize &size) | 190 | void CommentBox::resize(const QSize &size) |
191 | { | 191 | { |
192 | switch (mode) { | 192 | switch (mode) { |
193 | case mode_text: | 193 | case mode_text: |
194 | PWM_ASSERT(textDta); | 194 | PWM_ASSERT(textDta); |
195 | textDta->resize(size); | 195 | textDta->resize(size); |
196 | break; | 196 | break; |
197 | case mode_html: | 197 | case mode_html: |
198 | PWM_ASSERT(htmlDta); | 198 | PWM_ASSERT(htmlDta); |
199 | htmlDta->view()->resize(size); | 199 | htmlDta->view()->resize(size); |
200 | break; | 200 | break; |
201 | default: | 201 | default: |
202 | break; | 202 | break; |
203 | } | 203 | } |
204 | 204 | ||
205 | } | 205 | } |
206 | 206 | ||
207 | QSize CommentBox::size() | 207 | QSize CommentBox::size() |
208 | { | 208 | { |
209 | switch (mode) { | 209 | switch (mode) { |
210 | case mode_text: | 210 | case mode_text: |
211 | PWM_ASSERT(textDta); | 211 | PWM_ASSERT(textDta); |
212 | return textDta->size(); | 212 | return textDta->size(); |
213 | break; | 213 | break; |
214 | case mode_html: | 214 | case mode_html: |
215 | PWM_ASSERT(htmlDta); | 215 | PWM_ASSERT(htmlDta); |
216 | return htmlDta->view()->size(); | 216 | return htmlDta->view()->size(); |
217 | break; | 217 | break; |
218 | default: | 218 | default: |
219 | break; | 219 | break; |
220 | } | 220 | } |
221 | 221 | ||
222 | return QSize(); | 222 | return QSize(); |
223 | } | 223 | } |
224 | 224 | ||
225 | 225 | ||
226 | //////////////////////////////////////////////////////////////////////// | 226 | //////////////////////////////////////////////////////////////////////// |
227 | 227 | ||
228 | #else | 228 | #else |
229 | 229 | ||
230 | CommentBox::CommentBox(QWidget *_parentWidget) | 230 | CommentBox::CommentBox(QWidget *_parentWidget) |
231 | : QMultiLineEdit(_parentWidget) | 231 | : QMultiLineEdit(_parentWidget) |
232 | 232 | ||
233 | { | 233 | { |
234 | this->setReadOnly(true); | 234 | this->setReadOnly(true); |
235 | } | 235 | } |
236 | 236 | ||
237 | CommentBox::~CommentBox() | 237 | CommentBox::~CommentBox() |
238 | { | 238 | { |
239 | } | 239 | } |
240 | 240 | ||
241 | void CommentBox::clear() | 241 | void CommentBox::clear() |
242 | { | 242 | { |
243 | this->hide(); | 243 | this->hide(); |
244 | } | 244 | } |
245 | 245 | ||
246 | 246 | ||
247 | void CommentBox::setText(const QString &text) | 247 | void CommentBox::setText(const QString &text) |
248 | { | 248 | { |
249 | QMultiLineEdit::setText(i18n("Comment") + ": " + text); | 249 | QMultiLineEdit::setText( text); |
250 | if (!this->isVisible()) | 250 | if (!this->isVisible()) |
251 | this->show(); | 251 | this->show(); |
252 | } | 252 | } |
253 | 253 | ||
254 | bool CommentBox::getText(QString *text) | 254 | bool CommentBox::getText(QString *text) |
255 | { | 255 | { |
256 | *text = this->text(); | 256 | *text = this->text(); |
257 | return true; | 257 | return true; |
258 | } | 258 | } |
259 | 259 | ||
260 | void CommentBox::setContent(const QString &dta) | 260 | void CommentBox::setContent(const QString &dta) |
261 | { | 261 | { |
262 | // if there's no data, hide the comment-box | 262 | // if there's no data, hide the comment-box |
263 | if (dta.isEmpty()) { | 263 | if (dta.isEmpty()) { |
264 | clear(); | 264 | clear(); |
265 | return; | 265 | return; |
266 | } | 266 | } |
267 | 267 | ||
268 | // we assume it's plain text | 268 | // we assume it's plain text |
269 | setText(dta); | 269 | setText(dta); |
270 | } | 270 | } |
271 | 271 | ||
272 | #endif | 272 | #endif |
273 | 273 | ||
274 | 274 | ||
275 | 275 | ||
276 | 276 | ||
277 | 277 | ||
278 | 278 | ||
279 | 279 | ||
280 | 280 | ||
281 | 281 | ||