mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Add keyboard shorcuts to focus and unfocus chat (#3898)
* Added keyboard shorcuts to focus and unfocus chat * Fixed format * Changed the Esc behavior to work on any QLineEdit in the main Window and ignore shortcut conflicts * Fixed a conflict with shortcuts * Configurable unfocus shortcut and format fixes * minor style fix
This commit is contained in:
parent
7285f24a29
commit
63b4f9b2f0
25 changed files with 235 additions and 107 deletions
72
cockatrice/src/customlineedit.cpp
Normal file
72
cockatrice/src/customlineedit.cpp
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
|
||||
#include "customlineedit.h"
|
||||
|
||||
#include "settingscache.h"
|
||||
#include "shortcutssettings.h"
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QLineEdit>
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
|
||||
LineEditUnfocusable::LineEditUnfocusable(QWidget *parent) : QLineEdit(parent)
|
||||
{
|
||||
installEventFilter(this);
|
||||
}
|
||||
|
||||
LineEditUnfocusable::LineEditUnfocusable(const QString &contents, QWidget *parent) : QLineEdit(contents, parent)
|
||||
{
|
||||
installEventFilter(this);
|
||||
}
|
||||
|
||||
bool LineEditUnfocusable::isUnfocusShortcut(QKeyEvent *event)
|
||||
{
|
||||
QString modifier;
|
||||
QString keyNoMod;
|
||||
|
||||
if (event->modifiers() & Qt::ShiftModifier)
|
||||
modifier += "Shift+";
|
||||
if (event->modifiers() & Qt::ControlModifier)
|
||||
modifier += "Ctrl+";
|
||||
if (event->modifiers() & Qt::AltModifier)
|
||||
modifier += "Alt+";
|
||||
if (event->modifiers() & Qt::MetaModifier)
|
||||
modifier += "Meta+";
|
||||
|
||||
keyNoMod = QKeySequence(event->key()).toString();
|
||||
|
||||
QKeySequence key(modifier + keyNoMod);
|
||||
QList<QKeySequence> unfocusShortcut = settingsCache->shortcuts().getShortcut("Textbox/unfocusTextBox");
|
||||
|
||||
for (QList<QKeySequence>::iterator i = unfocusShortcut.begin(); i != unfocusShortcut.end(); ++i) {
|
||||
if (key.matches(*i) == QKeySequence::ExactMatch)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void LineEditUnfocusable::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (isUnfocusShortcut(event)) {
|
||||
clearFocus();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
QLineEdit::keyPressEvent(event);
|
||||
}
|
||||
|
||||
bool LineEditUnfocusable::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::ShortcutOverride) {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
|
||||
if (isUnfocusShortcut(keyEvent)) {
|
||||
event->accept();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return QLineEdit::eventFilter(watched, event);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue