Example #1
0
void PageItem::setFlickable(QDeclarativeItem *flickable)
{
    if (m_flickable.data() == flickable) {
        return;
    }

    //check the object can act as a flickable
    if (!flickable->property("contentX").isValid() ||
            !flickable->property("contentY").isValid()) {
        return;
    }

    if (m_flickable) {
        disconnect(m_flickable.data(), 0, this, 0);
    }

    //check the object can act as a flickable
    if (!flickable->property("contentX").isValid() ||
            !flickable->property("contentY").isValid()) {
        m_flickable.clear();
        return;
    }

    m_flickable = flickable;

    if (flickable) {
        connect(flickable, SIGNAL(contentXChanged()), this, SLOT(contentXChanged()));
        connect(flickable, SIGNAL(contentYChanged()), this, SLOT(contentYChanged()));
    }

    emit flickableChanged();
}
Example #2
0
QtFlickProvider::QtFlickProvider(QQuickWebView* viewItem, QQuickWebPage* pageItem)
    : QObject(viewItem)
{
    ASSERT(viewItem);
    ASSERT(pageItem);

    QDeclarativeEngine* engine = qmlEngine(viewItem);
    QDeclarativeContext* context = qmlContext(viewItem);

    ASSERT(engine);
    ASSERT(context);

    QDeclarativeComponent component(engine, viewItem);

    // Create the internal Flickable instance dynamically.
    // We only use public QML API so that we do not depend
    // on private API of the QtDeclarative module.
    component.setData(QByteArrayLiteral("import QtQuick 2.0\nFlickable {}"), QUrl());

    m_flickable = qobject_cast<QQuickItem*>(component.create(context));

    QMetaProperty content = resolveMetaProperty(m_flickable, "contentItem");
    m_contentItem = content.read(m_flickable).value<QQuickItem*>();
    ASSERT(m_contentItem);

    // Resolve meta methods and properties of the Flickable instance.
    m_returnToBoundsMethod = resolveMetaMethod(m_flickable, "returnToBounds()");
    m_cancelFlickMethod = resolveMetaMethod(m_flickable, "cancelFlick()");

    m_contentWidth = resolveMetaProperty(m_flickable, "contentWidth");
    m_contentHeight = resolveMetaProperty(m_flickable, "contentHeight");
    m_contentX = resolveMetaProperty(m_flickable, "contentX");
    m_contentY = resolveMetaProperty(m_flickable, "contentY");
    m_moving = resolveMetaProperty(m_flickable, "moving");
    m_dragging = resolveMetaProperty(m_flickable, "dragging");
    m_flicking = resolveMetaProperty(m_flickable, "flicking");

    m_flickableData = resolveMetaProperty(m_flickable, "flickableData");

    // Set the viewItem as the parent of the flickable instance
    // and reparent the page so it is placed on the flickable contentItem.
    m_flickable->setParentItem(viewItem);
    pageItem->setParentItem(m_contentItem);

    // Propagate flickable signals.
    connect(m_flickable, SIGNAL(movementStarted()), SIGNAL(movementStarted()), Qt::DirectConnection);
    connect(m_flickable, SIGNAL(movementEnded()), SIGNAL(movementEnded()), Qt::DirectConnection);
    connect(m_flickable, SIGNAL(flickingChanged()), SIGNAL(flickingChanged()), Qt::DirectConnection);
    connect(m_flickable, SIGNAL(draggingChanged()), SIGNAL(draggingChanged()), Qt::DirectConnection);
    connect(m_flickable, SIGNAL(contentWidthChanged()), SIGNAL(contentWidthChanged()), Qt::DirectConnection);
    connect(m_flickable, SIGNAL(contentHeightChanged()), SIGNAL(contentHeightChanged()), Qt::DirectConnection);
    connect(m_flickable, SIGNAL(contentXChanged()), SIGNAL(contentXChanged()), Qt::DirectConnection);
    connect(m_flickable, SIGNAL(contentYChanged()), SIGNAL(contentYChanged()), Qt::DirectConnection);
}
Example #3
0
void QtViewportHandler::flickMoveStarted()
{
    Q_ASSERT(m_viewportItem->isMoving());
    m_scrollUpdateDeferrer = adoptPtr(new ViewportUpdateDeferrer(this, ViewportUpdateDeferrer::DeferUpdateAndSuspendContent));

    m_lastScrollPosition = m_viewportItem->contentPos();
    connect(m_viewportItem, SIGNAL(contentXChanged()), SLOT(pageItemPositionChanged()));
    connect(m_viewportItem, SIGNAL(contentYChanged()), SLOT(pageItemPositionChanged()));
}
void QtViewportInteractionEngine::flickableMoveStarted()
{
    Q_ASSERT(m_viewport->isMoving());
    m_scrollUpdateDeferrer = adoptPtr(new ViewportUpdateDeferrer(this, ViewportUpdateDeferrer::DeferUpdateAndSuspendContent));

    m_lastScrollPosition = m_viewport->contentPos();
    connect(m_viewport, SIGNAL(contentXChanged()), SLOT(flickableMovingPositionUpdate()));
    connect(m_viewport, SIGNAL(contentYChanged()), SLOT(flickableMovingPositionUpdate()));
}
Example #5
0
void QtViewportHandler::flickMoveEnded()
{
    Q_ASSERT(!m_viewportItem->isMoving());
    // This method is called on the end of the pan or pan kinetic animation.
    m_scrollUpdateDeferrer.clear();

    m_lastScrollPosition = QPointF();
    disconnect(m_viewportItem, SIGNAL(contentXChanged()), this, SLOT(pageItemPositionChanged()));
    disconnect(m_viewportItem, SIGNAL(contentYChanged()), this, SLOT(pageItemPositionChanged()));
}
void QtViewportInteractionEngine::flickableMoveEnded()
{
    Q_ASSERT(!m_viewport->isMoving());
    // This method is called on the end of the pan or pan kinetic animation.
    m_scrollUpdateDeferrer.clear();

    m_lastScrollPosition = QPointF();
    disconnect(m_viewport, SIGNAL(contentXChanged()), this, SLOT(flickableMovingPositionUpdate()));
    disconnect(m_viewport, SIGNAL(contentYChanged()), this, SLOT(flickableMovingPositionUpdate()));
}
void BooksListWatcher::setListView(QQuickItem* aView)
{
    if (iListView != aView) {
        const QSize oldSize(iSize);
        if (iListView) iListView->disconnect(this);
        iListView = aView;
        if (iListView) {
            connect(iListView,
                SIGNAL(widthChanged()),
                SLOT(onWidthChanged()));
            connect(iListView,
                SIGNAL(heightChanged()),
                SLOT(onHeightChanged()));
            connect(iListView,
                SIGNAL(contentXChanged()),
                SLOT(onContentXChanged()));
            connect(iListView,
                SIGNAL(contentYChanged()),
                SLOT(onContentYChanged()));
            connect(iListView,
                SIGNAL(contentWidthChanged()),
                SLOT(onContentSizeChanged()));
            connect(iListView,
                SIGNAL(contentHeightChanged()),
                SLOT(onContentSizeChanged()));
            iContentX = contentX();
            iContentY = contentY();
            updateCurrentIndex();
        } else {
            iContentX = iContentY = 0;
            iSize = QSize(0,0);
        }
        Q_EMIT listViewChanged();
        if (oldSize != iSize) {
            Q_EMIT sizeChanged();
        }
        if (oldSize.width() != iSize.width()) {
            Q_EMIT widthChanged();
        }
        if (oldSize.height() != iSize.height()) {
            Q_EMIT heightChanged();
        }
    }
}
Example #8
0
PageViewportControllerClientQt::PageViewportControllerClientQt(QQuickWebView* viewportItem, QQuickWebPage* pageItem)
    : m_viewportItem(viewportItem)
    , m_pageItem(pageItem)
    , m_scaleAnimation(new ScaleAnimation(this))
    , m_pinchStartScale(-1)
    , m_lastCommittedScale(-1)
    , m_zoomOutScale(0)
    , m_isUserInteracting(false)
    , m_ignoreViewportChanges(false)
{
    m_scaleAnimation->setDuration(kScaleAnimationDurationMillis);
    m_scaleAnimation->setEasingCurve(QEasingCurve::OutCubic);

    connect(m_viewportItem, SIGNAL(movementStarted()), SLOT(flickMoveStarted()), Qt::DirectConnection);
    connect(m_viewportItem, SIGNAL(movementEnded()), SLOT(flickMoveEnded()), Qt::DirectConnection);
    connect(m_viewportItem, SIGNAL(contentXChanged()), SLOT(pageItemPositionChanged()));
    connect(m_viewportItem, SIGNAL(contentYChanged()), SLOT(pageItemPositionChanged()));


    connect(m_scaleAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)),
            SLOT(scaleAnimationStateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
}