2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include "centralwidget.h"
|
2010-03-30 17:44:28 +02:00
|
|
|
|
2010-03-23 16:56:59 +01:00
|
|
|
#include "helpmanager.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "helpviewer.h"
|
|
|
|
|
#include "topicchooser.h"
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QEvent>
|
|
|
|
|
#include <QtCore/QTimer>
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
#include <QtGui/QKeyEvent>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QLayout>
|
2010-03-30 17:44:28 +02:00
|
|
|
#include <QtGui/QPageSetupDialog>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QPrinter>
|
|
|
|
|
#include <QtGui/QPrintDialog>
|
|
|
|
|
#include <QtGui/QPrintPreviewDialog>
|
2010-03-30 17:44:28 +02:00
|
|
|
#include <QtGui/QStackedWidget>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
#include <QtHelp/QHelpEngine>
|
2010-03-23 18:11:43 +01:00
|
|
|
#include <QtHelp/QHelpEngineCore>
|
2010-03-30 17:44:28 +02:00
|
|
|
#include <QtHelp/QHelpSearchEngine>
|
2009-01-28 16:04:09 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace Help::Internal;
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
CentralWidget *gStaticCentralWidget = 0;
|
|
|
|
|
|
|
|
|
|
// -- CentralWidget
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-03-23 18:11:43 +01:00
|
|
|
CentralWidget::CentralWidget(QWidget *parent)
|
2008-12-02 12:01:29 +01:00
|
|
|
: QWidget(parent)
|
|
|
|
|
, printer(0)
|
2010-03-30 17:44:28 +02:00
|
|
|
, m_stackedWidget(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
Q_ASSERT(!gStaticCentralWidget);
|
|
|
|
|
gStaticCentralWidget = this;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QVBoxLayout *vboxLayout = new QVBoxLayout(this);
|
|
|
|
|
vboxLayout->setMargin(0);
|
2010-03-30 17:44:28 +02:00
|
|
|
m_stackedWidget = new QStackedWidget(this);
|
|
|
|
|
vboxLayout->addWidget(m_stackedWidget);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CentralWidget::~CentralWidget()
|
|
|
|
|
{
|
2009-06-25 15:20:38 +02:00
|
|
|
#ifndef QT_NO_PRINTER
|
|
|
|
|
delete printer;
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
QString zoomFactors;
|
2009-06-25 15:20:38 +02:00
|
|
|
QString currentPages;
|
2010-03-30 17:44:28 +02:00
|
|
|
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('|');
|
2009-06-25 16:03:02 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-03-23 16:56:59 +01:00
|
|
|
|
|
|
|
|
QHelpEngineCore *engine = &HelpManager::helpEngineCore();
|
|
|
|
|
engine->setCustomValue(QLatin1String("LastShownPages"), currentPages);
|
2010-03-30 17:44:28 +02:00
|
|
|
engine->setCustomValue(QLatin1String("LastShownPagesZoom"), zoomFactors);
|
|
|
|
|
engine->setCustomValue(QLatin1String("LastTabPage"), currentIndex());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CentralWidget *CentralWidget::instance()
|
|
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
Q_ASSERT(gStaticCentralWidget);
|
|
|
|
|
return gStaticCentralWidget;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
bool CentralWidget::hasSelection() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
if (HelpViewer* viewer = currentHelpViewer())
|
|
|
|
|
return !viewer->selectedText().isEmpty();
|
|
|
|
|
return false;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
bool CentralWidget::isForwardAvailable() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
const HelpViewer* viewer = currentHelpViewer();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (viewer)
|
2010-03-30 17:44:28 +02:00
|
|
|
return viewer->isForwardAvailable();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
return false;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
bool CentralWidget::isBackwardAvailable() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
const HelpViewer* viewer = currentHelpViewer();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (viewer)
|
2010-03-30 17:44:28 +02:00
|
|
|
return viewer->isBackwardAvailable();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
return false;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
HelpViewer* CentralWidget::viewerAt(int index) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
return qobject_cast<HelpViewer*> (m_stackedWidget->widget(index));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
HelpViewer* CentralWidget::currentHelpViewer() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
return qobject_cast<HelpViewer*> (m_stackedWidget->currentWidget());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::addPage(HelpViewer *page, bool fromSearch)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
page->installEventFilter(this);
|
|
|
|
|
page->setFocus(Qt::OtherFocusReason);
|
|
|
|
|
connectSignals(page);
|
|
|
|
|
m_stackedWidget->addWidget(page);
|
|
|
|
|
if (fromSearch) {
|
|
|
|
|
connect(currentHelpViewer(), SIGNAL(loadFinished(bool)), this,
|
|
|
|
|
SLOT(highlightSearchTerms()));
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::removePage(int index)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
const bool currentChanged = (index == currentIndex());
|
|
|
|
|
m_stackedWidget->removeWidget(m_stackedWidget->widget(index));
|
|
|
|
|
if (currentChanged)
|
|
|
|
|
emit currentViewerChanged();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
int CentralWidget::currentIndex() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
return m_stackedWidget->currentIndex();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::setCurrentPage(HelpViewer *page)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
m_stackedWidget->setCurrentWidget(page);
|
|
|
|
|
emit currentViewerChanged();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
bool CentralWidget::find(const QString &txt, Find::IFindSupport::FindFlags flags,
|
|
|
|
|
bool incremental)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
return currentHelpViewer()->findText(txt, flags, incremental, false);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
// -- public slots
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::copy()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
if (HelpViewer* viewer = currentHelpViewer())
|
|
|
|
|
viewer->copy();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::home()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
if (HelpViewer* viewer = currentHelpViewer())
|
|
|
|
|
viewer->home();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::zoomIn()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
HelpViewer* viewer = currentHelpViewer();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (viewer)
|
2010-03-30 17:44:28 +02:00
|
|
|
viewer->scaleUp();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::zoomOut()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
HelpViewer* viewer = currentHelpViewer();
|
|
|
|
|
if (viewer)
|
2010-03-30 17:44:28 +02:00
|
|
|
viewer->scaleDown();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::resetZoom()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
HelpViewer* viewer = currentHelpViewer();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (viewer)
|
2010-03-30 17:44:28 +02:00
|
|
|
viewer->resetScale();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::forward()
|
|
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
if (HelpViewer* viewer = currentHelpViewer())
|
2008-12-02 12:01:29 +01:00
|
|
|
viewer->forward();
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::nextPage()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
m_stackedWidget->setCurrentIndex((m_stackedWidget->currentIndex() + 1)
|
|
|
|
|
% m_stackedWidget->count());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CentralWidget::backward()
|
|
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
if (HelpViewer* viewer = currentHelpViewer())
|
2008-12-02 12:01:29 +01:00
|
|
|
viewer->backward();
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::previousPage()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
m_stackedWidget->setCurrentIndex((m_stackedWidget->currentIndex() - 1)
|
|
|
|
|
% m_stackedWidget->count());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-01-28 16:04:09 +01:00
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::print()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
#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;
|
|
|
|
|
}
|
2009-06-25 16:03:02 +02:00
|
|
|
#endif
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::pageSetup()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
#ifndef QT_NO_PRINTER
|
|
|
|
|
initPrinter();
|
|
|
|
|
QPageSetupDialog dlg(printer);
|
|
|
|
|
dlg.exec();
|
2008-12-02 12:01:29 +01:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::printPreview()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
#ifndef QT_NO_PRINTER
|
|
|
|
|
initPrinter();
|
|
|
|
|
QPrintPreviewDialog preview(printer, this);
|
|
|
|
|
connect(&preview, SIGNAL(paintRequested(QPrinter*)),
|
|
|
|
|
SLOT(printPreview(QPrinter*)));
|
|
|
|
|
preview.exec();
|
|
|
|
|
#endif
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::setSource(const QUrl &url)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
if (HelpViewer* viewer = currentHelpViewer()) {
|
|
|
|
|
viewer->setSource(url);
|
|
|
|
|
viewer->setFocus(Qt::OtherFocusReason);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::setSourceFromSearch(const QUrl &url)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-07-27 14:35:00 +02:00
|
|
|
if (HelpViewer* viewer = currentHelpViewer()) {
|
2010-03-30 17:44:28 +02:00
|
|
|
connect(viewer, SIGNAL(loadFinished(bool)), this,
|
|
|
|
|
SLOT(highlightSearchTerms()));
|
|
|
|
|
viewer->setSource(url);
|
|
|
|
|
viewer->setFocus(Qt::OtherFocusReason);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::showTopicChooser(const QMap<QString, QUrl> &links,
|
|
|
|
|
const QString &keyword)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
TopicChooser tc(this, keyword, links);
|
|
|
|
|
if (tc.exec() == QDialog::Accepted)
|
|
|
|
|
setSource(tc.link());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
// -- protected
|
2010-01-29 21:33:57 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void CentralWidget::focusInEvent(QFocusEvent * /* event */)
|
|
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
// 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;
|
2009-06-04 13:12:20 +02:00
|
|
|
QTimer::singleShot(1, receiver, SLOT(setFocus()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
// -- private slots
|
|
|
|
|
|
|
|
|
|
void CentralWidget::highlightSearchTerms()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
if (HelpViewer *viewer = currentHelpViewer()) {
|
|
|
|
|
QHelpSearchEngine *searchEngine =
|
|
|
|
|
HelpManager::instance().helpEngine().searchEngine();
|
|
|
|
|
QList<QHelpSearchQuery> queryList = searchEngine->query();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
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("\"")));
|
2009-06-25 15:20:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-03-30 17:44:28 +02:00
|
|
|
|
|
|
|
|
foreach (const QString& term, terms)
|
|
|
|
|
viewer->findText(term, 0, false, true);
|
|
|
|
|
disconnect(viewer, SIGNAL(loadFinished(bool)), this,
|
|
|
|
|
SLOT(highlightSearchTerms()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::printPreview(QPrinter *p)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
#ifndef QT_NO_PRINTER
|
|
|
|
|
HelpViewer *viewer = currentHelpViewer();
|
|
|
|
|
if (viewer)
|
|
|
|
|
viewer->print(p);
|
2008-12-02 12:01:29 +01:00
|
|
|
#else
|
2010-03-30 17:44:28 +02:00
|
|
|
Q_UNUSED(p)
|
2008-12-02 12:01:29 +01:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::handleSourceChanged(const QUrl &url)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
if (sender() == currentHelpViewer())
|
|
|
|
|
emit sourceChanged(url);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
// -- private
|
|
|
|
|
|
|
|
|
|
void CentralWidget::initPrinter()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
#ifndef QT_NO_PRINTER
|
|
|
|
|
if (!printer)
|
|
|
|
|
printer = new QPrinter(QPrinter::HighResolution);
|
|
|
|
|
#endif
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
void CentralWidget::connectSignals(HelpViewer *page)
|
2010-01-18 15:18:23 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
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)));
|
2010-01-18 15:18:23 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
bool CentralWidget::eventFilter(QObject *object, QEvent *e)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
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);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|