Help: Make it possible to duplicate search view

Change-Id: I6fac9f721fc3e2f877d9f600f9dea6650558516a
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
Eike Ziller
2014-10-10 15:32:46 +02:00
parent d7105cc245
commit 002093828a
5 changed files with 24 additions and 18 deletions

View File

@@ -315,8 +315,8 @@ void HelpPlugin::setupUi()
shortcutMap.insert(QLatin1String(Constants::HELP_CONTENTS), cmd); shortcutMap.insert(QLatin1String(Constants::HELP_CONTENTS), cmd);
auto searchItem = new SearchSideBarItem; auto searchItem = new SearchSideBarItem;
connect(searchItem, SIGNAL(linkActivated(QUrl)), m_centralWidget, connect(searchItem, &SearchSideBarItem::linkActivated,
SLOT(setSourceFromSearch(QUrl))); m_centralWidget, &HelpWidget::openFromSearch);
action = new QAction(tr("Activate Help Search View"), m_splitter); action = new QAction(tr("Activate Help Search View"), m_splitter);
cmd = ActionManager::registerAction(action, Constants::HELP_SEARCH, modecontext); cmd = ActionManager::registerAction(action, Constants::HELP_SEARCH, modecontext);

View File

@@ -453,13 +453,17 @@ void HelpWidget::setSource(const QUrl &url)
viewer->setFocus(Qt::OtherFocusReason); viewer->setFocus(Qt::OtherFocusReason);
} }
void HelpWidget::setSourceFromSearch(const QUrl &url) void HelpWidget::openFromSearch(const QUrl &url, bool newPage)
{ {
if (newPage)
OpenPagesManager::instance().createPageFromSearch(url);
else {
HelpViewer* viewer = currentViewer(); HelpViewer* viewer = currentViewer();
QTC_ASSERT(viewer, return); QTC_ASSERT(viewer, return);
connect(viewer, &HelpViewer::loadFinished, this, &HelpWidget::highlightSearchTerms); connect(viewer, &HelpViewer::loadFinished, this, &HelpWidget::highlightSearchTerms);
viewer->setSource(url); viewer->setSource(url);
viewer->setFocus(Qt::OtherFocusReason); viewer->setFocus(Qt::OtherFocusReason);
}
} }
void HelpWidget::closeEvent(QCloseEvent *) void HelpWidget::closeEvent(QCloseEvent *)

View File

@@ -81,12 +81,12 @@ public:
HelpViewer *viewerAt(int index) const; HelpViewer *viewerAt(int index) const;
void open(const QUrl &url, bool newPage = false); void open(const QUrl &url, bool newPage = false);
void openFromSearch(const QUrl &url, bool newPage = false);
void showTopicChooser(const QMap<QString, QUrl> &links, const QString &key, void showTopicChooser(const QMap<QString, QUrl> &links, const QString &key,
bool newPage = false); bool newPage = false);
public slots: public slots:
void setSource(const QUrl &url); void setSource(const QUrl &url);
void setSourceFromSearch(const QUrl &url);
void updateCloseButton(); void updateCloseButton();
protected: protected:

View File

@@ -104,7 +104,7 @@ void SearchWidget::showEvent(QShowEvent *event)
vLayout->setMargin(0); vLayout->setMargin(0);
vLayout->setSpacing(0); vLayout->setSpacing(0);
searchEngine = (&LocalHelpManager::helpEngine())->searchEngine(); searchEngine = new QHelpSearchEngine(&LocalHelpManager::helpEngine(), this);
Utils::StyledBar *toolbar = new Utils::StyledBar(this); Utils::StyledBar *toolbar = new Utils::StyledBar(this);
toolbar->setSingleRow(false); toolbar->setSingleRow(false);
@@ -129,8 +129,10 @@ void SearchWidget::showEvent(QShowEvent *event)
setFocusProxy(queryWidget); setFocusProxy(queryWidget);
connect(queryWidget, SIGNAL(search()), this, SLOT(search())); connect(queryWidget, SIGNAL(search()), this, SLOT(search()));
connect(resultWidget, SIGNAL(requestShowLink(QUrl)), this, connect(resultWidget, &QHelpSearchResultWidget::requestShowLink, this,
SIGNAL(linkActivated(QUrl))); [this](const QUrl &url) {
emit linkActivated(url, false/*newPage*/);
});
connect(searchEngine, SIGNAL(searchingStarted()), this, connect(searchEngine, SIGNAL(searchingStarted()), this,
SLOT(searchingStarted())); SLOT(searchingStarted()));
@@ -224,7 +226,7 @@ bool SearchWidget::eventFilter(QObject *o, QEvent *e)
bool controlPressed = me->modifiers() & Qt::ControlModifier; bool controlPressed = me->modifiers() & Qt::ControlModifier;
if ((me->button() == Qt::LeftButton && controlPressed) if ((me->button() == Qt::LeftButton && controlPressed)
|| (me->button() == Qt::MidButton)) { || (me->button() == Qt::MidButton)) {
OpenPagesManager::instance().createPageFromSearch(link); emit linkActivated(link, true/*newPage*/);
} }
} }
} }
@@ -261,9 +263,9 @@ void SearchWidget::contextMenuEvent(QContextMenuEvent *contextMenuEvent)
QAction *usedAction = menu.exec(mapToGlobal(contextMenuEvent->pos())); QAction *usedAction = menu.exec(mapToGlobal(contextMenuEvent->pos()));
if (usedAction == openLink) if (usedAction == openLink)
emit linkActivated(link); emit linkActivated(link, false/*newPage*/);
else if (usedAction == openLinkInNewTab) else if (usedAction == openLinkInNewTab)
OpenPagesManager::instance().createPageFromSearch(link); emit linkActivated(link, true/*newPage*/);
else if (usedAction == copyAnchorAction) else if (usedAction == copyAnchorAction)
QApplication::clipboard()->setText(link.toString()); QApplication::clipboard()->setText(link.toString());
} }
@@ -274,7 +276,7 @@ SearchSideBarItem::SearchSideBarItem()
: SideBarItem(new SearchWidget, QLatin1String(Constants::HELP_SEARCH)) : SideBarItem(new SearchWidget, QLatin1String(Constants::HELP_SEARCH))
{ {
widget()->setWindowTitle(tr(Constants::SB_SEARCH)); widget()->setWindowTitle(tr(Constants::SB_SEARCH));
connect(widget(), SIGNAL(linkActivated(QUrl)), this, SIGNAL(linkActivated(QUrl))); connect(widget(), SIGNAL(linkActivated(QUrl,bool)), this, SIGNAL(linkActivated(QUrl,bool)));
} }
QList<QToolButton *> SearchSideBarItem::createToolBarWidgets() QList<QToolButton *> SearchSideBarItem::createToolBarWidgets()

View File

@@ -57,7 +57,7 @@ public:
QList<QToolButton *> createToolBarWidgets(); QList<QToolButton *> createToolBarWidgets();
signals: signals:
void linkActivated(const QUrl &url); void linkActivated(const QUrl &url, bool newPage);
}; };
class SearchWidget : public QWidget class SearchWidget : public QWidget
@@ -73,7 +73,7 @@ public:
void resetZoom(); void resetZoom();
signals: signals:
void linkActivated(const QUrl &link); void linkActivated(const QUrl &link, bool newPage);
protected: protected:
void showEvent(QShowEvent *event); void showEvent(QShowEvent *event);