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 Jarosław Staniek <staniek@kde.org>
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.
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.
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.
22
#ifndef KEXIDBAUTOFIELD_H
23
#define KEXIDBAUTOFIELD_H
25
#include "kexiformutils_export.h"
26
#include <formeditor/container.h>
27
#include <formeditor/widgetwithsubpropertiesinterface.h>
28
#include <formeditor/FormWidgetInterface.h>
29
#include <widget/dataviewcommon/kexiformdataiteminterface.h>
38
//! Universal "Auto Field" widget for Kexi forms
39
/*! It acts as a container for most data-aware widgets. */
40
class KEXIFORMUTILS_EXPORT KexiDBAutoField :
42
public KexiFormDataItemInterface,
43
public KFormDesigner::DesignTimeDynamicChildWidgetHandler,
44
public KFormDesigner::WidgetWithSubpropertiesInterface,
45
public KFormDesigner::FormWidgetInterface
48
//'caption' is uncovered now Q_PROPERTY(QString labelCaption READ caption WRITE setCaption)
49
Q_PROPERTY(QString caption READ caption WRITE setCaption)
50
Q_PROPERTY(QColor foregroundLabelColor READ foregroundLabelColor WRITE setForegroundLabelColor RESET unsetPalette)
51
Q_PROPERTY(QColor backgroundLabelColor READ backgroundLabelColor WRITE setBackgroundLabelColor RESET unsetPalette)
52
Q_PROPERTY(bool autoCaption READ hasAutoCaption WRITE setAutoCaption)
53
Q_PROPERTY(QString dataSource READ dataSource WRITE setDataSource)
54
Q_PROPERTY(QString dataSourcePartClass READ dataSourcePluginId WRITE setDataSourcePluginId)
55
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
56
Q_PROPERTY(LabelPosition labelPosition READ labelPosition WRITE setLabelPosition)
57
Q_PROPERTY(WidgetType widgetType READ widgetType WRITE setWidgetType)
58
/*internal, for design time only*/
59
Q_PROPERTY(int fieldTypeInternal READ fieldTypeInternal WRITE setFieldTypeInternal STORED false)
60
Q_PROPERTY(QString fieldCaptionInternal READ fieldCaptionInternal WRITE setFieldCaptionInternal STORED false)
63
enum WidgetType { Auto = 100, Text, Integer, Double, Boolean, Date, Time, DateTime,
64
MultiLineText, ComboBox, Image
67
enum LabelPosition { Left = 300, Top, NoLabel };
70
KexiDBAutoField(const QString &text, WidgetType type, LabelPosition pos,
72
explicit KexiDBAutoField(QWidget *parent = 0, LabelPosition pos = Left);
74
virtual ~KexiDBAutoField();
76
inline QString dataSource() const {
77
return KexiFormDataItemInterface::dataSource();
79
inline QString dataSourcePluginId() const {
80
return KexiFormDataItemInterface::dataSourcePluginId();
82
virtual void setDataSource(const QString &ds);
83
virtual void setDataSourcePluginId(const QString &pluginId) {
84
KexiFormDataItemInterface::setDataSourcePluginId(pluginId);
86
virtual void setColumnInfo(KDbQueryColumnInfo* cinfo);
88
virtual void setInvalidState(const QString& text);
89
virtual bool isReadOnly() const;
90
virtual void setReadOnly(bool readOnly);
92
virtual QVariant value();
93
virtual bool valueIsNull();
94
virtual bool valueIsEmpty();
95
virtual bool valueIsValid();
96
virtual bool valueChanged();
99
//! Reimplemented to also install \a listenter for internal editor
100
virtual void installListener(KexiDataItemChangesListener* listener);
102
WidgetType widgetType() const;
103
void setWidgetType(WidgetType type);
105
LabelPosition labelPosition() const;
106
virtual void setLabelPosition(LabelPosition position);
108
QString caption() const;
109
void setCaption(const QString &caption);
111
bool hasAutoCaption() const;
112
void setAutoCaption(bool autoCaption);
114
/*! If \a displayDefaultValue is true, the value set by KexiDataItemInterface::setValue()
115
is displayed in a special way. Used by KexiFormDataProvider::fillDataItems().
116
\a widget is equal to 'this'.
117
Reimplemented after KexiFormDataItemInterface. */
118
virtual void setDisplayDefaultValue(QWidget* widget, bool displayDefaultValue);
120
QWidget* editor() const;
121
QLabel* label() const;
123
virtual bool cursorAtStart();
124
virtual bool cursorAtEnd();
126
static WidgetType widgetTypeForFieldType(KDbField::Type type);
128
/*! On design time it is not possible to pass a reference to KDbField object
129
so we're just providing field type. Only used when widget type is Auto.
131
void setFieldTypeInternal(int kexiDBFieldType);
133
/*! On design time it is not possible to pass a reference to KDbField object
134
so we're just providing field caption. Only used when widget type is Auto.
136
void setFieldCaptionInternal(const QString& text);
139
int fieldTypeInternal() const;
142
QString fieldCaptionInternal() const;
144
virtual QSize sizeHint() const;
145
virtual void setFocusPolicy(Qt::FocusPolicy policy);
147
//! Reimplemented to return internal editor's color.
148
QColor paletteForegroundColor() const;
150
//! Reimplemented to set internal editor's color.
151
void setPaletteForegroundColor(const QColor & color);
153
//! Reimplemented to return internal editor's color.
154
QColor paletteBackgroundColor() const;
156
//! Reimplemented to set internal editor's color.
157
virtual void setPaletteBackgroundColor(const QColor & color);
159
//! \return label's foreground color
160
QColor foregroundLabelColor() const;
162
//! Sets label's foreground color
163
virtual void setForegroundLabelColor(const QColor & color);
165
//! \return label's background color
166
QColor backgroundLabelColor() const;
168
//! Sets label's background color
169
virtual void setBackgroundLabelColor(const QColor & color);
171
//! Reimplemented to accept subproperties. @see KFormDesigner::WidgetWithSubpropertiesInterface
172
virtual QVariant property(const char * name) const;
174
//! Reimplemented to accept subproperties. @see KFormDesigner::WidgetWithSubpropertiesInterface
175
virtual bool setProperty(const char * name, const QVariant & value);
177
/*! Called by the top-level form on key press event to consume widget-specific shortcuts. */
178
virtual bool keyPressed(QKeyEvent *ke);
181
virtual void unsetPalette();
184
virtual void paletteChange(const QPalette& oldPal);
186
//! Implemented for KexiDataItemInterface
187
virtual void moveCursorToEnd();
189
//! Implemented for KexiDataItemInterface
190
virtual void moveCursorToStart();
192
//! Implemented for KexiDataItemInterface
193
virtual void selectAll();
196
virtual void setValueInternal(const QVariant&add, bool removeOld);
197
void init(const QString &text, WidgetType type, LabelPosition pos);
198
virtual void createEditor();
199
void changeText(const QString &text, bool beautify = true);
200
void updateInformationAboutUnboundField();
202
//! internal editor can be created too late, so certain properties should be copied
203
void copyPropertiesToEditor();
205
virtual bool eventFilter(QObject *o, QEvent *e);
207
//! Used by @ref setLabelPositionInternal(LabelPosition)
208
void setLabelPositionInternal(LabelPosition position, bool noLabel);
210
//! Used by KexiDBAutoField::setColumnInfo() and KexiDBComboBox::setColumnInfo()
211
void setColumnInfoInternal(KDbQueryColumnInfo* cinfo, KDbQueryColumnInfo* visibleColumnInfo);