示例#1
0
void QG_GraphicView::mousePressEvent(QMouseEvent* e) {
    // pan zoom with middle mouse button
#if QT_VERSION < 0x040700
    if (e->button()==Qt::MidButton /*|| (e->state()==Qt::LeftButton|Qt::AltButton)*/) {
#else
    if (e->button()==Qt::MiddleButton /*|| (e->state()==Qt::LeftButton|Qt::AltButton)*/) {
#endif
        setCurrentAction(new RS_ActionZoomPan(*container, *this));
    }

    RS_GraphicView::mousePressEvent(e);
    QWidget::mousePressEvent(e);
}

void QG_GraphicView::mouseDoubleClickEvent(QMouseEvent* e) {
    // zoom auto with double click middle mouse button
#if QT_VERSION < 0x040700
    if (e->button()==Qt::MidButton) {
#else
    if (e->button()==Qt::MiddleButton) {
#endif
        setCurrentAction(new RS_ActionZoomAuto(*container, *this));
        e->accept();
    }
}


void QG_GraphicView::mouseReleaseEvent(QMouseEvent* e) {
        RS_DEBUG->print("QG_GraphicView::mouseReleaseEvent");
    RS_GraphicView::mouseReleaseEvent(e);
    //QWidget::mouseReleaseEvent(e);

    if (!e->isAccepted()) {
        if (QG_DIALOGFACTORY!=NULL && QG_DIALOGFACTORY->getCadToolBar()!=NULL) {
                        RS_DEBUG->print("QG_GraphicView::mouseReleaseEvent: "
                                "fwd to cadtoolbar");
            QG_DIALOGFACTORY->getCadToolBar()->mouseReleaseEvent(e);
        }
    }
        RS_DEBUG->print("QG_GraphicView::mouseReleaseEvent: OK");
}


void QG_GraphicView::mouseMoveEvent(QMouseEvent* e) {
    //RS_DEBUG->print("QG_GraphicView::mouseMoveEvent begin");
    //QMouseEvent rsm = QG_Qt2Rs::mouseEvent(e);

    RS_GraphicView::mouseMoveEvent(e);
    QWidget::mouseMoveEvent(e);

#ifdef Q_OS_WIN32
        // make sure that we can still use hotkeys and the mouse wheel
        if (parent()!=NULL) {
                ((QWidget*)parent())->setFocus();
        }
#endif

    //RS_DEBUG->print("QG_GraphicView::mouseMoveEvent end");
}
示例#2
0
/**
 * mouse wheel event. zooms in/out or scrolls when
 * shift or ctrl is pressed.
 */
void QG_GraphicView::wheelEvent(QWheelEvent *e) {
    //RS_DEBUG->print("wheel: %d", e->delta());

    //printf("state: %d\n", e->state());
    //printf("ctrl: %d\n", Qt::ControlButton);

    if (container==NULL) {
        return;
    }

        RS_Vector mouse = toGraph(RS_Vector(e->x(), e->y()));

    bool scroll = false;
    RS2::Direction direction = RS2::Up;

    // scroll up / down:
    if (e->modifiers()==Qt::ControlModifier) {
        scroll = true;
        if (e->delta()>0) {
            direction = RS2::Up;
        } else {
            direction = RS2::Down;
        }
    }

    // scroll left / right:
    else if	(e->modifiers()==Qt::ShiftModifier) {
        scroll = true;
        if (e->delta()>0) {
            direction = RS2::Right;
        } else {
            direction = RS2::Left;
        }
    }

    if (scroll) {
        setCurrentAction(new RS_ActionZoomScroll(direction,
                         *container, *this));
    }

    // zoom in / out:
    else if (e->modifiers()==0) {
        if (e->delta()>0) {
            setCurrentAction(new RS_ActionZoomIn(*container, *this,
                                                 RS2::In, RS2::Both,
                                                                                                 mouse));
        } else {
            setCurrentAction(new RS_ActionZoomIn(*container, *this,
                                                 RS2::Out, RS2::Both,
                                                                                                 mouse));
        }
    }

        redraw();

    e->accept();
}
示例#3
0
void QG_ActionHandler::slotLockRelativeZero(bool on) {
    if (lockRelativeZero!=NULL) {
        lockRelativeZero->setChecked(on);
    }
    if (on) {
        setCurrentAction(RS2::ActionLockRelativeZero);
    } else {
        setCurrentAction(RS2::ActionUnlockRelativeZero);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setLockRelativeZero(on);
    }
}
示例#4
0
void QG_ActionHandler::slotLockRelativeZero(bool on) {
    if (lockRelativeZero!=NULL) {
        lockRelativeZero->setOn(on);
    }
    if (on) {
        setCurrentAction(RS2::ActionLockRelativeZero);
    } else {
        setCurrentAction(RS2::ActionUnlockRelativeZero);
    }
#if QT_VERSION>=0x030000
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setLockRelativeZero(on);
    }
#endif
}
示例#5
0
/*!
  \internal
  \brief Establishes all connections.
 */
void Ui::MainWindow::establishConnections()
{
    Ui::CommonBar *commonBar = qobject_cast<Ui::CommonBar *>(actionManager->toolBar(Core::ID::COMMON_BAR));
    connect(commonBar, SIGNAL(antialiasingChanged(bool)), this, SIGNAL(antialiasingChanged(bool)));

    connect(newAction, SIGNAL(triggered()), this, SLOT(showProjectCreateDialog()));
    connect(openAction, SIGNAL(triggered()), this, SLOT(showOpenDialog()));
    //connect(actionManager->action(Core::ID::Action::NEW), SIGNAL(triggered()), this, SLOT(showPreferencesDialog()));
    connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAboutDialog()));

    // tool box actions
    connect(lineToolAction, SIGNAL(triggered()), mapper, SLOT(map()));
    mapper->setMapping(lineToolAction, Core::ID::ACTION_DRAW_LINE);
    connect(textToolAction, SIGNAL(triggered()), mapper, SLOT(map()));
    mapper->setMapping(textToolAction, Core::ID::ACTION_DRAW_TEXT);
    connect(curveToolAction, SIGNAL(triggered()), mapper, SLOT(map()));
    mapper->setMapping(curveToolAction, Core::ID::ACTION_DRAW_CURVE);
    connect(ellipseToolAction, SIGNAL(triggered()), mapper, SLOT(map()));
    mapper->setMapping(ellipseToolAction, Core::ID::ACTION_DRAW_ELLIPSE);
    connect(polygonToolAction, SIGNAL(triggered()), mapper, SLOT(map()));
    mapper->setMapping(polygonToolAction, Core::ID::ACTION_DRAW_POLYGON);
    connect(rectangleToolAction, SIGNAL(triggered()), mapper, SLOT(map()));
    mapper->setMapping(rectangleToolAction, Core::ID::ACTION_DRAW_RECT);
    connect(roundRectangleToolAction, SIGNAL(triggered()), mapper, SLOT(map()));
    mapper->setMapping(roundRectangleToolAction, Core::ID::ACTION_DRAW_ROUND_RECT);
    connect(mapper, SIGNAL(mapped(QString)), appCtx, SLOT(setCurrentAction(QString)));
    connect(mapper, SIGNAL(mapped(QString)), commonBar, SLOT(resetCommonBar(QString)));

    connect(ci, SIGNAL(foregroundColorChanged(QColor)), appCtx, SLOT(setPenColor(const QColor &)));
}
示例#6
0
bool QG_GraphicView::event(QEvent *event) {
#if QT_VERSION >= 0x050200
    if (event->type() == QEvent::NativeGesture) {
        QNativeGestureEvent *nge = static_cast<QNativeGestureEvent *>(event);

        if (nge->gestureType() == Qt::ZoomNativeGesture) {
            double v = nge->value();
            RS2::ZoomDirection direction;
            double factor;

            if (v < 0) {
                direction = RS2::Out;
                factor = 1-v;
            } else {
                direction = RS2::In;
                factor = 1+v;
            }

            // It seems the NativeGestureEvent::pos() incorrectly reports global coordinates
            QPoint g = mapFromGlobal(nge->globalPos());
            RS_Vector mouse = toGraph(RS_Vector(g.x(), g.y()));
            setCurrentAction(new RS_ActionZoomIn(*container, *this, direction,
                                                 RS2::Both, mouse, factor));
        }

        return true;
    }
#endif
	return QWidget::event(event);
}
示例#7
0
void KoZoomAction::regenerateItems(const qreal zoom, bool asCurrent)
{
    // where we'll store sorted new zoom values
    QList<qreal> zoomLevels;
    zoomLevels << 33;
    zoomLevels << 50;
    zoomLevels << 75;
    zoomLevels << 100;
    zoomLevels << 125;
    zoomLevels << 150;
    zoomLevels << 200;
    zoomLevels << 250;
    zoomLevels << 350;
    zoomLevels << 400;
    zoomLevels << 450;
    zoomLevels << 500;

    if( !zoomLevels.contains( zoom*100 ) )
        zoomLevels << zoom*100;

    qSort(zoomLevels.begin(), zoomLevels.end());

    // update items with new sorted zoom values
    QStringList values;
    if(d->zoomModes & KoZoomMode::ZOOM_WIDTH)
    {
        values << KoZoomMode::toString(KoZoomMode::ZOOM_WIDTH);
    }
    if(d->zoomModes & KoZoomMode::ZOOM_PAGE)
    {
        values << KoZoomMode::toString(KoZoomMode::ZOOM_PAGE);
    }

    foreach(qreal value, zoomLevels) {
        if(value>10.0)
            values << i18n("%1%", KGlobal::locale()->formatNumber(value, 0));
        else
            values << i18n("%1%", KGlobal::locale()->formatNumber(value, 1));
    }

    setItems( values );

    if(d->input)
        d->input->setZoomLevels(values);

    if(asCurrent)
    {
        QString valueString;
        if(zoom*100>10.0)
            valueString = i18n("%1%", KGlobal::locale()->formatNumber(zoom*100, 0));
        else
            valueString = i18n("%1%", KGlobal::locale()->formatNumber(zoom*100, 1));

        setCurrentAction(valueString);

        if(d->input)
            d->input->setCurrentZoomLevel(valueString);
    }
}
示例#8
0
void QG_GraphicView::mousePressEvent(QMouseEvent* event)
{
    // pan zoom with middle mouse button
    if (event->button()==Qt::MiddleButton)
    {
        setCurrentAction(new RS_ActionZoomPan(*container, *this));
    }
    eventHandler->mousePressEvent(event);
}
示例#9
0
void QG_ActionHandler::slotSnapIntersectionManual() {
    //disableSnaps();
    /*if (snapIntersectionManual!=NULL) {
        snapIntersectionManual->setOn(true);
}*/
    /*if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapMode(RS2::SnapIntersectionManual);
}*/
    setCurrentAction(RS2::ActionSnapIntersectionManual);
}
示例#10
0
void QG_ActionHandler::slotRestrictVertical() {
    disableRestrictions();
    if (restrictVertical!=NULL) {
        restrictVertical->setChecked(true);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapRestriction(RS2::RestrictVertical);
    }
    setCurrentAction(RS2::ActionRestrictVertical);
}
示例#11
0
void QG_ActionHandler::slotSnapIntersection() {
    disableSnaps();
    if (snapIntersection!=NULL) {
        snapIntersection->setChecked(true);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapMode(RS2::SnapIntersection);
    }
    setCurrentAction(RS2::ActionSnapIntersection);
}
示例#12
0
void QG_ActionHandler::slotSnapOnEntity() {
    disableSnaps();
    if (snapOnEntity!=NULL) {
        snapOnEntity->setChecked(true);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapMode(RS2::SnapOnEntity);
    }
    setCurrentAction(RS2::ActionSnapOnEntity);
}
示例#13
0
void QG_ActionHandler::slotSnapEndpoint() {
    disableSnaps();
    if (snapEndpoint!=NULL) {
        snapEndpoint->setChecked(true);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapMode(RS2::SnapEndpoint);
    }
    setCurrentAction(RS2::ActionSnapEndpoint);
}
示例#14
0
void FontSizeAction::setFontSize( qreal size )
{
    if ( size == fontSize() ) {
        const QString test = format(size);
        Q_FOREACH(QAction* action, actions()) {
          if (action->text() == test) {
              setCurrentAction(action);
              return;
          }
        }
    }

    if ( size < 1 ) {
        kWarning() << "FontSizeAction: Size " << size << " is out of range";
        return;
    }

    QAction* a = action( format(size) );
    if ( !a ) {
        // Insert at the correct position in the list (to keep sorting)
        QList<qreal> lst;
        // Convert to list of qreals
        QStringListIterator itemsIt( items() );
	QStringList debug_lst = items();

        while ( itemsIt.hasNext() ) {
            lst.append( itemsIt.next().toDouble() );
        }
        //add the new size
        lst.append( size );

        //remove actions
        clear();

        // Sort the list
        qSort( lst );
        Q_FOREACH( qreal it, lst ) {
            KAction* const action = addAction( format(it) );
            if (it == size) {
                setCurrentAction(action);
            }
        }
示例#15
0
void QG_ActionHandler::slotRestrictVertical() {
    disableRestrictions();
    if (restrictVertical!=NULL) {
        restrictVertical->setOn(true);
    }
#if QT_VERSION>=0x030000
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapRestriction(RS2::RestrictVertical);
    }
#endif
    setCurrentAction(RS2::ActionRestrictVertical);
}
示例#16
0
void QG_ActionHandler::slotSnapIntersection() {
    disableSnaps();
    if (snapIntersection!=NULL) {
        snapIntersection->setOn(true);
    }
#if QT_VERSION>=0x030000
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapMode(RS2::SnapIntersection);
    }
#endif
    setCurrentAction(RS2::ActionSnapIntersection);
}
void QueryFinishWizardPage::initializePage()
{
	m_result->clear();
	ui.progressBar->setValue(0);
	Framework* fw = framework();
	setCurrentAction(tr("Collecting information..."));
	quint32 storeId = field("store").value<quint32>();
	const QString queryStr = field("query").toString();
	setCurrentAction(tr("Looking for store..."));
	const DataStore* dataStore = fw->dataStoreById(storeId);
	if(dataStore == NULL) return;
	setCurrentAction(tr("Store found..."));
	setCurrentAction(tr("Parsing query..."));
	CGSQL_NS::RootNode *root = CGSQL_NS::QueryParser::parse(queryStr.toStdString());
	if (root == NULL)
	{
		setCurrentAction("Error while parting query.");
		return;
	}
	pgn::GameCollection loadedGames;
	setCurrentAction(tr("Retrieving games from %1...").arg(dataStore->name().toLower()));
	bool loadResult = dataStore->load(root, loadedGames);
	if(!loadResult)
	{
		setCurrentAction(tr("Can not load games from %1...").arg(dataStore->name().toLower()));
		return;
	}
	setCurrentAction(tr("Loaded %1 games. Looking for concepts in its...").arg(loadedGames.size()));
	QProgressDialog* progressDialog = new QProgressDialog("Searching for concepts", "Cancel", 0, loadedGames.size());
	progressDialog->setWindowModality(Qt::WindowModal);
	progressDialog->setValue(0);
	int progress = 0;
	for(pgn::GameCollection::iterator it = loadedGames.begin();
		it != loadedGames.end();
		++it)
	{
		progressDialog->show();
		m_result->data().addGame(&(*it));
		if(root->body()->accept(&(m_result->data())))
			m_result->games().insert(*it);
		progressDialog->setValue(progress);
		++progress;
	}
	progressDialog->setValue(100);
	progressDialog->setAutoClose(true);
	progressDialog->reset();
	progressDialog->show();
	progressDialog->deleteLater();
	ui.progressBar->setValue(100);
}
示例#18
0
void QG_GraphicView::mouseDoubleClickEvent(QMouseEvent* e)
{
    switch(e->button())
    {
        default:
            break;
        case Qt::MiddleButton:
            setCurrentAction(new RS_ActionZoomAuto(*container, *this));
            break;
        case Qt::LeftButton:
            if (menus.contains("Double-Click"))
            {
                killAllActions();
                menus["Double-Click"]->popup(mapToGlobal(e->pos()));
            }
            break;
    }
    e->accept();
}
示例#19
0
void QG_GraphicView::keyPressEvent(QKeyEvent* e) {
    //if (e->key()==Qt::Key_Control) {
    //	setCtrlPressed(true);
    //}


    if (container==NULL) {
        return;
    }

    bool scroll = false;
    RS2::Direction direction = RS2::Up;

    switch (e->key()) {
    case Qt::Key_Left:
        scroll = true;
        direction = RS2::Right;
        break;
    case Qt::Key_Right:
        scroll = true;
        direction = RS2::Left;
        break;
    case Qt::Key_Up:
        scroll = true;
        direction = RS2::Up;
        break;
    case Qt::Key_Down:
        scroll = true;
        direction = RS2::Down;
        break;
    default:
        scroll = false;
        break;
    }

    if (scroll) {
        setCurrentAction(new RS_ActionZoomScroll(direction,
                         *container, *this));
    }

    RS_GraphicView::keyPressEvent(e);
}
示例#20
0
/**
 * Launches the given command if possible.
 *
 * @return true: the command was recognized. 
 *         false: the command is not known and was probably intended for a
 *            running action.
 */
bool QG_ActionHandler::command(const QString& cmd) {
	RS_DEBUG->print("QG_ActionHandler::command: %s", cmd.latin1());
    QString c = cmd.lower();

    if (c=="\n") {
        RS_GraphicView* gv = mainWindow->getGraphicView();
        if (gv!=NULL) {
            gv->back();
        }
		RS_DEBUG->print("QG_ActionHandler::command: back");
        return true;
    }

    // pass command on to running action:
    RS_CommandEvent e(cmd);

    RS_GraphicView* gv = mainWindow->getGraphicView();
    if (gv!=NULL) {
		RS_DEBUG->print("QG_ActionHandler::command: trigger command event in "
		" graphic view");
        gv->commandEvent(&e);
    }

    // if the current action can't deal with the command,
    //   it might be intended to launch a new command
    if (!e.isAccepted()) {
		RS_DEBUG->print("QG_ActionHandler::command: convert cmd to action type");
        // command for new action:
        RS2::ActionType type = RS_COMMANDS->cmdToAction(cmd);
        if (type!=RS2::ActionNone) {
			RS_DEBUG->print("QG_ActionHandler::command: setting current action");
            setCurrentAction(type);
			RS_DEBUG->print("QG_ActionHandler::command: current action set");
            return true;
        }
    }

	RS_DEBUG->print("QG_ActionHandler::command: current action not set");
    return false;
}
示例#21
0
void QG_ActionHandler::slotZoomPan() {
    setCurrentAction(RS2::ActionZoomPan);
}
示例#22
0
/**
 * mouse wheel event. zooms in/out or scrolls when
 * shift or ctrl is pressed.
 */
void QG_GraphicView::wheelEvent(QWheelEvent *e) {
    //RS_DEBUG->print("wheel: %d", e->delta());

    //printf("state: %d\n", e->state());
    //printf("ctrl: %d\n", Qt::ControlButton);

    if (container==NULL) {
        return;
    }

    RS_Vector mouse = toGraph(RS_Vector(e->x(), e->y()));

#if QT_VERSION >= 0x050200
    QPoint numPixels = e->pixelDelta();

    // high-resolution scrolling triggers Pan instead of Zoom logic
    isSmoothScrolling |= !numPixels.isNull();

    if (isSmoothScrolling) {
        if (e->phase() == Qt::ScrollEnd) isSmoothScrolling = false;

        if (!numPixels.isNull()) {
            if (e->modifiers()==Qt::ControlModifier) {
                // Hold ctrl to zoom. 1 % per pixel
                double v = -numPixels.y() / 100.;
                RS2::ZoomDirection direction;
                double factor;

                if (v < 0) {
                    direction = RS2::Out; factor = 1-v;
                } else {
                    direction = RS2::In;  factor = 1+v;
                }

                setCurrentAction(new RS_ActionZoomIn(*container, *this, direction,
                                                     RS2::Both, mouse, factor));
            } else {
                // otherwise, scroll
                setCurrentAction(new RS_ActionZoomScroll(numPixels.x(), numPixels.y(),
                                                         *container, *this));
            }
            redraw();
        }
        e->accept();
        return;
    }
#endif

    if (e->delta() == 0) {
        // A zero delta event occurs when smooth scrolling is ended. Ignore this
        e->accept();
        return;
    }

    bool scroll = false;
    RS2::Direction direction = RS2::Up;

    // scroll up / down:
    if (e->modifiers()==Qt::ControlModifier) {
        scroll = true;
        switch(e->orientation()){
        case Qt::Horizontal:
            direction=(e->delta()>0)?RS2::Left:RS2::Right;
            break;
        default:
        case Qt::Vertical:
            direction=(e->delta()>0)?RS2::Up:RS2::Down;
        }
    }

    // scroll left / right:
    else if	(e->modifiers()==Qt::ShiftModifier) {
        scroll = true;
        switch(e->orientation()){
        case Qt::Horizontal:
            direction=(e->delta()>0)?RS2::Up:RS2::Down;
            break;
        default:
        case Qt::Vertical:
            direction=(e->delta()>0)?RS2::Left:RS2::Right;
        }
    }

    if (scroll) {
        setCurrentAction(new RS_ActionZoomScroll(direction,
                         *container, *this));
    }

    // zoom in / out:
    else if (e->modifiers()==0) {
        if (e->delta()>0) {
            setCurrentAction(new RS_ActionZoomIn(*container, *this,
                                                 RS2::In, RS2::Both,
                                                                                                 mouse));
        } else {
            setCurrentAction(new RS_ActionZoomIn(*container, *this,
                                                 RS2::Out, RS2::Both,
                                                                                                 mouse));
        }
    }

        redraw();

    e->accept();
}
示例#23
0
/**
 * support for the wacom graphic tablet.
 */
void QG_GraphicView::tabletEvent(QTabletEvent* e) {
    if (testAttribute(Qt::WA_UnderMouse)) {
        switch (e->device()) {
        case QTabletEvent::Eraser:
            if (e->type()==QEvent::TabletRelease) {
                if (container!=NULL) {

                    RS_ActionSelectSingle* a =
                        new RS_ActionSelectSingle(*container, *this);
                    setCurrentAction(a);
                    QMouseEvent ev(QEvent::MouseButtonRelease, e->pos(),
                                   Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);//RLZ
                    mouseReleaseEvent(&ev);
                    a->finish();

                    if (container->countSelected()>0) {
                        setCurrentAction(
                            new RS_ActionModifyDelete(*container, *this));
                    }
                }
            }
            break;

        case QTabletEvent::Stylus:
        case QTabletEvent::Puck:
            if (e->type()==QEvent::TabletPress) {
                QMouseEvent ev(QEvent::MouseButtonPress, e->pos(),
                               Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);//RLZ
                mousePressEvent(&ev);
            } else if (e->type()==QEvent::TabletRelease) {
                QMouseEvent ev(QEvent::MouseButtonRelease, e->pos(),
                               Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);//RLZ
                mouseReleaseEvent(&ev);
            } else if (e->type()==QEvent::TabletMove) {
                QMouseEvent ev(QEvent::MouseMove, e->pos(),
                               Qt::NoButton, 0, Qt::NoModifier);//RLZ
                mouseMoveEvent(&ev);
            }
            break;

        default:
            break;
        }
    }

    // a 'mouse' click:
    /*if (e->pressure()>10 && lastPressure<10) {
        QMouseEvent e(QEvent::MouseButtonPress, e->pos(),
           Qt::LeftButton, Qt::LeftButton);
        mousePressEvent(&e);
}
    else if (e->pressure()<10 && lastPressure>10) {
        QMouseEvent e(QEvent::MouseButtonRelease, e->pos(),
           Qt::LeftButton, Qt::LeftButton);
        mouseReleaseEvent(&e);
}	else if (lastPos!=e->pos()) {
        QMouseEvent e(QEvent::MouseMove, e->pos(),
           Qt::NoButton, 0);
        mouseMoveEvent(&e);
}

    lastPressure = e->pressure();
    lastPos = e->pos();
    */
}
示例#24
0
void QG_ActionHandler::slotZoomPrevious() {
    setCurrentAction(RS2::ActionZoomPrevious);
}
示例#25
0
void QG_ActionHandler::slotZoomWindow() {
    setCurrentAction(RS2::ActionZoomWindow);
}
示例#26
0
/**
 * mouse wheel event. zooms in/out or scrolls when
 * shift or ctrl is pressed.
 */
void QG_GraphicView::wheelEvent(QWheelEvent *e) {
    //RS_DEBUG->print("wheel: %d", e->delta());

    //printf("state: %d\n", e->state());
    //printf("ctrl: %d\n", Qt::ControlButton);

    if (container==NULL) {
        return;
    }

    RS_Vector mouse = toGraph(e->x(), e->y());

    if (device == "Trackpad")
    {
        QPoint numPixels = e->pixelDelta();

        // high-resolution scrolling triggers Pan instead of Zoom logic
        isSmoothScrolling |= !numPixels.isNull();

        if (isSmoothScrolling)
        {
            if (e->phase() == Qt::ScrollEnd) isSmoothScrolling = false;
        }
        else // Trackpads that without high-resolution scrolling
             // e.g. libinput-XWayland trackpads
        {
            numPixels = e->angleDelta() / 4;
        }

        if (!numPixels.isNull())
        {
            if (e->modifiers()==Qt::ControlModifier)
            {
                RS_SETTINGS->beginGroup("/Defaults");
                bool invZoom = (RS_SETTINGS->readNumEntry("/InvertZoomDirection", 0) == 1);
                RS_SETTINGS->endGroup();

                // Hold ctrl to zoom. 1 % per pixel
                double v = (invZoom) ? (numPixels.y() / 100.) : (-numPixels.y() / 100.);
                RS2::ZoomDirection direction;
                double factor;

                if (v < 0) {
                    direction = RS2::Out; factor = 1-v;
                } else {
                    direction = RS2::In;  factor = 1+v;
                }

                setCurrentAction(new RS_ActionZoomIn(*container, *this, direction,
                                                     RS2::Both, &mouse, factor));
            }
            else
            {
                RS_SETTINGS->beginGroup("/Defaults");
                bool inv_h = (RS_SETTINGS->readNumEntry("/WheelScrollInvertH", 0) == 1);
                bool inv_v = (RS_SETTINGS->readNumEntry("/WheelScrollInvertV", 0) == 1);
                RS_SETTINGS->endGroup();

                int hDelta = (inv_h) ? -numPixels.x() : numPixels.x();
                int vDelta = (inv_v) ? -numPixels.y() : numPixels.y();

                // scroll by scrollbars: issue #479 (it has its own issues)
                if (scrollbars)
                {
                    hScrollBar->setValue(hScrollBar->value() - hDelta);
                    vScrollBar->setValue(vScrollBar->value() - vDelta);
                }
                else
                {
                    setCurrentAction(new RS_ActionZoomScroll(hDelta, vDelta,
                                                             *container, *this));
                }
            }
            redraw();
        }
        e->accept();
        return;
    }

    if (e->delta() == 0) {
        // A zero delta event occurs when smooth scrolling is ended. Ignore this
        e->accept();
        return;
    }

    bool scroll = false;
    RS2::Direction direction = RS2::Up;

    // scroll up / down:
    if (e->modifiers()==Qt::ControlModifier) {
        scroll = true;
        switch(e->orientation()){
        case Qt::Horizontal:
            direction=(e->delta()>0)?RS2::Left:RS2::Right;
            break;
        default:
        case Qt::Vertical:
            direction=(e->delta()>0)?RS2::Up:RS2::Down;
        }
    }

    // scroll left / right:
    else if	(e->modifiers()==Qt::ShiftModifier) {
        scroll = true;
        switch(e->orientation()){
        case Qt::Horizontal:
            direction=(e->delta()>0)?RS2::Up:RS2::Down;
            break;
        default:
        case Qt::Vertical:
            direction=(e->delta()>0)?RS2::Left:RS2::Right;
        }
    }

    if (scroll && scrollbars) {
		//scroll by scrollbars: issue #479

        RS_SETTINGS->beginGroup("/Defaults");
        bool inv_h = (RS_SETTINGS->readNumEntry("/WheelScrollInvertH", 0) == 1);
        bool inv_v = (RS_SETTINGS->readNumEntry("/WheelScrollInvertV", 0) == 1);
        RS_SETTINGS->endGroup();

        int delta;

		switch(direction){
		case RS2::Left:
		case RS2::Right:
            delta = (inv_h) ? -e->delta() : e->delta();
			hScrollBar->setValue(hScrollBar->value()+delta);
			break;
		default:
            delta = (inv_v) ? -e->delta() : e->delta();
			vScrollBar->setValue(vScrollBar->value()+delta);
		}

//        setCurrentAction(new RS_ActionZoomScroll(direction,
//                         *container, *this));
    }

    // zoom in / out:
    else if (e->modifiers()==0) {

        /*
         * The zoomFactor effects how quickly the scroll wheel will zoom in & out.
         *
         * Benchmarks:
         * 1.250 - the original; fast & usable, but seems a choppy & a bit 'jarring'
         * 1.175 - still a bit choppy
         * 1.150 - smoother than the original, but still 'quick' enough for good navigation.
         * 1.137 - seems to work well for me
         * 1.125 - about the lowest that would be acceptable and useful, a tad on the slow side for me
         * 1.100 - a very slow & deliberate zooming, but feels very "cautious", "controlled", "safe", and "precise".
         * 1.000 - goes nowhere. :)
         */
		const double zoomFactor=1.137;

		RS_Vector mainViewCenter = toGraph(getWidth()/2, getHeight()/2);

		RS_SETTINGS->beginGroup("/Defaults");
		bool invZoom = (RS_SETTINGS->readNumEntry("/InvertZoomDirection", 0) == 1);
		RS_SETTINGS->endGroup();

		if ((e->delta()>0 && !invZoom) || (e->delta()<0 && invZoom)) {
			const double zoomInOvershoot=1.20;

			RS_Vector effect{mouse};
			{
				effect-=mainViewCenter;
				effect.scale(zoomInOvershoot);
				effect+=mainViewCenter;
			}

			setCurrentAction(new RS_ActionZoomIn(*container, *this,
												 RS2::In, RS2::Both,
												 &effect,
												 zoomFactor
												));
		} else {
			const double zoomOutUndershoot=0.30;

			RS_Vector effect{mouse};
			{
				effect-=mainViewCenter;
				effect.scale(zoomOutUndershoot);
				effect+=mainViewCenter;
			}

			setCurrentAction(new RS_ActionZoomIn(*container, *this,
												 RS2::Out, RS2::Both,
												 &effect,
												 zoomFactor
												));
		}
    }
    redraw();

    QMouseEvent* event = new QMouseEvent(QEvent::MouseMove,
                                         QPoint(e->x(), e->y()),
                                         Qt::NoButton, Qt::NoButton,
                                         Qt::NoModifier);
    eventHandler->mouseMoveEvent(event);
    delete event;

    e->accept();
}
示例#27
0
void QG_ActionHandler::slotZoomRedraw() {
    setCurrentAction(RS2::ActionZoomRedraw);
}
示例#28
0
void QG_ActionHandler::slotToolRegenerateDimensions() {
    setCurrentAction(RS2::ActionToolRegenerateDimensions);
}
示例#29
0
void QG_ActionHandler::slotEditCopy() {
    setCurrentAction(RS2::ActionEditCopy);
}
示例#30
0
void QG_ActionHandler::slotEditRedo() {
    setCurrentAction(RS2::ActionEditRedo);
}