Пример #1
0
 bool MenuBarItem::mouseAction(Coordinate position, bool click){
     if (!visible) {
         selected = false;
         return false;
     }
     
     selected = false;
     visible = false;
     
     for (auto& subMenuEntry : subMenu) {
         selected |= subMenuEntry.mouseAction(position, click);
     }
     
     if (bgRect.contains(position)) {
         selected = true;
         visible = true;
         if (click && onClick) {
             onClick(this);
         }
     }
     
     if (selected) {
         showSubMenu();
     }
     
     return selected;
 }
Пример #2
0
void PopupMenuEditor::setFocusAt( const QPoint & pos )
{
    hideSubMenu();
    lineEdit->hide();

    currentIndex = 0;
    int iy = 0;
    PopupMenuEditorItem * i = itemList.first();

    while ( i ) {
	iy += itemHeight( i );
	if ( iy > pos.y() )
	    break;
	i = itemList.next();
	currentIndex++;
    }

    iy += itemHeight( &addItem );
    if ( iy <= pos.y() )
	currentIndex++;

    if ( currentIndex < (int)itemList.count() ) {
	if ( pos.x() < iconWidth )
	    currentField = 0;
	else if ( pos.x() < iconWidth + textWidth )
	    currentField = 1;
	else
	    currentField = 2;
    } else {
	currentField = 1;
    }

    showSubMenu();
}
Пример #3
0
bool DropDownList::showSubMenu() {
    if (selected_item == NO_SELECTION) {
        hideSubMenu();
        return false;
    } else {
        // find position to show item at
        return showSubMenu(selected_item, itemPosition(selected_item));
    }
}
Пример #4
0
void PopupMenuEditor::dropEvent( QDropEvent * e )
{
    if ( !( e->provides( "qt/popupmenueditoritemptr" ) ||
	    e->provides( "application/x-designer-actions" ) ||
	    e->provides( "application/x-designer-actiongroup" ) ) )
	return;

    // Hide the sub menu of the current item, but do it later
    if ( currentIndex < (int)itemList.count() ) {
	PopupMenuEditor *s = itemList.at( currentIndex )->s;
	QTimer::singleShot( 0, s, SLOT( hide() ) );
    }

    draggedItem = 0;
    PopupMenuEditorItem * i = 0;

    if ( e->provides( "qt/popupmenueditoritemptr" ) ) {
	PopupMenuEditorItemPtrDrag::decode( e, &i );
    } else {
	if ( e->provides( "application/x-designer-actiongroup" ) ) {
	    QActionGroup * g = ::qt_cast<QDesignerActionGroup*>(ActionDrag::action());
	    if ( g->usesDropDown() ) {
		i = new PopupMenuEditorItem( g, this );
		QString n = QString( g->name() ) + "Item";
		formWindow()->unify( i, n, FALSE );
		i->setName( n );
		QObjectList *l = g->queryList( "QAction", 0, FALSE, FALSE );
		QObjectListIterator it( *l );
		for ( ; it.current(); ++it ) {
		    g = ::qt_cast<QActionGroup*>(it.current());
		    if ( g )
			i->s->insert( g );
		    else
			i->s->insert( (QAction*)it.current() );
		}
		delete l;
	    } else {
		dropInPlace( g, e->pos().y() );
	    }
	} else if ( e->provides( "application/x-designer-actions" ) ) {
	    QAction *a = ::qt_cast<QDesignerAction*>(ActionDrag::action());
	    i = new PopupMenuEditorItem( a, this );
	}
    }

    if ( i ) {
	dropInPlace( i, e->pos().y() );
	QTimer::singleShot( 0, this, SLOT( resizeToContents() ) );
    }

    QTimer::singleShot( 0, this, SLOT( showSubMenu() ) );
    QTimer::singleShot( 0, this, SLOT( setFocus() ) );
    dropLine->hide();
    e->accept();
}
Пример #5
0
void PopupMenuEditor::dragMoveEvent( QDragMoveEvent * e )
{
    QPoint pos = e->pos();
    dropLine->move( borderSize, snapToItem( pos.y() ) );

    if ( currentItem() != itemAt( pos.y() ) ) {
	hideSubMenu();
	setFocusAt( pos );
	showSubMenu();
    }
}
Пример #6
0
void PopupMenuEditor::mouseMoveEvent( QMouseEvent * e )
{
    if ( e->state() & Qt::LeftButton ) {
	if ( ( e->pos() - mousePressPos ).manhattanLength() > 3 ) {
	    draggedItem = itemAt( mousePressPos.y() );
	    if ( draggedItem == &addItem ) {
		draggedItem = createItem();
		RenameActionCommand cmd( "Rename Item", formWnd, draggedItem->action(),
					 this, "Unnamed" );
		cmd.execute();
                // FIXME: start rename after drop
	    } else if ( draggedItem == &addSeparator ) {
		draggedItem = createItem( new QSeparatorAction( 0 ) );
		draggedItem->setSeparator( TRUE );
	    }

	    PopupMenuEditorItemPtrDrag * d =
		new PopupMenuEditorItemPtrDrag( draggedItem, this );

	    hideSubMenu();

	    draggedItem->setVisible( FALSE );
	    resizeToContents();

	    // If the item is dropped in the same list,
	    //  we will have two instances of the same pointer
	    // in the list. We use node instead.
	    int idx = itemList.find( draggedItem );
	    QLNode * node = itemList.currentNode();

	    d->dragCopy(); // dragevents and stuff happens

	    if ( draggedItem ) { // item was not dropped
		draggedItem->setVisible( TRUE );
		draggedItem = 0;
		if ( hasFocus() ) {
		    hideSubMenu();
		    resizeToContents();
		    showSubMenu();
		}
	    } else { // item was dropped
		itemList.takeNode( node )->setVisible( TRUE );
		if ( currentIndex > 0 && currentIndex > idx )
		    --currentIndex;
		// the drop might happen in another menu, so we'll resize
		// and show the submenu there
	    }
	}
    }
}
Пример #7
0
void PopupMenuEditor::leaveEditMode( QKeyEvent * e )
{
    setFocus();
    lineEdit->hide();

    PopupMenuEditorItem * i = 0;
    if ( e && e->key() == Qt::Key_Escape ) {
 	update();
	return;
    }

    if ( currentIndex >= (int)itemList.count() ) {
	// new item was created
	QAction * a = formWnd->mainWindow()->actioneditor()->newActionEx();
	QString actionText = lineEdit->text();
	actionText.replace("&&", "&");
	QString menuText = lineEdit->text();
	a->setText( actionText );
	a->setMenuText( menuText );
	i = createItem( a );
	QString n = constructName( i );
	formWindow()->unify( a, n, TRUE );
	a->setName( n );
	MetaDataBase::addEntry( a );
	MetaDataBase::setPropertyChanged( a, "menuText", TRUE );
	ActionEditor *ae = (ActionEditor*)formWindow()->mainWindow()->child( 0, "ActionEditor" );
	if ( ae )
	    ae->updateActionName( a );
    } else {
	i = itemList.at( currentIndex );
	RenameActionCommand * cmd = new RenameActionCommand( "Rename Item",
							     formWnd,
							     i->action(),
							     this,
							     lineEdit->text() );
	formWnd->commandHistory()->addCommand( cmd );
	cmd->execute();
    }
    resizeToContents();

    if ( !i )
	return;

    if ( i->isSeparator() )
	hideSubMenu();
    else
	showSubMenu();
}
bool PopupMenuEditor::qt_invoke( int _id, QUObject* _o )
{
    switch ( _id - staticMetaObject()->slotOffset() ) {
    case 0: cut(); break;
    case 1: copy(); break;
    case 2: paste(); break;
    case 3: remove((int)static_QUType_int.get(_o+1)); break;
    case 4: remove((QAction*)static_QUType_ptr.get(_o+1)); break;
    case 5: resizeToContents(); break;
    case 6: showSubMenu(); break;
    case 7: hideSubMenu(); break;
    case 8: focusOnSubMenu(); break;
    default:
	return QWidget::qt_invoke( _id, _o );
    }
    return TRUE;
}
Пример #9
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;
}
Пример #10
0
void PopupMenuEditor::navigateDown( bool ctrl )
{
    hideSubMenu();
    if ( ctrl ) {
	if ( currentIndex < ( (int)itemList.count() - 1 ) ) { // safe index
	    ExchangeActionInPopupCommand * cmd =
		new ExchangeActionInPopupCommand( "Move Item Down",
						  formWnd,
						  this,
						  currentIndex,
						  currentIndex + 1 );
	    formWnd->commandHistory()->addCommand( cmd );
	    cmd->execute();
	    safeInc();
	}
    } else { // ! Ctrl
	safeInc();
    }
    if ( currentIndex >= (int)itemList.count() )
	currentField = 1;
    showSubMenu();
}
Пример #11
0
void PopupMenuEditor::navigateUp( bool ctrl )
{
    if ( currentIndex > 0 ) {
	hideSubMenu();
	if ( ctrl ) {
	    ExchangeActionInPopupCommand * cmd =
		new ExchangeActionInPopupCommand( "Move Item Up",
						  formWnd,
						  this,
						  currentIndex,
						  currentIndex - 1 );
	    formWnd->commandHistory()->addCommand( cmd );
	    cmd->execute();
	    safeDec();
	} else {
	    safeDec();
	}
	showSubMenu();
    } else if ( parentMenu ) {
	parentMenu->setFocus();
	parentMenu->update();
    }
}
Пример #12
0
void DropDownList::onMotion(wxMouseEvent& ev) {
    // size
    wxSize cs = GetClientSize();
    // inside?
    if (ev.GetX() < marginW || ev.GetX() + marginW >= cs.GetWidth() || ev.GetY() < marginH || ev.GetY() + marginH >= cs.GetHeight()) {
        ev.Skip();
        return;
    }
    // find selected item
    int startY = marginH - visible_start;
    size_t count = itemCount();
    for (size_t i = 0 ; i < count ; ++i) {
        int endY = startY + (int)item_size.height;
        if (ev.GetY() >= startY && ev.GetY() < endY) {
            if (itemEnabled(i)) {
                showSubMenu(i, startY);
            }
            selectItem(i);
            return;
        }
        startY = endY + lineBelow(i);
    }
    hideSubMenu();
}
Пример #13
0
void PopupMenuEditor::clearCurrentField()
{
    if ( currentIndex >= (int)itemList.count() )
	return; // currentIndex is addItem or addSeparator
    PopupMenuEditorItem * i = currentItem();
    hideSubMenu();
    if ( i->isSeparator() )
	return;
    if ( currentField == 0 ) {
	QIconSet icons( 0 );
	SetActionIconsCommand * cmd = new SetActionIconsCommand( "Remove icon",
								 formWnd,
								 i->action(),
								 this,
								 icons );
	formWnd->commandHistory()->addCommand( cmd );
	cmd->execute();
    } else if ( currentField == 2 ) {
	i->action()->setAccel( 0 );
    }
    resizeToContents();
    showSubMenu();
    return;
}
Пример #14
0
bool DropDownList::onCharInParent(wxKeyEvent& ev) {
    // keyboard codes
    int k = ev.GetKeyCode();
    if (IsShown()) {
        if (open_sub_menu) {
            // sub menu always takes keys
            return open_sub_menu->onCharInParent(ev);
        } else {
            switch (k) {
            case WXK_UP:
                return selectItem(selected_item - 1);
            case WXK_DOWN:
                return selectItem(selected_item + 1);
            case WXK_RETURN:
                if (!showSubMenu() && (selected_item == NO_SELECTION || itemEnabled(selected_item))) {
                    hide(true, false); // don't veto; always close
                }
                break;
            case WXK_SPACE:
                if (!showSubMenu() && (selected_item == NO_SELECTION || itemEnabled(selected_item))) {
                    hide(true);
                }
                break;
            case WXK_ESCAPE:
                hide(false);
                break;
            case WXK_LEFT:
                if (parent_menu) hide(false);
                break;
            case WXK_RIGHT:
                return showSubMenu();
            default:
                // match first character of an item, start searching just after the current selection
                size_t si = selected_item != NO_SELECTION ? selected_item + 1 : 0;
                size_t count = itemCount();
                for (size_t i = 0 ; i < count ; ++i) {
                    size_t index = (si + i) % count;
                    if (!itemEnabled(index)) continue;
                    String c = itemText(index);
#ifdef UNICODE
                    if (!c.empty() && toUpper(c.GetChar(0)) == toUpper(ev.GetUnicodeKey())) {
#else
                    if (!c.empty() && toUpper(c.GetChar(0)) == toUpper(ev.GetKeyCode())) {
#endif
                        // first character matches
                        selected_item = index;
                        showSubMenu();
                        selectItem(index);
                        return true;
                    }
                }
            }
        }
        return true;
    }
    else if (k==WXK_SPACE || k==WXK_RETURN || k==WXK_DOWN) {
        // drop down list is not shown yet, show it now
        show(false, wxPoint(0,0));
        return true;
    }
    return false;
}
Пример #15
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();
}
Пример #16
0
void PopupMenuEditor::focusInEvent( QFocusEvent * )
{
    showSubMenu();
    update();
    parentMenu->update();
}