2014-06-17 18:14:37 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** 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 "helpwidget.h"
|
|
|
|
|
|
2014-06-18 17:42:01 +02:00
|
|
|
#include "helpconstants.h"
|
2014-06-17 18:14:37 +02:00
|
|
|
#include "helpplugin.h"
|
|
|
|
|
#include "helpviewer.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/findplaceholder.h>
|
|
|
|
|
#include <texteditor/texteditorconstants.h>
|
2014-06-18 17:42:01 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2014-06-17 18:14:37 +02:00
|
|
|
#include <utils/styledbar.h>
|
|
|
|
|
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QToolButton>
|
|
|
|
|
|
2014-09-23 19:16:17 +02:00
|
|
|
static QToolButton *toolButton(QAction *action, Core::Command *cmd = 0)
|
2014-06-17 18:14:37 +02:00
|
|
|
{
|
|
|
|
|
QToolButton *button = new QToolButton;
|
|
|
|
|
button->setDefaultAction(action);
|
|
|
|
|
button->setPopupMode(QToolButton::DelayedPopup);
|
2014-09-23 19:16:17 +02:00
|
|
|
if (cmd) {
|
|
|
|
|
action->setToolTip(cmd->stringWithAppendedShortcut(action->text()));
|
|
|
|
|
QObject::connect(cmd, &Core::Command::keySequenceChanged, action, [cmd, action]() {
|
|
|
|
|
action->setToolTip(cmd->stringWithAppendedShortcut(action->text()));
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-06-17 18:14:37 +02:00
|
|
|
return button;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace Help {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2014-06-18 17:42:01 +02:00
|
|
|
HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget *parent) :
|
|
|
|
|
QWidget(parent),
|
|
|
|
|
m_scaleUp(0),
|
|
|
|
|
m_scaleDown(0),
|
2014-06-23 12:30:54 +02:00
|
|
|
m_resetScale(0),
|
|
|
|
|
m_style(style)
|
2014-06-17 18:14:37 +02:00
|
|
|
{
|
|
|
|
|
Utils::StyledBar *toolBar = new Utils::StyledBar();
|
2014-09-23 19:16:17 +02:00
|
|
|
QHBoxLayout *layout = new QHBoxLayout(toolBar);
|
|
|
|
|
layout->setSpacing(0);
|
|
|
|
|
layout->setMargin(0);
|
|
|
|
|
Core::Command *cmd;
|
2014-06-17 18:14:37 +02:00
|
|
|
|
2014-07-01 10:33:20 +02:00
|
|
|
m_switchToHelp = new QAction(tr("Go to Help Mode"), toolBar);
|
2014-09-23 19:16:17 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(m_switchToHelp, Constants::CONTEXT_HELP, context);
|
2014-07-01 10:33:20 +02:00
|
|
|
connect(m_switchToHelp, SIGNAL(triggered()), this, SLOT(helpModeButtonClicked()));
|
2014-09-23 19:16:17 +02:00
|
|
|
layout->addWidget(toolButton(m_switchToHelp, cmd));
|
2014-06-17 18:14:37 +02:00
|
|
|
|
2014-09-23 19:16:17 +02:00
|
|
|
m_backAction = new QAction(QIcon(QLatin1String(":/help/images/previous.png")),
|
2014-06-17 18:14:37 +02:00
|
|
|
tr("Back"), toolBar);
|
|
|
|
|
m_backMenu = new QMenu(toolBar);
|
|
|
|
|
connect(m_backMenu, SIGNAL(aboutToShow()), this, SLOT(updateBackMenu()));
|
2014-09-23 19:16:17 +02:00
|
|
|
m_backAction->setMenu(m_backMenu);
|
|
|
|
|
cmd = Core::ActionManager::registerAction(m_backAction, Constants::HELP_PREVIOUS, context);
|
|
|
|
|
cmd->setDefaultKeySequence(QKeySequence::Back);
|
|
|
|
|
layout->addWidget(toolButton(m_backAction, cmd));
|
|
|
|
|
|
|
|
|
|
m_forwardAction = new QAction(QIcon(QLatin1String(":/help/images/next.png")),
|
2014-06-17 18:14:37 +02:00
|
|
|
tr("Forward"), toolBar);
|
|
|
|
|
m_forwardMenu = new QMenu(toolBar);
|
|
|
|
|
connect(m_forwardMenu, SIGNAL(aboutToShow()), this, SLOT(updateForwardMenu()));
|
2014-09-23 19:16:17 +02:00
|
|
|
m_forwardAction->setMenu(m_forwardMenu);
|
|
|
|
|
cmd = Core::ActionManager::registerAction(m_forwardAction, Constants::HELP_NEXT, context);
|
|
|
|
|
cmd->setDefaultKeySequence(QKeySequence::Forward);
|
|
|
|
|
layout->addWidget(toolButton(m_forwardAction, cmd));
|
2014-06-17 18:14:37 +02:00
|
|
|
|
|
|
|
|
layout->addStretch();
|
|
|
|
|
|
|
|
|
|
m_viewer = HelpPlugin::createHelpViewer(qreal(0.0));
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *vLayout = new QVBoxLayout(this);
|
|
|
|
|
vLayout->setMargin(0);
|
|
|
|
|
vLayout->setSpacing(0);
|
|
|
|
|
vLayout->addWidget(toolBar);
|
|
|
|
|
vLayout->addWidget(m_viewer);
|
|
|
|
|
Core::FindToolBarPlaceHolder *fth = new Core::FindToolBarPlaceHolder(this);
|
|
|
|
|
vLayout->addWidget(fth);
|
|
|
|
|
|
|
|
|
|
setFocusProxy(m_viewer);
|
|
|
|
|
|
2014-07-24 14:48:36 +02:00
|
|
|
m_context = new Core::IContext(this);
|
|
|
|
|
m_context->setContext(context);
|
|
|
|
|
m_context->setWidget(m_viewer);
|
|
|
|
|
Core::ICore::addContextObject(m_context);
|
2014-06-17 18:14:37 +02:00
|
|
|
|
2014-09-23 19:16:17 +02:00
|
|
|
m_backAction->setEnabled(m_viewer->isBackwardAvailable());
|
|
|
|
|
connect(m_backAction, SIGNAL(triggered()), m_viewer, SLOT(backward()));
|
|
|
|
|
connect(m_viewer, SIGNAL(backwardAvailable(bool)), m_backAction,
|
2014-06-17 18:14:37 +02:00
|
|
|
SLOT(setEnabled(bool)));
|
|
|
|
|
|
2014-09-23 19:16:17 +02:00
|
|
|
m_forwardAction->setEnabled(m_viewer->isForwardAvailable());
|
|
|
|
|
connect(m_forwardAction, SIGNAL(triggered()), m_viewer, SLOT(forward()));
|
|
|
|
|
connect(m_viewer, SIGNAL(forwardAvailable(bool)), m_forwardAction,
|
2014-06-17 18:14:37 +02:00
|
|
|
SLOT(setEnabled(bool)));
|
|
|
|
|
|
2014-06-18 17:42:01 +02:00
|
|
|
m_copy = new QAction(this);
|
2014-09-10 12:18:28 +02:00
|
|
|
Core::ActionManager::registerAction(m_copy, Core::Constants::COPY, context);
|
2014-06-18 17:42:01 +02:00
|
|
|
connect(m_copy, SIGNAL(triggered()), m_viewer, SLOT(copy()));
|
|
|
|
|
|
|
|
|
|
Core::ActionContainer *advancedMenu = Core::ActionManager::actionContainer(Core::Constants::M_EDIT_ADVANCED);
|
|
|
|
|
QTC_CHECK(advancedMenu);
|
|
|
|
|
if (advancedMenu) {
|
2014-06-17 18:14:37 +02:00
|
|
|
// reuse TextEditor constants to avoid a second pair of menu actions
|
2014-06-18 17:42:01 +02:00
|
|
|
m_scaleUp = new QAction(tr("Increase Font Size"), this);
|
|
|
|
|
cmd = Core::ActionManager::registerAction(m_scaleUp, TextEditor::Constants::INCREASE_FONT_SIZE,
|
2014-06-17 18:14:37 +02:00
|
|
|
context);
|
2014-06-18 17:42:01 +02:00
|
|
|
connect(m_scaleUp, SIGNAL(triggered()), m_viewer, SLOT(scaleUp()));
|
2014-06-17 18:14:37 +02:00
|
|
|
advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT);
|
|
|
|
|
|
2014-06-18 17:42:01 +02:00
|
|
|
m_scaleDown = new QAction(tr("Decrease Font Size"), this);
|
|
|
|
|
cmd = Core::ActionManager::registerAction(m_scaleDown, TextEditor::Constants::DECREASE_FONT_SIZE,
|
2014-06-17 18:14:37 +02:00
|
|
|
context);
|
2014-06-18 17:42:01 +02:00
|
|
|
connect(m_scaleDown, SIGNAL(triggered()), m_viewer, SLOT(scaleDown()));
|
2014-06-17 18:14:37 +02:00
|
|
|
advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT);
|
|
|
|
|
|
2014-06-18 17:42:01 +02:00
|
|
|
m_resetScale = new QAction(tr("Reset Font Size"), this);
|
|
|
|
|
cmd = Core::ActionManager::registerAction(m_resetScale, TextEditor::Constants::RESET_FONT_SIZE,
|
2014-06-17 18:14:37 +02:00
|
|
|
context);
|
2014-06-18 17:42:01 +02:00
|
|
|
connect(m_resetScale, SIGNAL(triggered()), m_viewer, SLOT(resetScale()));
|
2014-06-17 18:14:37 +02:00
|
|
|
advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT);
|
|
|
|
|
}
|
2014-06-18 17:42:01 +02:00
|
|
|
|
|
|
|
|
if (style == SideBarWidget) {
|
2014-08-01 15:14:15 +02:00
|
|
|
QAction *close = new QAction(QIcon(QLatin1String(Core::Constants::ICON_BUTTON_CLOSE)),
|
2014-06-18 17:42:01 +02:00
|
|
|
QString(), toolBar);
|
|
|
|
|
connect(close, SIGNAL(triggered()), this, SIGNAL(closeButtonClicked()));
|
|
|
|
|
layout->addWidget(toolButton(close));
|
2014-09-23 17:10:26 +02:00
|
|
|
m_viewer->setOpenInNewPageActionVisible(false);
|
2014-06-18 17:42:01 +02:00
|
|
|
} else if (style == ExternalWindow) {
|
2014-07-17 17:35:20 +02:00
|
|
|
static int windowId = 0;
|
|
|
|
|
Core::ICore::registerWindow(this,
|
|
|
|
|
Core::Context(Core::Id("Help.Window.").withSuffix(++windowId)));
|
2014-06-18 17:42:01 +02:00
|
|
|
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();
|
2014-09-23 17:10:26 +02:00
|
|
|
m_viewer->setOpenInNewPageActionVisible(false);
|
2014-06-18 17:42:01 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HelpWidget::~HelpWidget()
|
|
|
|
|
{
|
2014-07-24 14:48:36 +02:00
|
|
|
Core::ICore::removeContextObject(m_context);
|
2014-06-18 17:42:01 +02:00
|
|
|
Core::ActionManager::unregisterAction(m_copy, Core::Constants::COPY);
|
2014-09-23 19:16:17 +02:00
|
|
|
Core::ActionManager::unregisterAction(m_switchToHelp, Constants::CONTEXT_HELP);
|
|
|
|
|
Core::ActionManager::unregisterAction(m_forwardAction, Constants::HELP_NEXT);
|
|
|
|
|
Core::ActionManager::unregisterAction(m_backAction, Constants::HELP_PREVIOUS);
|
2014-06-18 17:42:01 +02:00
|
|
|
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);
|
2014-06-17 18:14:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HelpViewer *HelpWidget::currentViewer() const
|
|
|
|
|
{
|
|
|
|
|
return m_viewer;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-18 17:42:01 +02:00
|
|
|
void HelpWidget::closeEvent(QCloseEvent *)
|
|
|
|
|
{
|
|
|
|
|
emit aboutToClose();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-17 18:14:37 +02:00
|
|
|
void HelpWidget::updateBackMenu()
|
|
|
|
|
{
|
|
|
|
|
m_backMenu->clear();
|
|
|
|
|
m_viewer->addBackHistoryItems(m_backMenu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HelpWidget::updateForwardMenu()
|
|
|
|
|
{
|
|
|
|
|
m_forwardMenu->clear();
|
|
|
|
|
m_viewer->addForwardHistoryItems(m_forwardMenu);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-18 17:42:01 +02:00
|
|
|
void HelpWidget::updateWindowTitle()
|
|
|
|
|
{
|
|
|
|
|
const QString pageTitle = m_viewer->title();
|
|
|
|
|
if (pageTitle.isEmpty())
|
|
|
|
|
setWindowTitle(tr("Help"));
|
|
|
|
|
else
|
|
|
|
|
setWindowTitle(tr("Help - %1").arg(pageTitle));
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-23 12:30:54 +02:00
|
|
|
void HelpWidget::helpModeButtonClicked()
|
2014-06-17 18:14:37 +02:00
|
|
|
{
|
|
|
|
|
emit openHelpMode(m_viewer->source());
|
2014-06-23 12:30:54 +02:00
|
|
|
if (m_style == ExternalWindow)
|
|
|
|
|
close();
|
2014-06-17 18:14:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // Internal
|
|
|
|
|
} // Help
|