Skip to content

Commit

Permalink
updated with many changes. Trying to do mouse movement internally fro…
Browse files Browse the repository at this point in the history
…m viewer.
  • Loading branch information
inblueswithu committed Nov 22, 2013
1 parent c2ea65a commit 7c124ee
Show file tree
Hide file tree
Showing 10 changed files with 360 additions and 213 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Thumbs.db
Thumbs.db
*.user
48 changes: 48 additions & 0 deletions ButtonMouse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "ButtonMouse.h"

ButtonMouse::ButtonMouse(QQuickItem* gui, QCursor* cursor)
{
this->gui = gui;
this->cursor = cursor;
}

void ButtonMouse::Button1Slot()
{
// cursor->setPos(50, 175);

QGuiApplication::sendEvent(gui, new QMouseEvent(QEvent::MouseButtonPress, QPointF(50, 175),
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));
QGuiApplication::sendEvent(gui, new QMouseEvent(QEvent::MouseButtonRelease, QPointF(50, 175),
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));
}

void ButtonMouse::Button2Slot()
{
// cursor->setPos(50, 125);

QGuiApplication::sendEvent(gui, new QMouseEvent(QEvent::MouseButtonPress, QPointF(50, 125),
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));
QGuiApplication::sendEvent(gui, new QMouseEvent(QEvent::MouseButtonRelease, QPointF(50, 125),
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));
}

void ButtonMouse::Button3Slot()
{
// cursor->setPos(50, 75);

QGuiApplication::sendEvent(gui, new QMouseEvent(QEvent::MouseButtonPress, QPointF(50, 75),
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));
QGuiApplication::sendEvent(gui, new QMouseEvent(QEvent::MouseButtonRelease, QPointF(50, 75),
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));
}

void ButtonMouse::Button4Slot()
{
// cursor->setPos(50, 25);

QGuiApplication::sendEvent(gui, new QMouseEvent(QEvent::MouseButtonPress, QPointF(50, 25),
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));
QGuiApplication::sendEvent(gui, new QMouseEvent(QEvent::MouseButtonRelease, QPointF(50, 25),
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));
qDebug() << "in button4 slot";
}
29 changes: 29 additions & 0 deletions ButtonMouse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef BUTTONMOUSE_H
#define BUTTONMOUSE_H

#include <QObject>
#include <QtCore>
#include <QCursor>
#include <QGuiApplication>
#include <QMouseEvent>
#include <QQuickItem>

class ButtonMouse: public QObject
{
Q_OBJECT

public:
ButtonMouse(QQuickItem* gui, QCursor* cursor);

public slots:
void Button1Slot();
void Button2Slot();
void Button3Slot();
void Button4Slot();

private:
QCursor* cursor;
QQuickItem* gui;
};

#endif // BUTTONMOUSE_H
6 changes: 4 additions & 2 deletions MouseSimulation.pro
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ QML_IMPORT_PATH =

# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp \
Leap/LeapListener.cpp
Leap/LeapListener.cpp \
ButtonMouse.cpp

# QT Extra modules
#QT += multimedia \
Expand All @@ -36,4 +37,5 @@ INCLUDEPATH += $$PWD/Leap
DEPENDPATH += $$PWD/Leap

HEADERS += \
Leap/LeapListener.h
Leap/LeapListener.h \
ButtonMouse.h
192 changes: 0 additions & 192 deletions MouseSimulation.pro.user

This file was deleted.

54 changes: 43 additions & 11 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include "Leap/LeapListener.h"
//#include "Leap/LeapListener.h"
#include "ButtonMouse.h"
#include <QQuickItem>
#include <memory>

Expand All @@ -9,23 +10,54 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);

// Viewer & Custom Cursor
QCursor cursor(Qt::ArrowCursor);
// QCursor cursor(Qt::ArrowCursor);
QtQuick2ApplicationViewer viewer;
viewer.setCursor(cursor);
viewer.setMainQmlFile(QStringLiteral("qml/MouseSimulation/main.qml"));
// viewer.setCursor(cursor);
viewer.setMainQmlFile(QStringLiteral("qml/MouseSimulation/TryMouse.qml"));
std::shared_ptr<QQuickItem> root(viewer.rootObject());

// std::unique_ptr<ButtonMouse> bm(new ButtonMouse(root.get(), &cursor));

// Run QML File
// viewer.showExpanded();
viewer.showFullScreen();

// Leap Initialization
Controller controller;
LeapListener listener(root.get(), &cursor);
controller.addListener(listener);
// viewer.showMaximized();

// Connect Signals-Slots
QObject::connect(&listener, SIGNAL(signalKeyTap(float, float)), &viewer, SLOT(mouseClick(float, float)));
QObject::connect(&app, SIGNAL(focusWindowChanged(QWindow *)), &listener, SLOT(focusChanged()));
// QObject::connect(root.get(), SIGNAL(button1pressed()), bm.get(), SLOT(Button1Slot()));
// QObject::connect(root.get(), SIGNAL(button2pressed()), bm.get(), SLOT(Button2Slot()));
// QObject::connect(root.get(), SIGNAL(button3pressed()), bm.get(), SLOT(Button3Slot()));
// QObject::connect(root.get(), SIGNAL(button4pressed()), bm.get(), SLOT(Button4Slot()));
QObject::connect(root.get(), SIGNAL(button1pressed(QVariant , QVariant)), &viewer, SLOT(mouseClick(QVariant , QVariant)));
QObject::connect(root.get(), SIGNAL(button2pressed(QVariant , QVariant)), &viewer, SLOT(mouseClick(QVariant , QVariant)));
QObject::connect(root.get(), SIGNAL(button3pressed(QVariant , QVariant)), &viewer, SLOT(mouseClick(QVariant , QVariant)));
QObject::connect(root.get(), SIGNAL(button4pressed(QVariant , QVariant)), &viewer, SLOT(mouseClick(QVariant , QVariant)));

return app.exec();
}

//int main(int argc, char *argv[])
//{
// QGuiApplication app(argc, argv);

// // Viewer & Custom Cursor
// QCursor cursor(Qt::ArrowCursor);
// QtQuick2ApplicationViewer viewer;
// viewer.setCursor(cursor);
// viewer.setMainQmlFile(QStringLiteral("qml/MouseSimulation/main.qml"));
// std::shared_ptr<QQuickItem> root(viewer.rootObject());
// // Run QML File
//// viewer.showExpanded();
// viewer.showFullScreen();

// // Leap Initialization
// Controller controller;
// LeapListener listener(root.get(), &cursor);
// controller.addListener(listener);

// // Connect Signals-Slots
// QObject::connect(&listener, SIGNAL(signalKeyTap(float, float)), &viewer, SLOT(mouseClick(float, float)));
// QObject::connect(&app, SIGNAL(focusWindowChanged(QWindow *)), &listener, SLOT(focusChanged()));

// return app.exec();
//}
Loading

0 comments on commit 7c124ee

Please sign in to comment.