forked from qt-creator/qt-creator
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:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user