diff --git a/src/plugins/help/centralwidget.cpp b/src/plugins/help/centralwidget.cpp index eedc7f365515baa0c530072de447dba7e39c5019..d1f77bb55711daeac79aad6af50cff58bd32dede 100644 --- a/src/plugins/help/centralwidget.cpp +++ b/src/plugins/help/centralwidget.cpp @@ -28,6 +28,7 @@ **************************************************************************/ #include "centralwidget.h" + #include "helpmanager.h" #include "helpviewer.h" #include "topicchooser.h" @@ -35,88 +36,36 @@ #include <QtCore/QEvent> #include <QtCore/QTimer> -#include <QtGui/QMenu> -#include <QtGui/QLabel> +#include <QtGui/QKeyEvent> #include <QtGui/QLayout> +#include <QtGui/QPageSetupDialog> #include <QtGui/QPrinter> -#include <QtGui/QLineEdit> -#include <QtGui/QCheckBox> -#include <QtGui/QTabBar> -#include <QtGui/QTabWidget> -#include <QtGui/QToolButton> -#include <QtGui/QMouseEvent> -#include <QtGui/QFocusEvent> -#include <QtGui/QMainWindow> -#include <QtGui/QSpacerItem> -#include <QtGui/QTextCursor> #include <QtGui/QPrintDialog> -#include <QtGui/QApplication> -#include <QtGui/QTextDocumentFragment> #include <QtGui/QPrintPreviewDialog> -#include <QtGui/QPageSetupDialog> +#include <QtGui/QStackedWidget> +#include <QtHelp/QHelpEngine> #include <QtHelp/QHelpEngineCore> - -#include <coreplugin/coreconstants.h> +#include <QtHelp/QHelpSearchEngine> using namespace Help::Internal; -namespace { - HelpViewer* helpViewerFromTabPosition(const QTabWidget *widget, - const QPoint &point) - { - QTabBar *tabBar = qFindChild<QTabBar*>(widget); - for (int i = 0; i < tabBar->count(); ++i) { - if (tabBar->tabRect(i).contains(point)) - return qobject_cast<HelpViewer*>(widget->widget(i)); - } - return 0; - } - Help::Internal::CentralWidget *staticCentralWidget = 0; -} +CentralWidget *gStaticCentralWidget = 0; + +// -- CentralWidget CentralWidget::CentralWidget(QWidget *parent) : QWidget(parent) - , findBar(0) - , tabWidget(0) , printer(0) + , m_stackedWidget(0) { - lastTabPage = 0; - globalActionList.clear(); - - tabWidget = new QTabWidget; - tabWidget->setDocumentMode(true); - tabWidget->setMovable(true); - connect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int))); - connect(tabWidget, SIGNAL(currentChanged(int)), this, - SLOT(currentPageChanged(int))); - - QToolButton *newTabButton = new QToolButton(this); - newTabButton->setAutoRaise(true); - newTabButton->setToolTip(tr("Add new page")); - newTabButton->setIcon(QIcon( -#ifdef Q_OS_MAC - QLatin1String(":/trolltech/assistant/images/mac/addtab.png"))); -#else - QLatin1String(":/trolltech/assistant/images/win/addtab.png"))); -#endif - - tabWidget->setCornerWidget(newTabButton, Qt::TopLeftCorner); - connect(newTabButton, SIGNAL(clicked()), this, SLOT(newTab())); + Q_ASSERT(!gStaticCentralWidget); + gStaticCentralWidget = this; QVBoxLayout *vboxLayout = new QVBoxLayout(this); vboxLayout->setMargin(0); - vboxLayout->addWidget(tabWidget); - - QTabBar *tabBar = qFindChild<QTabBar*>(tabWidget); - if (tabBar) { - tabBar->installEventFilter(this); - tabBar->setContextMenuPolicy(Qt::CustomContextMenu); - connect(tabBar, SIGNAL(customContextMenuRequested(QPoint)), this, - SLOT(showTabBarContextMenu(QPoint))); - } - - staticCentralWidget = this; + m_stackedWidget = new QStackedWidget(this); + vboxLayout->addWidget(m_stackedWidget); } CentralWidget::~CentralWidget() @@ -125,597 +74,319 @@ CentralWidget::~CentralWidget() delete printer; #endif - QString zoomCount; + QString zoomFactors; QString currentPages; - for (int i = 0; i < tabWidget->count(); ++i) { - HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i)); - if (viewer && viewer->source().isValid()) { - currentPages += (viewer->source().toString() + QLatin1Char('|')); - zoomCount += QString::number(viewer->zoom()) + QLatin1Char('|'); + for (int i = 0; i < m_stackedWidget->count(); ++i) { + const HelpViewer * const viewer = viewerAt(i); + const QUrl &source = viewer->source(); + if (source.isValid()) { + currentPages += source.toString() + QLatin1Char('|'); + zoomFactors += QString::number(viewer->scale()) + QLatin1Char('|'); } } QHelpEngineCore *engine = &HelpManager::helpEngineCore(); - engine->setCustomValue(QLatin1String("LastTabPage"), lastTabPage); engine->setCustomValue(QLatin1String("LastShownPages"), currentPages); - engine->setCustomValue(QLatin1String("LastShownPagesZoom"), zoomCount); + engine->setCustomValue(QLatin1String("LastShownPagesZoom"), zoomFactors); + engine->setCustomValue(QLatin1String("LastTabPage"), currentIndex()); } CentralWidget *CentralWidget::instance() { - return staticCentralWidget; -} - -void CentralWidget::newTab() -{ - HelpViewer* viewer = currentHelpViewer(); -#if !defined(QT_NO_WEBKIT) - if (viewer && viewer->hasLoadFinished()) -#else - if (viewer) -#endif - setSourceInNewTab(viewer->source()); + Q_ASSERT(gStaticCentralWidget); + return gStaticCentralWidget; } -void CentralWidget::zoomIn() +bool CentralWidget::hasSelection() const { - HelpViewer* viewer = currentHelpViewer(); - if (viewer) - viewer->zoomIn(); + if (HelpViewer* viewer = currentHelpViewer()) + return !viewer->selectedText().isEmpty(); + return false; } -void CentralWidget::zoomOut() +bool CentralWidget::isForwardAvailable() const { - HelpViewer* viewer = currentHelpViewer(); + const HelpViewer* viewer = currentHelpViewer(); if (viewer) - viewer->zoomOut(); -} + return viewer->isForwardAvailable(); -void CentralWidget::nextPage() -{ - int index = tabWidget->currentIndex() + 1; - if (index >= tabWidget->count()) - index = 0; - tabWidget->setCurrentIndex(index); + return false; } -void CentralWidget::resetZoom() +bool CentralWidget::isBackwardAvailable() const { - HelpViewer* viewer = currentHelpViewer(); + const HelpViewer* viewer = currentHelpViewer(); if (viewer) - viewer->resetZoom(); -} + return viewer->isBackwardAvailable(); -void CentralWidget::previousPage() -{ - int index = tabWidget->currentIndex() -1; - if (index < 0) - index = tabWidget->count() -1; - tabWidget->setCurrentIndex(index); + return false; } -void CentralWidget::closeTab() +HelpViewer* CentralWidget::viewerAt(int index) const { - closeTab(tabWidget->currentIndex()); + return qobject_cast<HelpViewer*> (m_stackedWidget->widget(index)); } -void CentralWidget::closeTab(int index) +HelpViewer* CentralWidget::currentHelpViewer() const { - HelpViewer* viewer = helpViewerAtIndex(index); - if (!viewer || tabWidget->count() == 1) - return; - - emit viewerAboutToBeRemoved(index); - tabWidget->removeTab(index); - emit viewerRemoved(index); - QTimer::singleShot(0, viewer, SLOT(deleteLater())); + return qobject_cast<HelpViewer*> (m_stackedWidget->currentWidget()); } -void CentralWidget::setSource(const QUrl &url) +void CentralWidget::addPage(HelpViewer *page, bool fromSearch) { - HelpViewer* viewer = currentHelpViewer(); - HelpViewer* lastViewer = - qobject_cast<HelpViewer*>(tabWidget->widget(lastTabPage)); - - if (!viewer && !lastViewer) { - viewer = new HelpViewer(this, this); - viewer->installEventFilter(this); - lastTabPage = tabWidget->addTab(viewer, QString()); - tabWidget->setCurrentIndex(lastTabPage); - connectSignals(); - qApp->processEvents(); - } else { - viewer = lastViewer; - } - - viewer->setSource(url); - currentPageChanged(lastTabPage); - viewer->setFocus(Qt::OtherFocusReason); - tabWidget->setCurrentIndex(lastTabPage); - tabWidget->setTabText(lastTabPage, quoteTabTitle(viewer->documentTitle())); + page->installEventFilter(this); + page->setFocus(Qt::OtherFocusReason); + connectSignals(page); + m_stackedWidget->addWidget(page); + if (fromSearch) { + connect(currentHelpViewer(), SIGNAL(loadFinished(bool)), this, + SLOT(highlightSearchTerms())); + } } -void CentralWidget::setLastShownPages() +void CentralWidget::removePage(int index) { - const QHelpEngineCore &engine = HelpManager::helpEngineCore(); - QString value = engine.customValue(QLatin1String("LastShownPages"), - QString()).toString(); - const QStringList lastShownPageList = value.split(QLatin1Char('|'), - QString::SkipEmptyParts); - const int pageCount = lastShownPageList.count(); - - QString homePage = engine.customValue(QLatin1String("DefaultHomePage"), - QLatin1String("about:blank")).toString(); - - int option = engine.customValue(QLatin1String("StartOption"), 2).toInt(); - if (option == 0 || option == 1 || pageCount <= 0) { - if (option == 0) { - homePage = engine.customValue(QLatin1String("HomePage"), - homePage).toString(); - } else if (option == 1) { - homePage = QLatin1String("about:blank"); - } - setSource(homePage); - return; - } - - value = engine.customValue(QLatin1String("LastShownPagesZoom"), - QString()).toString(); - QVector<QString> zoomVector = value.split(QLatin1Char('|'), - QString::SkipEmptyParts).toVector(); - - const int zoomCount = zoomVector.count(); - zoomVector.insert(zoomCount, pageCount - zoomCount, QLatin1String("0")); - - QVector<QString>::const_iterator zIt = zoomVector.constBegin(); - QStringList::const_iterator it = lastShownPageList.constBegin(); - for (; it != lastShownPageList.constEnd(); ++it, ++zIt) - setSourceInNewTab((*it), (*zIt).toInt()); - - int tab = engine.customValue(QLatin1String("LastTabPage"), 0).toInt(); - tabWidget->setCurrentIndex(tab); + const bool currentChanged = (index == currentIndex()); + m_stackedWidget->removeWidget(m_stackedWidget->widget(index)); + if (currentChanged) + emit currentViewerChanged(); } -bool CentralWidget::hasSelection() const +int CentralWidget::currentIndex() const { - const HelpViewer* viewer = currentHelpViewer(); - return viewer ? viewer->hasSelection() : false; + return m_stackedWidget->currentIndex(); } -QUrl CentralWidget::currentSource() const +void CentralWidget::setCurrentPage(HelpViewer *page) { - const HelpViewer* viewer = currentHelpViewer(); - if (viewer) - return viewer->source(); - - return QUrl(); + m_stackedWidget->setCurrentWidget(page); + emit currentViewerChanged(); } -QString CentralWidget::currentTitle() const +bool CentralWidget::find(const QString &txt, Find::IFindSupport::FindFlags flags, + bool incremental) { - const HelpViewer* viewer = currentHelpViewer(); - if (viewer) - return viewer->documentTitle(); - - return QString(); + return currentHelpViewer()->findText(txt, flags, incremental, false); } -void CentralWidget::initPrinter() -{ -#ifndef QT_NO_PRINTER - if (!printer) - printer = new QPrinter(QPrinter::HighResolution); -#endif -} +// -- public slots -void CentralWidget::print() +void CentralWidget::copy() { -#ifndef QT_NO_PRINTER - HelpViewer* viewer = currentHelpViewer(); - if (!viewer) - return; - - initPrinter(); - - QPrintDialog *dlg = new QPrintDialog(printer, this); -#if defined(QT_NO_WEBKIT) - if (viewer->textCursor().hasSelection()) - dlg->addEnabledOption(QAbstractPrintDialog::PrintSelection); -#endif - dlg->addEnabledOption(QAbstractPrintDialog::PrintPageRange); - dlg->addEnabledOption(QAbstractPrintDialog::PrintCollateCopies); - dlg->setWindowTitle(tr("Print Document")); - if (dlg->exec() == QDialog::Accepted) { - viewer->print(printer); - } - delete dlg; -#endif + if (HelpViewer* viewer = currentHelpViewer()) + viewer->copy(); } -void CentralWidget::printPreview() +void CentralWidget::home() { -#ifndef QT_NO_PRINTER - initPrinter(); - QPrintPreviewDialog preview(printer, this); - connect(&preview, SIGNAL(paintRequested(QPrinter*)), - SLOT(printPreview(QPrinter*))); - preview.exec(); -#endif + if (HelpViewer* viewer = currentHelpViewer()) + viewer->home(); } -void CentralWidget::printPreview(QPrinter *p) +void CentralWidget::zoomIn() { -#ifndef QT_NO_PRINTER - HelpViewer *viewer = currentHelpViewer(); + HelpViewer* viewer = currentHelpViewer(); if (viewer) - viewer->print(p); -#else - Q_UNUSED(p) -#endif -} - -void CentralWidget::pageSetup() -{ -#ifndef QT_NO_PRINTER - initPrinter(); - QPageSetupDialog dlg(printer); - dlg.exec(); -#endif + viewer->scaleUp(); } -void CentralWidget::home() +void CentralWidget::zoomOut() { HelpViewer* viewer = currentHelpViewer(); if (viewer) - viewer->home(); + viewer->scaleDown(); } -bool CentralWidget::isForwardAvailable() const +void CentralWidget::resetZoom() { - const HelpViewer* viewer = currentHelpViewer(); + HelpViewer* viewer = currentHelpViewer(); if (viewer) - return viewer->isForwardAvailable(); - - return false; + viewer->resetScale(); } void CentralWidget::forward() { - HelpViewer* viewer = currentHelpViewer(); - if (viewer) + if (HelpViewer* viewer = currentHelpViewer()) viewer->forward(); } -bool CentralWidget::isBackwardAvailable() const +void CentralWidget::nextPage() { - const HelpViewer* viewer = currentHelpViewer(); - if (viewer) - return viewer->isBackwardAvailable(); - - return false; + m_stackedWidget->setCurrentIndex((m_stackedWidget->currentIndex() + 1) + % m_stackedWidget->count()); } void CentralWidget::backward() { - HelpViewer* viewer = currentHelpViewer(); - if (viewer) + if (HelpViewer* viewer = currentHelpViewer()) viewer->backward(); } - -QList<QAction*> CentralWidget::globalActions() const -{ - return globalActionList; -} - -void CentralWidget::setGlobalActions(const QList<QAction*> &actions) +void CentralWidget::previousPage() { - globalActionList = actions; + m_stackedWidget->setCurrentIndex((m_stackedWidget->currentIndex() - 1) + % m_stackedWidget->count()); } -void CentralWidget::setSourceInNewTab(const QUrl &url, int zoom) +void CentralWidget::print() { - HelpViewer* viewer = new HelpViewer(this, this); - viewer->installEventFilter(this); - viewer->setZoom(zoom); - viewer->setSource(url); - viewer->setFocus(Qt::OtherFocusReason); - -#if defined(QT_NO_WEBKIT) - QFont font = viewer->font(); - font.setPointSize(font.pointSize() + int(zoom)); - viewer->setFont(font); +#ifndef QT_NO_PRINTER + if (HelpViewer* viewer = currentHelpViewer()) { + initPrinter(); + + QPrintDialog *dlg = new QPrintDialog(printer, this); + dlg->setWindowTitle(tr("Print Document")); + if (!viewer->selectedText().isEmpty()) + dlg->addEnabledOption(QAbstractPrintDialog::PrintSelection); + dlg->addEnabledOption(QAbstractPrintDialog::PrintPageRange); + dlg->addEnabledOption(QAbstractPrintDialog::PrintCollateCopies); + + if (dlg->exec() == QDialog::Accepted) + viewer->print(printer); + delete dlg; + } #endif - - tabWidget->setCurrentIndex(tabWidget->addTab(viewer, - quoteTabTitle(viewer->documentTitle()))); - - connectSignals(); } -HelpViewer *CentralWidget::newEmptyTab() +void CentralWidget::pageSetup() { - HelpViewer* viewer = new HelpViewer(this, this); - viewer->installEventFilter(this); - viewer->setFocus(Qt::OtherFocusReason); -#if defined(QT_NO_WEBKIT) - viewer->setDocumentTitle(tr("unknown")); +#ifndef QT_NO_PRINTER + initPrinter(); + QPageSetupDialog dlg(printer); + dlg.exec(); #endif - tabWidget->setCurrentIndex(tabWidget->addTab(viewer, tr("unknown"))); - - connectSignals(); - return viewer; -} - -void CentralWidget::connectSignals() -{ - const HelpViewer* viewer = currentHelpViewer(); - if (viewer) { - connect(viewer, SIGNAL(copyAvailable(bool)), this, - SIGNAL(copyAvailable(bool))); - connect(viewer, SIGNAL(forwardAvailable(bool)), this, - SIGNAL(forwardAvailable(bool))); - connect(viewer, SIGNAL(backwardAvailable(bool)), this, - SIGNAL(backwardAvailable(bool))); - connect(viewer, SIGNAL(sourceChanged(QUrl)), this, - SIGNAL(sourceChanged(QUrl))); - connect(viewer, SIGNAL(highlighted(QString)), this, - SIGNAL(highlighted(QString))); - connect(viewer, SIGNAL(sourceChanged(QUrl)), this, - SLOT(setTabTitle(QUrl))); - } -} - -HelpViewer *CentralWidget::helpViewerAtIndex(int index) const -{ - return qobject_cast<HelpViewer*>(tabWidget->widget(index)); } -int CentralWidget::indexOf(HelpViewer *viewer) const -{ - if (!viewer) - return -1; - return tabWidget->indexOf(viewer); -} - -HelpViewer *CentralWidget::currentHelpViewer() const +void CentralWidget::printPreview() { - return qobject_cast<HelpViewer*>(tabWidget->currentWidget()); +#ifndef QT_NO_PRINTER + initPrinter(); + QPrintPreviewDialog preview(printer, this); + connect(&preview, SIGNAL(paintRequested(QPrinter*)), + SLOT(printPreview(QPrinter*))); + preview.exec(); +#endif } -void CentralWidget::activateTab(bool onlyHelpViewer) +void CentralWidget::setSource(const QUrl &url) { - if (currentHelpViewer()) { - currentHelpViewer()->setFocus(); - } else { - int idx = 0; - if (onlyHelpViewer) - idx = lastTabPage; - tabWidget->setCurrentIndex(idx); - tabWidget->currentWidget()->setFocus(); + if (HelpViewer* viewer = currentHelpViewer()) { + viewer->setSource(url); + viewer->setFocus(Qt::OtherFocusReason); } } -void CentralWidget::setTabTitle(const QUrl& url) +void CentralWidget::setSourceFromSearch(const QUrl &url) { - Q_UNUSED(url) -#if !defined(QT_NO_WEBKIT) - QTabBar *tabBar = qFindChild<QTabBar*>(tabWidget); - for (int i = 0; i < tabBar->count(); ++i) { - HelpViewer* view = qobject_cast<HelpViewer*>(tabWidget->widget(i)); - if (view) { - tabWidget->setTabText(i, - quoteTabTitle(view->documentTitle().trimmed())); - } - } -#else if (HelpViewer* viewer = currentHelpViewer()) { - tabWidget->setTabText(lastTabPage, - quoteTabTitle(viewer->documentTitle().trimmed())); + connect(viewer, SIGNAL(loadFinished(bool)), this, + SLOT(highlightSearchTerms())); + viewer->setSource(url); + viewer->setFocus(Qt::OtherFocusReason); } -#endif } -void CentralWidget::currentPageChanged(int index) +void CentralWidget::showTopicChooser(const QMap<QString, QUrl> &links, + const QString &keyword) { - lastTabPage = index; - - tabWidget->setTabsClosable(tabWidget->count() > 1); - tabWidget->cornerWidget(Qt::TopLeftCorner)->setEnabled(true); - - emit currentViewerChanged(index); + TopicChooser tc(this, keyword, links); + if (tc.exec() == QDialog::Accepted) + setSource(tc.link()); } -void CentralWidget::showTabBarContextMenu(const QPoint &point) -{ - HelpViewer* viewer = helpViewerFromTabPosition(tabWidget, point); - if (!viewer) - return; - - QTabBar *tabBar = qFindChild<QTabBar*>(tabWidget); - - QMenu menu(QLatin1String(""), tabBar); - QAction *newPage = menu.addAction(tr("Add New Page")); - - bool enableAction = tabBar->count() > 1; - QAction *closePage = menu.addAction(tr("Close This Page")); - closePage->setEnabled(enableAction); - - QAction *closePages = menu.addAction(tr("Close Other Pages")); - closePages->setEnabled(enableAction); - - menu.addSeparator(); +// -- protected - QAction *newBookmark = menu.addAction(tr("Add Bookmark for this Page...")); - const QString &url = viewer->source().toString(); - if (url.isEmpty() || url == QLatin1String("about:blank")) - newBookmark->setEnabled(false); - - QAction *pickedAction = menu.exec(tabBar->mapToGlobal(point)); - if (pickedAction == newPage) - setSourceInNewTab(viewer->source()); - - if (pickedAction == closePage) { - tabWidget->removeTab(tabWidget->indexOf(viewer)); - QTimer::singleShot(0, viewer, SLOT(deleteLater())); - } - - if (pickedAction == closePages) { - int currentPage = tabWidget->indexOf(viewer); - for (int i = tabBar->count() -1; i >= 0; --i) { - viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i)); - if (i != currentPage && viewer) { - tabWidget->removeTab(i); - QTimer::singleShot(0, viewer, SLOT(deleteLater())); - - if (i < currentPage) - --currentPage; - } - } - } - - if (pickedAction == newBookmark) - emit addNewBookmark(viewer->documentTitle(), url); -} - -// If we have a current help viewer then this is the 'focus proxy', otherwise -// it's the tab widget itself. This is needed, so an embedding program can just -// set the focus to the central widget and it does TheRightThing(TM) void CentralWidget::focusInEvent(QFocusEvent * /* event */) { - QObject *receiver = tabWidget; - if (currentHelpViewer()) - receiver = currentHelpViewer(); - + // If we have a current help viewer then this is the 'focus proxy', + // otherwise it's the central widget. This is needed, so an embedding + // program can just set the focus to the central widget and it does + // The Right Thing(TM) + QObject *receiver = m_stackedWidget; + if (HelpViewer *viewer = currentHelpViewer()) + receiver = viewer; QTimer::singleShot(1, receiver, SLOT(setFocus())); } -bool CentralWidget::eventFilter(QObject *object, QEvent *e) +// -- private slots + +void CentralWidget::highlightSearchTerms() { - if (e->type() == QEvent::KeyPress){ - if ((static_cast<QKeyEvent*>(e))->key() == Qt::Key_Backspace) { - HelpViewer *viewer = currentHelpViewer(); - if (viewer == object) { - if (viewer->isBackwardAvailable()) { -#if !defined(QT_NO_WEBKIT) - // this helps in case there is an html <input> field - if (!viewer->hasFocus()) -#endif - viewer->backward(); - } - return true; - } - } - } + if (HelpViewer *viewer = currentHelpViewer()) { + QHelpSearchEngine *searchEngine = + HelpManager::instance().helpEngine().searchEngine(); + QList<QHelpSearchQuery> queryList = searchEngine->query(); - if (qobject_cast<QTabBar*>(object)) { - bool dblClick = e->type() == QEvent::MouseButtonDblClick; - if((e->type() == QEvent::MouseButtonRelease) || dblClick) { - if (tabWidget->count() <= 1) - return QWidget::eventFilter(object, e); - - QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(e); - HelpViewer *viewer = helpViewerFromTabPosition(tabWidget, - mouseEvent->pos()); - - if (viewer) { - if ((mouseEvent->button() == Qt::MidButton) || dblClick) { - tabWidget->removeTab(tabWidget->indexOf(viewer)); - QTimer::singleShot(0, viewer, SLOT(deleteLater())); - currentPageChanged(tabWidget->currentIndex()); - return true; + QStringList terms; + foreach (const QHelpSearchQuery &query, queryList) { + switch (query.fieldName) { + default: break; + case QHelpSearchQuery::ALL: { + case QHelpSearchQuery::PHRASE: + case QHelpSearchQuery::DEFAULT: + case QHelpSearchQuery::ATLEAST: + foreach (QString term, query.wordList) + terms.append(term.remove(QLatin1String("\""))); } } } + + foreach (const QString& term, terms) + viewer->findText(term, 0, false, true); + disconnect(viewer, SIGNAL(loadFinished(bool)), this, + SLOT(highlightSearchTerms())); } - return QWidget::eventFilter(object, e); } -bool CentralWidget::find(const QString &txt, QTextDocument::FindFlags findFlags, - bool incremental) +void CentralWidget::printPreview(QPrinter *p) { - HelpViewer* viewer = currentHelpViewer(); - -#if !defined(QT_NO_WEBKIT) - Q_UNUSED(incremental) - if (viewer) { - QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument; - if (findFlags & QTextDocument::FindBackward) - options |= QWebPage::FindBackward; - if (findFlags & QTextDocument::FindCaseSensitively) - options |= QWebPage::FindCaseSensitively; - - bool found = viewer->findText(txt, options); - options = QWebPage::HighlightAllOccurrences; - viewer->findText(QLatin1String(""), options); // clear first - viewer->findText(txt, options); // force highlighting of all other matches - return found; - } - return false; +#ifndef QT_NO_PRINTER + HelpViewer *viewer = currentHelpViewer(); + if (viewer) + viewer->print(p); #else - QTextCursor cursor; - QTextDocument *doc = 0; - QTextBrowser *browser = 0; - - if (viewer) { - doc = viewer->document(); - cursor = viewer->textCursor(); - browser = qobject_cast<QTextBrowser*>(viewer); - } - /* - if (tabWidget->currentWidget() == m_searchWidget) { - QTextBrowser* browser = qFindChild<QTextBrowser*>(m_searchWidget); - if (browser) { - doc = browser->document(); - cursor = browser->textCursor(); - } - } - */ - if (!browser || !doc || cursor.isNull()) - return false; - if (incremental) - cursor.setPosition(cursor.selectionStart()); - - QTextCursor found = doc->find(txt, cursor, findFlags); - if (found.isNull()) { - if ((findFlags&QTextDocument::FindBackward) == 0) - cursor.movePosition(QTextCursor::Start); - else - cursor.movePosition(QTextCursor::End); - found = doc->find(txt, cursor, findFlags); - if (found.isNull()) { - return false; - } - } - if (!found.isNull()) { - viewer->setTextCursor(found); - } - return true; + Q_UNUSED(p) #endif } -void CentralWidget::showTopicChooser(const QMap<QString, QUrl> &links, - const QString &keyword) +void CentralWidget::handleSourceChanged(const QUrl &url) { - TopicChooser tc(this, keyword, links); - if (tc.exec() == QDialog::Accepted) - setSource(tc.link()); + if (sender() == currentHelpViewer()) + emit sourceChanged(url); } -void CentralWidget::copy() +// -- private + +void CentralWidget::initPrinter() { - HelpViewer* viewer = currentHelpViewer(); - if (viewer) - viewer->copy(); +#ifndef QT_NO_PRINTER + if (!printer) + printer = new QPrinter(QPrinter::HighResolution); +#endif } -void CentralWidget::activateTab(int index) +void CentralWidget::connectSignals(HelpViewer *page) { - tabWidget->setCurrentIndex(index); + connect(page, SIGNAL(sourceChanged(QUrl)), this, SLOT(handleSourceChanged(QUrl))); + connect(page, SIGNAL(forwardAvailable(bool)), this, SIGNAL(forwardAvailable(bool))); + connect(page, SIGNAL(backwardAvailable(bool)), this, SIGNAL(backwardAvailable(bool))); } -QString CentralWidget::quoteTabTitle(const QString &title) const +bool CentralWidget::eventFilter(QObject *object, QEvent *e) { - QString s = title; - return s.replace(QLatin1Char('&'), QLatin1String("&&")); + if (e->type() != QEvent::KeyPress) + return QWidget::eventFilter(object, e); + + HelpViewer *viewer = currentHelpViewer(); + QKeyEvent *keyEvent = static_cast<QKeyEvent*> (e); + if (viewer == object && keyEvent->key() == Qt::Key_Backspace) { + if (viewer->isBackwardAvailable()) { +#if !defined(QT_NO_WEBKIT) + // this helps in case there is an html <input> field + if (!viewer->hasFocus()) +#endif + viewer->backward(); + } + } + return QWidget::eventFilter(object, e); } diff --git a/src/plugins/help/centralwidget.h b/src/plugins/help/centralwidget.h index 271d8d9616866afcbba1e484683a2b3bbafb8dba..d02d80b23c8c74612d3fcce840e36bf561ff095d 100644 --- a/src/plugins/help/centralwidget.h +++ b/src/plugins/help/centralwidget.h @@ -30,29 +30,19 @@ #ifndef CENTRALWIDGET_H #define CENTRALWIDGET_H -#include <QtCore/QUrl> -#include <QtCore/QPoint> -#include <QtCore/QObject> +#include <find/ifindsupport.h> #include <QtGui/QWidget> -#include <QtGui/QTextDocument> -QT_BEGIN_NAMESPACE +QT_FORWARD_DECLARE_CLASS(QEvent) +QT_FORWARD_DECLARE_CLASS(QAction) +QT_FORWARD_DECLARE_CLASS(QStackedWidget) +QT_FORWARD_DECLARE_CLASS(QFocusEvent) -class QEvent; -class QLabel; -class QAction; -class QCheckBox; -class QLineEdit; -class QToolButton; -class QTabWidget; -class QFocusEvent; -QT_END_NAMESPACE +namespace Help { + namespace Internal { class HelpViewer; - -namespace Help { -namespace Internal { class PrintHelper; class CentralWidget : public QWidget @@ -63,82 +53,71 @@ public: CentralWidget(QWidget *parent = 0); ~CentralWidget(); + static CentralWidget *instance(); + bool hasSelection() const; - QUrl currentSource() const; - QString currentTitle() const; bool isForwardAvailable() const; bool isBackwardAvailable() const; - QList<QAction*> globalActions() const; - void setGlobalActions(const QList<QAction*> &actions); + + HelpViewer *viewerAt(int index) const; HelpViewer *currentHelpViewer() const; - void activateTab(bool onlyHelpViewer = false); - bool find(const QString &txt, QTextDocument::FindFlags findFlags, bool incremental); - void setLastShownPages(); - HelpViewer *helpViewerAtIndex(int index) const; - int indexOf(HelpViewer *viewer) const; - static CentralWidget *instance(); + void addPage(HelpViewer *page, bool fromSearch = false); + void removePage(int index); + + int currentIndex() const; + void setCurrentPage(HelpViewer *page); + + bool find(const QString &txt, Find::IFindSupport::FindFlags findFlags, + bool incremental); public slots: + void copy(); + void home(); + void zoomIn(); void zoomOut(); - void nextPage(); void resetZoom(); + + void forward(); + void nextPage(); + + void backward(); void previousPage(); + void print(); void pageSetup(); void printPreview(); + void setSource(const QUrl &url); - void setSourceInNewTab(const QUrl &url, int zoom = 0); - HelpViewer *newEmptyTab(); - void home(); - void forward(); - void backward(); - void showTopicChooser(const QMap<QString, QUrl> &links, - const QString &keyword); - void copy(); - void activateTab(int index); + void setSourceFromSearch(const QUrl &url); + void showTopicChooser(const QMap<QString, QUrl> &links, const QString &key); protected: void focusInEvent(QFocusEvent *event); signals: - void currentViewerChanged(int index); - void copyAvailable(bool yes); + void currentViewerChanged(); void sourceChanged(const QUrl &url); - void highlighted(const QString &link); void forwardAvailable(bool available); void backwardAvailable(bool available); - void addNewBookmark(const QString &title, const QString &url); - - void viewerAboutToBeRemoved(int index); - void viewerRemoved(int index); private slots: - void newTab(); - void closeTab(); - void closeTab(int index); - void setTabTitle(const QUrl& url); - void currentPageChanged(int index); - void showTabBarContextMenu(const QPoint &point); + void highlightSearchTerms(); void printPreview(QPrinter *printer); + void handleSourceChanged(const QUrl &url); private: - void connectSignals(); - bool eventFilter(QObject *object, QEvent *e); void initPrinter(); - QString quoteTabTitle(const QString &title) const; + void connectSignals(HelpViewer *page); + bool eventFilter(QObject *object, QEvent *e); private: - int lastTabPage; - QList<QAction*> globalActionList; - - QWidget *findBar; - QTabWidget* tabWidget; QPrinter *printer; + QStackedWidget *m_stackedWidget; }; -} // namespace Internal + } // namespace Internal } // namespace Help #endif // CENTRALWIDGET_H diff --git a/src/plugins/help/generalsettingspage.cpp b/src/plugins/help/generalsettingspage.cpp index defe4dfb6401214adc9f4ecdc53844273db7bee2..50709e8c37b5a23b32497f55293f8bd64db8b20b 100644 --- a/src/plugins/help/generalsettingspage.cpp +++ b/src/plugins/help/generalsettingspage.cpp @@ -41,25 +41,23 @@ #include <QtCore/QCoreApplication> #include <QtCore/QTextStream> -#if defined(QT_NO_WEBKIT) #include <QtGui/QApplication> -#else -#include <QtWebKit/QWebSettings> -#endif #include <QtGui/QFileDialog> #include <QtHelp/QHelpEngineCore> +#if !defined(QT_NO_WEBKIT) +#include <QtWebKit/QWebSettings> +#endif + using namespace Help::Internal; GeneralSettingsPage::GeneralSettingsPage() { + m_font = qApp->font(); #if !defined(QT_NO_WEBKIT) QWebSettings* webSettings = QWebSettings::globalSettings(); - m_font.setFamily(webSettings->fontFamily(QWebSettings::StandardFont)); m_font.setPointSize(webSettings->fontSize(QWebSettings::DefaultFontSize)); -#else - m_font = qApp->font(); #endif } @@ -168,13 +166,8 @@ void GeneralSettingsPage::apply() QHelpEngineCore *engine = &HelpManager::helpEngineCore(); engine->setCustomValue(QLatin1String("font"), newFont); -#if !defined(QT_NO_WEBKIT) - QWebSettings* webSettings = QWebSettings::globalSettings(); - webSettings->setFontFamily(QWebSettings::StandardFont, m_font.family()); - webSettings->setFontSize(QWebSettings::DefaultFontSize, m_font.pointSize()); -#else - emit fontChanged(); -#endif + if (newFont != m_font) + emit fontChanged(); QString homePage = m_ui.homePageLineEdit->text(); if (homePage.isEmpty()) diff --git a/src/plugins/help/help.pro b/src/plugins/help/help.pro index 0356e5e3e7fdaf14ab901943f30ae266414b8757..c8164485c8ce1f8a586a3e8761e8aff730da7c1d 100644 --- a/src/plugins/help/help.pro +++ b/src/plugins/help/help.pro @@ -6,33 +6,46 @@ include(../../qtcreatorplugin.pri) include(help_dependencies.pri) CONFIG += help -DEFINES += QT_CLUCENE_SUPPORT \ - HELP_LIBRARY -HEADERS += helpplugin.h \ +DEFINES += QT_CLUCENE_SUPPORT HELP_LIBRARY + +HEADERS += \ + centralwidget.h \ docsettingspage.h \ filtersettingspage.h \ + generalsettingspage.h \ + help_global.h \ helpconstants.h \ - helpmode.h \ - centralwidget.h \ - searchwidget.h \ helpfindsupport.h \ - help_global.h \ helpindexfilter.h \ - generalsettingspage.h \ - xbelsupport.h \ - helpmanager.h + helpmanager.h \ + helpmode.h \ + helpplugin.h \ + helpviewer.h \ + helpviewer_p.h \ + openpagesmanager.h \ + openpagesmodel.h \ + openpageswidget.h \ + searchwidget.h \ + xbelsupport.h -SOURCES += helpplugin.cpp \ +SOURCES += \ + centralwidget.cpp \ docsettingspage.cpp \ filtersettingspage.cpp \ - helpmode.cpp \ - centralwidget.cpp \ - searchwidget.cpp \ + generalsettingspage.cpp \ helpfindsupport.cpp \ helpindexfilter.cpp \ - generalsettingspage.cpp \ - xbelsupport.cpp \ - helpmanager.cpp + helpmanager.cpp \ + helpmode.cpp \ + helpplugin.cpp \ + helpviewer.cpp \ + helpviewer_qtb.cpp \ + helpviewer_qwv.cpp \ + openpagesmanager.cpp \ + openpagesmodel.cpp \ + openpageswidget.cpp \ + searchwidget.cpp \ + xbelsupport.cpp FORMS += docsettingspage.ui \ filtersettingspage.ui \ diff --git a/src/plugins/help/helpfindsupport.cpp b/src/plugins/help/helpfindsupport.cpp index b23d778929d6221ea9cb19fec953a172ef9cd411..91c1967935e6c76ad4b7d431e2298d5b696d271c 100644 --- a/src/plugins/help/helpfindsupport.cpp +++ b/src/plugins/help/helpfindsupport.cpp @@ -51,7 +51,7 @@ bool HelpFindSupport::isEnabled() const Find::IFindSupport::FindFlags HelpFindSupport::supportedFindFlags() const { return Find::IFindSupport::FindBackward | Find::IFindSupport::FindCaseSensitively - | Find::IFindSupport::FindWholeWords; + | Find::IFindSupport::FindWholeWords; } QString HelpFindSupport::currentFindString() const @@ -60,11 +60,7 @@ QString HelpFindSupport::currentFindString() const HelpViewer *viewer = m_centralWidget->currentHelpViewer(); if (!viewer) return QString(); -#if !defined(QT_NO_WEBKIT) return viewer->selectedText(); -#else - return viewer->textCursor().selectedText(); -#endif } QString HelpFindSupport::completedFindString() const @@ -72,95 +68,58 @@ QString HelpFindSupport::completedFindString() const return QString(); } -Find::IFindSupport::Result HelpFindSupport::findIncremental(const QString &txt, Find::IFindSupport::FindFlags findFlags) +Find::IFindSupport::Result HelpFindSupport::findIncremental(const QString &txt, + Find::IFindSupport::FindFlags findFlags) { QTC_ASSERT(m_centralWidget, return NotFound); findFlags &= ~Find::IFindSupport::FindBackward; - return m_centralWidget->find(txt, Find::IFindSupport::textDocumentFlagsForFindFlags(findFlags), true) - ? Found : NotFound; + return m_centralWidget->find(txt, findFlags, true) ? Found : NotFound; } -Find::IFindSupport::Result HelpFindSupport::findStep(const QString &txt, Find::IFindSupport::FindFlags findFlags) +Find::IFindSupport::Result HelpFindSupport::findStep(const QString &txt, + Find::IFindSupport::FindFlags findFlags) { QTC_ASSERT(m_centralWidget, return NotFound); - return m_centralWidget->find(txt, Find::IFindSupport::textDocumentFlagsForFindFlags(findFlags), false) - ? Found : NotFound; + return m_centralWidget->find(txt, findFlags, false) ? Found : NotFound; } +// -- HelpViewerFindSupport + HelpViewerFindSupport::HelpViewerFindSupport(HelpViewer *viewer) - : m_viewer(viewer) + : m_viewer(viewer) { } Find::IFindSupport::FindFlags HelpViewerFindSupport::supportedFindFlags() const { return Find::IFindSupport::FindBackward | Find::IFindSupport::FindCaseSensitively - | Find::IFindSupport::FindWholeWords; + | Find::IFindSupport::FindWholeWords; } QString HelpViewerFindSupport::currentFindString() const { QTC_ASSERT(m_viewer, return QString()); -#if !defined(QT_NO_WEBKIT) return m_viewer->selectedText(); -#else - return QString(); -#endif } -Find::IFindSupport::Result HelpViewerFindSupport::findIncremental(const QString &txt, Find::IFindSupport::FindFlags findFlags) +Find::IFindSupport::Result HelpViewerFindSupport::findIncremental(const QString &txt, + Find::IFindSupport::FindFlags findFlags) { QTC_ASSERT(m_viewer, return NotFound); findFlags &= ~Find::IFindSupport::FindBackward; return find(txt, findFlags, true) ? Found : NotFound; } -Find::IFindSupport::Result HelpViewerFindSupport::findStep(const QString &txt, Find::IFindSupport::FindFlags findFlags) +Find::IFindSupport::Result HelpViewerFindSupport::findStep(const QString &txt, + Find::IFindSupport::FindFlags findFlags) { QTC_ASSERT(m_viewer, return NotFound); return find(txt, findFlags, false) ? Found : NotFound; } -bool HelpViewerFindSupport::find(const QString &txt, Find::IFindSupport::FindFlags findFlags, bool incremental) +bool HelpViewerFindSupport::find(const QString &txt, + Find::IFindSupport::FindFlags findFlags, bool incremental) { QTC_ASSERT(m_viewer, return false); -#if !defined(QT_NO_WEBKIT) - Q_UNUSED(incremental) - QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument; - if (findFlags & Find::IFindSupport::FindBackward) - options |= QWebPage::FindBackward; - if (findFlags & Find::IFindSupport::FindCaseSensitively) - options |= QWebPage::FindCaseSensitively; - - bool found = m_viewer->findText(txt, options); - options = QWebPage::HighlightAllOccurrences; - m_viewer->findText(QLatin1String(""), options); // clear first - m_viewer->findText(txt, options); // force highlighting of all other matches - return found; -#else - QTextCursor cursor = m_viewer->textCursor(); - QTextDocument *doc = m_viewer->document(); - QTextBrowser *browser = qobject_cast<QTextBrowser*>(m_viewer); - - if (!browser || !doc || cursor.isNull()) - return false; - if (incremental) - cursor.setPosition(cursor.selectionStart()); - - QTextCursor found = doc->find(txt, cursor, Find::IFindSupport::textDocumentFlagsForFindFlags(findFlags)); - if (found.isNull()) { - if ((findFlags&Find::IFindSupport::FindBackward) == 0) - cursor.movePosition(QTextCursor::Start); - else - cursor.movePosition(QTextCursor::End); - found = doc->find(txt, cursor, Find::IFindSupport::textDocumentFlagsForFindFlags(findFlags)); - if (found.isNull()) { - return false; - } - } - if (!found.isNull()) { - m_viewer->setTextCursor(found); - } - return true; -#endif + return m_viewer->findText(txt, findFlags, incremental, false); } diff --git a/src/plugins/help/helpfindsupport.h b/src/plugins/help/helpfindsupport.h index faddc99b80ba46f3a10e8b47fb0b0e2189656b20..4292381b17c12c225cdc33d096359e8a4d54f577 100644 --- a/src/plugins/help/helpfindsupport.h +++ b/src/plugins/help/helpfindsupport.h @@ -34,12 +34,11 @@ #include <find/ifindsupport.h> - -class HelpViewer; - namespace Help { namespace Internal { +class HelpViewer; + class HelpFindSupport : public Find::IFindSupport { Q_OBJECT diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index 72765ee2f4717f45ca1d2d0e0f560c1f8f73ca11..79ff2769af53c1aa46475b1187c8e3cf375be01c 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -26,6 +26,7 @@ ** contact the sales department at http://qt.nokia.com/contact. ** **************************************************************************/ + #include "helpplugin.h" #include "bookmarkmanager.h" @@ -41,6 +42,8 @@ #include "helpmode.h" #include "helpviewer.h" #include "indexwindow.h" +#include "openpagesmanager.h" +#include "openpagesmodel.h" #include "searchwidget.h" #include <coreplugin/actionmanager/actionmanager.h> @@ -83,6 +86,7 @@ # include <QtWebKit/QWebSettings> #endif +using namespace Core::Constants; using namespace Help; using namespace Help::Internal; @@ -137,88 +141,94 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error) } addAutoReleasedObject(m_helpManager = new HelpManager(this)); + addAutoReleasedObject(m_openPagesManager = new OpenPagesManager(this)); + addAutoReleasedObject(m_docSettingsPage = new DocSettingsPage()); addAutoReleasedObject(m_filterSettingsPage = new FilterSettingsPage()); addAutoReleasedObject(m_generalSettingsPage = new GeneralSettingsPage()); connect(m_docSettingsPage, SIGNAL(documentationChanged()), m_filterSettingsPage, SLOT(updateFilterPage())); - connect(m_generalSettingsPage, SIGNAL(fontChanged()), this, SLOT(fontChanged())); - connect(m_helpManager, SIGNAL(helpRequested(QString)), this, SLOT(handleHelpRequest(QString))); - connect(m_filterSettingsPage, SIGNAL(filtersChanged()), this, SLOT(setupHelpEngineIfNeeded())); - connect(m_docSettingsPage, SIGNAL(documentationChanged()), this, SLOT(setupHelpEngineIfNeeded())); + connect(m_generalSettingsPage, SIGNAL(fontChanged()), this, + SLOT(fontChanged())); + connect(m_helpManager, SIGNAL(helpRequested(QString)), this, + SLOT(handleHelpRequest(QString))); + connect(m_filterSettingsPage, SIGNAL(filtersChanged()), this, + SLOT(setupHelpEngineIfNeeded())); + connect(m_docSettingsPage, SIGNAL(documentationChanged()), this, + SLOT(setupHelpEngineIfNeeded())); m_splitter = new Core::MiniSplitter; m_centralWidget = new Help::Internal::CentralWidget(); + connect(m_centralWidget, SIGNAL(sourceChanged(QUrl)), this, + SLOT(updateSideBarSource(QUrl))); - QList<QAction*> actionList; // Add Home, Previous and Next actions (used in the toolbar) - QAction *homeAction = new QAction(QIcon(QLatin1String(IMAGEPATH "home.png")), tr("Home"), this); + QAction *action = new QAction(QIcon(QLatin1String(IMAGEPATH "home.png")), + tr("Home"), this); Core::ActionManager *am = m_core->actionManager(); - Core::Command *cmd = am->registerAction(homeAction, QLatin1String("Help.Home"), globalcontext); - connect(homeAction, SIGNAL(triggered()), m_centralWidget, SLOT(home())); - actionList << homeAction; + Core::Command *cmd = am->registerAction(action, QLatin1String("Help.Home"), + globalcontext); + connect(action, SIGNAL(triggered()), m_centralWidget, SLOT(home())); - QAction *previousAction = new QAction(QIcon(QLatin1String(IMAGEPATH "previous.png")), + action = new QAction(QIcon(QLatin1String(IMAGEPATH "previous.png")), tr("Previous Page"), this); - cmd = am->registerAction(previousAction, QLatin1String("Help.Previous"), modecontext); + cmd = am->registerAction(action, QLatin1String("Help.Previous"), modecontext); cmd->setDefaultKeySequence(QKeySequence::Back); - previousAction->setEnabled(m_centralWidget->isBackwardAvailable()); - connect(previousAction, SIGNAL(triggered()), m_centralWidget, SLOT(backward())); - connect(m_centralWidget, SIGNAL(backwardAvailable(bool)), previousAction, SLOT(setEnabled(bool))); - actionList << previousAction; + action->setEnabled(m_centralWidget->isBackwardAvailable()); + connect(action, SIGNAL(triggered()), m_centralWidget, SLOT(backward())); + connect(m_centralWidget, SIGNAL(backwardAvailable(bool)), action, + SLOT(setEnabled(bool))); - QAction *nextAction = new QAction(QIcon(QLatin1String(IMAGEPATH "next.png")), tr("Next Page"), + action = new QAction(QIcon(QLatin1String(IMAGEPATH "next.png")), tr("Next Page"), this); - cmd = am->registerAction(nextAction, QLatin1String("Help.Next"), modecontext); + cmd = am->registerAction(action, QLatin1String("Help.Next"), modecontext); cmd->setDefaultKeySequence(QKeySequence::Forward); - nextAction->setEnabled(m_centralWidget->isForwardAvailable()); - connect(nextAction, SIGNAL(triggered()), m_centralWidget, SLOT(forward())); - connect(m_centralWidget, SIGNAL(forwardAvailable(bool)), nextAction, SLOT(setEnabled(bool))); - actionList << nextAction; + action->setEnabled(m_centralWidget->isForwardAvailable()); + connect(action, SIGNAL(triggered()), m_centralWidget, SLOT(forward())); + connect(m_centralWidget, SIGNAL(forwardAvailable(bool)), action, + SLOT(setEnabled(bool))); - QAction *addBookmarkAction = new QAction(QIcon(QLatin1String(IMAGEPATH "bookmark.png")), + action = new QAction(QIcon(QLatin1String(IMAGEPATH "bookmark.png")), tr("Add Bookmark"), this); - cmd = am->registerAction(addBookmarkAction, QLatin1String("Help.AddBookmark"), + cmd = am->registerAction(action, QLatin1String("Help.AddBookmark"), modecontext); cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::Key_M)); - connect(addBookmarkAction, SIGNAL(triggered()), this, SLOT(addBookmark())); + connect(action, SIGNAL(triggered()), this, SLOT(addBookmark())); // Add Index, Contents, and Context menu items and a separator to the Help menu - QAction *indexAction = new QAction(tr("Index"), this); - cmd = am->registerAction(indexAction, QLatin1String("Help.Index"), globalcontext); - am->actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP); - connect(indexAction, SIGNAL(triggered()), this, SLOT(activateIndex())); - - QAction *contentsAction = new QAction(tr("Contents"), this); - cmd = am->registerAction(contentsAction, QLatin1String("Help.Contents"), globalcontext); - am->actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP); - connect(contentsAction, SIGNAL(triggered()), this, SLOT(activateContents())); - - QAction *contextAction = new QAction(tr("Context Help"), this); - cmd = am->registerAction(contextAction, QLatin1String("Help.Context"), globalcontext); - am->actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP); + action = new QAction(tr("Index"), this); + cmd = am->registerAction(action, QLatin1String("Help.Index"), globalcontext); + am->actionContainer(M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP); + connect(action, SIGNAL(triggered()), this, SLOT(activateIndex())); + + action = new QAction(tr("Contents"), this); + cmd = am->registerAction(action, QLatin1String("Help.Contents"), globalcontext); + am->actionContainer(M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP); + connect(action, SIGNAL(triggered()), this, SLOT(activateContents())); + + action = new QAction(tr("Context Help"), this); + cmd = am->registerAction(action, QLatin1String("Help.Context"), globalcontext); + am->actionContainer(M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP); cmd->setDefaultKeySequence(QKeySequence(Qt::Key_F1)); - connect(contextAction, SIGNAL(triggered()), this, SLOT(activateContext())); + connect(action, SIGNAL(triggered()), this, SLOT(activateContext())); #ifndef Q_WS_MAC - QAction *sep = new QAction(this); - sep->setSeparator(true); - cmd = am->registerAction(sep, QLatin1String("Help.Separator"), globalcontext); - am->actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP); - actionList << sep; + action = new QAction(this); + action->setSeparator(true); + cmd = am->registerAction(action, QLatin1String("Help.Separator"), globalcontext); + am->actionContainer(M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP); #endif - QAction *printAction = new QAction(this); - am->registerAction(printAction, Core::Constants::PRINT, modecontext); - connect(printAction, SIGNAL(triggered()), m_centralWidget, SLOT(print())); + action = new QAction(this); + am->registerAction(action, Core::Constants::PRINT, modecontext); + connect(action, SIGNAL(triggered()), m_centralWidget, SLOT(print())); - QAction *copyAction = new QAction(this); - cmd = am->registerAction(copyAction, Core::Constants::COPY, modecontext); - connect(copyAction, SIGNAL(triggered()), m_centralWidget, SLOT(copy())); - copyAction->setText(cmd->action()->text()); - copyAction->setIcon(cmd->action()->icon()); - actionList << copyAction; + action = new QAction(this); + cmd = am->registerAction(action, Core::Constants::COPY, modecontext); + connect(action, SIGNAL(triggered()), m_centralWidget, SLOT(copy())); + action->setText(cmd->action()->text()); + action->setIcon(cmd->action()->icon()); if (Core::ActionContainer *advancedMenu = am->actionContainer(Core::Constants::M_EDIT_ADVANCED)) { @@ -255,7 +265,6 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error) mainWidgetLayout->setSpacing(0); mainWidgetLayout->addWidget(createToolBar()); mainWidgetLayout->addWidget(m_centralWidget); - m_centralWidget->setGlobalActions(actionList); HelpIndexFilter *helpIndexFilter = new HelpIndexFilter(); addAutoReleasedObject(helpIndexFilter); @@ -320,24 +329,10 @@ void HelpPlugin::extensionsInitialized() m_helpManager->verifyDocumenation(); m_helpManager->registerDocumentation(filesToRegister); -#if !defined(QT_NO_WEBKIT) - QWebSettings* webSettings = QWebSettings::globalSettings(); - QFont font(QApplication::font().family(), - webSettings->fontSize(QWebSettings::DefaultFontSize)); - - font = qVariantValue<QFont>(engine->customValue(QLatin1String("font"), - font)); - - webSettings->setFontFamily(QWebSettings::StandardFont, font.family()); - webSettings->setFontSize(QWebSettings::DefaultFontSize, font.pointSize()); -#endif - const QString &url = QString::fromLatin1("qthelp://com.nokia.qtcreator." "%1%2%3/doc/index.html").arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR) .arg(IDE_VERSION_RELEASE); engine->setCustomValue(QLatin1String("DefaultHomePage"), url); - - connectCentralWidget(); connect(engine, SIGNAL(setupFinished()), this, SLOT(updateFilterComboBox())); } @@ -357,42 +352,46 @@ void HelpPlugin::setupUi() IndexWindow *indexWindow = new IndexWindow(); indexWindow->setWindowTitle(tr("Index")); m_indexItem = new Core::SideBarItem(indexWindow); - connect(indexWindow, SIGNAL(linksActivated(QMap<QString, QUrl>, QString)), m_centralWidget, - SLOT(showTopicChooser(QMap<QString, QUrl>, QString))); - connect(indexWindow, SIGNAL(linkActivated(QUrl)), m_centralWidget, SLOT(setSource(QUrl))); + + connect(indexWindow, SIGNAL(linkActivated(QUrl)), m_centralWidget, + SLOT(setSource(QUrl))); + connect(indexWindow, SIGNAL(linksActivated(QMap<QString, QUrl>, QString)), + m_centralWidget, SLOT(showTopicChooser(QMap<QString, QUrl>, QString))); QMap<QString, Core::Command*> shortcutMap; QShortcut *shortcut = new QShortcut(m_splitter); shortcut->setWhatsThis(tr("Activate Index in Help mode")); - Core::Command* cmd = am->registerShortcut(shortcut, QLatin1String("Help.IndexShortcut"), - modecontext); - cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::Key_I)); + Core::Command* cmd = am->registerShortcut(shortcut, + QLatin1String("Help.IndexShortcut"), modecontext); + cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_I)); connect(shortcut, SIGNAL(activated()), this, SLOT(activateIndex())); shortcutMap.insert(indexWindow->windowTitle(), cmd); ContentWindow *contentWindow = new ContentWindow(); contentWindow->setWindowTitle(tr("Contents")); m_contentItem = new Core::SideBarItem(contentWindow); - connect(contentWindow, SIGNAL(linkActivated(QUrl)), m_centralWidget, SLOT(setSource(QUrl))); + connect(contentWindow, SIGNAL(linkActivated(QUrl)), m_centralWidget, + SLOT(setSource(QUrl))); shortcut = new QShortcut(m_splitter); shortcut->setWhatsThis(tr("Activate Contents in Help mode")); - cmd = am->registerShortcut(shortcut, QLatin1String("Help.ContentsShortcut"), modecontext); - cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::Key_T)); + cmd = am->registerShortcut(shortcut, QLatin1String("Help.ContentsShortcut"), + modecontext); + cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C)); connect(shortcut, SIGNAL(activated()), this, SLOT(activateContents())); shortcutMap.insert(contentWindow->windowTitle(), cmd); SearchWidget *searchWidget = new SearchWidget(); searchWidget->setWindowTitle(tr("Search")); m_searchItem = new Core::SideBarItem(searchWidget); - connect(searchWidget, SIGNAL(requestShowLinkInNewTab(QUrl)), m_centralWidget, - SLOT(setSourceInNewTab(QUrl))); - connect(searchWidget, SIGNAL(requestShowLink(QUrl)), m_centralWidget, SLOT(setSource(QUrl))); + connect(searchWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget, + SLOT(setSourceFromSearch(QUrl))); // TODO: enable and find a proper keysequence as this is ambiguous // shortcut = new QShortcut(m_splitter); // shortcut->setWhatsThis(tr("Activate Search in Help mode")); - // cmd = am->registerShortcut(shortcut, QLatin1String("Help.SearchShortcut"), modecontext); + // cmd = am->registerShortcut(shortcut, QLatin1String("Help.SearchShortcut"), + // modecontext); // cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::Key_S)); // connect(shortcut, SIGNAL(activated()), this, SLOT(activateSearch())); // shortcutMap.insert(searchWidget->windowTitle(), cmd); @@ -401,20 +400,35 @@ void HelpPlugin::setupUi() BookmarkWidget *bookmarkWidget = new BookmarkWidget(manager, 0, false); bookmarkWidget->setWindowTitle(tr("Bookmarks")); m_bookmarkItem = new Core::SideBarItem(bookmarkWidget); - connect(bookmarkWidget, SIGNAL(addBookmark()), this, SLOT(addBookmark())); - connect(bookmarkWidget, SIGNAL(requestShowLink(QUrl)), m_centralWidget, SLOT(setSource(QUrl))); + connect(bookmarkWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget, + SLOT(setSource(QUrl))); // TODO: enable and find a proper keysequence as this is ambiguous // shortcut = new QShortcut(m_splitter); // shortcut->setWhatsThis(tr("Activate Bookmarks in Help mode")); - // cmd = am->registerShortcut(shortcut, QLatin1String("Help.BookmarkShortcut"), modecontext); + // cmd = am->registerShortcut(shortcut, QLatin1String("Help.BookmarkShortcut"), + // modecontext); // cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::Key_B)); // connect(shortcut, SIGNAL(activated()), this, SLOT(activateBookmarks())); // shortcutMap.insert(bookmarkWidget->windowTitle(), cmd); + QWidget *openPagesWidget = OpenPagesManager::instance().openPagesWidget(); + openPagesWidget->setWindowTitle(tr("Open Pages")); + m_openPagesItem = new Core::SideBarItem(openPagesWidget); + + shortcut = new QShortcut(m_splitter); + shortcut->setWhatsThis(tr("Activate Open Pages in Help mode")); + cmd = am->registerShortcut(shortcut, QLatin1String("Help.PagesShortcut"), + modecontext); + cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_O)); + connect(shortcut, SIGNAL(activated()), this, SLOT(activateOpenPages())); + shortcutMap.insert(openPagesWidget->windowTitle(), cmd); + QList<Core::SideBarItem*> itemList; - itemList << m_contentItem << m_indexItem << m_searchItem << m_bookmarkItem; - m_sideBar = new Core::SideBar(itemList, QList<Core::SideBarItem*>() << m_indexItem); + itemList << m_contentItem << m_indexItem << m_searchItem << m_bookmarkItem + << m_openPagesItem; + m_sideBar = new Core::SideBar(itemList, QList<Core::SideBarItem*>() + << m_indexItem << m_openPagesItem); m_sideBar->setShortcutMap(shortcutMap); m_splitter->setOpaqueResize(false); @@ -433,9 +447,9 @@ void HelpPlugin::resetFilter() QHelpEngineCore *core = &m_helpManager->helpEngineCore(); if (core->customValue(weAddedFilterKey).toInt() == 1) { // we added a filter at some point, remove previously added filter - const QString &previousFilter = core->customValue(previousFilterNameKey).toString(); - if (!previousFilter.isEmpty()) - core->removeCustomFilter(previousFilter); + const QString &filter = core->customValue(previousFilterNameKey).toString(); + if (!filter.isEmpty()) + core->removeCustomFilter(filter); } // potentially remove a filter with new name @@ -447,21 +461,6 @@ void HelpPlugin::resetFilter() (&m_helpManager->helpEngine())->setCurrentFilter(filterName); } -void HelpPlugin::connectCentralWidget() -{ - connect(m_centralWidget, SIGNAL(sourceChanged(QUrl)), this, - SLOT(updateSideBarSource(QUrl))); - connect(m_centralWidget, SIGNAL(currentViewerChanged(int)), this, - SLOT(updateSideBarSource())); - connect(m_centralWidget, SIGNAL(currentViewerChanged(int)), this, - SLOT(updateViewerComboBoxIndex(int))); - connect(m_centralWidget, SIGNAL(viewerAboutToBeRemoved(int)), this, - SLOT(removeViewerFromComboBox(int))); - connect(m_centralWidget, SIGNAL(addNewBookmark(QString, QString)), this, - SLOT(addNewBookmark(QString, QString))); - connect(m_centralWidget, SIGNAL(sourceChanged(QUrl)), this, SLOT(rebuildViewerComboBox())); -} - void HelpPlugin::createRightPaneContextViewer() { if (m_helpViewerForSideBar) @@ -508,7 +507,7 @@ void HelpPlugin::createRightPaneContextViewer() rightPaneStyledBar->setLayout(hboxLayout); rightPaneLayout->addWidget(rightPaneStyledBar); - m_helpViewerForSideBar = new HelpViewer(0, rightPaneSideBar); + m_helpViewerForSideBar = new HelpViewer(qreal(0.0), rightPaneSideBar); rightPaneLayout->addWidget(m_helpViewerForSideBar); rightPaneLayout->addWidget(new Core::FindToolBarPlaceHolder(rightPaneSideBar)); rightPaneSideBar->setFocusProxy(m_helpViewerForSideBar); @@ -575,7 +574,7 @@ void HelpPlugin::modeChanged(Core::IMode *mode) setupUi(); resetFilter(); m_helpManager->setupGuiHelpEngine(); - m_centralWidget->setLastShownPages(); + OpenPagesManager::instance().setupInitialPages(); qApp->restoreOverrideCursor(); } else if (mode == m_mode && !m_firstModeChange) { @@ -587,9 +586,11 @@ void HelpPlugin::modeChanged(Core::IMode *mode) void HelpPlugin::updateSideBarSource() { - const QUrl &url = m_centralWidget->currentSource(); - if (url.isValid()) - updateSideBarSource(url); + if (HelpViewer *viewer = m_centralWidget->currentHelpViewer()) { + const QUrl &url = viewer->source(); + if (url.isValid()) + updateSideBarSource(url); + } } void HelpPlugin::updateSideBarSource(const QUrl &newUrl) @@ -598,25 +599,26 @@ void HelpPlugin::updateSideBarSource(const QUrl &newUrl) m_helpViewerForSideBar->setSource(newUrl); } -void HelpPlugin::fontChanged() +void HelpPlugin::updateCloseButton() { -#if defined(QT_NO_WEBKIT) - QFont font = qApp->font(); - const QHelpEngineCore &engine = m_helpManager->helpEngineCore(); - font = qVariantValue<QFont>(engine.customValue(QLatin1String("font"), - font)); + m_closeButton->setEnabled(OpenPagesManager::instance().pageCount() > 1); +} - if (m_helpViewerForSideBar) - m_helpViewerForSideBar->setFont(font); +void HelpPlugin::fontChanged() +{ + if (!m_helpViewerForSideBar) + createRightPaneContextViewer(); - if (m_centralWidget) { - int i = 0; - while (HelpViewer* viewer = m_centralWidget->helpViewerAtIndex(i++)) { - if (viewer->font() != font) - viewer->setFont(font); - } + const QHelpEngineCore &engine = m_helpManager->helpEngineCore(); + QFont font = qVariantValue<QFont>(engine.customValue(QLatin1String("font"), + m_helpViewerForSideBar->viewerFont())); + + m_helpViewerForSideBar->setFont(font); + const int count = OpenPagesManager::instance().pageCount(); + for (int i = 0; i < count; ++i) { + if (HelpViewer *viewer = CentralWidget::instance()->viewerAt(i)) + viewer->setViewerFont(font); } -#endif } void HelpPlugin::setupHelpEngineIfNeeded() @@ -625,31 +627,6 @@ void HelpPlugin::setupHelpEngineIfNeeded() m_helpManager->setupGuiHelpEngine(); } -void HelpPlugin::rebuildViewerComboBox() -{ - m_documentsCombo->clear(); - - int i = 0; - while (HelpViewer *viewer = m_centralWidget->helpViewerAtIndex(i++)) - m_documentsCombo->addItem(viewer->documentTitle()); - - int index = m_centralWidget->indexOf(m_centralWidget->currentHelpViewer()); - if (index >= 0) - m_documentsCombo->setCurrentIndex(index); -} - -void HelpPlugin::removeViewerFromComboBox(int index) -{ - if (index >= 0) - m_documentsCombo->removeItem(index); -} - -void HelpPlugin::updateViewerComboBoxIndex(int index) -{ - if (index >= 0) - m_documentsCombo->setCurrentIndex(index); -} - HelpViewer* HelpPlugin::viewerForContextMode() { using namespace Core; @@ -689,7 +666,7 @@ HelpViewer* HelpPlugin::viewerForContextMode() } else { activateHelpMode(); if (!viewer) - viewer = m_centralWidget->newEmptyTab(); + viewer = OpenPagesManager::instance().createPage(); } return viewer; } @@ -751,6 +728,12 @@ void HelpPlugin::activateSearch() m_sideBar->activateItem(m_searchItem); } +void HelpPlugin::activateOpenPages() +{ + activateHelpMode(); + m_sideBar->activateItem(m_openPagesItem); +} + QToolBar *HelpPlugin::createToolBar() { QToolBar *toolWidget = new QToolBar; @@ -770,20 +753,26 @@ QToolBar *HelpPlugin::createToolBar() QHBoxLayout *layout = new QHBoxLayout(w); layout->setMargin(0); layout->addSpacing(10); - m_documentsCombo = new QComboBox; - m_documentsCombo->setMinimumContentsLength(40); - layout->addWidget(m_documentsCombo); - - connect(m_documentsCombo, SIGNAL(activated(int)), m_centralWidget, - SLOT(activateTab(int))); + layout->addWidget(OpenPagesManager::instance().openPagesComboBox()); layout->addWidget(new QLabel(tr("Filtered by:"))); m_filterComboBox = new QComboBox; m_filterComboBox->setMinimumContentsLength(20); layout->addWidget(m_filterComboBox); - connect(m_filterComboBox, SIGNAL(activated(QString)), this, SLOT(filterDocumentation(QString))); + connect(m_filterComboBox, SIGNAL(currentIndexChanged(int)), this, + SLOT(updateSideBarSource())); + + m_closeButton = new QToolButton(); + m_closeButton->setIcon(QIcon(":/core/images/closebutton.png")); + m_closeButton->setToolTip(tr("Close current Page")); + connect(m_closeButton, SIGNAL(clicked()), &OpenPagesManager::instance(), + SLOT(closeCurrentPage())); + connect(&OpenPagesManager::instance(), SIGNAL(pagesChanged()), this, + SLOT(updateCloseButton())); + layout->addStretch(); + layout->addWidget(m_closeButton); return toolWidget; } @@ -809,21 +798,21 @@ void HelpPlugin::filterDocumentation(const QString &customFilter) void HelpPlugin::addBookmark() { - addNewBookmark(m_centralWidget->currentTitle(), - m_centralWidget->currentSource().toString()); -} + HelpViewer *viewer = m_centralWidget->currentHelpViewer(); -void HelpPlugin::addNewBookmark(const QString &title, const QString &url) -{ - if (url.isEmpty() || url == QLatin1String("about:blank")) + const QString &url = viewer->source().toString(); + if (url.isEmpty() || url == Help::Constants::AboutBlank) return; BookmarkManager *manager = &HelpManager::bookmarkManager(); - manager->showBookmarkDialog(m_centralWidget, title, url); + manager->showBookmarkDialog(m_centralWidget, viewer->title(), url); } void HelpPlugin::handleHelpRequest(const QString &address) { + if (HelpViewer::launchWithExternalApp(address)) + return; + if (m_helpManager->helpEngineCore().findFile(address).isValid()) { const QUrl url(address); if (url.queryItemValue(QLatin1String("view")) == QLatin1String("split")) { diff --git a/src/plugins/help/helpplugin.h b/src/plugins/help/helpplugin.h index c0425012cc3138480db9e4b3e8b17358850c7acc..11e6bf1eba88fe9e0e69005fb5939bcb534bc830 100644 --- a/src/plugins/help/helpplugin.h +++ b/src/plugins/help/helpplugin.h @@ -26,6 +26,7 @@ ** contact the sales department at http://qt.nokia.com/contact. ** **************************************************************************/ + #ifndef HELPPLUGIN_H #define HELPPLUGIN_H @@ -33,14 +34,11 @@ #include <QtCore/QMap> #include <QtCore/QStringList> -QT_BEGIN_NAMESPACE -class QAction; -class QComboBox; -class QToolBar; -class QUrl; -QT_END_NAMESPACE - -class HelpViewer; +QT_FORWARD_DECLARE_CLASS(QAction) +QT_FORWARD_DECLARE_CLASS(QComboBox) +QT_FORWARD_DECLARE_CLASS(QToolBar) +QT_FORWARD_DECLARE_CLASS(QToolButton) +QT_FORWARD_DECLARE_CLASS(QUrl) namespace Core { class ICore; @@ -57,8 +55,10 @@ namespace Internal { class CentralWidget; class DocSettingsPage; class FilterSettingsPage; -class HelpMode; class GeneralSettingsPage; +class HelpMode; +class HelpViewer; +class OpenPagesManager; class SearchWidget; class HelpPlugin : public ExtensionSystem::IPlugin @@ -78,14 +78,16 @@ public slots: private slots: void modeChanged(Core::IMode *mode); + void activateContext(); void activateIndex(); void activateContents(); void activateSearch(); + void activateOpenPages(); + + void addBookmark(); void updateFilterComboBox(); void filterDocumentation(const QString &customFilter); - void addBookmark(); - void addNewBookmark(const QString &title, const QString &url); void switchToHelpMode(); void switchToHelpMode(const QUrl &source); @@ -96,18 +98,14 @@ private slots: void updateSideBarSource(const QUrl &newUrl); void fontChanged(); + void updateCloseButton(); void setupHelpEngineIfNeeded(); - void rebuildViewerComboBox(); - void removeViewerFromComboBox(int index); - void updateViewerComboBoxIndex(int index); - private: void setupUi(); void resetFilter(); void activateHelpMode(); QToolBar *createToolBar(); - void connectCentralWidget(); HelpViewer* viewerForContextMode(); void createRightPaneContextViewer(); @@ -122,18 +120,21 @@ private: Core::SideBarItem *m_indexItem; Core::SideBarItem *m_searchItem; Core::SideBarItem *m_bookmarkItem; + Core::SideBarItem *m_openPagesItem; DocSettingsPage *m_docSettingsPage; FilterSettingsPage *m_filterSettingsPage; GeneralSettingsPage *m_generalSettingsPage; - QComboBox *m_documentsCombo; QComboBox *m_filterComboBox; Core::SideBar *m_sideBar; bool m_firstModeChange; HelpManager *m_helpManager; + OpenPagesManager *m_openPagesManager; Core::MiniSplitter *m_splitter; + + QToolButton *m_closeButton; }; } // namespace Internal diff --git a/src/plugins/help/searchwidget.cpp b/src/plugins/help/searchwidget.cpp index 378b6acfe5976923b57487782019b043905fb592..1e2536ce4b64d5392bff55f70a0c822bf08dbf28 100644 --- a/src/plugins/help/searchwidget.cpp +++ b/src/plugins/help/searchwidget.cpp @@ -29,6 +29,7 @@ #include "searchwidget.h" #include "helpmanager.h" +#include "openpagesmanager.h" #include <coreplugin/icore.h> #include <coreplugin/progressmanager/progressmanager.h> @@ -109,7 +110,7 @@ void SearchWidget::showEvent(QShowEvent *event) connect(queryWidget, SIGNAL(search()), this, SLOT(search())); connect(resultWidget, SIGNAL(requestShowLink(QUrl)), this, - SIGNAL(requestShowLink(QUrl))); + SIGNAL(linkActivated(QUrl))); connect(searchEngine, SIGNAL(searchingStarted()), this, SLOT(searchingStarted())); @@ -179,71 +180,47 @@ bool SearchWidget::eventFilter(QObject* o, QEvent *e) bool controlPressed = me->modifiers() & Qt::ControlModifier; if((me->button() == Qt::LeftButton && controlPressed) || (me->button() == Qt::MidButton)) { - emit requestShowLinkInNewTab(link); + OpenPagesManager::instance().createPageFromSearch(link); } } } return QWidget::eventFilter(o,e); } -void SearchWidget::keyPressEvent(QKeyEvent *keyEvent) -{ - if (keyEvent->key() == Qt::Key_Escape) - emit escapePressed(); -} - void SearchWidget::contextMenuEvent(QContextMenuEvent *contextMenuEvent) { - QMenu menu; - QPoint point = contextMenuEvent->globalPos(); - QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget); if (!browser) return; - point = browser->mapFromGlobal(point); + QPoint point = browser->mapFromGlobal(contextMenuEvent->globalPos()); if (!browser->rect().contains(point, true)) return; - QUrl link = browser->anchorAt(point); - - QKeySequence keySeq(QKeySequence::Copy); - QAction *copyAction = menu.addAction(tr("&Copy") + QLatin1String("\t") + - keySeq.toString(QKeySequence::NativeText)); - copyAction->setEnabled(QTextCursor(browser->textCursor()).hasSelection()); - - QAction *copyAnchorAction = menu.addAction(tr("Copy &Link Location")); - copyAnchorAction->setEnabled(!link.isEmpty() && link.isValid()); - - keySeq = QKeySequence(Qt::CTRL); - QAction *newTabAction = menu.addAction(tr("Open Link in New Tab") + - QLatin1String("\t") + keySeq.toString(QKeySequence::NativeText) + - QLatin1String("LMB")); - newTabAction->setEnabled(!link.isEmpty() && link.isValid()); - - menu.addSeparator(); + QAction *openLink = 0; + QAction *openLinkInNewTab = 0; + QAction *copyAnchorAction = 0; - keySeq = QKeySequence::SelectAll; - QAction *selectAllAction = menu.addAction(tr("Select All") + - QLatin1String("\t") + keySeq.toString(QKeySequence::NativeText)); + 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())); + } QAction *usedAction = menu.exec(mapToGlobal(contextMenuEvent->pos())); - if (usedAction == copyAction) { - QTextCursor cursor = browser->textCursor(); - if (!cursor.isNull() && cursor.hasSelection()) { - QString selectedText = cursor.selectedText(); - QMimeData *data = new QMimeData(); - data->setText(selectedText); - QApplication::clipboard()->setMimeData(data); - } - } - else if (usedAction == copyAnchorAction) { - QApplication::clipboard()->setText(link.toString()); - } - else if (usedAction == newTabAction) { - emit requestShowLinkInNewTab(link); - } - else if (usedAction == selectAllAction) { + if (usedAction == openLink) { browser->selectAll(); + } else if (usedAction == openLinkInNewTab) { + OpenPagesManager::instance().createPageFromSearch(link); + } else if (usedAction == copyAnchorAction) { + QApplication::clipboard()->setText(link.toString()); } } diff --git a/src/plugins/help/searchwidget.h b/src/plugins/help/searchwidget.h index dde21d6dc1b6346c00634fc5a181affc97efc5ae..603d8b5408aec35472f89e87f269499270406fb0 100644 --- a/src/plugins/help/searchwidget.h +++ b/src/plugins/help/searchwidget.h @@ -56,9 +56,7 @@ public: void resetZoom(); signals: - void requestShowLink(const QUrl &url); - void requestShowLinkInNewTab(const QUrl &url); - void escapePressed(); + void linkActivated(const QUrl &link); protected: void showEvent(QShowEvent *event); @@ -74,7 +72,6 @@ private slots: private: bool eventFilter(QObject* o, QEvent *e); - void keyPressEvent(QKeyEvent *keyEvent); void contextMenuEvent(QContextMenuEvent *contextMenuEvent); private: diff --git a/src/shared/help/bookmarkmanager.cpp b/src/shared/help/bookmarkmanager.cpp index 779aad1bbc7c53d2f06fc1caf11a53e46e9599ac..b3ad3dd204a17317849d92dae4014fc5fa102f6b 100644 --- a/src/shared/help/bookmarkmanager.cpp +++ b/src/shared/help/bookmarkmanager.cpp @@ -31,6 +31,7 @@ #include "centralwidget.h" #include "helpmanager.h" +#include "openpagesmanager.h" #include <QtGui/QMenu> #include <QtGui/QIcon> @@ -50,6 +51,7 @@ #include <QtGui/QDialogButtonBox> #include <QtGui/QSortFilterProxyModel> +using namespace Help::Internal; BookmarkDialog::BookmarkDialog(BookmarkManager *manager, const QString &title, const QString &url, QWidget *parent) @@ -360,7 +362,7 @@ void BookmarkWidget::activated(const QModelIndex &index) QString data = index.data(Qt::UserRole + 10).toString(); if (data != QLatin1String("Folder")) - emit requestShowLink(data); + emit linkActivated(data); } void BookmarkWidget::customContextMenuRequested(const QPoint &point) @@ -394,10 +396,10 @@ void BookmarkWidget::customContextMenuRequested(const QPoint &point) return; if (pickedAction == showItem) { - emit requestShowLink(data); + emit linkActivated(data); } else if (pickedAction == showItemNewTab) { - Help::Internal::CentralWidget::instance()->setSourceInNewTab(data); + OpenPagesManager::instance().createPage(data); } else if (pickedAction == removeItem) { bookmarkManager->removeBookmarkItem(treeView, @@ -540,13 +542,9 @@ bool BookmarkWidget::eventFilter(QObject *object, QEvent *e) if (index.isValid()) { QString data = index.data(Qt::UserRole + 10).toString(); if (!data.isEmpty() && data != QLatin1String("Folder")) - emit requestShowLink(data); + emit linkActivated(data); } } break; - - case Qt::Key_Escape: { - emit escapePressed(); - } break; } } else if (e->type() == QEvent::MouseButtonRelease) { if (index.isValid()) { @@ -556,7 +554,7 @@ bool BookmarkWidget::eventFilter(QObject *object, QEvent *e) || (me->button() == Qt::MidButton)) { QString data = index.data(Qt::UserRole + 10).toString(); if (!data.isEmpty() && data != QLatin1String("Folder")) - Help::Internal::CentralWidget::instance()->setSourceInNewTab(data); + OpenPagesManager::instance().createPage(data); } } } diff --git a/src/shared/help/bookmarkmanager.h b/src/shared/help/bookmarkmanager.h index 61884d60bab4af0580d5b3ec48f129cfa1e65d65..788f83eb9c0be9f8e5a93f980b83db4d87e3d7fc 100644 --- a/src/shared/help/bookmarkmanager.h +++ b/src/shared/help/bookmarkmanager.h @@ -115,8 +115,7 @@ public: signals: void addBookmark(); - void requestShowLink(const QUrl &url); - void escapePressed(); + void linkActivated(const QUrl &url); private slots: void removeClicked(); diff --git a/src/shared/help/contentwindow.cpp b/src/shared/help/contentwindow.cpp index 1560f27c56684dabd371cd64ceba156fc4bed0f9..e728a9a74780809a4eb24f23e131090e0fdc412b 100644 --- a/src/shared/help/contentwindow.cpp +++ b/src/shared/help/contentwindow.cpp @@ -29,8 +29,8 @@ #include "contentwindow.h" -#include "centralwidget.h" #include "helpmanager.h" +#include "openpagesmanager.h" #include <QtGui/QLayout> #include <QtGui/QFocusEvent> @@ -39,6 +39,8 @@ #include <QtHelp/QHelpEngine> #include <QtHelp/QHelpContentWidget> +using namespace Help::Internal; + ContentWindow::ContentWindow() : m_contentWidget(0) , m_expandDepth(-2) @@ -110,15 +112,12 @@ bool ContentWindow::eventFilter(QObject *o, QEvent *e) if (contentModel) { QHelpContentItem *itm = contentModel->contentItemAt(index); if (itm && !isPdfFile(itm)) - Help::Internal::CentralWidget::instance()->setSourceInNewTab(itm->url()); + OpenPagesManager::instance().createPage(itm->url()); } } else if (button == Qt::LeftButton) { itemClicked(index); } } - } else if (o == m_contentWidget && e->type() == QEvent::KeyPress) { - if (static_cast<QKeyEvent *>(e)->key() == Qt::Key_Escape) - emit escapePressed(); } return QWidget::eventFilter(o, e); } @@ -135,7 +134,7 @@ void ContentWindow::showContextMenu(const QPoint &pos) QMenu menu; QAction *curTab = menu.addAction(tr("Open Link")); - QAction *newTab = menu.addAction(tr("Open Link in New Tab")); + QAction *newTab = menu.addAction(tr("Open Link as New Page")); if (isPdfFile(itm)) newTab->setEnabled(false); @@ -145,7 +144,7 @@ void ContentWindow::showContextMenu(const QPoint &pos) if (curTab == action) emit linkActivated(itm->url()); else if (newTab == action) - Help::Internal::CentralWidget::instance()->setSourceInNewTab(itm->url()); + OpenPagesManager::instance().createPage(itm->url()); } void ContentWindow::itemClicked(const QModelIndex &index) diff --git a/src/shared/help/contentwindow.h b/src/shared/help/contentwindow.h index c86143bc60f83c47173b98052c148bd232ceb1ae..4bfd0d0f6a9a00655ebb4fe0178ff8370c675b0e 100644 --- a/src/shared/help/contentwindow.h +++ b/src/shared/help/contentwindow.h @@ -54,7 +54,6 @@ public: signals: void linkActivated(const QUrl &link); - void escapePressed(); private slots: void showContextMenu(const QPoint &pos); diff --git a/src/shared/help/help.pri b/src/shared/help/help.pri index ce6d3c088945a1cf40926a00e94df23caf41fa13..27ce8b42673b1b1a2b8dba265b97af555eedf0d6 100644 --- a/src/shared/help/help.pri +++ b/src/shared/help/help.pri @@ -8,7 +8,6 @@ HEADERS += \ $$PWD/bookmarkmanager.h \ $$PWD/contentwindow.h \ $$PWD/filternamedialog.h \ - $$PWD/helpviewer.h \ $$PWD/indexwindow.h \ $$PWD/topicchooser.h \ $$PWD/../namespace_global.h @@ -17,7 +16,6 @@ SOURCES += \ $$PWD/bookmarkmanager.cpp \ $$PWD/contentwindow.cpp \ $$PWD/filternamedialog.cpp \ - $$PWD/helpviewer.cpp \ $$PWD/indexwindow.cpp \ $$PWD/topicchooser.cpp diff --git a/src/shared/help/helpviewer.cpp b/src/shared/help/helpviewer.cpp deleted file mode 100644 index cf19931f43a6e4470f75828349931acf10a01b5a..0000000000000000000000000000000000000000 --- a/src/shared/help/helpviewer.cpp +++ /dev/null @@ -1,635 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** 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. -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#include "helpviewer.h" - -#include "centralwidget.h" -#include "helpmanager.h" - -#include <QtCore/QDir> -#include <QtCore/QEvent> -#include <QtCore/QVariant> -#include <QtCore/QByteArray> -#include <QtCore/QTimer> - -#include <QtGui/QMenu> -#include <QtGui/QKeyEvent> -#include <QtGui/QClipboard> -#include <QtGui/QApplication> -#include <QtGui/QMessageBox> -#include <QtGui/QDesktopServices> - -#include <QtHelp/QHelpEngineCore> - -#include <QNetworkAccessManager> -#include <QNetworkReply> -#include <QNetworkRequest> - -static QString PageNotFoundMessage = - QCoreApplication::translate("HelpViewer", "<title>Error 404...</title><div " - "align=\"center\"><br><br><h1>The page could not be found</h1><br><h3>'%1'" - "</h3></div>"); - -#if !defined(QT_NO_WEBKIT) - -class HelpNetworkReply : public QNetworkReply -{ -public: - HelpNetworkReply(const QNetworkRequest &request, const QByteArray &fileData, - const QString &mimeType); - - virtual void abort(); - - virtual qint64 bytesAvailable() const - { return data.length() + QNetworkReply::bytesAvailable(); } - -protected: - virtual qint64 readData(char *data, qint64 maxlen); - -private: - QByteArray data; - qint64 origLen; -}; - -HelpNetworkReply::HelpNetworkReply(const QNetworkRequest &request, - const QByteArray &fileData, const QString &mimeType) - : data(fileData), origLen(fileData.length()) -{ - setRequest(request); - setOpenMode(QIODevice::ReadOnly); - - setHeader(QNetworkRequest::ContentTypeHeader, mimeType); - setHeader(QNetworkRequest::ContentLengthHeader, QByteArray::number(origLen)); - QTimer::singleShot(0, this, SIGNAL(metaDataChanged())); - QTimer::singleShot(0, this, SIGNAL(readyRead())); -} - -void HelpNetworkReply::abort() -{ - // nothing to do -} - -qint64 HelpNetworkReply::readData(char *buffer, qint64 maxlen) -{ - qint64 len = qMin(qint64(data.length()), maxlen); - if (len) { - qMemCopy(buffer, data.constData(), len); - data.remove(0, len); - } - if (!data.length()) - QTimer::singleShot(0, this, SIGNAL(finished())); - return len; -} - -class HelpNetworkAccessManager : public QNetworkAccessManager -{ -public: - HelpNetworkAccessManager(QObject *parent); - -protected: - virtual QNetworkReply *createRequest(Operation op, - const QNetworkRequest &request, QIODevice *outgoingData = 0); -}; - -HelpNetworkAccessManager::HelpNetworkAccessManager(QObject *parent) - : QNetworkAccessManager(parent) -{ -} - -QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/, - const QNetworkRequest &request, QIODevice * /*outgoingData*/) -{ - const QUrl& url = request.url(); - QString mimeType = url.toString(); - if (mimeType.endsWith(QLatin1String(".svg")) - || mimeType.endsWith(QLatin1String(".svgz"))) { - mimeType = QLatin1String("image/svg+xml"); - } else if (mimeType.endsWith(QLatin1String(".css"))) { - mimeType = QLatin1String("text/css"); - } else if (mimeType.endsWith(QLatin1String(".js"))) { - mimeType = QLatin1String("text/javascript"); - } else if (mimeType.endsWith(QLatin1String(".txt"))) { - mimeType = QLatin1String("text/plain"); - } else { - mimeType = QLatin1String("text/html"); - } - - const QHelpEngineCore &engine = Help::HelpManager::helpEngineCore(); - const QByteArray &data = engine.findFile(url).isValid() - ? engine.fileData(url) : PageNotFoundMessage.arg(url.toString()).toUtf8(); - return new HelpNetworkReply(request, data, mimeType); -} - -class HelpPage : public QWebPage -{ - friend class HelpViewer; -public: - HelpPage(Help::Internal::CentralWidget *central, QObject *parent); - -protected: - virtual QWebPage *createWindow(QWebPage::WebWindowType); - - virtual bool acceptNavigationRequest(QWebFrame *frame, - const QNetworkRequest &request, NavigationType type); - -private: - Help::Internal::CentralWidget *centralWidget; - Qt::MouseButtons m_pressedButtons; - Qt::KeyboardModifiers m_keyboardModifiers; -}; - -HelpPage::HelpPage(Help::Internal::CentralWidget *central, QObject *parent) - : QWebPage(parent) - , centralWidget(central) - , m_pressedButtons(Qt::NoButton) - , m_keyboardModifiers(Qt::NoModifier) -{ -} - -QWebPage *HelpPage::createWindow(QWebPage::WebWindowType) -{ - return centralWidget->newEmptyTab()->page(); -} - -static bool isLocalUrl(const QUrl &url) -{ - const QString scheme = url.scheme(); - if (scheme.isEmpty() - || scheme == QLatin1String("file") - || scheme == QLatin1String("qrc") - || scheme == QLatin1String("data") - || scheme == QLatin1String("qthelp") - || scheme == QLatin1String("about")) - return true; - return false; -} - -bool HelpPage::acceptNavigationRequest(QWebFrame *, - const QNetworkRequest &request, QWebPage::NavigationType type) -{ - const QUrl &url = request.url(); - if (isLocalUrl(url)) { - const QString& path = url.path(); - if (path.endsWith(QLatin1String(".pdf"))) { - const int lastDash = path.lastIndexOf(QChar('/')); - QString fileName = QDir::tempPath() + QDir::separator(); - if (lastDash < 0) - fileName += path; - else - fileName += path.mid(lastDash + 1, path.length()); - - QFile tmpFile(QDir::cleanPath(fileName)); - if (tmpFile.open(QIODevice::ReadWrite)) { - tmpFile.write(Help::HelpManager::helpEngineCore().fileData(url)); - tmpFile.close(); - } - QDesktopServices::openUrl(QUrl(tmpFile.fileName())); - return false; - } - - if (type == QWebPage::NavigationTypeLinkClicked - && (m_keyboardModifiers & Qt::ControlModifier - || m_pressedButtons == Qt::MidButton)) { - HelpViewer* viewer = centralWidget->newEmptyTab(); - if (viewer) - centralWidget->setSource(url); - m_pressedButtons = Qt::NoButton; - m_keyboardModifiers = Qt::NoModifier; - return false; - } - return true; - } - - QDesktopServices::openUrl(url); - return false; -} - -HelpViewer::HelpViewer(Help::Internal::CentralWidget *central, QWidget *parent) - : QWebView(parent) - , parentWidget(central) - , multiTabsAllowed(true) - , loadFinished(false) -{ - setPage(new HelpPage(central, this)); - settings()->setAttribute(QWebSettings::PluginsEnabled, false); - settings()->setAttribute(QWebSettings::JavaEnabled, false); - - page()->setNetworkAccessManager(new HelpNetworkAccessManager(this)); - - QAction* action = pageAction(QWebPage::OpenLinkInNewWindow); - action->setText(tr("Open Link in New Tab")); - if (!central) { - multiTabsAllowed = false; - action->setVisible(false); - } - - pageAction(QWebPage::DownloadLinkToDisk)->setVisible(false); - pageAction(QWebPage::DownloadImageToDisk)->setVisible(false); - pageAction(QWebPage::OpenImageInNewWindow)->setVisible(false); - - connect(pageAction(QWebPage::Copy), SIGNAL(changed()), this, - SLOT(actionChanged())); - connect(pageAction(QWebPage::Back), SIGNAL(changed()), this, - SLOT(actionChanged())); - connect(pageAction(QWebPage::Forward), SIGNAL(changed()), this, - SLOT(actionChanged())); - connect(page(), SIGNAL(linkHovered(QString, QString, QString)), this, - SIGNAL(highlighted(QString))); - connect(this, SIGNAL(urlChanged(QUrl)), this, SIGNAL(sourceChanged(QUrl))); - connect(this, SIGNAL(loadFinished(bool)), this, SLOT(setLoadFinished(bool))); - setAcceptDrops(false); -} - -void HelpViewer::setSource(const QUrl &url) -{ - loadFinished = false; - if (!homeUrl.isValid()) - homeUrl = url; - load(url); -} - -void HelpViewer::resetZoom() -{ - setTextSizeMultiplier(1.0); -} - -void HelpViewer::zoomIn(int range) -{ - setTextSizeMultiplier(qMin(2.0, textSizeMultiplier() + range / 10.0)); -} - -void HelpViewer::zoomOut(int range) -{ - setTextSizeMultiplier(qMax(0.5, textSizeMultiplier() - range / 10.0)); -} - -int HelpViewer::zoom() const -{ - qreal zoom = textSizeMultiplier() * 10.0; - return (zoom < 10.0 ? zoom * -1.0 : zoom - 10.0); -} - -void HelpViewer::home() -{ - const QHelpEngineCore &engine = Help::HelpManager::helpEngineCore(); - QString homepage = engine.customValue(QLatin1String("HomePage"), - QLatin1String("")).toString(); - - if (homepage.isEmpty()) { - homepage = engine.customValue(QLatin1String("DefaultHomePage"), - QLatin1String("about:blank")).toString(); - } - - setSource(homepage); -} - -// TODO: remove this once we support multiple keysequences per command -void HelpViewer::keyPressEvent(QKeyEvent *e) -{ - if (e->key() == Qt::Key_Insert && e->modifiers() == Qt::CTRL) { - if (hasSelection()) - copy(); - } - - QWebView::keyPressEvent(e); -} - -void HelpViewer::wheelEvent(QWheelEvent *e) -{ - if (e->modifiers() & Qt::ControlModifier) { - const int delta = e->delta(); - if (delta > 0) - zoomIn(delta / 120); - else if (delta < 0) - zoomOut(-delta / 120); - e->accept(); - return; - } - QWebView::wheelEvent(e); -} - -bool HelpViewer::handleForwardBackwardMouseButtons(QMouseEvent *e) -{ - if (e->button() == Qt::XButton1) { - triggerPageAction(QWebPage::Back); - return true; - } - if (e->button() == Qt::XButton2) { - triggerPageAction(QWebPage::Forward); - return true; - } - - return false; -} - -void HelpViewer::mouseReleaseEvent(QMouseEvent *e) -{ -#ifndef Q_OS_LINUX - if (handleForwardBackwardMouseButtons(e)) - return; -#endif - - QWebView::mouseReleaseEvent(e); -} - -void HelpViewer::actionChanged() -{ - QAction *a = qobject_cast<QAction *>(sender()); - if (a == pageAction(QWebPage::Copy)) - emit copyAvailable(a->isEnabled()); - else if (a == pageAction(QWebPage::Back)) - emit backwardAvailable(a->isEnabled()); - else if (a == pageAction(QWebPage::Forward)) - emit forwardAvailable(a->isEnabled()); -} - -void HelpViewer::mousePressEvent(QMouseEvent *event) -{ - HelpPage *currentPage = static_cast<HelpPage*>(page()); - if ((currentPage != 0) && multiTabsAllowed) { - currentPage->m_pressedButtons = event->buttons(); - currentPage->m_keyboardModifiers = event->modifiers(); - } - -#ifdef Q_OS_LINUX - if (handleForwardBackwardMouseButtons(event)) - return; -#endif - - QWebView::mousePressEvent(event); -} - -void HelpViewer::setLoadFinished(bool ok) -{ - loadFinished = ok; - emit sourceChanged(url()); -} - -#else // !defined(QT_NO_WEBKIT) - -HelpViewer::HelpViewer(Help::Internal::CentralWidget *central, QWidget *parent) - : QTextBrowser(parent) - , zoomCount(0) - , controlPressed(false) - , lastAnchor(QString()) - , parentWidget(central) -{ - document()->setDocumentMargin(8); -} - -void HelpViewer::setSource(const QUrl &url) -{ - bool help = url.toString() == QLatin1String("help"); - if (url.isValid() && !help) { - if (launchedWithExternalApp(url)) - return; - - QUrl u = Help::HelpManager::helpEngineCore().findFile(url); - if (u.isValid()) { - if (!homeUrl.isValid()) - homeUrl = url; - QTextBrowser::setSource(u); - return; - } - } - - if (help) { - QTextBrowser::setSource(QUrl(QLatin1String("qthelp://com.trolltech.com." - "assistantinternal_1.0.0/assistant/assistant.html"))); - } else { - QTextBrowser::setSource(url); - setHtml(PageNotFoundMessage.arg(url.toString())); - emit sourceChanged(url); - } -} - -void HelpViewer::resetZoom() -{ - if (zoomCount == 0) - return; - - QTextBrowser::zoomOut(zoomCount); - zoomCount = 0; -} - -void HelpViewer::zoomIn(int range) -{ - if (zoomCount == 10) - return; - - QTextBrowser::zoomIn(range); - zoomCount++; -} - -void HelpViewer::zoomOut(int range) -{ - if (zoomCount == -5) - return; - - QTextBrowser::zoomOut(range); - zoomCount--; -} - -bool HelpViewer::launchedWithExternalApp(const QUrl &url) -{ - bool isPdf = url.path().endsWith(QLatin1String("pdf")); - if (url.scheme() == QLatin1String("http") - || url.scheme() == QLatin1String("ftp") - || url.scheme() == QLatin1String("mailto") || isPdf) { - bool launched = false; - if (isPdf && url.scheme() == QLatin1String("qthelp")) { - QString fileName = url.toString(); - fileName = QDir::tempPath() + QDir::separator() + fileName.right - (fileName.length() - fileName.lastIndexOf(QChar('/'))); - - QFile tmpFile(QDir::cleanPath(fileName)); - if (tmpFile.open(QIODevice::ReadWrite)) { - tmpFile.write(Help::HelpManager::helpEngineCore().fileData(url)); - tmpFile.close(); - } - launched = QDesktopServices::openUrl(QUrl(tmpFile.fileName())); - } else { - launched = QDesktopServices::openUrl(url); - } - - if (!launched) { - QMessageBox::information(this, tr("Help"), - tr("Unable to launch external application.\n"), tr("OK")); - } - return true; - } - return false; -} - -QVariant HelpViewer::loadResource(int type, const QUrl &name) -{ - QByteArray ba; - if (type < 4) { - ba = Help::HelpManager::helpEngineCore().fileData(name); - if (name.toString().endsWith(QLatin1String(".svg"), Qt::CaseInsensitive)) { - QImage image; - image.loadFromData(ba, "svg"); - if (!image.isNull()) - return image; - } - } - return ba; -} - -void HelpViewer::openLinkInNewTab() -{ - if (lastAnchor.isEmpty()) - return; - - parentWidget->setSourceInNewTab(QUrl(lastAnchor)); - lastAnchor.clear(); -} - -void HelpViewer::openLinkInNewTab(const QString &link) -{ - lastAnchor = link; - openLinkInNewTab(); -} - -bool HelpViewer::hasAnchorAt(const QPoint& pos) -{ - lastAnchor = anchorAt(pos); - if (lastAnchor.isEmpty()) - return false; - - lastAnchor = source().resolved(lastAnchor).toString(); - if (lastAnchor.at(0) == QLatin1Char('#')) { - QString src = source().toString(); - int hsh = src.indexOf(QLatin1Char('#')); - lastAnchor = (hsh>=0 ? src.left(hsh) : src) + lastAnchor; - } - - return true; -} - -void HelpViewer::contextMenuEvent(QContextMenuEvent *e) -{ - QMenu menu(QLatin1String(""), 0); - - QUrl link; - QAction *copyAnchorAction = 0; - if (hasAnchorAt(e->pos())) { - link = anchorAt(e->pos()); - if (link.isRelative()) - link = source().resolved(link); - copyAnchorAction = menu.addAction(tr("Copy &Link Location")); - copyAnchorAction->setEnabled(!link.isEmpty() && link.isValid()); - - menu.addAction(tr("Open Link in New Tab\tCtrl+LMB"), this, - SLOT(openLinkInNewTab())); - menu.addSeparator(); - } - menu.addActions(parentWidget->globalActions()); - QAction *action = menu.exec(e->globalPos()); - if (action == copyAnchorAction) - QApplication::clipboard()->setText(link.toString()); -} - -bool HelpViewer::handleForwardBackwardMouseButtons(QMouseEvent *e) -{ - if (e->button() == Qt::XButton1) { - QTextBrowser::backward(); - return true; - } - if (e->button() == Qt::XButton2) { - QTextBrowser::forward(); - return true; - } - - return false; -} - -void HelpViewer::mousePressEvent(QMouseEvent *e) -{ -#ifdef Q_OS_LINUX - if (handleForwardBackwardMouseButtons(e)) - return; -#endif - QTextBrowser::mousePressEvent(e); -} - -void HelpViewer::mouseReleaseEvent(QMouseEvent *e) -{ -#ifndef Q_OS_LINUX - if (handleForwardBackwardMouseButtons(e)) - return; -#endif - - controlPressed = e->modifiers() & Qt::ControlModifier; - if ((controlPressed && hasAnchorAt(e->pos())) || - (e->button() == Qt::MidButton && hasAnchorAt(e->pos()))) { - openLinkInNewTab(); - return; - } - - QTextBrowser::mouseReleaseEvent(e); -} - -void HelpViewer::keyPressEvent(QKeyEvent *e) -{ - if ((e->key() == Qt::Key_Home && e->modifiers() != Qt::NoModifier) - || (e->key() == Qt::Key_End && e->modifiers() != Qt::NoModifier)) { - QKeyEvent* event = new QKeyEvent(e->type(), e->key(), Qt::NoModifier, - e->text(), e->isAutoRepeat(), e->count()); - e = event; - } - QTextBrowser::keyPressEvent(e); -} - -void HelpViewer::home() -{ - const QHelpEngineCore &engine = Help::HelpManager::helpEngineCore(); - QString homepage = engine.customValue(QLatin1String("HomePage"), - QLatin1String("")).toString(); - - if (homepage.isEmpty()) { - homepage = engine.customValue(QLatin1String("DefaultHomePage"), - QLatin1String("about:blank")).toString(); - } - - setSource(homepage); -} - -void HelpViewer::wheelEvent(QWheelEvent *e) -{ - if (e->modifiers() == Qt::CTRL) { - e->accept(); - (e->delta() > 0) ? zoomIn() : zoomOut(); - } else { - e->ignore(); - QTextBrowser::wheelEvent(e); - } -} - -#endif // !defined(QT_NO_WEBKIT) diff --git a/src/shared/help/helpviewer.h b/src/shared/help/helpviewer.h deleted file mode 100644 index f5847f4f4de1ddb4d6720f91913aac994e11a84f..0000000000000000000000000000000000000000 --- a/src/shared/help/helpviewer.h +++ /dev/null @@ -1,176 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** 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. -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#ifndef HELPVIEWER_H -#define HELPVIEWER_H - -#include <QtCore/QUrl> -#include <QtCore/QVariant> -#include <QtGui/QTextBrowser> -#include <QtGui/QAction> - -#if !defined(QT_NO_WEBKIT) -#include <QWebView> -#endif - -QT_BEGIN_NAMESPACE - - -class QPoint; -class QString; -class QKeyEvent; -class QMouseEvent; -class QContextMenuEvent; - -QT_END_NAMESPACE - -namespace Help { -namespace Internal { - class CentralWidget; -} // namespace Internal -} // namespace Help - -#if !defined(QT_NO_WEBKIT) - -class HelpViewer : public QWebView -{ - Q_OBJECT - -public: - HelpViewer(Help::Internal::CentralWidget *central, QWidget *parent); - void setSource(const QUrl &url); - - inline QUrl source() const - { return url(); } - - inline QString documentTitle() const - { return title(); } - - inline bool hasSelection() const - { return !selectedText().isEmpty(); } // ### this is suboptimal - - void zoomIn(int range = 1); - void zoomOut(int range = 1); - - void resetZoom(); - int zoom() const; - void setZoom(int zoom) { zoomIn(zoom); } - - inline bool isForwardAvailable() const - { return pageAction(QWebPage::Forward)->isEnabled(); } - inline bool isBackwardAvailable() const - { return pageAction(QWebPage::Back)->isEnabled(); } - inline bool hasLoadFinished() const - { return loadFinished; } - -public Q_SLOTS: - void home(); - void backward() { back(); } - void copy() { triggerPageAction(QWebPage::Copy); } - -Q_SIGNALS: - void copyAvailable(bool enabled); - void forwardAvailable(bool enabled); - void backwardAvailable(bool enabled); - void highlighted(const QString &); - void sourceChanged(const QUrl &); - -protected: - void keyPressEvent(QKeyEvent *e); - - void wheelEvent(QWheelEvent *e); - void mouseReleaseEvent(QMouseEvent *e); - void mousePressEvent(QMouseEvent *event); - -private Q_SLOTS: - void actionChanged(); - void setLoadFinished(bool ok); - -private: - bool handleForwardBackwardMouseButtons(QMouseEvent *e); - - Help::Internal::CentralWidget* parentWidget; - QUrl homeUrl; - bool multiTabsAllowed; - bool loadFinished; -}; - -#else - -class HelpViewer : public QTextBrowser -{ - Q_OBJECT - -public: - HelpViewer(Help::Internal::CentralWidget *central, QWidget *parent); - void setSource(const QUrl &url); - - void zoomIn(int range = 1); - void zoomOut(int range = 1); - - void resetZoom(); - int zoom() const { return zoomCount; } - void setZoom(int zoom) { zoomCount = zoom; } - - inline bool hasSelection() const - { return textCursor().hasSelection(); } - - bool launchedWithExternalApp(const QUrl &url); - -public Q_SLOTS: - void home(); - -protected: - void wheelEvent(QWheelEvent *e); - -private: - QVariant loadResource(int type, const QUrl &name); - void openLinkInNewTab(const QString &link); - bool hasAnchorAt(const QPoint& pos); - void contextMenuEvent(QContextMenuEvent *e); - void mousePressEvent(QMouseEvent *e); - void mouseReleaseEvent(QMouseEvent *e); - void keyPressEvent(QKeyEvent *e); - -private slots: - void openLinkInNewTab(); - -private: - bool handleForwardBackwardMouseButtons(QMouseEvent *e); - - int zoomCount; - bool controlPressed; - QString lastAnchor; - Help::Internal::CentralWidget* parentWidget; - QUrl homeUrl; -}; - -#endif - -#endif diff --git a/src/shared/help/indexwindow.cpp b/src/shared/help/indexwindow.cpp index dcb99e22ed5a50cc3054cc31c5c36feb454fc7f0..0b9bf0935f0fb2d2a3fa9edf24f60a980d6ebb8b 100644 --- a/src/shared/help/indexwindow.cpp +++ b/src/shared/help/indexwindow.cpp @@ -28,8 +28,10 @@ **************************************************************************/ #include "centralwidget.h" + #include "helpmanager.h" #include "indexwindow.h" +#include "openpagesmanager.h" #include "topicchooser.h" #include <QtGui/QLayout> @@ -43,6 +45,8 @@ #include <QtHelp/QHelpEngine> #include <QtHelp/QHelpIndexWidget> +using namespace Help::Internal; + IndexWindow::IndexWindow() : m_searchLineEdit(0) , m_indexWidget(0) @@ -108,9 +112,6 @@ bool IndexWindow::eventFilter(QObject *obj, QEvent *e) if (idx.isValid()) m_indexWidget->setCurrentIndex(idx); break; - case Qt::Key_Escape: - emit escapePressed(); - break; default: ; // stop complaining } } else if (obj == m_searchLineEdit @@ -124,7 +125,7 @@ bool IndexWindow::eventFilter(QObject *obj, QEvent *e) if (idx.isValid()) { QMenu menu; QAction *curTab = menu.addAction(tr("Open Link")); - QAction *newTab = menu.addAction(tr("Open Link in New Tab")); + QAction *newTab = menu.addAction(tr("Open Link as New Page")); menu.move(m_indexWidget->mapToGlobal(ctxtEvent->pos())); QAction *action = menu.exec(); @@ -194,6 +195,6 @@ void IndexWindow::open(QHelpIndexWidget* indexWidget, const QModelIndex &index) if (url.path().endsWith(QLatin1String(".pdf"), Qt::CaseInsensitive)) Help::Internal::CentralWidget::instance()->setSource(url); else - Help::Internal::CentralWidget::instance()->setSourceInNewTab(url); + OpenPagesManager::instance().createPage(url); } } diff --git a/src/shared/help/indexwindow.h b/src/shared/help/indexwindow.h index a6bc991bc63db3189906ab88effe9c4957be473e..404daad1ca520bbae43274392a942105efe1d37a 100644 --- a/src/shared/help/indexwindow.h +++ b/src/shared/help/indexwindow.h @@ -59,7 +59,6 @@ signals: void linkActivated(const QUrl &link); void linksActivated(const QMap<QString, QUrl> &links, const QString &keyword); - void escapePressed(); private slots: void filterIndices(const QString &filter);