From 5e9027318b1d559d7ca95b3c39e328de65df0cbd Mon Sep 17 00:00:00 2001 From: shun-iwasawa Date: May 30 2023 08:33:27 +0000 Subject: fix text fx input field --- diff --git a/toonz/sources/include/toonzqt/paramfield.h b/toonz/sources/include/toonzqt/paramfield.h index ea0ee85..07acfa0 100644 --- a/toonz/sources/include/toonzqt/paramfield.h +++ b/toonz/sources/include/toonzqt/paramfield.h @@ -613,12 +613,12 @@ namespace component { class MyTextEdit : public QTextEdit { Q_OBJECT public: - MyTextEdit(const QString &text, QWidget *parent = Q_NULLPTR) - : QTextEdit(text, parent) {} + MyTextEdit(const QString &text, QWidget *parent = Q_NULLPTR); protected: void keyPressEvent(QKeyEvent *event) override; void focusOutEvent(QFocusEvent *e) override; + bool eventFilter(QObject *, QEvent *) override; signals: void edited(); diff --git a/toonz/sources/toonzqt/paramfield.cpp b/toonz/sources/toonzqt/paramfield.cpp index f119c45..292e9b9 100644 --- a/toonz/sources/toonzqt/paramfield.cpp +++ b/toonz/sources/toonzqt/paramfield.cpp @@ -9,6 +9,7 @@ #include "toonzqt/doublepairfield.h" #include "toonzqt/tonecurvefield.h" #include "toonzqt/checkbox.h" +#include "toonzqt/menubarcommand.h" #include "tdoubleparam.h" #include "tnotanimatableparam.h" @@ -1563,6 +1564,11 @@ void IntParamField::update(int frame) { namespace component { +MyTextEdit::MyTextEdit(const QString &text, QWidget *parent) + : QTextEdit(text, parent) { + installEventFilter(this); +} + void MyTextEdit::keyPressEvent(QKeyEvent *event) { QTextEdit::keyPressEvent(event); if (event->key() == Qt::Key_Return) emit edited(); @@ -1572,6 +1578,26 @@ void MyTextEdit::focusOutEvent(QFocusEvent *event) { QTextEdit::focusOutEvent(event); emit edited(); } + +bool MyTextEdit::eventFilter(QObject *obj, QEvent *e) { + if (e->type() != QEvent::ShortcutOverride) + return QTextEdit::eventFilter(obj, e); + + QKeyEvent *ke = (QKeyEvent *)e; + std::string keyStr = + QKeySequence(ke->key() + ke->modifiers()).toString().toStdString(); + QAction *action = CommandManager::instance()->getActionFromShortcut(keyStr); + if (!action) return QTextEdit::eventFilter(obj, e); + + std::string actionId = CommandManager::instance()->getIdFromAction(action); + if (actionId == "MI_Undo" || actionId == "MI_Redo" || + actionId == "MI_Clear" || actionId == "MI_Copy" || + actionId == "MI_Paste" || actionId == "MI_Cut") + return QTextEdit::eventFilter(obj, e); + + return true; +} + }; // namespace component StringParamField::StringParamField(QWidget *parent, QString name,