summaryrefslogtreecommitdiffstats
path: root/kexi/widget/tableview/kexicomboboxtableedit.h
blob: 7b8a7339e6819ca9a7535cb3cf26a2d283cbab3d (plain)
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
/* This file is part of the KDE project
   Copyright (C) 2002   Peter Simonsson <psn@linux.se>
   Copyright (C) 2003-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 _KEXICOMBOBOXTABLEEDIT_H_
#define _KEXICOMBOBOXTABLEEDIT_H_

#include "kexidb/field.h"
#include "kexiinputtableedit.h"
#include "kexicomboboxbase.h"
#include <kexidb/lookupfieldschema.h>

class KPushButton;
class KLineEdit;
class KexiComboBoxPopup;
class KexiTableItem;
class KexiTableViewColumn;

/*! @short Drop-down cell editor.
*/
class KexiComboBoxTableEdit : public KexiInputTableEdit, public KexiComboBoxBase
{
	Q_OBJECT
  TQ_OBJECT

	public:
		KexiComboBoxTableEdit(KexiTableViewColumn &column, TQWidget *tqparent=0);
		virtual ~KexiComboBoxTableEdit();

		//! Implemented for KexiComboBoxBase
		virtual KexiTableViewColumn *column() const { return m_column; }

		//! Implemented for KexiComboBoxBase
		virtual KexiDB::Field *field() const { return m_column->field(); }

		//! Implemented for KexiComboBoxBase
		virtual TQVariant origValue() const { return m_origValue; }

		virtual void setValueInternal(const TQVariant& add, bool removeOld)
			{ KexiComboBoxBase::setValueInternal(add, removeOld); }

		virtual TQVariant value() { return KexiComboBoxBase::value(); }

		virtual void clear();

		virtual bool valueChanged();

		virtual TQVariant visibleValue();

		/*! Reimplemented: resizes a view(). */
		virtual void resize(int w, int h);

		virtual void showFocus( const TQRect& r, bool readOnly );

		virtual void hideFocus();

		virtual void paintFocusBorders( TQPainter *p, TQVariant &cal, int x, int y, int w, int h );

		/*! Setups contents of the cell. As a special case, if there is lookup field schema 
		 defined, \a val already contains the visible value (usually the text)
		 set by \ref KexiTableView::paintcell(), so there is noo need to lookup the value 
		 in the combo box's popup. */
		virtual void setupContents( TQPainter *p, bool focused, const TQVariant& val, 
			TQString &txt, int &align, int &x, int &y_offset, int &w, int &h );

		/*! Used to handle key press events for the item. */
		virtual bool handleKeyPress( TQKeyEvent *ke, bool editorActive );

		virtual int widthForValue( TQVariant &val, const TQFontMetrics &fm );
	
		virtual void hide();
		virtual void show();

		/*! \return total size of this editor, including popup button. */
		virtual TQSize totalSize() const;

		virtual void createInternalEditor(KexiDB::QuerySchema& schema);

		/*! Reimplemented after KexiInputTableEdit. */
		virtual void handleAction(const TQString& actionName);

		/*! Reimplemented after KexiInputTableEdit. 
		 For a special case (combo box), \a visibleValue can be provided,
		 so it can be copied to the clipboard instead of unreadable \a value. */
		virtual void handleCopyAction(const TQVariant& value, const TQVariant& visibleValue);

	public slots:
		//! Implemented for KexiDataItemInterface
		virtual void moveCursorToEnd();

		//! Implemented for KexiDataItemInterface
		virtual void moveCursorToStart();

		//! Implemented for KexiDataItemInterface
		virtual void selectAll();

	protected slots:
		void slotButtonClicked();
		void slotRowAccepted(KexiTableItem *item, int row) { KexiComboBoxBase::slotRowAccepted(item, row); }
		void slotItemSelected(KexiTableItem* item) { KexiComboBoxBase::slotItemSelected(item); }
		void slotInternalEditorValueChanged(const TQVariant& v)
			{ KexiComboBoxBase::slotInternalEditorValueChanged(v); }
		void slotLineEditTextChanged(const TQString& s);
		void slotPopupHidden();

	protected:
		//! internal
		void updateFocus( const TQRect& r );

		virtual bool eventFilter( TQObject *o, TQEvent *e );

		//! Implemented for KexiComboBoxBase
		virtual TQWidget *internalEditor() const;

		//! Implemented for KexiComboBoxBase
		virtual void moveCursorToEndInInternalEditor();

		//! Implemented for KexiComboBoxBase
		virtual void selectAllInInternalEditor();

		//! Implemented for KexiComboBoxBase
		virtual void setValueInInternalEditor(const TQVariant& value);

		//! Implemented for KexiComboBoxBase
		virtual TQVariant valueFromInternalEditor();

		//! Implemented for KexiComboBoxBase
		virtual void editRequested() { KexiInputTableEdit::editRequested(); }

		//! Implemented for KexiComboBoxBase
		virtual void acceptRequested() { KexiInputTableEdit::acceptRequested(); }

		//! Implemented for KexiComboBoxBase
		virtual TQPoint mapFromParentToGlobal(const TQPoint& pos) const;

		//! Implemented for KexiComboBoxBase
		virtual int popupWidthHint() const;

		//! Implemented this to update button state. 
		virtual void updateButton();

		virtual KexiComboBoxPopup *popup() const;
		virtual void setPopup(KexiComboBoxPopup *popup);

		class Private;
		Private *d;
};

KEXI_DECLARE_CELLEDITOR_FACTORY_ITEM(KexiComboBoxEditorFactoryItem)

#endif