BuildmLearn Toolkit  2.0.4
BuildmLearn Toolkit is an easy-to-use program that helps users make mobile apps without any knowledge of application development.
 All Classes Functions Enumerations Groups Pages
DynamicShortcutsWidget Class Reference

Widget for displaying and editing shortcuts. More...

#include <dynamicshortcutswidget.h>

Collaboration diagram for DynamicShortcutsWidget:
Collaboration graph

Public Member Functions

 DynamicShortcutsWidget (QWidget *parent=0)
 Constructor. More...
 
virtual ~DynamicShortcutsWidget ()
 Destructor.
 
void updateShortcuts ()
 Updates shortcuts of all actions according to changes. More...
 
bool areShortcutsUnique ()
 Checks whether set shortcuts are unique. More...
 
void populate (const QList< QAction * > actions)
 Populates this widget with shortcut widgets for given actions. More...
 

Detailed Description

Widget for displaying and editing shortcuts.

Definition at line 44 of file dynamicshortcutswidget.h.

Constructor & Destructor Documentation

DynamicShortcutsWidget::DynamicShortcutsWidget ( QWidget *  parent = 0)
explicit

Constructor.

Parameters
parentPointer to parent object.

Definition at line 44 of file dynamicshortcutswidget.cpp.

44  : QWidget(parent) {
45  // Create layout for this control and set is as active.
46  m_layout = new QGridLayout(this);
47  m_layout->setMargin(0);
48 
49  setLayout(m_layout);
50 }

Member Function Documentation

bool DynamicShortcutsWidget::areShortcutsUnique ( )

Checks whether set shortcuts are unique.

Returns
Returns true if all shortcuts are unique, otherwise false.

Definition at line 56 of file dynamicshortcutswidget.cpp.

56  {
57  QList<QKeySequence> all_shortcuts;
58 
59  // Obtain all shortcuts.
60  foreach (const ActionBinding &binding, m_actionBindings) {
61  QKeySequence new_shortcut = binding.second->shortcut();
62 
63  if (!new_shortcut.isEmpty() && all_shortcuts.contains(new_shortcut)) {
64  // Problem, two identical non-empty shortcuts found.
65  return false;
66  }
67  else {
68  all_shortcuts.append(binding.second->shortcut());
69  }
70  }
71 
72  return true;
73 }
void DynamicShortcutsWidget::populate ( const QList< QAction * >  actions)

Populates this widget with shortcut widgets for given actions.

This gets initial shortcut for each action from its properties, NOT from the application settings, so shortcuts from settings need to be assigned to actions before calling this method.

Definition at line 81 of file dynamicshortcutswidget.cpp.

81  {
82  m_actionBindings.clear();
83 
84  int row_id = 0;
85 
86  foreach (QAction *action, actions) {
87  // Create shortcut catcher for this action and set default shortcut.
88  ShortcutCatcher *catcher = new ShortcutCatcher(this);
89  catcher->setDefaultShortcut(action->shortcut());
90 
91  // Store information for re-initialization of shortcuts
92  // of actions when widget gets "confirmed".
93  QPair<QAction*,ShortcutCatcher*> new_binding;
94  new_binding.first = action;
95  new_binding.second = catcher;
96 
97  m_actionBindings << new_binding;
98 
99  // Add new catcher to our control.
100  QLabel *action_label = new QLabel(this);
101  action_label->setText(action->text().remove('&'));
102  action_label->setToolTip(action->toolTip());
103  action_label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
104 
105  QLabel *action_icon = new QLabel(this);
106  action_icon->setPixmap(action->icon().pixmap(ICON_SIZE_SETTINGS, ICON_SIZE_SETTINGS));
107  action_icon->setToolTip(action->toolTip());
108 
109  m_layout->addWidget(action_icon, row_id, 0);
110  m_layout->addWidget(action_label, row_id, 1);
111  m_layout->addWidget(catcher, row_id, 2);
112 
113  row_id++;
114  }
115 
116  // Make sure that "spacer" is added.
117  m_layout->setRowStretch(row_id, 1);
118  m_layout->setColumnStretch(1, 1);
119 }
void setDefaultShortcut(const QKeySequence &key)
Sets default shortcut for the widget.
Represents extra widget for changing single keyboard shortcut.

Here is the call graph for this function:

void DynamicShortcutsWidget::updateShortcuts ( )

Updates shortcuts of all actions according to changes.

No access to settings is done here. Shortcuts are fetched from settings when applications starts and stored back to settings when application quits.

Definition at line 75 of file dynamicshortcutswidget.cpp.

75  {
76  foreach (const ActionBinding &binding, m_actionBindings) {
77  binding.first->setShortcut(binding.second->shortcut());
78  }
79 }

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