本文整理汇总了C++中QQuickItem::mapToScene方法的典型用法代码示例。如果您正苦于以下问题:C++ QQuickItem::mapToScene方法的具体用法?C++ QQuickItem::mapToScene怎么用?C++ QQuickItem::mapToScene使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QQuickItem
的用法示例。
在下文中一共展示了QQuickItem::mapToScene方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mouseWheel
static void mouseWheel(QWindow* window, QObject* item, Qt::MouseButtons buttons,
Qt::KeyboardModifiers stateKey,
QPointF _pos, int xDelta, int yDelta, int delay = -1)
{
QTEST_ASSERT(window);
QTEST_ASSERT(item);
if (delay == -1 || delay < QTest::defaultMouseDelay())
delay = QTest::defaultMouseDelay();
if (delay > 0)
QTest::qWait(delay);
QPoint pos;
QQuickItem *sgitem = qobject_cast<QQuickItem *>(item);
if (sgitem)
pos = sgitem->mapToScene(_pos).toPoint();
QTEST_ASSERT(buttons == Qt::NoButton || buttons & Qt::MouseButtonMask);
QTEST_ASSERT(stateKey == 0 || stateKey & Qt::KeyboardModifierMask);
stateKey &= static_cast<unsigned int>(Qt::KeyboardModifierMask);
QWheelEvent we(pos, window->mapToGlobal(pos), QPoint(0, 0), QPoint(xDelta, yDelta), 0, Qt::Vertical, buttons, stateKey);
QSpontaneKeyEvent::setSpontaneous(&we); // hmmmm
if (!qApp->notify(window, &we))
QTest::qWarn("Wheel event not accepted by receiving window");
}
示例2: mouseEvent
static void mouseEvent(MouseAction _action, QWindow* _window, QObject* _item, Qt::MouseButton _button, Qt::KeyboardModifiers _stateKey, QPointF _pos, int _delay = -1)
{
if (_delay == -1 || _delay < 30)
_delay = 30;
if (_delay > 0)
QTest::qWait(_delay);
if (_action == MouseClick)
{
mouseEvent(MousePress, _window, _item, _button, _stateKey, _pos);
mouseEvent(MouseRelease, _window, _item, _button, _stateKey, _pos);
return;
}
QPoint pos = _pos.toPoint();
QQuickItem* sgitem = qobject_cast<QQuickItem*>(_item);
if (sgitem)
pos = sgitem->mapToScene(_pos).toPoint();
_stateKey &= static_cast<unsigned int>(Qt::KeyboardModifierMask);
QMouseEvent me(QEvent::User, QPoint(), Qt::LeftButton, _button, _stateKey);
switch (_action)
{
case MousePress:
me = QMouseEvent(QEvent::MouseButtonPress, pos, _window->mapToGlobal(pos), _button, _button, _stateKey);
break;
case MouseRelease:
me = QMouseEvent(QEvent::MouseButtonRelease, pos, _window->mapToGlobal(pos), _button, 0, _stateKey);
break;
case MouseDoubleClick:
me = QMouseEvent(QEvent::MouseButtonDblClick, pos, _window->mapToGlobal(pos), _button, _button, _stateKey);
break;
case MouseMove:
// with move event the _button is NoButton, but 'buttons' holds the currently pressed buttons
me = QMouseEvent(QEvent::MouseMove, pos, _window->mapToGlobal(pos), Qt::NoButton, _button, _stateKey);
break;
default:
break;
}
QSpontaneKeyEvent::setSpontaneous(&me);
if (!qApp->notify(_window, &me))
{
static const char* mouseActionNames[] = { "MousePress", "MouseRelease", "MouseClick", "MouseDoubleClick", "MouseMove" };
QString warning = QString::fromLatin1("Mouse event \"%1\" not accepted by receiving window");
QWARN(warning.arg(QString::fromLatin1(mouseActionNames[static_cast<int>(_action)])).toLatin1().data());
}
}
示例3: traverseObject
/*!
Traverse QObject based items.
*/
void SceneGraphTraverse::traverseObject(TasObject* objectInfo, QObject* object, TasCommand* command)
{
Q_UNUSED(command);
QQuickItem* item = qobject_cast<QQuickItem*>(object);
if (item) {
QQmlContext* context = QQmlEngine::contextForObject(object);
if (context) {
QString name = context->nameForObject(object);
objectInfo->addAttribute("QML_ID", name);
}
#ifdef USE_QTQML_PRIVATE_HEADERS
addTypeInfo(item, objectInfo);
#endif
mTraverseUtils->addObjectDetails(objectInfo, object);
objectInfo->addAttribute("objectType", TYPE_QSCENEGRAPH);
QPointF point = item->mapToScene(QPoint());
// needed for visualizer
objectInfo->addAttribute("x", (int)point.x());
objectInfo->addAttribute("y", (int)point.y());
objectInfo->addAttribute("x_absolute", (int)point.x());
objectInfo->addAttribute("y_absolute", (int)point.y());
objectInfo->addAttribute("x_relative", item->x());
objectInfo->addAttribute("y_relative", item->y());
// TODO already included?
objectInfo->addAttribute("width", item->width());
objectInfo->addAttribute("height", item->height());
}
}
示例4: mouseEvent
static void mouseEvent(MouseAction action, QWindow *window,
QObject *item, Qt::MouseButton button,
Qt::KeyboardModifiers stateKey, QPointF _pos, int delay=-1)
{
QTEST_ASSERT(window);
QTEST_ASSERT(item);
if (delay == -1 || delay < QTest::defaultMouseDelay())
delay = QTest::defaultMouseDelay();
if (delay > 0)
QTest::qWait(delay);
if (action == MouseClick) {
mouseEvent(MousePress, window, item, button, stateKey, _pos);
mouseEvent(MouseRelease, window, item, button, stateKey, _pos);
return;
}
if (action == MouseDoubleClickSequence) {
mouseEvent(MousePress, window, item, button, stateKey, _pos);
mouseEvent(MouseRelease, window, item, button, stateKey, _pos);
mouseEvent(MousePress, window, item, button, stateKey, _pos);
mouseEvent(MouseDoubleClick, window, item, button, stateKey, _pos);
mouseEvent(MouseRelease, window, item, button, stateKey, _pos);
return;
}
QPoint pos;
QQuickItem *sgitem = qobject_cast<QQuickItem *>(item);
if (sgitem)
pos = sgitem->mapToScene(_pos).toPoint();
QTEST_ASSERT(button == Qt::NoButton || button & Qt::MouseButtonMask);
QTEST_ASSERT(stateKey == 0 || stateKey & Qt::KeyboardModifierMask);
stateKey &= static_cast<unsigned int>(Qt::KeyboardModifierMask);
QMouseEvent me(QEvent::User, QPoint(), Qt::LeftButton, button, stateKey);
switch (action)
{
case MousePress:
me = QMouseEvent(QEvent::MouseButtonPress, pos, window->mapToGlobal(pos), button, button, stateKey);
break;
case MouseRelease:
me = QMouseEvent(QEvent::MouseButtonRelease, pos, window->mapToGlobal(pos), button, 0, stateKey);
break;
case MouseDoubleClick:
me = QMouseEvent(QEvent::MouseButtonDblClick, pos, window->mapToGlobal(pos), button, button, stateKey);
break;
case MouseMove:
// with move event the button is NoButton, but 'buttons' holds the currently pressed buttons
me = QMouseEvent(QEvent::MouseMove, pos, window->mapToGlobal(pos), Qt::NoButton, button, stateKey);
break;
default:
QTEST_ASSERT(false);
}
QSpontaneKeyEvent::setSpontaneous(&me);
if (!qApp->notify(window, &me)) {
static const char *mouseActionNames[] =
{ "MousePress", "MouseRelease", "MouseClick", "MouseDoubleClick", "MouseMove", "MouseDoubleClickSequence" };
QString warning = QString::fromLatin1("Mouse event \"%1\" not accepted by receiving window");
QWARN(warning.arg(QString::fromLatin1(mouseActionNames[static_cast<int>(action)])).toLatin1().data());
}
}
示例5: getScreenshot
void ScreenshotService::getScreenshot(TasCommandModel& model, TasResponse& response)
{
QListIterator<TasTarget*> i(model.targetList());
QString errorMsg = PARSE_ERROR;
QImage screenshot;
QString pictureFormat = "PNG";
while (i.hasNext()) {
TasTarget* commandTarget = i.next();
QString targetId = commandTarget->id();
QString targetType = commandTarget->type();
TasCommand* command = commandTarget->findCommand("Screenshot");
// are required for command completion
if (targetId.isEmpty() || targetType.isEmpty() || !command) {
continue;
}
if (!command->parameter("format").isEmpty()) {
pictureFormat = command->parameter("format");
}
if (!isFormatSupported(pictureFormat)) {
errorMsg = "Given format " + pictureFormat + "is not supported. Supported formats are: PNG, JPEG and BMP.";
break;
}
bool draw = (command->parameter("draw") == "true");
QWidget* widget = 0;
QQuickWindow* qtQuickWindow = 0;
WId winId = 0;
QRect rect(0,0,-1,-1);
errorMsg = "Taking screenshot failed!";
if (targetType == TYPE_GRAPHICS_VIEW) {
//TasLogger::logger()->debug("TYPE_GRAPHICS_VIEW Target id:" + targetId);
QGraphicsItem* item = findGraphicsItem(targetId);
if (item) {
QGraphicsView* view = getViewForItem(item);
if(view) {
ItemLocationDetails locationDetails = TestabilityUtils::getItemLocationDetails(item);
rect = QRect(locationDetails.windowPoint.x(),
locationDetails.windowPoint.y(),
locationDetails.width,
locationDetails.height);
if (draw) {
widget = view->window();
} else {
winId = view->window()->winId();
}
} else {
errorMsg = "Could not find a GraphicsView for the GraphicsItem!";
}
} else {
errorMsg = "Could not find the GraphicsItem!";
}
} else if (targetType == TYPE_STANDARD_VIEW) {
//TasLogger::logger()->debug("TYPE_STANDARD_VIEW about to find widget Target id:" + targetId);
widget = findWidget(targetId);
if (widget) {
if ((widget->isWindow() && !draw) || widget->inherits("QDesktopWidget")) {
winId = widget->winId();
widget = 0;
} else if (!draw) {
QPoint point = widget->mapToGlobal(QPoint(0,0));
QPoint windowPoint = widget->window()->mapFromGlobal(point);
rect = QRect(windowPoint.x(),
windowPoint.y(),
widget->rect().width(),
widget->rect().width());
winId = widget->window()->winId();
widget = 0;
}
} else {
TasLogger::logger()->debug("ScreenshotService::executeService application has no visible ui!");
errorMsg = "Application has no visible ui!";
}
} else if (targetType == TYPE_QSCENEGRAPH) {
QQuickItem* item = TestabilityUtils::findQuickItem(targetId);
if (item) {
QPointF offset = item->mapToScene(QPointF(0,0));
rect = QRect(-offset.x(), -offset.y(), item->width(), item->height());
qtQuickWindow = item->window();
}
} else {
//TasLogger::logger()->debug("TYPE_APPLICATION_VIEW about to find application window Target id:" + targetId);
widget = getApplicationWidget();
if (!widget) {
QWindow *window = getApplicationWindow();
//in case no window false, return the desktop
qtQuickWindow = qobject_cast<QQuickWindow *>(window);
if (!window) {
//.........这里部分代码省略.........