Freeciv21
Develop your civilization from humble roots to a global empire
fc_shortcuts Class Reference

#include <shortcuts.h>

+ Inheritance diagram for fc_shortcuts:
+ Collaboration diagram for fc_shortcuts:

Public Member Functions

virtual ~fc_shortcuts ()
 fc_shortcuts destructor More...
 
void init_default (bool read)
 Inits defaults shortcuts or reads from settings. More...
 
auto shortcuts () const
 Returns all existing shortcuts. More...
 
fc_shortcut get_shortcut (shortcut_id id) const
 Returns shortcut for given id. More...
 
void set_shortcut (const fc_shortcut &sc)
 Sets given shortcut. More...
 
QString get_desc (shortcut_id id) const
 Returns description for given shortcut. More...
 
void link_action (shortcut_id id, QAction *action)
 Links an action to a shortcut. More...
 
void create_no_action_shortcuts (map_view *parent)
 Enable key bindings for all shortcuts that have no action associated with them. More...
 
void invoke (shortcut_id id, map_view *mapview)
 Invokes the action for a shortcut. More...
 
void maybe_route_mouse_shortcut (QMouseEvent *event, map_view *mapview)
 If the mouse event corresponds to a registered shortcut, fire the corresponding action. More...
 
bool read ()
 Reads shortcuts from file. More...
 
void write () const
 Writes shortcuts to file. More...
 

Static Public Member Functions

static fc_shortcutssc ()
 Returns given instance. More...
 
static void drop ()
 Deletes current instance. More...
 

Private Member Functions

 Q_DISABLE_COPY (fc_shortcuts)
 
 fc_shortcuts ()
 fc_shortcuts contructor More...
 
void setup_action (const fc_shortcut &sc, QAction *action)
 Sets up key bindings for the action. More...
 

Private Attributes

std::map< shortcut_id, QPointer< QAction > > m_actions
 
std::map< shortcut_id, QPointer< QShortcut > > m_shortcuts
 
std::map< shortcut_id, fc_shortcutm_shortcuts_by_id
 

Static Private Attributes

static fc_shortcutsm_instance = nullptr
 

Detailed Description

Definition at line 126 of file shortcuts.h.

Constructor & Destructor Documentation

◆ fc_shortcuts()

fc_shortcuts::fc_shortcuts ( )
private

fc_shortcuts contructor

Definition at line 229 of file shortcuts.cpp.

Referenced by sc().

◆ ~fc_shortcuts()

fc_shortcuts::~fc_shortcuts ( )
virtual

fc_shortcuts destructor

Definition at line 234 of file shortcuts.cpp.

Member Function Documentation

◆ create_no_action_shortcuts()

void fc_shortcuts::create_no_action_shortcuts ( map_view parent)

Enable key bindings for all shortcuts that have no action associated with them.

Definition at line 285 of file shortcuts.cpp.

◆ drop()

void fc_shortcuts::drop ( )
static

Deletes current instance.

Definition at line 345 of file shortcuts.cpp.

◆ get_desc()

QString fc_shortcuts::get_desc ( shortcut_id  id) const

Returns description for given shortcut.

Definition at line 239 of file shortcuts.cpp.

Referenced by fc_shortcuts_dialog::shortcut_exists().

◆ get_shortcut()

fc_shortcut fc_shortcuts::get_shortcut ( shortcut_id  id) const

Returns shortcut for given id.

Definition at line 247 of file shortcuts.cpp.

Referenced by fc_shortcuts_dialog::edit_shortcut(), map_view::shortcut_released(), and unit_actions::update_actions().

◆ init_default()

void fc_shortcuts::init_default ( bool  read)

Inits defaults shortcuts or reads from settings.

Definition at line 365 of file shortcuts.cpp.

Referenced by fc_shortcuts_dialog::apply_option(), and fc_shortcuts().

◆ invoke()

void fc_shortcuts::invoke ( shortcut_id  id,
map_view mapview 
)

Invokes the action for a shortcut.

Definition at line 313 of file shortcuts.cpp.

Referenced by maybe_route_mouse_shortcut(), and hud_action::mouse_clicked().

◆ link_action()

void fc_shortcuts::link_action ( shortcut_id  id,
QAction *  action 
)

Links an action to a shortcut.

This will synchronize the action with the shortcut, and it will be triggered whenever the shortcut is entered.

Definition at line 275 of file shortcuts.cpp.

◆ maybe_route_mouse_shortcut()

void fc_shortcuts::maybe_route_mouse_shortcut ( QMouseEvent *  event,
map_view mapview 
)

If the mouse event corresponds to a registered shortcut, fire the corresponding action.

Definition at line 328 of file shortcuts.cpp.

Referenced by map_view::mousePressEvent().

◆ Q_DISABLE_COPY()

fc_shortcuts::Q_DISABLE_COPY ( fc_shortcuts  )
private

◆ read()

bool fc_shortcuts::read ( )

Reads shortcuts from file.

Returns false if failed.

Definition at line 765 of file shortcuts.cpp.

Referenced by init_default().

◆ sc()

◆ set_shortcut()

void fc_shortcuts::set_shortcut ( const fc_shortcut sc)

Sets given shortcut.

Definition at line 255 of file shortcuts.cpp.

Referenced by fc_shortcuts_dialog::edit_shortcut(), and read().

◆ setup_action()

void fc_shortcuts::setup_action ( const fc_shortcut sc,
QAction *  action 
)
private

Sets up key bindings for the action.

Definition at line 384 of file shortcuts.cpp.

Referenced by link_action(), and set_shortcut().

◆ shortcuts()

auto fc_shortcuts::shortcuts ( ) const
inline

Returns all existing shortcuts.

Definition at line 138 of file shortcuts.h.

Referenced by create_no_action_shortcuts(), link_action(), maybe_route_mouse_shortcut(), and write().

◆ write()

void fc_shortcuts::write ( ) const

Writes shortcuts to file.

Definition at line 746 of file shortcuts.cpp.

Referenced by fc_shortcuts_dialog::apply_option(), and fc_client::write_settings().

Member Data Documentation

◆ m_actions

std::map<shortcut_id, QPointer<QAction> > fc_shortcuts::m_actions
private

Definition at line 161 of file shortcuts.h.

Referenced by create_no_action_shortcuts(), invoke(), link_action(), and set_shortcut().

◆ m_instance

fc_shortcuts * fc_shortcuts::m_instance = nullptr
staticprivate

Definition at line 159 of file shortcuts.h.

Referenced by drop(), and sc().

◆ m_shortcuts

std::map<shortcut_id, QPointer<QShortcut> > fc_shortcuts::m_shortcuts
private

Definition at line 162 of file shortcuts.h.

Referenced by create_no_action_shortcuts().

◆ m_shortcuts_by_id

std::map<shortcut_id, fc_shortcut> fc_shortcuts::m_shortcuts_by_id
private