Exemple #1
0
/*! \internal */
QCamera::QCamera(QCameraPrivate &dd, QNode *parent)
    : QEntity(dd, parent)
{
    QObject::connect(d_func()->m_lens, SIGNAL(projectionTypeChanged()), this, SIGNAL(projectionMatrixChanged()));
    QObject::connect(d_func()->m_lens, SIGNAL(nearPlaneChanged()), this, SIGNAL(nearPlaneChanged()));
    QObject::connect(d_func()->m_lens, SIGNAL(farPlaneChanged()), this, SIGNAL(farPlaneChanged()));
    QObject::connect(d_func()->m_lens, SIGNAL(fieldOfViewChanged()), this, SIGNAL(fieldOfViewChanged()));
    QObject::connect(d_func()->m_lens, SIGNAL(aspectRatioChanged()), this, SIGNAL(aspectRatioChanged()));
    QObject::connect(d_func()->m_lens, SIGNAL(leftChanged()), this, SIGNAL(leftChanged()));
    QObject::connect(d_func()->m_lens, SIGNAL(rightChanged()), this, SIGNAL(rightChanged()));
    QObject::connect(d_func()->m_lens, SIGNAL(bottomChanged()), this, SIGNAL(bottomChanged()));
    QObject::connect(d_func()->m_lens, SIGNAL(topChanged()), this, SIGNAL(topChanged()));
    QObject::connect(d_func()->m_lens, SIGNAL(projectionMatrixChanged()), this, SIGNAL(projectionMatrixChanged()));
    QObject::connect(d_func()->m_lookAt, SIGNAL(positionChanged()), this, SIGNAL(positionChanged()));
    QObject::connect(d_func()->m_lookAt, SIGNAL(upVectorChanged()), this, SIGNAL(upVectorChanged()));
    QObject::connect(d_func()->m_lookAt, SIGNAL(viewCenterChanged()), this, SIGNAL(viewCenterChanged()));
    QObject::connect(d_func()->m_transform, SIGNAL(matrixChanged()), this, SIGNAL(matrixChanged()));
    d_func()->m_transform->addTransform(d_func()->m_lookAt);
    addComponent(d_func()->m_lens);
    addComponent(d_func()->m_transform);
}
Exemple #2
0
void ImageView::zoomRegion(const QRect& region)
{
    QRect size = this->geometry();                              // Canvas size.
    QRect targetRect = region.intersected(size);                // Zoom region.
    QPoint targetCenter = targetRect.center();                  // Zoom center.
    QRect visibleRect = this->visibleRegion().boundingRect();   // Viewport.

    float sx = static_cast<float>(visibleRect.width()) / targetRect.width();
    float sy = static_cast<float>(visibleRect.height()) / targetRect.height();
    float newScale = (sx < sy) ? sx : sy;
    float scale = newScale * static_cast<float>(size.width()) / m_image.width();

    this->setZoomLevel(scale);

    emit viewCenterChanged(newScale * targetCenter.x(), 
        newScale * targetCenter.y());
}
Exemple #3
0
void ImageView::mouseReleaseEvent(QMouseEvent *event)
{
    switch (m_mouseMode) {
        case MM_ZOOM:	
            m_rubberBand->hide();
            if (m_rubberBand->geometry().isNull()) {
                /* Zoom step. */
                int newCenterX, newCenterY;
                int x = event->x();
                int y = event->y();

                if (event->modifiers() & Qt::ControlModifier) {
                    this->zoomOut();
                    if (m_zoomLevel != 1) {
                        newCenterX = (int)(x * (this->m_zoomLevel - 1.0) 
                            / this->m_zoomLevel);
                        newCenterY = (int)(y * (this->m_zoomLevel - 1.0) 
                            / this->m_zoomLevel);
                        emit viewCenterChanged(newCenterX, newCenterY);
                        if (visibleRegion().contains(event->pos())) {
                            this->canvasToImage(x, y);
                            emit mousePosChanged(x, y);
                        } else {
                            emit mousePosChanged(-1, -1);
                        }
                    }
                } else if (event->modifiers() == Qt::ShiftModifier) {
                    this->setZoomLevel(1.0f);
                } else {
                    this->zoomIn();
                    newCenterX = (int)(x * (this->m_zoomLevel + 1.0) 
                        / this->m_zoomLevel);
                    newCenterY = (int)(y * (this->m_zoomLevel + 1.0) 
                        / this->m_zoomLevel);
                    emit viewCenterChanged(newCenterX, newCenterY);
                    if (visibleRegion().contains(event->pos())) {
                        this->canvasToImage(x, y);
                        emit mousePosChanged(x, y);
                    } else {
                        emit mousePosChanged(-1, -1);
                    }
                }

            } else {
                /* Lasso zoom. */
                if (!(event->modifiers() & Qt::ControlModifier)) {
                    zoomRegion(m_rubberBand->geometry());
                }
            }
            break;
        case MM_MINMAX: 
            {
                QRect selRect = this->m_minMaxLens->geometry();
                //QRect visRect = this->visibleRegion().boundingRect();
                selRect.moveLeft(selRect.left() / this->m_zoomLevel);
                selRect.moveTop(selRect.top() / this->m_zoomLevel);
                selRect.setWidth(::ceilf(static_cast<float>(selRect.width()) 
                            / this->m_zoomLevel));
                selRect.setHeight(::ceilf(static_cast<float>(selRect.height()) 
                            / this->m_zoomLevel));
                emit minMaxAreaChanged(selRect);
                this->m_minMaxLens->setVisible(false);
                if (event->modifiers() & Qt::ControlModifier) {
                    emit setMappingBounds();
                }
            } break;
        default:
            break;
    }
}