1
0
Fork 0

GUI: working shortcuts dialog and some shortcuts binding

This commit is contained in:
tr4ceflow 2014-07-29 18:53:52 +02:00
parent c06eb683fb
commit 625aa68d22
7 changed files with 247 additions and 51 deletions

View File

@ -8,22 +8,40 @@ ShortcutEdit::ShortcutEdit(QWidget *parent) :
{
}
const QKeySequence ShortcutEdit::getKeysequence() const
{
// returns current keystroke combination
return QKeySequence(keyInt);
}
void ShortcutEdit::setErrorState(bool error){
if(error){
setStyleSheet("color: #FF0000");
}else{
setStyleSheet("color: #000000");
}
}
void ShortcutEdit::keyPressEvent(QKeyEvent *event)
{
int keyInt = event->key();
keyInt = event->key();
// find key-id
const Qt::Key key = static_cast<Qt::Key>(keyInt);
// we do not know how to handle this case
if( key == Qt::Key_unknown )
return;
// these keys will be ignored
if( key == Qt::Key_Escape || key == Qt::Key_Backspace )
{
setText("");
return;
}
// any combination of "Ctrl, Alt, Shift" ?
Qt::KeyboardModifiers modifiers = event->modifiers();
if(modifiers.testFlag(Qt::ShiftModifier))
keyInt += Qt::SHIFT;
@ -32,6 +50,21 @@ void ShortcutEdit::keyPressEvent(QKeyEvent *event)
if(modifiers.testFlag(Qt::AltModifier))
keyInt += Qt::ALT;
setText( QKeySequence(keyInt).toString(QKeySequence::NativeText) );
event->setAccepted(true);
// some strange cases (only Ctrl)
QString KeyText = QKeySequence(keyInt).toString(QKeySequence::NativeText) ;
for(int i=0;i<KeyText.length();i++){
if(KeyText[i].toAscii()==0){
setText("");
return;
}
}
// display key combination
setText( QKeySequence(keyInt).toString(QKeySequence::NativeText) );
// do not forward keypress-event
event->setAccepted(true);
// everything is fine , so ask for saving
emit askForSave();
}

View File

@ -6,11 +6,17 @@
class ShortcutEdit : public QLineEdit
{
Q_OBJECT
QKeySequence key;
int keyInt;
public:
explicit ShortcutEdit(QWidget *parent = 0);
signals:
const QKeySequence getKeysequence() const;
public slots:
void setErrorState(bool error);
signals:
void askForSave();
protected:
void keyPressEvent ( QKeyEvent * event );

View File

@ -166,6 +166,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
connect(mCpuWidget->mStack, SIGNAL(displayReferencesWidget()), this, SLOT(displayReferencesWidget()));
connect(Bridge::getBridge(), SIGNAL(getStrWindow(QString,QString*)), this, SLOT(getStrWindow(QString,QString*)));
connect(Config(),SIGNAL(shortcutsUpdated()),this, SLOT(refreshShortcuts()));
//Set default setttings (when not set)
SettingsDialog defaultSettings;
lastException=0;
@ -224,24 +226,24 @@ void MainWindow::setTab(QWidget* widget)
}
void MainWindow::refreshShortcuts(){
ui->actionOpen->setShortcut(ConfigShortcut("HK::FILE_OPEN"));
ui->actionClose->setShortcut(ConfigShortcut("HK::APP_EXIT"));
ui->actionOpen->setShortcut(ConfigShortcut(XH::FILE_OPEN));
ui->actionClose->setShortcut(ConfigShortcut(XH::APP_EXIT));
ui->actionRun->setShortcut(ConfigShortcut("HK::DBG_RUN"));
ui->actionRun->setShortcut(ConfigShortcut(XH::DBG_RUN));
ui->actionCpu->setShortcut(ConfigShortcut("HK::VIEW_CPU"));
ui->actionMemoryMap->setShortcut(ConfigShortcut("HK::VIEW_MEMORY"));
ui->actionLog->setShortcut(ConfigShortcut("HK::VIEW_LOG"));
ui->actionBreakpoints->setShortcut(ConfigShortcut("HK::VIEW_BREAKPOINTS"));
ui->actionScript->setShortcut(ConfigShortcut("HK::VIEW_SCRIPT"));
ui->actionSymbolInfo->setShortcut(ConfigShortcut("HK::VIEW_SYMINFO"));
ui->actionReferences->setShortcut(ConfigShortcut("HK::VIEW_REFERENCES"));
ui->actionThreads->setShortcut(ConfigShortcut("HK::VIEW_THREADS"));
ui->actionPatches->setShortcut(ConfigShortcut("HK::VIEW_PATCHES"));
ui->actionComments->setShortcut(ConfigShortcut("HK::VIEW_COMMENTS"));
ui->actionLabels->setShortcut(ConfigShortcut("HK::VIEW_LABELS"));
ui->actionBookmarks->setShortcut(ConfigShortcut("HK::VIEW_BOOKMARKS"));
ui->actionFunctions->setShortcut(ConfigShortcut("HK::VIEW_FUNCTIONS"));
ui->actionCpu->setShortcut(ConfigShortcut(XH::VIEW_CPU));
ui->actionMemoryMap->setShortcut(ConfigShortcut(XH::VIEW_MEMORY));
ui->actionLog->setShortcut(ConfigShortcut(XH::VIEW_LOG));
ui->actionBreakpoints->setShortcut(ConfigShortcut(XH::VIEW_BREAKPOINTS));
ui->actionScript->setShortcut(ConfigShortcut(XH::VIEW_SCRIPT));
ui->actionSymbolInfo->setShortcut(ConfigShortcut(XH::VIEW_SYMINFO));
ui->actionReferences->setShortcut(ConfigShortcut(XH::VIEW_REFERENCES));
ui->actionThreads->setShortcut(ConfigShortcut(XH::VIEW_THREADS));
ui->actionPatches->setShortcut(ConfigShortcut(XH::VIEW_PATCHES));
ui->actionComments->setShortcut(ConfigShortcut(XH::VIEW_COMMENTS));
ui->actionLabels->setShortcut(ConfigShortcut(XH::VIEW_LABELS));
ui->actionBookmarks->setShortcut(ConfigShortcut(XH::VIEW_BOOKMARKS));
ui->actionFunctions->setShortcut(ConfigShortcut(XH::VIEW_FUNCTIONS));
}
//Reads recent files list from settings

View File

@ -1,6 +1,8 @@
#include "ShortcutsDialog.h"
#include "ui_ShortcutsDialog.h"
#include "ShortcutEdit.h"
ShortcutsDialog::ShortcutsDialog(QWidget *parent) :
QDialog(parent),
@ -23,10 +25,76 @@ ShortcutsDialog::ShortcutsDialog(QWidget *parent) :
tbl->setSelectionBehavior(QAbstractItemView::SelectRows);
tbl->setSelectionMode(QAbstractItemView::SingleSelection);
tbl->setShowGrid(false);
tbl->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
tbl->verticalHeader()->setDefaultSectionSize(15);
const unsigned int numShortcuts = Config()->Shortcuts.count();
tbl->setRowCount(numShortcuts);
for(unsigned int i=0;i<numShortcuts;i++){
QTableWidgetItem* shortcutName = new QTableWidgetItem(Config()->getShortcut(static_cast<XH::ShortcutId>(i)).Name);
QTableWidgetItem* shortcutDummy = new QTableWidgetItem("");
QTableWidgetItem* shortcutKey = new QTableWidgetItem(Config()->getShortcut(static_cast<XH::ShortcutId>(i)).Hotkey.toString(QKeySequence::NativeText));
tbl->setItem(i,1,shortcutDummy);
tbl->setItem(i,0,shortcutName);
tbl->setItem(i,2,shortcutKey);
}
connect(ui->tblShortcuts,SIGNAL(clicked(QModelIndex)),this,SLOT(syncTextfield()));
shortcutfield = new ShortcutEdit(this);
ui->horizontalLayout->addWidget(shortcutfield);
connect(shortcutfield,SIGNAL(askForSave()),this,SLOT(updateShortcut()));
}
void ShortcutsDialog::updateShortcut(){
const QKeySequence newKey = shortcutfield->getKeysequence();
if(newKey != currentShortcut.Hotkey){
bool good=true;
foreach(XH::Shortcut S,Config()->Shortcuts ){
if((S.Hotkey == newKey) && (S.Id != currentShortcut.Id)){
good=false;
break;
}
}
if(good){
Config()->setShortcut(currentShortcut.Id,newKey);
ui->tblShortcuts->item(currentRow,2)->setText(newKey.toString(QKeySequence::NativeText));
shortcutfield->setErrorState(false);
}else{
shortcutfield->setErrorState(true);
}
}
}
void ShortcutsDialog::syncTextfield(){
QModelIndexList indexes = ui->tblShortcuts->selectionModel()->selectedRows();
if(indexes.count()<1)
return;
currentRow = indexes.at(0).row();
currentShortcut = Config()->getShortcut(static_cast<XH::ShortcutId>(indexes.at(0).row()));
shortcutfield->setErrorState(false);
shortcutfield->setText(currentShortcut.Hotkey.toString(QKeySequence::NativeText));
ShortcutEdit *SH = new ShortcutEdit(this);
ui->horizontalLayout->addWidget(SH);
}

View File

@ -2,6 +2,9 @@
#define SHORTCUTSDIALOG_H
#include <QDialog>
#include <QTableWidget>
#include "ShortcutEdit.h"
#include "Configuration.h"
namespace Ui {
class ShortcutsDialog;
@ -10,11 +13,20 @@ class ShortcutsDialog;
class ShortcutsDialog : public QDialog
{
Q_OBJECT
QTableWidget* tbl;
ShortcutEdit *shortcutfield;
XH::Shortcut currentShortcut;
int currentRow;
bool editLock;
public:
explicit ShortcutsDialog(QWidget *parent = 0);
~ShortcutsDialog();
signals:
protected slots:
void syncTextfield();
void updateShortcut();
private:
Ui::ShortcutsDialog *ui;
};

View File

@ -166,23 +166,22 @@ Configuration::Configuration() : QObject()
defaultFonts.insert("Application", QApplication::font());
// hotkeys settings
defaultShortcuts.insert("HK::DBG_RUN",QKeySequence(Qt::Key_F4));
defaultShortcuts.insert("HK::FILE_OPEN",QKeySequence(Qt::Key_F3));
defaultShortcuts.insert("HK::APP_EXIT",QKeySequence(Qt::ALT+Qt::Key_X));
defaultShortcuts.insert("HK::VIEW_CPU",QKeySequence(Qt::ALT+Qt::Key_C));
defaultShortcuts.insert("HK::VIEW_MEMORY",QKeySequence(Qt::ALT+Qt::Key_M));
defaultShortcuts.insert("HK::VIEW_LOG",QKeySequence(Qt::ALT+Qt::Key_L));
defaultShortcuts.insert("HK::VIEW_BREAKPOINTS",QKeySequence(Qt::ALT+Qt::Key_B));
defaultShortcuts.insert("HK::VIEW_SCRIPT",QKeySequence(Qt::ALT+Qt::Key_S));
defaultShortcuts.insert("HK::VIEW_SYMINFO",QKeySequence(Qt::CTRL+Qt::ALT+Qt::Key_S));
defaultShortcuts.insert("HK::VIEW_REFERENCES",QKeySequence(Qt::ALT+Qt::Key_R));
defaultShortcuts.insert("HK::VIEW_THREADS",QKeySequence(Qt::ALT+Qt::Key_T));
defaultShortcuts.insert("HK::VIEW_PATCHES",QKeySequence(Qt::CTRL+Qt::Key_P));
defaultShortcuts.insert("HK::VIEW_COMMENTS",QKeySequence(Qt::CTRL+Qt::ALT+Qt::Key_C));
defaultShortcuts.insert("HK::VIEW_LABELS",QKeySequence(Qt::CTRL+Qt::ALT+Qt::Key_L));
defaultShortcuts.insert("HK::VIEW_BOOKMARKS",QKeySequence(Qt::ALT+Qt::Key_B));
defaultShortcuts.insert("HK::VIEW_FUNCTIONS",QKeySequence(Qt::ALT+Qt::Key_F));
defaultShortcuts.insert(XH::DBG_RUN,XH::Shortcut(XH::DBG_RUN,tr("run debugger"),Qt::Key_F4));
defaultShortcuts.insert(XH::FILE_OPEN,XH::Shortcut(XH::FILE_OPEN,tr("open file"),Qt::Key_F3));
defaultShortcuts.insert(XH::APP_EXIT,XH::Shortcut(XH::APP_EXIT,tr("exit app"),Qt::ALT+Qt::Key_X));
defaultShortcuts.insert(XH::VIEW_CPU,XH::Shortcut(XH::VIEW_CPU,tr("view cpu"),Qt::ALT+Qt::Key_C));
defaultShortcuts.insert(XH::VIEW_MEMORY,XH::Shortcut(XH::VIEW_MEMORY,tr("view memory map"),Qt::ALT+Qt::Key_M));
defaultShortcuts.insert(XH::VIEW_LOG,XH::Shortcut(XH::VIEW_LOG,tr("view log"),Qt::ALT+Qt::Key_L));
defaultShortcuts.insert(XH::VIEW_BREAKPOINTS,XH::Shortcut(XH::VIEW_BREAKPOINTS,tr("view breakpoint"),Qt::ALT+Qt::Key_B));
defaultShortcuts.insert(XH::VIEW_SCRIPT,XH::Shortcut(XH::VIEW_SCRIPT,tr("view script"),Qt::ALT+Qt::Key_S));
defaultShortcuts.insert(XH::VIEW_SYMINFO,XH::Shortcut(XH::VIEW_SYMINFO,tr("view symbolinfo"),Qt::CTRL+Qt::ALT+Qt::Key_S));
defaultShortcuts.insert(XH::VIEW_REFERENCES,XH::Shortcut(XH::VIEW_REFERENCES,tr("view references"),Qt::ALT+Qt::Key_R));
defaultShortcuts.insert(XH::VIEW_THREADS,XH::Shortcut(XH::VIEW_THREADS,tr("view threads"),Qt::ALT+Qt::Key_T));
defaultShortcuts.insert(XH::VIEW_PATCHES,XH::Shortcut(XH::VIEW_PATCHES,tr("view patches"),Qt::CTRL+Qt::Key_P));
defaultShortcuts.insert(XH::VIEW_COMMENTS,XH::Shortcut(XH::VIEW_COMMENTS,tr("view comments"),Qt::CTRL+Qt::ALT+Qt::Key_C));
defaultShortcuts.insert(XH::VIEW_LABELS,XH::Shortcut(XH::VIEW_LABELS,tr("view labels"),Qt::CTRL+Qt::ALT+Qt::Key_L));
defaultShortcuts.insert(XH::VIEW_BOOKMARKS,XH::Shortcut(XH::VIEW_BOOKMARKS,tr("view bookmarks"),Qt::ALT+Qt::Key_B));
defaultShortcuts.insert(XH::VIEW_FUNCTIONS,XH::Shortcut(XH::VIEW_FUNCTIONS,tr("view functions"),Qt::ALT+Qt::Key_F));
Shortcuts = defaultShortcuts;
@ -321,6 +320,31 @@ void Configuration::writeFonts()
emit fontsUpdated();
}
void Configuration::readShortcuts()
{
Shortcuts = defaultShortcuts;
QMap<XH::ShortcutId,XH::Shortcut>::const_iterator it = Shortcuts.begin();
while(it!=Shortcuts.end()){
const int id = it.value().Id;
QKeySequence KeySequence(shortcutFromConfig(id));
Shortcuts[it.key()].Hotkey = KeySequence;
}
emit shortcutsUpdated();
}
void Configuration::writeShortcuts()
{
QMap<XH::ShortcutId,XH::Shortcut>::const_iterator it = Shortcuts.begin();
while(it!=Shortcuts.end()){
shortcutToConfig(it.value().Id,it.value().Hotkey);
}
}
const QColor Configuration::getColor(const QString id) const
{
if(Colors.contains(id))
@ -426,16 +450,21 @@ const QFont Configuration::getFont(const QString id) const
return ret;
}
const QKeySequence Configuration::getShortcut(const QString key_id) const
const XH::Shortcut Configuration::getShortcut(const XH::ShortcutId key_id) const
{
return Shortcuts.find(key_id).value();
}
void Configuration::setShortcut(QString key_id, const QKeySequence key_sequence)
void Configuration::setShortcut(const XH::ShortcutId key_id, const int key_sequence)
{
Shortcuts.insert(key_id,key_sequence);
XH::Shortcut sh = Shortcuts.find(key_id).value();
sh.Hotkey = QKeySequence(key_sequence);
Shortcuts.insert(key_id,sh);
emit shortcutsUpdated();
}
QColor Configuration::colorFromConfig(const QString id)
{
char setting[MAX_SETTING_SIZE]="";
@ -556,3 +585,15 @@ bool Configuration::fontToConfig(const QString id, const QFont font)
{
return BridgeSettingSet("Fonts", id.toUtf8().constData(), font.toString().toUtf8().constData());
}
QString Configuration::shortcutFromConfig(const int id)
{
return ""; // return the keysequence as string
}
bool Configuration::shortcutToConfig(const int id, const QKeySequence shortcut)
{
QString _id = QString("%1").arg(id);
QString key = shortcut.toString(QKeySequence::NativeText);
return true;
}

View File

@ -15,13 +15,41 @@
#define ConfigBool(x,y) (Config()->getBool(x,y))
#define ConfigUint(x,y) (Config()->getUint(x,y))
#define ConfigFont(x) (Config()->getFont(x))
#define ConfigShortcut(x) (Config()->getShortcut(x))
#define ConfigShortcut(x) (Config()->getShortcut(x).Hotkey)
// X64dbgHotkeys
// ^ ^
namespace XH{
enum Hotkeys{FILE_OPEN, APP_EXIT,
DBG_STEPIN,DBG_STEPOVER,DBG_RUN};
enum ShortcutId{DBG_RUN,
FILE_OPEN,
APP_EXIT,
VIEW_CPU,
VIEW_MEMORY,
VIEW_LOG,
VIEW_BREAKPOINTS,
VIEW_SCRIPT,
VIEW_SYMINFO,
VIEW_REFERENCES,
VIEW_THREADS,
VIEW_PATCHES,
VIEW_COMMENTS,
VIEW_LABELS,
VIEW_BOOKMARKS,
VIEW_FUNCTIONS
};
struct Shortcut{
ShortcutId Id;
QString Name;
QKeySequence Hotkey;
Shortcut(int i,QString n,int h) : Id(static_cast<XH::ShortcutId>(i)),Name(n),Hotkey(QKeySequence(h)){}
Shortcut() : Id(),Name(""),Hotkey(NULL){}
};
};
class Configuration : public QObject
@ -41,6 +69,8 @@ public:
void writeUints();
void readFonts();
void writeFonts();
void readShortcuts();
void writeShortcuts();
const QColor getColor(const QString id) const;
const bool getBool(const QString category, const QString id) const;
@ -48,26 +78,28 @@ public:
const uint_t getUint(const QString category, const QString id) const;
void setUint(const QString category, const QString id, const uint_t i);
const QFont getFont(const QString id) const;
const QKeySequence getShortcut(const QString key_id) const;
void setShortcut(const QString key_id, const QKeySequence key_sequence);
const XH::Shortcut getShortcut(const XH::ShortcutId key_id) const;
void setShortcut(const XH::ShortcutId key_id, const int key_sequence);
//default setting maps
QMap<QString, QColor> defaultColors;
QMap<QString, QMap<QString, bool>> defaultBools;
QMap<QString, QMap<QString, uint_t>> defaultUints;
QMap<QString, QFont> defaultFonts;
QMap<QString,QKeySequence> defaultShortcuts;
QMap<XH::ShortcutId,XH::Shortcut> defaultShortcuts;
//public variables
QMap<QString, QColor> Colors;
QMap<QString, QMap<QString, bool>> Bools;
QMap<QString, QMap<QString, uint_t>> Uints;
QMap<QString, QFont> Fonts;
QMap<QString,QKeySequence> Shortcuts;
QMap<XH::ShortcutId,XH::Shortcut> Shortcuts;
signals:
void colorsUpdated();
void fontsUpdated();
void shortcutsUpdated();
private:
QColor colorFromConfig(const QString id);
@ -78,6 +110,8 @@ private:
bool uintToConfig(const QString category, const QString id, uint_t i);
QFont fontFromConfig(const QString id);
bool fontToConfig(const QString id, const QFont font);
QString shortcutFromConfig(const int id);
bool shortcutToConfig(const int id, const QKeySequence shortcut);
};
#endif // CONFIGURATION_H