qskinny/src/controls/QskMenu.h

139 lines
3.6 KiB
C
Raw Normal View History

2021-12-23 18:36:32 +01:00
/******************************************************************************
2024-01-17 14:31:45 +01:00
* QSkinny - Copyright (C) The authors
2023-04-06 09:23:37 +02:00
* SPDX-License-Identifier: BSD-3-Clause
2021-12-23 18:36:32 +01:00
*****************************************************************************/
#ifndef QSK_MENU_H
#define QSK_MENU_H
#include "QskPopup.h"
2023-03-10 12:46:19 +01:00
#include <qstringlist.h>
2021-12-23 18:36:32 +01:00
class QskTextOptions;
2023-03-10 09:18:52 +01:00
class QskLabelData;
2023-03-10 12:46:19 +01:00
class QUrl;
2021-12-23 18:36:32 +01:00
class QSK_EXPORT QskMenu : public QskPopup
{
Q_OBJECT
Q_PROPERTY( QPointF origin READ origin
2021-12-23 19:05:59 +01:00
WRITE setOrigin NOTIFY originChanged )
2021-12-23 18:36:32 +01:00
2021-12-26 12:17:31 +01:00
Q_PROPERTY( bool cascading READ isCascading WRITE setCascading
RESET resetCascading NOTIFY cascadingChanged )
2024-02-17 13:24:14 +01:00
Q_PROPERTY( bool wrapping READ isWrapping
WRITE setWrapping NOTIFY wrappingChanged )
2023-03-10 09:18:52 +01:00
Q_PROPERTY( QVector< QskLabelData > options READ options
WRITE setOptions NOTIFY optionsChanged )
2021-12-23 18:36:32 +01:00
Q_PROPERTY( int currentIndex READ currentIndex
2021-12-23 19:05:59 +01:00
WRITE setCurrentIndex NOTIFY currentIndexChanged )
2021-12-23 18:36:32 +01:00
2023-03-10 12:46:19 +01:00
Q_PROPERTY( int triggeredIndex READ triggeredIndex NOTIFY triggered )
Q_PROPERTY( QString triggeredText READ triggeredText NOTIFY triggered )
Q_PROPERTY( QString currentText READ currentText NOTIFY currentIndexChanged )
2023-03-07 14:32:53 +01:00
2021-12-23 18:36:32 +01:00
using Inherited = QskPopup;
public:
QSK_SUBCONTROLS( Panel, Segment, Cursor, Text, Icon, Separator )
2023-06-30 15:44:49 +02:00
QSK_STATES( Selected, Pressed )
2021-12-23 18:36:32 +01:00
QskMenu( QQuickItem* parentItem = nullptr );
~QskMenu() override;
2021-12-26 12:17:31 +01:00
bool isCascading() const;
void setCascading( bool );
void resetCascading();
2024-02-17 13:24:14 +01:00
bool isWrapping() const;
void setWrapping( bool );
2021-12-23 18:36:32 +01:00
void setOrigin( const QPointF& );
QPointF origin() const;
void setTextOptions( const QskTextOptions& );
2022-01-06 18:36:15 +01:00
QskTextOptions textOptions() const;
2023-03-10 09:18:52 +01:00
int addOption( const QString&, const QString& );
int addOption( const QUrl&, const QString& );
int addOption( const QskLabelData& );
void addSeparator();
2023-03-10 09:18:52 +01:00
void setOptions( const QVector< QskLabelData >& );
2023-03-10 12:46:19 +01:00
void setOptions( const QStringList& );
2022-01-06 18:36:15 +01:00
2023-03-10 09:18:52 +01:00
QVector< QskLabelData > options() const;
QskLabelData optionAt( int ) const;
2023-03-07 14:32:53 +01:00
QVector< int > separators() const;
QVector< int > actions() const;
2021-12-23 18:36:32 +01:00
int currentIndex() const;
2023-06-30 15:28:20 +02:00
2023-03-07 14:32:53 +01:00
QString currentText() const;
2021-12-23 18:36:32 +01:00
2023-03-10 12:46:19 +01:00
int triggeredIndex() const;
QString triggeredText() const;
2021-12-23 18:36:32 +01:00
QRectF focusIndicatorRect() const override;
2021-12-24 16:20:34 +01:00
QRectF cellRect( int index ) const;
2021-12-26 09:15:15 +01:00
int indexAtPosition( const QPointF& ) const;
2021-12-24 16:20:34 +01:00
2023-06-30 15:44:49 +02:00
bool isPressed() const;
QRectF clipRect() const override;
QskAspect fadingAspect() const override;
2021-12-30 11:13:48 +01:00
Q_INVOKABLE int exec();
2021-12-23 18:36:32 +01:00
Q_SIGNALS:
2024-02-17 13:24:14 +01:00
void wrappingChanged( bool );
2021-12-26 12:17:31 +01:00
void cascadingChanged( bool );
void originChanged( const QPointF& );
2021-12-23 18:36:32 +01:00
void triggered( int index );
2023-03-10 09:18:52 +01:00
void currentIndexChanged( int );
2021-12-23 18:36:32 +01:00
2023-03-10 09:18:52 +01:00
void optionsChanged();
2021-12-27 09:50:14 +01:00
2021-12-23 18:36:32 +01:00
public Q_SLOTS:
2023-03-10 09:18:52 +01:00
void setCurrentIndex( int );
void clear();
2021-12-23 18:36:32 +01:00
protected:
void keyPressEvent( QKeyEvent* ) override;
void keyReleaseEvent( QKeyEvent* ) override;
2022-01-05 11:59:32 +01:00
2023-06-30 15:28:20 +02:00
void hoverEnterEvent( QHoverEvent* ) override;
void hoverMoveEvent( QHoverEvent* ) override;
void hoverLeaveEvent( QHoverEvent* ) override;
2022-01-05 11:59:32 +01:00
#ifndef QT_NO_WHEELEVENT
2021-12-23 18:36:32 +01:00
void wheelEvent( QWheelEvent* ) override;
2022-01-05 11:59:32 +01:00
#endif
2021-12-23 18:36:32 +01:00
void mousePressEvent( QMouseEvent* ) override;
2023-03-10 09:18:52 +01:00
void mouseUngrabEvent() override;
2021-12-23 18:36:32 +01:00
void mouseReleaseEvent( QMouseEvent* ) override;
void aboutToShow() override;
2023-03-10 12:46:19 +01:00
void trigger( int );
2021-12-23 18:36:32 +01:00
void updateResources() override;
void updateNode( QSGNode* ) override;
2021-12-23 18:36:32 +01:00
private:
void traverse( int steps );
class PrivateData;
std::unique_ptr< PrivateData > m_data;
};
#endif