• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdefile
 

tdeio/tdefile

  • tdeio
  • tdefile
tdefilemetainfowidget.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 2001,2002 Rolf Magnus <ramagnus@kde.org>
3
4 library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17
18 $Id$
19 */
20
21#include "tdefilemetainfowidget.h"
22
23#include <keditcl.h>
24#include <tdelocale.h>
25#include <knuminput.h>
26#include <kcombobox.h>
27#include <klineedit.h>
28#include <kstringvalidator.h>
29#include <kdebug.h>
30
31#include <tqlabel.h>
32#include <tqcheckbox.h>
33#include <tqspinbox.h>
34#include <tqdatetimeedit.h>
35#include <tqpixmap.h>
36#include <tqimage.h>
37#include <tqlayout.h>
38#include <tqvalidator.h>
39
40/*
41 Widgets used for different types:
42
43 bool : QCheckBox
44 int : QSpinBox
45 TQString : KComboBox if the validator is a KStringListValidator, else lineedit
46 TQDateTime : QDateTimeEdit
47
48*/
49
50KFileMetaInfoWidget::KFileMetaInfoWidget(KFileMetaInfoItem item,
51 TQValidator* val,
52 TQWidget* parent, const char* name)
53 : TQWidget(parent, name),
54 m_value(item.value()),
55 m_item(item),
56 m_validator(val)
57{
58 init(item, ReadWrite);
59}
60
61KFileMetaInfoWidget::KFileMetaInfoWidget(KFileMetaInfoItem item,
62 Mode mode,
63 TQValidator* val,
64 TQWidget* parent, const char* name)
65 : TQWidget(parent, name),
66 m_value(item.value()),
67 m_item(item),
68 m_validator(val)
69{
70 init(item, mode);
71}
72
73void KFileMetaInfoWidget::init(KFileMetaInfoItem item, Mode mode)
74{
75 kdDebug(7033) << "*** item " << m_item.key()
76 << " is a " << value().typeName() << endl;
77
78 if (m_item.isEditable() && !(mode & ReadOnly))
79 m_widget = makeWidget();
80 else
81 switch (m_value.type())
82 {
83 case TQVariant::Image :
84 m_widget = new TQLabel(this, "info image");
85 static_cast<TQLabel*>(m_widget)->setPixmap(TQPixmap(m_value.toImage()));
86 break;
87 case TQVariant::Pixmap :
88 m_widget = new TQLabel(this, "info pixmap");
89 static_cast<TQLabel*>(m_widget)->setPixmap(m_value.toPixmap());
90 break;
91 default:
92 m_widget = new TQLabel(item.string(true), this, "info label");
93 }
94
95 (new TQHBoxLayout(this))->addWidget(m_widget);
96}
97
98KFileMetaInfoWidget::~KFileMetaInfoWidget()
99{
100}
101
102TQWidget* KFileMetaInfoWidget::makeWidget()
103{
104 TQString valClass;
105 TQWidget* w;
106
107 switch (m_value.type())
108 {
109 case TQVariant::Invalid: // no type
110 // just make a label
111 w = new TQLabel(i18n("<Error>"), this, "label");
112 break;
113
114 case TQVariant::Int: // an int
115 case TQVariant::UInt: // an unsigned int
116 w = makeIntWidget();
117 break;
118
119 case TQVariant::Bool: // a bool
120 w = makeBoolWidget();
121 break;
122
123 case TQVariant::Double: // a double
124 w = makeDoubleWidget();
125 break;
126
127
128 case TQVariant::Date: // a QDate
129 w = makeDateWidget();
130 break;
131
132 case TQVariant::Time: // a QTime
133 w = makeTimeWidget();
134 break;
135
136 case TQVariant::DateTime: // a QDateTime
137 w = makeDateTimeWidget();
138 break;
139
140#if 0
141 case TQVariant::Size: // a QSize
142 case TQVariant::String: // a TQString
143 case TQVariant::List: // a QValueList
144 case TQVariant::Map: // a QMap
145 case TQVariant::StringList: // a QStringList
146 case TQVariant::Font: // a QFont
147 case TQVariant::Pixmap: // a QPixmap
148 case TQVariant::Brush: // a QBrush
149 case TQVariant::Rect: // a QRect
150 case TQVariant::Color: // a TQColor
151 case TQVariant::Palette: // a QPalette
152 case TQVariant::ColorGroup: // a QColorGroup
153 case TQVariant::IconSet: // a QIconSet
154 case TQVariant::Point: // a QPoint
155 case TQVariant::Image: // a TQImage
156 case TQVariant::CString: // a QCString
157 case TQVariant::PointArray: // a QPointArray
158 case TQVariant::Region: // a QRegion
159 case TQVariant::Bitmap: // a QBitmap
160 case TQVariant::Cursor: // a QCursor
161 case TQVariant::ByteArray: // a QByteArray
162 case TQVariant::BitArray: // a QBitArray
163 case TQVariant::SizePolicy: // a QSizePolicy
164 case TQVariant::KeySequence: // a QKeySequence
165#endif
166 default:
167 w = makeStringWidget();
168 }
169
170 kdDebug(7033) << "*** item " << m_item.key()
171 << "is a " << m_item.value().typeName() << endl;
172 if (m_validator)
173 kdDebug(7033) << " and validator is a " << m_validator->className() << endl;
174
175 kdDebug(7033) << "*** created a " << w->className() << " for it\n";
176
177 return w;
178}
179
180// ****************************************************************
181// now the different methods to make the widgets for specific types
182// ****************************************************************
183
184TQWidget* KFileMetaInfoWidget::makeBoolWidget()
185{
186 TQCheckBox* cb = new TQCheckBox(this, "metainfo bool widget");
187 cb->setChecked(m_item.value().toBool());
188 connect(cb, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(slotChanged(bool)));
189 return cb;
190}
191
192TQWidget* KFileMetaInfoWidget::makeIntWidget()
193{
194 TQSpinBox* sb = new TQSpinBox(this, "metainfo integer widget");
195 sb->setValue(m_item.value().toInt());
196
197 if (m_validator)
198 {
199 if (m_validator->inherits("TQIntValidator"))
200 {
201 sb->setMinValue(static_cast<TQIntValidator*>(m_validator)->bottom());
202 sb->setMaxValue(static_cast<TQIntValidator*>(m_validator)->top());
203 }
204 reparentValidator(sb, m_validator);
205 sb->setValidator(m_validator);
206 }
207
208 // make sure that an uint cannot be set to a value < 0
209 if (m_item.type() == TQVariant::UInt)
210 sb->setMinValue(TQMAX(sb->minValue(), 0));
211
212 connect(sb, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(slotChanged(int)));
213 return sb;
214}
215
216TQWidget* KFileMetaInfoWidget::makeDoubleWidget()
217{
218 KDoubleNumInput* dni = new KDoubleNumInput(m_item.value().toDouble(),
219 this, "metainfo double widget");
220
221
222 if (m_validator)
223 {
224 if (m_validator->inherits("QDoubleValidator"))
225 {
226 dni->setMinValue(static_cast<TQDoubleValidator*>(m_validator)->bottom());
227 dni->setMaxValue(static_cast<TQDoubleValidator*>(m_validator)->top());
228 }
229 reparentValidator(dni, m_validator);
230 }
231
232 connect(dni, TQ_SIGNAL(valueChanged(double)), this, TQ_SLOT(slotChanged(double)));
233 return dni;
234}
235
236TQWidget* KFileMetaInfoWidget::makeStringWidget()
237{
238 if (m_validator && m_validator->inherits("KStringListValidator"))
239 {
240 KComboBox* b = new KComboBox(true, this, "metainfo combobox");
241 KStringListValidator* val = static_cast<KStringListValidator*>
242 (m_validator);
243 b->insertStringList(val->stringList());
244 b->setCurrentText(m_item.value().toString());
245 connect(b, TQ_SIGNAL(activated(const TQString &)), this, TQ_SLOT(slotComboChanged(const TQString &)));
246 b->setValidator(val);
247 reparentValidator(b, val);
248 return b;
249 }
250
251 if ( m_item.attributes() & KFileMimeTypeInfo::MultiLine ) {
252 KEdit *edit = new KEdit( this );
253 edit->setText( m_item.value().toString() );
254 connect( edit, TQ_SIGNAL( textChanged() ),
255 this, TQ_SLOT( slotMultiLineEditChanged() ));
256 // can't use a validator with a TQTextEdit, but we may need to delete it
257 if ( m_validator )
258 reparentValidator( edit, m_validator );
259 return edit;
260 }
261
262 KLineEdit* e = new KLineEdit(m_item.value().toString(), this);
263 if (m_validator)
264 {
265 e->setValidator(m_validator);
266 reparentValidator(e, m_validator);
267 }
268 connect(e, TQ_SIGNAL(textChanged(const TQString&)),
269 this, TQ_SLOT(slotLineEditChanged(const TQString&)));
270 return e;
271}
272
273TQWidget* KFileMetaInfoWidget::makeDateWidget()
274{
275 TQWidget *e = new TQDateEdit(m_item.value().toDate(), this);
276 connect(e, TQ_SIGNAL(valueChanged(const TQDate&)),
277 this, TQ_SLOT(slotDateChanged(const TQDate&)));
278 return e;
279}
280
281TQWidget* KFileMetaInfoWidget::makeTimeWidget()
282{
283 return new TQTimeEdit(m_item.value().toTime(), this);
284}
285
286TQWidget* KFileMetaInfoWidget::makeDateTimeWidget()
287{
288 return new TQDateTimeEdit(m_item.value().toDateTime(), this);
289}
290
291void KFileMetaInfoWidget::reparentValidator( TQWidget *widget,
292 TQValidator *validator )
293{
294 if ( !validator->parent() )
295 widget->insertChild( validator );
296}
297
298// ****************************************************************
299// now the slots that let us get notified if the value changed in the child
300// ****************************************************************
301
302void KFileMetaInfoWidget::slotChanged(bool value)
303{
304 Q_ASSERT(m_widget->inherits("TQComboBox"));
305 m_value = TQVariant(value);
306 emit valueChanged(m_value);
307 m_dirty = true;
308}
309
310void KFileMetaInfoWidget::slotChanged(int value)
311{
312 Q_ASSERT(m_widget->inherits("TQSpinBox"));
313 m_value = TQVariant(value);
314 emit valueChanged(m_value);
315 m_dirty = true;
316}
317
318void KFileMetaInfoWidget::slotChanged(double value)
319{
320 Q_ASSERT(m_widget->inherits("KDoubleNumInput"));
321 m_value = TQVariant(value);
322 emit valueChanged(m_value);
323 m_dirty = true;
324}
325
326void KFileMetaInfoWidget::slotComboChanged(const TQString &value)
327{
328 Q_ASSERT(m_widget->inherits("KComboBox"));
329 m_value = TQVariant(value);
330 emit valueChanged(m_value);
331 m_dirty = true;
332}
333
334void KFileMetaInfoWidget::slotLineEditChanged(const TQString& value)
335{
336 Q_ASSERT(m_widget->inherits("KLineEdit"));
337 m_value = TQVariant(value);
338 emit valueChanged(m_value);
339 m_dirty = true;
340}
341
342// that may be a little expensive for long texts, but what can we do?
343void KFileMetaInfoWidget::slotMultiLineEditChanged()
344{
345 Q_ASSERT(m_widget->inherits("TQTextEdit"));
346 m_value = TQVariant( static_cast<const TQTextEdit*>( sender() )->text() );
347 emit valueChanged(m_value);
348 m_dirty = true;
349}
350
351void KFileMetaInfoWidget::slotDateChanged(const TQDate& value)
352{
353 Q_ASSERT(m_widget->inherits("TQDateEdit"));
354 m_value = TQVariant(value);
355 emit valueChanged(m_value);
356 m_dirty = true;
357}
358
359void KFileMetaInfoWidget::slotTimeChanged(const TQTime& value)
360{
361 Q_ASSERT(m_widget->inherits("TQTimeEdit"));
362 m_value = TQVariant(value);
363 emit valueChanged(m_value);
364 m_dirty = true;
365}
366
367void KFileMetaInfoWidget::slotDateTimeChanged(const TQDateTime& value)
368{
369 Q_ASSERT(m_widget->inherits("TQDateTimeEdit"));
370 m_value = TQVariant(value);
371 emit valueChanged(m_value);
372 m_dirty = true;
373}
374
375#include "tdefilemetainfowidget.moc"

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • 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 tdeio/tdefile by doxygen 1.9.4
This website is maintained by Timothy Pearson.