Ejemplo n.º 1
0
void PopupMenuEditor::mouseDoubleClickEvent( QMouseEvent * )
{
    setFocusAt( mousePressPos );
    if ( currentItem() == &addSeparator ) {
	PopupMenuEditorItem * i = createItem( new QSeparatorAction( 0 ) );
	i->setSeparator( TRUE );
	return;
    }
    if ( currentField == 0 ) {
	choosePixmap();
	resizeToContents();
    } else if ( currentField == 1 ) {
	showLineEdit();
    }
}
Ejemplo n.º 2
0
void PopupMenuEditor::enterEditMode( QKeyEvent * e )
{
    PopupMenuEditorItem * i = currentItem();

    if ( i == &addSeparator ) {
	i = createItem( new QSeparatorAction( 0 ) );
    } else if ( i->isSeparator() ) {
	return;
    } else if ( currentField == 0 ) {
	choosePixmap();
    } else if ( currentField == 1 ) {
	showLineEdit();
	return;
    } else {// currentField == 2
	setAccelerator( e->key(), e->state() );
    }
    showSubMenu();
    return;
}
Ejemplo n.º 3
0
void PopupMenuEditor::keyPressEvent( QKeyEvent * e )
{
    if ( lineEdit->isHidden() ) { // In navigation mode

	switch ( e->key() ) {

	case Qt::Key_Delete:
	    hideSubMenu();
	    removeItem();
	    showSubMenu();
	    break;

	case Qt::Key_Backspace:
	    clearCurrentField();
	    break;

	case Qt::Key_Up:
	    navigateUp( e->state() & Qt::ControlButton );
	    break;

	case Qt::Key_Down:
	    navigateDown( e->state() & Qt::ControlButton );
	    break;

	case Qt::Key_Left:
	    navigateLeft();
	    break;

	case Qt::Key_Right:
	    navigateRight();
	    break;

	case Qt::Key_PageUp:
	    currentIndex = 0;
	    break;

	case Qt::Key_PageDown:
	    currentIndex = itemList.count();
	    break;

	case Qt::Key_Enter:
	case Qt::Key_Return:
	case Qt::Key_F2:
	    enterEditMode( e );
	    // move on
	case Qt::Key_Alt:
	case Qt::Key_Shift:
	case Qt::Key_Control:
	    // do nothing
	    return;

	case Qt::Key_Escape:
	    currentField = 0;
	    navigateLeft();
	    break;

	case Qt::Key_C:
	    if ( e->state() & Qt::ControlButton &&
		 currentIndex < (int)itemList.count() ) {
		copy( currentIndex );
		break;
	    }

	case Qt::Key_X:
	    if ( e->state() & Qt::ControlButton &&
		 currentIndex < (int)itemList.count() ) {
		hideSubMenu();
		cut( currentIndex );
		showSubMenu();
		break;
	    }

	case Qt::Key_V:
	    if ( e->state() & Qt::ControlButton ) {
		hideSubMenu();
		paste( currentIndex < (int)itemList.count() ? currentIndex + 1: itemList.count() );
		showSubMenu();
		break;
	    }

	default:
	    if (  currentItem()->isSeparator() )
		return;
	    if ( currentField == 1 ) {
		showLineEdit();
		QApplication::sendEvent( lineEdit, e );
		e->accept();
		return;
	    } else if ( currentField == 2 ) {
		setAccelerator( e->key(), e->state() );
		showSubMenu();
	    }
	    break;

	}

    } else { // In edit mode
	switch ( e->key() ) {
	case Qt::Key_Enter:
	case Qt::Key_Return:
	case Qt::Key_Escape:
	    leaveEditMode( e );
	    e->accept();
	    return;
	}
    }
    update();
}
Ejemplo n.º 4
0
bool ListBoxRename::eventFilter( QObject *, QEvent * event )
{
    switch ( event->type() ) {
	
    case QEvent::MouseButtonPress:
        {
	    QPoint pos = ((QMouseEvent *) event)->pos();
	    
	    if ( clickedItem &&
		 clickedItem->isSelected() &&
		 (clickedItem == src->itemAt( pos )) ) {
		QTimer::singleShot( 500, this, SLOT( showLineEdit() ) );
		activity = FALSE; // no drags or clicks for 500 ms before we start the renaming
	    } else { // new item clicked
		activity = TRUE;
		clickedItem = src->itemAt( pos );
		ed->hide();
	    }
	}
        break;
	
    case QEvent::MouseMove:

	if ( ((QMouseEvent *) event)->state() & Qt::LeftButton ) {
	    activity = TRUE;  // drag
	}
	break;
	
    case QEvent::KeyPress:
	
	switch ( ((QKeyEvent *) event)->key() ) {

	case Qt::Key_F2:
	    
	    activity = FALSE;
	    clickedItem = src->item( src->currentItem() );
	    showLineEdit();
	    break;

	case Qt::Key_Escape:
	    if ( !ed->isHidden() ) {
		hideLineEdit(); // abort rename
		return TRUE;
	    }
	    break;

	case Qt::Key_Up:
	case Qt::Key_Down:
	case Qt::Key_PageUp:
	case Qt::Key_PageDown:
	    
	    if ( !ed->isHidden() )
		return TRUE; // Filter out the keystrokes
	    break;

	}
	break;

    case QEvent::Resize:

	if ( clickedItem && ed && !ed->isHidden() ) {
	    QRect rect = src->itemRect( clickedItem );
	    ed->resize( rect.right() - rect.left() - 1,
		rect.bottom() - rect.top() - 1 );
	}
	break;

    default:
	break;
    }
    
    return FALSE;
}