summaryrefslogtreecommitdiffstats
path: root/lib/widgets/qcomboview.h
blob: 8f618f50f5bc329a72fbf59436aa0660df362cd1 (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
/**********************************************************************
**
**
** Definition of QComboView class
**
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
** Copyright (C) 2003 Alexander Dymo <cloudtemple@mksat.net>
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
**********************************************************************/

#ifndef QCOMBOVIEW_H
#define QCOMBOVIEW_H

#ifndef QT_H
#include "qwidget.h"
#endif // QT_H

#ifndef QT_NO_COMBOBOX

/**
@file qcomboview.h
QComboView class.
*/

class QStrList;
class QStringList;
class QLineEdit;
class QValidator;
class QListView;
class QListViewItem;
class QComboViewData;

/**
QComboView - a combo with a QListView as a popup widget.
This means that you can have a treeview inside of a combo. Otherwise it works
in the same way as QComboBox and have similar API.
*/
class Q_EXPORT QComboView : public QWidget
{
    Q_OBJECT
    Q_ENUMS( Policy )
    Q_PROPERTY( bool editable READ editable WRITE setEditable )
//    Q_PROPERTY( int count READ count )
    Q_PROPERTY( QString currentText READ currentText WRITE setCurrentText DESIGNABLE false )
//    Q_PROPERTY( QListView *currentItem READ currentItem WRITE setCurrentItem )
    Q_PROPERTY( bool autoResize READ autoResize WRITE setAutoResize DESIGNABLE false )
    Q_PROPERTY( int sizeLimit READ sizeLimit WRITE setSizeLimit )
//    Q_PROPERTY( int maxCount READ maxCount WRITE setMaxCount )
    Q_PROPERTY( Policy insertionPolicy READ insertionPolicy WRITE setInsertionPolicy )
    Q_PROPERTY( bool autoCompletion READ autoCompletion WRITE setAutoCompletion )
    Q_PROPERTY( bool duplicatesEnabled READ duplicatesEnabled WRITE setDuplicatesEnabled )
    Q_OVERRIDE( bool autoMask DESIGNABLE true SCRIPTABLE true )

public:
//    QComboView( QWidget* parent=0, const char* name=0 );
    QComboView( bool rw, QWidget* parent=0, const char* name=0 );
    ~QComboView();

    int childCount() const;

    QListViewItem *currentItem() const;
    virtual void setCurrentItem( QListViewItem * );
    virtual void setCurrentActiveItem( QListViewItem * );

    bool	autoResize()	const;
    virtual void setAutoResize( bool );
    QSize	sizeHint() const;

    void	setPalette( const QPalette & );
    void	setFont( const QFont & );
    void	setEnabled( bool );

    virtual void setSizeLimit( int );
    int		sizeLimit() const;

/*    virtual void setMaxCount( int );
    int		maxCount() const;*/

    enum Policy { NoInsertion, AtTop, AtCurrent, AtBottom,
		  AfterCurrent, BeforeCurrent };

    virtual void setInsertionPolicy( Policy policy );
    Policy	insertionPolicy() const;

    virtual void setValidator( const QValidator * );
    const QValidator * validator() const;

    virtual void setListView( QListView * );
    QListView *	listView() const;

    virtual void setLineEdit( QLineEdit *edit );
    QLineEdit*	lineEdit() const;

    virtual void setAutoCompletion( bool );
    bool	autoCompletion() const;

    bool	eventFilter( QObject *object, QEvent *event );

    void	setDuplicatesEnabled( bool enable );
    bool	duplicatesEnabled() const;

    bool	editable() const;
    void	setEditable( bool );

    virtual void popup();

    QString currentText() const;
    void setCurrentText( const QString& );

public slots:
    virtual void clear();
    void	clearValidator();
    void	clearEdit();
    virtual void setEditText( const QString &);

signals:
    void	activated( QListViewItem * item );
    void	highlighted( QListViewItem * item );
    void	activated( const QString &);
    void	highlighted( const QString &);
    void	textChanged( const QString &);
    void    focusGranted();
    void    focusLost();

private slots:
    void	internalActivate( QListViewItem * );
    void	internalHighlight( QListViewItem * );
    void	internalClickTimeout();
    void	returnPressed();
    void checkState(QListViewItem*);

protected:
    void	paintEvent( QPaintEvent * );
    void	resizeEvent( QResizeEvent * );
    void	mousePressEvent( QMouseEvent * );
    void	mouseMoveEvent( QMouseEvent * );
    void	mouseReleaseEvent( QMouseEvent * );
    void	mouseDoubleClickEvent( QMouseEvent * );
    void	keyPressEvent( QKeyEvent *e );
    void	focusInEvent( QFocusEvent *e );
    void	focusOutEvent( QFocusEvent *e );
    void	wheelEvent( QWheelEvent *e );
    void	styleChange( QStyle& );

    void	updateMask();

private:
    virtual void setUpListView();
    void	setUpLineEdit();
    void	popDownListView();
    void	reIndex();
    void	currentChanged();
    QListViewItem *completionIndex( const QString &, QListViewItem * ) const;

    QComboViewData	*d;

private:	// Disabled copy constructor and operator=
#if defined(Q_DISABLE_COPY)
    QComboView( const QComboView & );
    QComboView &operator=( const QComboView & );
#endif
};


#endif // QT_NO_COMBOBOX

#endif // QCOMBOVIEW_H