QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskComboBox.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_COMBO_BOX_H
7#define QSK_COMBO_BOX_H
8
9#include "QskControl.h"
10#include <qstringlist.h>
11
12class QskTextOptions;
13class QskLabelData;
14class QUrl;
15
16class QSK_EXPORT QskComboBox : public QskControl
17{
18 Q_OBJECT
19
20 Q_PROPERTY( QVector< QskLabelData > options READ options
21 WRITE setOptions NOTIFY optionsChanged )
22
23 Q_PROPERTY( int currentIndex READ currentIndex
24 WRITE setCurrentIndex NOTIFY currentIndexChanged )
25
26 Q_PROPERTY( QString currentText READ currentText
27 NOTIFY currentIndexChanged USER true)
28
29 Q_PROPERTY( int count READ count )
30
31 Q_PROPERTY( QString placeholderText READ placeholderText
32 WRITE setPlaceholderText NOTIFY placeholderTextChanged )
33
34 Q_PROPERTY( int indexInPopup READ indexInPopup
35 NOTIFY indexInPopupChanged )
36
37 Q_PROPERTY( bool pressed READ isPressed
38 WRITE setPressed NOTIFY pressedChanged FINAL )
39
40 using Inherited = QskControl;
41
42 public:
43 QSK_SUBCONTROLS( Panel, Icon, Text, StatusIndicator )
44 QSK_STATES( Pressed, PopupOpen )
45
46 QskComboBox( QQuickItem* parent = nullptr );
47
48 ~QskComboBox() override;
49
50 void setPressed( bool on );
51 bool isPressed() const;
52
53 void setPopupOpen( bool );
54 bool isPopupOpen() const;
55
56 void setTextOptions( const QskTextOptions& );
57 QskTextOptions textOptions() const;
58
59 int addOption( const QUrl&, const QString& );
60 int addOption( const QString&, const QString& );
61 int addOption( const QskLabelData& );
62
63 void setOptions( const QVector< QskLabelData >& );
64 void setOptions( const QStringList& );
65
66 QVector< QskLabelData > options() const;
67 QskLabelData optionAt( int ) const;
68
69 void clear();
70
71 int currentIndex() const;
72 QString currentText() const;
73
74 // "highlightedIndex" ( see Qt's combo boxes ) is not very intuitive
75 virtual int indexInPopup() const;
76
77 int count() const;
78 QString textAt( int ) const;
79
80 QString placeholderText() const;
81 void setPlaceholderText( const QString& );
82
83 public Q_SLOTS:
84 void setCurrentIndex( int );
85
86 Q_SIGNALS:
87 void pressed();
88 void released();
89 void pressedChanged( bool );
90
91 void currentIndexChanged( int );
92 void indexInPopupChanged( int );
93
94 void optionsChanged();
95 void placeholderTextChanged( const QString& );
96
97 protected:
98 void mousePressEvent( QMouseEvent* ) override;
99 void mouseReleaseEvent( QMouseEvent* ) override;
100
101 void keyPressEvent( QKeyEvent* ) override;
102 void keyReleaseEvent( QKeyEvent* ) override;
103
104 void wheelEvent( QWheelEvent* ) override;
105
106 /*
107 open/close a menu - needs to be overloaded when using a custom popup
108 don't forget to modify indexInPopup/indexInPopupChanged as well
109 */
110 virtual void openPopup();
111 virtual void closePopup();
112
113 private:
114 class PrivateData;
115 std::unique_ptr< PrivateData > m_data;
116};
117
118#endif
Base class of all controls.
Definition QskControl.h:23