kexi

kexitableedit.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002 Peter Simonsson <psn@linux.se>
00003    Copyright (C) 2003-2005 Jaroslaw Staniek <js@iidea.pl>
00004 
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this program; see the file COPYING.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef _KEXITABLEEDIT_H_
00022 #define _KEXITABLEEDIT_H_
00023 
00024 #include <kexidataiteminterface.h>
00025 
00026 #include <qvariant.h>
00027 #include <qscrollview.h>
00028 
00029 #include "kexitableviewdata.h"
00030 
00031 namespace KexiDB {
00032     class Field;
00033     class QueryColumnInfo;
00034 }
00035 
00038 class KEXIDATATABLE_EXPORT KexiTableEdit : public QWidget, public KexiDataItemInterface
00039 {
00040     Q_OBJECT
00041 
00042     public:
00043         KexiTableEdit(KexiTableViewColumn &column, QScrollView* parent = 0, const char* name = 0);
00044 
00045         virtual ~KexiTableEdit();
00046 
00049         virtual KexiDB::Field *field() const { return m_column->field(); }
00050 
00053         virtual KexiDB::QueryColumnInfo *columnInfo() const { return m_column->fieldinfo; }
00054 
00057         virtual void setColumnInfo(KexiDB::QueryColumnInfo *) { }
00058 
00061         inline KexiTableViewColumn *column() const { return m_column; }
00062 
00064         virtual void resize(int w, int h);
00065 
00067         virtual QWidget* widget() { return m_view; }
00068 
00070         inline virtual void hideWidget() { hide(); }
00071 
00073         inline virtual void showWidget() { show(); }
00074 
00078         virtual void paintFocusBorders( QPainter *p, QVariant &cal, int x, int y, int w, int h );
00079 
00090         virtual void setupContents( QPainter *p, bool focused, QVariant val, 
00091             QString &txt, int &align, int &x, int &y_offset, int &w, int &h );
00092 
00097         virtual void paintSelectionBackground( QPainter *p, bool focused, const QString& txt, 
00098             int align, int x, int y_offset, int w, int h, const QColor& fillColor,
00099             bool readOnly, bool fullRowSelection );
00100 
00104         int leftMargin() const { return m_leftMargin; }
00105 
00109         int rightMargin() const { return m_rightMargin; }
00110 
00115         virtual bool handleKeyPress( QKeyEvent * /*ke*/, bool /*editorActive*/ ) { return false; }
00116 
00119         virtual int widthForValue( QVariant &val, QFontMetrics &fm );
00120 
00124         virtual QSize totalSize() { return QWidget::size(); }
00125 
00126     signals:
00127         void editRequested();
00128         void cancelRequested();
00129         void acceptRequested();
00130 
00131     protected:
00132         virtual bool eventFilter(QObject* watched, QEvent* e);
00133 
00136         void setViewWidget(QWidget *v);
00137 
00140         void moveChild( QWidget * child, int x, int y ) {
00141             m_scrollView->moveChild(child, x, y); }
00142 
00143         KexiTableViewColumn *m_column;
00144         int m_leftMargin;
00145         int m_rightMargin;
00146         QScrollView* m_scrollView;
00147 
00148     private:
00149         QWidget* m_view;
00150 };
00151 
00153 #define KEXI_DECLARE_CELLEDITOR_FACTORY_ITEM(factoryclassname) \
00154     class factoryclassname : public KexiCellEditorFactoryItem \
00155     { \
00156         public: \
00157             factoryclassname(); \
00158             virtual ~factoryclassname(); \
00159     \
00160         protected: \
00161             virtual KexiTableEdit* createEditor(KexiTableViewColumn &column, QScrollView* parent = 0); \
00162     };
00163 
00165 #define KEXI_CELLEDITOR_FACTORY_ITEM_IMPL(factoryclassname, itemclassname) \
00166 factoryclassname::factoryclassname() \
00167  : KexiCellEditorFactoryItem() \
00168 {} \
00169 \
00170 factoryclassname::~factoryclassname() \
00171 {} \
00172 \
00173 KexiTableEdit* factoryclassname::createEditor( \
00174     KexiTableViewColumn &column, QScrollView* parent) \
00175 { \
00176     return new itemclassname(column, parent); \
00177 }
00178 
00179 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys