Change mouse and wheel QPA events to use QPointF.

At least QMouseEvent already uses QPointF so there is no reason to
restrict handleMouseEvent to integer positions.

Change-Id: I9c72d2e0e99518b40a1898aec9ad2b3421a3e9e2
Reviewed-on: http://codereview.qt.nokia.com/2739
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
This commit is contained in:
Laszlo Agocs 2011-08-08 13:07:56 +03:00 committed by Qt by Nokia
parent 991033cf46
commit ffb279a149
5 changed files with 32 additions and 32 deletions

View File

@ -76,8 +76,8 @@ QWidget *qt_button_down = 0; // widget got last button-down
static bool app_do_modal = false;
extern QWidgetList *qt_modal_stack; // stack of modal widgets
int qt_last_x = 0;
int qt_last_y = 0;
qreal qt_last_x = 0;
qreal qt_last_y = 0;
QPointer<QWidget> qt_last_mouse_receiver = 0;
static Qt::MouseButtons buttons = Qt::NoButton;
@ -621,7 +621,7 @@ void QApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mouse
QEvent::Type type;
// move first
Qt::MouseButtons stateChange = e->buttons ^ buttons;
if (e->globalPos != QPoint(qt_last_x, qt_last_y) && (stateChange != Qt::NoButton)) {
if (e->globalPos != QPointF(qt_last_x, qt_last_y) && (stateChange != Qt::NoButton)) {
QWindowSystemInterfacePrivate::MouseEvent * newMouseEvent =
new QWindowSystemInterfacePrivate::MouseEvent(e->widget.data(), e->timestamp, e->localPos, e->globalPos, e->buttons);
QWindowSystemInterfacePrivate::windowSystemEventQueue.prepend(newMouseEvent); // just in case the move triggers a new event loop
@ -630,8 +630,8 @@ void QApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mouse
QWidget * tlw = e->widget.data();
QPoint localPoint = e->localPos;
QPoint globalPoint = e->globalPos;
QPointF localPoint = e->localPos;
QPointF globalPoint = e->globalPos;
QWidget *mouseWindow = tlw;
Qt::MouseButton button = Qt::NoButton;
@ -694,7 +694,7 @@ void QApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mouse
// find the tlw if we didn't get it from the plugin
if (!mouseWindow) {
mouseWindow = QApplication::topLevelAt(globalPoint);
mouseWindow = QApplication::topLevelAt(globalPoint.toPoint());
}
if (!mouseWindow && !implicit_mouse_grabber)
@ -702,13 +702,13 @@ void QApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mouse
if (mouseWindow && mouseWindow != tlw) {
//we did not get a sensible localPoint from the window system, so let's calculate it
localPoint = mouseWindow->mapFromGlobal(globalPoint);
localPoint = mouseWindow->mapFromGlobal(globalPoint.toPoint());
}
// which child should have it?
QWidget *mouseWidget = mouseWindow;
if (mouseWindow) {
QWidget *w = mouseWindow->childAt(localPoint);
QWidget *w = mouseWindow->childAt(localPoint.toPoint());
if (w) {
mouseWidget = w;
}
@ -724,13 +724,13 @@ void QApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mouse
mouseWidget = implicit_mouse_grabber.data();
mouseWindow = mouseWidget->window();
if (mouseWindow != tlw)
localPoint = mouseWindow->mapFromGlobal(globalPoint);
localPoint = mouseWindow->mapFromGlobal(globalPoint.toPoint());
}
Q_ASSERT(mouseWidget);
//localPoint is local to mouseWindow, but it needs to be local to mouseWidget
localPoint = mouseWidget->mapFrom(mouseWindow, localPoint);
localPoint = mouseWidget->mapFrom(mouseWindow, localPoint.toPoint());
if (buttons == Qt::NoButton) {
//qDebug() << "resetting mouse grabber";
@ -760,7 +760,7 @@ void QApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mouse
#ifndef QT_NO_CONTEXTMENU
if (type == QEvent::MouseButtonPress && button == Qt::RightButton && (openPopupCount == oldOpenPopupCount)) {
QContextMenuEvent e(QContextMenuEvent::Mouse, localPoint, globalPoint, QApplication::keyboardModifiers());
QContextMenuEvent e(QContextMenuEvent::Mouse, localPoint.toPoint(), globalPoint.toPoint(), QApplication::keyboardModifiers());
QApplication::sendSpontaneousEvent(mouseWidget, &e);
}
#endif // QT_NO_CONTEXTMENU
@ -772,7 +772,7 @@ void QApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mouse
void QApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e)
{
// QPoint localPoint = ev.pos();
QPoint globalPoint = e->globalPos;
QPointF globalPoint = e->globalPos;
// bool trustLocalPoint = !!tlw; //is there something the local point can be local to?
QWidget *mouseWidget;
@ -783,7 +783,7 @@ void QApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::Wheel
// find the tlw if we didn't get it from the plugin
if (!mouseWindow) {
mouseWindow = QApplication::topLevelAt(globalPoint);
mouseWindow = QApplication::topLevelAt(globalPoint.toPoint());
}
if (!mouseWindow)
@ -795,11 +795,11 @@ void QApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::Wheel
qDebug() << "modal blocked wheel event" << mouseWindow;
return;
}
QPoint p = mouseWindow->mapFromGlobal(globalPoint);
QWidget *w = mouseWindow->childAt(p);
QPointF p = mouseWindow->mapFromGlobal(globalPoint.toPoint());
QWidget *w = mouseWindow->childAt(p.toPoint());
if (w) {
mouseWidget = w;
p = mouseWidget->mapFromGlobal(globalPoint);
p = mouseWidget->mapFromGlobal(globalPoint.toPoint());
}
QWheelEvent ev(p, globalPoint, e->delta, buttons, QApplication::keyboardModifiers(),

View File

@ -107,11 +107,11 @@ void QCursorData::update()
#endif //QT_NO_CURSOR
extern int qt_last_x,qt_last_y;
extern qreal qt_last_x,qt_last_y;
QPoint QCursor::pos()
{
return QPoint(qt_last_x, qt_last_y);
return QPointF(qt_last_x, qt_last_y).toPoint();
}
void QCursor::setPos(int x, int y)

View File

@ -115,12 +115,12 @@ void QWindowSystemInterface::handleCloseEvent(QWidget *tlw)
*/
void QWindowSystemInterface::handleMouseEvent(QWidget *w, const QPoint & local, const QPoint & global, Qt::MouseButtons b) {
void QWindowSystemInterface::handleMouseEvent(QWidget *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b) {
unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
handleMouseEvent(w, time, local, global, b);
}
void QWindowSystemInterface::handleMouseEvent(QWidget *tlw, ulong timestamp, const QPoint & local, const QPoint & global, Qt::MouseButtons b)
void QWindowSystemInterface::handleMouseEvent(QWidget *tlw, ulong timestamp, const QPointF & local, const QPointF & global, Qt::MouseButtons b)
{
if (tlw) {
QWidgetData *data = qt_qwidget_data(tlw);
@ -180,12 +180,12 @@ void QWindowSystemInterface::handleExtendedKeyEvent(QWidget *tlw, ulong timestam
QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
}
void QWindowSystemInterface::handleWheelEvent(QWidget *w, const QPoint & local, const QPoint & global, int d, Qt::Orientation o) {
void QWindowSystemInterface::handleWheelEvent(QWidget *w, const QPointF & local, const QPointF & global, int d, Qt::Orientation o) {
unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
handleWheelEvent(w, time, local, global, d, o);
}
void QWindowSystemInterface::handleWheelEvent(QWidget *tlw, ulong timestamp, const QPoint & local, const QPoint & global, int d, Qt::Orientation o)
void QWindowSystemInterface::handleWheelEvent(QWidget *tlw, ulong timestamp, const QPointF & local, const QPointF & global, int d, Qt::Orientation o)
{
if (tlw) {
QWidgetData *data = qt_qwidget_data(tlw);

View File

@ -58,8 +58,8 @@ QT_MODULE(Gui)
class Q_GUI_EXPORT QWindowSystemInterface
{
public:
static void handleMouseEvent(QWidget *w, const QPoint & local, const QPoint & global, Qt::MouseButtons b);
static void handleMouseEvent(QWidget *w, ulong timestamp, const QPoint & local, const QPoint & global, Qt::MouseButtons b);
static void handleMouseEvent(QWidget *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b);
static void handleMouseEvent(QWidget *w, ulong timestamp, const QPointF & local, const QPointF & global, Qt::MouseButtons b);
static void handleKeyEvent(QWidget *w, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1);
static void handleKeyEvent(QWidget *w, ulong timestamp, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1);
@ -75,8 +75,8 @@ public:
const QString& text = QString(), bool autorep = false,
ushort count = 1);
static void handleWheelEvent(QWidget *w, const QPoint & local, const QPoint & global, int d, Qt::Orientation o);
static void handleWheelEvent(QWidget *w, ulong timestamp, const QPoint & local, const QPoint & global, int d, Qt::Orientation o);
static void handleWheelEvent(QWidget *w, const QPointF & local, const QPointF & global, int d, Qt::Orientation o);
static void handleWheelEvent(QWidget *w, ulong timestamp, const QPointF & local, const QPointF & global, int d, Qt::Orientation o);
struct TouchPoint {
int id; // for application use

View File

@ -121,20 +121,20 @@ public:
class MouseEvent : public UserEvent {
public:
MouseEvent(QWidget * w, ulong time, const QPoint & local, const QPoint & global, Qt::MouseButtons b)
MouseEvent(QWidget * w, ulong time, const QPointF & local, const QPointF & global, Qt::MouseButtons b)
: UserEvent(w, time, Mouse), localPos(local), globalPos(global), buttons(b) { }
QPoint localPos;
QPoint globalPos;
QPointF localPos;
QPointF globalPos;
Qt::MouseButtons buttons;
};
class WheelEvent : public UserEvent {
public:
WheelEvent(QWidget *w, ulong time, const QPoint & local, const QPoint & global, int d, Qt::Orientation o)
WheelEvent(QWidget *w, ulong time, const QPointF & local, const QPointF & global, int d, Qt::Orientation o)
: UserEvent(w, time, Wheel), delta(d), localPos(local), globalPos(global), orient(o) { }
int delta;
QPoint localPos;
QPoint globalPos;
QPointF localPos;
QPointF globalPos;
Qt::Orientation orient;
};