void QQuickPinchArea::clearPinch() { Q_D(QQuickPinchArea); d->touchPoints.clear(); if (d->inPinch) { d->inPinch = false; QPointF pinchCenter = mapFromScene(d->sceneLastCenter); QQuickPinchEvent pe(pinchCenter, d->pinchLastScale, d->pinchLastAngle, d->pinchRotation); pe.setStartCenter(d->pinchStartCenter); pe.setPreviousCenter(pinchCenter); pe.setPreviousAngle(d->pinchLastAngle); pe.setPreviousScale(d->pinchLastScale); pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); pe.setPoint1(mapFromScene(d->lastPoint1)); pe.setPoint2(mapFromScene(d->lastPoint2)); emit pinchFinished(&pe); if (d->pinch && d->pinch->target()) d->pinch->setActive(false); } d->pinchStartDist = 0; d->pinchActivated = false; d->initPinch = false; d->pinchRejected = false; d->stealMouse = false; d->id1 = -1; QQuickWindow *win = window(); if (win && win->mouseGrabberItem() == this) ungrabMouse(); setKeepMouseGrab(false); }
void Highlight::setItem(QQuickItem *item) { if (m_item) m_item->disconnect(this); if (item) { connect(item, &QQuickItem::xChanged, this, &Highlight::adjust); connect(item, &QQuickItem::yChanged, this, &Highlight::adjust); connect(item, &QQuickItem::widthChanged, this, &Highlight::adjust); connect(item, &QQuickItem::heightChanged, this, &Highlight::adjust); connect(item, &QQuickItem::rotationChanged, this, &Highlight::adjust); connect(item, &QQuickItem::transformOriginChanged, this, &Highlight::adjust); } QQuickWindow *view = item->window(); QQuickItem * contentItem = view->contentItem(); if (contentItem) { connect(contentItem, &QQuickItem::xChanged, this, &Highlight::adjust); connect(contentItem, &QQuickItem::yChanged, this, &Highlight::adjust); connect(contentItem, &QQuickItem::widthChanged, this, &Highlight::adjust); connect(contentItem, &QQuickItem::heightChanged, this, &Highlight::adjust); connect(contentItem, &QQuickItem::rotationChanged, this, &Highlight::adjust); connect(contentItem, &QQuickItem::transformOriginChanged, this, &Highlight::adjust); } m_item = item; setContentsSize(view->size()); adjust(); }
void QQuickMouseArea::mouseReleaseEvent(QMouseEvent *event) { Q_D(QQuickMouseArea); d->stealMouse = false; if (!d->enabled && !d->pressed) { QQuickItem::mouseReleaseEvent(event); } else { d->saveEvent(event); setPressed(event->button(), false); if (!d->pressed) { // no other buttons are pressed #ifndef QT_NO_DRAGANDDROP if (d->drag) d->drag->setActive(false); #endif // If we don't accept hover, we need to reset containsMouse. if (!acceptHoverEvents()) setHovered(false); QQuickWindow *w = window(); if (w && w->mouseGrabberItem() == this) ungrabMouse(); setKeepMouseGrab(false); } } d->doubleClick = false; }
QImage_ *windowGrabWindow(QQuickWindow_ *win) { QQuickWindow *qwin = reinterpret_cast<QQuickWindow *>(win); QImage *image = new QImage; *image = qwin->grabWindow().convertToFormat(QImage::Format_ARGB32_Premultiplied); return image; }
void Highlight::setItem(QQuickItem *item) { if (m_item) m_item->disconnect(this); if (item) { connect(item, SIGNAL(xChanged()), SLOT(adjust())); connect(item, SIGNAL(yChanged()), SLOT(adjust())); connect(item, SIGNAL(widthChanged()), SLOT(adjust())); connect(item, SIGNAL(heightChanged()), SLOT(adjust())); connect(item, SIGNAL(rotationChanged()), SLOT(adjust())); connect(item, SIGNAL(transformOriginChanged(TransformOrigin)), SLOT(adjust())); } QQuickWindow *view = item->window(); QQuickItem * contentItem = view->contentItem(); if (contentItem) { connect(contentItem, SIGNAL(xChanged()), SLOT(adjust())); connect(contentItem, SIGNAL(yChanged()), SLOT(adjust())); connect(contentItem, SIGNAL(widthChanged()), SLOT(adjust())); connect(contentItem, SIGNAL(heightChanged()), SLOT(adjust())); connect(contentItem, SIGNAL(rotationChanged()), SLOT(adjust())); connect(contentItem, SIGNAL(transformOriginChanged(TransformOrigin)), SLOT(adjust())); } m_item = item; setContentsSize(view->size()); adjust(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QStandardItemModel model; model.appendRow(new QStandardItem("Norway")); model.appendRow(new QStandardItem("Netherlands")); model.appendRow(new QStandardItem("New Zealand")); model.appendRow(new QStandardItem("Namibia")); model.appendRow(new QStandardItem("Nicaragua")); model.appendRow(new QStandardItem("North Korea")); model.appendRow(new QStandardItem("Northern Cyprus ")); model.appendRow(new QStandardItem("Sweden")); model.appendRow(new QStandardItem("Denmark")); QStringList strings; strings << "Norway" << "Sweden" << "Denmark"; QQmlApplicationEngine engine; engine.rootContext()->setContextProperty("standardmodel", &model); engine.rootContext()->setContextProperty("stringmodel", strings); engine.load(QUrl("main.qml")); QObject *topLevel = engine.rootObjects().value(0); QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel); if ( !window ) { qWarning("Error: Your root item has to be a Window."); return -1; } window->show(); return app.exec(); }
void QQuickMultiPointTouchArea::touchEvent(QTouchEvent *event) { switch (event->type()) { case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: { //if e.g. a parent Flickable has the mouse grab, don't process the touch events QQuickWindow *c = window(); QQuickItem *grabber = c ? c->mouseGrabberItem() : 0; if (grabber && grabber != this && grabber->keepMouseGrab() && grabber->isEnabled()) { QQuickItem *item = this; while ((item = item->parentItem())) { if (item == grabber) return; } } updateTouchData(event); if (event->type() == QEvent::TouchEnd) ungrab(); break; } case QEvent::TouchCancel: ungrab(); break; default: QQuickItem::touchEvent(event); break; } }
void Highlight::adjust() { if (!m_item) return; bool success = false; m_transform = m_item->itemTransform(0, &success); if (!success) m_transform = QTransform(); setSize(QSizeF(m_item->width(), m_item->height())); qreal scaleFactor = 1; QPointF originOffset = QPointF(0,0); QQuickWindow *view = m_item->window(); if (view->contentItem()) { scaleFactor = view->contentItem()->scale(); originOffset -= view->contentItem()->position(); } // The scale transform for the overlay needs to be cancelled // as the Item's transform which will be applied to the painter // takes care of it. parentItem()->setScale(1/scaleFactor); setPosition(originOffset); update(); }
void createTexture() { if (bufferRef) bufferRef.destroyTexture(); bufferRef = nextBuffer; QQuickWindow *window = static_cast<QQuickWindow *>(surface->mainOutput()->window()); // If the next buffer is NULL do not delete the current texture. If the client called // attach(0) the surface is going to be unmapped anyway, if instead the client attached // a valid buffer but died before we got here we want to keep the old buffer around // in case some destroy animation is run. if (bufferRef) { delete texture; if (bufferRef.isShm()) { texture = window->createTextureFromImage(bufferRef.image()); } else { QQuickWindow::CreateTextureOptions opt = 0; if (surface->useTextureAlpha()) { opt |= QQuickWindow::TextureHasAlphaChannel; } texture = window->createTextureFromId(bufferRef.createTexture(), surface->size(), opt); } texture->bind(); } update = false; }
QuickWindowNodeInstance::Pointer QuickWindowNodeInstance::create(QObject *object) { QQuickWindow *quickWindow = qobject_cast<QQuickWindow*>(object); Q_ASSERT(quickWindow); Pointer instance(new QuickWindowNodeInstance(quickWindow)); instance->setHasContent(anyItemHasContent(quickWindow->contentItem())); quickWindow->contentItem()->setFlag(QQuickItem::ItemHasContents, true); static_cast<QQmlParserStatus*>(quickWindow->contentItem())->classBegin(); instance->populateResetHashes(); QQuickItemPrivate *privateItem = static_cast<QQuickItemPrivate*>(QObjectPrivate::get(quickWindow->contentItem())); if (privateItem->window) { if (!privateItem->parentItem) QQuickWindowPrivate::get(privateItem->window)->parentlessItems.remove(quickWindow->contentItem()); privateItem->derefWindow(); privateItem->window = 0; } return instance; }
void TestService::setTargetWindow(QObject* _window) { QQuickWindow* window = qobject_cast<QQuickWindow*>(_window); if (window) m_targetWindow = window; window->requestActivate(); }
void tst_applicationwindow::defaultFocus() { QQmlEngine engine; QQmlComponent component(&engine); component.loadUrl(testFileUrl("defaultFocus.qml")); QObject* created = component.create(); QScopedPointer<QObject> cleanup(created); Q_UNUSED(cleanup); QVERIFY(created); QQuickWindow* window = qobject_cast<QQuickWindow*>(created); QVERIFY(window); window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); QVERIFY(QGuiApplication::focusWindow() == window); QQuickItem* contentItem = window->contentItem(); QVERIFY(contentItem); QVERIFY(contentItem->hasActiveFocus()); // A single item in an ApplicationWindow with focus: true should receive focus. QQuickItem* item = findItem<QQuickItem>(window->contentItem(), "item"); QVERIFY(item); QVERIFY(item->hasFocus()); QVERIFY(item->hasActiveFocus()); }
// A very simple implementation where we assume that there's only one window and that it's a // QQuickWindow. Thus the id parameter is irrelevant. // // Idea: Make the id contain the objectName of the QQuickWindow once we care about a multi-display // compositor? // Strictly speaking that could be the actual QWindow::winId(), but that's mostly a // meaningless arbitrary number. QImage WindowScreenshotProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) { Q_UNUSED(id); Q_UNUSED(requestedSize); QWindowList windows = QGuiApplication::topLevelWindows(); if (windows.count() != 1) { size->rwidth() = 0; size->rheight() = 0; return QImage(); } QQuickWindow *quickWindow = qobject_cast<QQuickWindow *>(windows[0]); if (!quickWindow) { size->rwidth() = 0; size->rheight() = 0; return QImage(); } QImage image = quickWindow->grabWindow(); size->rwidth() = image.width(); size->rheight() = image.height(); return image; }
void Compositor::onXdgToplevelCreated(QWaylandXdgToplevel *toplevel, QWaylandXdgSurface *shellSurface) //void Compositor::onXdgSurfaceCreated(QWaylandXdgSurface *shellSurface) { unsigned int windowId = mNextWindowId++; QWaylandSurface *surface = shellSurface->surface(); qDebug() << Q_FUNC_INFO << "windowId" << windowId << surface; QQuickWindow *defaultOutputWindow = static_cast<QQuickWindow*>(defaultOutput()->window()); CompositorWindow *window = new CompositorWindow(windowId, defaultOutputWindow->contentItem()); window->setOutput(defaultOutput()); //useful ? window->setFlag(QQuickItem::ItemIsFocusScope, true); // window->setUseTextureAlpha(true); window->initialize(shellSurface); window->setSize(surface->size()); window->setTouchEventsEnabled(true); mWindows.insert(windowId, window); connect(window, &CompositorWindow::readyChanged, this, &Compositor::windowIsReady); connect(window, &QWaylandQuickItem::surfaceDestroyed, this, &Compositor::onSurfaceDestroyed); window->sendWindowIdToClient(); }
QT_BEGIN_NAMESPACE #ifndef QT_NO_WIDGETS #define Application QApplication #else #define Application QGuiApplication #endif int main(int argc, char *argv[]) { Application app(argc, argv); QScreen* sc = app.primaryScreen(); if(sc){ sc->setOrientationUpdateMask(Qt::LandscapeOrientation | Qt::PortraitOrientation | Qt::InvertedLandscapeOrientation | Qt::InvertedPortraitOrientation); } QQmlApplicationEngine engine(QUrl("qrc:/main.qml")); QObject *topLevel = engine.rootObjects().value(0); QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel); if ( !window ) { qWarning("Error: Your root item has to be a Window."); return -1; } window->showFullScreen(); return app.exec(); }
int main(int argc, char ** argv) { QApplication app(argc, argv); qmlRegisterType<Hider>("com.ics.demo", 1, 0, "Hider"); int rc = 0; QQmlEngine engine; QQmlComponent *component = new QQmlComponent(&engine); QObject::connect(&engine, SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit())); component->loadUrl(QUrl("../../Source/main.qml")); Hider::image_provider = new ImageProvider; engine.addImageProvider("images", Hider::image_provider); if (!component->isReady() ) { qWarning("%s", qPrintable(component->errorString())); return -1; } QObject *topLevel = component->create(); QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel); QSurfaceFormat surfaceFormat = window->requestedFormat(); window->setFormat(surfaceFormat); window->show(); rc = app.exec(); delete component; return rc; }
void QQuickWindowAttached::windowChanged(QQuickWindow *window) { if (window != m_window) { QQuickWindow* oldWindow = m_window; m_window = window; if (oldWindow) oldWindow->disconnect(this); if (!window) return; // No values to get, therefore nothing to emit if (!oldWindow || window->visibility() != oldWindow->visibility()) emit visibilityChanged(); if (!oldWindow || window->isActive() != oldWindow->isActive()) emit activeChanged(); if (!oldWindow || window->activeFocusItem() != oldWindow->activeFocusItem()) emit activeFocusItemChanged(); emit contentItemChanged(); // QQuickWindowQmlImpl::visibilityChanged also exists, and window might even // be QQuickWindowQmlImpl, but that's not what we are connecting to. // So this is actual window state rather than a buffered or as-requested one. // If we used the metaobject connect syntax there would be a warning: // QMetaObjectPrivate::indexOfSignalRelative - QMetaObject::indexOfSignal: // signal visibilityChanged(QWindow::Visibility) from QQuickWindow redefined in QQuickWindowQmlImpl connect(window, &QQuickWindow::visibilityChanged, this, &QQuickWindowAttached::visibilityChanged); connect(window, &QQuickWindow::activeChanged, this, &QQuickWindowAttached::activeChanged); connect(window, &QQuickWindow::activeFocusItemChanged, this, &QQuickWindowAttached::activeFocusItemChanged); } }
int main(int argc, char* argv[]) { QtSingleApplication app(argc, argv); if (app.isRunning()) return 0; app.setApplicationName(CODE_NAME); app.setApplicationVersion(APPLICATION_VERSION); // TODO: session management testcase // http://marc.info/?l=kde-core-devel&m=144832700109449 // KDEBUG-341930 // perhaps we need to wait Qt5.9.x to fix it ;-) //app.setQuitOnLastWindowClosed(false); I18N i18n(TRANSLATIONS_PATH, APPLICATION_ENCODING); i18n.translate(); qmlRegisterType<QwxUUID>("cn.com.isoft.qwx", 1, 0, "QwxUUID"); qmlRegisterType<Scan>("cn.com.isoft.qwx", 1, 0, "Scan"); qmlRegisterType<Cookie>("cn.com.isoft.qwx", 1, 0, "Cookie"); qmlRegisterType<StatReport>("cn.com.isoft.qwx", 1, 0, "StatReport"); qmlRegisterType<Init>("cn.com.isoft.qwx", 1, 0, "Init"); qmlRegisterType<Sync>("cn.com.isoft.qwx", 1, 0, "Sync"); qmlRegisterType<Contact>("cn.com.isoft.qwx", 1, 0, "Contact"); qmlRegisterType<HeadImg>("cn.com.isoft.qwx", 1, 0, "HeadImg"); qmlRegisterType<StatusNotify>("cn.com.isoft.qwx", 1, 0, "StatusNotify"); qmlRegisterType<SendMsg>("cn.com.isoft.qwx", 1, 0, "SendMsg"); qmlRegisterType<Monitor>("cn.com.isoft.qwx", 1, 0, "Monitor"); qmlRegisterType<GetMsg>("cn.com.isoft.qwx", 1, 0, "GetMsg"); qmlRegisterType<CircleImage>("cn.com.isoft.qwx", 1, 0, "CircleImage"); qmlRegisterType<Process>("cn.com.isoft.qwx", 1, 0, "Process"); qmlRegisterType<XiaoDouBi>("cn.com.isoft.qwx", 1, 0, "XiaoDouBi"); qmlRegisterType<ChatLog>("cn.com.isoft.qwx", 1, 0, "ChatLog"); qmlRegisterType<Emotion>("cn.com.isoft.qwx", 1, 0, "Emotion"); qmlRegisterType<LogOut>("cn.com.isoft.qwx", 1, 0, "LogOut"); qmlRegisterType<IpCity>("cn.com.isoft.qwx", 1, 0, "IpCity"); qmlRegisterType<Weather>("cn.com.isoft.qwx", 1, 0, "Weather"); qmlRegisterType<Clipboard>("cn.com.isoft.qwx", 1, 0, "Clipboard"); QQmlApplicationEngine engine(QUrl("qrc:/qml/main.qml")); QObject* topLevel = engine.rootObjects().value(0); QQuickWindow* window = qobject_cast<QQuickWindow*>(topLevel); if (!window) { qWarning("Error: Your root item has to be a Window."); return -1; } // FIXME: it does not work for KWin 5.7.x // https://blog.martin-graesslin.com/blog/2016/07/multi-screen-woes-in-plasma-5-7/ // Newly opened windows not placed on the primary screen #if QWX_DEBUG qDebug() << "DEBUG:" << app.primaryScreen()->availableGeometry(); #endif window->setScreen(app.primaryScreen()); window->show(); return app.exec(); }
/*------------------------------------------------------------------------------ | OpenMAXILPlayerControl::appendCommand +-----------------------------------------------------------------------------*/ void OpenMAXILPlayerControl::appendCommand(PlayerCommand* command) { QMutexLocker locker(&m_pendingCommandsMutex); m_pendingCommands.append(command); QQuickWindow* window = m_quickItem->window(); if (window) window->update(); }
bool QQuickMouseArea::sendMouseEvent(QMouseEvent *event) { Q_D(QQuickMouseArea); QPointF localPos = mapFromScene(event->windowPos()); QQuickWindow *c = window(); QQuickItem *grabber = c ? c->mouseGrabberItem() : 0; bool stealThisEvent = d->stealMouse; if ((stealThisEvent || contains(localPos)) && (!grabber || !grabber->keepMouseGrab())) { QMouseEvent mouseEvent(event->type(), localPos, event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers()); mouseEvent.setAccepted(false); switch (event->type()) { case QEvent::MouseMove: mouseMoveEvent(&mouseEvent); break; case QEvent::MouseButtonPress: mousePressEvent(&mouseEvent); break; case QEvent::MouseButtonRelease: mouseReleaseEvent(&mouseEvent); stealThisEvent = d->stealMouse; break; default: break; } grabber = c ? c->mouseGrabberItem() : 0; if (grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this) grabMouse(); return stealThisEvent; } if (event->type() == QEvent::MouseButtonRelease) { if (d->pressed) { d->pressed &= ~event->button(); emit pressedButtonsChanged(); if (!d->pressed) { // no other buttons are pressed d->stealMouse = false; if (c && c->mouseGrabberItem() == this) ungrabMouse(); emit canceled(); emit pressedChanged(); emit containsPressChanged(); if (d->hovered) { d->hovered = false; emit hoveredChanged(); } } } } return false; }
void QuickMozView::itemChange(ItemChange change, const ItemChangeData &) { if (change == ItemSceneChange) { QQuickWindow *win = window(); if (!win) return; connect(win, SIGNAL(beforeRendering()), this, SLOT(beforeRendering()), Qt::DirectConnection); connect(win, SIGNAL(sceneGraphInitialized()), this, SLOT(sceneGraphInitialized()), Qt::DirectConnection); win->setClearBeforeRendering(false); } }
QRect QAccessibleQuickItem::viewRect() const { // ### no window in some cases. if (!item()->window()) { return QRect(); } QQuickWindow *window = item()->window(); QPoint screenPos = window->mapToGlobal(QPoint(0,0)); return QRect(screenPos, window->size()); }
Handle<Value> QuickWindowWrap::show(const Arguments& args) { HandleScope scope; QuickWindowWrap *obj_wrap = ObjectWrap::Unwrap<QuickWindowWrap>(args.This()); QQuickWindow *view = obj_wrap->GetObject(); view->setFormat(view->requestedFormat()); view->show(); return scope.Close(Undefined()); }
/*! \reimp */ QSGTextureProvider *QQuickPaintedItem::textureProvider() const { Q_D(const QQuickPaintedItem); QQuickWindow *w = window(); if (!w || !w->openglContext() || QThread::currentThread() != w->openglContext()->thread()) { qWarning("QQuickPaintedItem::textureProvider: can only be queried on the rendering thread of an exposed window"); return 0; } if (!d->textureProvider) d->textureProvider = new QQuickPaintedItemTextureProvider(); d->textureProvider->node = d->node; return d->textureProvider; }
void QuickMozView::itemChange(ItemChange change, const ItemChangeData &) { if (change == ItemSceneChange) { QQuickWindow *win = window(); if (!win) return; // All of these signals are emitted from scene graph rendering thread. connect(win, SIGNAL(beforeRendering()), this, SLOT(refreshNodeTexture()), Qt::DirectConnection); connect(win, SIGNAL(beforeSynchronizing()), this, SLOT(createThreadRenderObject()), Qt::DirectConnection); connect(win, SIGNAL(sceneGraphInvalidated()), this, SLOT(clearThreadRenderObject()), Qt::DirectConnection); win->setClearBeforeRendering(false); } }
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; //qmlRegisterType<NetworkComm>("Networking", 1, 0, "Networkcomm"); qmlRegisterType<FileIO, 1>("FileIO", 1, 0, "FileIO"); engine.load(QUrl("qrc:/main.qml")); QObject *topLevel = engine.rootObjects().value(0); QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel); //engine.load(QUrl("qrc:/main.qml")); window->show(); return app.exec(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); Vibrator vibrator; QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); QQuickWindow *window = qobject_cast<QQuickWindow *>(engine.rootObjects().first()); window->showFullScreen(); engine.rootContext()->setContextProperty("Vibrator", &vibrator); return app.exec(); }
/*------------------------------------------------------------------------------ | OpenMAXILPlayerControl::onItemSceneChanged +-----------------------------------------------------------------------------*/ void OpenMAXILPlayerControl::onItemSceneChanged() { QQuickWindow* window = m_quickItem->window(); if (!window) return; connect(window, SIGNAL(sceneGraphInitialized()), this, SLOT(onSceneGraphInitialized()), Qt::DirectConnection); connect(window, SIGNAL(afterRendering()), this, SLOT(onAfterRendering()), Qt::DirectConnection); window->update(); }
void WindowManager::registerQuickItem( QQuickItem* item ) { if ( !item ) return; QQuickWindow *window = item->window(); if (window) { QQuickItem *contentItem = window->contentItem(); contentItem->setAcceptedMouseButtons( Qt::LeftButton ); contentItem->removeEventFilter( this ); contentItem->installEventFilter( this ); } }
void AbstractThumbnailItem::findParentEffectWindow() { if (effects) { QQuickWindow *qw = window(); if (!qw) { qDebug() << "No QQuickWindow assigned yet"; return; } if (auto *w = static_cast<EffectWindowImpl*>(effects->findWindow(qw->winId()))) { m_parent = QWeakPointer<EffectWindowImpl>(w); } } }