OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
KeyboardShortcut Class Reference

#include <KeyboardShortcut.hh>

Inheritance diagram for KeyboardShortcut:
Inheritance graph
Collaboration diagram for KeyboardShortcut:
Collaboration graph

Public Member Functions

 KeyboardShortcut (const std::string &action, int fKey, bool ctrl, bool alt, char key)
 
 KeyboardShortcut (const ObjectState *state)
 
 KeyboardShortcut (const KeyboardShortcut &old)
 
virtual ~KeyboardShortcut ()
 
std::string action () const
 
int fKey () const
 
bool ctrl () const
 
bool alt () const
 
char key () const
 
void setFKey (int fKey)
 
void setCtrl (bool ctrl)
 
void setAlt (bool alt)
 
void setKey (char key)
 
bool equals (const KeyboardShortcut &sc) const
 
void loadState (const ObjectState *state)
 
ObjectStatesaveState () const
 
- Public Member Functions inherited from Serializable
virtual ~Serializable ()
 

Static Public Attributes

static const std::string OSNAME_KEYBOARD_SHORTCUT = "keybsc"
 ObjectState name for keyboard shortcut.
 
static const std::string OSKEY_ACTION = "action"
 ObjectState attribute key for action name.
 
static const std::string OSKEY_FKEY = "fkey"
 ObjectState attribute key for function key number.
 
static const std::string OSKEY_CTRL = "ctrl"
 ObjectState attribute key for ctrl key.
 
static const std::string OSKEY_ALT = "alt"
 ObjectState attribute key for alt key.
 
static const std::string OSKEY_KEY = "key"
 ObjectState attribute key for normal letter or number key.
 

Private Member Functions

KeyboardShortcutoperator= (const KeyboardShortcut)
 Assigment forbidden.
 

Private Attributes

std::string action_
 Name of the action which is performed by the key combination.
 
int fKey_
 Number of the function key if it is used, 0 otherwise.
 
bool ctrl_
 True if Ctrl button is used in the key combination.
 
bool alt_
 True if Alt button is used in the key combination.
 
char key_
 

Detailed Description

This class stores the keyboard buttons used in a keyboard shortcut.

It contains also the name of the action performed by the key combination. This class implements the Serializable interface because keyboard shortcuts are serialized into the configuration file.

Definition at line 50 of file KeyboardShortcut.hh.

Constructor & Destructor Documentation

◆ KeyboardShortcut() [1/3]

KeyboardShortcut::KeyboardShortcut ( const std::string &  action,
int  fKey,
bool  ctrl,
bool  alt,
char  key 
)

Constructor.

Parameters
actionName of the action performed by the key combination.
fKeyNumber of the function key used in the shortcut, if the value is not between 1 and 12 it is ignored and any function key won't be used.
ctrlTrue if the Ctrl button is used.
altTrue if the Alt button is used.
keyCharacter used in the key combination, NUL character if no character is used. If delete is used, apply ascii 127.

Definition at line 60 of file KeyboardShortcut.cc.

65 :
67
68 // validity checks
69 if (key < '0' && key != 0) {
70 assert(false);
71 }
72 if (key > '9' && key < 'A') {
73 assert(false);
74 }
75 if (key > 'Z' && key < 'a') {
76 assert(false);
77 }
78 if (key > 'z' && key != 127) {
79 assert(false);
80 }
81
82 // if key is lower case letter, convert it to lower case
83 if (key_ >= 'a' && key_ <= 'z') {
84 key_ -= 32;
85 }
86
87 // validity checks
88 if (this->fKey() != 0) {
89 assert(this->key() == 0);
90 }
91 if (this->key() != 0) {
92 assert(this->fKey() == 0);
93 assert(ctrl_ == true || alt_ == true);
94 }
95}
#define assert(condition)
bool alt_
True if Alt button is used in the key combination.
bool ctrl_
True if Ctrl button is used in the key combination.
int fKey_
Number of the function key if it is used, 0 otherwise.
std::string action() const
std::string action_
Name of the action which is performed by the key combination.

References alt_, assert, ctrl_, fKey(), key(), and key_.

Here is the call graph for this function:

◆ KeyboardShortcut() [2/3]

KeyboardShortcut::KeyboardShortcut ( const ObjectState state)

Constructor.

Loads the state of the object from the given ObjectState object.

Parameters
stateObjectState from which the state is loaded.

Definition at line 105 of file KeyboardShortcut.cc.

105 {
106 loadState(state);
107}
void loadState(const ObjectState *state)

References loadState().

Here is the call graph for this function:

◆ KeyboardShortcut() [3/3]

KeyboardShortcut::KeyboardShortcut ( const KeyboardShortcut old)

Copy constructor.

Definition at line 113 of file KeyboardShortcut.cc.

114 : Serializable() {
115
116 action_ = old.action_;
117 fKey_ = old.fKey_;
118 ctrl_ = old.ctrl_;
119 alt_ = old.alt_;
120 key_ = old.key_;
121}

References action_, alt_, ctrl_, fKey_, and key_.

◆ ~KeyboardShortcut()

KeyboardShortcut::~KeyboardShortcut ( )
virtual

Destructor.

Definition at line 127 of file KeyboardShortcut.cc.

127 {
128}

Member Function Documentation

◆ action()

std::string KeyboardShortcut::action ( ) const

Returns the name of the action performed by this key combination.

Returns
Name of the action performed by this key combination.

Definition at line 137 of file KeyboardShortcut.cc.

137 {
138 return action_;
139}

References action_.

Referenced by OptionsDialog::readOptions(), and GUIOptions::validate().

◆ alt()

bool KeyboardShortcut::alt ( ) const

Returns true if Alt button is used in the key combination.

Returns
True if Alt button is used in the key combination, otherwise false.

Definition at line 177 of file KeyboardShortcut.cc.

177 {
178 return alt_;
179}

References alt_.

Referenced by ProximMainFrame::menuAccelerator(), MainFrame::menuAccelerator(), setAlt(), and KeyboardShortcutDialog::TransferDataToWindow().

◆ ctrl()

bool KeyboardShortcut::ctrl ( ) const

Returns true if Ctrl button is used in the key combination.

Returns
True if Ctrl button is used in the key combination, otherwise false.

Definition at line 165 of file KeyboardShortcut.cc.

165 {
166 return ctrl_;
167}

References ctrl_.

Referenced by ProximMainFrame::menuAccelerator(), MainFrame::menuAccelerator(), setCtrl(), and KeyboardShortcutDialog::TransferDataToWindow().

◆ equals()

bool KeyboardShortcut::equals ( const KeyboardShortcut sc) const

Returns true if the given keyboard shortcut has the same key combination as this.

Parameters
scKeyboard shortcut.
Returns
True if the given keyboard shortcut has the same key combination as this.

Definition at line 250 of file KeyboardShortcut.cc.

250 {
251 if (ctrl_ == sc.ctrl_ && alt_ == sc.alt_ && key_ == sc.key_ &&
252 fKey() == sc.fKey()) {
253 return true;
254 } else {
255 return false;
256 }
257}

References alt_, ctrl_, fKey(), and key_.

Referenced by GUIOptions::validate().

Here is the call graph for this function:

◆ fKey()

int KeyboardShortcut::fKey ( ) const

Returns the number of the function key used in the key combination.

Returns
Number of the function key used in the key combination, 0 if no function key is used.

Definition at line 149 of file KeyboardShortcut.cc.

149 {
150 if (fKey_ < 1 || fKey_ > 12) {
151 return 0;
152 } else {
153 return fKey_;
154 }
155}

References fKey_.

Referenced by equals(), KeyboardShortcut(), ProximMainFrame::menuAccelerator(), MainFrame::menuAccelerator(), saveState(), setFKey(), and KeyboardShortcutDialog::TransferDataToWindow().

◆ key()

char KeyboardShortcut::key ( ) const

Returns the character used in the key combination or NUL character if no character is used.

Returns
The character used in the key combination or NUL character if no character is used.

Definition at line 190 of file KeyboardShortcut.cc.

190 {
191 return key_;
192}

References key_.

Referenced by KeyboardShortcut(), ProximMainFrame::menuAccelerator(), MainFrame::menuAccelerator(), setKey(), and KeyboardShortcutDialog::TransferDataToWindow().

◆ loadState()

void KeyboardShortcut::loadState ( const ObjectState state)
virtual

Loads the state of the object from the given ObjectState object.

Parameters
stateObjectState from which the state is loaded.
Exceptions
ObjectStateLoadingExceptionIf the given ObjectState instance is invalid.

Implements Serializable.

Definition at line 268 of file KeyboardShortcut.cc.

268 {
269 const string procName = "KeyboardShortcut::loadState";
270
271 if (state->name() != OSNAME_KEYBOARD_SHORTCUT) {
272 throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
273 }
274
275 try {
277
278 if (state->hasAttribute(OSKEY_FKEY)) {
279 fKey_ = state->intAttribute(OSKEY_FKEY);
280 } else {
281 fKey_ = 0;
282 }
283
284 ctrl_ = state->intAttribute(OSKEY_CTRL);
285 alt_ = state->intAttribute(OSKEY_ALT);
286
287 if (state->hasAttribute(OSKEY_KEY)) {
288 key_ = state->intAttribute(OSKEY_KEY);
289
290 // convert to upper case if lower case
291 if (key_ >= 'a' && key_ <= 'z') {
292 key_ -= 32;
293 }
294
295 } else {
296 key_ = 0;
297 }
298
299 } catch (...) {
300 throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
301 }
302}
static const std::string OSKEY_KEY
ObjectState attribute key for normal letter or number key.
static const std::string OSKEY_ALT
ObjectState attribute key for alt key.
static const std::string OSKEY_FKEY
ObjectState attribute key for function key number.
static const std::string OSKEY_ACTION
ObjectState attribute key for action name.
static const std::string OSKEY_CTRL
ObjectState attribute key for ctrl key.
static const std::string OSNAME_KEYBOARD_SHORTCUT
ObjectState name for keyboard shortcut.
bool hasAttribute(const std::string &name) const
std::string stringAttribute(const std::string &name) const
int intAttribute(const std::string &name) const
std::string name() const

References action_, alt_, ctrl_, fKey_, ObjectState::hasAttribute(), ObjectState::intAttribute(), key_, ObjectState::name(), OSKEY_ACTION, OSKEY_ALT, OSKEY_CTRL, OSKEY_FKEY, OSKEY_KEY, OSNAME_KEYBOARD_SHORTCUT, and ObjectState::stringAttribute().

Referenced by KeyboardShortcut().

Here is the call graph for this function:

◆ operator=()

KeyboardShortcut & KeyboardShortcut::operator= ( const KeyboardShortcut  )
private

Assigment forbidden.

◆ saveState()

ObjectState * KeyboardShortcut::saveState ( ) const
virtual

Creates an ObjectState object and saves the state of the object into it.

Returns
The created ObjectState object.

Implements Serializable.

Definition at line 310 of file KeyboardShortcut.cc.

310 {
311
313
315
316 // if function key is used
317 if (fKey() != 0) {
318 state->setAttribute(OSKEY_FKEY, fKey());
319 }
320
322 state->setAttribute(OSKEY_ALT, alt_);
323
324 // if key is not nul character
325 if (key_ != 0) {
326 state->setAttribute(OSKEY_KEY, key_);
327 }
328
329 return state;
330}
void setAttribute(const std::string &name, const std::string &value)

References action_, alt_, ctrl_, fKey(), key_, OSKEY_ACTION, OSKEY_ALT, OSKEY_CTRL, OSKEY_FKEY, OSKEY_KEY, OSNAME_KEYBOARD_SHORTCUT, and ObjectState::setAttribute().

Referenced by GUIOptions::saveState().

Here is the call graph for this function:

◆ setAlt()

void KeyboardShortcut::setAlt ( bool  alt)

Sets alt-button state of the shortcut.

Parameters
altAlt-button state of the shortcut.

Definition at line 212 of file KeyboardShortcut.cc.

212 {
213 alt_ = alt;
214}

References alt(), and alt_.

Referenced by KeyboardShortcutDialog::onCharEvent().

Here is the call graph for this function:

◆ setCtrl()

void KeyboardShortcut::setCtrl ( bool  ctrl)

Sets control button state of the shortcut.

Parameters
ctrlCtrl-button state of the shortcut.

Definition at line 201 of file KeyboardShortcut.cc.

201 {
202 ctrl_ = ctrl;
203}

References ctrl(), and ctrl_.

Referenced by KeyboardShortcutDialog::onCharEvent().

Here is the call graph for this function:

◆ setFKey()

void KeyboardShortcut::setFKey ( int  fKey)

Sets the function key of the keyboard shortcut. Set as 0 if the shortcut doesn't use function key.

Parameters
keyFunction key of the shortcut.

Definition at line 233 of file KeyboardShortcut.cc.

233 {
234 if (fKey < 0 || fKey > 12) {
235 fKey = 0;
236 } else {
237 fKey_ = fKey;
238 }
239}

References fKey(), and fKey_.

Referenced by KeyboardShortcutDialog::onCharEvent().

Here is the call graph for this function:

◆ setKey()

void KeyboardShortcut::setKey ( char  key)

Sets the character key of the keyboard shortcut.

Parameters
keyCharacter key of the shortcut.

Definition at line 222 of file KeyboardShortcut.cc.

222 {
223 key_ = key;
224}

References key(), and key_.

Referenced by KeyboardShortcutDialog::onCharEvent().

Here is the call graph for this function:

Member Data Documentation

◆ action_

std::string KeyboardShortcut::action_
private

Name of the action which is performed by the key combination.

Definition at line 93 of file KeyboardShortcut.hh.

Referenced by action(), KeyboardShortcut(), loadState(), and saveState().

◆ alt_

bool KeyboardShortcut::alt_
private

True if Alt button is used in the key combination.

Definition at line 99 of file KeyboardShortcut.hh.

Referenced by alt(), equals(), KeyboardShortcut(), KeyboardShortcut(), loadState(), saveState(), and setAlt().

◆ ctrl_

bool KeyboardShortcut::ctrl_
private

True if Ctrl button is used in the key combination.

Definition at line 97 of file KeyboardShortcut.hh.

Referenced by ctrl(), equals(), KeyboardShortcut(), KeyboardShortcut(), loadState(), saveState(), and setCtrl().

◆ fKey_

int KeyboardShortcut::fKey_
private

Number of the function key if it is used, 0 otherwise.

Definition at line 95 of file KeyboardShortcut.hh.

Referenced by fKey(), KeyboardShortcut(), loadState(), and setFKey().

◆ key_

char KeyboardShortcut::key_
private

ASCII character of the button used in the key combination, if the key is not used the value is a NUL character (ASCII 0).

Definition at line 104 of file KeyboardShortcut.hh.

Referenced by equals(), key(), KeyboardShortcut(), KeyboardShortcut(), loadState(), saveState(), and setKey().

◆ OSKEY_ACTION

const string KeyboardShortcut::OSKEY_ACTION = "action"
static

◆ OSKEY_ALT

const string KeyboardShortcut::OSKEY_ALT = "alt"
static

◆ OSKEY_CTRL

const string KeyboardShortcut::OSKEY_CTRL = "ctrl"
static

◆ OSKEY_FKEY

const string KeyboardShortcut::OSKEY_FKEY = "fkey"
static

◆ OSKEY_KEY

const string KeyboardShortcut::OSKEY_KEY = "key"
static

ObjectState attribute key for normal letter or number key.

Definition at line 63 of file KeyboardShortcut.hh.

Referenced by GUIOptionsSerializer::addKeyboardShortcut(), GUIOptionsSerializer::convertToConfigFileFormat(), loadState(), and saveState().

◆ OSNAME_KEYBOARD_SHORTCUT

const string KeyboardShortcut::OSNAME_KEYBOARD_SHORTCUT = "keybsc"
static

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