Exemplo n.º 1
0
PlotFrame::PlotFrame(QWidget *parent) :
    QFrame(parent), ui(new Ui::PlotFrame), plotScene(NULL), plotView(NULL)
{
    // GUI Configuration
    ui->setupUi(this);

    // Create scene
    this->plotScene = new PlotScene(this);

    // Create view
    this->plotView = new PlotView(this->plotScene);
    this->plotView->setAutoFillBackground(true);
    this->plotView->setRenderHint(QPainter::Antialiasing);
    this->plotView->setSizePolicy(QSizePolicy::Expanding,
                                  QSizePolicy::Expanding);

    // Layouts configuration
    this->topScaleLayout    = new QVBoxLayout;
    this->bottomScaleLayout = new QVBoxLayout;
    this->leftScaleLayout   = new QHBoxLayout;
    this->rightScaleLayout  = new QHBoxLayout;

    this->ui->plotLayout->addLayout(this->topScaleLayout, 0, 1, 1, 3);
    this->ui->plotLayout->addLayout(this->bottomScaleLayout, 5, 1, 1, 3);
    this->ui->plotLayout->addLayout(this->leftScaleLayout, 1, 0, 3, 1);
    this->ui->plotLayout->addLayout(this->rightScaleLayout, 1, 5, 3, 1);
    this->ui->plotLayout->addWidget(this->plotView, 1, 1, 3, 3);

    // Manage tool button state
    this->ui->showCurvesToolButton->setChecked(
                this->plotScene->curvesAreVisible());
    this->ui->showPointsToolButton->setChecked(
                this->plotScene->pointsAreVisible());
    this->ui->showLineToolButton->setChecked(
                this->plotScene->curveLabelsAreVisible());

    // Connect GUI signals to slots | Use autoconnect and call scene slots ?
    connect(this->ui->showCurvesToolButton, SIGNAL(toggled(bool)),
            this->plotScene, SLOT(setCurvesVisible(bool)));
    connect(this->ui->showPointsToolButton, SIGNAL(toggled(bool)),
            this->plotScene, SLOT(setPointsVisible(bool)));
    connect(this->ui->zoomOutToolButton, SIGNAL(clicked()),
            this->plotView, SLOT(zoomOut()));

    // Connect signals and slots of view and scene
    connect(this->plotView, SIGNAL(rectChange(QRectF)),
            this, SLOT(adaptScales(QRectF)));
    connect(this->plotView, SIGNAL(beginSelection()),
            this->plotScene, SLOT(lockSelectionAbility()));
    connect(this->plotView, SIGNAL(finishSelection()),
            this->plotScene, SLOT(unlockSelectionAbility()));
    connect(this->plotView, SIGNAL(mousePosChanged(QPointF,QPointF)),
            this->plotScene, SLOT(displayLabels(QPointF,QPointF)));
    connect(this->plotView, SIGNAL(mousePressed(QPointF)),
            this->plotScene, SLOT(slotDeTest(QPointF)));

    setMouseTracking(true);
}
Exemplo n.º 2
0
void ImageView::mouseMoveEvent(QMouseEvent *event)
{
    /* this is really ugly! But as far as I can see the only way to ensure that
     * the ImageView always has focus when the window is in the foreground
     */
    if (m_pWorkspace->activeWindow() == parent()->parent()->parent()->parent()) {
        setFocus(Qt::MouseFocusReason);
    }
    if (visibleRegion().contains(event->pos())) {
        int x = event->x();
        int y = event->y();
        this->canvasToImage(x, y);
        emit mousePosChanged(x, y);
    } else {
        emit mousePosChanged(-1, -1);
    }

    switch (m_mouseMode) {
        case MM_ZOOM:
            if (event->modifiers() & Qt::ControlModifier) {
                m_rubberBand->hide();
            } else if (m_rubberBand->isVisible()) {
                m_rubberBand->setGeometry(QRect(m_rubberBandOrigin,
                    event->pos()).normalized());
            }
            break;
        case MM_MINMAX:
            if ((event->buttons() & Qt::LeftButton) 
                    && m_minMaxLens->isVisible()) {
                m_minMaxLens->setGeometry(QRect(m_minMaxLensOrigin,
                    event->pos()).normalized());
            }
            break;
        default:
            break;
    }
}
Exemplo n.º 3
0
void WWindowPrivate::init()
{
    Q_Q(WWindow);

    icon = sk->icon();

    visible = true;

    hoverItem = NULL;

    q->setAcceptHoverEvents(true);

#ifdef QT_LATEST
    q->setFlag(QQuickItem::ItemAcceptsDrops);
#endif

    //---------------------------------------------------------------------------------------------
    // View

#if defined(SK_WIN_NATIVE)
    view = new WView(q, NULL);
#elif defined(Q_OS_WIN)
    view = new WView(q, NULL, Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint);
#else
    view = new WView(q, NULL, Qt::FramelessWindowHint);
#endif

#ifdef QT_4
    view->setWindowTitle(sk->name());
#else
    view->setTitle(sk->name());
#endif

    if (icon.isEmpty() == false)
    {
#ifdef QT_4
        view->setWindowIcon(QIcon(icon));
#else
        view->setIcon(QIcon(icon));
#endif
    }

    view->setVisible(true);

    //---------------------------------------------------------------------------------------------
    // Signals

    QObject::connect(view, SIGNAL(messageReceived(const QString &)),
                     q,    SIGNAL(messageReceived(const QString &)));

    QObject::connect(view, SIGNAL(stateChanged(Qt::WindowState)),
                     q,    SIGNAL(stateChanged(Qt::WindowState)));

    QObject::connect(view, SIGNAL(fadeIn ()), q, SIGNAL(fadeIn ()));
    QObject::connect(view, SIGNAL(fadeOut()), q, SIGNAL(fadeOut()));

    QObject::connect(view, SIGNAL(dragEnded()), q, SIGNAL(dragEnded()));

    QObject::connect(view, SIGNAL(beforeClose()), q, SIGNAL(beforeClose()));

    //---------------------------------------------------------------------------------------------

    QObject::connect(view, SIGNAL(itemWidthChanged ()), q, SIGNAL(itemWidthChanged ()));
    QObject::connect(view, SIGNAL(itemHeightChanged()), q, SIGNAL(itemHeightChanged()));

    QObject::connect(view, SIGNAL(xChanged()), q, SIGNAL(viewXChanged()));
    QObject::connect(view, SIGNAL(yChanged()), q, SIGNAL(viewYChanged()));

    QObject::connect(view, SIGNAL(widthChanged ()), q, SIGNAL(viewWidthChanged ()));
    QObject::connect(view, SIGNAL(heightChanged()), q, SIGNAL(viewHeightChanged()));

    QObject::connect(view, SIGNAL(centerXChanged()), q, SIGNAL(centerXChanged()));
    QObject::connect(view, SIGNAL(centerYChanged()), q, SIGNAL(centerYChanged()));

    QObject::connect(view, SIGNAL(originXChanged()), q, SIGNAL(originXChanged()));
    QObject::connect(view, SIGNAL(originYChanged()), q, SIGNAL(originYChanged()));

    QObject::connect(view, SIGNAL(ratioChanged()), q, SIGNAL(ratioChanged()));

    QObject::connect(view, SIGNAL(zoomChanged()), q, SIGNAL(zoomChanged()));

    QObject::connect(view, SIGNAL(minimumWidthChanged ()), q, SIGNAL(minimumWidthChanged ()));
    QObject::connect(view, SIGNAL(minimumHeightChanged()), q, SIGNAL(minimumHeightChanged()));

    QObject::connect(view, SIGNAL(maximumWidthChanged ()), q, SIGNAL(maximumWidthChanged ()));
    QObject::connect(view, SIGNAL(maximumHeightChanged()), q, SIGNAL(maximumHeightChanged()));

    QObject::connect(view, SIGNAL(geometryNormalChanged()), q, SIGNAL(geometryNormalChanged()));

    QObject::connect(view, SIGNAL(minimizedChanged ()), q, SIGNAL(minimizedChanged ()));
    QObject::connect(view, SIGNAL(maximizedChanged ()), q, SIGNAL(maximizedChanged ()));
    QObject::connect(view, SIGNAL(fullScreenChanged()), q, SIGNAL(fullScreenChanged()));
    QObject::connect(view, SIGNAL(lockedChanged    ()), q, SIGNAL(lockedChanged    ()));
    QObject::connect(view, SIGNAL(scalingChanged   ()), q, SIGNAL(scalingChanged   ()));

    QObject::connect(view, SIGNAL(activeChanged  ()), q, SIGNAL(activeChanged  ()));
    QObject::connect(view, SIGNAL(enteredChanged ()), q, SIGNAL(enteredChanged ()));
    QObject::connect(view, SIGNAL(draggingChanged()), q, SIGNAL(draggingChanged()));
    QObject::connect(view, SIGNAL(draggedChanged ()), q, SIGNAL(draggedChanged ()));
    QObject::connect(view, SIGNAL(resizingChanged()), q, SIGNAL(resizingChanged()));
    QObject::connect(view, SIGNAL(touchingChanged()), q, SIGNAL(touchingChanged()));

    QObject::connect(view, SIGNAL(mousePosChanged   ()), q, SIGNAL(mousePosChanged   ()));
    QObject::connect(view, SIGNAL(mouseCursorChanged()), q, SIGNAL(mouseCursorChanged()));

#ifdef QT_4
    QObject::connect(view, SIGNAL(openglChanged()), q, SIGNAL(openglChanged()));
#endif

    QObject::connect(view, SIGNAL(antialiasChanged()), q, SIGNAL(antialiasChanged()));
    QObject::connect(view, SIGNAL(vsyncChanged    ()), q, SIGNAL(vsyncChanged    ()));

    QObject::connect(view, SIGNAL(hoverEnabledChanged()), q, SIGNAL(hoverEnabledChanged()));

    QObject::connect(view, SIGNAL(fadeEnabledChanged ()), q, SIGNAL(fadeEnabledChanged ()));
    QObject::connect(view, SIGNAL(fadeDurationChanged()), q, SIGNAL(fadeDurationChanged()));

    //---------------------------------------------------------------------------------------------

    QObject::connect(view, SIGNAL(idleCheckChanged()), q, SIGNAL(idleCheckChanged()));
    QObject::connect(view, SIGNAL(idleChanged     ()), q, SIGNAL(idleChanged     ()));
    QObject::connect(view, SIGNAL(idleDelayChanged()), q, SIGNAL(idleDelayChanged()));

    //---------------------------------------------------------------------------------------------

    QObject::connect(view, SIGNAL(mousePressed(WDeclarativeMouseEvent *)),
                     q,    SIGNAL(mousePressed(WDeclarativeMouseEvent *)));

    QObject::connect(view, SIGNAL(mouseReleased(WDeclarativeMouseEvent *)),
                     q,    SIGNAL(mouseReleased(WDeclarativeMouseEvent *)));

    QObject::connect(view, SIGNAL(mouseDoubleClicked(WDeclarativeMouseEvent *)),
                     q,    SIGNAL(mouseDoubleClicked(WDeclarativeMouseEvent *)));

    QObject::connect(view, SIGNAL(keyPressed(WDeclarativeKeyEvent *)),
                     q,    SIGNAL(keyPressed(WDeclarativeKeyEvent *)));

    QObject::connect(view, SIGNAL(keyReleased(WDeclarativeKeyEvent *)),
                     q,    SIGNAL(keyReleased(WDeclarativeKeyEvent *)));

    //---------------------------------------------------------------------------------------------

    QObject::connect(view, SIGNAL(keyShiftPressedChanged()),
                     q,    SIGNAL(keyShiftPressedChanged()));

    QObject::connect(view, SIGNAL(keyControlPressedChanged()),
                     q,    SIGNAL(keyControlPressedChanged()));

    QObject::connect(view, SIGNAL(keyAltPressedChanged()),
                     q,    SIGNAL(keyAltPressedChanged()));

    //---------------------------------------------------------------------------------------------

    QObject::connect(view, SIGNAL(availableGeometryChanged()),
                     q,    SIGNAL(availableGeometryChanged()));
}
Exemplo n.º 4
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;
    }
}