2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include "searchwidget.h"
|
2010-03-23 18:11:43 +01:00
|
|
|
#include "helpmanager.h"
|
2010-03-30 17:44:28 +02:00
|
|
|
#include "openpagesmanager.h"
|
2010-03-23 18:11:43 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include <QtCore/QMap>
|
|
|
|
|
#include <QtCore/QString>
|
|
|
|
|
#include <QtCore/QStringList>
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QMenu>
|
|
|
|
|
#include <QtGui/QLayout>
|
|
|
|
|
#include <QtGui/QKeyEvent>
|
|
|
|
|
#include <QtGui/QClipboard>
|
|
|
|
|
#include <QtGui/QApplication>
|
|
|
|
|
#include <QtGui/QTextBrowser>
|
|
|
|
|
|
2010-03-23 18:11:43 +01:00
|
|
|
#include <QtHelp/QHelpEngine>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtHelp/QHelpSearchEngine>
|
|
|
|
|
#include <QtHelp/QHelpSearchQueryWidget>
|
|
|
|
|
#include <QtHelp/QHelpSearchResultWidget>
|
|
|
|
|
|
|
|
|
|
using namespace Help::Internal;
|
|
|
|
|
|
2010-03-23 18:11:43 +01:00
|
|
|
SearchWidget::SearchWidget()
|
|
|
|
|
: zoomCount(0)
|
|
|
|
|
, m_progress(0)
|
|
|
|
|
, searchEngine(0)
|
2010-06-02 14:51:03 +02:00
|
|
|
, resultWidget(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SearchWidget::~SearchWidget()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::zoomIn()
|
|
|
|
|
{
|
|
|
|
|
QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
|
|
|
|
|
if (browser && zoomCount != 10) {
|
|
|
|
|
zoomCount++;
|
|
|
|
|
browser->zoomIn();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::zoomOut()
|
|
|
|
|
{
|
|
|
|
|
QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
|
|
|
|
|
if (browser && zoomCount != -5) {
|
|
|
|
|
zoomCount--;
|
|
|
|
|
browser->zoomOut();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::resetZoom()
|
|
|
|
|
{
|
|
|
|
|
if (zoomCount == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
|
|
|
|
|
if (browser) {
|
|
|
|
|
browser->zoomOut(zoomCount);
|
|
|
|
|
zoomCount = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-23 18:11:43 +01:00
|
|
|
void SearchWidget::showEvent(QShowEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (!event->spontaneous() && !searchEngine) {
|
|
|
|
|
QVBoxLayout *vLayout = new QVBoxLayout(this);
|
|
|
|
|
vLayout->setMargin(4);
|
|
|
|
|
|
2010-06-11 13:11:37 +02:00
|
|
|
searchEngine = (&LocalHelpManager::helpEngine())->searchEngine();
|
2010-03-23 18:11:43 +01:00
|
|
|
resultWidget = searchEngine->resultWidget();
|
|
|
|
|
QHelpSearchQueryWidget *queryWidget = searchEngine->queryWidget();
|
|
|
|
|
|
|
|
|
|
vLayout->addWidget(queryWidget);
|
|
|
|
|
vLayout->addWidget(resultWidget);
|
|
|
|
|
|
|
|
|
|
setFocusProxy(queryWidget);
|
|
|
|
|
|
|
|
|
|
connect(queryWidget, SIGNAL(search()), this, SLOT(search()));
|
|
|
|
|
connect(resultWidget, SIGNAL(requestShowLink(QUrl)), this,
|
2010-03-30 17:44:28 +02:00
|
|
|
SIGNAL(linkActivated(QUrl)));
|
2010-03-23 18:11:43 +01:00
|
|
|
|
|
|
|
|
connect(searchEngine, SIGNAL(searchingStarted()), this,
|
|
|
|
|
SLOT(searchingStarted()));
|
|
|
|
|
connect(searchEngine, SIGNAL(searchingFinished(int)), this,
|
|
|
|
|
SLOT(searchingFinished(int)));
|
|
|
|
|
|
|
|
|
|
QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
|
|
|
|
|
browser->viewport()->installEventFilter(this);
|
|
|
|
|
|
|
|
|
|
connect(searchEngine, SIGNAL(indexingStarted()), this,
|
|
|
|
|
SLOT(indexingStarted()));
|
|
|
|
|
connect(searchEngine, SIGNAL(indexingFinished()), this,
|
|
|
|
|
SLOT(indexingFinished()));
|
|
|
|
|
|
2010-06-11 13:11:37 +02:00
|
|
|
QMetaObject::invokeMethod(&LocalHelpManager::helpEngine(), "setupFinished",
|
2010-03-23 18:11:43 +01:00
|
|
|
Qt::QueuedConnection);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void SearchWidget::search() const
|
|
|
|
|
{
|
|
|
|
|
QList<QHelpSearchQuery> query = searchEngine->queryWidget()->query();
|
|
|
|
|
searchEngine->search(query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::searchingStarted()
|
|
|
|
|
{
|
|
|
|
|
qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::searchingFinished(int hits)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(hits)
|
|
|
|
|
qApp->restoreOverrideCursor();
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-23 18:11:43 +01:00
|
|
|
void SearchWidget::indexingStarted()
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(!m_progress);
|
|
|
|
|
m_progress = new QFutureInterface<void>();
|
|
|
|
|
Core::ICore::instance()->progressManager() ->addTask(m_progress->future(),
|
|
|
|
|
tr("Indexing"), QLatin1String("Help.Indexer"));
|
|
|
|
|
m_progress->setProgressRange(0, 2);
|
|
|
|
|
m_progress->setProgressValueAndText(1, tr("Indexing Documentation..."));
|
|
|
|
|
m_progress->reportStarted();
|
|
|
|
|
|
|
|
|
|
m_watcher.setFuture(m_progress->future());
|
|
|
|
|
connect(&m_watcher, SIGNAL(canceled()), searchEngine, SLOT(cancelIndexing()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::indexingFinished()
|
|
|
|
|
{
|
|
|
|
|
m_progress->reportFinished();
|
|
|
|
|
|
|
|
|
|
delete m_progress;
|
|
|
|
|
m_progress = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-18 14:03:13 +02:00
|
|
|
bool SearchWidget::eventFilter(QObject* o, QEvent *e)
|
|
|
|
|
{
|
|
|
|
|
QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
|
|
|
|
|
if (browser && o == browser->viewport()
|
|
|
|
|
&& e->type() == QEvent::MouseButtonRelease){
|
|
|
|
|
QMouseEvent *me = static_cast<QMouseEvent*>(e);
|
|
|
|
|
QUrl link = resultWidget->linkAt(me->pos());
|
|
|
|
|
if (!link.isEmpty() || link.isValid()) {
|
|
|
|
|
bool controlPressed = me->modifiers() & Qt::ControlModifier;
|
|
|
|
|
if((me->button() == Qt::LeftButton && controlPressed)
|
|
|
|
|
|| (me->button() == Qt::MidButton)) {
|
2010-03-30 17:44:28 +02:00
|
|
|
OpenPagesManager::instance().createPageFromSearch(link);
|
2009-05-18 14:03:13 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QWidget::eventFilter(o,e);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void SearchWidget::contextMenuEvent(QContextMenuEvent *contextMenuEvent)
|
|
|
|
|
{
|
|
|
|
|
QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
|
|
|
|
|
if (!browser)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
QPoint point = browser->mapFromGlobal(contextMenuEvent->globalPos());
|
2008-12-02 12:01:29 +01:00
|
|
|
if (!browser->rect().contains(point, true))
|
|
|
|
|
return;
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
QAction *openLink = 0;
|
|
|
|
|
QAction *openLinkInNewTab = 0;
|
|
|
|
|
QAction *copyAnchorAction = 0;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
QMenu menu;
|
|
|
|
|
QUrl link = browser->anchorAt(point);
|
|
|
|
|
if (!link.isEmpty() && link.isValid()) {
|
|
|
|
|
if (link.isRelative())
|
|
|
|
|
link = browser->source().resolved(link);
|
|
|
|
|
openLink = menu.addAction(tr("Open Link"));
|
|
|
|
|
openLinkInNewTab = menu.addAction(tr("Open Link as New Page"));
|
|
|
|
|
copyAnchorAction = menu.addAction(tr("Copy Link"));
|
|
|
|
|
} else if (browser->textCursor().hasSelection()) {
|
|
|
|
|
menu.addAction(tr("Copy"), browser, SLOT(copy()));
|
|
|
|
|
} else {
|
|
|
|
|
menu.addAction(tr("Reload"), browser, SLOT(reload()));
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QAction *usedAction = menu.exec(mapToGlobal(contextMenuEvent->pos()));
|
2010-03-30 17:44:28 +02:00
|
|
|
if (usedAction == openLink) {
|
2008-12-02 12:01:29 +01:00
|
|
|
browser->selectAll();
|
2010-03-30 17:44:28 +02:00
|
|
|
} else if (usedAction == openLinkInNewTab) {
|
|
|
|
|
OpenPagesManager::instance().createPageFromSearch(link);
|
|
|
|
|
} else if (usedAction == copyAnchorAction) {
|
|
|
|
|
QApplication::clipboard()->setText(link.toString());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|