diff options
Diffstat (limited to 'src/mixxxapplication.cpp')
-rw-r--r-- | src/mixxxapplication.cpp | 58 |
1 files changed, 53 insertions, 5 deletions
diff --git a/src/mixxxapplication.cpp b/src/mixxxapplication.cpp index f2b5e965ee..7bed455878 100644 --- a/src/mixxxapplication.cpp +++ b/src/mixxxapplication.cpp @@ -36,13 +36,24 @@ Q_IMPORT_PLUGIN(QGifPlugin) //Q_IMPORT_PLUGIN(AccessibleFactory) #endif +namespace { + +/// This class allows to change the button of a mouse event on the fly. +/// This is required because we want to change the behaviour of Qts mouse +/// buttony synthesizer without duplicate all the code. +class QMouseEventEditable : public QMouseEvent { + public: + void setButton(Qt::MouseButton button) { + b = button; + } +}; + +} // anonymous namespace MixxxApplication::MixxxApplication(int& argc, char** argv) : QApplication(argc, argv), - m_fakeMouseSourcePointId(0), - m_fakeMouseWidget(NULL), - m_activeTouchButton(Qt::NoButton), - m_pTouchShift(NULL) { + m_rightPressedButtons(0), + m_pTouchShift(nullptr) { registerMetaTypes(); // Increase the size of the global thread pool to at least @@ -86,10 +97,47 @@ void MixxxApplication::registerMetaTypes() { qRegisterMetaType<std::optional<mixxx::RgbColor>>("std::optional<mixxx::RgbColor>"); } +bool MixxxApplication::notify(QObject* target, QEvent* event) { + // All touch events are translated into two simultaneous events: one for + // the target QWidgetWindow and one for the target QWidget. + // A second touch becomes a mouse move without additional press and release + // events. + switch (event->type()) { + case QEvent::MouseButtonPress: { + QMouseEventEditable* mouseEvent = static_cast<QMouseEventEditable*>(event); + if (mouseEvent->source() == Qt::MouseEventSynthesizedByQt && + mouseEvent->button() == Qt::LeftButton && + touchIsRightButton()) { + // Assert the assumption that QT synthesizes only one click at a time + // = two events (see above) + VERIFY_OR_DEBUG_ASSERT(m_rightPressedButtons < 2) { + break; + } + mouseEvent->setButton(Qt::RightButton); + m_rightPressedButtons++; + } + break; + } + case QEvent::MouseButtonRelease: { + QMouseEventEditable* mouseEvent = static_cast<QMouseEventEditable*>(event); + if (mouseEvent->source() == Qt::MouseEventSynthesizedByQt && + mouseEvent->button() == Qt::LeftButton && + m_rightPressedButtons > 0) { + mouseEvent->setButton(Qt::RightButton); + m_rightPressedButtons--; + } + break; + } + default: + break; + } + return QApplication::notify(target, event); +} + bool MixxxApplication::touchIsRightButton() { if (!m_pTouchShift) { m_pTouchShift = new ControlProxy( "[Controls]", "touch_shift", this); } - return (m_pTouchShift->get() != 0.0); + return m_pTouchShift->toBool(); } |