ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvModalShortcut Class Reference

Manage an action and/or widget's responsivity to a shortcut. More...

#include <ecvModalShortcut.h>

Inheritance diagram for ecvModalShortcut:
Collaboration diagram for ecvModalShortcut:

Public Types

using Superclass = QObject
 

Signals

void enabled ()
 
void disabled ()
 
void unregister ()
 
void activated ()
 

Public Member Functions

 ~ecvModalShortcut () override
 
void setContextWidget (QWidget *contextWidget, Qt::ShortcutContext contextArea=Qt::WindowShortcut)
 
bool isEnabled () const
 
void setEnabled (bool shouldEnable, bool changeFocus=true)
 
QKeySequence keySequence () const
 

Protected Member Functions

 ecvModalShortcut (const QKeySequence &key, QAction *action=nullptr, QWidget *parent=nullptr)
 

Protected Attributes

QKeySequence m_key
 
QPointer< QShortcut > m_shortcut
 
QPointer< QAction > m_action
 

Detailed Description

Manage an action and/or widget's responsivity to a shortcut.

This object will add and remove a connection between a widget/action and a QShortcut as required by the ecvKeySequences manager to prevent any ambiguous activations.

Key features:

  • Automatic enable/disable based on ecvKeySequences manager
  • Context-aware: can be restricted to a specific widget
  • Signal emission for visual feedback

Example:

// This is typically created by ecvKeySequences::addModalShortcut()
auto* modalShortcut = new ecvModalShortcut(
QKeySequence(Qt::Key_S), myAction, myWidget);
modalShortcut->setEnabled(true);
ecvModalShortcut(const QKeySequence &key, QAction *action=nullptr, QWidget *parent=nullptr)

Definition at line 43 of file ecvModalShortcut.h.

Member Typedef Documentation

◆ Superclass

Definition at line 47 of file ecvModalShortcut.h.

Constructor & Destructor Documentation

◆ ~ecvModalShortcut()

ecvModalShortcut::~ecvModalShortcut ( )
override

◆ ecvModalShortcut()

ecvModalShortcut::ecvModalShortcut ( const QKeySequence &  key,
QAction *  action = nullptr,
QWidget *  parent = nullptr 
)
protected

Constructor (protected - use ecvKeySequences::addModalShortcut()).

Member Function Documentation

◆ activated

void ecvModalShortcut::activated ( )
signal

Invoked when the key sequence is pressed.

◆ disabled

void ecvModalShortcut::disabled ( )
signal

Called from setEnabled() whenever it is passed false.

This may be used by widgets to update their visual state, indicating they are no longer accepting shortcuts.

◆ enabled

void ecvModalShortcut::enabled ( )
signal

Called from setEnabled() whenever it is passed true.

This is used by ecvKeySequences to disable any sibling shortcuts with the same keysequence.

This may also be used by widgets to update their visual state, indicating they are now accepting shortcuts.

◆ isEnabled()

bool ecvModalShortcut::isEnabled ( ) const

Check if the shortcut is currently enabled.

◆ keySequence()

QKeySequence ecvModalShortcut::keySequence ( ) const

Get the key sequence this shortcut responds to.

◆ setContextWidget()

void ecvModalShortcut::setContextWidget ( QWidget *  contextWidget,
Qt::ShortcutContext  contextArea = Qt::WindowShortcut 
)

If the shortcut should be restricted to a particular widget (such as a view), use this method to set and update the widget during the life of the ecvModalShortcut.

Parameters
contextWidgetThe widget to restrict the shortcut to
contextAreaThe context scope (default: WindowShortcut)

◆ setEnabled()

void ecvModalShortcut::setEnabled ( bool  shouldEnable,
bool  changeFocus = true 
)

Enable or disable the shortcut.

Parameters
shouldEnableTrue to enable, false to disable
changeFocusIf true and enabling, move focus to context widget

◆ unregister

void ecvModalShortcut::unregister ( )
signal

Called from the destructor.

This is used by ecvKeySequences to clean its records.

Member Data Documentation

◆ m_action

QPointer<QAction> ecvModalShortcut::m_action
protected

Definition at line 123 of file ecvModalShortcut.h.

◆ m_key

QKeySequence ecvModalShortcut::m_key
protected

Definition at line 121 of file ecvModalShortcut.h.

◆ m_shortcut

QPointer<QShortcut> ecvModalShortcut::m_shortcut
protected

Definition at line 122 of file ecvModalShortcut.h.


The documentation for this class was generated from the following file: