void PopupMenu::mouseReleaseEvent(QMouseEvent *e) { DEBUG_PRST_ROUTES(stderr, "PopupMenu::mouseReleaseEvent this:%p\n", this); if(_contextMenu && _contextMenu->isVisible()) return; // Removed by Tim. Why not stay-open scrollable menus? // if(MusEGlobal::config.scrollableSubMenus) // { // QMenu::mouseReleaseEvent(e); // return; // } QAction* action = actionAt(e->pos()); if (!(action && action == activeAction() && !action->isSeparator() && action->isEnabled())) action=NULL; #ifdef POPUP_MENU_DISABLE_STAY_OPEN if (action && action->menu() != NULL && action->isCheckable()) action->activate(QAction::Trigger); QMenu::mouseReleaseEvent(e); if (action && action->menu() != NULL && action->isCheckable()) close(); return; #else // Check for Ctrl to stay open. const bool stay_open = _stayOpen && (MusEGlobal::config.popupsDefaultStayOpen || (e->modifiers() & Qt::ControlModifier)); // Stay open? Or does the action have a submenu, but also a checkbox of its own? if(action && (stay_open || (action->isEnabled() && action->menu() && action->isCheckable()))) { DEBUG_PRST_ROUTES(stderr, "PopupMenu::mouseReleaseEvent: stay open\n"); action->trigger(); // Trigger the action. e->accept(); if(!stay_open) closeUp(); return; // We handled it. } // Otherwise let ancestor QMenu handle it... e->ignore(); QMenu::mouseReleaseEvent(e); #endif // POPUP_MENU_DISABLE_STAY_OPEN }
void ActionsManager::setupLocalAction(QAction *localAction, const QLatin1String &globalAction, bool connectTrigger) { if (!localAction) { return; } QAction *action = getAction(globalAction); if (action) { localAction->setCheckable(action->isCheckable()); localAction->setChecked(action->isChecked()); localAction->setEnabled(action->isEnabled()); localAction->setIcon(action->icon()); localAction->setText(action->text()); localAction->setShortcut(action->shortcut()); localAction->setObjectName(action->objectName()); if (connectTrigger) { connect(localAction, SIGNAL(triggered()), action, SLOT(trigger())); } } }
void QRToolBar::setChecked(int id, bool checked) { eAssert(id < (int) numButtons(), ("index (%d) out of bounds (0..%d) for QRToolBar::setChecked!", id, numButtons()-1)); QAction *action = getAction(id); eAssert(action->isCheckable(), ("cannot set checked state to button %s[%d], as it is not-checkable type!", QROSE::getName(this).c_str(), id)); action->setChecked(checked); }
bool QActionProto::isCheckable() const { QAction *item = qscriptvalue_cast<QAction*>(thisObject()); if (item) return item->isCheckable(); return false; }
bool QRToolBar::isChecked(int id) const { eAssert(id < (int) numButtons(), ("index (%d) out of bounds (0..%d) for QRToolBar::isEnabled!", id, numButtons()-1)); QAction *action = getAction(id); eAssert(action->isCheckable(), ("cannot verify checked state to button %s[%d], as it is not-checkable type!", QROSE::getName(this).c_str(), id)); return action->isChecked(); }
void PopupProxy::tryInsertItem( HistoryItem const * const item, int& remainingHeight, const int index ) { QAction *action = new QAction(m_proxy_for_menu); QPixmap image( item->image() ); if ( image.isNull() ) { // Squeeze text strings so that do not take up the entire screen (or more) QString text = m_proxy_for_menu->fontMetrics().elidedText( item->text().simplified(), Qt::ElideMiddle, m_menu_width ); text.replace( '&', "&&" ); action->setText(text); } else { #if 0 // not used because QAction#setIcon does not respect this size; it does scale anyway. TODO: find a way to set a bigger image const QSize max_size( m_menu_width,m_menu_height/4 ); if ( image.height() > max_size.height() || image.width() > max_size.width() ) { image = image.scaled( max_size, Qt::KeepAspectRatio, Qt::SmoothTransformation ); } #endif action->setIcon(QIcon(image)); } action->setData(item->uuid()); // if the m_proxy_for_menu is a submenu (aka a "More" menu) then it may the case, that there is no other action in that menu yet. QAction *before = index < m_proxy_for_menu->actions().count() ? m_proxy_for_menu->actions().at(index) : 0; // insert the new action to the m_proxy_for_menu m_proxy_for_menu->insertAction(before, action); // Determine height of a menu item. QStyleOptionMenuItem style_options; // It would be much easier to use QMenu::initStyleOptions. But that is protected, so until we have a better // excuse to subclass that, I'd rather implement this manually. // Note 2 properties, tabwidth and maxIconWidth, are not available from the public interface, so those are left out (probably not // important for height. Also, Exlsive checkType is disregarded as I don't think we will ever use it) style_options.initFrom(m_proxy_for_menu); style_options.checkType = action->isCheckable() ? QStyleOptionMenuItem::NonExclusive : QStyleOptionMenuItem::NotCheckable; style_options.checked = action->isChecked(); style_options.font = action->font(); style_options.icon = action->icon(); style_options.menuHasCheckableItems = true; style_options.menuRect = m_proxy_for_menu->rect(); style_options.text = action->text(); int font_height = QFontMetrics(m_proxy_for_menu->fontMetrics()).height(); int itemheight = m_proxy_for_menu->style()->sizeFromContents(QStyle::CT_MenuItem, &style_options, QSize( 0, font_height ), m_proxy_for_menu).height(); // Subtract the used height remainingHeight -= itemheight; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void CmdFeature::refreshCheckedState() { std::map<QString, QAction*>::iterator it; bool isChecked = this->isCommandChecked(); for (it = m_customTextToActionMap.begin(); it != m_customTextToActionMap.end(); ++it) { QAction* act = it->second; if (act->isCheckable()) { it->second->setChecked(isChecked); } } }
QVariant ActionModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); QMutexLocker lock(Probe::objectLock()); QAction *action = m_actions.at(index.row()); if (!Probe::instance()->isValidObject(action)) return QVariant(); const int column = index.column(); if (role == Qt::DisplayRole) { switch (column) { case AddressColumn: return Util::addressToString(action); case NameColumn: return action->text(); case CheckablePropColumn: return action->isCheckable(); case CheckedPropColumn: return VariantHandler::displayString(action->isChecked()); case PriorityPropColumn: return Util::enumToString(action->priority(), 0, action); case ShortcutsPropColumn: return toString(action->shortcuts()); default: return QVariant(); } } else if (role == Qt::DecorationRole) { if (column == NameColumn) { return action->icon(); } else if (column == ShortcutsPropColumn && m_duplicateFinder->hasAmbiguousShortcut(action)) { QIcon icon = QIcon::fromTheme(QStringLiteral("dialog-warning")); if (!icon.isNull()) { return icon; } else { return QColor(Qt::red); } } } else if (role == Qt::ToolTipRole) { if (column == ShortcutsPropColumn && m_duplicateFinder->hasAmbiguousShortcut(action)) { return tr("Warning: Ambiguous shortcut detected."); } } else if (role == ObjectModel::ObjectRole) { return QVariant::fromValue<QObject*>(action); } return QVariant(); }
void PopupMenu::clearAllChecks() const { QList<QAction*> list = actions(); for(int i = 0; i < list.size(); ++i) { QAction* act = list[i]; if(PopupMenu* menu = qobject_cast<PopupMenu*>(act->menu())) menu->clearAllChecks(); // Recursive. if(act->isCheckable()) { act->blockSignals(true); act->setChecked(false); act->blockSignals(false); } } }
void ActionMapper::rebuildMenu(const QString& menu, QMenu* qmenu, const ShortcutController& shortcuts) { for (const QString& actionName : m_menus[menu]) { if (actionName.isNull()) { qmenu->addSeparator(); continue; } if (m_hiddenActions.contains(actionName)) { continue; } if (actionName[0] == '.') { QString name = actionName.mid(1); QMenu* newMenu = qmenu->addMenu(m_menuNames[name]); rebuildMenu(name, newMenu, shortcuts); continue; } Action* action = &m_actions[actionName]; QAction* qaction = qmenu->addAction(action->visibleName()); qaction->setEnabled(action->isEnabled()); if (action->isExclusive() || action->booleanAction()) { qaction->setCheckable(true); } if (action->isActive()) { qaction->setChecked(true); } const Shortcut* shortcut = shortcuts.shortcut(actionName); if (shortcut && shortcut->shortcut() > 0) { qaction->setShortcut(QKeySequence(shortcut->shortcut())); } else if (!m_defaultShortcuts[actionName].isEmpty()) { qaction->setShortcut(m_defaultShortcuts[actionName][0]); } QObject::connect(qaction, &QAction::triggered, [qaction, action](bool enabled) { if (qaction->isCheckable()) { action->trigger(enabled); } else { action->trigger(); } }); QObject::connect(action, &Action::enabled, qaction, &QAction::setEnabled); QObject::connect(action, &Action::activated, qaction, &QAction::setChecked); QObject::connect(action, &Action::destroyed, qaction, &QAction::deleteLater); if (shortcut) { QObject::connect(shortcut, &Shortcut::shortcutChanged, qaction, [qaction](int shortcut) { qaction->setShortcut(QKeySequence(shortcut)); }); } } }
void TabBar::contextMenuEvent(QContextMenuEvent* event) { if (event->x() < 0) return; int index = tabAt(event->x()); if (index == -1) m_sessionMenu->exec(QCursor::pos()); else { readyTabContextMenu(); updateMoveActions(index); int sessionId = sessionAtTab(index); updateToggleActions(sessionId); updateToggleKeyboardInputMenu(sessionId); updateToggleMonitorActivityMenu(sessionId); updateToggleMonitorSilenceMenu(sessionId); m_mainWindow->setContextDependentActionsQuiet(true); QAction* action = m_tabContextMenu->exec(QCursor::pos()); emit tabContextMenuClosed(); if (action) { if (action->isCheckable()) m_mainWindow->handleContextDependentToggleAction(action->isChecked(), action, sessionId); else m_mainWindow->handleContextDependentAction(action, sessionId); } m_mainWindow->setContextDependentActionsQuiet(false); updateMoveActions(m_tabs.indexOf(m_selectedSessionId)); updateToggleActions(m_selectedSessionId); updateToggleKeyboardInputMenu(m_selectedSessionId); updateToggleMonitorActivityMenu(m_selectedSessionId); updateToggleMonitorSilenceMenu(m_selectedSessionId); } QWidget::contextMenuEvent(event); }
void QWKPagePrivate::updateAction(QWKPage::WebAction action) { #ifdef QT_NO_ACTION Q_UNUSED(action) #else QAction* a = actions[action]; if (!a) return; RefPtr<WebKit::WebFrameProxy> mainFrame = page->mainFrame(); if (!mainFrame) return; bool enabled = a->isEnabled(); bool checked = a->isChecked(); switch (action) { case QWKPage::Back: enabled = page->canGoBack(); break; case QWKPage::Forward: enabled = page->canGoForward(); break; case QWKPage::Stop: enabled = !(WebFrameProxy::LoadStateFinished == mainFrame->loadState()); break; case QWKPage::Reload: enabled = (WebFrameProxy::LoadStateFinished == mainFrame->loadState()); break; default: break; } a->setEnabled(enabled); if (a->isCheckable()) a->setChecked(checked); #endif // QT_NO_ACTION }
QWidget* GCF::ActionContainerWidget::createWidget(QAction* action, int rowSpan, int colSpan) { QWidget* ret = 0; int gSize=int((fontMetrics().height()+fontMetrics().ascent())*1.2); int minWidth = gSize*colSpan; QWidgetAction* wAction = qobject_cast<QWidgetAction*>(action); if(wAction) ret = wAction->requestWidget(this); else { QToolButton* tb = new QToolButton(this); tb->setDefaultAction(action); tb->setAutoRaise(true); /*if(action->menu()) tb->setMenu(action->menu());*/ tb->setIconSize(QSize(gSize-4,gSize-4)); if(action->icon().isNull()) tb->setToolButtonStyle(Qt::ToolButtonTextOnly); else if(colSpan == rowSpan && colSpan >= 2) tb->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); else if(colSpan == rowSpan && colSpan == 1) tb->setToolButtonStyle(Qt::ToolButtonIconOnly); else if(colSpan >= 2 || rowSpan == 1) tb->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); else if(rowSpan >= 3) tb->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); int mw = 0; if(tb->toolButtonStyle() != Qt::ToolButtonIconOnly) mw += fontMetrics().width(action->iconText())+2*fontMetrics().width("_"); if(!action->icon().isNull()) { switch(tb->toolButtonStyle()) { case Qt::ToolButtonTextUnderIcon: if(mw < gSize-4) mw = gSize-4; break; case Qt::ToolButtonTextBesideIcon: mw += gSize-4; break; } } if(minWidth < mw) minWidth = mw; if(action->menu()) { // Connect the default action object to the tool button. This way // when the toolbutton with menu is clicked, the default action is // shown. QList<QAction*> actions = action->menu()->actions(); QAction* defAction = 0; for(int i=0; i<actions.count(); i++) { QAction* action = actions[i]; QList<QByteArray> propNames = action->dynamicPropertyNames(); if(propNames.contains("_default_")) { bool val = action->property("_default_").toBool(); if(val) { defAction = action; break; } } } if(defAction) { if(defAction->isCheckable()) connect(tb, SIGNAL(clicked()), defAction, SLOT(toggle())); else connect(tb, SIGNAL(clicked()), defAction, SLOT(trigger())); QFont font = defAction->font(); font.setBold(true); defAction->setFont(font); } } ret = tb; } ret->setMinimumSize(minWidth, gSize*rowSpan); if(!action->icon().isNull()) { QFont font = ret->font(); // font.setPointSize(font.pointSize()-1); ret->setFont(font); } /*static QPlastiqueStyle Style; ret->setStyle(&Style);*/ return ret; }
//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- void tAutopilotSelectedDeviceMenu::AddDevice( const tN2kName& name, bool selected, bool enabled ) { QString nameStr = tGlobal<tNDP2k>::Instance()->DeviceManager().DataSourceStr( name ); //DbgPrintf( QString("AddDevice nameStr=%1 value=%2").arg( nameStr ).arg( quint64( name.llValue() ) ) ); if( nameStr == "???" ) // incase the simnet selection is a device we have never seen... { // Get Simnet Nmea2k DevTag instead unsigned char devTag[16] = ""; // DEV_TAG_CHARS if( SystemData::bGetDevTag( (unsigned char*)name.ToByteArray().data(), 0, devTag ) ) { nameStr = QString((char *)devTag); } } bool insertDevice = false; // Sort names into order of decreasing name QList<tAction*> actionList = SubActions(); int i; for( i = 0; i < actionList.size(); ++i ) { quint64 nameInList = quint64( actionList[i]->data().toLongLong() ); //DbgPrintf( QString("AddDevice: index=%1 nameInList=%2").arg( i ).arg( nameInList ) ); if ( nameInList > 0 ) //If it's not one of the fixed items at the top or a separator { if( quint64( name.llValue() ) == nameInList ) { //Already in list - just update //DbgPrintf( "Device already in list" ); QAction* pAction = actionList[i]; pAction->setText( nameStr ); if ( pAction->isCheckable() ) { pAction->setChecked( selected ); } return; } else if( quint64( name.llValue() ) > nameInList ) { DbgPrintf( "Name greater than nameInList" ); insertDevice = true; break; } } } tAction* pAction = new tAction( nameStr, this ); pAction->setCheckable( true ); pAction->setChecked( selected ); pAction->setData( QVariant( name.llValue() ) ); pAction->setEnabled( enabled ); if( insertDevice ) { DbgPrintf( QString("Inserting action at index %1").arg( i ) ); InsertAction( actionList[i], pAction ); } else // Append { DbgPrintf( QString("Adding action %1").arg( nameStr ) ); AddAction( pAction ); } m_SelectDeviceActGroup.append( pAction ); Connect( pAction, SIGNAL( triggered( bool ) ), this, SLOT( SelectDevice( bool ) ) ); }
bool QRToolBar::isCheckable(int id) const { eAssert(id < (int) numButtons(), ("index (%d) out of bounds (0..%d) for QRToolBar::isCheckable!", id, numButtons()-1)); QAction *action = getAction(id); return action->isCheckable(); }