kexi

kexidbautofield.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Cedric Pasteur <cedric.pasteur@free.fr>
00003    Copyright (C) 2005 Christian Nitschkowski <segfault_ii@web.de>
00004    Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
00005 
00006    This program is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this program; see the file COPYING.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #ifndef KEXIDBAUTOFIELD_H
00023 #define KEXIDBAUTOFIELD_H
00024 
00025 #include <qwidget.h>
00026 #include <kexidb/field.h>
00027 #include <formeditor/container.h>
00028 #include "kexiformdataiteminterface.h"
00029 
00030 class QBoxLayout;
00031 class QLabel;
00032 
00034 
00035 class KEXIFORMUTILS_EXPORT KexiDBAutoField : 
00036     public QWidget,
00037     public KexiFormDataItemInterface,
00038     public KFormDesigner::DesignTimeDynamicChildWidgetHandler
00039 {
00040     Q_OBJECT
00041 //'caption' is uncovered now    Q_PROPERTY(QString labelCaption READ caption WRITE setCaption DESIGNABLE true)
00042     Q_OVERRIDE(QString caption READ caption WRITE setCaption DESIGNABLE true)
00043     Q_PROPERTY(bool autoCaption READ hasAutoCaption WRITE setAutoCaption DESIGNABLE true)
00044     Q_PROPERTY(QString dataSource READ dataSource WRITE setDataSource DESIGNABLE true)
00045     Q_PROPERTY(QCString dataSourceMimeType READ dataSourceMimeType WRITE setDataSourceMimeType DESIGNABLE true)
00046     Q_PROPERTY(LabelPosition labelPosition READ labelPosition WRITE setLabelPosition DESIGNABLE true)
00047     Q_PROPERTY(WidgetType widgetType READ widgetType WRITE setWidgetType DESIGNABLE true)
00048     /*internal, for design time only*/
00049     Q_PROPERTY(int fieldTypeInternal READ fieldTypeInternal WRITE setFieldTypeInternal DESIGNABLE true STORED false)
00050     Q_PROPERTY(QString fieldCaptionInternal READ fieldCaptionInternal WRITE setFieldCaptionInternal DESIGNABLE true STORED false)
00051     Q_ENUMS( WidgetType LabelPosition )
00052 
00053     public:
00054         enum WidgetType { Auto = 100, Text, Integer, Double, Boolean, Date, Time, DateTime,
00055             MultiLineText, Enum, Image };
00056         enum LabelPosition { Left = 300, Top, NoLabel };
00057 
00058         KexiDBAutoField(const QString &text, WidgetType type, LabelPosition pos, QWidget *parent = 0, const char *name = 0, bool designMode = true);
00059         KexiDBAutoField(QWidget *parent = 0, const char *name = 0, bool designMode = true);
00060 
00061         virtual ~KexiDBAutoField();
00062 
00063         inline QString dataSource() const { return KexiFormDataItemInterface::dataSource(); }
00064         inline QCString dataSourceMimeType() const { return KexiFormDataItemInterface::dataSourceMimeType(); }
00065         virtual void setDataSource( const QString &ds );
00066         virtual void setDataSourceMimeType(const QCString &ds) { KexiFormDataItemInterface::setDataSourceMimeType(ds); }
00067         virtual void setColumnInfo(KexiDB::QueryColumnInfo* cinfo);
00068 
00069         virtual void setInvalidState(const QString& text);
00070         virtual bool isReadOnly() const;
00071 
00072         virtual QVariant value();
00073         virtual bool valueIsNull();
00074         virtual bool valueIsEmpty();
00075         virtual bool valueChanged();
00076         virtual void clear();
00077 
00079         virtual void installListener(KexiDataItemChangesListener* listener);
00080 
00081         WidgetType widgetType() const { return m_widgetType_property; }
00082         void setWidgetType(WidgetType type);
00083 
00084         LabelPosition labelPosition() const { return m_lblPosition; }
00085         void setLabelPosition(LabelPosition position);
00086 
00087         QString caption() const { return m_caption; }
00088         void setCaption(const QString &caption);
00089 
00090         bool hasAutoCaption() const { return m_autoCaption; }
00091         void setAutoCaption(bool autoCaption);
00092 
00093         QWidget* editor() const { return m_editor; }
00094         QLabel* label() const { return m_label; }
00095 
00096         virtual bool cursorAtStart();
00097         virtual bool cursorAtEnd();
00098 
00099         static WidgetType widgetTypeForFieldType(KexiDB::Field::Type type);
00100 
00104         void setFieldTypeInternal(int kexiDBFieldType);
00105 
00109         void setFieldCaptionInternal(const QString& text);
00110 
00112         int fieldTypeInternal() const { return m_fieldTypeInternal; }
00113 
00115         QString fieldCaptionInternal() const { return m_fieldCaptionInternal; }
00116 
00117         virtual QSize sizeHint() const;
00118         virtual void setFocusPolicy ( FocusPolicy policy );
00119 
00120     protected:
00121         virtual void setValueInternal(const QVariant&add, bool removeOld);
00122         void init(const QString &text, WidgetType type, LabelPosition pos);
00123         void createEditor();
00124         void changeText(const QString &text, bool beautify = true);
00125 //      virtual void paintEvent( QPaintEvent* pe );
00126         void updateInformationAboutUnboundField();
00127 
00128     protected slots:
00129         void slotValueChanged();
00130         virtual void paletteChange( const QPalette& oldPal );
00131 
00132     private:
00133         WidgetType m_widgetType; 
00134 
00135         WidgetType  m_widgetType_property; 
00136         LabelPosition  m_lblPosition;
00137         QBoxLayout  *m_layout;
00138         QLabel  *m_label;
00139         QWidget *m_editor;
00140         QString  m_caption;
00141         KexiDB::Field::Type m_fieldTypeInternal;
00142         QString m_fieldCaptionInternal;
00143         bool m_autoCaption : 1;
00144         bool m_focusPolicyChanged : 1;
00145         bool m_designMode : 1;
00146 };
00147 
00148 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys