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
|
/* 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-2006 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.
*/
#ifndef KEXIDBAUTOFIELD_H
#define KEXIDBAUTOFIELD_H
#include <qwidget.h>
#include <kexidb/field.h>
#include <formeditor/container.h>
#include <formeditor/widgetwithsubpropertiesinterface.h>
#include "kexiformdataiteminterface.h"
class QBoxLayout;
class QLabel;
//! Universal "Auto Field" widget for Kexi forms
/*! It acts as a container for most data-aware widgets. */
class KEXIFORMUTILS_EXPORT KexiDBAutoField :
public QWidget,
public KexiFormDataItemInterface,
public KFormDesigner::DesignTimeDynamicChildWidgetHandler,
public KFormDesigner::WidgetWithSubpropertiesInterface
{
Q_OBJECT
//'caption' is uncovered now Q_PROPERTY(QString labelCaption READ caption WRITE setCaption DESIGNABLE true)
Q_OVERRIDE(QString caption READ caption WRITE setCaption DESIGNABLE true)
Q_OVERRIDE(QColor paletteForegroundColor READ paletteForegroundColor WRITE setPaletteForegroundColor DESIGNABLE true RESET unsetPalette)
Q_OVERRIDE(QColor paletteBackgroundColor READ paletteBackgroundColor WRITE setPaletteBackgroundColor DESIGNABLE true RESET unsetPalette)
Q_PROPERTY(QColor foregroundLabelColor READ foregroundLabelColor WRITE setForegroundLabelColor DESIGNABLE true RESET unsetPalette)
Q_PROPERTY(QColor backgroundLabelColor READ backgroundLabelColor WRITE setBackgroundLabelColor DESIGNABLE true RESET unsetPalette)
Q_PROPERTY(bool autoCaption READ hasAutoCaption WRITE setAutoCaption DESIGNABLE true)
Q_PROPERTY(QString dataSource READ dataSource WRITE setDataSource DESIGNABLE true)
Q_PROPERTY(QCString dataSourceMimeType READ dataSourceMimeType WRITE setDataSourceMimeType DESIGNABLE true)
Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
Q_PROPERTY(LabelPosition labelPosition READ labelPosition WRITE setLabelPosition DESIGNABLE true)
Q_PROPERTY(WidgetType widgetType READ widgetType WRITE setWidgetType DESIGNABLE true)
/*internal, for design time only*/
Q_PROPERTY(int fieldTypeInternal READ fieldTypeInternal WRITE setFieldTypeInternal DESIGNABLE true STORED false)
Q_PROPERTY(QString fieldCaptionInternal READ fieldCaptionInternal WRITE setFieldCaptionInternal DESIGNABLE true STORED false)
Q_ENUMS( WidgetType LabelPosition )
public:
enum WidgetType { Auto = 100, Text, Integer, Double, Boolean, Date, Time, DateTime,
MultiLineText, ComboBox, Image };
enum LabelPosition { Left = 300, Top, NoLabel };
KexiDBAutoField(const QString &text, WidgetType type, LabelPosition pos,
QWidget *parent = 0, const char *name = 0, bool designMode = true);
KexiDBAutoField(QWidget *parent = 0, const char *name = 0, bool designMode = true,
LabelPosition pos = Left);
virtual ~KexiDBAutoField();
inline QString dataSource() const { return KexiFormDataItemInterface::dataSource(); }
inline QCString dataSourceMimeType() const { return KexiFormDataItemInterface::dataSourceMimeType(); }
virtual void setDataSource( const QString &ds );
virtual void setDataSourceMimeType(const QCString &ds) { KexiFormDataItemInterface::setDataSourceMimeType(ds); }
virtual void setColumnInfo(KexiDB::QueryColumnInfo* cinfo);
virtual void setInvalidState(const QString& text);
virtual bool isReadOnly() const;
virtual void setReadOnly( bool readOnly );
virtual QVariant value();
virtual bool valueIsNull();
virtual bool valueIsEmpty();
virtual bool valueIsValid();
virtual bool valueChanged();
virtual void clear();
//! Reimpelmented to also install \a listenter for internal editor
virtual void installListener(KexiDataItemChangesListener* listener);
WidgetType widgetType() const;
void setWidgetType(WidgetType type);
LabelPosition labelPosition() const;
virtual void setLabelPosition(LabelPosition position);
QString caption() const;
void setCaption(const QString &caption);
bool hasAutoCaption() const;
void setAutoCaption(bool autoCaption);
/*! If \a displayDefaultValue is true, the value set by KexiDataItemInterface::setValue()
is displayed in a special way. Used by KexiFormDataProvider::fillDataItems().
\a widget is equal to 'this'.
Reimplemented after KexiFormDataItemInterface. */
virtual void setDisplayDefaultValue(QWidget* widget, bool displayDefaultValue);
QWidget* editor() const;
QLabel* label() const;
virtual bool cursorAtStart();
virtual bool cursorAtEnd();
static WidgetType widgetTypeForFieldType(KexiDB::Field::Type type);
/*! On design time it is not possible to pass a reference to KexiDB::Field object
so we're just providing field type. Only used when widget type is Auto.
@internal */
void setFieldTypeInternal(int kexiDBFieldType);
/*! On design time it is not possible to pass a reference to KexiDB::Field object
so we're just providing field caption. Only used when widget type is Auto.
@internal */
void setFieldCaptionInternal(const QString& text);
/*! @internal */
int fieldTypeInternal() const;
/*! @internal */
QString fieldCaptionInternal() const;
virtual QSize sizeHint() const;
virtual void setFocusPolicy ( FocusPolicy policy );
//! Reimplemented to return internal editor's color.
const QColor & paletteForegroundColor() const;
//! Reimplemented to set internal editor's color.
void setPaletteForegroundColor( const QColor & color );
//! Reimplemented to return internal editor's color.
const QColor & paletteBackgroundColor() const;
//! Reimplemented to set internal editor's color.
virtual void setPaletteBackgroundColor( const QColor & color );
//! \return label's foreground color
const QColor & foregroundLabelColor() const;
//! Sets label's foreground color
virtual void setForegroundLabelColor( const QColor & color );
//! \return label's background color
const QColor & backgroundLabelColor() const;
//! Sets label's background color
virtual void setBackgroundLabelColor( const QColor & color );
//! Reimplemented to accept subproperties. @see KFormDesigner::WidgetWithSubpropertiesInterface
virtual QVariant property( const char * name ) const;
//! Reimplemented to accept subproperties. @see KFormDesigner::WidgetWithSubpropertiesInterface
virtual bool setProperty( const char * name, const QVariant & value );
/*! Called by the top-level form on key press event to consume widget-specific shortcuts. */
virtual bool keyPressed(QKeyEvent *ke);
public slots:
virtual void unsetPalette();
protected slots:
// void slotValueChanged();
virtual void paletteChange( const QPalette& oldPal );
//! Implemented for KexiDataItemInterface
virtual void moveCursorToEnd();
//! Implemented for KexiDataItemInterface
virtual void moveCursorToStart();
//! Implemented for KexiDataItemInterface
virtual void selectAll();
protected:
virtual void setValueInternal(const QVariant&add, bool removeOld);
void init(const QString &text, WidgetType type, LabelPosition pos);
virtual void createEditor();
void changeText(const QString &text, bool beautify = true);
// virtual void paintEvent( QPaintEvent* pe );
void updateInformationAboutUnboundField();
//! internal editor can be created too late, so certain properties should be copied
void copyPropertiesToEditor();
virtual bool eventFilter( QObject *o, QEvent *e );
//! Used by @ref setLabelPositionInternal(LabelPosition)
void setLabelPositionInternal(LabelPosition position, bool noLabel);
//! Used by KexiDBAutoField::setColumnInfo() and KexiDBComboBox::setColumnInfo()
void setColumnInfoInternal(KexiDB::QueryColumnInfo* cinfo, KexiDB::QueryColumnInfo* visibleColumnInfo);
private:
class Private;
Private *d;
};
#endif
|