1
0
Fork 0

GUI: new dialog for shortcuts and some custom code for demonstrating how to use the shortcut mapping

This commit is contained in:
tr4ceflow 2014-07-28 23:59:48 +02:00
parent 439fbac25f
commit 564ed38c12
5 changed files with 224 additions and 0 deletions

View File

@ -0,0 +1,37 @@
#include "ShortcutEdit.h"
#include <QKeyEvent>
#include <QDebug>
ShortcutEdit::ShortcutEdit(QWidget *parent) :
QLineEdit(parent)
{
}
void ShortcutEdit::keyPressEvent(QKeyEvent *event)
{
int keyInt = event->key();
const Qt::Key key = static_cast<Qt::Key>(keyInt);
if( key == Qt::Key_unknown )
return;
if( key == Qt::Key_Escape || key == Qt::Key_Backspace )
{
setText("");
return;
}
Qt::KeyboardModifiers modifiers = event->modifiers();
if(modifiers.testFlag(Qt::ShiftModifier))
keyInt += Qt::SHIFT;
if(modifiers.testFlag(Qt::ControlModifier))
keyInt += Qt::CTRL;
if(modifiers.testFlag(Qt::AltModifier))
keyInt += Qt::ALT;
setText( QKeySequence(keyInt).toString(QKeySequence::NativeText) );
event->setAccepted(true);
}

View File

@ -0,0 +1,19 @@
#ifndef SHORTCUTEDIT_H
#define SHORTCUTEDIT_H
#include <QLineEdit>
class ShortcutEdit : public QLineEdit
{
Q_OBJECT
public:
explicit ShortcutEdit(QWidget *parent = 0);
signals:
protected:
void keyPressEvent ( QKeyEvent * event );
};
#endif // SHORTCUTEDIT_H

View File

@ -0,0 +1,36 @@
#include "ShortcutsDialog.h"
#include "ui_ShortcutsDialog.h"
#include "ShortcutEdit.h"
ShortcutsDialog::ShortcutsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ShortcutsDialog)
{
ui->setupUi(this);
//set window flags
setModal(true);
setWindowFlags(Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
setFixedSize(this->size()); //fixed size
// x64 has no model-view-controler pattern
QStringList tblHeader;
tblHeader << "Instruction" << "Description" << "Shortcut";
QTableWidget* tbl = ui->tblShortcuts;
tbl->setColumnCount(3);
tbl->verticalHeader()->setVisible(false);
tbl->setHorizontalHeaderLabels(tblHeader);
tbl->setEditTriggers(QAbstractItemView::NoEditTriggers);
tbl->setSelectionBehavior(QAbstractItemView::SelectRows);
tbl->setSelectionMode(QAbstractItemView::SingleSelection);
tbl->setShowGrid(false);
ShortcutEdit *SH = new ShortcutEdit(this);
ui->horizontalLayout->addWidget(SH);
}
ShortcutsDialog::~ShortcutsDialog()
{
delete ui;
}

View File

@ -0,0 +1,22 @@
#ifndef SHORTCUTSDIALOG_H
#define SHORTCUTSDIALOG_H
#include <QDialog>
namespace Ui {
class ShortcutsDialog;
}
class ShortcutsDialog : public QDialog
{
Q_OBJECT
public:
explicit ShortcutsDialog(QWidget *parent = 0);
~ShortcutsDialog();
private:
Ui::ShortcutsDialog *ui;
};
#endif // SHORTCUTSDIALOG_H

View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ShortcutsDialog</class>
<widget class="QDialog" name="ShortcutsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>622</width>
<height>409</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>270</x>
<y>370</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QTableWidget" name="tblShortcuts">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>601</width>
<height>281</height>
</rect>
</property>
</widget>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>10</x>
<y>310</y>
<width>601</width>
<height>51</height>
</rect>
</property>
<property name="title">
<string>Shortcut</string>
</property>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>561</width>
<height>22</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>current Shortcut</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ShortcutsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ShortcutsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>