ShortcutDialog.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package MemoryX::gui-plugins::SceneEditor
19  * @date 2015
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 #include "ShortcutDialog.h"
25 
26 #include <QHash>
27 #include <QKeySequence>
28 
29 #include <MemoryX/gui-plugins/SceneEditor/ui_ShortcutDialog.h>
30 
32  QDialog(parent), ui(new Ui::ShortcutDialog)
33 {
34  ui->setupUi(this);
35  shortcutController = control->getShortcutController();
36 
37  tableModel = new ShortcutTableModel();
38  proxyModel = new QSortFilterProxyModel();
39  proxyModel->setSourceModel(tableModel);
40 
41  ui->shortcutsTableView->setModel(proxyModel);
42  ui->shortcutsTableView->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
43  ui->shortcutsTableView->horizontalHeader()->resizeSection(1, 150);
44 
45  // Connect Slots and Signals
46  connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(close()));
47  connect(ui->shortcutsTableView,
48  SIGNAL(clicked(QModelIndex)),
49  this,
50  SLOT(shortcutClicked(QModelIndex)));
51  connect(ui->shortcutLineEdit, SIGNAL(textChanged(QString)), this, SLOT(shortcutChanged()));
52 }
53 
55 {
56  delete ui;
57 }
58 
59 void
60 gui::dialog::ShortcutDialog::showEvent(QShowEvent* event)
61 {
62  tableModel->setShortcutHashTable(shortcutController->getAllRegisteredShortcuts());
63  proxyModel = new QSortFilterProxyModel();
64  proxyModel->setSourceModel(tableModel);
65  ui->shortcutsTableView->setModel(proxyModel);
66  ui->shortcutsTableView->sortByColumn(0, Qt::AscendingOrder);
67 }
68 
69 void
70 gui::dialog::ShortcutDialog::shortcutClicked(QModelIndex index)
71 {
72  ui->keySequenceGroupBox->setEnabled(true);
73  activeAction =
74  tableModel->actionName(proxyModel->mapToSource(index), Qt::DisplayRole).toString();
75  ui->shortcutLineEdit->setText(
76  shortcutController->getAllRegisteredShortcuts().value(activeAction));
77  ui->shortcutLineEdit->setFocus();
78 }
79 
80 void
81 gui::dialog::ShortcutDialog::shortcutChanged()
82 {
83  shortcutController->updateShortcut(activeAction, ui->shortcutLineEdit->text());
84  tableModel->setShortcutHashTable(shortcutController->getAllRegisteredShortcuts());
85  proxyModel = new QSortFilterProxyModel();
86  proxyModel->setSourceModel(tableModel);
87  ui->shortcutsTableView->setModel(proxyModel);
88  ui->shortcutsTableView->sortByColumn(0, Qt::AscendingOrder);
89 }
90 
91 void
93 {
94  this->ui->retranslateUi(this);
95 }
index
uint8_t index
Definition: EtherCATFrame.h:59
gui::dialog::ShortcutDialog
Definition: ShortcutDialog.h:41
gui::dialog::ShortcutDialog::retranslate
void retranslate()
Translates all translatable strings in this dialog.
Definition: ShortcutDialog.cpp:92
gui::ShortcutTableModel
Definition: ShortcutTableModel.h:32
gui::dialog::ShortcutDialog::ShortcutDialog
ShortcutDialog(controller::ControllerPtr control, QWidget *parent=0)
Constructor.
Definition: ShortcutDialog.cpp:31
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
controller::ControllerPtr
std::shared_ptr< Controller > ControllerPtr
Definition: ClassDefinitions.h:41
ShortcutDialog.h
gui::dialog::ShortcutDialog::~ShortcutDialog
~ShortcutDialog() override
Destructor.
Definition: ShortcutDialog.cpp:54
control
This file is part of ArmarX.