Ejemplo n.º 1
0
void QuickItemModel::itemReparented()
{
  QQuickItem *item = qobject_cast<QQuickItem*>(sender());
  if (!item || item->window() != m_window)
    return;

  QQuickItem* sourceParent = m_childParentMap.value(item);
  Q_ASSERT(sourceParent);
  const QModelIndex sourceParentIndex = indexForItem(sourceParent);

  QVector<QQuickItem*> &sourceSiblings = m_parentChildMap[sourceParent];
  QVector<QQuickItem*>::iterator sit = std::lower_bound(sourceSiblings.begin(), sourceSiblings.end(), item);
  Q_ASSERT(sit != sourceSiblings.end() && *sit == item);
  const int sourceRow = std::distance(sourceSiblings.begin(), sit);

  QQuickItem* destParent = item->parentItem();
  Q_ASSERT(destParent);
  const QModelIndex destParentIndex = indexForItem(destParent);

  QVector<QQuickItem*> &destSiblings = m_parentChildMap[destParent];
  QVector<QQuickItem*>::iterator dit = std::lower_bound(destSiblings.begin(), destSiblings.end(), item);
  const int destRow = std::distance(destSiblings.begin(), dit);

  beginMoveRows(sourceParentIndex, sourceRow, sourceRow, destParentIndex, destRow);
  destSiblings.insert(dit, item);
  sourceSiblings.erase(sit);
  m_childParentMap.insert(item, destParent);
  endMoveRows();
}
Ejemplo n.º 2
0
void QuickItemModel::objectAdded(QObject* obj)
{
  Q_ASSERT(thread() == QThread::currentThread());
  QQuickItem *item = qobject_cast<QQuickItem*>(obj);
  if (!item)
    return;

  if (item->window() != m_window)
    return; // item for a different scene

  if (m_childParentMap.contains(item))
    return; // already known

  QQuickItem *parentItem = item->parentItem();
  if (parentItem) {
    // add parent first, if we don't know that yet
    if (!m_childParentMap.contains(parentItem))
      objectAdded(parentItem);
  }

  connectItem(item);

  const QModelIndex index = indexForItem(parentItem);
  Q_ASSERT(index.isValid() || !parentItem);

  QVector<QQuickItem*> &children = m_parentChildMap[parentItem];
  QVector<QQuickItem*>::iterator it = std::lower_bound(children.begin(), children.end(), obj);
  const int row = std::distance(children.begin(), it);

  beginInsertRows(index, row, row);
  children.insert(it, item);
  m_childParentMap.insert(item, parentItem);
  endInsertRows();
}
Ejemplo n.º 3
0
QT_BEGIN_NAMESPACE

QQuickItem *QQuickTextUtil::createCursor(
    QQmlComponent *component, QQuickItem *parent, const QRectF &rectangle, const char *className)
{
    QQuickItem *item = 0;
    if (component->isReady()) {
        QQmlContext *creationContext = component->creationContext();

        if (QObject *object = component->beginCreate(creationContext
                              ? creationContext
                              : qmlContext(parent))) {
            if ((item = qobject_cast<QQuickItem *>(object))) {
                QQml_setParent_noEvent(item, parent);
                item->setParentItem(parent);
                item->setPosition(rectangle.topLeft());
                item->setHeight(rectangle.height());
            } else {
                qmlInfo(parent) << tr("%1 does not support loading non-visual cursor delegates.")
                                .arg(QString::fromUtf8(className));
            }
            component->completeCreate();
            return item;
        }
    } else if (component->isLoading()) {
        QObject::connect(component, SIGNAL(statusChanged(QQmlComponent::Status)),
                         parent, SLOT(createCursor()), Qt::UniqueConnection);
        return item;
    }
    qmlInfo(parent, component->errors()) << tr("Could not load cursor delegate");
    return item;
}
bool QmlProfilerTraceView::hasValidSelection() const
{
    QQuickItem *rootObject = d->m_mainView->rootObject();
    if (rootObject)
        return rootObject->property("selectionRangeReady").toBool();
    return false;
}
Ejemplo n.º 5
0
void GuiItem::findGui()
{
    if (m_gui)
        return;

//    // Disconnect from an external sender
//    QObject *sender = QObject::sender();
//    if (sender && this != sender)
//        sender->disconnect(this);

    // Work up the tree until the next Figure item is found.
    QQuickItem *newParent = parentItem();
    if (!newParent) return; // Either being deleted or instantiated
    GuiBase *guiObj;
    while (true) {
        guiObj = qobject_cast<GuiBase*>(newParent);
        if (guiObj)
            break;
        if (!newParent->parentItem()) {
            connect(newParent, &QQuickItem::parentChanged, this, &GuiItem::findGui);
            return;
        }
        newParent = newParent->parentItem();
    }

    if (guiObj) {
        disconnect(this, &QQuickItem::parentChanged, this, &GuiItem::findGui);
        setGui(guiObj);
    }
}
void QQuickWebEngineViewPrivate::passOnFocus(bool reverse)
{
    Q_Q(QQuickWebEngineView);
    // The child delegate currently has focus, find the next one from there and give it focus.
    QQuickItem *next = q->scopedFocusItem()->nextItemInFocusChain(!reverse);
    next->forceActiveFocus(reverse ? Qt::BacktabFocusReason : Qt::TabFocusReason);
}
Ejemplo n.º 7
0
void tst_QQuickAccessible::ignoredTest()
{
    QScopedPointer<QQuickView> window(new QQuickView());
    window->setSource(testFileUrl("ignored.qml"));
    window->show();

    QQuickItem *contentItem = window->contentItem();
    QVERIFY(contentItem);
    QQuickItem *rootItem = contentItem->childItems().first();
    QVERIFY(rootItem);

    // the window becomes active
    QAccessible::State activatedChange;
    activatedChange.active = true;

    QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(window.data());
    QVERIFY(iface);
    QAccessibleInterface *rectangleA = iface->child(0);

    QCOMPARE(rectangleA->role(), QAccessible::StaticText);
    QCOMPARE(rectangleA->text(QAccessible::Name), QLatin1String("A"));
    static const char *expected = "BEFIHD";
    // check if node "C" and "G" is skipped and that the order is as expected.
    for (int i = 0; i < rectangleA->childCount(); ++i) {
        QAccessibleInterface *child = rectangleA->child(i);
        QCOMPARE(child->text(QAccessible::Name), QString(QLatin1Char(expected[i])));
    }
    QTestAccessibility::clearEvents();
}
Ejemplo n.º 8
0
/* Q_INVOKABLE */ void WWindow::clearFocusItem(QQuickItem * item)
#endif
{
    Q_ASSERT(item);

#ifdef QT_4
    if (item->focusItem())
    {
        setFocus(true);
    }
#else
    Q_D(WWindow);

    QQuickItem * parent = d->view->activeFocusItem();

    while (parent)
    {
        parent = parent->parentItem();

        if (parent == item)
        {
            setFocus(true);

            return;
        }
    }
#endif
}
Ejemplo n.º 9
0
void Fix8Log::aboutSlot()
{

    QDialog *aboutDialog = new QDialog();
    QVBoxLayout *aboutLayout = new QVBoxLayout(0);

    QDialogButtonBox *dialogButtonBox = new QDialogButtonBox();

    dialogButtonBox->addButton(QDialogButtonBox::Ok);
    connect(dialogButtonBox,SIGNAL(clicked(QAbstractButton*)),
            aboutDialog,SLOT(close()));

    QQuickView *aboutView = new QQuickView(QUrl("qrc:qml/helpAbout.qml"));
    QQuickItem *qmlObject = aboutView->rootObject();
    qmlObject->setProperty("color",aboutDialog->palette().color(QPalette::Window));
    qmlObject->setProperty("bgColor",aboutDialog->palette().color(QPalette::Window));
    qmlObject->setProperty("version",QString::number(Globals::version));

    aboutView->setResizeMode(QQuickView::SizeRootObjectToView);

    QWidget *aboutWidget = QWidget::createWindowContainer(aboutView,0);
    aboutWidget->setPalette(aboutDialog->palette());
    aboutWidget->setAutoFillBackground(false);
    aboutDialog->setLayout(aboutLayout);

    aboutLayout->addWidget(aboutWidget,1);
    aboutLayout->addWidget(dialogButtonBox,0);
    aboutDialog->resize(500,400);
    aboutDialog->setWindowTitle(GUI::Globals::appName);
    aboutDialog->exec();
    aboutDialog->deleteLater();

}
Ejemplo n.º 10
0
qint64 QmlProfilerTraceView::selectionEnd() const
{
    QQuickItem *rootObject = d->m_mainView->rootObject();
    if (rootObject)
        return rootObject->property("selectionRangeEnd").toLongLong();
    return 0;
}
Ejemplo n.º 11
0
Web3DOverlay::~Web3DOverlay() {
    if (_webSurface) {
        QQuickItem* rootItem = _webSurface->getRootItem();

        if (rootItem && rootItem->objectName() == "tabletRoot") {
            auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
            tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", nullptr);
        }

        // Fix for crash in QtWebEngineCore when rapidly switching domains
        // Call stop on the QWebEngineView before destroying OffscreenQMLSurface.
        if (rootItem) {
            QObject* obj = rootItem->findChild<QObject*>("webEngineView");
            if (obj) {
                // stop loading
                QMetaObject::invokeMethod(obj, "stop");
            }
        }

        _webSurface->pause();
        auto overlays = &(qApp->getOverlays());
        QObject::disconnect(overlays, &Overlays::mousePressOnOverlay, this, nullptr);
        QObject::disconnect(overlays, &Overlays::mouseReleaseOnOverlay, this, nullptr);
        QObject::disconnect(overlays, &Overlays::mouseMoveOnOverlay, this, nullptr);
        QObject::disconnect(overlays, &Overlays::hoverLeaveOverlay, this, nullptr);
        QObject::disconnect(this, &Web3DOverlay::scriptEventReceived, _webSurface.data(), &OffscreenQmlSurface::emitScriptEvent);
        QObject::disconnect(_webSurface.data(), &OffscreenQmlSurface::webEventReceived, this, &Web3DOverlay::webEventReceived);
        DependencyManager::get<OffscreenQmlSurfaceCache>()->release(QML, _webSurface);
        _webSurface.reset();
    }
    auto geometryCache = DependencyManager::get<GeometryCache>();
    if (geometryCache) {
        geometryCache->releaseID(_geometryId);
    }
}
Ejemplo n.º 12
0
    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");
    }
Ejemplo n.º 13
0
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());
}
Ejemplo n.º 14
0
void QmlProfilerTraceView::changeEvent(QEvent *e)
{
    if (e->type() == QEvent::EnabledChange) {
        QQuickItem *rootObject = d->m_mainView->rootObject();
        rootObject->setProperty("enabled", isEnabled());
    }
}
Ejemplo n.º 15
0
// Copied with minor modifications from qtdeclarative/src/quick/items/qquickwindow.cpp
QMouseEvent *TouchDispatcher::touchToMouseEvent(
        QEvent::Type type, const QTouchEvent::TouchPoint &p,
        ulong timestamp, Qt::KeyboardModifiers modifiers,
        bool transformNeeded)
{
    QQuickItem *item = m_targetItem.data();

    // The touch point local position and velocity are not yet transformed.
    QMouseEvent *me = new QMouseEvent(type, transformNeeded ? item->mapFromScene(p.scenePos()) : p.pos(),
                                      p.scenePos(), p.screenPos(), Qt::LeftButton,
                                      (type == QEvent::MouseButtonRelease ? Qt::NoButton : Qt::LeftButton),
                                      modifiers);
    me->setAccepted(true);
    me->setTimestamp(timestamp);
    QVector2D transformedVelocity = p.velocity();
    if (transformNeeded) {
        QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
        QMatrix4x4 transformMatrix(itemPrivate->windowToItemTransform());
        transformedVelocity = transformMatrix.mapVector(p.velocity()).toVector2D();
    }

    // Add these later if needed:
    //QGuiApplicationPrivate::setMouseEventCapsAndVelocity(me, event->device()->capabilities(), transformedVelocity);
    //QGuiApplicationPrivate::setMouseEventSource(me, Qt::MouseEventSynthesizedByQt);
    return me;
}
Ejemplo n.º 16
0
void zLayout::layoutSolved(LayoutProblem &prob)
{
    //printf("LayoutSolved(%p)\n", this);

    int j=0;
    for(int i=0; i<childItems().size(); ++i)
    {
        QQuickItem *obj = dynamic_cast<QQuickItem*>(childItems()[i]);
        if(QString("QQuickRepeater") == obj->metaObject()->className())
            continue;
        if(QString("zImplicitLabel") == obj->metaObject()->className())
            continue;
        BBox *box = m_ch[j];
        if(!box->y.solved) {
            //XXX weird bug
            printf("----Weird Bug\n");
            return;
        }
        assert(box->y.solved);
        box->y.solve(box->y.solution+layoutY());
        //printf("Setting <%s>(%f,%f,%f,%f)\n", obj->metaObject()->className(),
        //        box->x.solution, box->y.solution, box->w.solution, box->h.solution);
        setBounds(*obj, *box);
        if(auto *obj_=dynamic_cast<zWidget*>(obj)) {
            obj_->layoutSolved(prob);
        }
        j++;
    }
}
Ejemplo n.º 17
0
/*!
 * Copies command data to execute queue. GUI thread must be locked when this
 * method is called.
 */
void CanvasGlCommandQueue::transferCommands(QVector<GlCommand> &executeQueue)
{
    memcpy(executeQueue.data(), m_queue.data(), m_queuedCount * sizeof(GlCommand));

    m_queuedCount = 0;

    // Grab texture providers from quick items and cache them
    const int quickItemCount = m_quickItemsAsTextureList.size();
    if (quickItemCount) {
        for (int i = 0; i < quickItemCount; i++) {
            const ItemAndId *itemAndId = m_quickItemsAsTextureList.at(i);
            if (!itemAndId->itemPtr.isNull()) {
                QQuickItem *quickItem = itemAndId->itemPtr.data();
                QSGTextureProvider *texProvider = quickItem->textureProvider();
                if (texProvider) {
                    // Make sure the old provider, if any, gets cleared up before inserting a new one
                    delete m_providerCache.take(itemAndId->id);
                    m_providerCache.insert(itemAndId->id,
                                           new ProviderCacheItem(texProvider, quickItem));
                    // Reset the mapped glId so it gets resolved at render time
                    setGlIdToMap(itemAndId->id, 0,
                                 CanvasGlCommandQueue::internalClearQuickItemAsTexture);
                } else {
                    qCWarning(canvas3drendering).nospace() << "CanvasGlCommandQueue::"
                                                           << __FUNCTION__
                                                           << ": The Quick item doesn't implement a texture provider: "
                                                           << quickItem;
                }
            }
        }
        clearQuickItemAsTextureList();
    }
}
Ejemplo n.º 18
0
void KonvergoWindow::playerWindowVisible(bool visible)
{
  // adjust webengineview transparecy depending on player visibility
  QQuickItem *web = findChild<QQuickItem *>("web");
  if (web)
    web->setProperty("backgroundColor", visible ? "transparent" : "#111111");
}
Ejemplo n.º 19
0
void PaperManager::deletePaper(const QVariant & var)
{
    QQuickItem *paper = var.value<QQuickItem*>();
    if( !paper )
        return;

    const int paperId = paper->property("paperItem").toInt();
    if( paperId == -1 )
        return;

    const int bufferIdx  = p->buffer.indexOf(paper);
    const int currentIdx = (p->current==0)? p->current + bufferIdx : p->current + bufferIdx -1;

    if( currentIdx != p->current )
        return;

    p->papers.removeAll(paperId);
    int nextId = (p->current<p->papers.count())? p->papers.at(p->current) : -1;

    paper->setProperty("paperItem", -1 );
    paper->setProperty("paperItem", nextId );

    Papyrus::database()->deletePaper(paperId);
    reindexBuffer();
    load_buffers();
    emit papersChanged();
}
Ejemplo n.º 20
0
QQuickItem *GlobalFunctions::itemAt(QQuickItem* parent, int x, int y, QJSValue matcher)
{
    if (!parent) return nullptr;
    QList<QQuickItem *> children = QQuickItemPrivate::get(parent)->paintOrderChildItems();

    for (int i = children.count() - 1; i >= 0; --i) {
        QQuickItem *child = children.at(i);

        // Map coordinates to the child element's coordinate space
        QPointF point = parent->mapToItem(child, QPointF(x, y));
        if (child->isVisible() && point.x() >= 0
                && child->width() >= point.x()
                && point.y() >= 0
                && child->height() >= point.y()) {
            if (!matcher.isCallable()) return child;

            QQmlEngine* engine = qmlEngine(child);
            if (!engine) return child;

            QJSValue newObj = engine->newQObject(child);
            if (matcher.call(QJSValueList() << newObj).toBool()) {
                return child;
            }
        }
    }
    return nullptr;
}
Ejemplo n.º 21
0
void QQuickLoaderPrivate::setInitialState(QObject *obj)
{
    Q_Q(QQuickLoader);

    QQuickItem *item = qmlobject_cast<QQuickItem*>(obj);
    if (item) {
        // If the item doesn't have an explicit size, but the Loader
        // does, then set the item's size now before bindings are
        // evaluated, otherwise we will end up resizing the item
        // later and triggering any affected bindings/anchors.
        if (widthValid && !QQuickItemPrivate::get(item)->widthValid)
            item->setWidth(q->width());
        if (heightValid && !QQuickItemPrivate::get(item)->heightValid)
            item->setHeight(q->height());
        item->setParentItem(q);
    }
    if (obj) {
        QQml_setParent_noEvent(itemContext, obj);
        QQml_setParent_noEvent(obj, q);
        itemContext = 0;
    }

    if (initialPropertyValues.isUndefined())
        return;

    QQmlComponentPrivate *d = QQmlComponentPrivate::get(component);
    Q_ASSERT(d && d->engine);
    QV4::ExecutionEngine *v4 = qmlGlobalForIpv.engine();
    Q_ASSERT(v4);
    QV4::Scope scope(v4);
    QV4::ScopedValue ipv(scope, initialPropertyValues.value());
    d->initializeObjectWithInitialProperties(qmlGlobalForIpv, ipv, obj);
}
Ejemplo n.º 22
0
MnemonicAttached::MnemonicAttached(QObject *parent)
    : QObject(parent)
{
    QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent);
    if (parentItem) {
        if (parentItem->window()) {
            m_window = parentItem->window();
            m_window->installEventFilter(this);
        }
        connect(parentItem, &QQuickItem::windowChanged, this,
                [this](QQuickWindow *window) {
            if (m_window) {
                QWindow *renderWindow = QQuickRenderControl::renderWindowFor(m_window);
                if (renderWindow) {
                    renderWindow->removeEventFilter(this);
                } else {
                    m_window->removeEventFilter(this);
                }
            }
            m_window = window;
            if (m_window) {
                QWindow *renderWindow = QQuickRenderControl::renderWindowFor(m_window);
                //renderWindow means the widget is rendering somewhere else, like a QQuickWidget
                if (renderWindow && renderWindow != m_window) {
                    renderWindow->installEventFilter(this);
                } else {
                    m_window->installEventFilter(this);
                }
            }
        });
    }
}
Ejemplo n.º 23
0
bool Navigation::dispatchNavigationEvent(NavEvent *event)
{
    if (event->key() == Navigation::Undefined)
        return false;

    QObject * receiver = QGuiApplication::focusObject();

    while (receiver && !event->isAccepted())
    {
        // Send to object
        QCoreApplication::sendEvent(receiver, event);

        if (!event->isAccepted())
        {
            // Send to attached item
            QObject * attachee = qmlAttachedPropertiesObject<Navigation>(receiver, false);

            if (attachee)
                QCoreApplication::sendEvent(attachee, event);

            // Try parent next, visual items if Quick items
            QQuickItem * qItem = qobject_cast<QQuickItem *>(receiver);
            if (qItem && qItem->parentItem())
                receiver = qItem->parentItem();
            else
                receiver = receiver->parent();
        }
    }

    return event->isAccepted();
}
Ejemplo n.º 24
0
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;
    }
}
Ejemplo n.º 25
0
void IconDialog::open()
{
    if (m_dialog->isVisible()) {
        return;
    }

    QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
    QQuickWindow *parentWindow = (parentItem ? parentItem->window() : qobject_cast<QQuickWindow *>(parent()));

    if (m_modality == Qt::NonModal) {
        m_dialog->setModal(false);
    } else if (m_modality == Qt::WindowModal) {
        m_dialog->winId(); // needed to get the windowHandle prior to showing
        m_dialog->windowHandle()->setTransientParent(parentWindow);
        m_dialog->setModal(false); // WindowModal does not unset the overall modality
    } else if (m_modality == Qt::ApplicationModal) {
        m_dialog->setModal(true);
    }

    m_dialog->setWindowModality(m_modality);

    m_dialog->setup(KIconLoader::NoGroup, KIconLoader::Application, false, m_iconSize, m_user);

    m_dialog->show();
}
Ejemplo n.º 26
0
/////////////////////////////////////////////////////////
// Goto source location
void QmlProfilerTraceView::updateCursorPosition()
{
    QQuickItem *rootObject = d->m_mainView->rootObject();
    emit gotoSourceLocation(rootObject->property("fileName").toString(),
                            rootObject->property("lineNumber").toInt(),
                            rootObject->property("columnNumber").toInt());
}
Ejemplo n.º 27
0
void Packet::update_dest_pos(Node *node)
{
    std::pair<int,int> dest_loc = location(node);
    QQuickItem *item = qobject_cast<QQuickItem*>(pac_obj);
    item->setProperty("dest_x", dest_loc.first+offset);
    item->setProperty("dest_y", dest_loc.second+offset);
}
Ejemplo n.º 28
0
int FloodingRT::view_full_table(QQmlApplicationEngine *engine, QQuickItem *panel)
{
    //===============================
    //Populate Flooding Routing Table
    //===============================
    // Check to make sure all vectors are of the same size
    if (destination_node_pool.size() != gateway_node_pool.size() ||
            gateway_node_pool.size() != weight_pool.size() ||
            weight_pool.size() != destination_node_pool.size())
        return -1; // return -1 for an error
    // Get the iterators for the different vectors
    std::vector<Node*>::iterator dest_iter = destination_node_pool.begin();
    std::vector<Node*>::iterator gate_iter = gateway_node_pool.begin();
    std::vector<int>::iterator weight_iter = weight_pool.begin();
    // Creating a QObject for the routing table model, this is where
    // all of the items get added to
    QQmlComponent comp(engine, QUrl("qrc:/qml_files/flooding_model.qml"));
    QObject *object = comp.create();
    QQuickItem *model = qobject_cast<QQuickItem*>(object);
    /*
    // While loop setup - Make sure all iterators are not at the end
    while (dest_iter != destination_node_pool.end() &&
           gate_iter != gateway_node_pool.end() &&
           weight_iter != weight_pool.end())
    {
        // Grab the reference to the next item in each vector
        // This is the information for a row in the routing table
        Node *dest = *dest_iter;
        Node *gate = *gate_iter;
        int weight = *weight_iter;
        // Creating the routing table item QObject
        QQmlComponent component(engine, QUrl("qrc:/qml_files/flooding_item.qml"));
        object = component.create();
        QQuickItem *item = qobject_cast<QQuickItem*>(object);
        // Setting the properties of the QObject
        item->setProperty("destination", dest->get_name());
        item->setProperty("gateway", gate->get_name());
        item->setProperty("weight", weight);
        // Adding the routing table item to the model
        item->setParentItem(model);
        // Moving the iterators to the next item
        dest_iter++;
        gate_iter++;
        weight_iter++;
    }
    */
    // Create the routing table to actually be displayed
    QQmlComponent comp1(engine, QUrl("qrc:/qml_files/flooding_routing_table.qml"));
    QObject *obj = comp1.create();
    QQuickItem *routing_table = qobject_cast<QQuickItem*>(obj);
    obj->findChild<QObject*>("table");
    model->setParentItem(routing_table);
    obj->setProperty("model", "flooding_routing_table_model");

    // Add the routing table to the main panel for viewing
    routing_table->setParentItem(panel);

    return 0;
}//end of view_full_table
Ejemplo n.º 29
0
QImage ImageHandler::extractQImage(QObject *imageObj, int offsetX, int offsetY, int width, int height)
{
    QImage img;
#if defined(QZXING_QML)
#if QT_VERSION >= 0x050000
    QQuickItem *item = qobject_cast<QQuickItem *>(imageObj);

    if (!item || !item->window()->isVisible()) {
        return QImage();
    }

    QTime timer;
    timer.start();
    QSharedPointer<QQuickItemGrabResult> result = item->grabToImage();
    pendingGrabbersLocker.lockForWrite();
    pendingGrabbers << result.data();
    pendingGrabbersLocker.unlock();

    connect(result.data(), &QQuickItemGrabResult::ready, this, &ImageHandler::imageGrabberReady);
    while (timer.elapsed() < 1000) {
        pendingGrabbersLocker.lockForRead();
        if (!pendingGrabbers.contains(result.data())) {
            pendingGrabbersLocker.unlock();
            break;
        }
        pendingGrabbersLocker.unlock();
        qApp->processEvents();
        QThread::yieldCurrentThread();
    }
    img = result->image();
#else
    QGraphicsObject *item = qobject_cast<QGraphicsObject*>(imageObj);

    if (!item) {
        return QImage();
    }

    img = QImage(item->boundingRect().size().toSize(), QImage::Format_RGB32);
    img.fill(QColor(255, 255, 255).rgb());
    QPainter painter(&img);
    QStyleOptionGraphicsItem styleOption;
    item->paint(&painter, &styleOption);
#endif
#endif //defined(QZXING_QML)

    if (offsetX < 0)
        offsetX = 0;
    if (offsetY < 0)
        offsetY = 0;
    if (width < 0)
        width = 0;
    if (height < 0)
        height = 0;

    if (offsetX || offsetY || width || height)
        return img.copy(offsetX, offsetY, width, height);
    else
        return img;
}
Ejemplo n.º 30
0
void StackableItem::lower()
{
    QQuickItem *parent = parentItem();
    Q_ASSERT(parent);
    QQuickItem *bottom = parent->childItems().first();
    if (this != bottom)
        stackBefore(bottom);
}