QSize PopupMenuEditor::contentsSize() { QRect textRect = fontMetrics().boundingRect( addSeparator.action()->menuText() ); textWidth = textRect.width(); accelWidth = textRect.height(); // default size iconWidth = textRect.height(); int w = 0; int h = itemHeight( &addItem ) + itemHeight( &addSeparator ); PopupMenuEditorItem * i = itemList.first(); QAction * a = 0; while ( i ) { if ( i->isVisible() ) { if ( !i->isSeparator() ) { a = i->action(); w = a->iconSet().pixmap( QIconSet::Automatic, QIconSet::Normal ).rect().width() + borderSize; // padding iconWidth = QMAX( iconWidth, w ); w = fontMetrics().boundingRect( a->menuText() ).width(); textWidth = QMAX( textWidth, w ); w = fontMetrics().boundingRect( a->accel() ).width() + 2; // added padding? accelWidth = QMAX( accelWidth, w ); } h += itemHeight( i ); } i = itemList.next(); } int width = iconWidth + textWidth + borderSize * 3 + accelWidth + arrowWidth; return QSize( width, h ); }
static void saveShortcuts(QTextStream &fout) { QPtrList<QAction> *actions; QAction *action; fout << "# all shortcuts \n"; actions = Shortcuts::actions(); for( action = actions->first(); action; action = actions->next() ) if(strlen(action->name())) fout << "map(\"" << action->name() << "\", \"" << (QString)action->accel() << "\")\n"; }
int PopupMenuEditor::itemHeight( const PopupMenuEditorItem * item ) const { if ( !item || ( item && !item->isVisible() ) ) return 0; if ( item->isSeparator() ) return 4; // FIXME: hardcoded ( get from styles )r int padding = + borderSize * 6; QAction * a = item->action(); int h = a->iconSet().pixmap( QIconSet::Automatic, QIconSet::Normal ).rect().height(); h = QMAX( h, fontMetrics().boundingRect( a->menuText() ).height() + padding ); h = QMAX( h, fontMetrics().boundingRect( a->accel() ).height() + padding ); return h; }
void PopupMenuEditor::setAccelerator( int key, Qt::ButtonState state, int index ) { // FIXME: make this a command int idx = ( index == -1 ? currentIndex : index ); if ( key == Qt::Key_Shift || key == Qt::Key_Control || key == Qt::Key_Alt || key == Qt::Key_Meta || key == Qt::Key_unknown ) return; // ignore these keys when they are pressed PopupMenuEditorItem * i = 0; if ( idx >= (int)itemList.count() ) i = createItem(); else i = itemList.at( idx ); int shift = ( state & Qt::ShiftButton ? Qt::SHIFT : 0 ); int ctrl = ( state & Qt::ControlButton ? Qt::CTRL : 0 ); int alt = ( state & Qt::AltButton ? Qt::ALT : 0 ); int meta = ( state & Qt::MetaButton ? Qt::META : 0 ); QAction * a = i->action(); QKeySequence ks = a->accel(); int keys[4] = { ks[0], ks[1], ks[2], ks[3] }; int n = 0; while ( n < 4 && ks[n++] ); n--; if ( n < 4 ) keys[n] = key | shift | ctrl | alt | meta; a->setAccel( QKeySequence( keys[0], keys[1], keys[2], keys[3] ) ); MetaDataBase::setPropertyChanged( a, "accel", TRUE ); resizeToContents(); }