mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
[MouseGestures] Configurable mouse gesture button
UI changes: * the Settings dialog offers a combo box to select left and right mouse buttons, or disable the gestures completely * changes are permanently saved * OK button is added Closes #386 Closes #1280 It is now also possible to enable/disable rocker navigation. Closes #1234
This commit is contained in:
parent
f69c8645fb
commit
3360f17735
@ -29,14 +29,28 @@
|
||||
#include <QMouseEvent>
|
||||
#include <QWebFrame>
|
||||
#include <QWebHistory>
|
||||
#include <QSettings>
|
||||
|
||||
MouseGestures::MouseGestures(QObject* parent)
|
||||
MouseGestures::MouseGestures(const QString &settingsPath, QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_filter(0)
|
||||
, m_settingsFile(settingsPath + QL1S("/extensions.ini"))
|
||||
, m_button(Qt::MiddleButton)
|
||||
, m_enableRockerNavigation(false)
|
||||
, m_blockNextRightMouseRelease(false)
|
||||
, m_blockNextLeftMouseRelease(false)
|
||||
, m_enableRockerNavigation(false)
|
||||
{
|
||||
m_filter = new QjtMouseGestureFilter(false, Qt::MiddleButton, 20);
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
void MouseGestures::initFilter()
|
||||
{
|
||||
if (m_filter) {
|
||||
m_filter->clearGestures(true);
|
||||
delete m_filter;
|
||||
}
|
||||
|
||||
m_filter = new QjtMouseGestureFilter(false, m_button, 20);
|
||||
|
||||
QjtMouseGesture* upGesture = new QjtMouseGesture(DirectionList() << Up, m_filter);
|
||||
connect(upGesture, SIGNAL(gestured()), this, SLOT(upGestured()));
|
||||
@ -142,7 +156,7 @@ bool MouseGestures::mouseMove(QObject* obj, QMouseEvent* event)
|
||||
void MouseGestures::showSettings(QWidget* parent)
|
||||
{
|
||||
if (!m_settings) {
|
||||
m_settings = new MouseGesturesSettingsDialog(parent);
|
||||
m_settings = new MouseGesturesSettingsDialog(this, parent);
|
||||
}
|
||||
|
||||
m_settings.data()->show();
|
||||
@ -257,6 +271,90 @@ void MouseGestures::upRightGestured()
|
||||
}
|
||||
}
|
||||
|
||||
void MouseGestures::init()
|
||||
{
|
||||
initFilter();
|
||||
|
||||
// We need to override right mouse button events
|
||||
WebView::setForceContextMenuOnMouseRelease(m_button == Qt::RightButton || m_enableRockerNavigation);
|
||||
}
|
||||
|
||||
void MouseGestures::setGestureButton(Qt::MouseButton button)
|
||||
{
|
||||
m_button = button;
|
||||
init();
|
||||
}
|
||||
|
||||
void MouseGestures::setGestureButtonByIndex(int index)
|
||||
{
|
||||
switch (index) {
|
||||
case 0:
|
||||
m_button = Qt::MiddleButton;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
m_button = Qt::RightButton;
|
||||
break;
|
||||
|
||||
default:
|
||||
m_button = Qt::NoButton;
|
||||
}
|
||||
|
||||
setGestureButton(m_button);
|
||||
}
|
||||
|
||||
Qt::MouseButton MouseGestures::gestureButton() const
|
||||
{
|
||||
return m_button;
|
||||
}
|
||||
|
||||
int MouseGestures::buttonToIndex() const
|
||||
{
|
||||
switch (m_button) {
|
||||
case Qt::MiddleButton:
|
||||
return 0;
|
||||
|
||||
case Qt::RightButton:
|
||||
return 1;
|
||||
|
||||
default:
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
bool MouseGestures::rockerNavigationEnabled() const
|
||||
{
|
||||
return m_enableRockerNavigation;
|
||||
}
|
||||
|
||||
void MouseGestures::setRockerNavigationEnabled(bool enable)
|
||||
{
|
||||
m_enableRockerNavigation = enable;
|
||||
init();
|
||||
}
|
||||
|
||||
void MouseGestures::loadSettings()
|
||||
{
|
||||
QSettings settings(m_settingsFile, QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup("MouseGestures");
|
||||
setGestureButtonByIndex(settings.value("Button", 0).toInt());
|
||||
m_enableRockerNavigation = settings.value("RockerNavigation", true).toBool();
|
||||
settings.endGroup();
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
void MouseGestures::saveSettings()
|
||||
{
|
||||
QSettings settings(m_settingsFile, QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup("MouseGestures");
|
||||
settings.setValue("Button", buttonToIndex());
|
||||
settings.setValue("RockerNavigation", m_enableRockerNavigation);
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
MouseGestures::~MouseGestures()
|
||||
{
|
||||
m_filter->clearGestures(true);
|
||||
|
@ -31,7 +31,7 @@ class MouseGestures : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MouseGestures(QObject* parent = 0);
|
||||
explicit MouseGestures(const QString &settingsPath, QObject* parent = 0);
|
||||
~MouseGestures();
|
||||
|
||||
bool mousePress(QObject* obj, QMouseEvent* event);
|
||||
@ -41,6 +41,17 @@ public:
|
||||
void showSettings(QWidget* parent);
|
||||
void unloadPlugin();
|
||||
|
||||
Qt::MouseButton gestureButton() const;
|
||||
void setGestureButton(Qt::MouseButton button);
|
||||
void setGestureButtonByIndex(int index);
|
||||
int buttonToIndex() const;
|
||||
|
||||
bool rockerNavigationEnabled() const;
|
||||
void setRockerNavigationEnabled(bool enable);
|
||||
|
||||
void loadSettings();
|
||||
void saveSettings();
|
||||
|
||||
private slots:
|
||||
void upGestured();
|
||||
void downGestured();
|
||||
@ -55,13 +66,19 @@ private slots:
|
||||
void upRightGestured();
|
||||
|
||||
private:
|
||||
void init();
|
||||
void initFilter();
|
||||
|
||||
QjtMouseGestureFilter* m_filter;
|
||||
QPointer<MouseGesturesSettingsDialog> m_settings;
|
||||
QPointer<WebView> m_view;
|
||||
|
||||
QString m_settingsFile;
|
||||
Qt::MouseButton m_button;
|
||||
bool m_enableRockerNavigation;
|
||||
|
||||
bool m_blockNextRightMouseRelease;
|
||||
bool m_blockNextLeftMouseRelease;
|
||||
|
||||
bool m_enableRockerNavigation;
|
||||
};
|
||||
|
||||
#endif // MOUSEGESTURES_H
|
||||
|
@ -46,9 +46,8 @@ PluginSpec MouseGesturesPlugin::pluginSpec()
|
||||
void MouseGesturesPlugin::init(InitState state, const QString &settingsPath)
|
||||
{
|
||||
Q_UNUSED(state)
|
||||
Q_UNUSED(settingsPath)
|
||||
|
||||
m_gestures = new MouseGestures(this);
|
||||
m_gestures = new MouseGestures(settingsPath, this);
|
||||
|
||||
QZ_REGISTER_EVENT_HANDLER(PluginProxy::MousePressHandler);
|
||||
QZ_REGISTER_EVENT_HANDLER(PluginProxy::MouseReleaseHandler);
|
||||
|
@ -18,12 +18,14 @@
|
||||
#include "mousegesturessettingsdialog.h"
|
||||
#include "ui_mousegesturessettingsdialog.h"
|
||||
#include "licenseviewer.h"
|
||||
#include "mousegestures.h"
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
MouseGesturesSettingsDialog::MouseGesturesSettingsDialog(QWidget* parent)
|
||||
MouseGesturesSettingsDialog::MouseGesturesSettingsDialog(MouseGestures* gestures, QWidget* parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::MouseGesturesSettingsDialog)
|
||||
, m_gestures(gestures)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
ui->setupUi(this);
|
||||
@ -35,8 +37,14 @@ MouseGesturesSettingsDialog::MouseGesturesSettingsDialog(QWidget* parent)
|
||||
ui->label_20->setPixmap(QPixmap(":/mousegestures/data/up-left.gif"));
|
||||
}
|
||||
|
||||
m_gestures->loadSettings();
|
||||
ui->mouseButtonComboBox->setCurrentIndex(m_gestures->buttonToIndex());
|
||||
ui->enableRockerNavigation->setChecked(m_gestures->rockerNavigationEnabled());
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accepted()));
|
||||
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(close()));
|
||||
connect(ui->licenseButton, SIGNAL(clicked()), this, SLOT(showLicense()));
|
||||
}
|
||||
|
||||
@ -52,3 +60,11 @@ void MouseGesturesSettingsDialog::showLicense()
|
||||
|
||||
v->show();
|
||||
}
|
||||
|
||||
void MouseGesturesSettingsDialog::accepted()
|
||||
{
|
||||
m_gestures->setGestureButtonByIndex(ui->mouseButtonComboBox->currentIndex());
|
||||
m_gestures->setRockerNavigationEnabled(ui->enableRockerNavigation->isChecked());
|
||||
m_gestures->saveSettings();
|
||||
close();
|
||||
}
|
||||
|
@ -26,19 +26,23 @@ namespace Ui
|
||||
class MouseGesturesSettingsDialog;
|
||||
}
|
||||
|
||||
class MouseGestures;
|
||||
|
||||
class MouseGesturesSettingsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MouseGesturesSettingsDialog(QWidget* parent = 0);
|
||||
explicit MouseGesturesSettingsDialog(MouseGestures* gestures, QWidget* parent = 0);
|
||||
~MouseGesturesSettingsDialog();
|
||||
|
||||
private slots:
|
||||
void showLicense();
|
||||
void accepted();
|
||||
|
||||
private:
|
||||
Ui::MouseGesturesSettingsDialog* ui;
|
||||
MouseGestures* m_gestures;
|
||||
};
|
||||
|
||||
#endif // MOUSEGESTURESSETTINGSDIALOG_H
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>502</width>
|
||||
<height>420</height>
|
||||
<height>433</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -32,7 +32,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="pixmap">
|
||||
<pixmap resource="mousegestures.qrc">:/mousegestures/data/icon.png</pixmap>
|
||||
<pixmap>:/mousegestures/data/icon.png</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -58,10 +58,93 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="topMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::ExpandingFieldsGrow</enum>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_22">
|
||||
<property name="text">
|
||||
<string>Mouse button:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="mouseButtonComboBox">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Middle button</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Right button</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Disabled</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_23">
|
||||
<property name="text">
|
||||
<string>Rocker Navigation:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QCheckBox" name="enableRockerNavigation">
|
||||
<property name="text">
|
||||
<string>Enable Rocker Navigation</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_17">
|
||||
<property name="text">
|
||||
<string>Press and hold the middle mouse button and move your mouse in the indicated directions.</string>
|
||||
<string>Press and hold the mouse button and move your mouse in the indicated directions.</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
@ -71,19 +154,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
@ -101,7 +171,7 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="mousegestures.qrc">:/mousegestures/data/up.gif</pixmap>
|
||||
<pixmap>:/mousegestures/data/up.gif</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -115,7 +185,7 @@
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="pixmap">
|
||||
<pixmap resource="mousegestures.qrc">:/mousegestures/data/down.gif</pixmap>
|
||||
<pixmap>:/mousegestures/data/down.gif</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -129,7 +199,7 @@
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="pixmap">
|
||||
<pixmap resource="mousegestures.qrc">:/mousegestures/data/left.gif</pixmap>
|
||||
<pixmap>:/mousegestures/data/left.gif</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -149,21 +219,14 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="mousegestures.qrc">:/mousegestures/data/up-down.gif</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string><b>Reload</b><br/>Reload page</string>
|
||||
<pixmap>:/mousegestures/data/up-down.gif</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="pixmap">
|
||||
<pixmap resource="mousegestures.qrc">:/mousegestures/data/down-right.gif</pixmap>
|
||||
<pixmap>:/mousegestures/data/down-right.gif</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -177,7 +240,7 @@
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="pixmap">
|
||||
<pixmap resource="mousegestures.qrc">:/mousegestures/data/right.gif</pixmap>
|
||||
<pixmap>:/mousegestures/data/right.gif</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -198,7 +261,7 @@
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_14">
|
||||
<property name="pixmap">
|
||||
<pixmap resource="mousegestures.qrc">:/mousegestures/data/down-left.gif</pixmap>
|
||||
<pixmap>:/mousegestures/data/down-left.gif</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -212,7 +275,7 @@
|
||||
<item row="3" column="2">
|
||||
<widget class="QLabel" name="label_20">
|
||||
<property name="pixmap">
|
||||
<pixmap resource="mousegestures.qrc">:/mousegestures/data/up-right.gif</pixmap>
|
||||
<pixmap>:/mousegestures/data/up-right.gif</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -226,7 +289,14 @@
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_18">
|
||||
<property name="pixmap">
|
||||
<pixmap resource="mousegestures.qrc">:/mousegestures/data/up-left.gif</pixmap>
|
||||
<pixmap>:/mousegestures/data/up-left.gif</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string><b>Reload</b><br/>Reload page</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -260,7 +330,7 @@
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close</set>
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -268,9 +338,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="mousegestures.qrc"/>
|
||||
</resources>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
|
Loading…
Reference in New Issue
Block a user