~ubuntu-branches/debian/sid/kexi/sid

« back to all changes in this revision

Viewing changes to src/plugins/forms/widgets/kexidbcombobox.h

  • Committer: Package Import Robot
  • Author(s): Pino Toscano
  • Date: 2017-06-24 20:10:10 UTC
  • Revision ID: package-import@ubuntu.com-20170624201010-5lrzd5r2vwthwifp
Tags: upstream-3.0.1.1
Import upstream version 3.0.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2006-2014 Jarosław Staniek <staniek@kde.org>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
18
*/
 
19
 
 
20
#ifndef KEXIDBCOMBOBOX_H
 
21
#define KEXIDBCOMBOBOX_H
 
22
 
 
23
#include "kexidbutils.h"
 
24
#include "kexidbautofield.h"
 
25
#include <widget/tableview/kexicomboboxbase.h>
 
26
 
 
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.
 
33
*/
 
34
class KEXIFORMUTILS_EXPORT KexiDBComboBox : public KexiDBAutoField,
 
35
                                            public KexiComboBoxBase
 
36
{
 
37
    Q_OBJECT
 
38
    Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
 
39
 
 
40
public:
 
41
    explicit KexiDBComboBox(QWidget *parent = 0);
 
42
    virtual ~KexiDBComboBox();
 
43
 
 
44
    //! Implemented for KexiComboBoxBase: form has no 'related data' model (only the full database model)
 
45
    virtual const KDbTableViewColumn *column() const;
 
46
 
 
47
    //! Implemented for KexiComboBoxBase
 
48
    virtual KDbField *field() const;
 
49
 
 
50
    //! Implemented for KexiComboBoxBase
 
51
    virtual QVariant origValue() const;
 
52
 
 
53
    void setEditable(bool set);
 
54
 
 
55
    bool isEditable() const;
 
56
 
 
57
    virtual void setLabelPosition(LabelPosition position);
 
58
 
 
59
    virtual QVariant value();
 
60
 
 
61
    virtual QVariant visibleValue();
 
62
 
 
63
    //! Reimplemented because to avoid taking value from the internal editor (index is taken from the popup instead)
 
64
    virtual bool valueChanged();
 
65
 
 
66
    virtual QSize sizeHint() const;
 
67
 
 
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);
 
71
 
 
72
    /*! Used internally to set visible database column information.
 
73
     Reimplemented: performs initialization of the subwidget. */
 
74
    virtual void setVisibleColumnInfo(KDbQueryColumnInfo* cinfo);
 
75
 
 
76
    /*! \return visible database column information for this item.
 
77
     Reimplemented. */
 
78
    virtual KDbQueryColumnInfo* visibleColumnInfo() const;
 
79
 
 
80
    virtual QColor paletteBackgroundColor() const;
 
81
 
 
82
    //! Reimplemented to also set 'this' widget's background color, not only subwidget's.
 
83
    virtual void setPaletteBackgroundColor(const QColor & color);
 
84
 
 
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();
 
89
 
 
90
public Q_SLOTS:
 
91
    virtual void slotRecordAccepted(KDbRecordData *data, int record);
 
92
    virtual void slotRecordSelected(KDbRecordData *data);
 
93
 
 
94
protected Q_SLOTS:
 
95
    virtual void slotInternalEditorValueChanged(const QVariant& v);
 
96
    void slotPopupHidden();
 
97
 
 
98
protected:
 
99
    QRect buttonGeometry() const;
 
100
 
 
101
    virtual void paintEvent(QPaintEvent *);
 
102
 
 
103
    virtual void mousePressEvent(QMouseEvent *e);
 
104
 
 
105
    virtual void mouseDoubleClickEvent(QMouseEvent *e);
 
106
 
 
107
    virtual void changeEvent(QEvent * event);
 
108
 
 
109
    virtual bool eventFilter(QObject *o, QEvent *e);
 
110
 
 
111
    //! \return internal editor's geometry
 
112
    QRect editorGeometry() const;
 
113
 
 
114
    //! Creates editor. Reimplemented, because if the combo box is not editable,
 
115
    //! editor should not be created.
 
116
    virtual void createEditor();
 
117
 
 
118
    virtual bool subwidgetStretchRequired(KexiDBAutoField* autoField) const;
 
119
 
 
120
    //! Implemented for KexiComboBoxBase
 
121
    virtual QWidget *internalEditor() const;
 
122
 
 
123
    //! Implemented for KexiComboBoxBase. Does nothing if the widget is not editable.
 
124
    virtual void moveCursorToEndInInternalEditor();
 
125
 
 
126
    //! Implemented for KexiComboBoxBase. Does nothing if the widget is not editable.
 
127
    virtual void selectAllInInternalEditor();
 
128
 
 
129
    //! Implemented for KexiComboBoxBase
 
130
    virtual void setValueInInternalEditor(const QVariant& value);
 
131
 
 
132
    //! Implemented for KexiComboBoxBase
 
133
    virtual QVariant valueFromInternalEditor();
 
134
 
 
135
    //! Implemented for KexiComboBoxBase
 
136
    virtual void editRequested();
 
137
 
 
138
    //! Implemented for KexiComboBoxBase
 
139
    virtual void acceptRequested();
 
140
 
 
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;
 
144
 
 
145
    //! Implement this to return a hint for popup width.
 
146
    virtual int popupWidthHint() const;
 
147
 
 
148
    virtual void setValueInternal(const QVariant& add, bool removeOld);
 
149
 
 
150
    //! Implemented to handle visible value instead of index
 
151
    virtual void setVisibleValueInternal(const QVariant& value);
 
152
 
 
153
    bool handleMousePressEvent(QMouseEvent *e);
 
154
 
 
155
    bool handleKeyPressEvent(QKeyEvent *ke);
 
156
 
 
157
    //! Implemented for KexiDataItemInterface
 
158
    virtual void beforeSignalValueChanged();
 
159
 
 
160
    virtual KexiComboBoxPopup *popup() const;
 
161
    virtual void setPopup(KexiComboBoxPopup *popup);
 
162
 
 
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);
 
168
 
 
169
    class Private;
 
170
    Private * const d;
 
171
};
 
172
 
 
173
#endif