mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-13 01:24:46 -07:00
Add No annotations export option w/ shortcut (#3013)
This commit is contained in:
parent
5757d60b1d
commit
ebec30dd1c
11 changed files with 1777 additions and 1662 deletions
|
|
@ -6,12 +6,12 @@
|
|||
#include <QEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <QToolTip>
|
||||
#include <utility>
|
||||
|
||||
SequenceEdit::SequenceEdit(QString _shorcutName, QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
shorcutName = _shorcutName;
|
||||
shorcutName = std::move(_shorcutName);
|
||||
currentKey = 0;
|
||||
maxKeys = 4;
|
||||
keys = 0;
|
||||
valid = false;
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ SequenceEdit::SequenceEdit(QString _shorcutName, QWidget *parent) : QWidget(pare
|
|||
clearButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
defaultButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||
auto *layout = new QHBoxLayout(this);
|
||||
layout->setContentsMargins(0,0,0,0);
|
||||
layout->setSpacing(1);
|
||||
layout->addWidget(lineEdit);
|
||||
|
|
@ -53,14 +53,18 @@ QString SequenceEdit::getSecuence()
|
|||
void SequenceEdit::removeLastShortcut()
|
||||
{
|
||||
QString secuences = lineEdit->text();
|
||||
if(!secuences.isEmpty())
|
||||
if (!secuences.isEmpty())
|
||||
{
|
||||
if(secuences.lastIndexOf(";") > 0){
|
||||
if (secuences.lastIndexOf(";") > 0)
|
||||
{
|
||||
QString valid = secuences.left(secuences.lastIndexOf(";"));
|
||||
lineEdit->setText(valid);
|
||||
}
|
||||
else
|
||||
{
|
||||
lineEdit->clear();
|
||||
}
|
||||
|
||||
updateSettings();
|
||||
}
|
||||
}
|
||||
|
|
@ -83,14 +87,19 @@ void SequenceEdit::clear()
|
|||
|
||||
bool SequenceEdit::eventFilter(QObject *, QEvent * event)
|
||||
{
|
||||
if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease)
|
||||
if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease)
|
||||
{
|
||||
QKeyEvent * keyEvent = (QKeyEvent *) event;
|
||||
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())
|
||||
{
|
||||
finishShortcut();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -99,16 +108,18 @@ bool SequenceEdit::eventFilter(QObject *, QEvent * event)
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
||||
int SequenceEdit::translateModifiers(Qt::KeyboardModifiers state, const QString &text)
|
||||
|
|
@ -120,29 +131,42 @@ int SequenceEdit::translateModifiers(Qt::KeyboardModifiers state, const QString
|
|||
!text.at(0).isPrint() ||
|
||||
text.at(0).isLetterOrNumber() ||
|
||||
text.at(0).isSpace()))
|
||||
{
|
||||
result |= Qt::SHIFT;
|
||||
}
|
||||
|
||||
if (state & Qt::ControlModifier)
|
||||
{
|
||||
result |= Qt::CTRL;
|
||||
}
|
||||
|
||||
if (state & Qt::MetaModifier)
|
||||
{
|
||||
result |= Qt::META;
|
||||
}
|
||||
|
||||
if (state & Qt::AltModifier)
|
||||
{
|
||||
result |= Qt::ALT;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
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 (settingsCache->shortcuts().isValid(shorcutName,secuenceString))
|
||||
{
|
||||
if(!lineEdit->text().isEmpty())
|
||||
if (!lineEdit->text().isEmpty())
|
||||
{
|
||||
if(lineEdit->text().contains(secuenceString))
|
||||
if (lineEdit->text().contains(secuenceString))
|
||||
{
|
||||
return;
|
||||
}
|
||||
lineEdit->setText(lineEdit->text() + ";");
|
||||
}
|
||||
lineEdit->setText(lineEdit->text() + secuenceString);
|
||||
|
|
@ -152,6 +176,7 @@ void SequenceEdit::finishShortcut()
|
|||
QToolTip::showText(lineEdit->mapToGlobal(QPoint()), tr("Shortcut already in use"));
|
||||
}
|
||||
}
|
||||
|
||||
currentKey = 0;
|
||||
keys = 0;
|
||||
valid = false;
|
||||
|
|
@ -161,5 +186,4 @@ void SequenceEdit::finishShortcut()
|
|||
void SequenceEdit::updateSettings()
|
||||
{
|
||||
settingsCache->shortcuts().setShortcuts(shorcutName,lineEdit->text());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -11,33 +11,32 @@ class QEvent;
|
|||
class SequenceEdit : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SequenceEdit(QString _shorcutName, QWidget *parent = 0);
|
||||
QString getSecuence();
|
||||
void refreshShortcut();
|
||||
void clear();
|
||||
signals:
|
||||
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);
|
||||
private:
|
||||
QString shorcutName;
|
||||
QLineEdit *lineEdit;
|
||||
QPushButton *clearButton;
|
||||
QPushButton *defaultButton;
|
||||
int keys;
|
||||
int currentKey;
|
||||
int maxKeys;
|
||||
bool valid;
|
||||
protected:
|
||||
bool eventFilter(QObject *, QEvent *event);
|
||||
|
||||
void processKey(QKeyEvent *e);
|
||||
int translateModifiers(Qt::KeyboardModifiers state, const QString &text);
|
||||
void finishShortcut();
|
||||
void updateSettings();
|
||||
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();
|
||||
};
|
||||
|
||||
#endif // SECUENCEEDIT_H
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
#include "../settingscache.h"
|
||||
#include <QMessageBox>
|
||||
|
||||
ShortcutsTab::ShortcutsTab() :
|
||||
ui(new Ui::shortcutsTab)
|
||||
ShortcutsTab::ShortcutsTab() : ui(new Ui::shortcutsTab)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->btnResetAll,SIGNAL(clicked()),this,SLOT(resetShortcuts()));
|
||||
|
|
@ -26,7 +25,7 @@ ShortcutsTab::~ShortcutsTab()
|
|||
|
||||
void ShortcutsTab::resetShortcuts()
|
||||
{
|
||||
if(QMessageBox::question(this,tr("Restore all default shortcuts"),
|
||||
if (QMessageBox::question(this,tr("Restore all default shortcuts"),
|
||||
tr("Do you really want to restore all default shortcuts?")) == QMessageBox::Yes)
|
||||
{
|
||||
settingsCache->shortcuts().resetAllShortcuts();
|
||||
|
|
@ -36,15 +35,15 @@ void ShortcutsTab::resetShortcuts()
|
|||
void ShortcutsTab::refreshEdits()
|
||||
{
|
||||
QList<SequenceEdit*> edits = this->findChildren<SequenceEdit*>();
|
||||
for(int i= 0; i < edits.length(); ++i)
|
||||
for (auto edit : edits)
|
||||
{
|
||||
edits.at(i)->refreshShortcut();
|
||||
edit->refreshShortcut();
|
||||
}
|
||||
}
|
||||
|
||||
void ShortcutsTab::clearShortcuts()
|
||||
{
|
||||
if(QMessageBox::question(this,tr("Clear all default shortcuts"),
|
||||
if (QMessageBox::question(this,tr("Clear all default shortcuts"),
|
||||
tr("Do you really want to clear all shortcuts?")) == QMessageBox::Yes)
|
||||
{
|
||||
settingsCache->shortcuts().clearAllShortcuts();
|
||||
|
|
@ -54,8 +53,8 @@ void ShortcutsTab::clearShortcuts()
|
|||
void ShortcutsTab::afterClear()
|
||||
{
|
||||
QList<SequenceEdit*> edits = this->findChildren<SequenceEdit*>();
|
||||
for(int i= 0; i < edits.length(); ++i)
|
||||
for (auto edit : edits)
|
||||
{
|
||||
edits.at(i)->clear();
|
||||
edit->clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,25 +5,27 @@
|
|||
|
||||
#include "../dlg_settings.h"
|
||||
|
||||
namespace Ui {
|
||||
class shortcutsTab;
|
||||
namespace Ui
|
||||
{
|
||||
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:
|
||||
Ui::shortcutsTab *ui;
|
||||
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