Help: Implement a real external help window

With this patch it is just used with the context help "always show in
external window" option.

Change-Id: I4bc6ba8e0e241500f6970d4cb72f66ba02075ef5
Reviewed-by: Karsten Heimrich <karsten.heimrich@digia.com>
This commit is contained in:
Eike Ziller
2014-06-18 17:42:01 +02:00
parent b2a2a89358
commit e7ac9facd3
12 changed files with 154 additions and 437 deletions

View File

@@ -1,203 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "externalhelpwindow.h"
#include "centralwidget.h"
#include "helpconstants.h"
#include "openpagesmanager.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
#include <utils/hostosinfo.h>
#include <QAction>
#include <QHBoxLayout>
#include <QKeyEvent>
#include <QStatusBar>
#include <QToolButton>
using namespace Help::Internal;
ExternalHelpWindow::ExternalHelpWindow(QWidget *parent)
: QMainWindow(parent)
{
QSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String(Help::Constants::ID_MODE_HELP));
const QVariant geometry = settings->value(QLatin1String("geometry"));
if (geometry.isValid())
restoreGeometry(geometry.toByteArray());
else
resize(640, 480);
settings->endGroup();
QAction *action = new QAction(this);
action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_I));
connect(action, SIGNAL(triggered()), this, SIGNAL(activateIndex()));
addAction(action);
action = new QAction(this);
action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C));
connect(action, SIGNAL(triggered()), this, SIGNAL(activateContents()));
addAction(action);
action = new QAction(this);
action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Slash));
connect(action, SIGNAL(triggered()), this, SIGNAL(activateSearch()));
addAction(action);
action = new QAction(this);
action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B));
connect(action, SIGNAL(triggered()), this, SIGNAL(activateBookmarks()));
addAction(action);
action = new QAction(this);
action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_O));
connect(action, SIGNAL(triggered()), this, SIGNAL(activateOpenPages()));
addAction(action);
CentralWidget *centralWidget = CentralWidget::instance();
action = new QAction(this);
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Plus));
connect(action, SIGNAL(triggered()), centralWidget, SLOT(zoomIn()));
addAction(action);
action = new QAction(this);
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Minus));
connect(action, SIGNAL(triggered()), centralWidget, SLOT(zoomOut()));
addAction(action);
action = new QAction(this);
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M));
connect(action, SIGNAL(triggered()), this, SIGNAL(addBookmark()));
addAction(action);
action = new QAction(this);
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));
connect(action, SIGNAL(triggered()), centralWidget, SLOT(copy()));
addAction(action);
action = new QAction(this);
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P));
connect(action, SIGNAL(triggered()), centralWidget, SLOT(print()));
addAction(action);
action = new QAction(this);
action->setShortcut(QKeySequence::Back);
action->setEnabled(centralWidget->isBackwardAvailable());
connect(action, SIGNAL(triggered()), centralWidget, SLOT(backward()));
connect(centralWidget, SIGNAL(backwardAvailable(bool)), action,
SLOT(setEnabled(bool)));
action = new QAction(this);
action->setShortcut(QKeySequence::Forward);
action->setEnabled(centralWidget->isForwardAvailable());
connect(action, SIGNAL(triggered()), centralWidget, SLOT(forward()));
connect(centralWidget, SIGNAL(forwardAvailable(bool)), action,
SLOT(setEnabled(bool)));
QAction *reset = new QAction(this);
connect(reset, SIGNAL(triggered()), centralWidget, SLOT(resetZoom()));
addAction(reset);
QAction *ctrlTab = new QAction(this);
connect(ctrlTab, SIGNAL(triggered()), &OpenPagesManager::instance(),
SLOT(gotoPreviousPage()));
addAction(ctrlTab);
QAction *ctrlShiftTab = new QAction(this);
connect(ctrlShiftTab, SIGNAL(triggered()), &OpenPagesManager::instance(),
SLOT(gotoNextPage()));
addAction(ctrlShiftTab);
action = new QAction(QIcon(QLatin1String(Core::Constants::ICON_TOGGLE_SIDEBAR)),
tr("Show Sidebar"), this);
connect(action, SIGNAL(triggered()), this, SIGNAL(showHideSidebar()));
if (Utils::HostOsInfo::isMacHost()) {
reset->setShortcut(QKeySequence(Qt::ALT + Qt::Key_0));
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_0));
ctrlTab->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Tab));
ctrlShiftTab->setShortcut(QKeySequence(Qt::ALT + Qt::SHIFT + Qt::Key_Tab));
} else {
reset->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_0));
action->setShortcut(QKeySequence(Qt::ALT + Qt::Key_0));
ctrlTab->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Tab));
ctrlShiftTab->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab));
}
QToolButton *button = new QToolButton;
button->setDefaultAction(action);
QStatusBar *statusbar = statusBar();
statusbar->show();
statusbar->setProperty("p_styled", true);
statusbar->addPermanentWidget(button);
QWidget *w = new QWidget;
QHBoxLayout *layout = new QHBoxLayout(w);
layout->addStretch(1);
statusbar->insertWidget(1, w, 1);
installEventFilter(this);
setWindowTitle(tr("Qt Creator Offline Help"));
}
ExternalHelpWindow::~ExternalHelpWindow()
{
}
void ExternalHelpWindow::closeEvent(QCloseEvent *event)
{
QSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String(Help::Constants::ID_MODE_HELP));
settings->setValue(QLatin1String("geometry"), saveGeometry());
settings->endGroup();
QMainWindow::closeEvent(event);
}
bool ExternalHelpWindow::eventFilter(QObject *obj, QEvent *event)
{
if (obj == this) {
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent*> (event);
switch (keyEvent->key()) {
case Qt::Key_Escape:
Core::ICore::raiseWindow(Core::ICore::mainWindow());
default:
break;
}
}
}
return QMainWindow::eventFilter(obj, event);
}

View File

@@ -1,66 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef EXTERNALHELPWINDOW
#define EXTERNALHELPWINDOW
#include <QMainWindow>
QT_FORWARD_DECLARE_CLASS(QCloseEvent)
QT_FORWARD_DECLARE_CLASS(QToolButton)
namespace Help {
namespace Internal {
class ExternalHelpWindow : public QMainWindow
{
Q_OBJECT
public:
ExternalHelpWindow(QWidget *parent = 0);
virtual ~ExternalHelpWindow();
signals:
void activateIndex();
void activateContents();
void activateSearch();
void activateBookmarks();
void activateOpenPages();
void addBookmark();
void showHideSidebar();
protected:
void closeEvent(QCloseEvent *event);
bool eventFilter(QObject *obj, QEvent *event);
};
} // Internal
} // Help
#endif // EXTERNALHELPWINDOW

View File

@@ -185,8 +185,6 @@ void GeneralSettingsPage::apply()
settings->beginGroup(QLatin1String(Help::Constants::ID_MODE_HELP));
settings->setValue(QLatin1String("ContextHelpOption"), helpOption);
settings->endGroup();
emit contextHelpOptionChanged();
}
const bool close = m_ui->m_returnOnClose->isChecked();

View File

@@ -55,7 +55,6 @@ signals:
void fontChanged();
void startOptionChanged();
void returnOnCloseChanged();
void contextHelpOptionChanged();
private slots:
void setCurrentPage();

View File

@@ -196,7 +196,7 @@
</item>
<item>
<property name="text">
<string>Always Show Help in External Window</string>
<string>Always Show in External Window</string>
</property>
</item>
</widget>

View File

@@ -35,7 +35,6 @@ HEADERS += \
remotehelpfilter.h \
searchwidget.h \
xbelsupport.h \
externalhelpwindow.h \
searchtaskhandler.h \
qtwebkithelpviewer.h \
textbrowserhelpviewer.h \
@@ -59,7 +58,6 @@ SOURCES += \
remotehelpfilter.cpp \
searchwidget.cpp \
xbelsupport.cpp \
externalhelpwindow.cpp \
searchtaskhandler.cpp \
qtwebkithelpviewer.cpp \
textbrowserhelpviewer.cpp \

View File

@@ -42,7 +42,6 @@ QtcPlugin {
files: [
"centralwidget.cpp", "centralwidget.h",
"docsettingspage.cpp", "docsettingspage.h", "docsettingspage.ui",
"externalhelpwindow.cpp", "externalhelpwindow.h",
"filtersettingspage.cpp", "filtersettingspage.h", "filtersettingspage.ui",
"generalsettingspage.cpp", "generalsettingspage.h", "generalsettingspage.ui",
"help.qrc",

View File

@@ -64,6 +64,9 @@ const char HELP_TR_CATEGORY[] = QT_TRANSLATE_NOOP("Help", "Help");
const char C_MODE_HELP [] = "Help Mode";
const char C_HELP_SIDEBAR[] = "Help Sidebar";
const char C_HELP_EXTERNAL[] = "Help.ExternalWindow";
const char CONTEXT_HELP[] = "Help.Context";
} // Constants
} // Help

View File

@@ -31,7 +31,6 @@
#include "centralwidget.h"
#include "docsettingspage.h"
#include "externalhelpwindow.h"
#include "filtersettingspage.h"
#include "generalsettingspage.h"
#include "helpconstants.h"
@@ -39,7 +38,6 @@
#include "helpindexfilter.h"
#include "helpmode.h"
#include "helpviewer.h"
#include "helpwidget.h"
#include "localhelpmanager.h"
#include "openpagesmanager.h"
#include "openpagesmodel.h"
@@ -104,6 +102,8 @@ const char SB_BOOKMARKS[] = QT_TRANSLATE_NOOP("Help::Internal::HelpPlugin", "Boo
const char SB_OPENPAGES[] = "OpenPages";
static const char kExternalWindowStateKey[] = "Help/ExternalWindowState";
#define IMAGEPATH ":/help/images/"
using namespace Core;
@@ -128,9 +128,6 @@ HelpPlugin::HelpPlugin()
m_firstModeChange(true),
m_helpManager(0),
m_openPagesManager(0),
m_oldMode(0),
m_connectWindow(true),
m_externalWindow(0),
m_backMenu(0),
m_nextMenu(0),
m_isSidebarVisible(true)
@@ -177,8 +174,6 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
connect(m_generalSettingsPage, SIGNAL(fontChanged()), this,
SLOT(fontChanged()));
connect(m_generalSettingsPage, SIGNAL(contextHelpOptionChanged()), this,
SLOT(contextHelpOptionChanged()));
connect(m_generalSettingsPage, SIGNAL(returnOnCloseChanged()), this,
SLOT(updateCloseButton()));
connect(HelpManager::instance(), SIGNAL(helpRequested(QUrl)), this,
@@ -241,7 +236,7 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
connect(action, SIGNAL(triggered()), this, SLOT(activateIndex()));
action = new QAction(tr("Context Help"), this);
cmd = ActionManager::registerAction(action, "Help.Context", globalcontext);
cmd = ActionManager::registerAction(action, Help::Constants::CONTEXT_HELP, globalcontext);
ActionManager::actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP);
cmd->setDefaultKeySequence(QKeySequence(Qt::Key_F1));
connect(action, SIGNAL(triggered()), this, SLOT(activateContext()));
@@ -340,18 +335,9 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
connect(ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode*,Core::IMode*)),
this, SLOT(modeChanged(Core::IMode*,Core::IMode*)));
m_externalWindow = new ExternalHelpWindow;
m_mode = new HelpMode;
if (contextHelpOption() == Help::Constants::ExternalHelpAlways) {
m_mode->setWidget(new QWidget);
m_mode->setEnabled(false);
m_externalHelpBar->setVisible(true);
m_externalWindow->setCentralWidget(m_splitter);
QTimer::singleShot(0, this, SLOT(showExternalWindow()));
} else {
m_mode->setWidget(m_splitter);
m_internalHelpBar->setVisible(true);
}
m_mode->setWidget(m_splitter);
m_internalHelpBar->setVisible(true);
addAutoReleasedObject(m_mode);
return true;
@@ -375,12 +361,6 @@ ExtensionSystem::IPlugin::ShutdownFlag HelpPlugin::aboutToShutdown()
settings->setValue(QLatin1String("HelpSideBar/") + QLatin1String("Visible"), m_isSidebarVisible);
}
if (m_externalWindow) {
delete m_externalWindow;
m_centralWidget = 0; // Running the external window will take down the central widget as well, cause
// calling m_externalWindow->setCentralWidget(m_centralWidget) will pass ownership to the window.
}
return SynchronousShutdown;
}
@@ -524,23 +504,58 @@ void HelpPlugin::resetFilter()
connect(engine, SIGNAL(setupFinished()), this, SLOT(updateFilterComboBox()));
}
void HelpPlugin::createRightPaneContextViewer()
void HelpPlugin::saveExternalWindowSettings()
{
if (m_rightPaneSideBarWidget)
if (!m_externalWindow)
return;
m_externalWindowState = m_externalWindow->geometry();
QSettings *settings = Core::ICore::settings();
settings->setValue(QLatin1String(kExternalWindowStateKey),
qVariantFromValue(m_externalWindowState));
}
m_rightPaneSideBarWidget = new HelpWidget(Core::Context(Constants::C_HELP_SIDEBAR));
HelpWidget *HelpPlugin::createHelpWidget(const Context &context, HelpWidget::WidgetStyle style)
{
HelpWidget *widget = new HelpWidget(context, style);
connect(m_rightPaneSideBarWidget->currentViewer(), SIGNAL(loadFinished()),
connect(widget->currentViewer(), SIGNAL(loadFinished()),
this, SLOT(highlightSearchTermsInContextHelp()));
connect(m_rightPaneSideBarWidget, SIGNAL(openHelpMode(QUrl)),
connect(widget, SIGNAL(openHelpMode(QUrl)),
this, SLOT(switchToHelpMode(QUrl)));
connect(m_rightPaneSideBarWidget, SIGNAL(close()),
connect(widget, SIGNAL(closeButtonClicked()),
this, SLOT(slotHideRightPane()));
connect(widget, SIGNAL(aboutToClose()),
this, SLOT(saveExternalWindowSettings()));
// force setup, as we might have never switched to full help mode
// thus the help engine might still run without collection file setup
m_helpManager->setupGuiHelpEngine();
return widget;
}
void HelpPlugin::createRightPaneContextViewer()
{
if (m_rightPaneSideBarWidget)
return;
m_rightPaneSideBarWidget = createHelpWidget(Core::Context(Constants::C_HELP_SIDEBAR),
HelpWidget::SideBarWidget);
}
HelpViewer *HelpPlugin::externalHelpViewer()
{
if (m_externalWindow)
return m_externalWindow->currentViewer();
m_externalWindow = createHelpWidget(Core::Context(Constants::C_HELP_EXTERNAL),
HelpWidget::ExternalWindow);
if (m_externalWindowState.isNull()) {
QSettings *settings = Core::ICore::settings();
m_externalWindowState = settings->value(QLatin1String(kExternalWindowStateKey)).toRect();
}
if (!m_externalWindowState.isNull())
m_externalWindow->setGeometry(m_externalWindowState);
m_externalWindow->show();
return m_externalWindow->currentViewer();
}
HelpViewer *HelpPlugin::createHelpViewer(qreal zoom)
@@ -576,15 +591,13 @@ HelpViewer *HelpPlugin::createHelpViewer(qreal zoom)
void HelpPlugin::activateHelpMode()
{
if (contextHelpOption() != Help::Constants::ExternalHelpAlways)
ModeManager::activateMode(Id(Constants::ID_MODE_HELP));
else
showExternalWindow();
ModeManager::activateMode(Id(Constants::ID_MODE_HELP));
}
void HelpPlugin::switchToHelpMode(const QUrl &source)
{
activateHelpMode();
Core::ICore::raiseWindow(m_mode->widget());
m_centralWidget->setSource(source);
m_centralWidget->setFocus();
}
@@ -600,22 +613,10 @@ void HelpPlugin::showHideSidebar()
onSideBarVisibilityChanged();
}
void HelpPlugin::showExternalWindow()
{
bool firstTime = m_firstModeChange;
doSetupIfNeeded();
m_externalWindow->show();
connectExternalHelpWindow();
if (firstTime)
ICore::raiseWindow(ICore::mainWindow());
else
ICore::raiseWindow(m_externalWindow);
}
void HelpPlugin::modeChanged(IMode *mode, IMode *old)
{
Q_UNUSED(old)
if (mode == m_mode) {
m_oldMode = old;
qApp->setOverrideCursor(Qt::WaitCursor);
doSetupIfNeeded();
qApp->restoreOverrideCursor();
@@ -673,55 +674,6 @@ QStackedLayout * layoutForWidget(QWidget *parent, QWidget *widget)
return 0;
}
void HelpPlugin::contextHelpOptionChanged()
{
doSetupIfNeeded();
QWidget *modeWidget = m_mode->widget();
if (modeWidget == m_splitter
&& contextHelpOption() == Help::Constants::ExternalHelpAlways) {
if (QWidget *widget = m_splitter->parentWidget()) {
if (QStackedLayout *layout = layoutForWidget(widget, m_splitter)) {
const int index = layout->indexOf(m_splitter);
layout->removeWidget(m_splitter);
m_mode->setWidget(new QWidget);
layout->insertWidget(index, m_mode->widget());
m_externalWindow->setCentralWidget(m_splitter);
m_splitter->show();
slotHideRightPane();
m_mode->setEnabled(false);
m_externalHelpBar->setVisible(true);
m_internalHelpBar->setVisible(false);
m_externalWindow->show();
connectExternalHelpWindow();
if (m_oldMode && m_mode == ModeManager::currentMode())
ModeManager::activateMode(m_oldMode->id());
}
}
} else if (modeWidget != m_splitter
&& contextHelpOption() != Help::Constants::ExternalHelpAlways) {
QStackedLayout *wLayout = layoutForWidget(modeWidget->parentWidget(),
modeWidget);
if (wLayout && m_splitter->parentWidget()->layout()) {
const int index = wLayout->indexOf(modeWidget);
QWidget *tmp = wLayout->widget(index);
wLayout->removeWidget(modeWidget);
delete tmp;
m_splitter->parentWidget()->layout()->removeWidget(m_splitter);
m_mode->setWidget(m_splitter);
wLayout->insertWidget(index, m_splitter);
m_mode->setEnabled(true);
m_externalWindow->close();
m_sideBar->setVisible(true);
m_internalHelpBar->setVisible(true);
m_externalHelpBar->setVisible(false);
}
}
}
void HelpPlugin::setupHelpEngineIfNeeded()
{
m_helpManager->setEngineNeedsUpdate();
@@ -732,6 +684,7 @@ void HelpPlugin::setupHelpEngineIfNeeded()
HelpViewer *HelpPlugin::viewerForContextMode()
{
// TODO this is a hack for opening examples
if (ModeManager::currentMode()->id() == Core::Constants::MODE_WELCOME)
ModeManager::activateMode(Core::Constants::MODE_EDIT);
@@ -755,7 +708,8 @@ HelpViewer *HelpPlugin::viewerForContextMode()
// side by side
showSideBySide = true;
} break;
case Help::Constants::ExternalHelpAlways:
return externalHelpViewer();
default: // help mode
break;
}
@@ -804,14 +758,6 @@ static QUrl findBestLink(const QMap<QString, QUrl> &links, QString *highlightId)
void HelpPlugin::activateContext()
{
createRightPaneContextViewer();
RightPanePlaceHolder *placeHolder = RightPanePlaceHolder::current();
if (placeHolder && qApp->focusWidget()
&& qApp->focusWidget() == m_rightPaneSideBarWidget->currentViewer()->focusWidget()) {
switchToHelpMode(m_rightPaneSideBarWidget->currentViewer()->source());
return;
}
if (ModeManager::currentMode() == m_mode)
return;
@@ -843,6 +789,7 @@ void HelpPlugin::activateContext()
viewer->scrollToAnchor(source.fragment());
}
viewer->setFocus();
Core::ICore::raiseWindow(viewer);
}
}
}
@@ -1083,29 +1030,6 @@ int HelpPlugin::contextHelpOption() const
Help::Constants::SideBySideIfPossible).toInt();
}
void HelpPlugin::connectExternalHelpWindow()
{
if (m_connectWindow) {
m_connectWindow = false;
connect(Core::ICore::instance(), SIGNAL(coreAboutToClose()),
m_externalWindow, SLOT(close()));
connect(m_externalWindow, SIGNAL(activateIndex()), this,
SLOT(activateIndex()));
connect(m_externalWindow, SIGNAL(activateContents()), this,
SLOT(activateContents()));
connect(m_externalWindow, SIGNAL(activateSearch()), this,
SLOT(activateSearch()));
connect(m_externalWindow, SIGNAL(activateBookmarks()), this,
SLOT(activateBookmarks()));
connect(m_externalWindow, SIGNAL(activateOpenPages()), this,
SLOT(activateOpenPages()));
connect(m_externalWindow, SIGNAL(addBookmark()), this,
SLOT(addBookmark()));
connect(m_externalWindow, SIGNAL(showHideSidebar()), this,
SLOT(showHideSidebar()));
}
}
void HelpPlugin::setupNavigationMenus(QAction *back, QAction *next, QWidget *parent)
{
if (!m_backMenu) {

View File

@@ -30,7 +30,11 @@
#ifndef HELPPLUGIN_H
#define HELPPLUGIN_H
#include "helpwidget.h"
#include <coreplugin/icontext.h>
#include <extensionsystem/iplugin.h>
#include <QMap>
#include <QStringList>
@@ -55,11 +59,9 @@ namespace Help {
namespace Internal {
class CentralWidget;
class DocSettingsPage;
class ExternalHelpWindow;
class FilterSettingsPage;
class GeneralSettingsPage;
class HelpMode;
class HelpWidget;
class HelpViewer;
class LocalHelpManager;
class OpenPagesManager;
@@ -84,7 +86,6 @@ public:
private slots:
void unregisterOldQtCreatorDocumentation();
void showExternalWindow();
void modeChanged(Core::IMode *mode, Core::IMode *old);
void activateContext();
@@ -98,6 +99,7 @@ private slots:
void updateFilterComboBox();
void filterDocumentation(const QString &customFilter);
void saveExternalWindowSettings();
void switchToHelpMode(const QUrl &source);
void slotHideRightPane();
void showHideSidebar();
@@ -106,7 +108,6 @@ private slots:
void updateSideBarSource(const QUrl &newUrl);
void fontChanged();
void contextHelpOptionChanged();
void updateCloseButton();
void setupHelpEngineIfNeeded();
@@ -128,11 +129,12 @@ private:
Utils::StyledBar *createWidgetToolBar();
Utils::StyledBar *createIconToolBar(bool external);
HelpViewer* viewerForContextMode();
HelpWidget *createHelpWidget(const Core::Context &context, HelpWidget::WidgetStyle style);
void createRightPaneContextViewer();
HelpViewer *externalHelpViewer();
void doSetupIfNeeded();
int contextHelpOption() const;
void connectExternalHelpWindow();
void setupNavigationMenus(QAction *back, QAction *next, QWidget *parent);
private:
@@ -163,9 +165,8 @@ private:
QString m_contextHelpHighlightId;
Core::IMode* m_oldMode;
bool m_connectWindow;
ExternalHelpWindow *m_externalWindow;
QPointer<HelpWidget> m_externalWindow;
QRect m_externalWindowState;
QMenu *m_backMenu;
QMenu *m_nextMenu;

View File

@@ -29,6 +29,7 @@
#include "helpwidget.h"
#include "helpconstants.h"
#include "helpplugin.h"
#include "helpviewer.h"
@@ -38,6 +39,7 @@
#include <coreplugin/icore.h>
#include <coreplugin/findplaceholder.h>
#include <texteditor/texteditorconstants.h>
#include <utils/qtcassert.h>
#include <utils/styledbar.h>
#include <QHBoxLayout>
@@ -55,8 +57,11 @@ static QToolButton *toolButton(QAction *action)
namespace Help {
namespace Internal {
HelpWidget::HelpWidget(const Core::Context &context, QWidget *parent) :
QWidget(parent)
HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget *parent) :
QWidget(parent),
m_scaleUp(0),
m_scaleDown(0),
m_resetScale(0)
{
Utils::StyledBar *toolBar = new Utils::StyledBar();
@@ -74,10 +79,6 @@ HelpWidget::HelpWidget(const Core::Context &context, QWidget *parent) :
connect(m_forwardMenu, SIGNAL(aboutToShow()), this, SLOT(updateForwardMenu()));
forward->setMenu(m_forwardMenu);
QAction *close = new QAction(QIcon(QLatin1String(Core::Constants::ICON_CLOSE_DOCUMENT)),
QString(), toolBar);
connect(close, SIGNAL(triggered()), this, SIGNAL(close()));
QHBoxLayout *layout = new QHBoxLayout(toolBar);
layout->setSpacing(0);
layout->setMargin(0);
@@ -86,10 +87,8 @@ HelpWidget::HelpWidget(const Core::Context &context, QWidget *parent) :
layout->addWidget(toolButton(back));
layout->addWidget(toolButton(forward));
layout->addStretch();
layout->addWidget(toolButton(close));
m_viewer = HelpPlugin::createHelpViewer(qreal(0.0));
m_viewer->setOpenInNewWindowActionVisible(false);
QVBoxLayout *vLayout = new QVBoxLayout(this);
vLayout->setMargin(0);
@@ -106,10 +105,6 @@ HelpWidget::HelpWidget(const Core::Context &context, QWidget *parent) :
icontext->setWidget(m_viewer);
Core::ICore::addContextObject(icontext);
QAction *copy = new QAction(this);
Core::Command *cmd = Core::ActionManager::registerAction(copy, Core::Constants::COPY, context);
connect(copy, SIGNAL(triggered()), m_viewer, SLOT(copy()));
back->setEnabled(m_viewer->isBackwardAvailable());
connect(back, SIGNAL(triggered()), m_viewer, SLOT(backward()));
connect(m_viewer, SIGNAL(backwardAvailable(bool)), back,
@@ -120,26 +115,64 @@ HelpWidget::HelpWidget(const Core::Context &context, QWidget *parent) :
connect(m_viewer, SIGNAL(forwardAvailable(bool)), forward,
SLOT(setEnabled(bool)));
if (Core::ActionContainer *advancedMenu = Core::ActionManager::actionContainer(Core::Constants::M_EDIT_ADVANCED)) {
m_copy = new QAction(this);
Core::Command *cmd = Core::ActionManager::registerAction(m_copy, Core::Constants::COPY, context);
connect(m_copy, SIGNAL(triggered()), m_viewer, SLOT(copy()));
m_openHelpMode = new QAction(this);
cmd = Core::ActionManager::registerAction(m_openHelpMode,
Help::Constants::CONTEXT_HELP,
context);
connect(m_openHelpMode, SIGNAL(triggered()), this, SLOT(emitOpenHelpMode()));
Core::ActionContainer *advancedMenu = Core::ActionManager::actionContainer(Core::Constants::M_EDIT_ADVANCED);
QTC_CHECK(advancedMenu);
if (advancedMenu) {
// reuse TextEditor constants to avoid a second pair of menu actions
QAction *action = new QAction(tr("Increase Font Size"), this);
cmd = Core::ActionManager::registerAction(action, TextEditor::Constants::INCREASE_FONT_SIZE,
m_scaleUp = new QAction(tr("Increase Font Size"), this);
cmd = Core::ActionManager::registerAction(m_scaleUp, TextEditor::Constants::INCREASE_FONT_SIZE,
context);
connect(action, SIGNAL(triggered()), m_viewer, SLOT(scaleUp()));
connect(m_scaleUp, SIGNAL(triggered()), m_viewer, SLOT(scaleUp()));
advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT);
action = new QAction(tr("Decrease Font Size"), this);
cmd = Core::ActionManager::registerAction(action, TextEditor::Constants::DECREASE_FONT_SIZE,
m_scaleDown = new QAction(tr("Decrease Font Size"), this);
cmd = Core::ActionManager::registerAction(m_scaleDown, TextEditor::Constants::DECREASE_FONT_SIZE,
context);
connect(action, SIGNAL(triggered()), m_viewer, SLOT(scaleDown()));
connect(m_scaleDown, SIGNAL(triggered()), m_viewer, SLOT(scaleDown()));
advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT);
action = new QAction(tr("Reset Font Size"), this);
cmd = Core::ActionManager::registerAction(action, TextEditor::Constants::RESET_FONT_SIZE,
m_resetScale = new QAction(tr("Reset Font Size"), this);
cmd = Core::ActionManager::registerAction(m_resetScale, TextEditor::Constants::RESET_FONT_SIZE,
context);
connect(action, SIGNAL(triggered()), m_viewer, SLOT(resetScale()));
connect(m_resetScale, SIGNAL(triggered()), m_viewer, SLOT(resetScale()));
advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT);
}
if (style == SideBarWidget) {
QAction *close = new QAction(QIcon(QLatin1String(Core::Constants::ICON_CLOSE_DOCUMENT)),
QString(), toolBar);
connect(close, SIGNAL(triggered()), this, SIGNAL(closeButtonClicked()));
layout->addWidget(toolButton(close));
m_viewer->setOpenInNewWindowActionVisible(false);
} else if (style == ExternalWindow) {
setAttribute(Qt::WA_DeleteOnClose);
setAttribute(Qt::WA_QuitOnClose, false); // don't prevent Qt Creator from closing
connect(m_viewer, SIGNAL(titleChanged()), this, SLOT(updateWindowTitle()));
updateWindowTitle();
m_viewer->setOpenInNewWindowActionVisible(false);
}
}
HelpWidget::~HelpWidget()
{
Core::ActionManager::unregisterAction(m_copy, Core::Constants::COPY);
Core::ActionManager::unregisterAction(m_openHelpMode, Help::Constants::CONTEXT_HELP);
if (m_scaleUp)
Core::ActionManager::unregisterAction(m_scaleUp, TextEditor::Constants::INCREASE_FONT_SIZE);
if (m_scaleDown)
Core::ActionManager::unregisterAction(m_scaleDown, TextEditor::Constants::DECREASE_FONT_SIZE);
if (m_resetScale)
Core::ActionManager::unregisterAction(m_resetScale, TextEditor::Constants::RESET_FONT_SIZE);
}
HelpViewer *HelpWidget::currentViewer() const
@@ -147,6 +180,11 @@ HelpViewer *HelpWidget::currentViewer() const
return m_viewer;
}
void HelpWidget::closeEvent(QCloseEvent *)
{
emit aboutToClose();
}
void HelpWidget::updateBackMenu()
{
m_backMenu->clear();
@@ -159,6 +197,15 @@ void HelpWidget::updateForwardMenu()
m_viewer->addForwardHistoryItems(m_forwardMenu);
}
void HelpWidget::updateWindowTitle()
{
const QString pageTitle = m_viewer->title();
if (pageTitle.isEmpty())
setWindowTitle(tr("Help"));
else
setWindowTitle(tr("Help - %1").arg(pageTitle));
}
void HelpWidget::emitOpenHelpMode()
{
emit openHelpMode(m_viewer->source());

View File

@@ -36,6 +36,7 @@
#include <QWidget>
QT_BEGIN_NAMESPACE
class QAction;
class QMenu;
QT_END_NAMESPACE
@@ -48,22 +49,38 @@ class HelpWidget : public QWidget
{
Q_OBJECT
public:
explicit HelpWidget(const Core::Context &context, QWidget *parent = 0);
enum WidgetStyle {
SideBarWidget,
ExternalWindow
};
HelpWidget(const Core::Context &context, WidgetStyle style, QWidget *parent = 0);
~HelpWidget();
HelpViewer *currentViewer() const;
protected:
void closeEvent(QCloseEvent *);
signals:
void openHelpMode(const QUrl &url);
void close();
void closeButtonClicked();
void aboutToClose();
private slots:
void updateBackMenu();
void updateForwardMenu();
void updateWindowTitle();
void emitOpenHelpMode();
private:
QMenu *m_backMenu;
QMenu *m_forwardMenu;
QAction *m_openHelpMode;
QAction *m_scaleUp;
QAction *m_scaleDown;
QAction *m_resetScale;
QAction *m_copy;
HelpViewer *m_viewer;
};