/*!
 \brief Checks the direction of pan gesture.
 
 Changes the scrolling style according to movement direction, 
 stores the orientation of the pan gesture.
 Function is used when switching widgets by panning gesture is enabled.
 
 \param panGesture Pan gesture event
 */
void CalenDayContentScrollArea::checkPanDirection(QPanGesture *panGesture)
{
    // Gets the offset of pan gesture.
    QPointF offset = panGesture->offset();

    // Note: in horizontal orientation x should is treaten as Y, y as X.
    QPointF movement;
    if (mOrientation == Qt::Vertical) {
        movement = offset;
    }
    else {
        movement.setX(offset.y());
        movement.setY(offset.x());
    }

    // If gesture is started check leading movement direction
    if (panGesture->state() == Qt::GestureStarted) {
        if (qAbs(movement.x()) < qAbs(movement.y())) {
            mPanDayDirection = ECalenPanVertical;
        }
        else {
            mStartPosition = contentWidget()->pos();
            mPanDayDirection = ECalenPanHorizontal;
        }
    }
}
示例#2
0
bool AbstractRenderView::eventFilter(QObject * watched, QEvent * event)
{
    if (event->type() != QEvent::MouseButtonPress || watched != contentWidget())
    {
        return AbstractDataView::eventFilter(watched, event);
    }

    auto mouseEvent = static_cast<QMouseEvent *>(event);
    setActiveSubView(implementation().subViewIndexAtPos(mouseEvent->pos()));

    return AbstractDataView::eventFilter(watched, event);
}
示例#3
0
void AbstractDataView::showEvent(QShowEvent * event)
{
    DockableWidget::showEvent(event);

    if (m_initialized)
    {
        return;
    }

    contentWidget()->installEventFilter(this);

    m_initialized = true;
}
/*!
 \brief Scrolls to middle widget.
 
 Scrolling to middle widget is done if needed.
 Resets internal pan direction flag.
 */
void CalenDayContentScrollArea::scrollToMiddleWidget()
{
    QPointF currentPosition = contentWidget()->pos();
    QPointF destPosition = QPointF(mContentWidth, currentPosition.y());

    // Scroll only when x position is wrong
    if (currentPosition.x() != destPosition.x()) {
        scrollContentsTo(QPointF(mContentWidth, currentPosition.y()), 0);
    }

    // Reset pan direction flag and scrolling flag
    mPanDayDirection = ECalenPanNotSet;
}
示例#5
0
    ViewerWidget(osgViewer::ViewerBase::ThreadingModel threadingModel=osgViewer::CompositeViewer::SingleThreaded)
    {
        setThreadingModel(threadingModel);

        QWidget* widget1 = addViewWidget( createCamera(0,0,100,100), osgDB::readNodeFile("D:\\ThirdParty\\OpenSceneGraph-3.0.1\\data\\cow.osg") );
        QWidget* widget2 = addViewWidget( createCamera(0,0,100,100), osgDB::readNodeFile("D:\\ThirdParty\\OpenSceneGraph-3.0.1\\data\\cow.osgt") );
        QWidget* widget3 = addViewWidget( createCamera(0,0,100,100), osgDB::readNodeFile("D:\\ThirdParty\\OpenSceneGraph-3.0.1\\data\\cow.osgt") );
        QWidget* widget4 = addViewWidget( createCamera(0,0,100,100), osgDB::readNodeFile("D:\\ThirdParty\\OpenSceneGraph-3.0.1\\data\\cow.osgt") );
        QWidget* popupWidget = addViewWidget( createCamera(900,100,320,240,"Popup window",true),
                                            osgDB::readNodeFile("D:\\ThirdParty\\OpenSceneGraph-3.0.1\\data\\cow.osgt") );
        popupWidget->show();

        QGridLayout* grid = new QGridLayout(contentWidget());
        grid->addWidget( widget1, 0, 0 );
        grid->addWidget( widget2, 0, 1 );
        grid->addWidget( widget3, 1, 0 );
        grid->addWidget( widget4, 1, 1 );
        //setLayout( grid );

        connect( &_timer, SIGNAL(timeout()), this, SLOT(update()) );
        _timer.start( 10 );
    }
示例#6
0
QWidget* UtilityPanelController::widget()
{
    return contentWidget();
}
/*!
 \brief Handles pan gesture event (horizontal) or swipe gesture. 
 
 Ignores vertical pan gestures.
 
 \param event Gesture event to be handled
 */
void CalenDayContentScrollArea::gestureEvent(QGestureEvent *event)
{
#ifdef CALENDAYVIEW_PANNING_ENABLED
    // Process a pan gesture event
    if (QPanGesture *panGesture = qobject_cast<QPanGesture*> (event->gesture(
        Qt::PanGesture))) {

        // Checks pan gesture direction
        checkPanDirection(panGesture);

        // Put the gesture forward before working with finished gesture
        HbScrollArea::gestureEvent(event);

        // If gesture is finished move the scroll area to next or previous 
        // widget or resume to gesture start point
        if (panGesture->state() == Qt::GestureFinished) {
            // Pan direction should be reseted when scrolling ends

            // Gets the offset of pan gesture.
            QPointF offset = panGesture->offset();

            // Note: in horizontal orientation x should is treaten as Y, y as X.
            QPointF movement;
            if (mOrientation == Qt::Vertical) {
                movement = offset;
            }
            else {
                movement.setX(offset.y());
                movement.setY(offset.x());
            }

            // Gesture was long enough for place movement
            if (qAbs(movement.x()) > (KCalenHScrollMoveParam * mContentWidth / 100)) {
                if (movement.x() < 0) {
                    mMoveDirection = ECalenScrollToNext;
                    moveTo(QPointF((-mStartPosition.x() + mContentWidth),
                        -mStartPosition.y()), KCalenScrollDaysTimeout);
                }
                else {
                    mMoveDirection = ECalenScrollToPrev;
                    moveTo(QPointF(-mStartPosition.x() - mContentWidth,
                        -mStartPosition.y()), KCalenScrollDaysTimeout);
                }
            }
            // Gesture was short one, reset to gesture start point
            else {
                qreal startPos = mStartPosition.x();
                bool isNegative = false;
                if (startPos < 0) {
                    isNegative = true;
                }
                startPos = qAbs(startPos);
                qreal normalizeValue = mContentWidth / 2;

                while (startPos > normalizeValue) {
                    normalizeValue += mContentWidth;
                }

                if (isNegative) {
                    mStartPosition.setX(-(normalizeValue - (mContentWidth / 2)));
                }
                else {
                    mStartPosition.setX(normalizeValue - (mContentWidth / 2));
                }

                mMoveDirection = ECalenScrollNoDayChange;
                moveTo(-mStartPosition, KCalenScrollDaysTimeout);
            }
        }
    }
    else {
        HbScrollArea::gestureEvent(event);
    }
#else
    // Let the content scroll area ignore pan gestures
    if (QPanGesture *panGesture = qobject_cast<QPanGesture *> (event->gesture(
                Qt::PanGesture))) {
        // do nothing with pan gesture
    }

    if (HbSwipeGesture *swipeGesture =
        qobject_cast<HbSwipeGesture *> (event->gesture(Qt::SwipeGesture))) {
        if (swipeGesture->state() == Qt::GestureStarted) {
            mStartPosition = contentWidget()->pos();
            
            qreal swipeAngle = swipeGesture->sceneSwipeAngle();
            if (isHorizontalSwipe(swipeAngle)) {
                if (QSwipeGesture::Left == 
                    swipeGesture->sceneHorizontalDirection()) {
                    mMoveDirection = ECalenScrollToNext;
                    moveTo(QPointF((-mStartPosition.x() + mContentWidth),
                            -mStartPosition.y()), KCalenScrollDaysTimeout);
                }
                else if (QSwipeGesture::Right == 
                    swipeGesture->sceneHorizontalDirection()) {
                    mMoveDirection = ECalenScrollToPrev;
                    moveTo(QPointF(-mStartPosition.x() - mContentWidth,
                            -mStartPosition.y()), KCalenScrollDaysTimeout);
                }
            }
        }
    }
#endif
}