示例#1
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++;
    }
}
示例#2
0
int zLayout::getLayoutChildren()
{
    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;
        j++;
    }
    return j;
}
bool
QcMapItem::send_mouse_event(QMouseEvent * event)
{
  qInfo() << event;

  QPointF local_position = mapFromScene(event->windowPos());
  QQuickWindow * _window = window();
  QQuickItem * grabber = _window ? _window->mouseGrabberItem() : nullptr;
  // Fixme: faster ? / duplicated
  bool is_mouse_area = !grabber or QString(grabber->metaObject()->className()).startsWith(QStringLiteral("QQuickMouseArea"));
  bool steal_event = m_gesture_area->is_active(); // means pan or pinch is active

  // grabber is QQuickMouseArea, steal_event is false first then true
  // qInfo() << event << "\ngrabber" << grabber << "\nsteal_event" << steal_event << is_mouse_area;

  if (is_mouse_area and (steal_event or contains(local_position)) and (!grabber or !grabber->keepMouseGrab())) {
    QScopedPointer<QMouseEvent> mouseEvent(QQuickWindowPrivate::cloneMouseEvent(event, &local_position));
    mouseEvent->setAccepted(false);

    switch (mouseEvent->type()) {
    case QEvent::MouseMove:
      m_gesture_area->handle_mouse_move_event(mouseEvent.data());
      break;
    case QEvent::MouseButtonPress:
      m_gesture_area->handle_mouse_press_event(mouseEvent.data());
      break;
    case QEvent::MouseButtonRelease:
      m_gesture_area->handle_mouse_release_event(mouseEvent.data());
      break;
    default:
      break;
    }

    steal_event = m_gesture_area->is_active(); // recheck value
    // Fixme: duplicated code ???
    grabber = _window ? _window->mouseGrabberItem() : nullptr;
    // qInfo() << "grabber" << grabber << "\nsteal_event" << steal_event;

    if (grabber and steal_event and !grabber->keepMouseGrab() and grabber != this) {
      // qInfo() << "grab mouse";
      grabMouse();
    }

    if (steal_event) {
      event->setAccepted(true);
      return true; // do not deliver event
    } else
      return false; // deliver event

  } else {
    // ungrab if necessary and deliver event
    if (event->type() == QEvent::MouseButtonRelease
        and (_window and _window->mouseGrabberItem() == this))
      // qInfo() << "ungrab mouse";
      ungrabMouse();
    return false; // deliver event
  }
}
示例#4
0
QString Canvas::getTypeOfChildAt(int x, int y)
{
    QQuickItem *item = childAt(x,y);
    if ( item )
    {
        QString tp = item->metaObject()->className();
        if ( tp=="QQuickLoader")
        {
            QPointF p = mapToItem(item, QPointF(x, y));
            QQuickItem *childItem = item->childAt(p.x(), p.y() );
            tp = childItem->metaObject()->className();
            Item* castItem = dynamic_cast<Item*>(childItem);
            if ( castItem )
            {
                tp = castItem->getClassName();
            }
        }
        return tp;
    }
    return QString("notDefined");
}
bool
QcMapItem::send_touch_event(QTouchEvent * event)
{
  QQuickWindowPrivate * _window = window() ? QQuickWindowPrivate::get(window()) : nullptr;
  const QTouchEvent::TouchPoint & point = event->touchPoints().first();
  QQuickItem * grabber = _window ? _window->itemForTouchPointId.value(point.id()) : nullptr;
  // Fixme: faster ?
  bool is_mouse_area = QString(grabber->metaObject()->className()).startsWith(QStringLiteral("QQuickMouseArea"));

  bool steal_event = m_gesture_area->is_active();
  bool contains_point = contains(mapFromScene(point.scenePos()));

  if (is_mouse_area and (steal_event or contains_point) and (!grabber or !grabber->keepTouchGrab())) {
    QScopedPointer<QTouchEvent> touch_event(new QTouchEvent(event->type(), event->device(), event->modifiers(),
                                                            event->touchPointStates(), event->touchPoints()));
    touch_event->setTimestamp(event->timestamp());
    touch_event->setAccepted(false);

    m_gesture_area->handle_touch_event(touch_event.data());

    steal_event = m_gesture_area->is_active(); // recheck value
    // Fixme: duplicated code ???
    grabber = _window ? _window->itemForTouchPointId.value(point.id()) : nullptr;

    if (grabber and steal_event and !grabber->keepTouchGrab() and grabber != this) {
      QVector<int> ids;
      for (const auto & touch_point : event->touchPoints())
        if (!(touch_point.state() & Qt::TouchPointReleased))
          ids.append(touch_point.id());
      grabTouchPoints(ids);
    }

    if (steal_event) {
      // do not deliver
      event->setAccepted(true);
      return true;
    } else
      return false;

  } else {
    // ungrab if necessary and deliver event
    if (event->type() == QEvent::TouchEnd
        and (_window and _window->itemForTouchPointId.value(point.id()) == this))
      ungrabTouchPoints();
    return false;
  }
}
void QQuickShaderEffectCommon::updateMaterial(QQuickShaderEffectNode *node,
                                              QQuickShaderEffectMaterial *material,
                                              bool updateUniforms, bool updateUniformValues,
                                              bool updateTextureProviders)
{
    if (updateUniforms) {
        for (int i = 0; i < material->textureProviders.size(); ++i) {
            QSGTextureProvider *t = material->textureProviders.at(i);
            if (t) {
                QObject::disconnect(t, SIGNAL(textureChanged()), node, SLOT(markDirtyTexture()));
                QObject::disconnect(t, SIGNAL(destroyed(QObject*)), node, SLOT(textureProviderDestroyed(QObject*)));
            }
        }

        // First make room in the textureProviders array. Set to proper value further down.
        int textureProviderCount = 0;
        for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) {
            for (int i = 0; i < uniformData[shaderType].size(); ++i) {
                if (uniformData[shaderType].at(i).specialType == UniformData::Sampler)
                    ++textureProviderCount;
            }
            material->uniforms[shaderType] = uniformData[shaderType];
        }
        material->textureProviders.fill(0, textureProviderCount);
        updateUniformValues = false;
        updateTextureProviders = true;
    }

    if (updateUniformValues) {
        for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) {
            Q_ASSERT(uniformData[shaderType].size() == material->uniforms[shaderType].size());
            for (int i = 0; i < uniformData[shaderType].size(); ++i)
                material->uniforms[shaderType][i].value = uniformData[shaderType].at(i).value;
        }
    }

    if (updateTextureProviders) {
        int index = 0;
        for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) {
            for (int i = 0; i < uniformData[shaderType].size(); ++i) {
                const UniformData &d = uniformData[shaderType].at(i);
                if (d.specialType != UniformData::Sampler)
                    continue;
                QSGTextureProvider *oldProvider = material->textureProviders.at(index);
                QSGTextureProvider *newProvider = 0;
                QQuickItem *source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(d.value));
                if (source && source->isTextureProvider())
                    newProvider = source->textureProvider();
                if (newProvider != oldProvider) {
                    if (oldProvider) {
                        QObject::disconnect(oldProvider, SIGNAL(textureChanged()), node, SLOT(markDirtyTexture()));
                        QObject::disconnect(oldProvider, SIGNAL(destroyed(QObject*)), node, SLOT(textureProviderDestroyed(QObject*)));
                    }
                    if (newProvider) {
                        Q_ASSERT_X(newProvider->thread() == QThread::currentThread(),
                                   "QQuickShaderEffect::updatePaintNode",
                                   "Texture provider must belong to the rendering thread");
                        QObject::connect(newProvider, SIGNAL(textureChanged()), node, SLOT(markDirtyTexture()));
                        QObject::connect(newProvider, SIGNAL(destroyed(QObject*)), node, SLOT(textureProviderDestroyed(QObject*)));
                    } else {
                        const char *typeName = source ? source->metaObject()->className() : d.value.typeName();
                        qWarning("ShaderEffect: Property '%s' is not assigned a valid texture provider (%s).",
                                 d.name.constData(), typeName);
                    }
                    material->textureProviders[index] = newProvider;
                }
                ++index;
            }
        }
        Q_ASSERT(index == material->textureProviders.size());
    }
}