enable a stripped, non-functional mouseventlistener

This commit is contained in:
Sebastian Kügler 2013-02-14 06:08:29 +01:00
parent 81302acf9d
commit 2e9a8b7051
4 changed files with 142 additions and 142 deletions

View File

@ -8,8 +8,8 @@ set(qtextracomponents_SRCS
qtextracomponentsplugin.cpp
# qpixmapitem.cpp
# qimageitem.cpp
qiconitem.cpp
# mouseeventlistener.cpp
qiconitem.cpp
mouseeventlistener.cpp
columnproxymodel.cpp
)

View File

@ -43,7 +43,7 @@ MouseEventListener::MouseEventListener(QQuickItem *parent)
qmlRegisterType<KDeclarativeMouseEvent>();
qmlRegisterType<KDeclarativeWheelEvent>();
setFiltersChildEvents(true);
setFiltersChildMouseEvents(true);
setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton|Qt::MidButton|Qt::XButton1|Qt::XButton2);
}
@ -66,85 +66,85 @@ bool MouseEventListener::hoverEnabled() const
return acceptHoverEvents();
}
void MouseEventListener::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
m_containsMouse = true;
emit containsMouseChanged(true);
}
void MouseEventListener::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
m_containsMouse = false;
emit containsMouseChanged(false);
}
// void MouseEventListener::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
// {
// Q_UNUSED(event);
//
// m_containsMouse = true;
// emit containsMouseChanged(true);
// }
//
// void MouseEventListener::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
// {
// Q_UNUSED(event);
//
// m_containsMouse = false;
// emit containsMouseChanged(false);
// }
bool MouseEventListener::containsMouse() const
{
return m_containsMouse;
}
void MouseEventListener::mousePressEvent(QGraphicsSceneMouseEvent *me)
{
if (m_lastEvent == me) {
return;
}
//FIXME: when a popup window is visible: a click anywhere hides it: but the old qgraphicswidget will continue to think it's under the mouse
//doesn't seem to be any good way to properly reset this.
//this msolution will still caused a missed click after the popup is gone, but gets the situation unblocked.
if (!isUnderMouse()) {
me->ignore();
return;
}
KDeclarativeMouseEvent dme(me->pos().x(), me->pos().y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
m_pressAndHoldEvent = new KDeclarativeMouseEvent(me->pos().x(), me->pos().y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
emit pressed(&dme);
m_pressed = true;
m_pressAndHoldTimer->start(PressAndHoldDelay);
}
void MouseEventListener::mouseMoveEvent(QGraphicsSceneMouseEvent *me)
{
if (m_lastEvent == me) {
return;
}
KDeclarativeMouseEvent dme(me->pos().x(), me->pos().y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
emit positionChanged(&dme);
}
void MouseEventListener::mouseReleaseEvent(QGraphicsSceneMouseEvent *me)
{
if (m_lastEvent == me) {
return;
}
KDeclarativeMouseEvent dme(me->pos().x(), me->pos().y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
m_pressed = false;
emit released(&dme);
if (QPointF(me->pos() - me->buttonDownPos(me->button())).manhattanLength() <= QApplication::startDragDistance() && m_pressAndHoldTimer->isActive()) {
emit clicked(&dme);
m_pressAndHoldTimer->stop();
}
}
void MouseEventListener::wheelEvent(QGraphicsSceneWheelEvent *we)
{
if (m_lastEvent == we) {
return;
}
KDeclarativeWheelEvent dwe(we->pos(), we->screenPos(), we->delta(), we->buttons(), we->modifiers(), we->orientation());
emit wheelMoved(&dwe);
}
// void MouseEventListener::mousePressEvent(QGraphicsSceneMouseEvent *me)
// {
// if (m_lastEvent == me) {
// return;
// }
//
// //FIXME: when a popup window is visible: a click anywhere hides it: but the old qgraphicswidget will continue to think it's under the mouse
// //doesn't seem to be any good way to properly reset this.
// //this msolution will still caused a missed click after the popup is gone, but gets the situation unblocked.
// if (!isUnderMouse()) {
// me->ignore();
// return;
// }
//
// KDeclarativeMouseEvent dme(me->pos().x(), me->pos().y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
// m_pressAndHoldEvent = new KDeclarativeMouseEvent(me->pos().x(), me->pos().y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
// emit pressed(&dme);
// m_pressed = true;
//
// m_pressAndHoldTimer->start(PressAndHoldDelay);
// }
//
// void MouseEventListener::mouseMoveEvent(QGraphicsSceneMouseEvent *me)
// {
// if (m_lastEvent == me) {
// return;
// }
//
// KDeclarativeMouseEvent dme(me->pos().x(), me->pos().y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
// emit positionChanged(&dme);
// }
//
// void MouseEventListener::mouseReleaseEvent(QGraphicsSceneMouseEvent *me)
// {
// if (m_lastEvent == me) {
// return;
// }
//
// KDeclarativeMouseEvent dme(me->pos().x(), me->pos().y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
// m_pressed = false;
// emit released(&dme);
//
// if (QPointF(me->pos() - me->buttonDownPos(me->button())).manhattanLength() <= QApplication::startDragDistance() && m_pressAndHoldTimer->isActive()) {
// emit clicked(&dme);
// m_pressAndHoldTimer->stop();
// }
// }
//
// void MouseEventListener::wheelEvent(QGraphicsSceneWheelEvent *we)
// {
// if (m_lastEvent == we) {
// return;
// }
//
// KDeclarativeWheelEvent dwe(we->pos(), we->screenPos(), we->delta(), we->buttons(), we->modifiers(), we->orientation());
// emit wheelMoved(&dwe);
// }
//
void MouseEventListener::handlePressAndHold()
{
if (m_pressed) {
@ -154,63 +154,63 @@ void MouseEventListener::handlePressAndHold()
}
bool MouseEventListener::sceneEventFilter(QGraphicsItem *item, QEvent *event)
{
if (!isEnabled()) {
return false;
}
m_lastEvent = event;
switch (event->type()) {
case QEvent::GraphicsSceneMousePress: {
QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent *>(event);
//the parent will receive events in its own coordinates
const QPointF myPos = item->mapToItem(this, me->pos());
KDeclarativeMouseEvent dme(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
m_pressAndHoldEvent = new KDeclarativeMouseEvent(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
//kDebug() << "pressed in sceneEventFilter";
emit pressed(&dme);
m_pressed = true;
m_pressAndHoldTimer->start(PressAndHoldDelay);
break;
}
case QEvent::GraphicsSceneMouseMove: {
QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent *>(event);
const QPointF myPos = item->mapToItem(this, me->pos());
KDeclarativeMouseEvent dme(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
//kDebug() << "positionChanged..." << dme.x() << dme.y();
m_pressAndHoldEvent = new KDeclarativeMouseEvent(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
emit positionChanged(&dme);
break;
}
case QEvent::GraphicsSceneMouseRelease: {
QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent *>(event);
const QPointF myPos = item->mapToItem(this, me->pos());
KDeclarativeMouseEvent dme(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
m_pressed = false;
emit released(&dme);
if (QPointF(me->pos() - me->buttonDownPos(me->button())).manhattanLength() <= QApplication::startDragDistance() && m_pressAndHoldTimer->isActive()) {
emit clicked(&dme);
m_pressAndHoldTimer->stop();
}
break;
}
case QEvent::GraphicsSceneWheel: {
QGraphicsSceneWheelEvent *we = static_cast<QGraphicsSceneWheelEvent *>(event);
KDeclarativeWheelEvent dwe(we->pos(), we->screenPos(), we->delta(), we->buttons(), we->modifiers(), we->orientation());
emit wheelMoved(&dwe);
break;
}
default:
break;
}
return QQuickItem::sceneEventFilter(item, event);
}
// bool MouseEventListener::sceneEventFilter(QGraphicsItem *item, QEvent *event)
// {
// if (!isEnabled()) {
// return false;
// }
//
// m_lastEvent = event;
//
// switch (event->type()) {
// case QEvent::GraphicsSceneMousePress: {
// QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent *>(event);
// //the parent will receive events in its own coordinates
// const QPointF myPos = item->mapToItem(this, me->pos());
// KDeclarativeMouseEvent dme(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
// m_pressAndHoldEvent = new KDeclarativeMouseEvent(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
// //kDebug() << "pressed in sceneEventFilter";
// emit pressed(&dme);
// m_pressed = true;
//
// m_pressAndHoldTimer->start(PressAndHoldDelay);
// break;
// }
// case QEvent::GraphicsSceneMouseMove: {
// QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent *>(event);
// const QPointF myPos = item->mapToItem(this, me->pos());
// KDeclarativeMouseEvent dme(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
// //kDebug() << "positionChanged..." << dme.x() << dme.y();
// m_pressAndHoldEvent = new KDeclarativeMouseEvent(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
// emit positionChanged(&dme);
// break;
// }
// case QEvent::GraphicsSceneMouseRelease: {
// QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent *>(event);
// const QPointF myPos = item->mapToItem(this, me->pos());
// KDeclarativeMouseEvent dme(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
// m_pressed = false;
//
// emit released(&dme);
//
// if (QPointF(me->pos() - me->buttonDownPos(me->button())).manhattanLength() <= QApplication::startDragDistance() && m_pressAndHoldTimer->isActive()) {
// emit clicked(&dme);
// m_pressAndHoldTimer->stop();
// }
// break;
// }
// case QEvent::GraphicsSceneWheel: {
// QGraphicsSceneWheelEvent *we = static_cast<QGraphicsSceneWheelEvent *>(event);
// KDeclarativeWheelEvent dwe(we->pos(), we->screenPos(), we->delta(), we->buttons(), we->modifiers(), we->orientation());
// emit wheelMoved(&dwe);
// break;
// }
// default:
// break;
// }
//
// return QQuickItem::sceneEventFilter(item, event);
// }
#include "mouseeventlistener.moc"

View File

@ -143,13 +143,13 @@ public:
bool hoverEnabled() const;
protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void wheelEvent(QGraphicsSceneWheelEvent *event);
bool sceneEventFilter(QGraphicsItem *i, QEvent *e);
// void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
// void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
// void mousePressEvent(QGraphicsSceneMouseEvent *event);
// void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
// void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
// void wheelEvent(QGraphicsSceneWheelEvent *event);
// bool sceneEventFilter(QGraphicsItem *i, QEvent *e);
Q_SIGNALS:
void pressed(KDeclarativeMouseEvent *mouse);

View File

@ -27,7 +27,7 @@
// #include "qpixmapitem.h"
// #include "qimageitem.h"
#include "qiconitem.h"
//#include "mouseeventlistener.h"
#include "mouseeventlistener.h"
#include "columnproxymodel.h"
// void QtExtraComponentsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
@ -42,7 +42,7 @@ void QtExtraComponentsPlugin::registerTypes(const char *uri)
// qmlRegisterType<QPixmapItem>(uri, 0, 1, "QPixmapItem");
// qmlRegisterType<QImageItem>(uri, 0, 1, "QImageItem");
qmlRegisterType<QIconItem>(uri, 0, 1, "QIconItem");
// qmlRegisterType<MouseEventListener>(uri, 0, 1, "MouseEventListener");
qmlRegisterType<MouseEventListener>(uri, 0, 1, "MouseEventListener");
qmlRegisterType<ColumnProxyModel>(uri, 0, 1, "ColumnProxyModel");
qmlRegisterType<QAbstractItemModel>();