summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Schürmann <daschuer@mixxx.org>2013-10-29 18:59:58 +0100
committerDaniel Schürmann <daschuer@mixxx.org>2013-10-29 18:59:58 +0100
commit61348aedd7813dea1b56d4609f12a63307cc2c21 (patch)
tree0121f2fd0d13b35ff352a81a8e225c7acb530e99 /src
parentdb9244e319ee9932f3f4c72b114d77f93ee3ecb7 (diff)
mouse click fake works but issues with drag and drop
Diffstat (limited to 'src')
-rw-r--r--src/mixxx.cpp8
-rw-r--r--src/mixxxapplication.cpp139
-rw-r--r--src/mixxxapplication.h27
3 files changed, 170 insertions, 4 deletions
diff --git a/src/mixxx.cpp b/src/mixxx.cpp
index 8d87223681..d419bf69ed 100644
--- a/src/mixxx.cpp
+++ b/src/mixxx.cpp
@@ -1517,12 +1517,12 @@ bool MixxxMainWindow::event(QEvent* e) {
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
{
- // If the touch event falls trough to the main Widget, we ignore it this
- // way it is resends as mouse event
+ // If the touch event falls trough to the main Widget, no touch widget
+ // was touched, so we resent it as a mouse events.
+ // We have to accept it here, so QApplication will continue to deliver
+ // the following events of this touch point as well.
QTouchEvent* touchEvent = static_cast<QTouchEvent*>(e);
touchEvent->accept();
- qDebug() << "%" << e->type();
- qDebug() << "%" << ((QTouchEvent*)e)->widget() << this;
return true;
}
default:
diff --git a/src/mixxxapplication.cpp b/src/mixxxapplication.cpp
new file mode 100644
index 0000000000..81d2c92af6
--- /dev/null
+++ b/src/mixxxapplication.cpp
@@ -0,0 +1,139 @@
+
+#include <QtDebug>
+#include <QTouchEvent>
+
+
+#include "mixxxapplication.h"
+#include "controlobjectthread.h"
+#include "mixxx.h"
+
+
+MixxxApplication::MixxxApplication(int& argc, char** argv)
+ : QApplication(argc, argv),
+ m_fakeMouseSourcePointId(0),
+ m_fakeMouseWidget(NULL),
+ m_activeTouchButton(Qt::NoButton),
+ m_pTouchShift(NULL) {
+}
+
+MixxxApplication::~MixxxApplication() {
+ delete m_pTouchShift;
+}
+
+bool MixxxApplication::notify(QObject* target, QEvent* event) {
+ switch (event->type()) {
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ case QEvent::TouchEnd:
+ {
+ QTouchEvent* touchEvent = static_cast<QTouchEvent*>(event);
+ QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
+ QEvent::Type eventType = QEvent::None;
+ Qt::MouseButtons buttons = Qt::NoButton;
+ QWidget* fakeMouseWidget = NULL;
+
+ qDebug() << "&" << touchEvent->type() << target;
+
+ // return QApplication::notify(target, event);
+
+
+
+ if (touchEvent->deviceType() != QTouchEvent::TouchScreen) {
+ break;
+ }
+
+ switch (event->type()) {
+ case QEvent::TouchBegin:
+ // try to deliver as touch event
+ (void)QApplication::notify(target, event);
+ if (dynamic_cast<MixxxMainWindow*>(touchEvent->widget())) {
+ // the touchEvent has fallen trough to the MixxxMainWindow, because there
+ // was no touch enabled widget found.
+ // Now we resent this event and all following events for this touch point
+ // as Mouse events.
+ eventType = QEvent::MouseButtonPress;
+ if (touchIsRightButton()) {
+ // touch is right click
+ m_activeTouchButton = Qt::RightButton;
+ buttons = Qt::RightButton;
+ } else {
+ m_activeTouchButton = Qt::LeftButton;
+ buttons = Qt::LeftButton;
+ }
+ m_fakeMouseSourcePointId = touchPoints.first().id();
+ m_fakeMouseWidget = dynamic_cast<QWidget*>(target);
+ fakeMouseWidget = m_fakeMouseWidget;
+ }
+ break;
+ case QEvent::TouchUpdate:
+ if (m_fakeMouseWidget) {
+ eventType = QEvent::MouseMove;
+ buttons = m_activeTouchButton;
+ fakeMouseWidget = m_fakeMouseWidget;
+ break;
+ }
+ return QApplication::notify(target, event);
+ case QEvent::TouchEnd:
+ if (m_fakeMouseWidget) {
+ eventType = QEvent::MouseButtonRelease;
+ m_fakeMouseSourcePointId = touchPoints.first().id();
+ fakeMouseWidget = m_fakeMouseWidget;
+ m_fakeMouseWidget = NULL;
+ break;
+ }
+ return QApplication::notify(target, event);
+ default:
+ return QApplication::notify(target, event);
+ }
+
+ for (int i = 0; i < touchPoints.count(); ++i) {
+ const QTouchEvent::TouchPoint& touchPoint = touchPoints.at(i);
+ if (touchPoint.id() == m_fakeMouseSourcePointId) {
+ QMouseEvent mouseEvent(eventType,
+ fakeMouseWidget->mapFromGlobal(touchPoint.screenPos().toPoint()),
+ touchPoint.screenPos().toPoint(),
+ m_activeTouchButton, // Button that causes the event
+ buttons,
+ touchEvent->modifiers());
+
+ qDebug() << "#" << mouseEvent.type() << mouseEvent.button() << mouseEvent.buttons() << mouseEvent.pos() << mouseEvent.globalPos();
+
+ // touch event was not accepted by any widget in the Main window
+ // send as the previously prepared faked Mouse event now.
+ //if (m_fakeMouseWidget->focusPolicy() & Qt::ClickFocus) {
+ // fakeMouseWidget->setFocus();
+ //}
+ QApplication::notify(fakeMouseWidget, &mouseEvent);
+ return true;
+ }
+ }
+ qDebug() << "return false";
+ return false;
+ break;
+ }
+ case QEvent::MouseButtonPress:
+ case QEvent::MouseMove:
+ qDebug() << "+" << event->type() << target;
+ break;
+ case QEvent::MouseButtonRelease:
+ qDebug() << "+" << event->type() << target;
+ QApplication::notify(target, event);
+ if (m_fakeMouseWidget) {
+ QApplication::notify(m_fakeMouseWidget, event);
+ m_fakeMouseWidget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent, false);
+ m_fakeMouseWidget = NULL;
+ }
+ return true;
+ default:
+ break;
+ }
+ // No touch event
+ return QApplication::notify(target, event);
+}
+
+bool MixxxApplication::touchIsRightButton() {
+ if (!m_pTouchShift) {
+ m_pTouchShift = new ControlObjectThread("[Controls]", "touch_shift");
+ }
+ return (m_pTouchShift->get() != 0.0);
+}
diff --git a/src/mixxxapplication.h b/src/mixxxapplication.h
new file mode 100644
index 0000000000..33626effbd
--- /dev/null
+++ b/src/mixxxapplication.h
@@ -0,0 +1,27 @@
+#ifndef MIXXXAPPLICATION_H
+#define MIXXXAPPLICATION_H
+
+#include <QApplication>
+
+class ControlObjectThread;
+
+class MixxxApplication : public QApplication {
+ Q_OBJECT
+
+ public:
+ MixxxApplication(int& argc, char** argv);
+ virtual ~MixxxApplication();
+
+ virtual bool notify(QObject*, QEvent*);
+
+ private:
+ bool touchIsRightButton();
+
+ int m_fakeMouseSourcePointId;
+ QWidget* m_fakeMouseWidget;
+ enum Qt::MouseButton m_activeTouchButton;
+ ControlObjectThread* m_pTouchShift;
+
+};
+
+#endif // MIXXXAPPLICATION_H