diff --git a/src/plugins/MouseGestures/mousegestures.cpp b/src/plugins/MouseGestures/mousegestures.cpp index eb7261b72..1a865162a 100644 --- a/src/plugins/MouseGestures/mousegestures.cpp +++ b/src/plugins/MouseGestures/mousegestures.cpp @@ -29,14 +29,28 @@ #include #include #include +#include -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); diff --git a/src/plugins/MouseGestures/mousegestures.h b/src/plugins/MouseGestures/mousegestures.h index a3ece6e30..4f64952fc 100644 --- a/src/plugins/MouseGestures/mousegestures.h +++ b/src/plugins/MouseGestures/mousegestures.h @@ -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 m_settings; QPointer m_view; + + QString m_settingsFile; + Qt::MouseButton m_button; + bool m_enableRockerNavigation; + bool m_blockNextRightMouseRelease; bool m_blockNextLeftMouseRelease; - - bool m_enableRockerNavigation; }; #endif // MOUSEGESTURES_H diff --git a/src/plugins/MouseGestures/mousegesturesplugin.cpp b/src/plugins/MouseGestures/mousegesturesplugin.cpp index 53d5ffe1f..82b803765 100644 --- a/src/plugins/MouseGestures/mousegesturesplugin.cpp +++ b/src/plugins/MouseGestures/mousegesturesplugin.cpp @@ -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); diff --git a/src/plugins/MouseGestures/mousegesturessettingsdialog.cpp b/src/plugins/MouseGestures/mousegesturessettingsdialog.cpp index aed607b71..f1868b46d 100644 --- a/src/plugins/MouseGestures/mousegesturessettingsdialog.cpp +++ b/src/plugins/MouseGestures/mousegesturessettingsdialog.cpp @@ -18,12 +18,14 @@ #include "mousegesturessettingsdialog.h" #include "ui_mousegesturessettingsdialog.h" #include "licenseviewer.h" +#include "mousegestures.h" #include -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(); +} diff --git a/src/plugins/MouseGestures/mousegesturessettingsdialog.h b/src/plugins/MouseGestures/mousegesturessettingsdialog.h index a99d2e381..ed23e04d4 100644 --- a/src/plugins/MouseGestures/mousegesturessettingsdialog.h +++ b/src/plugins/MouseGestures/mousegesturessettingsdialog.h @@ -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 diff --git a/src/plugins/MouseGestures/mousegesturessettingsdialog.ui b/src/plugins/MouseGestures/mousegesturessettingsdialog.ui index c9a46d24b..f1565cfd0 100644 --- a/src/plugins/MouseGestures/mousegesturessettingsdialog.ui +++ b/src/plugins/MouseGestures/mousegesturessettingsdialog.ui @@ -7,7 +7,7 @@ 0 0 502 - 420 + 433 @@ -32,7 +32,7 @@ - :/mousegestures/data/icon.png + :/mousegestures/data/icon.png @@ -58,10 +58,93 @@ + + + + 10 + + + 10 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Mouse button: + + + + + + + + Middle button + + + + + Right button + + + + + Disabled + + + + + + + + Rocker Navigation: + + + + + + + Enable Rocker Navigation + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + - Press and hold the middle mouse button and move your mouse in the indicated directions. + Press and hold the mouse button and move your mouse in the indicated directions. Qt::AlignCenter @@ -71,19 +154,6 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - @@ -101,7 +171,7 @@ - :/mousegestures/data/up.gif + :/mousegestures/data/up.gif @@ -115,7 +185,7 @@ - :/mousegestures/data/down.gif + :/mousegestures/data/down.gif @@ -129,7 +199,7 @@ - :/mousegestures/data/left.gif + :/mousegestures/data/left.gif @@ -149,21 +219,14 @@ - :/mousegestures/data/up-down.gif - - - - - - - <b>Reload</b><br/>Reload page + :/mousegestures/data/up-down.gif - :/mousegestures/data/down-right.gif + :/mousegestures/data/down-right.gif @@ -177,7 +240,7 @@ - :/mousegestures/data/right.gif + :/mousegestures/data/right.gif @@ -198,7 +261,7 @@ - :/mousegestures/data/down-left.gif + :/mousegestures/data/down-left.gif @@ -212,7 +275,7 @@ - :/mousegestures/data/up-right.gif + :/mousegestures/data/up-right.gif @@ -226,7 +289,14 @@ - :/mousegestures/data/up-left.gif + :/mousegestures/data/up-left.gif + + + + + + + <b>Reload</b><br/>Reload page @@ -260,7 +330,7 @@ Qt::Horizontal - QDialogButtonBox::Close + QDialogButtonBox::Cancel|QDialogButtonBox::Ok @@ -268,9 +338,7 @@ - - - + buttonBox