kexidbautofield.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Cedric Pasteur <cedric.pasteur@free.fr>
3 Copyright (C) 2005 Christian Nitschkowski <segfault_ii@web.de>
4 Copyright (C) 2005-2007 Jaroslaw Staniek <js@iidea.pl>
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this program; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20*/
21
22#include "kexidbautofield.h"
23
24#include <tqlabel.h>
25#include <tqlayout.h>
26#include <tqpainter.h>
27#include <tqmetaobject.h>
28#include <tqapplication.h>
29
30#include <kdebug.h>
31#include <tdelocale.h>
32
33#include "kexidbcheckbox.h"
34#include "kexidbimagebox.h"
35#include "kexidblabel.h"
36#include "kexidblineedit.h"
37#include "kexidbtextedit.h"
38#include "kexidbcombobox.h"
39#include "kexipushbutton.h"
40#include "kexidbform.h"
41
42#include <kexidb/queryschema.h>
43#include <formeditor/utils.h>
44#include <kexiutils/utils.h>
45
46#define KexiDBAutoField_SPACING 10 //10 pixel for spacing between a label and an editor widget
47
49class KexiDBAutoField::Private
50{
51 public:
52 Private()
53 {
54 }
55
56 WidgetType widgetType;
58 WidgetType widgetType_property;
59 LabelPosition lblPosition;
60 TQBoxLayout *layout;
61 TQLabel *label;
62 TQString caption;
63 KexiDB::Field::Type fieldTypeInternal;
64 TQString fieldCaptionInternal;
65 TQColor baseColor;
66 TQColor textColor;
67 bool autoCaption : 1;
68 bool focusPolicyChanged : 1;
69 bool designMode : 1;
70};
71
72//-------------------------------------
73
74KexiDBAutoField::KexiDBAutoField(const TQString &text, WidgetType type, LabelPosition pos,
75 TQWidget *parent, const char *name, bool designMode)
76 : TQWidget(parent, name)
78 , KFormDesigner::DesignTimeDynamicChildWidgetHandler()
79 , d( new Private() )
80{
81 d->designMode = designMode;
82 init(text, type, pos);
83}
84
85KexiDBAutoField::KexiDBAutoField(TQWidget *parent, const char *name, bool designMode, LabelPosition pos)
86 : TQWidget(parent, name)
88 , KFormDesigner::DesignTimeDynamicChildWidgetHandler()
89 , d( new Private() )
90{
91 d->designMode = designMode;
92 init(TQString()/*i18n("Auto Field")*/, Auto, pos);
93}
94
95KexiDBAutoField::~KexiDBAutoField()
96{
97 setUpdatesEnabled(false);
98 if (m_subwidget)
99 m_subwidget->setUpdatesEnabled(false);
100 delete d;
101}
102
103void
104KexiDBAutoField::init(const TQString &text, WidgetType type, LabelPosition pos)
105{
106 d->fieldTypeInternal = KexiDB::Field::InvalidType;
107 d->layout = 0;
108 m_subwidget = 0;
109 d->label = new TQLabel(text, this);
110 d->label->installEventFilter( this );
111 //TQFontMetrics fm( font() );
112 //d->label->setFixedWidth( fm.width("This is a test string length") );
113 d->autoCaption = true;
114 d->focusPolicyChanged = false;
115 d->widgetType = Auto;
116 d->widgetType_property = (type==Auto ? Text : type); //to force "differ" to be true in setWidgetType()
117 setLabelPosition(pos);
118 setWidgetType(type);
119 d->baseColor = palette().active().base();
120 d->textColor = palette().active().text();
121}
122
123void
124KexiDBAutoField::setWidgetType(WidgetType type)
125{
126 const bool differ = (type != d->widgetType_property);
127 d->widgetType_property = type;
128 if(differ) {
129 if(type == Auto) {// try to guess type from data source type
130 if (visibleColumnInfo())
131 d->widgetType = KexiDBAutoField::widgetTypeForFieldType(visibleColumnInfo()->field->type());
132 else
133 d->widgetType = Auto;
134 }
135 else
136 d->widgetType = d->widgetType_property;
137 createEditor();
138 }
139}
140
141void
143{
144 if(m_subwidget) {
145 delete (TQWidget *)m_subwidget;
146 }
147
148 TQWidget *newSubwidget;
149 switch( d->widgetType ) {
150 case Text:
151 case Double:
152 case Integer:
153 case Date:
154 case Time:
155 case DateTime:
156 newSubwidget = new KexiDBLineEdit( this, TQCString("KexiDBAutoField_KexiDBLineEdit:")+name() );
157 break;
158 case MultiLineText:
159 newSubwidget = new KexiDBTextEdit( this, TQCString("KexiDBAutoField_KexiDBTextEdit:")+name() );
160 break;
161 case Boolean:
162 newSubwidget = new KexiDBCheckBox(dataSource(), this, TQCString("KexiDBAutoField_KexiDBCheckBox:")+name());
163 break;
164 case Image:
165 newSubwidget = new KexiDBImageBox(d->designMode, this, TQCString("KexiDBAutoField_KexiDBImageBox:")+name());
166 break;
167 case ComboBox:
168 newSubwidget = new KexiDBComboBox(this, TQCString("KexiDBAutoField_KexiDBComboBox:")+name(), d->designMode);
169 break;
170 default:
171 newSubwidget = 0;
172 changeText(d->caption);
173 //d->label->setText( d->dataSource.isEmpty() ? "<datasource>" : d->dataSource );
174 break;
175 }
176
177 setSubwidget( newSubwidget ); //this will also allow to declare subproperties, see KFormDesigner::WidgetWithSubpropertiesInterface
178 if(newSubwidget) {
179 newSubwidget->setName( TQCString("KexiDBAutoField_") + newSubwidget->className() );
180 dynamic_cast<KexiDataItemInterface*>(newSubwidget)->setParentDataItemInterface(this);
181 dynamic_cast<KexiFormDataItemInterface*>(newSubwidget)
182 ->setColumnInfo(columnInfo()); //needed at least by KexiDBImageBox
183 dynamic_cast<KexiFormDataItemInterface*>(newSubwidget)
184 ->setVisibleColumnInfo(visibleColumnInfo()); //needed at least by KexiDBComboBox
185 newSubwidget->setProperty("dataSource", dataSource()); //needed at least by KexiDBImageBox
186 KFormDesigner::DesignTimeDynamicChildWidgetHandler::childWidgetAdded(this);
187 newSubwidget->show();
188 d->label->setBuddy(newSubwidget);
189 if (d->focusPolicyChanged) {//if focusPolicy is changed at top level, editor inherits it
190 newSubwidget->setFocusPolicy(focusPolicy());
191 }
192 else {//if focusPolicy is not changed at top level, inherit it from editor
193 TQWidget::setFocusPolicy(newSubwidget->focusPolicy());
194 }
195 setFocusProxy(newSubwidget); //ok?
196 if (parentWidget())
197 newSubwidget->setPalette( tqApp->palette() );
199// KFormDesigner::installRecursiveEventFilter(newSubwidget, this);
200 }
201
202 setLabelPosition(labelPosition());
203}
204
206{
207 if (m_subwidget) {
208// kdDebug() << "KexiDBAutoField::copyPropertiesToEditor(): base col: " << d->baseColor.name() <<
209// "; text col: " << d->textColor.name() << endl;
210 TQPalette p( m_subwidget->palette() );
211 p.setColor( TQPalette::Active, TQColorGroup::Base, d->baseColor );
212 if(d->widgetType == Boolean)
213 p.setColor( TQPalette::Active, TQColorGroup::Foreground, d->textColor );
214 else
215 p.setColor( TQPalette::Active, TQColorGroup::Text, d->textColor );
216 m_subwidget->setPalette(p);
217 //m_subwidget->setPaletteBackgroundColor( d->baseColor );
218 }
219}
220
221void
223{
224 d->lblPosition = position;
225 if(d->layout) {
226 TQBoxLayout *lyr = d->layout;
227 d->layout = 0;
228 delete lyr;
229 }
230
231 if(m_subwidget)
232 m_subwidget->show();
234 if (position==Top || position==Left) {
235 int align = d->label->alignment();
236 if(position == Top) {
237 d->layout = (TQBoxLayout*) new TQVBoxLayout(this);
238 align |= AlignVertical_Mask;
239 align ^= AlignVertical_Mask;
240 align |= AlignTop;
241 }
242 else {
243 d->layout = (TQBoxLayout*) new TQHBoxLayout(this);
244 align |= AlignVertical_Mask;
245 align ^= AlignVertical_Mask;
246 align |= AlignVCenter;
247 }
248 d->label->setAlignment(align);
249 if(d->widgetType == Boolean
250 || (d->widgetType == Auto && fieldTypeInternal() == KexiDB::Field::InvalidType && !d->designMode))
251 {
252 d->label->hide();
253 }
254 else {
255 d->label->show();
256 }
257 d->layout->addWidget(d->label, 0, position == Top ? int(TQt::AlignLeft) : 0);
258 if(position == Left && d->widgetType != Boolean)
259 d->layout->addSpacing(KexiDBAutoField_SPACING);
260 d->layout->addWidget(m_subwidget, 1);
261 KexiSubwidgetInterface *subwidgetInterface = dynamic_cast<KexiSubwidgetInterface*>((TQWidget*)m_subwidget);
262 if (subwidgetInterface) {
263 if (subwidgetInterface->appendStretchRequired(this))
264 d->layout->addStretch(0);
265 if (subwidgetInterface->subwidgetStretchRequired(this)) {
266 TQSizePolicy sizePolicy( m_subwidget->sizePolicy() );
267 if(position == Left) {
268 sizePolicy.setHorData( TQSizePolicy::Minimum );
269 d->label->setSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Preferred);
270 }
271 else {
272 sizePolicy.setVerData( TQSizePolicy::Minimum );
273 d->label->setSizePolicy(TQSizePolicy::Preferred, TQSizePolicy::Fixed);
274 }
275 m_subwidget->setSizePolicy(sizePolicy);
276 }
277 }
278// if(m_subwidget)
279 // m_subwidget->setSizePolicy(...);
280 }
281 else {
282 d->layout = (TQBoxLayout*) new TQHBoxLayout(this);
283 d->label->hide();
284 d->layout->addWidget(m_subwidget);
285 }
286 //a hack to force layout to be refreshed (any better idea for this?)
287 resize(size()+TQSize(1,0));
288 resize(size()-TQSize(1,0));
289 if (dynamic_cast<KexiDBAutoField*>((TQWidget*)m_subwidget)) {
290 //needed for KexiDBComboBox
291 dynamic_cast<KexiDBAutoField*>((TQWidget*)m_subwidget)->setLabelPosition(position);
292 }
293}
294
295void
296KexiDBAutoField::setInvalidState( const TQString &text )
297{
298 // Widget with an invalid dataSource is just a TQLabel
299 if (d->designMode)
300 return;
301 d->widgetType = Auto;
302 createEditor();
303 setFocusPolicy(TQWidget::NoFocus);
304 if (m_subwidget)
305 m_subwidget->setFocusPolicy(TQWidget::NoFocus);
307 d->label->setText( text );
308}
309
310bool
312{
313 KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((TQWidget*)m_subwidget);
314 if(iface)
315 return iface->isReadOnly();
316 else
317 return false;
318}
319
320void
322{
323 KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((TQWidget*)m_subwidget);
324 if(iface)
325 iface->setReadOnly(readOnly);
326}
327
328void
329KexiDBAutoField::setValueInternal(const TQVariant& add, bool removeOld)
330{
331 KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((TQWidget*)m_subwidget);
332 if(iface)
333 iface->setValue(m_origValue, add, removeOld);
334// iface->setValueInternal(add, removeOld);
335}
336
337TQVariant
339{
340 KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((TQWidget*)m_subwidget);
341 if(iface)
342 return iface->value();
343 return TQVariant();
344}
345
346bool
348{
349 KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((TQWidget*)m_subwidget);
350 if(iface)
351 return iface->valueIsNull();
352 return true;
353}
354
355bool
357{
358 KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((TQWidget*)m_subwidget);
359 if(iface)
360 return iface->valueIsEmpty();
361 return true;
362}
363
364bool
366{
367 KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((TQWidget*)m_subwidget);
368 if(iface)
369 return iface->valueIsValid();
370 return true;
371}
372
373bool
375{
376 KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((TQWidget*)m_subwidget);
377 kexipluginsdbg << m_origValue << endl;
378 if(iface)
379 return iface->valueChanged();
380 return false;
381}
382
383void
385{
387 KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((TQWidget*)m_subwidget);
388 if(iface)
389 iface->installListener(listener);
390}
391
392KexiDBAutoField::WidgetType KexiDBAutoField::widgetType() const
393{
394 return d->widgetType_property;
395}
396
397KexiDBAutoField::LabelPosition KexiDBAutoField::labelPosition() const
398{
399 return d->lblPosition;
400}
401
402TQString KexiDBAutoField::caption() const
403{
404 return d->caption;
405}
406
407bool KexiDBAutoField::hasAutoCaption() const
408{
409 return d->autoCaption;
410}
411
412TQWidget* KexiDBAutoField::editor() const
413{
414 return m_subwidget;
415}
416
417TQLabel* KexiDBAutoField::label() const
418{
419 return d->label;
420}
421
422int KexiDBAutoField::fieldTypeInternal() const
423{
424 return d->fieldTypeInternal;
425}
426
427TQString KexiDBAutoField::fieldCaptionInternal() const
428{
429 return d->fieldCaptionInternal;
430}
431
432bool
434{
435 KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((TQWidget*)m_subwidget);
436 if(iface)
437 return iface->cursorAtStart();
438 return false;
439}
440
441bool
443{
444 KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((TQWidget*)m_subwidget);
445 if(iface)
446 return iface->cursorAtEnd();
447 return false;
448}
449
450void
452{
453 KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((TQWidget*)m_subwidget);
454 if(iface)
455 iface->clear();
456}
457
458void
460{
461 d->fieldTypeInternal = (KexiDB::Field::Type)kexiDBFieldType;
462 KexiDB::Field::Type fieldType;
463 //find real fied type to use
464 if (d->fieldTypeInternal==KexiDB::Field::InvalidType) {
465 if (visibleColumnInfo())
466 fieldType = KexiDB::Field::Text;
467 else
468 fieldType = KexiDB::Field::InvalidType;
469 }
470 else
471 fieldType = d->fieldTypeInternal;
472
473 const WidgetType newWidgetType = KexiDBAutoField::widgetTypeForFieldType( fieldType );
474
475 if(d->widgetType != newWidgetType) {
476 d->widgetType = newWidgetType;
477 createEditor();
478 }
479 setFieldCaptionInternal(d->fieldCaptionInternal);
480}
481
482void
484{
485 d->fieldCaptionInternal = text;
486 //change text only if autocaption is set and no columnInfo is available
487 KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((TQWidget*)m_subwidget);
488 if((!iface || !iface->columnInfo()) && d->autoCaption) {
489 changeText(d->fieldCaptionInternal);
490 }
491}
492
493void
499
500void
502{
503 // change widget type depending on field type
504 if(d->widgetType_property == Auto) {
505 WidgetType newWidgetType = Auto;
506 KexiDB::Field::Type fieldType;
507 if (cinfo)
508 fieldType = visibleColumnInfo->field->type();
509 else if (dataSource().isEmpty())
510 fieldType = KexiDB::Field::InvalidType;
511 else
512 fieldType = KexiDB::Field::Text;
513
514 if (fieldType != KexiDB::Field::InvalidType) {
515 newWidgetType = KexiDBAutoField::widgetTypeForFieldType( fieldType );
516 }
517 if(d->widgetType != newWidgetType || newWidgetType==Auto) {
518 d->widgetType = newWidgetType;
519 createEditor();
520 }
521 }
522 // update label's text
523 changeText((cinfo && d->autoCaption) ? cinfo->captionOrAliasOrName() : d->caption);
524
525 KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((TQWidget*)m_subwidget);
526 if(iface)
528}
529
530//static
531KexiDBAutoField::WidgetType
532KexiDBAutoField::widgetTypeForFieldType(KexiDB::Field::Type type)
533{
534 switch(type) {
538 return Integer;
540 return Boolean;
543 return Double;
544 case KexiDB::Field::Date:
545 return Date;
546 case KexiDB::Field::DateTime:
547 return DateTime;
548 case KexiDB::Field::Time:
549 return Time;
551 return Text;
553 return MultiLineText;
555 return ComboBox;
557 return Auto;
559 return Image;
560 default:
561 break;
562 }
563 return Text;
564}
565
566void
567KexiDBAutoField::changeText(const TQString &text, bool beautify)
568{
569 TQString realText;
570 bool unbound = false;
571 if (d->autoCaption && (d->widgetType==Auto || dataSource().isEmpty())) {
572 if (d->designMode)
573 realText = TQString::fromLatin1(name())+" "+i18n("Unbound Auto Field", "(unbound)");
574 else
575 realText = TQString();
576 unbound = true;
577 }
578 else {
579 if (beautify) {
583 if (!text.isEmpty()) {
584 realText = text[0].upper() + text.mid(1);
585 if (d->widgetType!=Boolean) {
588 realText += ": ";
589 }
590 }
591 }
592 else
593 realText = text;
594 }
595
596 if (unbound)
597 d->label->setAlignment( TQt::AlignCenter | TQt::WordBreak );
598 else
599 d->label->setAlignment( TQt::AlignCenter );
600// TQWidget* widgetToAlterForegroundColor;
601 if(d->widgetType == Boolean) {
602 static_cast<TQCheckBox*>((TQWidget*)m_subwidget)->setText(realText);
603// widgetToAlterForegroundColor = m_subwidget;
604 }
605 else {
606 d->label->setText(realText);
607// widgetToAlterForegroundColor = d->label;
608 }
609/*
610 if (unbound)
611 widgetToAlterForegroundColor->setPaletteForegroundColor(
612 KexiUtils::blendedColors(
613 widgetToAlterForegroundColor->paletteForegroundColor(),
614 widgetToAlterForegroundColor->paletteBackgroundColor(), 2, 1));
615 else
616 widgetToAlterForegroundColor->setPaletteForegroundColor( paletteForegroundColor() );*/
617}
618
619void
620KexiDBAutoField::setCaption(const TQString &caption)
621{
622 d->caption = caption;
623 if(!d->autoCaption && !caption.isEmpty())
624 changeText(d->caption);
625}
626
627void
628KexiDBAutoField::setAutoCaption(bool autoCaption)
629{
630 d->autoCaption = autoCaption;
631 if(d->autoCaption) {
632 //d->caption = TQString();
633 if(columnInfo()) {
634 changeText(columnInfo()->captionOrAliasOrName());
635 }
636 else {
637 changeText(d->fieldCaptionInternal);
638 }
639 }
640 else
641 changeText(d->caption);
642}
643
644void
645KexiDBAutoField::setDataSource( const TQString &ds ) {
647 if (ds.isEmpty()) {
648 setColumnInfo(0);
649 }
650}
651
652TQSize
653KexiDBAutoField::sizeHint() const
654{
655 if (d->lblPosition == NoLabel)
656 return m_subwidget ? m_subwidget->sizeHint() : TQWidget::sizeHint();
657
658 TQSize s1(0,0);
659 if (m_subwidget)
660 s1 = m_subwidget->sizeHint();
661 TQSize s2(d->label->sizeHint());
662 if (d->lblPosition == Top)
663 return TQSize(TQMAX(s1.width(), s2.width()), s1.height()+KexiDBAutoField_SPACING+s2.height());
664
665 //left
666 return TQSize(s1.width()+KexiDBAutoField_SPACING+s2.width(), TQMAX(s1.height(), s2.height()));
667}
668
669void
670KexiDBAutoField::setFocusPolicy( TQWidget::FocusPolicy policy )
671{
672 d->focusPolicyChanged = true;
673 TQWidget::setFocusPolicy(policy);
674 d->label->setFocusPolicy(policy);
675 if (m_subwidget)
676 m_subwidget->setFocusPolicy(policy);
677}
678
679void
680KexiDBAutoField::updateInformationAboutUnboundField()
681{
682 if ( (d->autoCaption && (dataSource().isEmpty() || dataSourceMimeType().isEmpty()))
683 || (!d->autoCaption && d->caption.isEmpty()) )
684 {
685 d->label->setText( TQString::fromLatin1(name())+" "+i18n("Unbound Auto Field", " (unbound)") );
686 }
687// else
688// d->label->setText( TQString::fromLatin1(name())+" "+i18n(" (unbound)") );
689}
690
691/*void
692KexiDBAutoField::paintEvent( TQPaintEvent* pe )
693{
694 TQWidget::paintEvent( pe );
695
696 if ( (d->autoCaption && (dataSource().isEmpty() || dataSourceMimeType().isEmpty()))
697 || (!d->autoCaption && d->caption.isEmpty()) )
698 {
699 TQPainter p(this);
700 p.setPen( d->label->paletteForegroundColor() );
701 p.setClipRect(pe->rect());
702 p.setFont(d->label->font());
703 p.drawText(rect(), TQt::AlignLeft | TQt::WordBreak,
704 TQString::fromLatin1(name())+" "+i18n(" (unbound)"));
705 }
706}*/
707
708void
709KexiDBAutoField::paletteChange( const TQPalette& oldPal )
710{
711 Q_UNUSED(oldPal);
712 d->label->setPalette( palette() );
713}
714
715void KexiDBAutoField::unsetPalette()
716{
717 TQWidget::unsetPalette();
718
719}
720
721// ===== methods below are just proxies for the internal editor or label =====
722
724{
725 return d->textColor;
726}
727
729{
730 d->textColor = color;
732}
733
735{
736 return d->baseColor;
737}
738
740{
741 d->baseColor = color;
743}
744
746{
747 if(d->widgetType == Boolean)
748 return paletteForegroundColor();
749
750 return d->label->paletteForegroundColor();
751}
752
753void KexiDBAutoField::setForegroundLabelColor( const TQColor & color )
754{
755 if(d->widgetType == Boolean)
757 else {
758 d->label->setPaletteForegroundColor(color);
759 TQWidget::setPaletteForegroundColor(color);
760 }
761}
762
764{
765 if(d->widgetType == Boolean)
766 return paletteBackgroundColor();
767
768 return d->label->paletteBackgroundColor();
769}
770
771void KexiDBAutoField::setBackgroundLabelColor( const TQColor & color )
772{
773 if(d->widgetType == Boolean)
775 else {
776 d->label->setPaletteBackgroundColor(color);
777 TQWidget::setPaletteBackgroundColor(color);
778 }
779
780// if (m_subwidget)
781// m_subwidget->setPalette( tqApp->palette() );
782}
783
784TQVariant KexiDBAutoField::property( const char * name ) const
785{
786 bool ok;
788 if (ok)
789 return val;
790 return TQWidget::property(name);
791}
792
793bool KexiDBAutoField::setProperty( const char * name, const TQVariant & value )
794{
796 if (ok)
797 return true;
798 return TQWidget::setProperty(name, value);
799}
800
801bool KexiDBAutoField::eventFilter( TQObject *o, TQEvent *e )
802{
803 if (o==d->label && d->label->buddy() && e->type()==TQEvent::MouseButtonRelease) {
804 //focus label's buddy when user clicked the label
805 d->label->buddy()->setFocus();
806 }
807 return TQWidget::eventFilter(o, e);
808}
809
810void KexiDBAutoField::setDisplayDefaultValue(TQWidget* widget, bool displayDefaultValue)
811{
813 if (dynamic_cast<KexiFormDataItemInterface*>((TQWidget*)m_subwidget))
814 dynamic_cast<KexiFormDataItemInterface*>((TQWidget*)m_subwidget)->setDisplayDefaultValue(m_subwidget, displayDefaultValue);
815}
816
818{
819 KexiDataItemInterface *iface = dynamic_cast<KexiDataItemInterface*>((TQWidget*)m_subwidget);
820 if (iface)
821 iface->moveCursorToEnd();
822}
823
825{
826 KexiDataItemInterface *iface = dynamic_cast<KexiDataItemInterface*>((TQWidget*)m_subwidget);
827 if (iface)
828 iface->moveCursorToStart();
829}
830
832{
833 KexiDataItemInterface *iface = dynamic_cast<KexiDataItemInterface*>((TQWidget*)m_subwidget);
834 if (iface)
835 iface->selectAll();
836}
837
838bool KexiDBAutoField::keyPressed(TQKeyEvent *ke)
839{
840 KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((TQWidget*)m_subwidget);
841 if (iface && iface->keyPressed(ke))
842 return true;
843 return false;
844}
845
846#include "kexidbautofield.moc"
void setSubwidget(TQWidget *widget)
Sets widget subwidget handling subproperties.
bool setSubproperty(const char *name, const TQVariant &value)
Sets a subproperty value value for a subproperty name.
TQVariant subproperty(const char *name, bool &ok) const
Universal "Auto Field" widget for Kexi forms.
virtual void setForegroundLabelColor(const TQColor &color)
Sets label's foreground color.
virtual void clear()
clears item's data, so the data will contain NULL data
virtual void moveCursorToEnd()
Implemented for KexiDataItemInterface.
virtual TQVariant value()
virtual void setLabelPosition(LabelPosition position)
virtual void installListener(KexiDataItemChangesListener *listener)
Reimpelmented to also install listenter for internal editor.
const TQColor & paletteForegroundColor() const
Reimplemented to return internal editor's color.
void setFieldCaptionInternal(const TQString &text)
const TQColor & foregroundLabelColor() const
virtual void setColumnInfo(KexiDB::QueryColumnInfo *cinfo)
virtual void setReadOnly(bool readOnly)
virtual bool cursorAtStart()
void changeText(const TQString &text, bool beautify=true)
const TQColor & backgroundLabelColor() const
void setFieldTypeInternal(int kexiDBFieldType)
virtual void setInvalidState(const TQString &text)
virtual void setDisplayDefaultValue(TQWidget *widget, bool displayDefaultValue)
const TQColor & paletteBackgroundColor() const
Reimplemented to return internal editor's color.
virtual bool valueChanged()
virtual bool keyPressed(TQKeyEvent *ke)
virtual void moveCursorToStart()
Implemented for KexiDataItemInterface.
virtual void setPaletteBackgroundColor(const TQColor &color)
Reimplemented to set internal editor's color.
virtual bool setProperty(const char *name, const TQVariant &value)
Reimplemented to accept subproperties.
void setPaletteForegroundColor(const TQColor &color)
Reimplemented to set internal editor's color.
virtual bool valueIsEmpty()
virtual TQVariant property(const char *name) const
Reimplemented to accept subproperties.
virtual bool isReadOnly() const
virtual bool valueIsNull()
virtual void createEditor()
void copyPropertiesToEditor()
internal editor can be created too late, so certain properties should be copied
virtual void selectAll()
Implemented for KexiDataItemInterface.
virtual void setValueInternal(const TQVariant &add, bool removeOld)
virtual bool valueIsValid()
virtual bool cursorAtEnd()
void setColumnInfoInternal(KexiDB::QueryColumnInfo *cinfo, KexiDB::QueryColumnInfo *visibleColumnInfo)
Used by KexiDBAutoField::setColumnInfo() and KexiDBComboBox::setColumnInfo()
virtual void setBackgroundLabelColor(const TQColor &color)
Sets label's background color.
A db-aware check box.
Combo box widget for Kexi forms.
A data-aware, editable image box.
Line edit widget for Kexi forms.
Multiline edit widget for Kexi forms.
Type type() const
Definition field.cpp:134
@ ShortInteger
Definition field.h:86
@ InvalidType
Definition field.h:84
Helper class that assigns additional information for the column in a query.
Definition queryschema.h:49
TQString captionOrAliasOrName() const
Definition queryschema.h:65
An helper class used to react on KexiDataItemInterface objects' changes.
An interface for declaring widgets to be data-aware.
virtual bool cursorAtEnd()=0
void setParentDataItemInterface(KexiDataItemInterface *parentDataItemInterface)
virtual bool cursorAtStart()=0
virtual bool isReadOnly() const
virtual TQVariant value()=0
virtual bool valueIsNull()=0
virtual bool valueIsEmpty()=0
void setValue(const TQVariant &value, const TQVariant &add=TQVariant(), bool removeOld=false, const TQVariant *visibleValue=0)
virtual void installListener(KexiDataItemChangesListener *listener)
Sets listener. No need to reimplement this.
virtual void clear()=0
clears item's data, so the data will contain NULL data
An interface for declaring form widgets to be data-aware.
virtual KexiDB::QueryColumnInfo * columnInfo() const
virtual void setVisibleColumnInfo(KexiDB::QueryColumnInfo *cinfo)
virtual void setColumnInfo(KexiDB::QueryColumnInfo *cinfo)
virtual void setDisplayDefaultValue(TQWidget *widget, bool displayDefaultValue)
virtual KexiDB::QueryColumnInfo * visibleColumnInfo() const
void setDataSource(const TQString &ds)
Sets the name of the data source for this widget.
virtual void setReadOnly(bool readOnly)=0
An interface allowing to define custom behaviour for subwidget of the KexiDBAutoField.
Definition kexidbutils.h:60