示例#1
0
void MenuBar::dragMoveEvent(QDragMoveEvent *event)
{
    const MimeDataObject *mimeData
            = qobject_cast<const MimeDataObject *>(event->mimeData());

    QAction *eAction = this->actionAt(event->pos());
    if (mimeData->hasFormat("application/x-qobject") && isEdited())
        if (mimeData->object() != eAction && eAction)
            if (eAction->menu() && activeAction()!= eAction)
                setActiveAction(eAction);
    event->accept();
}
示例#2
0
void
LauncherContextualMenu::setFocus()
{
    /* FIXME: for some reason, invoking QMenu::activateWindow() directly here
       doesn’t work, the active window remains unchanged. */
    QTimer::singleShot(1, this, SLOT(activateWindow()));

    /* Set the first enabled action active. */
    Q_FOREACH(QAction* action, actions()) {
        if (action->isEnabled() && !action->isSeparator()) {
            setActiveAction(action);
            break;
        }
    }
    QMenu::setFocus();
}
示例#3
0
void KlipperPopup::slotSetTopActive()
{
  if (actions().size() > TOP_HISTORY_ITEM_INDEX) {
    setActiveAction(actions().at(TOP_HISTORY_ITEM_INDEX));
  }
}
示例#4
0
/* virtual */
void KlipperPopup::keyPressEvent( QKeyEvent* e ) {
    // If alt-something is pressed, select a shortcut
    // from the menu. Do this by sending a keyPress
    // without the alt-modifier to the superobject.
    if ( e->modifiers() & Qt::AltModifier ) {
        QKeyEvent ke( QEvent::KeyPress,
                      e->key(),
                      e->modifiers() ^ Qt::AltModifier,
                      e->text(),
                      e->isAutoRepeat(),
                      e->count() );
        KMenu::keyPressEvent( &ke );
#ifdef DEBUG_EVENTS__
        kDebug() << "Passing this event to ancestor (KMenu): " << e << "->" << ke;
#endif
        if (ke.isAccepted()) {
            e->accept();
            return;
        } else {
            e->ignore();
        }
    }

    // Otherwise, send most events to the search
    // widget, except a few used for navigation:
    // These go to the superobject.
    switch( e->key() ) {
    case Qt::Key_Up:
    case Qt::Key_Down:
    case Qt::Key_Right:
    case Qt::Key_Left:
    case Qt::Key_Tab:
    case Qt::Key_Backtab:
    case Qt::Key_Escape:
    {
#ifdef DEBUG_EVENTS__
        kDebug() << "Passing this event to ancestor (KMenu): " << e;
#endif
        KMenu::keyPressEvent(e);

        break;
    }
    case Qt::Key_Return:
    case Qt::Key_Enter:
    {
        KMenu::keyPressEvent(e);
        this->hide();

        if (activeAction() ==  m_filterWidgetAction)
            setActiveAction(actions().at(TOP_HISTORY_ITEM_INDEX));

        break;
    }
    default:
    {
#ifdef DEBUG_EVENTS__
        kDebug() << "Passing this event down to child (KLineEdit): " << e;
#endif
        setActiveAction(actions().at(actions().indexOf(m_filterWidgetAction)));
        QString lastString = m_filterWidget->text();
        QApplication::sendEvent(m_filterWidget, e);

        if (m_filterWidget->text().isEmpty()) {
            if (m_filterWidgetAction->isVisible())
                m_filterWidget->setVisible(false);
                m_filterWidgetAction->setVisible(false);
        }
        else if (!m_filterWidgetAction->isVisible() )
            m_filterWidgetAction->setVisible(true);

        if (m_filterWidget->text() != lastString) {
            m_dirty = true;
            rebuild(m_filterWidget->text());
        }

        break;
    } //default:
    } //case
}
示例#5
0
文件: kmenu.cpp 项目: vasi/kdelibs
void KMenu::keyPressEvent(QKeyEvent* e)
{
    d->mouseButtons = Qt::NoButton;
    d->keyboardModifiers = Qt::NoModifier;

    if (!d->shortcuts) {
        d->keyboardModifiers = e->modifiers();
        QMenu::keyPressEvent(e);

        if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Down) {
            d->skipTitles(e);
        }

        return;
    }

    QAction* a = 0L;
    bool firstpass = true;
    QString keyString = e->text();

    // check for common commands dealt with by QMenu
    int key = e->key();
    if (key == Qt::Key_Escape || key == Qt::Key_Return || key == Qt::Key_Enter
            || key == Qt::Key_Up || key == Qt::Key_Down || key == Qt::Key_Left
            || key == Qt::Key_Right || key == Qt::Key_F1 || key == Qt::Key_PageUp
            || key == Qt::Key_PageDown || key == Qt::Key_Back || key == Qt::Key_Select) {

        d->resetKeyboardVars();
        // continue event processing by QMenu
        //e->ignore();
        d->keyboardModifiers = e->modifiers();
        QMenu::keyPressEvent(e);

        if (key == Qt::Key_Up || key == Qt::Key_Down) {
            d->skipTitles(e);
        }
        return;
    } else if ( key == Qt::Key_Shift || key == Qt::Key_Control || key == Qt::Key_Alt || key == Qt::Key_Meta )
        return QMenu::keyPressEvent(e);

    // check to see if the user wants to remove a key from the sequence (backspace)
    // or clear the sequence (delete)
    if (!d->keySeq.isNull()) {
        if (key == Qt::Key_Backspace) {

            if (d->keySeq.length() == 1) {
                d->resetKeyboardVars();
                return;
            }

            // keep the last sequence in keyString
            keyString = d->keySeq.left(d->keySeq.length() - 1);

            // allow sequence matching to be tried again
            d->resetKeyboardVars();

        } else if (key == Qt::Key_Delete) {
            d->resetKeyboardVars();

            // clear active item
            setActiveAction(0L);
            return;

        } else if (d->noMatches) {
            // clear if there are no matches
            d->resetKeyboardVars();

            // clear active item
            setActiveAction(0L);

        } else {
            // the key sequence is not a null string
            // therefore the lastHitAction is valid
            a = d->lastHitAction;
        }

    } else if (key == Qt::Key_Backspace && menuAction()) {
        // backspace with no chars in the buffer... go back a menu.
        hide();
        d->resetKeyboardVars();
        return;
    }

    d->keySeq += keyString;
    const int seqLen = d->keySeq.length();

    foreach (a, actions()) {
        // don't search disabled entries
        if (!a->isEnabled())
            continue;

        QString thisText;

        // retrieve the right text
        // (the last selected item one may have additional ampersands)
        if (a == d->lastHitAction)
            thisText = d->originalText;
        else
            thisText = a->text();

        // if there is an accelerator present, remove it
        thisText = KGlobal::locale()->removeAcceleratorMarker(thisText);

        // chop text to the search length
        thisText = thisText.left(seqLen);

        // do the search
        if (!thisText.indexOf(d->keySeq, 0, Qt::CaseInsensitive)) {

            if (firstpass) {
                // match
                setActiveAction(a);

                // check to see if we're underlining a different item
                if (d->lastHitAction && d->lastHitAction != a)
                    // yes; revert the underlining
                    d->lastHitAction->setText(d->originalText);

                // set the original text if it's a different item
                if (d->lastHitAction != a || d->lastHitAction == 0L)
                    d->originalText = a->text();

                // underline the currently selected item
                a->setText(underlineText(d->originalText, d->keySeq.length()));

                // remember what's going on
                d->lastHitAction = a;

                // start/restart the clear timer
                d->clearTimer.setSingleShot(true);
                d->clearTimer.start(5000);

                // go around for another try, to see if we can execute
                firstpass = false;
            } else {
                // don't allow execution
                return;
            }
        }

        // fall through to allow execution
    }

    if (!firstpass) {
        if (d->autoExec) {
            // activate anything
            d->lastHitAction->activate(QAction::Trigger);
            d->resetKeyboardVars();

        } else if (d->lastHitAction && d->lastHitAction->menu()) {
            // only activate sub-menus
            d->lastHitAction->activate(QAction::Trigger);
            d->resetKeyboardVars();
        }

        return;
    }

    // no matches whatsoever, clean up
    d->resetKeyboardVars(true);
    //e->ignore();
    QMenu::keyPressEvent(e);
}
示例#6
0
void Listener :: exec ( const QPoint & Loc ) {

  { const ActList AL = FindActs ( CurrDev ) ;
    if ( ! AL . isEmpty ( ) ) { setActiveAction ( AL . first ( ) ) ; }//fi
  }

  ActPtr Act = QMenu :: exec ( Loc ) ;

  if ( Act ) {

    const QString AN = Act -> objectName ( ) ; // Primary key.
    CurrDev = sect ( AN , 0 ) ; // SysPath.
    const UdevDev Dev ( UdevContext , CurrDev ) ;
    QString Node = Dev . DevNode ( ) ;
    const QString MP = Mounts :: DecodeIFS ( sect ( AN , 1 ) ) ;
      // Mountpoint/dm-name if any.
    const bool Cont = isLUKS ( Dev ) ,     // It's container.
               MoM  = ! MP . isEmpty ( ) ; // It's mounted or mapped.
    int RC = 0 ; // Return code for command.

    if ( MoM || ! Suppl ) {
      // Currently Suppl may be Eject, Remove or UnmountAll.

      loKey C , T , S ;
      if ( MoM ) {
        if ( Cont ) { C = kLockCmd   ; T = kLockTO   ; S = kLockShow   ;
        }    else   { C = kUnmntCmd  ; T = kUnmntTO  ; S = kUnmntShow  ;
        }//fi
      } else {
        if ( Cont ) { C = kUnlockCmd ; T = kUnlockTO ; S = kUnlockShow ;
        }    else   { C = kMountCmd  ; T = kMountTO  ; S = kMountShow  ;
        }//fi
      }//fi

      RC = ExecCmd ( Opt . toStr ( C ) , MoM ? MP : Node ,
                     Opt . toInt ( T ) , Opt . toBool ( S ) ) ;

    }//fi

    const UdevDev WD ( WDisk ( Dev ) ) ; // whole disk.
    bool Show = Opt . toBool ( kEjectShow ) ;
    RefreshMInfo ( ) ;

    { const bool
        A = Opt . toBool ( kAutoEject ) ,
        D = Opt . toStr  ( kEjectCmd  ) . isEmpty ( ) ,
        L = ( MPoints ( Dev ) + Holders ( Dev ) ) . isEmpty ( ) ,
        S = Suppl == reqEject || Suppl == reqRemove ,
        E = Ejectable ( WD  ) ;
      if ( MoM && ( L || Suppl ) && A && ! D && E && ! S ) {
        Suppl = reqEject ; Show = Opt . toBool ( kAutoEjShow ) ;
      }//fi
    }

    if ( RC ) { SetActions ( Dev ) ; // workaround for setChecked ()

    } else if ( Suppl == reqUnmtAll ) {

      UnmntAll ( Dev , Opt . toBool ( kUnmntShow ) ) ;

    } else if ( Suppl ) { // Eject or Remove.

      QStringList Msg , NL ; Node = WD . DevNode ( ) ;

      foreach ( const QString P , Parts ( WD ) << WD . SysPath ( ) ) {
        const UdevDev D ( UdevContext , P ) ;
        const QString N = D . DevNode ( ) ; NL += N ;
        UnmntAll ( D , false ) ; RefreshMInfo ( ) ;
        foreach ( const QString M , MPoints ( D ) ) {
          Msg << N + tr ( " mounted on " ) + M ;
        }//done
        foreach ( const QString M , Holders ( D ) ) {
          Msg << N + tr ( " mapped on "  ) + M ;
        }//done
        UdevEnum En ( UdevContext ) ; En . MatchSubsys ( Subsys_Block ) ;
        En . MatchSysAttr ( SA_BackFile , N . toLatin1 ( ) ) ;
        En . ScanDevs ( ) ;
        foreach ( const UdevPair M , En . GetList ( ) ) {
          Msg << N + tr ( " mapped on " ) +
                       UdevDev ( UdevContext , M . first ) . DevNode ( ) ;
        }//done
      }//done

      const QStringList F ( "[1-9]*" ) ;
      foreach ( const QString P , QDir ( "/proc" ) . entryList ( F , Drs ) ) {
        const QDir D ( "/proc/" + P + "/fd" ) ;
        foreach ( const QFileInfo I , D . entryInfoList ( QDir :: Files ) ) {
          const QString N = I . symLinkTarget ( ) ;
          if ( NL . contains ( N ) ) { Msg << N + tr ( " used by PId " ) + P ;
          }//fi
        }//done
      }//done

      if ( ! Msg . isEmpty ( ) ) {

        QMessageBox :: critical (
          this , TPref + tr ( "Error" ) ,
          tr ( "Device "  ) + Node +
          tr ( " in use:" ) + "\n" + Msg . join ( "\n" )
        ) ;

      } else {

        QString Cmd ; int TO ;
        if ( Suppl == reqEject ) {
          Cmd = Opt . toStr ( kEjectCmd ) ;
          TO  = Opt . toInt ( kEjectTO  ) ;
        } else {
          Cmd  = Opt . toStr  ( kRemoveCmd  ) ;
          TO   = Opt . toInt  ( kRemoveTO   ) ;
          Show = Opt . toBool ( kRemoveShow ) ;
        }//fi

        ExecCmd ( Cmd , Node , TO , Show ) ;

      }//fi

    }//fi