Fix Stage Schematic Column (Right click) now w/Context (Qt 5.9 fix)

This commit is contained in:
manongjohn 2022-03-12 01:44:44 -05:00
parent 3f8d7b288d
commit 6e334e02f5
2 changed files with 23 additions and 2 deletions

View file

@ -43,19 +43,23 @@ protected:
void focusOutEvent(QFocusEvent *fe) override;
void keyPressEvent(QKeyEvent *ke) override;
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
void contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) override;
#endif
signals:
void focusOut();
protected slots:
void onContentsChanged();
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
void onPopupHide();
void onCut();
void onCopy();
void onPaste();
void onDelete();
void onSelectAll();
#endif
};
//========================================================

View file

@ -20,11 +20,13 @@
#include "toonzqt/menubarcommand.h"
#include "toonzqt/gutil.h"
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
#define ACCEL_KEY(k) \
(!QCoreApplication::testAttribute(Qt::AA_DontShowShortcutsInContextMenus) \
? QLatin1Char('\t') + \
QKeySequence(k).toString(QKeySequence::NativeText) \
: QString())
#endif
//========================================================
//
@ -43,6 +45,7 @@ SchematicName::SchematicName(QGraphicsItem *parent, double width, double height)
setFlag(QGraphicsItem::ItemIsFocusable, true);
setTextInteractionFlags(Qt::TextEditorInteraction);
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
popup = new QMenu();
popup->setObjectName(QLatin1String("qt_edit_menu"));
@ -69,14 +72,20 @@ SchematicName::SchematicName(QGraphicsItem *parent, double width, double height)
this, SLOT(onSelectAll()));
actionSelectAll->setObjectName(QStringLiteral("select-all"));
connect(popup, SIGNAL(aboutToHide()), this, SLOT(onPopupHide()));
#endif
connect(document(), SIGNAL(contentsChanged()), this,
SLOT(onContentsChanged()));
connect(popup, SIGNAL(aboutToHide()), this, SLOT(onPopupHide()));
}
//--------------------------------------------------------
SchematicName::~SchematicName() { delete popup; }
SchematicName::~SchematicName() {
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
delete popup;
#endif
}
//--------------------------------------------------------
@ -154,6 +163,7 @@ bool SchematicName::eventFilter(QObject *object, QEvent *event) {
void SchematicName::focusInEvent(QFocusEvent *fe) {
QGraphicsTextItem::focusInEvent(fe);
qApp->installEventFilter(this);
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
if (!m_refocus) {
QTextDocument *doc = document();
QTextCursor cursor(doc->begin());
@ -161,10 +171,16 @@ void SchematicName::focusInEvent(QFocusEvent *fe) {
setTextCursor(cursor);
m_curName = toPlainText();
}
#else
QTextDocument *doc = document();
QTextCursor cursor(doc->begin());
cursor.select(QTextCursor::Document);
#endif
}
//--------------------------------------------------------
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
void SchematicName::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
QClipboard *clipboard = QApplication::clipboard();
QTextCursor cursor = textCursor();
@ -269,6 +285,7 @@ void SchematicName::onSelectAll() {
cursor.select(QTextCursor::Document);
setTextCursor(cursor);
}
#endif
//========================================================
//