summaryrefslogtreecommitdiffstats
path: root/kexi/plugins/forms/widgets/kexidbcombobox.h
blob: c38027f8e4b7194839656855984425785a5729c4 (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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* This file is part of the KDE project
   Copyright (C) 2006-2007 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 KexiDBComboBox_H
#define KexiDBComboBox_H

#include "kexidbutils.h"
#include "kexidbautofield.h"
#include <widget/tableview/kexicomboboxbase.h>

//! @short Combo box widget for Kexi forms
/*! This widget is implemented on top of KexiDBAutoField, 
 so as it uses KexiDBAutoField's ability of embedding subwidgets,
 it can display not only a line edit but also text edit or image box
 (more can be added in the future). 
 A drop-down button is added to mimic native combo box widget's functionality.
*/
class KEXIFORMUTILS_EXPORT KexiDBComboBox : 
	public KexiDBAutoField, public KexiComboBoxBase
{
	Q_OBJECT
  
	TQ_PROPERTY( bool editable READ isEditable WRITE setEditable )
	//properties from KexiDBAutoField that should not be visible:
	TQ_OVERRIDE(TQColor paletteBackgroundColor READ paletteBackgroundColor WRITE setPaletteBackgroundColor DESIGNABLE true RESET unsetPalette)
	TQ_OVERRIDE(TQColor foregroundLabelColor DESIGNABLE false)
	TQ_OVERRIDE(TQColor backgroundLabelColor DESIGNABLE false)
	TQ_OVERRIDE(bool autoCaption DESIGNABLE false)

	public:
		KexiDBComboBox(TQWidget *parent, const char *name=0, bool designMode = true);
		virtual ~KexiDBComboBox();

		//! Implemented for KexiComboBoxBase: form has no 'related data' model (only the full database model)
		virtual KexiTableViewColumn *column() const { return 0; }

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

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

		void setEditable(bool set);
		bool isEditable() const;

		virtual void setLabelPosition(LabelPosition position);

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

		virtual TQVariant visibleValue();

		//! Reimpemented because to avoid taking value from the internal editor (index is taken from the popup instead)
		virtual bool valueChanged();

		virtual TQSize sizeHint() const;

		//! Reimplemented after KexiDBAutoField: jsut sets \a cinfo without initializing a subwidget.
		//! Initialization is performed by \ref setVisibleColumnInfo().
		virtual void setColumnInfo(KexiDB::QueryColumnInfo* cinfo);

		/*! Used internally to set visible database column information.
		 Reimplemented: performs initialization of the subwidget. */
		virtual void setVisibleColumnInfo(KexiDB::QueryColumnInfo* cinfo);

		/*! \return visible database column information for this item.
		 Reimplemented. */
		virtual KexiDB::QueryColumnInfo* visibleColumnInfo() const;

		const TQColor & paletteBackgroundColor() const { return KexiDBAutoField::paletteBackgroundColor(); }

		//! Reimplemented to also set 'this' widget's background color, not only subwidget's.
		virtual void setPaletteBackgroundColor( const TQColor & color );

		/*! Undoes changes made to this item - just resets the widget to original value. 
		 Reimplemented after KexiFormDataItemInterface to also revert the visible value 
		 (i.e. text) to the original state. */
		virtual void undoChanges();

	public slots:
		void slotRowAccepted(KexiTableItem *item, int row);
		void slotItemSelected(KexiTableItem* item) { KexiComboBoxBase::slotItemSelected(item); }

	protected slots:
		void slotInternalEditorValueChanged(const TQVariant& v)
			{ KexiComboBoxBase::slotInternalEditorValueChanged(v); }

	protected:
		TQRect buttonGeometry() const;

		virtual void paintEvent( TQPaintEvent * );

		virtual void mousePressEvent( TQMouseEvent *e );

		void mouseDoubleClickEvent( TQMouseEvent *e );

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

		//! \return internal editor's geometry
		TQRect editorGeometry() const;

		//! Creates editor. Reimplemented, because if the combo box is not editable, 
		//! editor should not be created.
		virtual void createEditor();

		/*! Reimplemented */
		virtual void styleChange( TQStyle& oldStyle );

		/*! Reimplemented */
		virtual void fontChange( const TQFont & oldFont );

		virtual bool subwidgetStretchRequired(KexiDBAutoField* autoField) const;

		//! Implemented for KexiComboBoxBase
		virtual TQWidget *internalEditor() const { return /*WidgetWithSubpropertiesInterface*/m_subwidget; }

		//! Implemented for KexiComboBoxBase. Does nothing if the widget is not editable.
		virtual void moveCursorToEndInInternalEditor();

		//! Implemented for KexiComboBoxBase. Does nothing if the widget is not editable.
		virtual void selectAllInInternalEditor();

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

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

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

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

		//! Implement this to return a position \a pos mapped from parent (e.g. viewport) 
		//! to global coordinates. TQPoint(-1, -1) should be returned if this cannot be computed.
		virtual TQPoint mapFromParentToGlobal(const TQPoint& pos) const;

		//! Implement this to return a hint for popup width.
		virtual int popupWidthHint() const;

		virtual void setValueInternal(const TQVariant& add, bool removeOld);

		//! Implemented to handle visible value instead of index
		virtual void setVisibleValueInternal(const TQVariant& value);

		bool handleMousePressEvent(TQMouseEvent *e);

		bool handleKeyPressEvent(TQKeyEvent *ke);

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

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

		/*! Called by top-level form on key press event.
		 Used for Key_Escape to if the popup is visible,
		 so the key press won't be consumed to perform "cancel editing". 
		 Also used for grabbing page down/up keys. */
		virtual bool keyPressed(TQKeyEvent *ke);

		class Private;
		Private * const d;
};

#endif