mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 16:44:48 -07:00
Clang script (#3085)
This commit is contained in:
parent
fcfb2b12b7
commit
35159ef61a
24 changed files with 2098 additions and 2054 deletions
|
|
@ -1,10 +1,10 @@
|
|||
#include "sequenceedit.h"
|
||||
#include "../settingscache.h"
|
||||
#include <QEvent>
|
||||
#include <QHBoxLayout>
|
||||
#include <QKeyEvent>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QHBoxLayout>
|
||||
#include <QEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <QToolTip>
|
||||
#include <utility>
|
||||
|
||||
|
|
@ -32,14 +32,14 @@ SequenceEdit::SequenceEdit(QString _shorcutName, QWidget *parent) : QWidget(pare
|
|||
defaultButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
|
||||
auto *layout = new QHBoxLayout(this);
|
||||
layout->setContentsMargins(0,0,0,0);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(1);
|
||||
layout->addWidget(lineEdit);
|
||||
layout->addWidget(clearButton);
|
||||
layout->addWidget(defaultButton);
|
||||
|
||||
connect(clearButton,SIGNAL(clicked()),this,SLOT(removeLastShortcut()));
|
||||
connect(defaultButton,SIGNAL(clicked()),this,SLOT(restoreDefault()));
|
||||
connect(clearButton, SIGNAL(clicked()), this, SLOT(removeLastShortcut()));
|
||||
connect(defaultButton, SIGNAL(clicked()), this, SLOT(restoreDefault()));
|
||||
lineEdit->installEventFilter(this);
|
||||
|
||||
lineEdit->setText(settingsCache->shortcuts().getShortcutString(shorcutName));
|
||||
|
|
@ -53,15 +53,11 @@ QString SequenceEdit::getSecuence()
|
|||
void SequenceEdit::removeLastShortcut()
|
||||
{
|
||||
QString secuences = lineEdit->text();
|
||||
if (!secuences.isEmpty())
|
||||
{
|
||||
if (secuences.lastIndexOf(";") > 0)
|
||||
{
|
||||
if (!secuences.isEmpty()) {
|
||||
if (secuences.lastIndexOf(";") > 0) {
|
||||
QString valid = secuences.left(secuences.lastIndexOf(";"));
|
||||
lineEdit->setText(valid);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
lineEdit->clear();
|
||||
}
|
||||
|
||||
|
|
@ -85,18 +81,14 @@ 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) {
|
||||
auto *keyEvent = reinterpret_cast<QKeyEvent *>(event);
|
||||
|
||||
if (event->type() == QEvent::KeyPress && !keyEvent->isAutoRepeat())
|
||||
{
|
||||
if (event->type() == QEvent::KeyPress && !keyEvent->isAutoRepeat()) {
|
||||
processKey(keyEvent);
|
||||
}
|
||||
else if (event->type() == QEvent::KeyRelease && !keyEvent->isAutoRepeat())
|
||||
{
|
||||
} else if (event->type() == QEvent::KeyRelease && !keyEvent->isAutoRepeat()) {
|
||||
finishShortcut();
|
||||
}
|
||||
|
||||
|
|
@ -105,19 +97,17 @@ bool SequenceEdit::eventFilter(QObject *, QEvent * event)
|
|||
return false;
|
||||
}
|
||||
|
||||
void SequenceEdit::processKey(QKeyEvent* e)
|
||||
void SequenceEdit::processKey(QKeyEvent *e)
|
||||
{
|
||||
int key = e->key();
|
||||
if (key != Qt::Key_Control && key != Qt::Key_Shift && key != Qt::Key_Meta && key != Qt::Key_Alt)
|
||||
{
|
||||
if (key != Qt::Key_Control && key != Qt::Key_Shift && key != Qt::Key_Meta && key != Qt::Key_Alt) {
|
||||
valid = true;
|
||||
key |= translateModifiers(e->modifiers(), e->text());
|
||||
}
|
||||
|
||||
keys = key;
|
||||
currentKey++;
|
||||
if (currentKey >= key)
|
||||
{
|
||||
if (currentKey >= key) {
|
||||
finishShortcut();
|
||||
}
|
||||
}
|
||||
|
|
@ -127,26 +117,20 @@ int SequenceEdit::translateModifiers(Qt::KeyboardModifiers state, const QString
|
|||
int result = 0;
|
||||
// The shift modifier only counts when it is not used to type a symbol
|
||||
// that is only reachable using the shift key anyway
|
||||
if ((state & Qt::ShiftModifier) && (text.isEmpty() ||
|
||||
!text.at(0).isPrint() ||
|
||||
text.at(0).isLetterOrNumber() ||
|
||||
text.at(0).isSpace()))
|
||||
{
|
||||
if ((state & Qt::ShiftModifier) &&
|
||||
(text.isEmpty() || !text.at(0).isPrint() || text.at(0).isLetterOrNumber() || text.at(0).isSpace())) {
|
||||
result |= Qt::SHIFT;
|
||||
}
|
||||
|
||||
if (state & Qt::ControlModifier)
|
||||
{
|
||||
if (state & Qt::ControlModifier) {
|
||||
result |= Qt::CTRL;
|
||||
}
|
||||
|
||||
if (state & Qt::MetaModifier)
|
||||
{
|
||||
if (state & Qt::MetaModifier) {
|
||||
result |= Qt::META;
|
||||
}
|
||||
|
||||
if (state & Qt::AltModifier)
|
||||
{
|
||||
if (state & Qt::AltModifier) {
|
||||
result |= Qt::ALT;
|
||||
}
|
||||
|
||||
|
|
@ -156,23 +140,17 @@ int SequenceEdit::translateModifiers(Qt::KeyboardModifiers state, const QString
|
|||
void SequenceEdit::finishShortcut()
|
||||
{
|
||||
QKeySequence secuence(keys);
|
||||
if (!secuence.isEmpty() && valid)
|
||||
{
|
||||
if (!secuence.isEmpty() && valid) {
|
||||
QString secuenceString = secuence.toString();
|
||||
if (settingsCache->shortcuts().isValid(shorcutName,secuenceString))
|
||||
{
|
||||
if (!lineEdit->text().isEmpty())
|
||||
{
|
||||
if (lineEdit->text().contains(secuenceString))
|
||||
{
|
||||
if (settingsCache->shortcuts().isValid(shorcutName, secuenceString)) {
|
||||
if (!lineEdit->text().isEmpty()) {
|
||||
if (lineEdit->text().contains(secuenceString)) {
|
||||
return;
|
||||
}
|
||||
lineEdit->setText(lineEdit->text() + ";");
|
||||
}
|
||||
lineEdit->setText(lineEdit->text() + secuenceString);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
QToolTip::showText(lineEdit->mapToGlobal(QPoint()), tr("Shortcut already in use"));
|
||||
}
|
||||
}
|
||||
|
|
@ -185,5 +163,5 @@ void SequenceEdit::finishShortcut()
|
|||
|
||||
void SequenceEdit::updateSettings()
|
||||
{
|
||||
settingsCache->shortcuts().setShortcuts(shorcutName,lineEdit->text());
|
||||
settingsCache->shortcuts().setShortcuts(shorcutName, lineEdit->text());
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef SECUENCEEDIT_H
|
||||
#define SECUENCEEDIT_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QKeySequence>
|
||||
#include <QWidget>
|
||||
|
||||
class QLineEdit;
|
||||
class QPushButton;
|
||||
|
|
@ -11,32 +11,32 @@ class QEvent;
|
|||
class SequenceEdit : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SequenceEdit(QString _shorcutName, QWidget *parent = nullptr);
|
||||
QString getSecuence();
|
||||
void refreshShortcut();
|
||||
void clear();
|
||||
public:
|
||||
SequenceEdit(QString _shorcutName, QWidget *parent = nullptr);
|
||||
QString getSecuence();
|
||||
void refreshShortcut();
|
||||
void clear();
|
||||
|
||||
private slots:
|
||||
void removeLastShortcut();
|
||||
void restoreDefault();
|
||||
private slots:
|
||||
void removeLastShortcut();
|
||||
void restoreDefault();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *, QEvent *event);
|
||||
protected:
|
||||
bool eventFilter(QObject *, QEvent *event);
|
||||
|
||||
private:
|
||||
QString shorcutName;
|
||||
QLineEdit *lineEdit;
|
||||
QPushButton *clearButton;
|
||||
QPushButton *defaultButton;
|
||||
int keys;
|
||||
int currentKey;
|
||||
bool valid;
|
||||
private:
|
||||
QString shorcutName;
|
||||
QLineEdit *lineEdit;
|
||||
QPushButton *clearButton;
|
||||
QPushButton *defaultButton;
|
||||
int keys;
|
||||
int currentKey;
|
||||
bool valid;
|
||||
|
||||
void processKey(QKeyEvent *e);
|
||||
int translateModifiers(Qt::KeyboardModifiers state, const QString &text);
|
||||
void finishShortcut();
|
||||
void updateSettings();
|
||||
void processKey(QKeyEvent *e);
|
||||
int translateModifiers(Qt::KeyboardModifiers state, const QString &text);
|
||||
void finishShortcut();
|
||||
void updateSettings();
|
||||
};
|
||||
|
||||
#endif // SECUENCEEDIT_H
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@
|
|||
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()));
|
||||
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()
|
||||
|
|
@ -25,36 +25,32 @@ ShortcutsTab::~ShortcutsTab()
|
|||
|
||||
void ShortcutsTab::resetShortcuts()
|
||||
{
|
||||
if (QMessageBox::question(this,tr("Restore all default shortcuts"),
|
||||
tr("Do you really want to restore all default shortcuts?")) == QMessageBox::Yes)
|
||||
{
|
||||
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)
|
||||
{
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
{
|
||||
QList<SequenceEdit *> edits = this->findChildren<SequenceEdit *>();
|
||||
for (auto edit : edits) {
|
||||
edit->clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,25 +7,25 @@
|
|||
|
||||
namespace Ui
|
||||
{
|
||||
class shortcutsTab;
|
||||
class shortcutsTab;
|
||||
}
|
||||
|
||||
class ShortcutsTab : public AbstractSettingsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ShortcutsTab();
|
||||
void retranslateUi();
|
||||
~ShortcutsTab();
|
||||
public:
|
||||
ShortcutsTab();
|
||||
void retranslateUi();
|
||||
~ShortcutsTab();
|
||||
|
||||
private slots:
|
||||
void resetShortcuts();
|
||||
void refreshEdits();
|
||||
void clearShortcuts();
|
||||
void afterClear();
|
||||
private slots:
|
||||
void resetShortcuts();
|
||||
void refreshEdits();
|
||||
void clearShortcuts();
|
||||
void afterClear();
|
||||
|
||||
private:
|
||||
Ui::shortcutsTab *ui;
|
||||
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