aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/help/helpwidget.cpp
diff options
context:
space:
mode:
authorEike Ziller <[email protected]>2014-06-17 18:14:37 +0200
committerEike Ziller <[email protected]>2014-06-20 14:01:18 +0200
commitb2a2a893581433ac06ef29569aba491a7db92e90 (patch)
tree601e15d209709f76fc10b830063a699993876636 /src/plugins/help/helpwidget.cpp
parent5ee81929acf77428d817c6b808034660389c9273 (diff)
Help: Create separate help widget class
That contains the tool bar together with a help viewer, which can also be used for an external help window, and later be extended to also replace the extra "central widget". Change-Id: I73fac4c135b985cbe47062b90783f156b5062005 Reviewed-by: Karsten Heimrich <[email protected]>
Diffstat (limited to 'src/plugins/help/helpwidget.cpp')
-rw-r--r--src/plugins/help/helpwidget.cpp168
1 files changed, 168 insertions, 0 deletions
diff --git a/src/plugins/help/helpwidget.cpp b/src/plugins/help/helpwidget.cpp
new file mode 100644
index 00000000000..652b5f06528
--- /dev/null
+++ b/src/plugins/help/helpwidget.cpp
@@ -0,0 +1,168 @@
+/****************************************************************************
+**
+** 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"
+
+#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>
+#include <utils/styledbar.h>
+
+#include <QHBoxLayout>
+#include <QMenu>
+#include <QToolButton>
+
+static QToolButton *toolButton(QAction *action)
+{
+ QToolButton *button = new QToolButton;
+ button->setDefaultAction(action);
+ button->setPopupMode(QToolButton::DelayedPopup);
+ return button;
+}
+
+namespace Help {
+namespace Internal {
+
+HelpWidget::HelpWidget(const Core::Context &context, QWidget *parent) :
+ QWidget(parent)
+{
+ Utils::StyledBar *toolBar = new Utils::StyledBar();
+
+ QAction *switchToHelp = new QAction(tr("Go to Help Mode"), toolBar);
+ connect(switchToHelp, SIGNAL(triggered()), this, SLOT(emitOpenHelpMode()));
+
+ QAction *back = new QAction(QIcon(QLatin1String(":/help/images/previous.png")),
+ tr("Back"), toolBar);
+ m_backMenu = new QMenu(toolBar);
+ connect(m_backMenu, SIGNAL(aboutToShow()), this, SLOT(updateBackMenu()));
+ back->setMenu(m_backMenu);
+ QAction *forward = new QAction(QIcon(QLatin1String(":/help/images/next.png")),
+ tr("Forward"), toolBar);
+ m_forwardMenu = new QMenu(toolBar);
+ 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);
+
+ layout->addWidget(toolButton(switchToHelp));
+ 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);
+ vLayout->setSpacing(0);
+ vLayout->addWidget(toolBar);
+ vLayout->addWidget(m_viewer);
+ Core::FindToolBarPlaceHolder *fth = new Core::FindToolBarPlaceHolder(this);
+ vLayout->addWidget(fth);
+
+ setFocusProxy(m_viewer);
+
+ Core::IContext *icontext = new Core::IContext(this);
+ icontext->setContext(context);
+ 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,
+ SLOT(setEnabled(bool)));
+
+ forward->setEnabled(m_viewer->isForwardAvailable());
+ connect(forward, SIGNAL(triggered()), m_viewer, SLOT(forward()));
+ connect(m_viewer, SIGNAL(forwardAvailable(bool)), forward,
+ SLOT(setEnabled(bool)));
+
+ if (Core::ActionContainer *advancedMenu = Core::ActionManager::actionContainer(Core::Constants::M_EDIT_ADVANCED)) {
+ // 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,
+ context);
+ connect(action, 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,
+ context);
+ connect(action, 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,
+ context);
+ connect(action, SIGNAL(triggered()), m_viewer, SLOT(resetScale()));
+ advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT);
+ }
+}
+
+HelpViewer *HelpWidget::currentViewer() const
+{
+ return m_viewer;
+}
+
+void HelpWidget::updateBackMenu()
+{
+ m_backMenu->clear();
+ m_viewer->addBackHistoryItems(m_backMenu);
+}
+
+void HelpWidget::updateForwardMenu()
+{
+ m_forwardMenu->clear();
+ m_viewer->addForwardHistoryItems(m_forwardMenu);
+}
+
+void HelpWidget::emitOpenHelpMode()
+{
+ emit openHelpMode(m_viewer->source());
+}
+
+} // Internal
+} // Help