void MyPopupMenu::checkCheck(int id) { bool* var = bools.find(id); if ( var ) { bool check = !isItemChecked(id); setItemChecked(id, check); *var = check; emit variableChanged(var); } else { int* var = ints.find(id); int* val = values.find(id); if ( var && val ) { *var = *val; int ind=indexOf(id); // go back to start/separator while (idAt(ind)!=-1) { ind--; } ind++; // go forward to end/separator int i; while ((i=idAt(ind))!=-1) { setItemChecked( i, i==id ); ind++; } emit variableChanged(var); } } }
MyPopupMenu::~MyPopupMenu() { for (uint i=0; i<count(); i++) { bools.remove(idAt( i )); ints.remove(idAt( i )); values.remove(idAt( i )); } }
void MyMenuBar::setItemState(ZLToolbar::ItemPtr item, bool visible, bool enabled) { switch (item->type()) { case ZLToolbar::Item::PLAIN_BUTTON: case ZLToolbar::Item::TOGGLE_BUTTON: case ZLToolbar::Item::MENU_BUTTON: { ZLToolbar::AbstractButtonItem &button = (ZLToolbar::AbstractButtonItem&)*item; const std::string &id = button.actionId(); std::map<std::string,int> ::const_iterator iter = myActionIndices.find(id); int actionIndex = (iter != myActionIndices.end()) ? iter->second : 0; if (visible) { if ((actionIndex == 0) || (idAt(myIndex) != actionIndex)) { ToolBarButton *tbButton = myButtons[id]; if (actionIndex == 0) { tbButton = new ToolBarButton(myWindow, button); myButtons[id] = tbButton; actionIndex = myActionIndices.size() + 1; myActionIndices[id] = actionIndex; } insertItem(tbButton->pixmap(), tbButton, SLOT(doActionSlot()), 0, actionIndex, myIndex); } setItemEnabled(actionIndex, enabled); ++myIndex; } else { if ((actionIndex != 0) && (idAt(myIndex) == actionIndex)) { removeItem(actionIndex); } } break; } /* case ZLToolbar::Item::OPTION_ENTRY: if (idAt(myIndex) < 10001) { shared_ptr<ZLOptionEntry> entry = ((ZLToolbar::OptionEntryItem&)*item).entry(); if (entry->isVisible()) { ZLOptionView *view = createViewByEntry("", "", entry); view->setVisible(true); } } else { ++myIndex; } break; */ case ZLToolbar::Item::SEPARATOR: break; } }
void PanelBrowserMenu::mouseMoveEvent(QMouseEvent *e) { QPopupMenu::mouseMoveEvent(e); if (!(e->state() & LeftButton)) return; if(_lastpress == QPoint(-1, -1)) return; // DND delay if((_lastpress - e->pos()).manhattanLength() < 12) return; // get id int id = idAt(_lastpress); if(!_filemap.contains(id)) return; // reset _lastpress _lastpress = QPoint(-1, -1); // start drag KURL url; url.setPath(path() + "/" + _filemap[id]); KURL::List files(url); KURLDrag *d = new KURLDrag(files, this); connect(d, SIGNAL(destroyed()), this, SLOT(slotDragObjectDestroyed())); d->setPixmap(iconSet(id)->pixmap()); d->drag(); }
void TaskLMBMenu::mouseMoveEvent(QMouseEvent* e) { if (m_dragStartPos.isNull()) { QPopupMenu::mouseMoveEvent(e); return; } int delay = KGlobalSettings::dndEventDelay(); QPoint newPos(e->pos()); if ((m_dragStartPos - newPos).manhattanLength() > delay) { int index = indexOf(idAt(m_dragStartPos)); if (index != -1) { bool ok = false; Task::Ptr task = m_tasks.at(index, &ok); if (ok) { Task::List tasks; tasks.append(task); TaskDrag* drag = new TaskDrag(tasks, this); drag->setPixmap(task->pixmap()); drag->dragMove(); } } } QPopupMenu::mouseMoveEvent(e); }
// This popup is much more useful from keyboard if it has the active // window active by default - however, TQPopupMenu tries hard to resist. // TQPopupMenu::popup() resets the active item, so this needs to be // called after popup(). void KWindowListMenu::selectActiveWindow() { for( unsigned int i = 0; i < count(); ++i ) if( isItemChecked( idAt( i ))) { setActiveItem( i ); break; } }
void KPopupMenu::resetKeyboardVars(bool noMatches) { // Clean up keyboard variables if (d->lastHitIndex != -1) { changeItem(idAt(d->lastHitIndex), d->originalText); d->lastHitIndex = -1; } if (!noMatches) { d->keySeq = QString::null; } d->noMatches = noMatches; }
void TaskLMBMenu::dragSwitch() { bool ok = false; Task::Ptr t = m_tasks.at(indexOf(m_lastDragId), &ok); if (ok) { t->activate(); for (unsigned int i = 0; i < count(); ++i) { setItemChecked(idAt(i), false ); } setItemChecked( m_lastDragId, true ); } }
void TaskLMBMenu::dragMoveEvent( QDragMoveEvent* e ) { // ignore task drags if (TaskDrag::canDecode(e)) { return; } int id = idAt(e->pos()); if (id == -1) { m_dragSwitchTimer->stop(); m_lastDragId = -1; } else if (id != m_lastDragId) { m_lastDragId = id; m_dragSwitchTimer->start(1000, true); } QPopupMenu::dragMoveEvent(e); }
void KPopupMenu::keyPressEvent(QKeyEvent* e) { if (!d->shortcuts) { // continue event processing by Qpopup //e->ignore(); QPopupMenu::keyPressEvent(e); return; } int i = 0; bool firstpass = true; QString keyString = e->text(); // check for common commands dealt with by QPopup int key = e->key(); if (key == Key_Escape || key == Key_Return || key == Key_Enter || key == Key_Up || key == Key_Down || key == Key_Left || key == Key_Right || key == Key_F1) { resetKeyboardVars(); // continue event processing by Qpopup //e->ignore(); QPopupMenu::keyPressEvent(e); return; } // check to see if the user wants to remove a key from the sequence (backspace) // or clear the sequence (delete) if (d->keySeq != QString::null) { if (key == Key_Backspace) { if (d->keySeq.length() == 1) { resetKeyboardVars(); return; } // keep the last sequence in keyString keyString = d->keySeq.left(d->keySeq.length() - 1); // allow sequence matching to be tried again resetKeyboardVars(); } else if (key == Key_Delete) { resetKeyboardVars(); // clear active item setActiveItem(0); return; } else if (d->noMatches) { // clear if there are no matches resetKeyboardVars(); // clear active item setActiveItem(0); } else { // the key sequence is not a null string // therefore the lastHitIndex is valid i = d->lastHitIndex; } } else if (key == Key_Backspace && parentMenu) { // backspace with no chars in the buffer... go back a menu. hide(); resetKeyboardVars(); return; } d->keySeq += keyString; int seqLen = d->keySeq.length(); for (; i < (int)count(); i++) { // compare typed text with text of this entry int j = idAt(i); // don't search disabled entries if (!isItemEnabled(j)) continue; QString thisText; // retrieve the right text // (the last selected item one may have additional ampersands) if (i == d->lastHitIndex) thisText = d->originalText; else thisText = text(j); // if there is an accelerator present, remove it if ((int)accel(j) != 0) thisText = thisText.replace(QRegExp("&"), ""); // chop text to the search length thisText = thisText.left(seqLen); // do the search if (thisText.find(d->keySeq, 0, false) == 0) { if (firstpass) { // match setActiveItem(i); // check to see if we're underlining a different item if (d->lastHitIndex != i) // yes; revert the underlining changeItem(idAt(d->lastHitIndex), d->originalText); // set the original text if it's a different item if (d->lastHitIndex != i || d->lastHitIndex == -1) d->originalText = text(j); // underline the currently selected item changeItem(j, underlineText(d->originalText, d->keySeq.length())); // remeber what's going on d->lastHitIndex = i; // start/restart the clear timer d->clearTimer.start(5000, true); // 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 activateItemAt(d->lastHitIndex); resetKeyboardVars(); } else if (findItem(idAt(d->lastHitIndex)) && findItem(idAt(d->lastHitIndex))->popup()) { // only activate sub-menus activateItemAt(d->lastHitIndex); resetKeyboardVars(); } return; } // no matches whatsoever, clean up resetKeyboardVars(true); //e->ignore(); QPopupMenu::keyPressEvent(e); }
void KMenuBar::drawContents(QPainter *p) { // Closes the BR77113 // We need to overload this method to paint only the menu items // This way when the KMenuBar is embedded in the menu applet it // integrates correctly. // // Background mode and origin are set so late because of styles // using the polish() method to modify these settings. // // Of course this hack can safely be removed when real transparency // will be available if(!d->topLevel) { QMenuBar::drawContents(p); } else { bool up_enabled = isUpdatesEnabled(); BackgroundMode bg_mode = backgroundMode(); BackgroundOrigin bg_origin = backgroundOrigin(); setUpdatesEnabled(false); setBackgroundMode(X11ParentRelative); setBackgroundOrigin(WindowOrigin); p->eraseRect(rect()); erase(); QColorGroup g = colorGroup(); bool e; for(int i = 0; i < (int)count(); i++) { QMenuItem *mi = findItem(idAt(i)); if(!mi->text().isNull() || mi->pixmap()) { QRect r = itemRect(i); if(r.isEmpty() || !mi->isVisible()) continue; e = mi->isEnabledAndVisible(); if(e) g = isEnabled() ? (isActiveWindow() ? palette().active() : palette().inactive()) : palette().disabled(); else g = palette().disabled(); bool item_active = (actItem == i); p->setClipRect(r); if(item_active) { QStyle::SFlags flags = QStyle::Style_Default; if(isEnabled() && e) flags |= QStyle::Style_Enabled; if(item_active) flags |= QStyle::Style_Active; if(item_active && actItemDown) flags |= QStyle::Style_Down; flags |= QStyle::Style_HasFocus; style().drawControl(QStyle::CE_MenuBarItem, p, this, r, g, flags, QStyleOption(mi)); } else { style().drawItem(p, r, AlignCenter | AlignVCenter | ShowPrefix, g, e, mi->pixmap(), mi->text()); } } } setBackgroundOrigin(bg_origin); setBackgroundMode(bg_mode); setUpdatesEnabled(up_enabled); } }