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 #include <MemoryX/gui-plugins/SceneEditor/ui_ShortcutDialog.h>
26 
27 #include <QHash>
28 #include <QKeySequence>
29 
31  QDialog(parent),
32  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, SIGNAL(clicked(QModelIndex)), this, SLOT(shortcutClicked(QModelIndex)));
48  connect(ui->shortcutLineEdit, SIGNAL(textChanged(QString)), this, SLOT(shortcutChanged()));
49 }
50 
52 {
53  delete ui;
54 }
55 
56 void gui::dialog::ShortcutDialog::showEvent(QShowEvent* event)
57 {
58  tableModel->setShortcutHashTable(shortcutController->getAllRegisteredShortcuts());
59  proxyModel = new QSortFilterProxyModel();
60  proxyModel->setSourceModel(tableModel);
61  ui->shortcutsTableView->setModel(proxyModel);
62  ui->shortcutsTableView->sortByColumn(0, Qt::AscendingOrder);
63 }
64 
65 void gui::dialog::ShortcutDialog::shortcutClicked(QModelIndex index)
66 {
67  ui->keySequenceGroupBox->setEnabled(true);
68  activeAction = tableModel->actionName(proxyModel->mapToSource(index), Qt::DisplayRole).toString();
69  ui->shortcutLineEdit->setText(shortcutController->getAllRegisteredShortcuts().value(activeAction));
70  ui->shortcutLineEdit->setFocus();
71 }
72 
73 void gui::dialog::ShortcutDialog::shortcutChanged()
74 {
75  shortcutController->updateShortcut(activeAction, ui->shortcutLineEdit->text());
76  tableModel->setShortcutHashTable(shortcutController->getAllRegisteredShortcuts());
77  proxyModel = new QSortFilterProxyModel();
78  proxyModel->setSourceModel(tableModel);
79  ui->shortcutsTableView->setModel(proxyModel);
80  ui->shortcutsTableView->sortByColumn(0, Qt::AscendingOrder);
81 }
82 
84 {
85  this->ui->retranslateUi(this);
86 }
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:83
gui::ShortcutTableModel
Definition: ShortcutTableModel.h:32
gui::dialog::ShortcutDialog::ShortcutDialog
ShortcutDialog(controller::ControllerPtr control, QWidget *parent=0)
Constructor.
Definition: ShortcutDialog.cpp:30
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:58
controller::ControllerPtr
std::shared_ptr< Controller > ControllerPtr
Definition: ClassDefinitions.h:41
ShortcutDialog.h
gui::dialog::ShortcutDialog::~ShortcutDialog
~ShortcutDialog() override
Destructor.
Definition: ShortcutDialog.cpp:51
control
This file is part of ArmarX.