Beispiel #1
0
void SC_SimulateTab::keyReleaseEvent( QKeyEvent* e )
{
    int k = e -> key();
    Qt::KeyboardModifiers m = e -> modifiers();
    switch ( k )
    {
    case Qt::Key_W:
    {
        if ( m.testFlag( Qt::ControlModifier ) == true )
        {
            TabCloseRequest( currentIndex() );
            return;
        }
    }
        break;
    case Qt::Key_T:
    {
        if ( m.testFlag( Qt::ControlModifier ) == true )
        {
            insertNewTabAt( currentIndex() + 1 );
            return;
        }
    }
        break;
    default: break;
    }
    SC_RecentlyClosedTab::keyReleaseEvent( e );
}
void MouseEventHandler::mousePressEvent( QMouseEvent* event ) 
{ 
    if( event->button() == Qt::LeftButton )
    {
        Qt::KeyboardModifiers keyMod = event->modifiers();
        bool shift = keyMod.testFlag(Qt::ShiftModifier);
        bool ctrl = keyMod.testFlag(Qt::ControlModifier);

        if( shift && !ctrl ) // as long as shift is pressed
        {
            Q_EMIT mouseLeftButtonShift( true, event->x(), event->y() );
        }
        if( ctrl && !shift ) // if only ctrl is pressed
        {
            Q_EMIT mouseLeftButtonCtrl( true, event->x(), event->y() );
        }

        if( !ctrl && !shift )
        {
            Q_EMIT mouseLeftButton( true, event->x(), event->y() );
        }
    }
    else if( event->button() == Qt::RightButton )
    {
        Q_EMIT mouseRightButton( true, event->x(), event->y() );
    }
}
Beispiel #3
0
 void Wt_TextEdit::keyPressEvent(QKeyEvent *e)
 {
 	printf("keyPressEvent key: %d \n", e->key());
 	printf("keyPressEvent text: %s \n", e->text().toStdString().c_str());
	Qt::KeyboardModifiers keyMod = QApplication::keyboardModifiers();
	bool isSHIFT = keyMod.testFlag(Qt::ShiftModifier);
	bool isCTRL  = keyMod.testFlag(Qt::ControlModifier);
 	
    if(e->key() == Qt::Key_Return) {
			wt_pressEnter();
			return;
    }
    if(e->text() == "}") {
    	QTextCursor textCursor = this->textCursor();
    	int currentPos = textCursor.position();
    	textCursor.insertText("}");
    	int findPositivePos = wt_findPairChar(currentPos, '{');
    	if(findPositivePos != -1) {
    		wt_indentChar(currentPos, findPositivePos);
    	}
    	return;
    }
	if(isCTRL && e->text() == "y"){
		printf("key = ctrl + y\n");
		redo();
		return;
	}
    QPlainTextEdit::keyPressEvent(e);
    
 }
SoGesturePinchEvent::SoGesturePinchEvent(QPinchGesture* qpinch, QWidget *widget)
{
    int h = widget->height();
    QPointF widgetCorner = QPointF(widget->mapToGlobal(QPoint(0,0)));
    qreal scaleToWidget = (widget->mapFromGlobal(QPoint(800,800))-widget->mapFromGlobal(QPoint(0,0))).x()/800.0;
    QPointF pnt;//temporary
    pnt = qpinch->startCenterPoint();
    pnt = (pnt-widgetCorner)*scaleToWidget;//translate screen coord. into widget coord.
    startCenter = SbVec2f(pnt.x(), h - pnt.y());

    pnt = qpinch->centerPoint();
    pnt = (pnt-widgetCorner)*scaleToWidget;
    curCenter = SbVec2f(pnt.x(), h - pnt.y());

    pnt = qpinch->lastCenterPoint();
    pnt = (pnt-widgetCorner)*scaleToWidget;
    deltaCenter = curCenter - SbVec2f(pnt.x(), h - pnt.y());

    deltaZoom = qpinch->scaleFactor();
    totalZoom = qpinch->totalScaleFactor();

    deltaAngle = qpinch->rotationAngle();
    totalAngle = qpinch->totalRotationAngle();

    state = SbGestureState(qpinch->state());

    this->setPosition(SbVec2s(curCenter));
    Qt::KeyboardModifiers mods = QApplication::keyboardModifiers();
    this->setAltDown(mods.testFlag(Qt::AltModifier));
    this->setCtrlDown(mods.testFlag(Qt::ControlModifier));
    this->setShiftDown(mods.testFlag(Qt::ShiftModifier));
    this->setTime(SbTime::getTimeOfDay());
}
Beispiel #5
0
Qt::KeyboardModifiers KxPopupMenu::popupMenuModifiers() const
{
    Qt::KeyboardModifiers mods = fModifiers;

    // Swap the CTRL & ALT keys if requested on the fly.
    //
    if ( fsSwapMetaKeys ) {
        bool isControl = mods.testFlag( Qt::ControlModifier );
        bool isAlt = mods.testFlag( Qt::AltModifier );

        if ( isControl ) {
            mods &= ~Qt::ControlModifier;
        }
        if ( isAlt ) {
            mods &= ~Qt::AltModifier;
        }

        if ( isControl ) {
            mods |= Qt::AltModifier;
        }
        if ( isAlt ) {
            mods |= Qt::ControlModifier;
        }
    }

    return mods;
}
SoGestureSwipeEvent::SoGestureSwipeEvent(QSwipeGesture *qwsipe, QWidget *widget)
{
    angle = qwsipe->swipeAngle();
    switch (qwsipe->verticalDirection()){
    case QSwipeGesture::Up :
        vertDir = +1;
        break;
    case QSwipeGesture::Down :
        vertDir = -1;
        break;
    default:
        vertDir = 0;
        break;
    }
    switch (qwsipe->horizontalDirection()){
    case QSwipeGesture::Right :
        horzDir = +1;
        break;
    case QSwipeGesture::Left :
        horzDir = -1;
        break;
    default:
        horzDir = 0;
        break;
    }

    state = SbGestureState(qwsipe->state());

    Qt::KeyboardModifiers mods = QApplication::keyboardModifiers();
    this->setAltDown(mods.testFlag(Qt::AltModifier));
    this->setCtrlDown(mods.testFlag(Qt::ControlModifier));
    this->setShiftDown(mods.testFlag(Qt::ShiftModifier));
    this->setTime(SbTime::getTimeOfDay());
}
Beispiel #7
0
void SC_SimulateTab::keyPressEvent( QKeyEvent* e )
{
    int k = e -> key();
    Qt::KeyboardModifiers m = e -> modifiers();

    if ( k == Qt::Key_Backtab ||
         (k == Qt::Key_Tab && m.testFlag( Qt::ControlModifier ) && m.testFlag( Qt::ShiftModifier )) )
    {
        if ( wrapToEnd() )
            return;
    }
    else if ( k == Qt::Key_Tab )
    {
        if ( wrapToBeginning() )
            return;
    }
    else if ( k == Qt::Key_W && m.testFlag( Qt::ControlModifier ) )
    {
        // close the tab in keyReleaseEvent()
        return;
    }
    else if ( k == Qt::Key_T && m.testFlag( Qt::ControlModifier ) )
    {
        return;
    }
    QTabWidget::keyPressEvent( e );
}
bool Scene_polyhedron_shortest_path_item::eventFilter(QObject* /*target*/, QEvent* event)
{
  if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease)
  {
    QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
    Qt::KeyboardModifiers modifiers = keyEvent->modifiers();
    m_shiftHeld = modifiers.testFlag(Qt::ShiftModifier);
  }
  
  if (event->type() == QEvent::MouseButtonPress && m_shiftHeld)
  {
    QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
    if(mouseEvent->button() == Qt::LeftButton) 
    {
      Ray_3 mouseRay;
      
      if (get_mouse_ray(mouseEvent, mouseRay))
      {
        if (run_point_select(mouseRay))
        {
          return true;
        }
      }
    }
  }
  
  return false;
}
void SkCanvasWidget::mouseDoubleClickEvent(QMouseEvent* event) {
    Qt::KeyboardModifiers modifiers = event->modifiers();
    if (modifiers.testFlag(Qt::ControlModifier)) {
        snapWidgetTransform();
    } else {
        resetWidgetTransform();
    }
}
static bool modifiersForGreedyAdd(Qt::KeyboardModifiers modifiers)
{
    // whether drag select should include intersected as well as contained features
    if (M_PREFS->getMouseSingleButton())
        return modifiers.testFlag(Qt::ShiftModifier) && modifiers.testFlag(Qt::AltModifier);
    else
        return modifiers.testFlag(Qt::ShiftModifier);
}
SoGesturePanEvent::SoGesturePanEvent(QPanGesture* qpan, QWidget *widget)
{
    totalOffset = SbVec2f(qpan->offset().x(), -qpan->offset().y());
    deltaOffset = SbVec2f(qpan->delta().x(), -qpan->delta().y());
    state = SbGestureState(qpan->state());

    Qt::KeyboardModifiers mods = QApplication::keyboardModifiers();
    this->setAltDown(mods.testFlag(Qt::AltModifier));
    this->setCtrlDown(mods.testFlag(Qt::ControlModifier));
    this->setShiftDown(mods.testFlag(Qt::ShiftModifier));
    this->setTime(SbTime::getTimeOfDay());
}
QPointF manipulatedVector(const QPointF &vector, Qt::KeyboardModifiers keyboardModifier)
{
    QPointF manipulatedVector = roundedVector(vector, snapFactor(keyboardModifier));

    if (keyboardModifier.testFlag(Qt::ShiftModifier))
        manipulatedVector.setX(0.);

    if (keyboardModifier.testFlag(Qt::AltModifier))
        manipulatedVector.setY(0.);

    return manipulatedVector;
}
Beispiel #13
0
LiveSingleSelectionManipulator::SelectionType LiveSelectionTool::getSelectionType(Qt::KeyboardModifiers
                                                                          modifiers)
{
   LiveSingleSelectionManipulator::SelectionType selectionType
            = LiveSingleSelectionManipulator::ReplaceSelection;
    if (modifiers.testFlag(Qt::ControlModifier)) {
        selectionType = LiveSingleSelectionManipulator::RemoveFromSelection;
    } else if (modifiers.testFlag(Qt::ShiftModifier)) {
        selectionType = LiveSingleSelectionManipulator::AddToSelection;
    }
    return selectionType;
}
//handle mouse press events
//
void
SystemTopologyDrawing::mousePressEvent( QMouseEvent* event )
{
    Qt::KeyboardModifiers mods = event->modifiers();
    //check if shift is pressed
    if ( mods.testFlag( Qt::ShiftModifier ) )
    {
        shiftPressed = true;
    }
    else
    {
        shiftPressed = false;
    }
    //check if control is pressed
    if ( mods.testFlag( Qt::ControlModifier ) )
    {
        controlPressed = true;
    }
    else
    {
        controlPressed = false;
    }

    //get the position of the click
    lastPoint = event->pos();
    //for left-mouse-pull remember the first point to compute the
    //difference later for mouse movement
    if ( !leftMousePressed )
    {
        firstPoint = lastPoint;
    }
    //left button is handled at mouse release or mouse movement
    if ( event->button() == Qt::LeftButton )
    {
        leftMousePressed = true;
        event->accept();
    }
    else if ( event->button() == Qt::RightButton )
    {
        //right button is for context info (painted by  draw())
        rightMousePressed = true;
        draw();
        event->accept();
    }
    else
    {
        event->ignore();
    }

    data->updateSelection();
}
Beispiel #15
0
void
ScaleSliderQWidget::focusInEvent(QFocusEvent* e)
{
    Qt::KeyboardModifiers mod = qApp->keyboardModifiers();

    if ( mod.testFlag(Qt::ControlModifier) ) {
        _imp->ctrlDown = true;
    }
    if ( mod.testFlag(Qt::ShiftModifier) ) {
        _imp->shiftDown = true;
    }
    zoomRange();
    QWidget::focusInEvent(e);
}
void SkCanvasWidget::wheelEvent(QWheelEvent* event) {
    Qt::KeyboardModifiers modifiers = event->modifiers();
    if (modifiers.testFlag(Qt::ControlModifier)) {
        zoom(event->delta() > 0 ? ZOOM_FACTOR : (1.0f / ZOOM_FACTOR), event->x(), event->y());
    } else {
        if (Qt::Horizontal == event->orientation()) {
            fUserMatrix.postTranslate(event->delta(), 0.0f);
        } else {
            fUserMatrix.postTranslate(0.0f, event->delta());
        }
        fDebugger->setUserMatrix(fUserMatrix);
        drawTo(fDebugger->index());
    }
}
static bool modifiersForDrag(Qt::KeyboardModifiers modifiers)
{
    if (M_PREFS->getMouseSingleButton())
        return modifiers.testFlag(Qt::ShiftModifier);
    else
        return true;
}
void
LauncherView::setHotkeysForModifiers(Qt::KeyboardModifiers modifiers)
{
    /* This is the new new state of the Super key (AKA Meta key), while
       m_superKeyPressed is the previous state of the key at the last modifiers change. */
    bool superKeyPressed = modifiers.testFlag(Qt::MetaModifier);

    if (m_superKeyPressed != superKeyPressed) {
        m_superKeyPressed = superKeyPressed;
        if (superKeyPressed) {
            m_superPressIgnored = false;
            /* If the key is pressed, start up a timer to monitor if it's being held short
               enough to qualify as just a "tap" or as a proper hold */
            m_superKeyHoldTimer.start();
        } else {
            m_superKeyHoldTimer.stop();

            /* If the key is released, and was not being held, it means that the user just
               performed a "tap". Unless we're told to ignore that tap, that is. */
            if (!m_superKeyHeld && !m_superPressIgnored) {
                Q_EMIT superKeyTapped();
            }
            /* Otherwise the user just terminated a hold. */
            else if(m_superKeyHeld){
                m_superKeyHeld = false;
                Q_EMIT superKeyHeldChanged(m_superKeyHeld);
            }
        }
    }
}
double snapFactor(Qt::KeyboardModifiers keyboardModifier)
{
    if (keyboardModifier.testFlag(Qt::ControlModifier))
        return 10.;

    return 1.;
}
Beispiel #20
0
uint32_t TranslateQtKeyboardEventModifiers(Qt::KeyboardModifiers mods)
{
	int obsModifiers = INTERACT_NONE;

	if (mods.testFlag(Qt::ShiftModifier))
		obsModifiers |= INTERACT_SHIFT_KEY;
	if (mods.testFlag(Qt::AltModifier))
		obsModifiers |= INTERACT_ALT_KEY;
#ifdef __APPLE__
	// Mac: Meta = Control, Control = Command
	if (mods.testFlag(Qt::ControlModifier))
		obsModifiers |= INTERACT_COMMAND_KEY;
	if (mods.testFlag(Qt::MetaModifier))
		obsModifiers |= INTERACT_CONTROL_KEY;
#else
	// Handle windows key? Can a browser even trap that key?
	if (mods.testFlag(Qt::ControlModifier))
		obsModifiers |= INTERACT_CONTROL_KEY;
	if (mods.testFlag(Qt::MetaModifier))
		obsModifiers |= INTERACT_COMMAND_KEY;

#endif

	return obsModifiers;
}
bool ItemEditorWidget::eventFilter(QObject *object, QEvent *event)
{
    if ( object == m_editor && event->type() == QEvent::KeyPress ) {
        QKeyEvent *keyevent = static_cast<QKeyEvent *>(event);
        int k = keyevent->key();

        if (k == Qt::Key_Return || k == Qt::Key_Enter) {
            Qt::KeyboardModifiers mods = keyevent->modifiers();
            if ( (mods & (Qt::ShiftModifier | Qt::AltModifier | Qt::MetaModifier)) == 0 ) {
                bool controlPressed = mods.testFlag(Qt::ControlModifier);
                if (m_saveOnReturnKey && controlPressed ) {
                    keyevent->setModifiers(mods & ~Qt::ControlModifier);
                    return false;
                }
                if ( m_saveOnReturnKey || controlPressed ) {
                    saveAndExit();
                    return true;
                }
            }
        }
    }

    return false;
}
Beispiel #22
0
bool MultiQFileDialog::eventFilter(QObject *obj, QEvent *e)
{
    if (e->type() == QEvent::KeyPress)
    {
        QKeyEvent* keyEvent = dynamic_cast<QKeyEvent*>(e);
        Qt::KeyboardModifiers modifiers = QApplication::queryKeyboardModifiers();
        if (modifiers.testFlag(Qt::ControlModifier) && keyEvent && keyEvent->key() == Qt::Key_H)
        {
            if (showHidden)
            {
                if (multiSelect)
                {
                    setFilter(QDir::AllDirs | QDir::AllEntries | QDir::NoDotAndDotDot);
                }
                else
                {
                    setFilter(QDir::AllDirs | QDir::NoDotAndDotDot);
                }
            }
            else
            {
                if (multiSelect)
                {
                    setFilter(QDir::AllDirs | QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot);
                }
                else
                {
                    setFilter(QDir::AllDirs | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot);
                }
            }
            showHidden = !showHidden;
        }
    }

    return QFileDialog::eventFilter(obj, e);
}
WindowsManager::OpenHints WindowsManager::calculateOpenHints(Qt::KeyboardModifiers modifiers, Qt::MouseButton button, OpenHints hints)
{
	const bool useNewTab = (!hints.testFlag(NewWindowOpen) && SettingsManager::getValue(QLatin1String("Browser/OpenLinksInNewTab")).toBool());

	if (modifiers == Qt::NoModifier)
	{
		modifiers = QGuiApplication::keyboardModifiers();
	}

	if (button == Qt::MiddleButton && modifiers.testFlag(Qt::AltModifier))
	{
		return ((useNewTab ? NewTabOpen : NewWindowOpen) | BackgroundOpen | EndOpen);
	}

	if (modifiers.testFlag(Qt::ControlModifier) || button == Qt::MiddleButton)
	{
		return ((useNewTab ? NewTabOpen : NewWindowOpen) | BackgroundOpen);
	}

	if (modifiers.testFlag(Qt::ShiftModifier))
	{
		return (useNewTab ? NewTabOpen : NewWindowOpen);
	}

	if (hints != DefaultOpen)
	{
		return hints;
	}

	if (SettingsManager::getValue(QLatin1String("Browser/ReuseCurrentTab")).toBool())
	{
		return CurrentTabOpen;
	}

	return (useNewTab ? NewTabOpen : NewWindowOpen);
}
Beispiel #24
0
/* Auxiliar function for key events. Returns the wx keycode for a qt one.
 * The event is needed to check it flags (numpad key or not) */
wxKeyCode wxQtConvertKeyCode( int key, const Qt::KeyboardModifiers modifiers )
{
    /* First treat common ranges and then handle specific values
     * The macro takes Qt first and last codes and the first wx code
     * to make the conversion */
    #define WXQT_KEY_GROUP( firstQT, lastQT, firstWX ) \
        if ( key >= firstQT && key <= lastQT ) \
            return (wxKeyCode)(key - (firstQT - firstWX));

    if ( modifiers.testFlag( Qt::KeypadModifier ) )
    {
        // This is a numpad event
        WXQT_KEY_GROUP( Qt::Key_0, Qt::Key_9, WXK_NUMPAD0 )
        WXQT_KEY_GROUP( Qt::Key_F1, Qt::Key_F4, WXK_NUMPAD_F1 )
        WXQT_KEY_GROUP( Qt::Key_Left, Qt::Key_Down, WXK_NUMPAD_LEFT )

        // * + , - . /
        WXQT_KEY_GROUP( Qt::Key_Asterisk, Qt::Key_Slash, WXK_NUMPAD_MULTIPLY )

        switch (key)
        {
            case Qt::Key_Space:
                return WXK_NUMPAD_SPACE;
            case Qt::Key_Tab:
                return WXK_NUMPAD_TAB;
            case Qt::Key_Enter:
                return WXK_NUMPAD_ENTER;
            case Qt::Key_Home:
                return WXK_NUMPAD_HOME;
            case Qt::Key_PageUp:
                return WXK_NUMPAD_PAGEUP;
            case Qt::Key_PageDown:
                return WXK_NUMPAD_PAGEDOWN;
            case Qt::Key_End:
                return WXK_NUMPAD_END;
            case Qt::Key_Insert:
                return WXK_NUMPAD_INSERT;
            case Qt::Key_Delete:
                return WXK_NUMPAD_DELETE;
            case Qt::Key_Clear:
                return WXK_NUMPAD_BEGIN;
            case Qt::Key_Equal:
                return WXK_NUMPAD_EQUAL;
        }

        // All other possible numpads button have no equivalent in wx
        return (wxKeyCode)0;
    }
Beispiel #25
0
// Qt Slot (key press event)
void Viewer::keyPressEvent(QKeyEvent *event)
{
	// Check datamodel...
	bool refresh = false, ignore = true;
	Qt::KeyboardModifiers km = event->modifiers();
	
	switch (event->key())
	{
		case (Qt::Key_Left):
			if (UChromaSession::currentViewPane()) UChromaSession::currentViewPane()->rotateView(0.0, km.testFlag(Qt::ShiftModifier) ? -1.0 : -10.0);
			refresh = true;
			ignore = false;
			break;
		case (Qt::Key_Right):
			if (UChromaSession::currentViewPane()) UChromaSession::currentViewPane()->rotateView(0.0, km.testFlag(Qt::ShiftModifier) ? 1.0 : 10.0);
			refresh = true;
			ignore = false;
			break;
		case (Qt::Key_Up):
			if (UChromaSession::currentViewPane()) UChromaSession::currentViewPane()->rotateView(km.testFlag(Qt::ShiftModifier) ? -1.0 : -10.0, 0.0);
			refresh = true;
			ignore = false;
			break;
		case (Qt::Key_Down):
			if (UChromaSession::currentViewPane()) UChromaSession::currentViewPane()->rotateView(km.testFlag(Qt::ShiftModifier) ? 1.0 : 10.0, 0.0);
			refresh = true;
			ignore = false;
			break;
		default:
			break;
	}
	
	// Update display if necessary
	if (refresh) postRedisplay();
	if (ignore) event->ignore();
	else event->accept();
}
QModelIndex UIBootTable::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
{
    if (modifiers.testFlag(Qt::ControlModifier))
    {
        switch (cursorAction)
        {
        case QAbstractItemView::MoveUp:
        {
            QModelIndex index = currentIndex();
            return moveItemTo(index, index.row() - 1);
        }
        case QAbstractItemView::MoveDown:
        {
            QModelIndex index = currentIndex();
            return moveItemTo(index, index.row() + 2);
        }
        case QAbstractItemView::MovePageUp:
        {
            QModelIndex index = currentIndex();
            return moveItemTo(index, qMax(0, index.row() - verticalScrollBar()->pageStep()));
        }
        case QAbstractItemView::MovePageDown:
        {
            QModelIndex index = currentIndex();
            return moveItemTo(index, qMin(model()->rowCount(), index.row() + verticalScrollBar()->pageStep() + 1));
        }
        case QAbstractItemView::MoveHome:
            return moveItemTo(currentIndex(), 0);
        case QAbstractItemView::MoveEnd:
            return moveItemTo(currentIndex(), model()->rowCount());
        default:
            break;
        }
    }
    return QListWidget::moveCursor(cursorAction, modifiers);
}
Beispiel #27
0
// ---------------------------------------------------------------------
string Form::getsysmodifiers(Qt::KeyboardModifiers mod)
{
  return i2s((mod.testFlag(Qt::ShiftModifier) ? 1 : 0) +
             (mod.testFlag(Qt::ControlModifier)? 2 : 0) +
             (mod.testFlag(Qt::AltModifier)? 4 : 0));
}
static bool modifiersForToggle(Qt::KeyboardModifiers modifiers)
{
    return modifiers.testFlag(Qt::ControlModifier);
}
static bool modifiersForSegmentSelect(Qt::KeyboardModifiers modifiers)
{
    return modifiers.testFlag(Qt::AltModifier);
}
static bool modifiersForAdd(Qt::KeyboardModifiers modifiers)
{
    return modifiers.testFlag(Qt::ShiftModifier);
}