1
/* This file is part of the KDE project
2
Copyright (C) 2006-2014 Jarosław Staniek <staniek@kde.org>
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this program; see the file COPYING. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
20
#ifndef KEXIDBCOMBOBOX_H
21
#define KEXIDBCOMBOBOX_H
23
#include "kexidbutils.h"
24
#include "kexidbautofield.h"
25
#include <widget/tableview/kexicomboboxbase.h>
27
//! @short Combo box widget for Kexi forms
28
/*! This widget is implemented on top of KexiDBAutoField,
29
so as it uses KexiDBAutoField's ability of embedding subwidgets,
30
it can display not only a line edit but also text edit or image box
31
(more can be added in the future).
32
A drop-down button is added to mimic native combo box widget's functionality.
34
class KEXIFORMUTILS_EXPORT KexiDBComboBox : public KexiDBAutoField,
35
public KexiComboBoxBase
38
Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
41
explicit KexiDBComboBox(QWidget *parent = 0);
42
virtual ~KexiDBComboBox();
44
//! Implemented for KexiComboBoxBase: form has no 'related data' model (only the full database model)
45
virtual const KDbTableViewColumn *column() const;
47
//! Implemented for KexiComboBoxBase
48
virtual KDbField *field() const;
50
//! Implemented for KexiComboBoxBase
51
virtual QVariant origValue() const;
53
void setEditable(bool set);
55
bool isEditable() const;
57
virtual void setLabelPosition(LabelPosition position);
59
virtual QVariant value();
61
virtual QVariant visibleValue();
63
//! Reimplemented because to avoid taking value from the internal editor (index is taken from the popup instead)
64
virtual bool valueChanged();
66
virtual QSize sizeHint() const;
68
//! Reimplemented after KexiDBAutoField: jsut sets \a cinfo without initializing a subwidget.
69
//! Initialization is performed by \ref setVisibleColumnInfo().
70
virtual void setColumnInfo(KDbQueryColumnInfo* cinfo);
72
/*! Used internally to set visible database column information.
73
Reimplemented: performs initialization of the subwidget. */
74
virtual void setVisibleColumnInfo(KDbQueryColumnInfo* cinfo);
76
/*! \return visible database column information for this item.
78
virtual KDbQueryColumnInfo* visibleColumnInfo() const;
80
virtual QColor paletteBackgroundColor() const;
82
//! Reimplemented to also set 'this' widget's background color, not only subwidget's.
83
virtual void setPaletteBackgroundColor(const QColor & color);
85
/*! Undoes changes made to this item - just resets the widget to original value.
86
Reimplemented after KexiFormDataItemInterface to also revert the visible value
87
(i.e. text) to the original state. */
88
virtual void undoChanges();
91
virtual void slotRecordAccepted(KDbRecordData *data, int record);
92
virtual void slotRecordSelected(KDbRecordData *data);
95
virtual void slotInternalEditorValueChanged(const QVariant& v);
96
void slotPopupHidden();
99
QRect buttonGeometry() const;
101
virtual void paintEvent(QPaintEvent *);
103
virtual void mousePressEvent(QMouseEvent *e);
105
virtual void mouseDoubleClickEvent(QMouseEvent *e);
107
virtual void changeEvent(QEvent * event);
109
virtual bool eventFilter(QObject *o, QEvent *e);
111
//! \return internal editor's geometry
112
QRect editorGeometry() const;
114
//! Creates editor. Reimplemented, because if the combo box is not editable,
115
//! editor should not be created.
116
virtual void createEditor();
118
virtual bool subwidgetStretchRequired(KexiDBAutoField* autoField) const;
120
//! Implemented for KexiComboBoxBase
121
virtual QWidget *internalEditor() const;
123
//! Implemented for KexiComboBoxBase. Does nothing if the widget is not editable.
124
virtual void moveCursorToEndInInternalEditor();
126
//! Implemented for KexiComboBoxBase. Does nothing if the widget is not editable.
127
virtual void selectAllInInternalEditor();
129
//! Implemented for KexiComboBoxBase
130
virtual void setValueInInternalEditor(const QVariant& value);
132
//! Implemented for KexiComboBoxBase
133
virtual QVariant valueFromInternalEditor();
135
//! Implemented for KexiComboBoxBase
136
virtual void editRequested();
138
//! Implemented for KexiComboBoxBase
139
virtual void acceptRequested();
141
//! Implement this to return a position \a pos mapped from parent (e.g. viewport)
142
//! to global coordinates. QPoint(-1, -1) should be returned if this cannot be computed.
143
virtual QPoint mapFromParentToGlobal(const QPoint& pos) const;
145
//! Implement this to return a hint for popup width.
146
virtual int popupWidthHint() const;
148
virtual void setValueInternal(const QVariant& add, bool removeOld);
150
//! Implemented to handle visible value instead of index
151
virtual void setVisibleValueInternal(const QVariant& value);
153
bool handleMousePressEvent(QMouseEvent *e);
155
bool handleKeyPressEvent(QKeyEvent *ke);
157
//! Implemented for KexiDataItemInterface
158
virtual void beforeSignalValueChanged();
160
virtual KexiComboBoxPopup *popup() const;
161
virtual void setPopup(KexiComboBoxPopup *popup);
163
/*! Called by top-level form on key press event.
164
Used for Key_Escape to if the popup is visible,
165
so the key press won't be consumed to perform "cancel editing".
166
Also used for grabbing page down/up keys. */
167
virtual bool keyPressed(QKeyEvent *ke);