Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions client/funq/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,31 @@ def drag_n_drop(self, src_widget, src_pos=None,
srcpos=src_pos,
destpos=dest_pos)

def mouse_move(self, ref_widget, src_pos=None, dest_pos=None,
key_press=False):
"""
Simulate a mouse move event.

:param ref_widget: widget source
:param src_pos: starting position for the drag. If None, the center
of `ref_widget` will be used, else it must be a
tuple (x, y) in widget coordinates.
:param dest_pos: ending position for the drop. If None, the center
of `ref_widget` will be used, else it must be a
tuple (x, y) in widget coordinates.
"""

if src_pos is not None:
src_pos = ','.join(map(str, src_pos))
if dest_pos is not None:
dest_pos = ','.join(map(str, dest_pos))

self.send_command("widget_mouse_move",
oid=ref_widget.oid,
srcpos=src_pos,
destpos=dest_pos,
keypress=key_press)

class ApplicationContext(object): # pylint: disable=R0903
"""
This is the context of a tested application.
Expand Down
15 changes: 15 additions & 0 deletions client/funq/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,21 @@ def drag_n_drop(self, src_pos=None,
self.client.drag_n_drop(self, src_pos=src_pos, dest_widget=dest_widget,
dest_pos=dest_pos)

def mouse_move(self, src_pos=None, dest_pos=None):
"""

Simulate a mouse move event.
:param src_pos: starting position for the drag. If None, the center
of `self` will be used, else it must be a
tuple (x, y) in widget coordinates.
:param dest_pos: ending position for the drop. If None, the center
of `self` will be used, else it must be a
tuple (x, y) in widget coordinates.
"""
self.client.mouse_move(ref_widget=self,
src_pos=src_pos,
dest_pos=dest_pos)

def close(self):
"""
Ask to close a widget, using QWidget::close().
Expand Down
2 changes: 1 addition & 1 deletion server/libFunq/dragndropresponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ knowledge of the CeCILL v2.1 license and that you accept its terms.
void calculate_drag_n_drop_moves(QList<QPoint> & moves,
const QPoint & globalSourcePos,
const QPoint & globalDestPos,
int deltaFactor=4) {
int deltaFactor) {
QPoint delta = globalDestPos - globalSourcePos;
delta /= deltaFactor;

Expand Down
3 changes: 3 additions & 0 deletions server/libFunq/dragndropresponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ knowledge of the CeCILL v2.1 license and that you accept its terms.
#include "delayedresponse.h"
#include <QWidget>

void calculate_drag_n_drop_moves(QList<QPoint> & moves, const QPoint & globalSourcePos, const QPoint & globalDestPos, int deltaFactor=4);
QPoint pointFromString(const QString & data);

class DragNDropResponse : public DelayedResponse
{
public:
Expand Down
43 changes: 43 additions & 0 deletions server/libFunq/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ void mouse_dclick(QWidget * w, const QPoint & pos) {
Qt::NoModifier));
}

void mouse_move(QWidget * w, const QPoint & srcpos, const QPoint & destpos) {
QList<QPoint> moves;
QPoint globalsrcpos = w->mapToGlobal(srcpos);
QPoint globaldestpos = w->mapToGlobal(destpos);
calculate_drag_n_drop_moves(moves, globalsrcpos, globaldestpos, 4);
foreach (const QPoint & move, moves) {
qApp->postEvent(w,
new QMouseEvent(QEvent::MouseMove,
w->mapFromGlobal(move),
move,
Qt::NoButton,
Qt::NoButton,
Qt::NoModifier));
}
mouse_click(w, destpos);
}

void dump_properties(QObject * object, QtJson::JsonObject & out) {
const QMetaObject * metaobject = object->metaObject();
for (int i = 0; i < metaobject->propertyCount(); ++i) {
Expand Down Expand Up @@ -398,6 +415,32 @@ QtJson::JsonObject Player::widget_click(const QtJson::JsonObject & command) {
return result;
}

QtJson::JsonObject Player::widget_mouse_move(const QtJson::JsonObject & command) {
WidgetLocatorContext<QAbstractScrollArea> ctx(this, command, "oid");
if (ctx.hasError()) { return ctx.lastError; }

QPoint srcPos;
if (command.contains("srcpos") && ! command["srcpos"].isNull()) {
srcPos = pointFromString(command["srcpos"].toString());
} else {
srcPos = ctx.widget->rect().center();
}

QPoint destPos;
if (command.contains("destpos") && ! command["destpos"].isNull()) {
destPos = pointFromString(command["destpos"].toString());
destPos.setX(srcPos.x() + destPos.x());
destPos.setY(srcPos.y() + destPos.y());
} else {
destPos = ctx.widget->rect().center();
}

mouse_move(ctx.widget->viewport(), srcPos, destPos);

QtJson::JsonObject result;
return result;
}

QtJson::JsonObject Player::widget_close(const QtJson::JsonObject & command) {
WidgetLocatorContext<QWidget> ctx(this, command, "oid");
if (ctx.hasError()) { return ctx.lastError; }
Expand Down
1 change: 1 addition & 0 deletions server/libFunq/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public slots:
QtJson::JsonObject object_set_properties(const QtJson::JsonObject & command);
QtJson::JsonObject widgets_list(const QtJson::JsonObject & command);
QtJson::JsonObject widget_click(const QtJson::JsonObject & command);
QtJson::JsonObject widget_mouse_move(const QtJson::JsonObject & command);
QtJson::JsonObject widget_close(const QtJson::JsonObject & command);
DelayedResponse * drag_n_drop(const QtJson::JsonObject & command);
QtJson::JsonObject model_items(const QtJson::JsonObject & command);
Expand Down