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

Definition at line 39 of file ecvModalShortcut.cpp.

References m_shortcut, and unregister().

◆ ecvModalShortcut()

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

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

Definition at line 18 of file ecvModalShortcut.cpp.

References activated(), m_action, and m_shortcut.

Member Function Documentation

◆ activated

void ecvModalShortcut::activated ( )
signal

Invoked when the key sequence is pressed.

Referenced by cvPointPickingHelper::cvPointPickingHelper(), ecvModalShortcut(), and setContextWidget().

◆ 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.

Referenced by ecvShortcutDecorator::addShortcut(), and setEnabled().

◆ 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.

Referenced by ecvKeySequences::addModalShortcut(), ecvShortcutDecorator::addShortcut(), setContextWidget(), and setEnabled().

◆ isEnabled()

bool ecvModalShortcut::isEnabled ( ) const

Check if the shortcut is currently enabled.

Definition at line 106 of file ecvModalShortcut.cpp.

References m_shortcut.

Referenced by ecvKeySequences::reorder(), and setContextWidget().

◆ keySequence()

QKeySequence ecvModalShortcut::keySequence ( ) const

Get the key sequence this shortcut responds to.

Definition at line 144 of file ecvModalShortcut.cpp.

References m_key.

Referenced by ecvShortcutDecorator::addShortcut(), and ecvKeySequences::reorder().

◆ 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)

Definition at line 45 of file ecvModalShortcut.cpp.

References activated(), enabled(), isEnabled(), m_action, m_key, and m_shortcut.

◆ 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

Definition at line 111 of file ecvModalShortcut.cpp.

References disabled(), enabled(), and m_shortcut.

◆ unregister

void ecvModalShortcut::unregister ( )
signal

Called from the destructor.

This is used by ecvKeySequences to clean its records.

Referenced by ecvKeySequences::addModalShortcut(), and ~ecvModalShortcut().

Member Data Documentation

◆ m_action

QPointer<QAction> ecvModalShortcut::m_action
protected

Definition at line 123 of file ecvModalShortcut.h.

Referenced by ecvModalShortcut(), and setContextWidget().

◆ m_key

QKeySequence ecvModalShortcut::m_key
protected

Definition at line 121 of file ecvModalShortcut.h.

Referenced by keySequence(), and setContextWidget().

◆ m_shortcut

QPointer<QShortcut> ecvModalShortcut::m_shortcut
protected

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