void Action::init( QWidget *, const char *pName, const QString &pDisplayName, QObject *pTarget, const char *pActivateSlot, QWidget *pAddTo, const QString & pEnabled ) { setObjectName(pName); _name = pName; _displayName = pDisplayName; QString hotkey; hotkey = _preferences->parent(pName); if (!hotkey.isNull() && !_hotkeyList.contains(hotkey)) { _hotkeyList << hotkey; setShortcutContext(Qt::ApplicationShortcut); if (hotkey.left(1) == "C") setShortcut(QString("Ctrl+%1").arg(hotkey.right(1))); else if (hotkey.left(1) == "F") setShortcut(hotkey); } connect(this, SIGNAL(activated()), pTarget, pActivateSlot); //setEnabled(pEnabled); pAddTo->addAction(this); if(!pEnabled.isEmpty()) setData(pEnabled); __menuEvaluate(this); }
Action::Action( QWidget *pParent, const char *pName, const QString &pDisplayName, QObject *pTarget, const char *pActivateSlot, QWidget *pAddTo, bool pEnabled, const QPixmap &pIcon, QWidget *pToolBar, const QString &pToolTip ) : QAction(pDisplayName, pParent) { setObjectName(pName); _name = pName; _displayName = pDisplayName; _toolTip = pToolTip; QString hotkey = _preferences->parent(pName); if (!hotkey.isNull() && !_hotkeyList.contains(hotkey)) { _hotkeyList << hotkey; setShortcutContext(Qt::ApplicationShortcut); if (hotkey.left(1) == "C") setShortcut(QString("Ctrl+%1").arg(hotkey.right(1))); else if (hotkey.left(1) == "F") setShortcut(hotkey); } connect(this, SIGNAL(activated()), pTarget, pActivateSlot); setEnabled(pEnabled); pAddTo->addAction(this); setIconSet(QIcon(pIcon)); addTo(pToolBar); setToolTip(_toolTip); }
ActionWithShortcut::ActionWithShortcut(const std::string & group, const std::list<std::string> & actionIDs, const std::string & actionDescription, QObject* parent, bool setShortcutOnAction) : QAction(parent) , _group( QString::fromUtf8( group.c_str() ) ) , _shortcuts() { QKeySequence seq0; for (std::list<std::string>::const_iterator it = actionIDs.begin(); it != actionIDs.end(); ++it) { QString actionIDStr = QString::fromUtf8( it->c_str() ); std::list<QKeySequence> seq = getKeybind(_group, actionIDStr); if ( seq.empty() ) { seq.push_back( QKeySequence() ); } _shortcuts.push_back( std::make_pair( actionIDStr, seq.front() ) ); if ( it == actionIDs.begin() ) { seq0 = seq.front(); } appPTR->addShortcutAction(_group, actionIDStr, this); } assert ( !_group.isEmpty() && !actionIDs.empty() ); if (setShortcutOnAction) { setShortcut(seq0); } setShortcutContext(Qt::WindowShortcut); setText( tr( actionDescription.c_str() ) ); }
QAction* makeToolbarAction(const QString& name, QObject* parent, const Data& data, const QString& shortcut) { auto act = new QAction{name, parent}; act->setCheckable(true); act->setData(QVariant::fromValue((int) data)); act->setShortcut(shortcut); act->setShortcutContext(Qt::WidgetWithChildrenShortcut); act->setToolTip(name+ " (" + shortcut + ")"); return act; }
void Action::initialize() { const ActionsManager::ActionDefinition definition(getDefinition()); switch (m_identifier) { case ActionsManager::PreferencesAction: setMenuRole(QAction::PreferencesRole); break; case ActionsManager::AboutQtAction: setMenuRole(QAction::AboutQtRole); break; case ActionsManager::ExitAction: setMenuRole(QAction::QuitRole); break; case ActionsManager::AboutApplicationAction: setMenuRole(QAction::AboutRole); break; default: break; } setShortcutContext(Qt::WidgetShortcut); if (definition.isValid()) { if (definition.flags.testFlag(ActionsManager::ActionDefinition::IsCheckableFlag)) { setCheckable(true); } if (definition.flags.testFlag(ActionsManager::ActionDefinition::IsDeprecatedFlag)) { Console::addMessage(tr("Creating instance of deprecated action: %1").arg(ActionsManager::getActionName(m_identifier)), Console::OtherCategory, Console::WarningLevel); } connect(this, &Action::triggered, this, &Action::triggerAction); } updateIcon(); updateState(); connect(ActionsManager::getInstance(), &ActionsManager::shortcutsChanged, this, &Action::updateShortcut); }
void PadWindow::initContextMenu() { auto newPadAction = new QAction("&New pad", this); newPadAction->setShortcutContext(Qt::ApplicationShortcut); newPadAction->setShortcut(QKeySequence::New); connect(newPadAction, &QAction::triggered, [&](){ emit pad->newPadRequested(); }); auto propertiesAction = new QAction("&Properties", ui->textEdit); propertiesAction->setShortcut(QKeySequence("Ctrl+,")); connect(propertiesAction, &QAction::triggered, [&](){ propertiesWindowRequested();; }); auto preferencesAction = new QAction("P&references", ui->textEdit); preferencesAction->setShortcut(QKeySequence("Ctrl+p")); connect(preferencesAction, &QAction::triggered, [&](){ preferencesWindowRequested(); }); auto closeAction = new QAction("&Close", ui->textEdit); closeAction->setShortcut(QKeySequence::Close); connect(closeAction, &QAction::triggered, [&](){ hide(); }); auto deletePadAction = new QAction("&Delete pad", ui->textEdit); deletePadAction->setShortcut(QKeySequence("Shift+Del")); connect(deletePadAction, &QAction::triggered,[&](){ emit pad->deletePadRequested(pad); }); actions.push_back(newPadAction); actions.push_back(propertiesAction); actions.push_back(preferencesAction); actions.push_back(closeAction); actions.push_back(deletePadAction); padMenu.addActions(actions); ui->textEdit->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->textEdit, &QWidget::customContextMenuRequested, this, &PadWindow::showContextMenu); }
ActionWithShortcut::ActionWithShortcut(const std::string & group, const std::string & actionID, const std::string & actionDescription, QObject* parent, bool setShortcutOnAction) : QAction(parent) , _group( QString::fromUtf8( group.c_str() ) ) , _shortcuts() { // insert here the output of: // fgrep "#define kShortcutDescAction" ActionShortcuts.h | sed -e 's/#define /(void)QT_TR_NOOP(/' -e 's/ .*/);/' (void)QT_TR_NOOP(kShortcutDescActionNewProject); (void)QT_TR_NOOP(kShortcutDescActionOpenProject); (void)QT_TR_NOOP(kShortcutDescActionCloseProject); (void)QT_TR_NOOP(kShortcutDescActionReloadProject); (void)QT_TR_NOOP(kShortcutDescActionSaveProject); (void)QT_TR_NOOP(kShortcutDescActionSaveAsProject); (void)QT_TR_NOOP(kShortcutDescActionSaveAndIncrVersion); (void)QT_TR_NOOP(kShortcutDescActionExportProject); (void)QT_TR_NOOP(kShortcutDescActionPreferences); (void)QT_TR_NOOP(kShortcutDescActionQuit); (void)QT_TR_NOOP(kShortcutDescActionProjectSettings); (void)QT_TR_NOOP(kShortcutDescActionShowErrorLog); (void)QT_TR_NOOP(kShortcutDescActionNewViewer); (void)QT_TR_NOOP(kShortcutDescActionFullscreen); (void)QT_TR_NOOP(kShortcutDescActionShowWindowsConsole); (void)QT_TR_NOOP(kShortcutDescActionClearDiskCache); (void)QT_TR_NOOP(kShortcutDescActionClearPlaybackCache); (void)QT_TR_NOOP(kShortcutDescActionClearNodeCache); (void)QT_TR_NOOP(kShortcutDescActionClearPluginsLoadCache); (void)QT_TR_NOOP(kShortcutDescActionClearAllCaches); (void)QT_TR_NOOP(kShortcutDescActionShowAbout); (void)QT_TR_NOOP(kShortcutDescActionRenderSelected); (void)QT_TR_NOOP(kShortcutDescActionEnableRenderStats); (void)QT_TR_NOOP(kShortcutDescActionRenderAll); (void)QT_TR_NOOP(kShortcutDescActionConnectViewerToInput1); (void)QT_TR_NOOP(kShortcutDescActionConnectViewerToInput2); (void)QT_TR_NOOP(kShortcutDescActionConnectViewerToInput3); (void)QT_TR_NOOP(kShortcutDescActionConnectViewerToInput4); (void)QT_TR_NOOP(kShortcutDescActionConnectViewerToInput5); (void)QT_TR_NOOP(kShortcutDescActionConnectViewerToInput6); (void)QT_TR_NOOP(kShortcutDescActionConnectViewerToInput7); (void)QT_TR_NOOP(kShortcutDescActionConnectViewerToInput8); (void)QT_TR_NOOP(kShortcutDescActionConnectViewerToInput9); (void)QT_TR_NOOP(kShortcutDescActionConnectViewerToInput10); (void)QT_TR_NOOP(kShortcutDescActionShowPaneFullScreen); (void)QT_TR_NOOP(kShortcutDescActionImportLayout); (void)QT_TR_NOOP(kShortcutDescActionExportLayout); (void)QT_TR_NOOP(kShortcutDescActionDefaultLayout); (void)QT_TR_NOOP(kShortcutDescActionNextTab); (void)QT_TR_NOOP(kShortcutDescActionPrevTab); (void)QT_TR_NOOP(kShortcutDescActionCloseTab); (void)QT_TR_NOOP(kShortcutDescActionGraphRearrangeNodes); (void)QT_TR_NOOP(kShortcutDescActionGraphRemoveNodes); (void)QT_TR_NOOP(kShortcutDescActionGraphShowExpressions); (void)QT_TR_NOOP(kShortcutDescActionGraphNavigateUpstream); (void)QT_TR_NOOP(kShortcutDescActionGraphNavigateDownstram); (void)QT_TR_NOOP(kShortcutDescActionGraphSelectUp); (void)QT_TR_NOOP(kShortcutDescActionGraphSelectDown); (void)QT_TR_NOOP(kShortcutDescActionGraphSelectAll); (void)QT_TR_NOOP(kShortcutDescActionGraphSelectAllVisible); (void)QT_TR_NOOP(kShortcutDescActionGraphAutoHideInputs); (void)QT_TR_NOOP(kShortcutDescActionGraphHideInputs); (void)QT_TR_NOOP(kShortcutDescActionGraphSwitchInputs); (void)QT_TR_NOOP(kShortcutDescActionGraphCopy); (void)QT_TR_NOOP(kShortcutDescActionGraphPaste); (void)QT_TR_NOOP(kShortcutDescActionGraphClone); (void)QT_TR_NOOP(kShortcutDescActionGraphDeclone); (void)QT_TR_NOOP(kShortcutDescActionGraphCut); (void)QT_TR_NOOP(kShortcutDescActionGraphDuplicate); (void)QT_TR_NOOP(kShortcutDescActionGraphDisableNodes); (void)QT_TR_NOOP(kShortcutDescActionGraphToggleAutoPreview); (void)QT_TR_NOOP(kShortcutDescActionGraphToggleAutoTurbo); (void)QT_TR_NOOP(kShortcutDescActionGraphTogglePreview); (void)QT_TR_NOOP(kShortcutDescActionGraphForcePreview); (void)QT_TR_NOOP(kShortcutDescActionGraphShowCacheSize); (void)QT_TR_NOOP(kShortcutDescActionGraphFrameNodes); (void)QT_TR_NOOP(kShortcutDescActionGraphFindNode); (void)QT_TR_NOOP(kShortcutDescActionGraphRenameNode); (void)QT_TR_NOOP(kShortcutDescActionGraphExtractNode); (void)QT_TR_NOOP(kShortcutDescActionGraphMakeGroup); (void)QT_TR_NOOP(kShortcutDescActionGraphExpandGroup); (void)QT_TR_NOOP(kShortcutDescActionAnimationModuleRemoveKeys); (void)QT_TR_NOOP(kShortcutDescActionAnimationModuleConstant); (void)QT_TR_NOOP(kShortcutDescActionAnimationModuleLinear); (void)QT_TR_NOOP(kShortcutDescActionAnimationModuleSmooth); (void)QT_TR_NOOP(kShortcutDescActionAnimationModuleCatmullrom); (void)QT_TR_NOOP(kShortcutDescActionAnimationModuleCubic); (void)QT_TR_NOOP(kShortcutDescActionAnimationModuleHorizontal); (void)QT_TR_NOOP(kShortcutDescActionAnimationModuleBreak); (void)QT_TR_NOOP(kShortcutDescActionAnimationModuleSelectAll); (void)QT_TR_NOOP(kShortcutDescActionAnimationModuleCenter); (void)QT_TR_NOOP(kShortcutDescActionAnimationModuleCopy); (void)QT_TR_NOOP(kShortcutDescActionAnimationModulePasteKeyframes); (void)QT_TR_NOOP(kShortcutDescActionAnimationModulePasteKeyframesAbsolute); (void)QT_TR_NOOP(kShortcutDescActionScriptEditorPrevScript); (void)QT_TR_NOOP(kShortcutDescActionScriptEditorNextScript); (void)QT_TR_NOOP(kShortcutDescActionScriptEditorClearHistory); (void)QT_TR_NOOP(kShortcutDescActionScriptExecScript); (void)QT_TR_NOOP(kShortcutDescActionScriptClearOutput); (void)QT_TR_NOOP(kShortcutDescActionScriptShowOutput); QString actionIDStr = QString::fromUtf8( actionID.c_str() ); std::list<QKeySequence> seq = getKeybind(_group, actionIDStr); if ( seq.empty() ) { seq.push_back( QKeySequence() ); } _shortcuts.push_back( std::make_pair( actionIDStr, seq.front() ) ); assert ( !_group.isEmpty() && !actionIDStr.isEmpty() ); if (setShortcutOnAction) { setShortcut( seq.front() ); } appPTR->addShortcutAction(_group, actionIDStr, this); setShortcutContext(Qt::WindowShortcut); setText( tr( actionDescription.c_str() ) ); }
int QAction::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 15) qt_static_metacall(this, _c, _id, _a); _id -= 15; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< bool*>(_v) = isCheckable(); break; case 1: *reinterpret_cast< bool*>(_v) = isChecked(); break; case 2: *reinterpret_cast< bool*>(_v) = isEnabled(); break; case 3: *reinterpret_cast< QIcon*>(_v) = icon(); break; case 4: *reinterpret_cast< QString*>(_v) = text(); break; case 5: *reinterpret_cast< QString*>(_v) = iconText(); break; case 6: *reinterpret_cast< QString*>(_v) = toolTip(); break; case 7: *reinterpret_cast< QString*>(_v) = statusTip(); break; case 8: *reinterpret_cast< QString*>(_v) = whatsThis(); break; case 9: *reinterpret_cast< QFont*>(_v) = font(); break; case 10: *reinterpret_cast< QKeySequence*>(_v) = shortcut(); break; case 11: *reinterpret_cast< Qt::ShortcutContext*>(_v) = shortcutContext(); break; case 12: *reinterpret_cast< bool*>(_v) = autoRepeat(); break; case 13: *reinterpret_cast< bool*>(_v) = isVisible(); break; case 14: *reinterpret_cast< MenuRole*>(_v) = menuRole(); break; case 15: *reinterpret_cast< SoftKeyRole*>(_v) = softKeyRole(); break; case 16: *reinterpret_cast< bool*>(_v) = isIconVisibleInMenu(); break; case 17: *reinterpret_cast< Priority*>(_v) = priority(); break; } _id -= 18; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setCheckable(*reinterpret_cast< bool*>(_v)); break; case 1: setChecked(*reinterpret_cast< bool*>(_v)); break; case 2: setEnabled(*reinterpret_cast< bool*>(_v)); break; case 3: setIcon(*reinterpret_cast< QIcon*>(_v)); break; case 4: setText(*reinterpret_cast< QString*>(_v)); break; case 5: setIconText(*reinterpret_cast< QString*>(_v)); break; case 6: setToolTip(*reinterpret_cast< QString*>(_v)); break; case 7: setStatusTip(*reinterpret_cast< QString*>(_v)); break; case 8: setWhatsThis(*reinterpret_cast< QString*>(_v)); break; case 9: setFont(*reinterpret_cast< QFont*>(_v)); break; case 10: setShortcut(*reinterpret_cast< QKeySequence*>(_v)); break; case 11: setShortcutContext(*reinterpret_cast< Qt::ShortcutContext*>(_v)); break; case 12: setAutoRepeat(*reinterpret_cast< bool*>(_v)); break; case 13: setVisible(*reinterpret_cast< bool*>(_v)); break; case 14: setMenuRole(*reinterpret_cast< MenuRole*>(_v)); break; case 15: setSoftKeyRole(*reinterpret_cast< SoftKeyRole*>(_v)); break; case 16: setIconVisibleInMenu(*reinterpret_cast< bool*>(_v)); break; case 17: setPriority(*reinterpret_cast< Priority*>(_v)); break; } _id -= 18; } else if (_c == QMetaObject::ResetProperty) { _id -= 18; } else if (_c == QMetaObject::QueryPropertyDesignable) { bool *_b = reinterpret_cast<bool*>(_a[0]); switch (_id) { case 1: *_b = isCheckable(); break; } _id -= 18; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 18; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 18; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 18; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 18; } #endif // QT_NO_PROPERTIES return _id; }
PythonEditorWidget::PythonEditorWidget(InviwoMainWindow* ivwwin, InviwoApplication* app) : InviwoDockWidget(tr("Python Editor"), ivwwin) , settings_("Inviwo", "Inviwo") , infoTextColor_(153, 153, 153) , errorTextColor_(255, 107, 107) , runAction_(nullptr) , script_() , unsavedChanges_(false) , app_(app) , appendLog_(true) { setObjectName("PythonEditor"); settings_.beginGroup("PythonEditor"); QString lastFile = settings_.value("lastScript", "").toString(); appendLog_ = settings_.value("appendLog", appendLog_).toBool(); settings_.endGroup(); setVisible(false); setWindowIcon(QIcon(":/icons/python.png")); QMainWindow* mainWindow = new QMainWindow(); mainWindow->setContextMenuPolicy(Qt::NoContextMenu); QToolBar* toolBar = new QToolBar(); mainWindow->addToolBar(toolBar); toolBar->setFloatable(false); toolBar->setMovable(false); setWidget(mainWindow); { runAction_ = toolBar->addAction(QIcon(":/icons/python.png"), "Compile and Run"); runAction_->setShortcut(QKeySequence(tr("F5"))); runAction_->setShortcutContext(Qt::WidgetWithChildrenShortcut); runAction_->setToolTip("Compile and Run Script"); mainWindow->addAction(runAction_); connect(runAction_, &QAction::triggered, [this]() {run(); }); } { auto action = toolBar->addAction(QIcon(":/icons/new.png"), tr("&New Script")); action->setShortcut(QKeySequence::New); action->setShortcutContext(Qt::WidgetWithChildrenShortcut); action->setToolTip("New Script"); mainWindow->addAction(action); connect(action, &QAction::triggered, [this](){setDefaultText();}); } { auto action = toolBar->addAction(QIcon(":/icons/open.png"), tr("&Open Script")); action->setShortcut(QKeySequence::Open); action->setShortcutContext(Qt::WidgetWithChildrenShortcut); action->setToolTip("Open Script"); mainWindow->addAction(action); connect(action, &QAction::triggered, [this](){open();}); } { auto action = toolBar->addAction(QIcon(":/icons/save.png"), tr("&Save Script")); action->setShortcut(QKeySequence::Save); action->setShortcutContext(Qt::WidgetWithChildrenShortcut); action->setToolTip("Save Script"); mainWindow->addAction(action); connect(action, &QAction::triggered, [this](){save();}); } { auto action = toolBar->addAction(QIcon(":/icons/saveas.png"), tr("&Save Script As...")); action->setShortcut(QKeySequence::SaveAs); action->setShortcutContext(Qt::WidgetWithChildrenShortcut); action->setToolTip("Save Script As..."); mainWindow->addAction(action); connect(action, &QAction::triggered, [this](){saveAs();}); } { QIcon icon; icon.addFile(":/icons/log-append.png", QSize(), QIcon::Normal, QIcon::On); icon.addFile(":/icons/log-clearonrun.png", QSize(), QIcon::Normal, QIcon::Off); QString str = (appendLog_ ? "Append Log" : "Clear Log on Run"); auto action = toolBar->addAction(icon, str); action->setShortcut(Qt::ControlModifier + Qt::Key_E); action->setShortcutContext(Qt::WidgetWithChildrenShortcut); action->setCheckable(true); action->setChecked(appendLog_); action->setToolTip(appendLog_ ? "Append Log" : "Clear Log on Run"); mainWindow->addAction(action); connect(action, &QAction::toggled, [this, action](bool toggle) { appendLog_ = toggle; // update tooltip and menu entry QString tglstr = (toggle ? "Append Log" : "Clear Log on Run"); action->setText(tglstr); action->setToolTip(tglstr); // update settings settings_.beginGroup("PythonEditor"); settings_.setValue("appendLog", appendLog_); settings_.endGroup(); }); } { auto action = toolBar->addAction(QIcon(":/icons/log-clear.png"), "Clear Log Output"); action->setShortcut(Qt::ControlModifier + Qt::Key_E); action->setShortcutContext(Qt::WidgetWithChildrenShortcut); action->setToolTip("Clear Log Output"); mainWindow->addAction(action); connect(action, &QAction::triggered, [this](){clearOutput();}); } // Done creating buttons QSplitter* splitter = new QSplitter(nullptr); splitter->setOrientation(Qt::Vertical); pythonCode_ = new PythonTextEditor(nullptr); pythonCode_->setObjectName("pythonEditor"); pythonCode_->setUndoRedoEnabled(true); setDefaultText(); pythonOutput_ = new QTextEdit(nullptr); pythonOutput_->setObjectName("pythonConsole"); pythonOutput_->setReadOnly(true); pythonOutput_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); syntaxHighligther_ = SyntaxHighligther::createSyntaxHighligther<Python>(pythonCode_->document()); splitter->addWidget(pythonCode_); splitter->addWidget(pythonOutput_); splitter->setStretchFactor(0, 1); splitter->setStretchFactor(1, 0); splitter->setHandleWidth(2); // enable QSplitter:hover stylesheet // QTBUG-13768 https://bugreports.qt.io/browse/QTBUG-13768 splitter->handle(1)->setAttribute(Qt::WA_Hover); mainWindow->setCentralWidget(splitter); QObject::connect(pythonCode_, SIGNAL(textChanged()), this, SLOT(onTextChange())); // close this window before the main window is closed QObject::connect(ivwwin, &InviwoMainWindow::closingMainWindow, [this]() { delete this; }); this->updateStyle(); this->resize(500, 700); if (app_) { app_->getSettingsByType<SystemSettings>()->pythonSyntax_.onChange( this, &PythonEditorWidget::updateStyle); app_->getSettingsByType<SystemSettings>()->pyFontSize_.onChange( this, &PythonEditorWidget::updateStyle); app_->registerFileObserver(this); } unsavedChanges_ = false; if (lastFile.size() != 0) loadFile(lastFile.toLocal8Bit().constData(), false); setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); setFloating(true); }