Merge pull request #1523 from marcofernandezheras/Restore-Shortcuts
Restore shortcuts
This commit is contained in:
commit
8125358052
7 changed files with 111 additions and 3 deletions
|
@ -71,6 +71,16 @@ void SequenceEdit::restoreDefault()
|
||||||
updateSettings();
|
updateSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SequenceEdit::refreshShortcut()
|
||||||
|
{
|
||||||
|
lineEdit->setText(settingsCache->shortcuts().getShortcutString(shorcutName));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SequenceEdit::clear()
|
||||||
|
{
|
||||||
|
this->lineEdit->setText("");
|
||||||
|
}
|
||||||
|
|
||||||
bool SequenceEdit::eventFilter(QObject *, QEvent * event)
|
bool SequenceEdit::eventFilter(QObject *, QEvent * event)
|
||||||
{
|
{
|
||||||
if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease)
|
if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease)
|
||||||
|
|
|
@ -14,11 +14,14 @@ class SequenceEdit : public QWidget
|
||||||
public:
|
public:
|
||||||
SequenceEdit(QString _shorcutName, QWidget *parent = 0);
|
SequenceEdit(QString _shorcutName, QWidget *parent = 0);
|
||||||
QString getSecuence();
|
QString getSecuence();
|
||||||
|
void refreshShortcut();
|
||||||
|
void clear();
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void removeLastShortcut();
|
void removeLastShortcut();
|
||||||
void restoreDefault();
|
void restoreDefault();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject *, QEvent *event);
|
bool eventFilter(QObject *, QEvent *event);
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
#include "shortcutstab.h"
|
#include "shortcutstab.h"
|
||||||
#include "ui_shortcutstab.h"
|
#include "ui_shortcutstab.h"
|
||||||
|
|
||||||
|
#include "../settingscache.h"
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
ShortcutsTab::ShortcutsTab() :
|
ShortcutsTab::ShortcutsTab() :
|
||||||
ui(new Ui::shortcutsTab)
|
ui(new Ui::shortcutsTab)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
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()
|
void ShortcutsTab::retranslateUi()
|
||||||
|
@ -16,3 +23,39 @@ ShortcutsTab::~ShortcutsTab()
|
||||||
{
|
{
|
||||||
delete ui;
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -17,7 +17,11 @@ public:
|
||||||
ShortcutsTab();
|
ShortcutsTab();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
~ShortcutsTab();
|
~ShortcutsTab();
|
||||||
|
private slots:
|
||||||
|
void resetShortcuts();
|
||||||
|
void refreshEdits();
|
||||||
|
void clearShortcuts();
|
||||||
|
void afterClear();
|
||||||
private:
|
private:
|
||||||
Ui::shortcutsTab *ui;
|
Ui::shortcutsTab *ui;
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QPushButton>
|
||||||
#include <QSpacerItem>
|
#include <QSpacerItem>
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
@ -18,6 +19,8 @@
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
#define WIKI "https://github.com/Cockatrice/Cockatrice/wiki/Custom-Keyboard-Shortcuts"
|
||||||
|
|
||||||
class Ui_shortcutsTab
|
class Ui_shortcutsTab
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -267,6 +270,9 @@ public:
|
||||||
SequenceEdit *Player_aAlwaysRevealTopCard;
|
SequenceEdit *Player_aAlwaysRevealTopCard;
|
||||||
QSpacerItem *verticalSpacer_3;
|
QSpacerItem *verticalSpacer_3;
|
||||||
QWidget * tab_4;
|
QWidget * tab_4;
|
||||||
|
QLabel *faqLabel;
|
||||||
|
QPushButton *btnResetAll;
|
||||||
|
QPushButton *btnClearAll;
|
||||||
|
|
||||||
void setupUi(QWidget *shortcutsTab)
|
void setupUi(QWidget *shortcutsTab)
|
||||||
{
|
{
|
||||||
|
@ -1402,7 +1408,24 @@ public:
|
||||||
grid->addItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding),1,0);
|
grid->addItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding),1,0);
|
||||||
|
|
||||||
tabWidget->addTab(tab_4, QString());
|
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);
|
tabWidget->setCurrentIndex(0);
|
||||||
|
|
||||||
grid->setSpacing(3);
|
grid->setSpacing(3);
|
||||||
|
@ -1557,6 +1580,9 @@ public:
|
||||||
lbl_Player_aAlwaysRevealTopCard->setText(QApplication::translate("shortcutsTab", "Always reveal top card", 0));
|
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_3), QApplication::translate("shortcutsTab", "Draw | Move | View | Gameplay", 0));
|
||||||
tabWidget->setTabText(tabWidget->indexOf(tab_4), QApplication::translate("shortcutsTab","Counters", 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
|
} // retranslateUi
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -119,6 +119,24 @@ bool ShortcutsSettings::isValid(QString name, QString Sequences)
|
||||||
return true;
|
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()
|
void ShortcutsSettings::fillDefaultShorcuts()
|
||||||
{
|
{
|
||||||
defaultShortCuts["MainWindow/aCheckCardUpdates"] = parseSequenceString("");
|
defaultShortCuts["MainWindow/aCheckCardUpdates"] = parseSequenceString("");
|
||||||
|
|
|
@ -24,9 +24,13 @@ public:
|
||||||
void setShortcuts(QString name, QString Sequences);
|
void setShortcuts(QString name, QString Sequences);
|
||||||
|
|
||||||
bool isValid(QString name, QString Sequences);
|
bool isValid(QString name, QString Sequences);
|
||||||
|
|
||||||
|
void resetAllShortcuts();
|
||||||
|
void clearAllShortcuts();
|
||||||
signals:
|
signals:
|
||||||
void shortCutchanged();
|
void shortCutchanged();
|
||||||
|
void allShortCutsReset();
|
||||||
|
void allShortCutsClear();
|
||||||
private:
|
private:
|
||||||
QString settingsFilePath;
|
QString settingsFilePath;
|
||||||
QMap<QString,QList<QKeySequence> > shortCuts;
|
QMap<QString,QList<QKeySequence> > shortCuts;
|
||||||
|
|
Loading…
Reference in a new issue