qskinny/qmlexport/QskShortcut.h

95 lines
2.3 KiB
C
Raw Normal View History

2017-07-21 18:21:34 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#ifndef QSK_SHORTCUT_H
#define QSK_SHORTCUT_H
2018-10-12 08:03:03 +02:00
#include "QskQmlGlobal.h"
2017-07-21 18:21:34 +02:00
2018-08-03 08:15:28 +02:00
#include <qnamespace.h>
2018-07-19 14:10:48 +02:00
#include <qobject.h>
#include <qqmlparserstatus.h>
#include <memory>
2017-12-05 17:40:21 +01:00
class QKeySequence;
2017-12-03 17:58:18 +01:00
/*
For QML, with C++ there is also QskShortcutMap that does
not need to create QObjects per shortcut
*/
2018-10-12 08:03:03 +02:00
class QSK_QML_EXPORT QskShortcut : public QObject, public QQmlParserStatus
2017-12-05 17:40:21 +01:00
{
Q_OBJECT
Q_INTERFACES( QQmlParserStatus )
2017-12-05 17:40:21 +01:00
Q_PROPERTY( QVariant sequence READ sequenceVariant
WRITE setSequenceVariant NOTIFY sequenceChanged FINAL)
Q_PROPERTY( Qt::ShortcutContext context READ context
WRITE setContext NOTIFY contextChanged )
Q_PROPERTY( bool enabled READ isEnabled
WRITE setEnabled NOTIFY enabledChanged )
2017-12-05 17:40:21 +01:00
Q_PROPERTY( bool autoRepeat READ autoRepeat
WRITE setAutoRepeat NOTIFY autoRepeatChanged )
2017-12-05 17:40:21 +01:00
Q_PROPERTY( int shortcutId READ shortcutId
NOTIFY shortcutIdChanged )
2017-12-05 17:40:21 +01:00
using Inherited = QObject;
2017-12-05 17:40:21 +01:00
2018-08-03 08:15:28 +02:00
public:
QskShortcut( QObject* parent = nullptr );
2017-12-05 17:40:21 +01:00
QskShortcut( const QKeySequence&, QObject* = nullptr );
QskShortcut( const QKeySequence&, Qt::ShortcutContext, QObject* = nullptr );
2017-12-05 17:40:21 +01:00
2018-07-31 17:32:25 +02:00
~QskShortcut() override;
2017-12-05 17:40:21 +01:00
int shortcutId() const;
2017-12-05 17:40:21 +01:00
void setSequence( const QKeySequence& );
QKeySequence sequence() const;
2017-12-05 17:40:21 +01:00
// for QML
void setSequenceVariant( const QVariant& );
QVariant sequenceVariant() const;
2017-12-05 17:40:21 +01:00
Qt::ShortcutContext context() const;
2018-08-03 08:15:28 +02:00
void setContext( Qt::ShortcutContext );
2017-12-05 17:40:21 +01:00
void setEnabled( bool );
bool isEnabled() const;
2017-12-05 17:40:21 +01:00
void setAutoRepeat( bool );
bool autoRepeat() const;
virtual bool isFocusInScope() const;
2018-08-03 08:15:28 +02:00
Q_SIGNALS:
void sequenceChanged();
void contextChanged();
void enabledChanged();
void autoRepeatChanged();
void activated();
void activatedAmbiguously();
2018-08-03 11:11:42 +02:00
int shortcutIdChanged( int );
2018-08-03 08:15:28 +02:00
protected:
2018-07-31 17:32:25 +02:00
bool event( QEvent* ) override;
void classBegin() override;
void componentComplete() override;
2018-08-03 08:15:28 +02:00
private:
class PrivateData;
std::unique_ptr< PrivateData > m_data;
};
2017-07-21 18:21:34 +02:00
#endif