kexidbautofield.h
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-2006 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#ifndef KEXIDBAUTOFIELD_H
23#define KEXIDBAUTOFIELD_H
24
25#include <tqwidget.h>
26#include <kexidb/field.h>
27#include <formeditor/container.h>
28#include <formeditor/widgetwithsubpropertiesinterface.h>
29#include "kexiformdataiteminterface.h"
30
31class TQBoxLayout;
32class TQLabel;
33
35
36class KEXIFORMUTILS_EXPORT KexiDBAutoField :
37 public TQWidget,
41{
42 TQ_OBJECT
43
44//'caption' is uncovered now TQ_PROPERTY(TQString labelCaption READ caption WRITE setCaption DESIGNABLE true)
45 TQ_OVERRIDE(TQString caption READ caption WRITE setCaption DESIGNABLE true)
46 TQ_OVERRIDE(TQColor paletteForegroundColor READ paletteForegroundColor WRITE setPaletteForegroundColor DESIGNABLE true RESET unsetPalette)
47 TQ_OVERRIDE(TQColor paletteBackgroundColor READ paletteBackgroundColor WRITE setPaletteBackgroundColor DESIGNABLE true RESET unsetPalette)
48 TQ_PROPERTY(TQColor foregroundLabelColor READ foregroundLabelColor WRITE setForegroundLabelColor DESIGNABLE true RESET unsetPalette)
49 TQ_PROPERTY(TQColor backgroundLabelColor READ backgroundLabelColor WRITE setBackgroundLabelColor DESIGNABLE true RESET unsetPalette)
50 TQ_PROPERTY(bool autoCaption READ hasAutoCaption WRITE setAutoCaption DESIGNABLE true)
51 TQ_PROPERTY(TQString dataSource READ dataSource WRITE setDataSource DESIGNABLE true)
52 TQ_PROPERTY(TQCString dataSourceMimeType READ dataSourceMimeType WRITE setDataSourceMimeType DESIGNABLE true)
53 TQ_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
54 TQ_PROPERTY(LabelPosition labelPosition READ labelPosition WRITE setLabelPosition DESIGNABLE true)
55 TQ_PROPERTY(WidgetType widgetType READ widgetType WRITE setWidgetType DESIGNABLE true)
56 /*internal, for design time only*/
57 TQ_PROPERTY(int fieldTypeInternal READ fieldTypeInternal WRITE setFieldTypeInternal DESIGNABLE true STORED false)
58 TQ_PROPERTY(TQString fieldCaptionInternal READ fieldCaptionInternal WRITE setFieldCaptionInternal DESIGNABLE true STORED false)
59 TQ_ENUMS( WidgetType LabelPosition )
60
61 public:
62 enum WidgetType { Auto = 100, Text, Integer, Double, Boolean, Date, Time, DateTime,
63 MultiLineText, ComboBox, Image };
64 enum LabelPosition { Left = 300, Top, NoLabel };
65
66 KexiDBAutoField(const TQString &text, WidgetType type, LabelPosition pos,
67 TQWidget *parent = 0, const char *name = 0, bool designMode = true);
68 KexiDBAutoField(TQWidget *parent = 0, const char *name = 0, bool designMode = true,
69 LabelPosition pos = Left);
70
71 virtual ~KexiDBAutoField();
72
73 inline TQString dataSource() const { return KexiFormDataItemInterface::dataSource(); }
74 inline TQCString dataSourceMimeType() const { return KexiFormDataItemInterface::dataSourceMimeType(); }
75 virtual void setDataSource( const TQString &ds );
76 virtual void setDataSourceMimeType(const TQCString &ds) { KexiFormDataItemInterface::setDataSourceMimeType(ds); }
77 virtual void setColumnInfo(KexiDB::QueryColumnInfo* cinfo);
78
79 virtual void setInvalidState(const TQString& text);
80 virtual bool isReadOnly() const;
81 virtual void setReadOnly( bool readOnly );
82
83 virtual TQVariant value();
84 virtual bool valueIsNull();
85 virtual bool valueIsEmpty();
86 virtual bool valueIsValid();
87 virtual bool valueChanged();
88 virtual void clear();
89
91 virtual void installListener(KexiDataItemChangesListener* listener);
92
93 WidgetType widgetType() const;
94 void setWidgetType(WidgetType type);
95
96 LabelPosition labelPosition() const;
97 virtual void setLabelPosition(LabelPosition position);
98
99 TQString caption() const;
100 void setCaption(const TQString &caption);
101
102 bool hasAutoCaption() const;
103 void setAutoCaption(bool autoCaption);
104
109 virtual void setDisplayDefaultValue(TQWidget* widget, bool displayDefaultValue);
110
111 TQWidget* editor() const;
112 TQLabel* label() const;
113
114 virtual bool cursorAtStart();
115 virtual bool cursorAtEnd();
116
117 static WidgetType widgetTypeForFieldType(KexiDB::Field::Type type);
118
122 void setFieldTypeInternal(int kexiDBFieldType);
123
127 void setFieldCaptionInternal(const TQString& text);
128
130 int fieldTypeInternal() const;
131
133 TQString fieldCaptionInternal() const;
134
135 virtual TQSize sizeHint() const;
136 virtual void setFocusPolicy ( TQWidget::FocusPolicy policy );
137
139 const TQColor & paletteForegroundColor() const;
140
142 void setPaletteForegroundColor( const TQColor & color );
143
145 const TQColor & paletteBackgroundColor() const;
146
148 virtual void setPaletteBackgroundColor( const TQColor & color );
149
151 const TQColor & foregroundLabelColor() const;
152
154 virtual void setForegroundLabelColor( const TQColor & color );
155
157 const TQColor & backgroundLabelColor() const;
158
160 virtual void setBackgroundLabelColor( const TQColor & color );
161
163 virtual TQVariant property( const char * name ) const;
164
166 virtual bool setProperty( const char * name, const TQVariant & value );
167
169 virtual bool keyPressed(TQKeyEvent *ke);
170
171 public slots:
172 virtual void unsetPalette();
173
174 protected slots:
175// void slotValueChanged();
176 virtual void paletteChange( const TQPalette& oldPal );
177
179 virtual void moveCursorToEnd();
180
182 virtual void moveCursorToStart();
183
185 virtual void selectAll();
186
187 protected:
188 virtual void setValueInternal(const TQVariant&add, bool removeOld);
189 void init(const TQString &text, WidgetType type, LabelPosition pos);
190 virtual void createEditor();
191 void changeText(const TQString &text, bool beautify = true);
192// virtual void paintEvent( TQPaintEvent* pe );
193 void updateInformationAboutUnboundField();
194
196 void copyPropertiesToEditor();
197
198 virtual bool eventFilter( TQObject *o, TQEvent *e );
199
201 void setLabelPositionInternal(LabelPosition position, bool noLabel);
202
204 void setColumnInfoInternal(KexiDB::QueryColumnInfo* cinfo, KexiDB::QueryColumnInfo* visibleColumnInfo);
205
206 private:
207 class Private;
208 Private *d;
209};
210
211#endif
Interface for adding dynamically created (at design time) widget to event eater.
Definition container.h:233
An interface for declaring form widgets to have subproperties.
Universal "Auto Field" widget for Kexi forms.
void setLabelPositionInternal(LabelPosition position, bool noLabel)
Used by setLabelPositionInternal(LabelPosition)
Helper class that assigns additional information for the column in a query.
Definition queryschema.h:49
An helper class used to react on KexiDataItemInterface objects' changes.
virtual bool cursorAtEnd()=0
virtual bool cursorAtStart()=0
virtual bool isReadOnly() const
virtual TQVariant value()=0
virtual bool valueIsNull()=0
virtual bool valueIsEmpty()=0
virtual void setValueInternal(const TQVariant &add, bool removeOld)=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.
void setDataSourceMimeType(const TQCString &ds)
virtual void setColumnInfo(KexiDB::QueryColumnInfo *cinfo)
virtual void setDisplayDefaultValue(TQWidget *widget, bool displayDefaultValue)
void setDataSource(const TQString &ds)
Sets the name of the data source for this widget.
virtual void setInvalidState(const TQString &displayText)=0
virtual void setReadOnly(bool readOnly)=0
type * findParent(TQObject *o, const char *className, TQObject *&prevPrev)