00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00039 class KEXIDATATABLE_EXPORT KexiTableEdit : public QWidget, public KexiDataItemInterface
00040 {
00041 Q_OBJECT
00042
00043 public:
00044 KexiTableEdit(KexiTableViewColumn &column, QWidget* parent = 0);
00045
00046 virtual ~KexiTableEdit();
00047
00050 virtual KexiDB::Field *field() const { return m_column->field(); }
00051
00054 virtual KexiDB::QueryColumnInfo *columnInfo() const { return m_column->columnInfo; }
00055
00058 virtual void setColumnInfo(KexiDB::QueryColumnInfo *) { }
00059
00062 inline KexiTableViewColumn *column() const { return m_column; }
00063
00069 KexiDB::Field *displayedField() const;
00070
00072 virtual void resize(int w, int h);
00073
00075 virtual QWidget* widget() { return m_view; }
00076
00078 inline virtual void hideWidget() { hide(); }
00079
00081 inline virtual void showWidget() { show(); }
00082
00086 virtual void paintFocusBorders( QPainter *p, QVariant &cal, int x, int y, int w, int h );
00087
00104 virtual void setupContents( QPainter *p, bool focused, const QVariant& val,
00105 QString &txt, int &align, int &x, int &y_offset, int &w, int &h );
00106
00113 bool usesSelectedTextColor() const { return m_usesSelectedTextColor; }
00114
00118 virtual void paintSelectionBackground( QPainter *p, bool focused, const QString& txt,
00119 int align, int x, int y_offset, int w, int h, const QColor& fillColor,
00120 const QFontMetrics &fm, bool readOnly, bool fullRowSelection );
00121
00125 int leftMargin() const { return m_leftMargin; }
00126
00130 int rightMargin(bool focused) const;
00131
00136 virtual bool handleKeyPress( QKeyEvent* ke, bool editorActive ) {
00137 Q_UNUSED(ke); Q_UNUSED(editorActive); return false; }
00138
00142 virtual bool handleDoubleClick() { return false; }
00143
00149 virtual void handleCopyAction(const QVariant& value, const QVariant& visibleValue) = 0;
00150
00153 virtual int widthForValue( QVariant &val, const QFontMetrics &fm );
00154
00158 virtual QSize totalSize() { return QWidget::size(); }
00159
00166 virtual bool showToolTipIfNeeded(const QVariant& value, const QRect& rect, const QFontMetrics& fm,
00167 bool focused);
00168
00172 virtual void createInternalEditor(KexiDB::QuerySchema& schema) { Q_UNUSED(schema); }
00173
00174 signals:
00175 void editRequested();
00176 void cancelRequested();
00177 void acceptRequested();
00178
00179 protected:
00180 virtual bool eventFilter(QObject* watched, QEvent* e);
00181
00184 void setViewWidget(QWidget *v);
00185
00188 void moveChild( QWidget * child, int x, int y );
00189
00192 void repaintRelatedCell();
00193
00194 KexiTableViewColumn *m_column;
00195 int m_leftMargin;
00196 int m_rightMargin, m_rightMarginWhenFocused;
00197 QScrollView* m_scrollView;
00198 bool m_usesSelectedTextColor : 1;
00199
00200 private:
00201 QWidget* m_view;
00202 };
00203
00205 #define KEXI_DECLARE_CELLEDITOR_FACTORY_ITEM(factoryclassname) \
00206 class factoryclassname : public KexiCellEditorFactoryItem \
00207 { \
00208 public: \
00209 factoryclassname(); \
00210 virtual ~factoryclassname(); \
00211 \
00212 protected: \
00213 virtual KexiTableEdit* createEditor(KexiTableViewColumn &column, QWidget* parent = 0); \
00214 };
00215
00217 #define KEXI_CELLEDITOR_FACTORY_ITEM_IMPL(factoryclassname, itemclassname) \
00218 factoryclassname::factoryclassname() \
00219 : KexiCellEditorFactoryItem() \
00220 { \
00221 m_className = "" #itemclassname ""; \
00222 } \
00223 \
00224 factoryclassname::~factoryclassname() \
00225 {} \
00226 \
00227 KexiTableEdit* factoryclassname::createEditor( \
00228 KexiTableViewColumn &column, QWidget* parent) \
00229 { \
00230 return new itemclassname(column, parent); \
00231 }
00232
00233 #endif