mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-11-25 09:13:16 -05:00
Prevent mouse wheel scroll on entry edit username field (#12398)
* Reported by shawnkhu via Matrix, thank you!
This commit is contained in:
parent
544f983bad
commit
606cf37952
4 changed files with 32 additions and 22 deletions
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#include "autotype/AutoType.h"
|
#include "autotype/AutoType.h"
|
||||||
#include "core/Translator.h"
|
#include "core/Translator.h"
|
||||||
|
#include "gui/GuiTools.h"
|
||||||
#include "gui/Icons.h"
|
#include "gui/Icons.h"
|
||||||
#include "gui/MainWindow.h"
|
#include "gui/MainWindow.h"
|
||||||
#include "gui/osutils/OSUtils.h"
|
#include "gui/osutils/OSUtils.h"
|
||||||
|
|
@ -62,28 +63,6 @@ private:
|
||||||
QWidget* widget;
|
QWidget* widget;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper class to ignore mouse wheel events on non-focused widgets
|
|
||||||
* NOTE: The widget must NOT have a focus policy of "WHEEL"
|
|
||||||
*/
|
|
||||||
class MouseWheelEventFilter : public QObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit MouseWheelEventFilter(QObject* parent)
|
|
||||||
: QObject(parent){};
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool eventFilter(QObject* obj, QEvent* event) override
|
|
||||||
{
|
|
||||||
const auto* widget = qobject_cast<QWidget*>(obj);
|
|
||||||
if (event->type() == QEvent::Wheel && widget && !widget->hasFocus()) {
|
|
||||||
event->ignore();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return QObject::eventFilter(obj, event);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ApplicationSettingsWidget::ApplicationSettingsWidget(QWidget* parent)
|
ApplicationSettingsWidget::ApplicationSettingsWidget(QWidget* parent)
|
||||||
: EditWidget(parent)
|
: EditWidget(parent)
|
||||||
, m_secWidget(new QWidget())
|
, m_secWidget(new QWidget())
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
#ifndef KEEPASSXC_GUITOOLS_H
|
#ifndef KEEPASSXC_GUITOOLS_H
|
||||||
#define KEEPASSXC_GUITOOLS_H
|
#define KEEPASSXC_GUITOOLS_H
|
||||||
|
|
||||||
|
#include <QEvent>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
|
@ -29,4 +30,27 @@ namespace GuiTools
|
||||||
bool confirmDeletePluginData(QWidget* parent, const QList<Entry*>& entries);
|
bool confirmDeletePluginData(QWidget* parent, const QList<Entry*>& entries);
|
||||||
size_t deleteEntriesResolveReferences(QWidget* parent, const QList<Entry*>& entries, bool permanent);
|
size_t deleteEntriesResolveReferences(QWidget* parent, const QList<Entry*>& entries, bool permanent);
|
||||||
} // namespace GuiTools
|
} // namespace GuiTools
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class to ignore mouse wheel events on non-focused widgets
|
||||||
|
* NOTE: The widget must NOT have a focus policy of "WHEEL"
|
||||||
|
*/
|
||||||
|
class MouseWheelEventFilter : public QObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit MouseWheelEventFilter(QObject* parent)
|
||||||
|
: QObject(parent){};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool eventFilter(QObject* obj, QEvent* event) override
|
||||||
|
{
|
||||||
|
const auto* widget = qobject_cast<QWidget*>(obj);
|
||||||
|
if (event->type() == QEvent::Wheel && widget && !widget->hasFocus()) {
|
||||||
|
event->ignore();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return QObject::eventFilter(obj, event);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#endif // KEEPASSXC_GUITOOLS_H
|
#endif // KEEPASSXC_GUITOOLS_H
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@
|
||||||
#include "gui/EditWidgetProperties.h"
|
#include "gui/EditWidgetProperties.h"
|
||||||
#include "gui/FileDialog.h"
|
#include "gui/FileDialog.h"
|
||||||
#include "gui/Font.h"
|
#include "gui/Font.h"
|
||||||
|
#include "gui/GuiTools.h"
|
||||||
#include "gui/Icons.h"
|
#include "gui/Icons.h"
|
||||||
#include "gui/MessageBox.h"
|
#include "gui/MessageBox.h"
|
||||||
#include "gui/entry/AutoTypeAssociationsModel.h"
|
#include "gui/entry/AutoTypeAssociationsModel.h"
|
||||||
|
|
@ -185,7 +186,10 @@ void EditEntryWidget::setupMain()
|
||||||
m_mainUi->setupUi(m_mainWidget);
|
m_mainUi->setupUi(m_mainWidget);
|
||||||
addPage(tr("Entry"), icons()->icon("document-edit"), m_mainWidget);
|
addPage(tr("Entry"), icons()->icon("document-edit"), m_mainWidget);
|
||||||
|
|
||||||
|
// Disable mouse wheel grab when scrolling
|
||||||
|
m_mainUi->usernameComboBox->installEventFilter(new MouseWheelEventFilter(this));
|
||||||
m_mainUi->usernameComboBox->setEditable(true);
|
m_mainUi->usernameComboBox->setEditable(true);
|
||||||
|
m_mainUi->usernameComboBox->lineEdit()->setFocusPolicy(Qt::StrongFocus);
|
||||||
m_usernameCompleter->setCompletionMode(QCompleter::InlineCompletion);
|
m_usernameCompleter->setCompletionMode(QCompleter::InlineCompletion);
|
||||||
m_usernameCompleter->setCaseSensitivity(Qt::CaseSensitive);
|
m_usernameCompleter->setCaseSensitivity(Qt::CaseSensitive);
|
||||||
m_usernameCompleter->setModel(m_usernameCompleterModel);
|
m_usernameCompleter->setModel(m_usernameCompleterModel);
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,9 @@
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QComboBox" name="usernameComboBox">
|
<widget class="QComboBox" name="usernameComboBox">
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::StrongFocus</enum>
|
||||||
|
</property>
|
||||||
<property name="accessibleName">
|
<property name="accessibleName">
|
||||||
<string>Username field</string>
|
<string>Username field</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue