2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-06-17 00:01:27 +10:00
|
|
|
** contact the sales department at http://www.qtsoftware.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include "centralwidget.h"
|
|
|
|
|
#include "helpviewer.h"
|
|
|
|
|
#include "topicchooser.h"
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
#include <QtCore/QEvent>
|
|
|
|
|
#include <QtCore/QTimer>
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QMenu>
|
|
|
|
|
#include <QtGui/QLabel>
|
|
|
|
|
#include <QtGui/QLayout>
|
|
|
|
|
#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 <QtHelp/QHelpEngine>
|
|
|
|
|
|
2009-01-28 16:04:09 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
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;
|
|
|
|
|
}
|
2009-05-07 15:34:52 +02:00
|
|
|
Help::Internal::CentralWidget *staticCentralWidget = 0;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CentralWidget::CentralWidget(QHelpEngine *engine, QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
, findBar(0)
|
|
|
|
|
, tabWidget(0)
|
|
|
|
|
, helpEngine(engine)
|
|
|
|
|
, printer(0)
|
|
|
|
|
{
|
|
|
|
|
lastTabPage = 0;
|
|
|
|
|
globalActionList.clear();
|
|
|
|
|
collectionFile = helpEngine->collectionFile();
|
|
|
|
|
|
|
|
|
|
#ifdef Q_OS_MAC
|
2009-06-03 20:45:49 +02:00
|
|
|
# define SYSTEM "mac"
|
|
|
|
|
#else
|
|
|
|
|
# define SYSTEM "win"
|
2008-12-02 12:01:29 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
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"));
|
2009-06-03 20:45:49 +02:00
|
|
|
newTabButton->setIcon(QIcon(QString::fromLatin1(":/trolltech/assistant/images/" SYSTEM "/addtab.png")));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
tabWidget->setCornerWidget(newTabButton, Qt::TopLeftCorner);
|
|
|
|
|
connect(newTabButton, SIGNAL(clicked()), this, SLOT(newTab()));
|
|
|
|
|
|
|
|
|
|
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);
|
2009-06-02 18:41:12 +02:00
|
|
|
connect(tabBar, SIGNAL(customContextMenuRequested(QPoint)), this,
|
|
|
|
|
SLOT(showTabBarContextMenu(QPoint)));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
staticCentralWidget = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CentralWidget::~CentralWidget()
|
|
|
|
|
{
|
|
|
|
|
QDir dir;
|
|
|
|
|
QString currentPages;
|
|
|
|
|
QHelpEngineCore engine(collectionFile, 0);
|
|
|
|
|
|
|
|
|
|
if (engine.setupData()) {
|
|
|
|
|
for (int i = 0; i < tabWidget->count(); ++i) {
|
|
|
|
|
HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i));
|
|
|
|
|
if (viewer && viewer->source().isValid())
|
|
|
|
|
currentPages.append(viewer->source().toString()).append(QLatin1Char('|'));
|
|
|
|
|
}
|
|
|
|
|
engine.setCustomValue(QLatin1String("LastTabPage"), lastTabPage);
|
|
|
|
|
engine.setCustomValue(QLatin1String("LastShownPages"), currentPages);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CentralWidget *CentralWidget::instance()
|
|
|
|
|
{
|
|
|
|
|
return staticCentralWidget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::newTab()
|
|
|
|
|
{
|
|
|
|
|
HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
if (viewer)
|
|
|
|
|
setSourceInNewTab(viewer->source());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::zoomIn()
|
|
|
|
|
{
|
|
|
|
|
HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
if (viewer)
|
|
|
|
|
viewer->zoomIn();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::zoomOut()
|
|
|
|
|
{
|
|
|
|
|
HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
if (viewer)
|
|
|
|
|
viewer->zoomOut();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::nextPage()
|
|
|
|
|
{
|
|
|
|
|
if (tabWidget->currentIndex() < tabWidget->count() -1)
|
|
|
|
|
tabWidget->setCurrentIndex(tabWidget->currentIndex() +1);
|
|
|
|
|
else
|
|
|
|
|
tabWidget->setCurrentIndex(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::resetZoom()
|
|
|
|
|
{
|
|
|
|
|
HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
if (viewer)
|
|
|
|
|
viewer->resetZoom();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::previousPage()
|
|
|
|
|
{
|
|
|
|
|
int index = tabWidget->currentIndex() -1;
|
|
|
|
|
if (index >= 0)
|
|
|
|
|
tabWidget->setCurrentIndex(index);
|
|
|
|
|
else
|
|
|
|
|
tabWidget->setCurrentIndex(tabWidget->count() -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::closeTab()
|
|
|
|
|
{
|
|
|
|
|
closeTab(tabWidget->currentIndex());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::closeTab(int index)
|
|
|
|
|
{
|
|
|
|
|
HelpViewer* viewer = helpViewerAtIndex(index);
|
|
|
|
|
if (!viewer || tabWidget->count() == 1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
tabWidget->removeTab(index);
|
|
|
|
|
QTimer::singleShot(0, viewer, SLOT(deleteLater()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::setSource(const QUrl &url)
|
|
|
|
|
{
|
|
|
|
|
HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
HelpViewer* lastViewer = qobject_cast<HelpViewer*>(tabWidget->widget(lastTabPage));
|
|
|
|
|
|
|
|
|
|
if (!viewer && !lastViewer) {
|
|
|
|
|
viewer = new HelpViewer(helpEngine, 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()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::setLastShownPages()
|
|
|
|
|
{
|
2009-01-28 16:04:09 +01:00
|
|
|
const QStringList lastShownPageList =
|
|
|
|
|
helpEngine->customValue(QLatin1String("LastShownPages")). toString().
|
|
|
|
|
split(QLatin1Char('|'), QString::SkipEmptyParts);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
if (!lastShownPageList.isEmpty()) {
|
2009-01-28 16:04:09 +01:00
|
|
|
foreach (const QString& page, lastShownPageList)
|
2008-12-02 12:01:29 +01:00
|
|
|
setSourceInNewTab(page);
|
|
|
|
|
|
2009-01-28 16:04:09 +01:00
|
|
|
tabWidget->setCurrentIndex(helpEngine->
|
|
|
|
|
customValue(QLatin1String("LastTabPage"), 0).toInt());
|
2008-12-02 12:01:29 +01:00
|
|
|
} else {
|
2009-01-28 16:04:09 +01:00
|
|
|
QUrl url(helpEngine->findFile(QUrl("qthelp://com.trolltech.qt.440/qdoc/index.html")));
|
|
|
|
|
if (!url.isValid()) {
|
|
|
|
|
url.setUrl(QString("qthelp://com.nokia.qtcreator.%1%2/doc/index.html").
|
|
|
|
|
arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR));
|
|
|
|
|
}
|
|
|
|
|
setSource(url);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CentralWidget::hasSelection() const
|
|
|
|
|
{
|
|
|
|
|
const HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
return viewer ? viewer->hasSelection() : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QUrl CentralWidget::currentSource() const
|
|
|
|
|
{
|
|
|
|
|
const HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
if (viewer)
|
|
|
|
|
return viewer->source();
|
|
|
|
|
|
|
|
|
|
return QUrl();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CentralWidget::currentTitle() const
|
|
|
|
|
{
|
|
|
|
|
const HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
if (viewer)
|
|
|
|
|
return viewer->documentTitle();
|
|
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::copySelection()
|
|
|
|
|
{
|
|
|
|
|
HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
if (viewer)
|
|
|
|
|
viewer->copy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::initPrinter()
|
|
|
|
|
{
|
|
|
|
|
#ifndef QT_NO_PRINTER
|
|
|
|
|
if (!printer)
|
|
|
|
|
printer = new QPrinter(QPrinter::HighResolution);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::print()
|
|
|
|
|
{
|
|
|
|
|
#ifndef QT_NO_PRINTER
|
|
|
|
|
HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
if (!viewer)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
initPrinter();
|
|
|
|
|
|
|
|
|
|
QPrintDialog *dlg = new QPrintDialog(printer, this);
|
2008-12-02 13:38:31 +01:00
|
|
|
#if defined(QT_NO_WEBKIT)
|
2008-12-02 12:01:29 +01:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::printPreview()
|
|
|
|
|
{
|
|
|
|
|
#ifndef QT_NO_PRINTER
|
|
|
|
|
initPrinter();
|
|
|
|
|
QPrintPreviewDialog preview(printer, this);
|
2009-06-02 18:41:12 +02:00
|
|
|
connect(&preview, SIGNAL(paintRequested(QPrinter*)),
|
|
|
|
|
SLOT(printPreview(QPrinter*)));
|
2008-12-02 12:01:29 +01:00
|
|
|
preview.exec();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::printPreview(QPrinter *p)
|
|
|
|
|
{
|
|
|
|
|
#ifndef QT_NO_PRINTER
|
|
|
|
|
HelpViewer *viewer = currentHelpViewer();
|
|
|
|
|
if (viewer)
|
|
|
|
|
viewer->print(p);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::pageSetup()
|
|
|
|
|
{
|
|
|
|
|
#ifndef QT_NO_PRINTER
|
|
|
|
|
initPrinter();
|
|
|
|
|
QPageSetupDialog dlg(printer);
|
|
|
|
|
dlg.exec();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CentralWidget::isHomeAvailable() const
|
|
|
|
|
{
|
|
|
|
|
return currentHelpViewer() ? true : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::home()
|
|
|
|
|
{
|
|
|
|
|
HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
if (viewer)
|
|
|
|
|
viewer->home();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CentralWidget::isForwardAvailable() const
|
|
|
|
|
{
|
|
|
|
|
const HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
if (viewer)
|
|
|
|
|
return viewer->isForwardAvailable();
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::forward()
|
|
|
|
|
{
|
|
|
|
|
HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
if (viewer)
|
|
|
|
|
viewer->forward();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CentralWidget::isBackwardAvailable() const
|
|
|
|
|
{
|
|
|
|
|
const HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
if (viewer)
|
|
|
|
|
return viewer->isBackwardAvailable();
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::backward()
|
|
|
|
|
{
|
|
|
|
|
HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
if (viewer)
|
|
|
|
|
viewer->backward();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QList<QAction*> CentralWidget::globalActions() const
|
|
|
|
|
{
|
|
|
|
|
return globalActionList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::setGlobalActions(const QList<QAction*> &actions)
|
|
|
|
|
{
|
|
|
|
|
globalActionList = actions;
|
|
|
|
|
}
|
2009-01-28 16:04:09 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void CentralWidget::setSourceInNewTab(const QUrl &url)
|
|
|
|
|
{
|
|
|
|
|
HelpViewer* viewer = new HelpViewer(helpEngine, this);
|
|
|
|
|
viewer->installEventFilter(this);
|
|
|
|
|
viewer->setSource(url);
|
|
|
|
|
viewer->setFocus(Qt::OtherFocusReason);
|
2009-01-28 16:04:09 +01:00
|
|
|
tabWidget->setCurrentIndex(tabWidget->addTab(viewer,
|
|
|
|
|
quoteTabTitle(viewer->documentTitle())));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
connectSignals();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HelpViewer *CentralWidget::newEmptyTab()
|
|
|
|
|
{
|
|
|
|
|
HelpViewer* viewer = new HelpViewer(helpEngine, this);
|
|
|
|
|
viewer->installEventFilter(this);
|
|
|
|
|
viewer->setFocus(Qt::OtherFocusReason);
|
2008-12-02 13:38:31 +01:00
|
|
|
#if defined(QT_NO_WEBKIT)
|
2008-12-02 12:01:29 +01:00
|
|
|
viewer->setDocumentTitle(tr("unknown"));
|
|
|
|
|
#endif
|
|
|
|
|
tabWidget->setCurrentIndex(tabWidget->addTab(viewer, tr("unknown")));
|
|
|
|
|
|
|
|
|
|
connectSignals();
|
|
|
|
|
return viewer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::connectSignals()
|
|
|
|
|
{
|
|
|
|
|
const HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
if (viewer) {
|
2009-06-02 18:41:12 +02:00
|
|
|
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)));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HelpViewer *CentralWidget::helpViewerAtIndex(int index) const
|
|
|
|
|
{
|
|
|
|
|
return qobject_cast<HelpViewer*>(tabWidget->widget(index));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HelpViewer *CentralWidget::currentHelpViewer() const
|
|
|
|
|
{
|
|
|
|
|
return qobject_cast<HelpViewer*>(tabWidget->currentWidget());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::activateTab(bool onlyHelpViewer)
|
|
|
|
|
{
|
|
|
|
|
if (currentHelpViewer()) {
|
|
|
|
|
currentHelpViewer()->setFocus();
|
|
|
|
|
} else {
|
|
|
|
|
int idx = 0;
|
|
|
|
|
if (onlyHelpViewer)
|
|
|
|
|
idx = lastTabPage;
|
|
|
|
|
tabWidget->setCurrentIndex(idx);
|
|
|
|
|
tabWidget->currentWidget()->setFocus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::setTabTitle(const QUrl& url)
|
|
|
|
|
{
|
|
|
|
|
int tab = lastTabPage;
|
|
|
|
|
HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
|
2008-12-02 13:38:31 +01:00
|
|
|
#if !defined(QT_NO_WEBKIT)
|
2008-12-02 12:01:29 +01:00
|
|
|
if (!viewer || viewer->source() != url) {
|
|
|
|
|
QTabBar *tabBar = qFindChild<QTabBar*>(tabWidget);
|
|
|
|
|
for (tab = 0; tab < tabBar->count(); ++tab) {
|
|
|
|
|
viewer = qobject_cast<HelpViewer*>(tabWidget->widget(tab));
|
|
|
|
|
if (viewer && viewer->source() == url)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (viewer) {
|
|
|
|
|
tabWidget->setTabText(tab,
|
|
|
|
|
quoteTabTitle(viewer->documentTitle().trimmed()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::currentPageChanged(int index)
|
|
|
|
|
{
|
|
|
|
|
const HelpViewer *viewer = currentHelpViewer();
|
|
|
|
|
|
|
|
|
|
if (viewer || tabWidget->count() == 1)
|
|
|
|
|
lastTabPage = index;
|
|
|
|
|
|
|
|
|
|
bool enabled = false;
|
|
|
|
|
if (viewer)
|
|
|
|
|
enabled = tabWidget->count() > 1;
|
2009-01-28 16:04:09 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
tabWidget->setTabsClosable(enabled);
|
|
|
|
|
tabWidget->cornerWidget(Qt::TopLeftCorner)->setEnabled(true);
|
|
|
|
|
|
|
|
|
|
emit currentViewerChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::showTabBarContextMenu(const QPoint &point)
|
|
|
|
|
{
|
|
|
|
|
HelpViewer* viewer = helpViewerFromTabPosition(tabWidget, point);
|
|
|
|
|
if (!viewer)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QTabBar *tabBar = qFindChild<QTabBar*>(tabWidget);
|
|
|
|
|
|
|
|
|
|
QMenu menu(QLatin1String(""), tabBar);
|
|
|
|
|
QAction *new_page = menu.addAction(tr("Add New Page"));
|
|
|
|
|
QAction *close_page = menu.addAction(tr("Close This Page"));
|
|
|
|
|
QAction *close_pages = menu.addAction(tr("Close Other Pages"));
|
|
|
|
|
menu.addSeparator();
|
|
|
|
|
QAction *newBookmark = menu.addAction(tr("Add Bookmark for this Page..."));
|
|
|
|
|
|
|
|
|
|
if (tabBar->count() == 1) {
|
|
|
|
|
close_page->setEnabled(false);
|
|
|
|
|
close_pages->setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-04 13:12:20 +02:00
|
|
|
const QString &url = viewer->source().toString();
|
|
|
|
|
if (url.isEmpty() || url == QLatin1String("about:blank"))
|
|
|
|
|
newBookmark->setEnabled(false);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QAction *picked_action = menu.exec(tabBar->mapToGlobal(point));
|
|
|
|
|
if (!picked_action)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (picked_action == new_page)
|
|
|
|
|
setSourceInNewTab(viewer->source());
|
|
|
|
|
|
|
|
|
|
if (picked_action == close_page) {
|
|
|
|
|
tabWidget->removeTab(tabWidget->indexOf(viewer));
|
|
|
|
|
QTimer::singleShot(0, viewer, SLOT(deleteLater()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (picked_action == close_pages) {
|
|
|
|
|
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 (picked_action == newBookmark)
|
2009-06-04 13:12:20 +02:00
|
|
|
emit addNewBookmark(viewer->documentTitle(), url);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-06-04 13:12:20 +02:00
|
|
|
// 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)
|
2008-12-02 12:01:29 +01:00
|
|
|
void CentralWidget::focusInEvent(QFocusEvent * /* event */)
|
|
|
|
|
{
|
2009-06-04 13:12:20 +02:00
|
|
|
QObject *receiver = tabWidget;
|
2008-12-02 12:01:29 +01:00
|
|
|
if (currentHelpViewer())
|
2009-06-04 13:12:20 +02:00
|
|
|
receiver = currentHelpViewer();
|
|
|
|
|
|
|
|
|
|
QTimer::singleShot(1, receiver, SLOT(setFocus()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CentralWidget::eventFilter(QObject *object, QEvent *e)
|
|
|
|
|
{
|
|
|
|
|
if (currentHelpViewer() == object && e->type() == QEvent::KeyPress){
|
|
|
|
|
QKeyEvent *ke = static_cast<QKeyEvent*>(e);
|
|
|
|
|
if (ke->key() == Qt::Key_Backspace) {
|
|
|
|
|
HelpViewer *viewer = currentHelpViewer();
|
|
|
|
|
if (viewer && viewer->isBackwardAvailable())
|
|
|
|
|
viewer->backward();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTabBar *tabBar = qobject_cast<QTabBar*>(object);
|
|
|
|
|
bool mousRel = e->type() == QEvent::MouseButtonRelease;
|
|
|
|
|
bool dblClick = e->type() == QEvent::MouseButtonDblClick;
|
|
|
|
|
|
|
|
|
|
if (tabBar && (mousRel || dblClick)) {
|
|
|
|
|
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(e);
|
|
|
|
|
HelpViewer *viewer = helpViewerFromTabPosition(tabWidget, mouseEvent->pos());
|
|
|
|
|
if (tabWidget->count() <= 1)
|
|
|
|
|
return QWidget::eventFilter(object, e);
|
|
|
|
|
|
|
|
|
|
if (viewer && (mouseEvent->button() == Qt::MidButton || dblClick)) {
|
|
|
|
|
tabWidget->removeTab(tabWidget->indexOf(viewer));
|
|
|
|
|
QTimer::singleShot(0, viewer, SLOT(deleteLater()));
|
|
|
|
|
currentPageChanged(tabWidget->currentIndex());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QWidget::eventFilter(object, e);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-28 16:04:09 +01:00
|
|
|
bool CentralWidget::find(const QString &txt, QTextDocument::FindFlags findFlags,
|
|
|
|
|
bool incremental)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
|
2008-12-02 13:38:31 +01:00
|
|
|
#if !defined(QT_NO_WEBKIT)
|
2008-12-02 12:01:29 +01:00
|
|
|
Q_UNUSED(incremental);
|
|
|
|
|
if (viewer) {
|
|
|
|
|
QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument;
|
|
|
|
|
if (findFlags & QTextDocument::FindBackward)
|
|
|
|
|
options |= QWebPage::FindBackward;
|
|
|
|
|
if (findFlags & QTextDocument::FindCaseSensitively)
|
|
|
|
|
options |= QWebPage::FindCaseSensitively;
|
|
|
|
|
|
|
|
|
|
return viewer->findText(txt, options);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
#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;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::showTopicChooser(const QMap<QString, QUrl> &links,
|
2009-01-28 16:04:09 +01:00
|
|
|
const QString &keyword)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
TopicChooser tc(this, keyword, links);
|
|
|
|
|
if (tc.exec() == QDialog::Accepted)
|
|
|
|
|
setSource(tc.link());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::copy()
|
|
|
|
|
{
|
|
|
|
|
HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
if (viewer)
|
|
|
|
|
viewer->copy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CentralWidget::quoteTabTitle(const QString &title) const
|
|
|
|
|
{
|
|
|
|
|
QString s = title;
|
|
|
|
|
return s.replace(QLatin1Char('&'), QLatin1String("&&"));
|
|
|
|
|
}
|