//----------------------------------------------------------------------------- void CloseFileGuiCommand::init () { getQAction(CLOSE_FILE_)->setShortcut (QKeySequence::Close); getQAction(CLOSE_FILE_)->setIcon (QIcon(":/images/icons/fileclose.png")); getQAction(EXIT_APPLICATION_)->setShortcut (QKeySequence::Quit); getQAction(EXIT_APPLICATION_)->setIcon (QIcon(":/images/icons/exit.png")); resetActionTriggerSlot(CLOSE_FILE_, SLOT(closeFile())); resetActionTriggerSlot(EXIT_APPLICATION_, SLOT(exitApplication())); }
//------------------------------------------------------------------------- void UndoRedoGuiCommand::evaluateEnabledness () { bool can_undo = getTabEditState() != TAB_STATE_NO_UNDO && getTabEditState() != TAB_STATE_NO_REDO_NO_UNDO && getTabEditState() != NO_TAB_EDIT_STATE && getApplicationState() == APP_STATE_FILE_OPEN; bool can_redo = getTabEditState() != TAB_STATE_NO_REDO && getTabEditState() != TAB_STATE_NO_REDO_NO_UNDO && getTabEditState() != NO_TAB_EDIT_STATE && getApplicationState() == APP_STATE_FILE_OPEN; getQAction (UNDO_)->setEnabled (can_undo); getQAction (REDO_)->setEnabled (can_redo); }
QAction* QtMenu::createQAction(IAction& action) { auto qAction = getQAction(action); if (qAction != nullptr) { NGT_WARNING_MSG("Action %s already existing.\n", action.text()); return nullptr; } actions_[&action] = createSharedQAction(action); qAction = getQAction(action); TF_ASSERT(qAction != nullptr); return qAction; }
void QtMenuBar::addAction(IAction& action, const char* path) { auto qAction = getQAction(action); if (qAction == nullptr) { qAction = createQAction(action); } assert(qAction != nullptr); path = relativePath(path); if (path == nullptr || strlen(path) == 0) { path = action.text(); } auto tok = strchr(path, '.'); auto menuPath = tok != nullptr ? QString::fromUtf8(path, tok - path) : path; QMenu* menu = qMenuBar_.findChild<QMenu*>(menuPath, Qt::FindDirectChildrenOnly); if (menu == nullptr) { menu = qMenuBar_.addMenu(menuPath); menu->setObjectName(menuPath); } path = tok != nullptr ? tok + 1 : nullptr; QtMenu::addMenuAction(*menu, *qAction, path); qMenuBar_.repaint(); }
SyncActionsConfigurationMenu::SyncActionsConfigurationMenu(SyncActionsConfiguration *config, QWidget *parent) : QMenu(parent) { Q_ASSERT(config); m_syncActionsConfig = config; m_signalMapper = new QSignalMapper(this); foreach (const SyncActionMetaData &syncActionMetaData, SignalToSyncActionMapperFactory::instance()->getFactoryIdentifiersList()) { // First we get the corresponding menu's QAction to the sync action QAction *enableSyncAction = getQAction(syncActionMetaData); // Adding the configured QAction to the menu addAction(enableSyncAction); // Then we configure the mapping of the sync actions and the corresponding QActions to enable/disable them when toggled m_syncActionsMap.insert(syncActionMetaData, enableSyncAction); connect(enableSyncAction, SIGNAL(toggled(bool)), m_signalMapper, SLOT(map())); m_signalMapper->setMapping(enableSyncAction, syncActionMetaData.getName()); }
void QtMenuBar::removeAction(IAction& action) { auto qAction = getQAction(action); if (qAction == nullptr) { NGT_ERROR_MSG("Target action '%s' '%s' does not exist\n", action.text(), StringUtils::join(action.paths(), ';').c_str()); return; } auto menus = qMenuBar_.findChildren<QMenu*>(QString(), Qt::FindDirectChildrenOnly); for (auto& menu : menus) { QtMenu::removeMenuAction(*menu, *qAction); if (menu->isEmpty()) { delete menu; } } destroyQAction(action); }