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

Decorate a widget by highlighting its frame when keyboard shortcuts are active. More...

#include <ecvShortcutDecorator.h>

Inheritance diagram for ecvShortcutDecorator:
[legend]
Collaboration diagram for ecvShortcutDecorator:
[legend]

Public Types

using Superclass = QObject
 

Public Slots

virtual void setEnabled (bool enable, bool refocusWhenEnabling=false)
 

Public Member Functions

 ecvShortcutDecorator (QFrame *parent)
 
 ~ecvShortcutDecorator () override=default
 
void addShortcut (ecvModalShortcut *shortcut)
 
bool isEnabled () const
 

Protected Slots

virtual void onShortcutEnabled ()
 
virtual void onShortcutDisabled ()
 

Protected Member Functions

QFrame * decoratedFrame () const
 
bool eventFilter (QObject *obj, QEvent *event) override
 
void markFrame (bool active, const QColor &frameColor)
 

Protected Attributes

QList< QPointer< ecvModalShortcut > > m_shortcuts
 
bool m_pressed
 
bool m_silent
 Prevent recursive signaling inside onShortcutEnabled/onShortcutDisabled. More...
 
bool m_allowRefocus
 

Detailed Description

Decorate a widget by highlighting its frame when keyboard shortcuts are active.

This class provides visual feedback for widgets that have modal shortcuts attached. Features:

  • Highlights the widget's border when shortcuts are active
  • Allows users to click on the border to activate/deactivate shortcuts
  • Monitors mouse enter/exit events for visual feedback
  • Manages multiple shortcuts as a group (all enabled/disabled together)

Usage:

auto* decorator = new ecvShortcutDecorator(myWidget);
decorator->addShortcut(shortcut);

Member Typedef Documentation

◆ Superclass

Constructor & Destructor Documentation

◆ ecvShortcutDecorator()

ecvShortcutDecorator::ecvShortcutDecorator ( QFrame *  parent)
explicit

Create a decorator for the given widget.

Parameters
parentThe widget to decorate (must be a QFrame or subclass)

References CVLog::Error(), and markFrame().

◆ ~ecvShortcutDecorator()

ecvShortcutDecorator::~ecvShortcutDecorator ( )
overridedefault

Destructor.

Member Function Documentation

◆ addShortcut()

void ecvShortcutDecorator::addShortcut ( ecvModalShortcut *  shortcut)

Add a shortcut to this decorator. All shortcuts attached to a decorator are enabled/disabled as a group.

Parameters
shortcutThe modal shortcut to attach

References ecvModalShortcut::disabled(), ecvModalShortcut::enabled(), ecvModalShortcut::keySequence(), m_shortcuts, onShortcutDisabled(), onShortcutEnabled(), CVLog::Print(), and CVLog::Warning().

◆ decoratedFrame()

QFrame * ecvShortcutDecorator::decoratedFrame ( ) const
protected

Get the decorated widget as a QFrame.

Referenced by eventFilter(), markFrame(), and onShortcutEnabled().

◆ eventFilter()

bool ecvShortcutDecorator::eventFilter ( QObject *  obj,
QEvent *  event 
)
overrideprotected

Monitor mouse events to allow users to enable/disable shortcuts.

References decoratedFrame(), event, frame, ecvKeySequences::instance(), isEnabled(), m_pressed, m_shortcuts, markFrame(), ecvKeySequences::reorder(), and setEnabled().

◆ isEnabled()

bool ecvShortcutDecorator::isEnabled ( ) const

Check if any attached shortcuts are enabled.

Returns
True if at least one shortcut is enabled

References m_shortcuts.

Referenced by eventFilter().

◆ markFrame()

void ecvShortcutDecorator::markFrame ( bool  active,
const QColor &  frameColor 
)
protected

Show/hide and color the frame border.

Parameters
activeTrue if the shortcut is active
frameColorThe color to use for the border

References decoratedFrame(), and frame.

Referenced by ecvShortcutDecorator(), eventFilter(), onShortcutDisabled(), and onShortcutEnabled().

◆ onShortcutDisabled

void ecvShortcutDecorator::onShortcutDisabled ( )
protectedvirtualslot

Called when any shortcut is disabled. Ensures all shortcuts are disabled and marks the widget as inactive.

References m_shortcuts, m_silent, and markFrame().

Referenced by addShortcut(), and setEnabled().

◆ onShortcutEnabled

void ecvShortcutDecorator::onShortcutEnabled ( )
protectedvirtualslot

Called when any shortcut is enabled. Ensures all shortcuts are enabled and marks the widget as active.

References decoratedFrame(), frame, m_allowRefocus, m_shortcuts, m_silent, and markFrame().

Referenced by addShortcut(), and setEnabled().

◆ setEnabled

void ecvShortcutDecorator::setEnabled ( bool  enable,
bool  refocusWhenEnabling = false 
)
virtualslot

Enable or disable all attached shortcuts.

Parameters
enableTrue to enable, false to disable
refocusWhenEnablingIf true, focus will shift to the context widget

References m_allowRefocus, onShortcutDisabled(), and onShortcutEnabled().

Referenced by eventFilter().

Member Data Documentation

◆ m_allowRefocus

bool ecvShortcutDecorator::m_allowRefocus
protected

Should shortcuts set the keyboard focus to their context widget? This is set to true when users explicitly click on the widget frame and false otherwise.

Referenced by onShortcutEnabled(), and setEnabled().

◆ m_pressed

bool ecvShortcutDecorator::m_pressed
protected

Note when the user has pressed the mouse inside the widget and not released it.

Referenced by eventFilter().

◆ m_shortcuts

QList<QPointer<ecvModalShortcut> > ecvShortcutDecorator::m_shortcuts
protected

All the shortcuts that decorate the widget. These will all be enabled/disabled en banc.

Referenced by addShortcut(), eventFilter(), isEnabled(), onShortcutDisabled(), and onShortcutEnabled().

◆ m_silent

bool ecvShortcutDecorator::m_silent
protected

Prevent recursive signaling inside onShortcutEnabled/onShortcutDisabled.

Referenced by onShortcutDisabled(), and onShortcutEnabled().


The documentation for this class was generated from the following files:
ecvShortcutDecorator::ecvShortcutDecorator
ecvShortcutDecorator(QFrame *parent)
Definition: ecvShortcutDecorator.cpp:21
ecvKeySequences::instance
static ecvKeySequences & instance()
Definition: ecvKeySequences.cpp:52
ecvKeySequences::addModalShortcut
ecvModalShortcut * addModalShortcut(const QKeySequence &keySequence, QAction *action, QWidget *parent)
Definition: ecvKeySequences.cpp:83