Adapt to key sequence changes in Qt6

Use operator| instead of operator+ which was removed.
Individual keys in QKeySequence are now QKeyCombinations instead of
ints.

Task-number: QTCREATORBUG-24098
Change-Id: I43a6122cf660e6a6de7edbf3ac9954e0a39cec06
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Eike Ziller
2020-09-28 16:23:15 +02:00
parent 5722ab8706
commit 47955ed4fa
6 changed files with 24 additions and 16 deletions

View File

@@ -1008,8 +1008,8 @@ void ObjectItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
menu.addSeparator(); menu.addSeparator();
menu.addAction(new ContextMenuAction(tr("Remove"), "remove", menu.addAction(new ContextMenuAction(tr("Remove"), "remove",
QKeySequence(QKeySequence::Delete), &menu)); QKeySequence(QKeySequence::Delete), &menu));
menu.addAction(new ContextMenuAction(tr("Delete"), "delete", menu.addAction(
QKeySequence(Qt::CTRL + Qt::Key_D), &menu)); new ContextMenuAction(tr("Delete"), "delete", QKeySequence(Qt::CTRL | Qt::Key_D), &menu));
//menu.addAction(new ContextMenuAction(tr("Select in Model Tree"), "selectInModelTree", &menu)); //menu.addAction(new ContextMenuAction(tr("Select in Model Tree"), "selectInModelTree", &menu));
QMenu alignMenu; QMenu alignMenu;
alignMenu.setTitle(tr("Align Objects")); alignMenu.setTitle(tr("Align Objects"));

View File

@@ -260,8 +260,10 @@ void ModelTreeView::contextMenuEvent(QContextMenuEvent *event)
if (melement->owner()) { if (melement->owner()) {
if (addSeparator) if (addSeparator)
menu.addSeparator(); menu.addSeparator();
menu.addAction(new ContextMenuAction(tr("Delete"), "delete", menu.addAction(new ContextMenuAction(tr("Delete"),
QKeySequence(Qt::CTRL + Qt::Key_D), &menu)); "delete",
QKeySequence(Qt::CTRL | Qt::Key_D),
&menu));
} }
QAction *selectedAction = menu.exec(event->globalPos()); QAction *selectedAction = menu.exec(event->globalPos());
if (selectedAction) { if (selectedAction) {

View File

@@ -117,12 +117,18 @@ static QKeySequence keySequenceFromEditString(const QString &editString)
return QKeySequence::fromString(text, QKeySequence::PortableText); return QKeySequence::fromString(text, QKeySequence::PortableText);
} }
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
using KeyCombination = int;
#else
using KeyCombination = QKeyCombination;
#endif
static bool keySequenceIsValid(const QKeySequence &sequence) static bool keySequenceIsValid(const QKeySequence &sequence)
{ {
if (sequence.isEmpty()) if (sequence.isEmpty())
return false; return false;
for (int i = 0; i < sequence.count(); ++i) { for (int i = 0; i < sequence.count(); ++i) {
if (sequence[i] == Qt::Key_unknown) if (sequence[i] == KeyCombination(Qt::Key_unknown))
return false; return false;
} }
return true; return true;

View File

@@ -175,7 +175,7 @@ FormEditorWidget::FormEditorWidget(FormEditorView *view) :
28, 28, textColorNormal); 28, 28, textColorNormal);
m_zoomInAction = new QAction(zoomInIcon, tr("Zoom in"), this); m_zoomInAction = new QAction(zoomInIcon, tr("Zoom in"), this);
m_zoomInAction->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Plus)); m_zoomInAction->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Plus));
connect(m_zoomInAction.data(), &QAction::triggered, this, [this] { connect(m_zoomInAction.data(), &QAction::triggered, this, [this] {
if (!m_formEditorView) if (!m_formEditorView)
return; return;
@@ -187,7 +187,7 @@ FormEditorWidget::FormEditorWidget(FormEditorView *view) :
m_toolBox->addRightSideAction(m_zoomInAction.data()); m_toolBox->addRightSideAction(m_zoomInAction.data());
m_zoomOutAction = new QAction(zoomOutIcon, tr("Zoom out"), this); m_zoomOutAction = new QAction(zoomOutIcon, tr("Zoom out"), this);
m_zoomOutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Minus)); m_zoomOutAction->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Minus));
connect(m_zoomOutAction.data(), &QAction::triggered, this, [this] { connect(m_zoomOutAction.data(), &QAction::triggered, this, [this] {
if (!m_formEditorView) if (!m_formEditorView)
return; return;
@@ -206,7 +206,7 @@ FormEditorWidget::FormEditorWidget(FormEditorView *view) :
m_toolBox->addRightSideAction(m_zoomAction.data()); m_toolBox->addRightSideAction(m_zoomAction.data());
m_zoomAllAction = new QAction(zoomAllIcon, tr("Zoom screen to fit all content"), this); m_zoomAllAction = new QAction(zoomAllIcon, tr("Zoom screen to fit all content"), this);
m_zoomAllAction->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_0)); m_zoomAllAction->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_0));
connect(m_zoomAllAction.data(), &QAction::triggered, this, [this] { connect(m_zoomAllAction.data(), &QAction::triggered, this, [this] {
if (!m_formEditorView) if (!m_formEditorView)
return; return;
@@ -218,7 +218,7 @@ FormEditorWidget::FormEditorWidget(FormEditorView *view) :
m_toolBox->addRightSideAction(m_zoomAllAction.data()); m_toolBox->addRightSideAction(m_zoomAllAction.data());
m_zoomSelectionAction = new QAction(zoomSelectionIcon, tr("Zoom screen to fit current selection"), this); m_zoomSelectionAction = new QAction(zoomSelectionIcon, tr("Zoom screen to fit current selection"), this);
m_zoomSelectionAction->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_I)); m_zoomSelectionAction->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_I));
connect(m_zoomSelectionAction.data(), &QAction::triggered, this, [this] { connect(m_zoomSelectionAction.data(), &QAction::triggered, this, [this] {
if (!m_formEditorView) if (!m_formEditorView)
return; return;

View File

@@ -185,11 +185,11 @@ bool TextEditorWidget::eventFilter( QObject *, QEvent *event)
static std::vector<QKeySequence> overrideSequences = { QKeySequence::SelectAll, QKeySequence::Cut, static std::vector<QKeySequence> overrideSequences = { QKeySequence::SelectAll, QKeySequence::Cut,
QKeySequence::Copy, QKeySequence::Delete, QKeySequence::Copy, QKeySequence::Delete,
QKeySequence::Paste, QKeySequence::Undo, QKeySequence::Paste, QKeySequence::Undo,
QKeySequence::Redo, QKeySequence(Qt::CTRL + Qt::ALT), QKeySequence::Redo, QKeySequence(Qt::CTRL | Qt::ALT),
QKeySequence(Qt::Key_Left + Qt::CTRL), QKeySequence(Qt::Key_Left | Qt::CTRL),
QKeySequence(Qt::Key_Right + Qt::CTRL), QKeySequence(Qt::Key_Right | Qt::CTRL),
QKeySequence(Qt::Key_Up + Qt::CTRL), QKeySequence(Qt::Key_Up | Qt::CTRL),
QKeySequence(Qt::Key_Down + Qt::CTRL) QKeySequence(Qt::Key_Down | Qt::CTRL)
}; };
if (event->type() == QEvent::ShortcutOverride) { if (event->type() == QEvent::ShortcutOverride) {
auto keyEvent = static_cast<QKeyEvent *>(event); auto keyEvent = static_cast<QKeyEvent *>(event);

View File

@@ -191,8 +191,8 @@ QmlJSEditorPluginPrivate::QmlJSEditorPluginPrivate()
QAction *showQuickToolbar = new QAction(QmlJSEditorPlugin::tr("Show Qt Quick Toolbar"), this); QAction *showQuickToolbar = new QAction(QmlJSEditorPlugin::tr("Show Qt Quick Toolbar"), this);
cmd = ActionManager::registerAction(showQuickToolbar, Constants::SHOW_QT_QUICK_HELPER, context); cmd = ActionManager::registerAction(showQuickToolbar, Constants::SHOW_QT_QUICK_HELPER, context);
cmd->setDefaultKeySequence(useMacShortcuts ? QKeySequence(Qt::META + Qt::ALT + Qt::Key_Space) cmd->setDefaultKeySequence(useMacShortcuts ? QKeySequence(Qt::META | Qt::ALT | Qt::Key_Space)
: QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Space)); : QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Space));
connect(showQuickToolbar, &QAction::triggered, this, &QmlJSEditorPluginPrivate::showContextPane); connect(showQuickToolbar, &QAction::triggered, this, &QmlJSEditorPluginPrivate::showContextPane);
contextMenu->addAction(cmd); contextMenu->addAction(cmd);
qmlToolsMenu->addAction(cmd); qmlToolsMenu->addAction(cmd);