void HelpBrowser::createActions() { QAction * action; OverridingAction *ovrAction; mActions[GoHome] = action = new QAction(tr("Home"), this); connect( action, SIGNAL(triggered()), this, SLOT(goHome()) ); mActions[ZoomIn] = ovrAction = new OverridingAction(tr("Zoom In"), this); connect(ovrAction, SIGNAL(triggered()), this, SLOT(zoomIn())); ovrAction->addToWidget(mWebView); mActions[ZoomOut] = ovrAction = new OverridingAction(tr("Zoom Out"), this); connect(ovrAction, SIGNAL(triggered()), this, SLOT(zoomOut())); ovrAction->addToWidget(mWebView); mActions[ResetZoom] = ovrAction = new OverridingAction(tr("Reset Zoom"), this); connect(ovrAction, SIGNAL(triggered()), this, SLOT(resetZoom())); ovrAction->addToWidget(mWebView); mActions[Evaluate] = ovrAction = new OverridingAction(tr("Evaluate as Code"), this); connect(ovrAction, SIGNAL(triggered()), this, SLOT(evaluateSelection())); ovrAction->addToWidget(mWebView); // For the sake of display: mWebView->pageAction(QWebPage::Copy)->setShortcut( QKeySequence::Copy ); mWebView->pageAction(QWebPage::Paste)->setShortcut( QKeySequence::Paste ); }
void MainWindow::createMenus() { Settings::Manager *s = mMain->settings(); s->beginGroup("IDE/shortcuts"); new QShortcut( s->shortcut("cmdLineFocus"), this, SLOT(toggleComandLineFocus()) ); QAction *act; // File mActions[Quit] = act = new QAction( QIcon::fromTheme("application-exit"), tr("&Quit..."), this); act->setShortcut(s->shortcut("quit")); act->setStatusTip(tr("Quit SuperCollider IDE")); QObject::connect( act, SIGNAL(triggered()), this, SLOT(onQuit()) ); // View mActions[ShowDocList] = act = new QAction(tr("&Documents"), this); act->setStatusTip(tr("Show/Hide the Documents dock")); act->setCheckable(true); connect(act, SIGNAL(triggered(bool)), mDocListDock, SLOT(setVisible(bool))); connect(mDocListDock, SIGNAL(visibilityChanged(bool)), act, SLOT(setChecked(bool))); // Language mActions[EvaluateCurrentFile] = act = new QAction( QIcon::fromTheme("media-playback-start"), tr("Evaluate &File"), this); act->setStatusTip(tr("Evaluate current File")); connect(act, SIGNAL(triggered()), this, SLOT(evaluateCurrentFile())); mActions[EvaluateSelection] = act = new QAction( QIcon::fromTheme("media-playback-start"), tr("&Evaluate Selection"), this); act->setShortcut(s->shortcut("evaluateSelection")); act->setStatusTip(tr("Evaluate selection or current line")); connect(act, SIGNAL(triggered()), this, SLOT(evaluateSelection())); mActions[EvaluateRegion] = act = new QAction( QIcon::fromTheme("media-playback-start"), tr("&Evaluate Region"), this); act->setShortcut(s->shortcut("evaluateRegion")); act->setStatusTip(tr("Evaluate current region")); connect(act, SIGNAL(triggered()), this, SLOT(evaluateRegion())); mMain->scProcess()->action(ScIDE::SCProcess::StopMain) ->setShortcut(s->shortcut("stopMain")); // Settings mActions[ShowSettings] = act = new QAction(tr("&Configure IDE..."), this); act->setStatusTip(tr("Show configuration dialog")); connect(act, SIGNAL(triggered()), this, SLOT(showSettings())); // Help mActions[BrowseHelp] = act = new QAction( QIcon::fromTheme("system-help"), tr("&Browse Help"), this); act->setStatusTip(tr("Open help browser on the Browse page.")); //connect(act, SIGNAL(triggered()), this, SLOT(browseHelp())); mCodeEvalMapper.setMapping(act, "HelpBrowser.openBrowsePage"); connect(act, SIGNAL(triggered()), &mCodeEvalMapper, SLOT(map())); mActions[SearchHelp] = act = new QAction( QIcon::fromTheme("system-help"), tr("&Search Help"), this); act->setStatusTip(tr("Open help browser on the Search page.")); //connect(act, SIGNAL(triggered()), this, SLOT(searchHelp())); mCodeEvalMapper.setMapping(act, "HelpBrowser.openSearchPage"); connect(act, SIGNAL(triggered()), &mCodeEvalMapper, SLOT(map())); mActions[HelpForSelection] = act = new QAction( QIcon::fromTheme("system-help"), tr("&Help for Selection"), this); act->setShortcut(s->shortcut("helpForSelection")); act->setStatusTip(tr("Find help for selected text")); connect(act, SIGNAL(triggered()), this, SLOT(helpForSelection())); s->endGroup(); // IDE/shortcuts; QMenu *menu; QMenu *submenu; menu = new QMenu(tr("&File"), this); menu->addAction( mEditors->action(MultiEditor::DocNew) ); menu->addAction( mEditors->action(MultiEditor::DocOpen) ); menu->addAction( mEditors->action(MultiEditor::DocSave) ); menu->addAction( mEditors->action(MultiEditor::DocSaveAs) ); menu->addSeparator(); menu->addAction( mEditors->action(MultiEditor::DocClose) ); menu->addSeparator(); menu->addAction( mActions[Quit] ); menuBar()->addMenu(menu); menu = new QMenu(tr("&Edit"), this); menu->addAction( mEditors->action(MultiEditor::Undo) ); menu->addAction( mEditors->action(MultiEditor::Redo) ); menu->addSeparator(); menu->addAction( mEditors->action(MultiEditor::Cut) ); menu->addAction( mEditors->action(MultiEditor::Copy) ); menu->addAction( mEditors->action(MultiEditor::Paste) ); menu->addSeparator(); menu->addAction( mEditors->action(MultiEditor::Find) ); menu->addAction( mEditors->action(MultiEditor::Replace) ); menu->addSeparator(); menu->addAction( mEditors->action(MultiEditor::IndentMore) ); menu->addAction( mEditors->action(MultiEditor::IndentLess) ); menu->addSeparator(); menu->addAction( mEditors->action(MultiEditor::OpenClassDefinition) ); menuBar()->addMenu(menu); menu = new QMenu(tr("&View"), this); submenu = new QMenu(tr("&Docks"), this); submenu->addAction( mActions[ShowDocList] ); menu->addMenu(submenu); menu->addSeparator(); menu->addAction( mEditors->action(MultiEditor::EnlargeFont) ); menu->addAction( mEditors->action(MultiEditor::ShrinkFont) ); menu->addSeparator(); menu->addAction( mEditors->action(MultiEditor::ShowWhitespace) ); menuBar()->addMenu(menu); menu = new QMenu(tr("&Language"), this); menu->addAction( mMain->scProcess()->action(SCProcess::StartSCLang) ); menu->addAction( mMain->scProcess()->action(SCProcess::RecompileClassLibrary) ); menu->addAction( mMain->scProcess()->action(SCProcess::StopSCLang) ); menu->addSeparator(); menu->addAction( mActions[EvaluateCurrentFile] ); menu->addAction( mActions[EvaluateRegion] ); menu->addAction( mActions[EvaluateSelection] ); menu->addSeparator(); menu->addAction( mMain->scProcess()->action(ScIDE::SCProcess::RunMain) ); menu->addAction( mMain->scProcess()->action(ScIDE::SCProcess::StopMain) ); menuBar()->addMenu(menu); menu = new QMenu(tr("&Settings"), this); menu->addAction( mActions[ShowSettings] ); menuBar()->addMenu(menu); menu = new QMenu(tr("&Help"), this); menu->addAction( mActions[BrowseHelp] ); menu->addAction( mActions[SearchHelp] ); menu->addAction( mActions[HelpForSelection] ); menuBar()->addMenu(menu); }
HelpBrowser::HelpBrowser( QWidget * parent ): QWidget(parent) { QRect availableScreenRect = qApp->desktop()->availableGeometry(this); mSizeHint = QSize( availableScreenRect.width() * 0.4, availableScreenRect.height() * 0.7 ); QtCollider::WebPage *webPage = new QtCollider::WebPage(this); webPage->setDelegateReload(true); webPage->setLinkDelegationPolicy( QWebPage::DelegateAllLinks ); mWebView = new QWebView; mWebView->setPage( webPage ); mWebView->settings()->setAttribute( QWebSettings::LocalStorageEnabled, true ); // NOTE: we assume all web page shortcuts have Qt::WidgetShortcut context mWebView->setContextMenuPolicy( Qt::ActionsContextMenu ); mWebView->addAction( webPage->action( QWebPage::Copy ) ); mWebView->addAction( webPage->action( QWebPage::Paste ) ); // Set the style's standard palette to avoid system's palette incoherencies // get in the way of rendering web pages mWebView->setPalette( style()->standardPalette() ); mWebView->installEventFilter(this); mLoadProgressIndicator = new LoadProgressIndicator; mLoadProgressIndicator->setIndent(10); QToolBar *toolBar = new QToolBar; toolBar->setIconSize( QSize(16,16) ); QAction *action = toolBar->addAction("Home"); connect( action, SIGNAL(triggered()), this, SLOT(goHome()) ); toolBar->addAction( mWebView->pageAction(QWebPage::Back) ); toolBar->addAction( mWebView->pageAction(QWebPage::Forward) ); toolBar->addAction( mWebView->pageAction(QWebPage::Reload) ); toolBar->addWidget(mLoadProgressIndicator); QVBoxLayout *layout = new QVBoxLayout; layout->setContentsMargins(0,0,0,0); layout->setSpacing(0); layout->addWidget(toolBar); layout->addWidget(mWebView); setLayout(layout); connect( mWebView, SIGNAL(linkClicked(QUrl)), this, SLOT(onLinkClicked(QUrl)) ); connect( mWebView, SIGNAL(loadStarted()), mLoadProgressIndicator, SLOT(start()) ); connect( mWebView, SIGNAL(loadFinished(bool)), mLoadProgressIndicator, SLOT(stop()) ); connect( webPage->action(QWebPage::Reload), SIGNAL(triggered(bool)), this, SLOT(onReload()) ); connect( webPage, SIGNAL(jsConsoleMsg(QString,int,QString)), this, SLOT(onJsConsoleMsg(QString,int,QString)) ); ScProcess * scProcess = Main::scProcess(); connect( scProcess, SIGNAL(response(QString,QString)), this, SLOT(onScResponse(QString,QString)) ); connect( scProcess, SIGNAL(finished(int)), mLoadProgressIndicator, SLOT(stop()) ); // FIXME: should actually respond to class library shutdown, but we don't have that signal connect( scProcess, SIGNAL(classLibraryRecompiled()), mLoadProgressIndicator, SLOT(stop()) ); mEvaluateShortcut = new QShortcut(this); mEvaluateShortcut->setContext( Qt::WidgetWithChildrenShortcut ); connect( mEvaluateShortcut, SIGNAL(activated()), this, SLOT(evaluateSelection()) ); applySettings( Main::settings() ); }