Merge pull request #1523 from marcofernandezheras/Restore-Shortcuts

Restore shortcuts
This commit is contained in:
Zach 2015-09-22 16:00:49 -04:00
commit 8125358052
7 changed files with 111 additions and 3 deletions

View file

@ -71,6 +71,16 @@ void SequenceEdit::restoreDefault()
updateSettings();
}
void SequenceEdit::refreshShortcut()
{
lineEdit->setText(settingsCache->shortcuts().getShortcutString(shorcutName));
}
void SequenceEdit::clear()
{
this->lineEdit->setText("");
}
bool SequenceEdit::eventFilter(QObject *, QEvent * event)
{
if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease)

View file

@ -14,11 +14,14 @@ class SequenceEdit : public QWidget
public:
SequenceEdit(QString _shorcutName, QWidget *parent = 0);
QString getSecuence();
void refreshShortcut();
void clear();
signals:
private slots:
void removeLastShortcut();
void restoreDefault();
protected:
bool eventFilter(QObject *, QEvent *event);
private:

View file

@ -1,10 +1,17 @@
#include "shortcutstab.h"
#include "ui_shortcutstab.h"
#include "../settingscache.h"
#include <QMessageBox>
ShortcutsTab::ShortcutsTab() :
ui(new Ui::shortcutsTab)
{
ui->setupUi(this);
connect(ui->btnResetAll,SIGNAL(clicked()),this,SLOT(resetShortcuts()));
connect(ui->btnClearAll,SIGNAL(clicked()),this,SLOT(clearShortcuts()));
connect(&settingsCache->shortcuts(),SIGNAL(allShortCutsReset()),this,SLOT(refreshEdits()));
connect(&settingsCache->shortcuts(),SIGNAL(allShortCutsClear()),this,SLOT(afterClear()));
}
void ShortcutsTab::retranslateUi()
@ -16,3 +23,39 @@ ShortcutsTab::~ShortcutsTab()
{
delete ui;
}
void ShortcutsTab::resetShortcuts()
{
if(QMessageBox::question(this,tr("Restore all default shortcuts"),
tr("Do you really want to restore all default shortcuts?")) == QMessageBox::Yes)
{
settingsCache->shortcuts().resetAllShortcuts();
}
}
void ShortcutsTab::refreshEdits()
{
QList<SequenceEdit*> edits = this->findChildren<SequenceEdit*>();
for(int i= 0; i < edits.length(); ++i)
{
edits.at(i)->refreshShortcut();
}
}
void ShortcutsTab::clearShortcuts()
{
if(QMessageBox::question(this,tr("Clear all default shortcuts"),
tr("Do you really want to clear all shortcuts?")) == QMessageBox::Yes)
{
settingsCache->shortcuts().clearAllShortcuts();
}
}
void ShortcutsTab::afterClear()
{
QList<SequenceEdit*> edits = this->findChildren<SequenceEdit*>();
for(int i= 0; i < edits.length(); ++i)
{
edits.at(i)->clear();
}
}

View file

@ -17,7 +17,11 @@ public:
ShortcutsTab();
void retranslateUi();
~ShortcutsTab();
private slots:
void resetShortcuts();
void refreshEdits();
void clearShortcuts();
void afterClear();
private:
Ui::shortcutsTab *ui;
};

View file

@ -10,6 +10,7 @@
#include <QHBoxLayout>
#include <QHeaderView>
#include <QLabel>
#include <QPushButton>
#include <QSpacerItem>
#include <QTabWidget>
#include <QVBoxLayout>
@ -18,6 +19,8 @@
QT_BEGIN_NAMESPACE
#define WIKI "https://github.com/Cockatrice/Cockatrice/wiki/Custom-Keyboard-Shortcuts"
class Ui_shortcutsTab
{
public:
@ -267,6 +270,9 @@ public:
SequenceEdit *Player_aAlwaysRevealTopCard;
QSpacerItem *verticalSpacer_3;
QWidget * tab_4;
QLabel *faqLabel;
QPushButton *btnResetAll;
QPushButton *btnClearAll;
void setupUi(QWidget *shortcutsTab)
{
@ -1402,7 +1408,24 @@ public:
grid->addItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding),1,0);
tabWidget->addTab(tab_4, QString());
gridLayout_9->addWidget(tabWidget, 0, 0, 1, 1);
faqLabel = new QLabel(shortcutsTab);
faqLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
faqLabel->setOpenExternalLinks(true);
btnResetAll = new QPushButton(shortcutsTab);
btnClearAll = new QPushButton(shortcutsTab);
btnResetAll->setIcon(QPixmap("theme:icons/update"));
btnClearAll->setIcon(QPixmap("theme:icons/clearsearch"));
QHBoxLayout *buttonsLayout = new QHBoxLayout(shortcutsTab);
buttonsLayout->addWidget(btnClearAll);
buttonsLayout->addWidget(btnResetAll);
gridLayout_9->addWidget(tabWidget, 0, 0, 1, 2);
gridLayout_9->addWidget(faqLabel,1,0,1,1);
gridLayout_9->addLayout(buttonsLayout,1,1,1,1,Qt::AlignRight);
tabWidget->setCurrentIndex(0);
grid->setSpacing(3);
@ -1557,6 +1580,9 @@ public:
lbl_Player_aAlwaysRevealTopCard->setText(QApplication::translate("shortcutsTab", "Always reveal top card", 0));
tabWidget->setTabText(tabWidget->indexOf(tab_3), QApplication::translate("shortcutsTab", "Draw | Move | View | Gameplay", 0));
tabWidget->setTabText(tabWidget->indexOf(tab_4), QApplication::translate("shortcutsTab","Counters", 0));
faqLabel->setText(QString("<a href='%1'>%2</a>").arg(WIKI).arg(QApplication::translate("shortcutsTab","How to set custom shortcuts",0)));
btnResetAll->setText(QApplication::translate("shortcutsTab","Restore all default shortcuts",0));
btnClearAll->setText(QApplication::translate("shortcutsTab","Clear all shortcuts",0));
} // retranslateUi
};

View file

@ -119,6 +119,24 @@ bool ShortcutsSettings::isValid(QString name, QString Sequences)
return true;
}
void ShortcutsSettings::resetAllShortcuts()
{
for(QMap<QString,QList<QKeySequence> >::const_iterator it = defaultShortCuts.begin();
it != defaultShortCuts.end(); ++it){
setShortcuts(it.key(), it.value());
}
emit allShortCutsReset();
}
void ShortcutsSettings::clearAllShortcuts()
{
for(QMap<QString,QList<QKeySequence> >::const_iterator it = shortCuts.begin();
it != shortCuts.end(); ++it){
setShortcuts(it.key(), "");
}
emit allShortCutsClear();
}
void ShortcutsSettings::fillDefaultShorcuts()
{
defaultShortCuts["MainWindow/aCheckCardUpdates"] = parseSequenceString("");

View file

@ -24,9 +24,13 @@ public:
void setShortcuts(QString name, QString Sequences);
bool isValid(QString name, QString Sequences);
void resetAllShortcuts();
void clearAllShortcuts();
signals:
void shortCutchanged();
void allShortCutsReset();
void allShortCutsClear();
private:
QString settingsFilePath;
QMap<QString,QList<QKeySequence> > shortCuts;