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