diff options
author | Eike Ziller <eike.ziller@theqtcompany.com> | 2014-10-10 11:01:21 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@theqtcompany.com> | 2014-10-13 11:23:52 +0200 |
commit | 9e74d06402854d79c92c16e6d10b2d9a03faeae7 (patch) | |
tree | a5195ee6cf126c05b34b7e2d360d43ccc120e09f | |
parent | 2735ff4068f0a72233b2a837d4bed0ec726b5371 (diff) |
Help Window: Add contents view to side bar
Change-Id: Id690c71471ed9a61bd7a926db70e1b1fb9fac8ab
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
-rw-r--r-- | src/plugins/help/helpwidget.cpp | 20 | ||||
-rw-r--r-- | src/plugins/help/helpwidget.h | 1 | ||||
-rw-r--r-- | src/shared/help/contentwindow.cpp | 20 | ||||
-rw-r--r-- | src/shared/help/contentwindow.h | 3 |
4 files changed, 34 insertions, 10 deletions
diff --git a/src/plugins/help/helpwidget.cpp b/src/plugins/help/helpwidget.cpp index b87dacae31..e4a102995f 100644 --- a/src/plugins/help/helpwidget.cpp +++ b/src/plugins/help/helpwidget.cpp @@ -30,6 +30,7 @@ #include "helpwidget.h" #include "bookmarkmanager.h" +#include "contentwindow.h" #include "helpconstants.h" #include "helpplugin.h" #include "helpviewer.h" @@ -256,6 +257,7 @@ HelpWidget::~HelpWidget() { if (m_sideBar) { m_sideBar->saveSettings(Core::ICore::settings(), QLatin1String(kSideBarSettingsKey)); + Core::ActionManager::unregisterAction(m_contentsAction, Constants::HELP_CONTENTS); Core::ActionManager::unregisterAction(m_indexAction, Constants::HELP_INDEX); Core::ActionManager::unregisterAction(m_bookmarkAction, Constants::HELP_BOOKMARKS); } @@ -283,6 +285,18 @@ void HelpWidget::addSideBar() QMap<QString, Core::Command *> shortcutMap; Core::Command *cmd; + auto contentWindow = new ContentWindow; + auto contentItem = new Core::SideBarItem(contentWindow, QLatin1String(Constants::HELP_CONTENTS)); + contentWindow->setOpenInNewPageActionVisible(false); + contentWindow->setWindowTitle(tr(Constants::SB_CONTENTS)); + connect(contentWindow, &ContentWindow::linkActivated, + this, &HelpWidget::open); + m_contentsAction = new QAction(tr("Activate Help Contents View"), this); + cmd = Core::ActionManager::registerAction(m_contentsAction, Constants::HELP_CONTENTS, m_context->context()); + cmd->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+Shift+C") + : tr("Ctrl+Shift+C"))); + shortcutMap.insert(QLatin1String(Constants::HELP_CONTENTS), cmd); + auto indexWindow = new IndexWindow(); auto indexItem = new Core::SideBarItem(indexWindow, QLatin1String(Constants::HELP_INDEX)); indexWindow->setOpenInNewPageActionVisible(false); @@ -311,14 +325,16 @@ void HelpWidget::addSideBar() shortcutMap.insert(QLatin1String(Constants::HELP_BOOKMARKS), cmd); QList<Core::SideBarItem *> itemList; - itemList << indexItem << bookmarkItem; - m_sideBar = new Core::SideBar(itemList, QList<Core::SideBarItem *>() << indexItem); + itemList << contentItem << indexItem << bookmarkItem; + m_sideBar = new Core::SideBar(itemList, + QList<Core::SideBarItem *>() << contentItem << indexItem); m_sideBar->setShortcutMap(shortcutMap); m_sideBar->setCloseWhenEmpty(true); m_sideBarSplitter->insertWidget(0, m_sideBar); m_sideBarSplitter->setStretchFactor(0, 0); m_sideBarSplitter->setStretchFactor(1, 1); m_sideBar->setVisible(false); + m_sideBar->resize(250, size().height()); m_sideBar->readSettings(Core::ICore::settings(), QLatin1String(kSideBarSettingsKey)); m_sideBarSplitter->setSizes(QList<int>() << m_sideBar->size().width() << 300); m_toggleSideBarAction->setChecked(m_sideBar->isVisibleTo(this)); diff --git a/src/plugins/help/helpwidget.h b/src/plugins/help/helpwidget.h index 428202afc2..8942fa9727 100644 --- a/src/plugins/help/helpwidget.h +++ b/src/plugins/help/helpwidget.h @@ -140,6 +140,7 @@ private: Core::MiniSplitter *m_sideBarSplitter; Core::SideBar *m_sideBar; + QAction *m_contentsAction; QAction *m_indexAction; QAction *m_bookmarkAction; }; diff --git a/src/shared/help/contentwindow.cpp b/src/shared/help/contentwindow.cpp index 13cf0907a9..04a49bedcb 100644 --- a/src/shared/help/contentwindow.cpp +++ b/src/shared/help/contentwindow.cpp @@ -48,6 +48,7 @@ using namespace Help::Internal; ContentWindow::ContentWindow() : m_contentWidget(0) , m_expandDepth(-2) + , m_isOpenInNewPageActionVisible(true) { m_contentModel = (&LocalHelpManager::helpEngine())->contentModel(); m_contentWidget = new Utils::NavigationTreeView; @@ -75,6 +76,11 @@ ContentWindow::~ContentWindow() { } +void ContentWindow::setOpenInNewPageActionVisible(bool visible) +{ + m_isOpenInNewPageActionVisible = visible; +} + void ContentWindow::expandTOC() { if (m_expandDepth > -2) { @@ -94,7 +100,7 @@ void ContentWindow::expandToDepth(int depth) bool ContentWindow::eventFilter(QObject *o, QEvent *e) { - if (m_contentWidget && o == m_contentWidget->viewport() + if (m_isOpenInNewPageActionVisible && m_contentWidget && o == m_contentWidget->viewport() && e->type() == QEvent::MouseButtonRelease) { QMouseEvent *me = static_cast<QMouseEvent*>(e); QItemSelectionModel *sm = m_contentWidget->selectionModel(); @@ -128,16 +134,14 @@ void ContentWindow::showContextMenu(const QPoint &pos) QMenu menu; QAction *curTab = menu.addAction(tr("Open Link")); - QAction *newTab = menu.addAction(tr("Open Link as New Page")); - if (!HelpViewer::canOpenPage(itm->url().path())) - newTab->setEnabled(false); - - menu.move(m_contentWidget->mapToGlobal(pos)); + QAction *newTab = 0; + if (m_isOpenInNewPageActionVisible) + newTab = menu.addAction(tr("Open Link as New Page")); - QAction *action = menu.exec(); + QAction *action = menu.exec(m_contentWidget->mapToGlobal(pos)); if (curTab == action) emit linkActivated(itm->url(), false/*newPage*/); - else if (newTab == action) + else if (newTab && newTab == action) emit linkActivated(itm->url(), true/*newPage*/); } diff --git a/src/shared/help/contentwindow.h b/src/shared/help/contentwindow.h index ee05415729..eb645ae463 100644 --- a/src/shared/help/contentwindow.h +++ b/src/shared/help/contentwindow.h @@ -53,6 +53,8 @@ public: ContentWindow(); ~ContentWindow(); + void setOpenInNewPageActionVisible(bool visible); + signals: void linkActivated(const QUrl &link, bool newPage); @@ -66,6 +68,7 @@ private: Utils::NavigationTreeView *m_contentWidget; QHelpContentModel *m_contentModel; int m_expandDepth; + bool m_isOpenInNewPageActionVisible; }; #endif // CONTENTWINDOW_H |