mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-17 15:31:20 +00:00
Fix DolphinRemoveAction Shift toggling on Wayland
QGuiApplication::queryKeyboardModifiers() does not work on Wayland [1]. We don't need it in the first place, since we already know (thanks to the key events) whether Shift has been pressed or released. So we can just pass this information to DolphinRemoveAction::update(). BUG: 354301 [1]: https://bugreports.qt.io/browse/QTBUG-62786 Differential Revision: https://phabricator.kde.org/D7519
This commit is contained in:
parent
735b171451
commit
2fd85facf8
|
@ -124,7 +124,7 @@ DolphinContextMenu::Command DolphinContextMenu::open()
|
||||||
void DolphinContextMenu::keyPressEvent(QKeyEvent *ev)
|
void DolphinContextMenu::keyPressEvent(QKeyEvent *ev)
|
||||||
{
|
{
|
||||||
if (m_removeAction && ev->key() == Qt::Key_Shift) {
|
if (m_removeAction && ev->key() == Qt::Key_Shift) {
|
||||||
m_removeAction->update();
|
m_removeAction->update(DolphinRemoveAction::ShiftState::Pressed);
|
||||||
}
|
}
|
||||||
QMenu::keyPressEvent(ev);
|
QMenu::keyPressEvent(ev);
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ void DolphinContextMenu::keyPressEvent(QKeyEvent *ev)
|
||||||
void DolphinContextMenu::keyReleaseEvent(QKeyEvent *ev)
|
void DolphinContextMenu::keyReleaseEvent(QKeyEvent *ev)
|
||||||
{
|
{
|
||||||
if (m_removeAction && ev->key() == Qt::Key_Shift) {
|
if (m_removeAction && ev->key() == Qt::Key_Shift) {
|
||||||
m_removeAction->update();
|
m_removeAction->update(DolphinRemoveAction::ShiftState::Released);
|
||||||
}
|
}
|
||||||
QMenu::keyReleaseEvent(ev);
|
QMenu::keyReleaseEvent(ev);
|
||||||
}
|
}
|
||||||
|
|
|
@ -597,6 +597,7 @@ void DolphinPart::setFilesToSelect(const QList<QUrl>& files)
|
||||||
|
|
||||||
bool DolphinPart::eventFilter(QObject* obj, QEvent* event)
|
bool DolphinPart::eventFilter(QObject* obj, QEvent* event)
|
||||||
{
|
{
|
||||||
|
using ShiftState = DolphinRemoveAction::ShiftState;
|
||||||
const int type = event->type();
|
const int type = event->type();
|
||||||
|
|
||||||
if ((type == QEvent::KeyPress || type == QEvent::KeyRelease) && m_removeAction) {
|
if ((type == QEvent::KeyPress || type == QEvent::KeyRelease) && m_removeAction) {
|
||||||
|
@ -604,7 +605,7 @@ bool DolphinPart::eventFilter(QObject* obj, QEvent* event)
|
||||||
if (menu && menu->parent() == m_view) {
|
if (menu && menu->parent() == m_view) {
|
||||||
QKeyEvent* ev = static_cast<QKeyEvent*>(event);
|
QKeyEvent* ev = static_cast<QKeyEvent*>(event);
|
||||||
if (ev->key() == Qt::Key_Shift) {
|
if (ev->key() == Qt::Key_Shift) {
|
||||||
m_removeAction->update();
|
m_removeAction->update(type == QEvent::KeyPress ? ShiftState::Pressed : ShiftState::Released);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (C) 2013 by Dawit Alemayehu <adawit@kde.org *
|
* Copyright (C) 2013 by Dawit Alemayehu <adawit@kde.org> *
|
||||||
|
* Copyright (C) 2017 by Elvis Angelaccio <elvis.angelaccio@kde.org> *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU General Public License as published by *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
@ -39,13 +40,27 @@ void DolphinRemoveAction::slotRemoveActionTriggered()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DolphinRemoveAction::update()
|
void DolphinRemoveAction::update(ShiftState shiftState)
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_collection);
|
if (!m_collection) {
|
||||||
if (qApp->queryKeyboardModifiers() & Qt::ShiftModifier) {
|
m_action = nullptr;
|
||||||
m_action = m_collection ? m_collection->action(KStandardAction::name(KStandardAction::DeleteFile)) : 0;
|
return;
|
||||||
} else {
|
}
|
||||||
m_action = m_collection ? m_collection->action(KStandardAction::name(KStandardAction::MoveToTrash)) : 0;
|
|
||||||
|
if (shiftState == ShiftState::Unknown) {
|
||||||
|
shiftState = QGuiApplication::keyboardModifiers() & Qt::ShiftModifier ? ShiftState::Pressed : ShiftState::Released;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (shiftState) {
|
||||||
|
case ShiftState::Pressed:
|
||||||
|
m_action = m_collection->action(KStandardAction::name(KStandardAction::DeleteFile));
|
||||||
|
break;
|
||||||
|
case ShiftState::Released:
|
||||||
|
m_action = m_collection->action(KStandardAction::name(KStandardAction::MoveToTrash));
|
||||||
|
break;
|
||||||
|
case ShiftState::Unknown:
|
||||||
|
Q_UNREACHABLE();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_action) {
|
if (m_action) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (C) 2013 by Dawit Alemayehu <adawit@kde.org *
|
* Copyright (C) 2013 by Dawit Alemayehu <adawit@kde.org> *
|
||||||
|
* Copyright (C) 2017 by Elvis Angelaccio <elvis.angelaccio@kde.org> *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU General Public License as published by *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
@ -38,11 +39,20 @@ class DOLPHIN_EXPORT DolphinRemoveAction : public QAction
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
enum class ShiftState {
|
||||||
|
Unknown,
|
||||||
|
Pressed,
|
||||||
|
Released
|
||||||
|
};
|
||||||
|
|
||||||
DolphinRemoveAction(QObject* parent, KActionCollection* collection);
|
DolphinRemoveAction(QObject* parent, KActionCollection* collection);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates this action key based on the state of the Shift key.
|
* Updates this action key based on @p shiftState.
|
||||||
|
* Default value is QueryShiftState, meaning it will query QGuiApplication::modifiers().
|
||||||
*/
|
*/
|
||||||
void update();
|
void update(ShiftState shiftState = ShiftState::Unknown);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void slotRemoveActionTriggered();
|
void slotRemoveActionTriggered();
|
||||||
|
|
Loading…
Reference in a new issue