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 } } } }
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(); }
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)); } }
void PopupMenuEditor::dragMoveEvent( QDragMoveEvent * e ) { QPoint pos = e->pos(); dropLine->move( borderSize, snapToItem( pos.y() ) ); if ( currentItem() != itemAt( pos.y() ) ) { hideSubMenu(); setFocusAt( pos ); showSubMenu(); } }
bool DropDownList::showSubMenu(size_t item, int y) { DropDownList* sub_menu = item == NO_SELECTION ? nullptr : submenu(item); if (sub_menu == open_sub_menu) return sub_menu; // no change hideSubMenu(); open_sub_menu = sub_menu; if (!sub_menu) return false; // open new menu wxSize size = GetSize(); sub_menu->show(true, sub_menu->GetParent()->ScreenToClient(ClientToScreen( wxPoint(size.GetWidth() - 1, y + (int)item_size.height) ))); return true; }
void DropDownList::realHide() { if (!IsShown()) return; Window::Hide(); onHide(); hideSubMenu(); if (parent_menu) { parent_menu->open_sub_menu = nullptr; } else { redrawArrowOnParent(); // disconnect event handler GetParent() ->RemoveEventHandler(hider2); wxGetTopLevelParent(GetParent())->RemoveEventHandler(hider); } }
void PopupMenuEditor::focusOutEvent( QFocusEvent * ) { QWidget * fw = qApp->focusWidget(); if ( !fw || ( !::qt_cast<PopupMenuEditor*>(fw) && fw != lineEdit ) ) { hideSubMenu(); if ( fw && ::qt_cast<MenuBarEditor*>(fw) ) return; QWidget * w = this; while ( w && w != fw && ::qt_cast<PopupMenuEditor*>(w) ) { // hide all popups w->hide(); w = ((PopupMenuEditor *)w)->parentEditor(); } } }
void PopupMenuEditor::navigateLeft() { if ( currentItem()->isSeparator() || currentIndex >= (int)itemList.count() || currentField == 0 ) { if ( parentMenu ) { hideSubMenu(); parentMenu->setFocus(); } else if ( !currentItem()->isSeparator() ) { currentField = 2; } } else { currentField--; } }
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; }
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(); }
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(); } }
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(); }
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; }
void MenuBarItem::hide() { visible = false; hideSubMenu(); }
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(); }