mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-15 19:47:46 -07:00
Shortcuts preference pane (#3641)
* Shortcuts preference pane * Honor and glory to the hypnoclangifier * clanfigy: exclude deleted files from being checked * keep the olf translation context to be able to reuse old translations * Fix gcc; extract translations * Moved generic buttons after the groupbox * Update current item on "clear/reset all" * Sequenceedit: make buttons larger and translatable, add text * Event filter * Don't filter arrow keys; added placeholder text * group counters
This commit is contained in:
parent
11b2942d09
commit
389f7fdc25
13 changed files with 1606 additions and 3123 deletions
|
|
@ -5,24 +5,16 @@
|
|||
#include <QToolTip>
|
||||
#include <utility>
|
||||
|
||||
SequenceEdit::SequenceEdit(const QString &_shortcutName, QWidget *parent) : QWidget(parent), shortcutName(_shortcutName)
|
||||
SequenceEdit::SequenceEdit(const QString &_shortcutName, QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
lineEdit = new QLineEdit(this);
|
||||
clearButton = new QPushButton("", this);
|
||||
defaultButton = new QPushButton("", this);
|
||||
|
||||
lineEdit->setMinimumWidth(70);
|
||||
clearButton->setMaximumWidth(lineEdit->height());
|
||||
defaultButton->setMaximumWidth(lineEdit->height());
|
||||
clearButton->setMaximumHeight(lineEdit->height());
|
||||
defaultButton->setMaximumHeight(lineEdit->height());
|
||||
|
||||
clearButton->setIcon(QPixmap("theme:icons/clearsearch"));
|
||||
defaultButton->setIcon(QPixmap("theme:icons/update"));
|
||||
|
||||
clearButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
defaultButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
|
||||
auto *layout = new QHBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(1);
|
||||
|
|
@ -34,7 +26,26 @@ SequenceEdit::SequenceEdit(const QString &_shortcutName, QWidget *parent) : QWid
|
|||
connect(defaultButton, SIGNAL(clicked()), this, SLOT(restoreDefault()));
|
||||
lineEdit->installEventFilter(this);
|
||||
|
||||
lineEdit->setText(settingsCache->shortcuts().getShortcutString(shortcutName));
|
||||
setShortcutName(_shortcutName);
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void SequenceEdit::setShortcutName(const QString &_shortcutName)
|
||||
{
|
||||
shortcutName = _shortcutName;
|
||||
if (shortcutName.isEmpty()) {
|
||||
clearButton->setEnabled(false);
|
||||
defaultButton->setEnabled(false);
|
||||
lineEdit->setEnabled(false);
|
||||
lineEdit->setText("");
|
||||
lineEdit->setPlaceholderText(tr("Choose an action from the table"));
|
||||
} else {
|
||||
clearButton->setEnabled(true);
|
||||
defaultButton->setEnabled(true);
|
||||
lineEdit->setEnabled(true);
|
||||
lineEdit->setText(settingsCache->shortcuts().getShortcutString(shortcutName));
|
||||
lineEdit->setPlaceholderText(tr("Hit the key/combination of keys you want to set for this action"));
|
||||
}
|
||||
}
|
||||
|
||||
QString SequenceEdit::getSequence()
|
||||
|
|
@ -73,11 +84,23 @@ void SequenceEdit::clear()
|
|||
lineEdit->setText("");
|
||||
}
|
||||
|
||||
bool SequenceEdit::eventFilter(QObject *, QEvent *event)
|
||||
bool SequenceEdit::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
|
||||
auto *keyEvent = reinterpret_cast<QKeyEvent *>(event);
|
||||
|
||||
// don't filter outside arrow key events
|
||||
if (obj != lineEdit) {
|
||||
switch (keyEvent->key()) {
|
||||
case Qt::Key_Up:
|
||||
case Qt::Key_Down:
|
||||
case Qt::Key_Left:
|
||||
case Qt::Key_Right:
|
||||
return false;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (event->type() == QEvent::KeyPress && !keyEvent->isAutoRepeat()) {
|
||||
processKey(keyEvent);
|
||||
} else if (event->type() == QEvent::KeyRelease && !keyEvent->isAutoRepeat()) {
|
||||
|
|
@ -161,3 +184,10 @@ void SequenceEdit::updateSettings()
|
|||
{
|
||||
settingsCache->shortcuts().setShortcuts(shortcutName, lineEdit->text());
|
||||
}
|
||||
|
||||
void SequenceEdit::retranslateUi()
|
||||
{
|
||||
clearButton->setText(tr("Clear"));
|
||||
defaultButton->setText(tr("Restore default"));
|
||||
setShortcutName(shortcutName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,10 @@ class SequenceEdit : public QWidget
|
|||
public:
|
||||
SequenceEdit(const QString &_shortcutName, QWidget *parent = nullptr);
|
||||
QString getSequence();
|
||||
void setShortcutName(const QString &_shortcutName);
|
||||
void refreshShortcut();
|
||||
void clear();
|
||||
void retranslateUi();
|
||||
|
||||
private slots:
|
||||
void removeLastShortcut();
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
#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()
|
||||
{
|
||||
ui->retranslateUi(this);
|
||||
}
|
||||
|
||||
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 (auto edit : edits) {
|
||||
edit->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 (auto edit : edits) {
|
||||
edit->clear();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
#ifndef SHORTCUTSTAB_H
|
||||
#define SHORTCUTSTAB_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "../dlg_settings.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class shortcutsTab;
|
||||
}
|
||||
|
||||
class ShortcutsTab : public AbstractSettingsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ShortcutsTab();
|
||||
void retranslateUi();
|
||||
~ShortcutsTab();
|
||||
|
||||
private slots:
|
||||
void resetShortcuts();
|
||||
void refreshEdits();
|
||||
void clearShortcuts();
|
||||
void afterClear();
|
||||
|
||||
private:
|
||||
Ui::shortcutsTab *ui;
|
||||
};
|
||||
|
||||
#endif // SHORTCUTSTAB_H
|
||||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue