2023-02-14 07:58:37 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2023 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef QSK_COMBO_BOX_H
|
|
|
|
#define QSK_COMBO_BOX_H
|
|
|
|
|
|
|
|
#include "QskControl.h"
|
2023-03-10 11:46:19 +00:00
|
|
|
#include <qstringlist.h>
|
2023-02-14 07:58:37 +00:00
|
|
|
|
2023-03-10 11:46:19 +00:00
|
|
|
class QskTextOptions;
|
2023-03-09 16:59:54 +00:00
|
|
|
class QskLabelData;
|
2023-03-10 11:46:19 +00:00
|
|
|
class QUrl;
|
2023-02-14 07:58:37 +00:00
|
|
|
|
|
|
|
class QSK_EXPORT QskComboBox : public QskControl
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2023-03-09 16:59:54 +00:00
|
|
|
Q_PROPERTY( QVector< QskLabelData > options READ options
|
|
|
|
WRITE setOptions NOTIFY optionsChanged )
|
|
|
|
|
2023-02-14 07:58:37 +00:00
|
|
|
Q_PROPERTY( int currentIndex READ currentIndex
|
|
|
|
WRITE setCurrentIndex NOTIFY currentIndexChanged )
|
|
|
|
|
2023-03-07 14:00:33 +00:00
|
|
|
Q_PROPERTY( QString currentText READ currentText
|
|
|
|
NOTIFY currentIndexChanged )
|
2023-03-06 09:44:00 +00:00
|
|
|
|
2023-03-09 16:59:54 +00:00
|
|
|
Q_PROPERTY( int count READ count )
|
2023-02-14 07:58:37 +00:00
|
|
|
|
2023-03-03 18:01:40 +00:00
|
|
|
Q_PROPERTY( QString placeholderText READ placeholderText
|
|
|
|
WRITE setPlaceholderText NOTIFY placeholderTextChanged )
|
|
|
|
|
2023-03-07 14:00:33 +00:00
|
|
|
Q_PROPERTY( int indexInPopup READ indexInPopup
|
|
|
|
NOTIFY indexInPopupChanged )
|
|
|
|
|
2023-02-14 07:58:37 +00:00
|
|
|
using Inherited = QskControl;
|
|
|
|
|
|
|
|
public:
|
2023-03-08 13:11:27 +00:00
|
|
|
QSK_SUBCONTROLS( Panel, Icon, Text, StatusIndicator )
|
2023-03-06 09:44:00 +00:00
|
|
|
QSK_STATES( PopupOpen )
|
2023-02-14 07:58:37 +00:00
|
|
|
|
|
|
|
QskComboBox( QQuickItem* parent = nullptr );
|
|
|
|
|
|
|
|
~QskComboBox() override;
|
|
|
|
|
2023-03-06 09:44:00 +00:00
|
|
|
void setPopupOpen( bool );
|
2023-02-14 07:58:37 +00:00
|
|
|
bool isPopupOpen() const;
|
|
|
|
|
|
|
|
void setTextOptions( const QskTextOptions& );
|
|
|
|
QskTextOptions textOptions() const;
|
|
|
|
|
2023-03-09 16:59:54 +00:00
|
|
|
int addOption( const QUrl&, const QString& );
|
|
|
|
int addOption( const QString&, const QString& );
|
|
|
|
int addOption( const QskLabelData& );
|
|
|
|
|
|
|
|
void setOptions( const QVector< QskLabelData >& );
|
2023-03-10 11:46:19 +00:00
|
|
|
void setOptions( const QStringList& );
|
2023-03-09 16:59:54 +00:00
|
|
|
|
|
|
|
QVector< QskLabelData > options() const;
|
|
|
|
QskLabelData optionAt( int ) const;
|
2023-02-14 07:58:37 +00:00
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
int currentIndex() const;
|
2023-03-06 09:44:00 +00:00
|
|
|
QString currentText() const;
|
2023-02-14 07:58:37 +00:00
|
|
|
|
2023-03-07 14:00:33 +00:00
|
|
|
// "highlightedIndex" ( see Qt's combo boxes ) is not very intuitive
|
|
|
|
virtual int indexInPopup() const;
|
|
|
|
|
2023-02-14 07:58:37 +00:00
|
|
|
int count() const;
|
2023-03-07 13:32:53 +00:00
|
|
|
QString textAt( int ) const;
|
2023-02-14 07:58:37 +00:00
|
|
|
|
2023-03-03 18:01:40 +00:00
|
|
|
QString placeholderText() const;
|
|
|
|
void setPlaceholderText( const QString& );
|
2023-02-14 07:58:37 +00:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
2023-03-01 09:51:46 +00:00
|
|
|
void setCurrentIndex( int );
|
2023-02-14 07:58:37 +00:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void currentIndexChanged( int );
|
2023-03-07 14:00:33 +00:00
|
|
|
void indexInPopupChanged( int );
|
2023-02-14 07:58:37 +00:00
|
|
|
|
2023-03-09 16:59:54 +00:00
|
|
|
void optionsChanged();
|
2023-03-03 18:01:40 +00:00
|
|
|
void placeholderTextChanged( const QString& );
|
|
|
|
|
2023-02-14 07:58:37 +00:00
|
|
|
protected:
|
|
|
|
void mousePressEvent( QMouseEvent* ) override;
|
|
|
|
void mouseReleaseEvent( QMouseEvent* ) override;
|
|
|
|
|
|
|
|
void keyPressEvent( QKeyEvent* ) override;
|
|
|
|
void keyReleaseEvent( QKeyEvent* ) override;
|
|
|
|
|
2023-03-06 09:44:00 +00:00
|
|
|
void wheelEvent( QWheelEvent* ) override;
|
|
|
|
|
2023-03-07 14:00:33 +00:00
|
|
|
/*
|
|
|
|
open/close a menu - needs to be overloaded when using a custom popup
|
|
|
|
don't forget to modify indexInPopup/indexInPopupChanged as well
|
|
|
|
*/
|
2023-03-06 09:44:00 +00:00
|
|
|
virtual void openPopup();
|
|
|
|
virtual void closePopup();
|
|
|
|
|
2023-02-14 07:58:37 +00:00
|
|
|
private:
|
|
|
|
class PrivateData;
|
|
|
|
std::unique_ptr< PrivateData > m_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|