summaryrefslogtreecommitdiffstats
path: root/tools/assistant
diff options
context:
space:
mode:
Diffstat (limited to 'tools/assistant')
-rw-r--r--tools/assistant/lib/qhelpsearchquerywidget.cpp84
-rw-r--r--tools/assistant/lib/qhelpsearchquerywidget.h4
-rw-r--r--tools/assistant/tools/assistant/aboutdialog.cpp9
-rw-r--r--tools/assistant/tools/assistant/assistant.pro24
-rw-r--r--tools/assistant/tools/assistant/assistant_images.qrc6
-rw-r--r--tools/assistant/tools/assistant/bookmarkfiltermodel.cpp114
-rw-r--r--tools/assistant/tools/assistant/bookmarkmanager.cpp103
-rw-r--r--tools/assistant/tools/assistant/bookmarkmanager.h9
-rw-r--r--tools/assistant/tools/assistant/bookmarkmodel.cpp35
-rw-r--r--tools/assistant/tools/assistant/centralwidget.cpp1112
-rw-r--r--tools/assistant/tools/assistant/centralwidget.h122
-rw-r--r--tools/assistant/tools/assistant/contentwindow.cpp12
-rw-r--r--tools/assistant/tools/assistant/contentwindow.h1
-rw-r--r--tools/assistant/tools/assistant/doc/assistant.qdocconf2
-rw-r--r--tools/assistant/tools/assistant/findwidget.cpp2
-rw-r--r--tools/assistant/tools/assistant/findwidget.h5
-rw-r--r--tools/assistant/tools/assistant/globalactions.cpp246
-rw-r--r--tools/assistant/tools/assistant/globalactions.h105
-rw-r--r--tools/assistant/tools/assistant/helpenginewrapper.cpp41
-rw-r--r--tools/assistant/tools/assistant/helpenginewrapper.h8
-rw-r--r--tools/assistant/tools/assistant/helpviewer.cpp71
-rw-r--r--tools/assistant/tools/assistant/helpviewer.h105
-rw-r--r--tools/assistant/tools/assistant/helpviewer_p.h (renamed from tools/assistant/tools/assistant/helpviewer_qtb.h)118
-rw-r--r--tools/assistant/tools/assistant/helpviewer_qtb.cpp337
-rw-r--r--tools/assistant/tools/assistant/helpviewer_qwv.cpp230
-rw-r--r--tools/assistant/tools/assistant/helpviewer_qwv.h123
-rw-r--r--tools/assistant/tools/assistant/images/closebutton.pngbin0 -> 288 bytes
-rw-r--r--tools/assistant/tools/assistant/images/darkclosebutton.pngbin0 -> 319 bytes
-rw-r--r--tools/assistant/tools/assistant/indexwindow.cpp8
-rw-r--r--tools/assistant/tools/assistant/mainwindow.cpp513
-rw-r--r--tools/assistant/tools/assistant/mainwindow.h27
-rw-r--r--tools/assistant/tools/assistant/openpagesmanager.cpp378
-rw-r--r--tools/assistant/tools/assistant/openpagesmanager.h115
-rw-r--r--tools/assistant/tools/assistant/openpagesmodel.cpp119
-rw-r--r--tools/assistant/tools/assistant/openpagesmodel.h76
-rw-r--r--tools/assistant/tools/assistant/openpagesswitcher.cpp194
-rw-r--r--tools/assistant/tools/assistant/openpagesswitcher.h85
-rw-r--r--tools/assistant/tools/assistant/openpageswidget.cpp237
-rw-r--r--tools/assistant/tools/assistant/openpageswidget.h92
-rw-r--r--tools/assistant/tools/assistant/preferencesdialog.cpp26
-rw-r--r--tools/assistant/tools/assistant/preferencesdialog.h3
-rw-r--r--tools/assistant/tools/assistant/preferencesdialog.ui20
-rw-r--r--tools/assistant/tools/assistant/remotecontrol.cpp32
-rw-r--r--tools/assistant/tools/assistant/searchwidget.cpp25
-rw-r--r--tools/assistant/tools/assistant/searchwidget.h4
-rw-r--r--tools/assistant/tools/qcollectiongenerator/main.cpp11
-rw-r--r--tools/assistant/tools/shared/collectionconfiguration.cpp14
-rw-r--r--tools/assistant/tools/shared/collectionconfiguration.h4
48 files changed, 3249 insertions, 1762 deletions
diff --git a/tools/assistant/lib/qhelpsearchquerywidget.cpp b/tools/assistant/lib/qhelpsearchquerywidget.cpp
index 1634a0d..8e8b278 100644
--- a/tools/assistant/lib/qhelpsearchquerywidget.cpp
+++ b/tools/assistant/lib/qhelpsearchquerywidget.cpp
@@ -215,37 +215,36 @@ private:
queryHist->curQuery += addend;
const QList<QHelpSearchQuery> &query =
- queryHist->queries.at(queryHist->curQuery);
+ queryHist->queries.at(queryHist->curQuery);
foreach (const QHelpSearchQuery &queryPart, query) {
- QLineEdit *lineEdit = 0;
- switch (queryPart.fieldName) {
+ if (QLineEdit *lineEdit = lineEditFor(queryPart.fieldName))
+ lineEdit->setText(queryPart.wordList.join(" "));
+ }
+
+ if (queryHist->curQuery == maxOrMinIndex)
+ thisButton->setEnabled(false);
+ otherButton->setEnabled(true);
+ }
+
+ QLineEdit* lineEditFor(const QHelpSearchQuery::FieldName &fieldName) const
+ {
+ switch (fieldName) {
case QHelpSearchQuery::DEFAULT:
- lineEdit = defaultQuery;
- break;
+ return defaultQuery;
case QHelpSearchQuery::ALL:
- lineEdit = allQuery;
- break;
+ return allQuery;
case QHelpSearchQuery::ATLEAST:
- lineEdit = atLeastQuery;
- break;
+ return atLeastQuery;
case QHelpSearchQuery::FUZZY:
- lineEdit = similarQuery;
- break;
+ return similarQuery;
case QHelpSearchQuery::WITHOUT:
- lineEdit = withoutQuery;
- break;
+ return withoutQuery;
case QHelpSearchQuery::PHRASE:
- lineEdit = exactQuery;
- break;
+ return exactQuery;
default:
Q_ASSERT(0);
- }
- lineEdit->setText(queryPart.wordList.join(" "));
}
-
- if (queryHist->curQuery == maxOrMinIndex)
- thisButton->setEnabled(false);
- otherButton->setEnabled(true);
+ return 0;
}
void enableOrDisableToolButtons()
@@ -512,8 +511,27 @@ QHelpSearchQueryWidget::~QHelpSearchQueryWidget()
}
/*!
+ Expands the search query widget so that the extended search fields are shown.
+*/
+void QHelpSearchQueryWidget::expandExtendedSearch()
+{
+ if (d->simpleSearch)
+ d->showHideAdvancedSearch();
+}
+
+/*!
+ Collapses the search query widget so that only the default search field is
+ shown.
+*/
+void QHelpSearchQueryWidget::collapseExtendedSearch()
+{
+ if (!d->simpleSearch)
+ d->showHideAdvancedSearch();
+}
+
+/*!
Returns a list of queries to use in combination with the search engines
- search(QList<QHelpSearchQuery> &query) function.
+ search(QList<QHelpSearchQuery> &queryList) function.
*/
QList<QHelpSearchQuery> QHelpSearchQueryWidget::query() const
{
@@ -524,6 +542,28 @@ QList<QHelpSearchQuery> QHelpSearchQueryWidget::query() const
}
/*!
+ Sets the QHelpSearchQueryWidget input fields to the values specified by
+ \a queryList search field name. Please note that one has to call the search
+ engine's search(QList<QHelpSearchQuery> &queryList) function to perform the
+ actual search.
+*/
+void QHelpSearchQueryWidget::setQuery(const QList<QHelpSearchQuery> &queryList)
+{
+ QList<QLineEdit *> lineEdits;
+ lineEdits << d->defaultQuery << d->allQuery << d->atLeastQuery
+ << d->similarQuery << d->withoutQuery << d->exactQuery;
+ foreach (QLineEdit *lineEdit, lineEdits)
+ lineEdit->clear();
+
+ const QLatin1String space(" ");
+ foreach (const QHelpSearchQuery &q, queryList) {
+ if (QLineEdit *lineEdit = d->lineEditFor(q.fieldName))
+ lineEdit->setText(lineEdit->text() + q.wordList.join(space) + space);
+ }
+ d->searchRequested();
+}
+
+/*!
\reimp
*/
void QHelpSearchQueryWidget::focusInEvent(QFocusEvent *focusEvent)
diff --git a/tools/assistant/lib/qhelpsearchquerywidget.h b/tools/assistant/lib/qhelpsearchquerywidget.h
index 2afc4b4..f3c290f 100644
--- a/tools/assistant/lib/qhelpsearchquerywidget.h
+++ b/tools/assistant/lib/qhelpsearchquerywidget.h
@@ -68,7 +68,11 @@ public:
QHelpSearchQueryWidget(QWidget *parent = 0);
~QHelpSearchQueryWidget();
+ void expandExtendedSearch();
+ void collapseExtendedSearch();
+
QList<QHelpSearchQuery> query() const;
+ void setQuery(const QList<QHelpSearchQuery> &queryList);
Q_SIGNALS:
void search();
diff --git a/tools/assistant/tools/assistant/aboutdialog.cpp b/tools/assistant/tools/assistant/aboutdialog.cpp
index a9bc352..9935a1e 100644
--- a/tools/assistant/tools/assistant/aboutdialog.cpp
+++ b/tools/assistant/tools/assistant/aboutdialog.cpp
@@ -38,6 +38,9 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+
+#include "aboutdialog.h"
+
#include "helpviewer.h"
#include "tracer.h"
@@ -51,8 +54,6 @@
#include <QtGui/QMessageBox>
#include <QtGui/QDesktopServices>
-#include "aboutdialog.h"
-
QT_BEGIN_NAMESPACE
AboutLabel::AboutLabel(QWidget *parent)
@@ -96,8 +97,8 @@ QVariant AboutLabel::loadResource(int type, const QUrl &name)
void AboutLabel::setSource(const QUrl &url)
{
TRACE_OBJ
- if (url.isValid() && (!AbstractHelpViewer::isLocalUrl(url)
- || !AbstractHelpViewer::canOpenPage(url.path()))) {
+ if (url.isValid() && (!HelpViewer::isLocalUrl(url)
+ || !HelpViewer::canOpenPage(url.path()))) {
if (!QDesktopServices::openUrl(url)) {
QMessageBox::warning(this, tr("Warning"),
tr("Unable to launch external application.\n"), tr("OK"));
diff --git a/tools/assistant/tools/assistant/assistant.pro b/tools/assistant/tools/assistant/assistant.pro
index d9aff7a..7f0fdd1 100644
--- a/tools/assistant/tools/assistant/assistant.pro
+++ b/tools/assistant/tools/assistant/assistant.pro
@@ -12,6 +12,8 @@ DESTDIR = ../../../../bin
target.path = $$[QT_INSTALL_BINS]
INSTALLS += target
DEPENDPATH += ../shared
+DEPENDPATH += .
+INCLUDEPATH += .
# ## Work around a qmake issue when statically linking to
# ## not-yet-installed plugins
@@ -30,6 +32,7 @@ HEADERS += aboutdialog.h \
filternamedialog.h \
helpenginewrapper.h \
helpviewer.h \
+ helpviewer_p.h \
indexwindow.h \
installdialog.h \
mainwindow.h \
@@ -40,12 +43,12 @@ HEADERS += aboutdialog.h \
topicchooser.h \
tracer.h \
xbelsupport.h \
- ../shared/collectionconfiguration.h
-contains(QT_CONFIG, webkit) {
- HEADERS += helpviewer_qwv.h
-} else {
- HEADERS += helpviewer_qtb.h
- }
+ ../shared/collectionconfiguration.h \
+ openpagesmodel.h \
+ globalactions.h \
+ openpageswidget.h \
+ openpagesmanager.h \
+ openpagesswitcher.h
win32:HEADERS += remotecontrol_win.h
SOURCES += aboutdialog.cpp \
@@ -72,8 +75,13 @@ SOURCES += aboutdialog.cpp \
searchwidget.cpp \
topicchooser.cpp \
xbelsupport.cpp \
- ../shared/collectionconfiguration.cpp
- contains(QT_CONFIG, webkit) {
+ ../shared/collectionconfiguration.cpp \
+ openpagesmodel.cpp \
+ globalactions.cpp \
+ openpageswidget.cpp \
+ openpagesmanager.cpp \
+ openpagesswitcher.cpp
+contains(QT_CONFIG, webkit) {
SOURCES += helpviewer_qwv.cpp
} else {
SOURCES += helpviewer_qtb.cpp
diff --git a/tools/assistant/tools/assistant/assistant_images.qrc b/tools/assistant/tools/assistant/assistant_images.qrc
index 34918c0..b4f2523 100644
--- a/tools/assistant/tools/assistant/assistant_images.qrc
+++ b/tools/assistant/tools/assistant/assistant_images.qrc
@@ -1,11 +1,10 @@
<RCC>
- <qresource prefix="/trolltech/assistant" >
+ <qresource prefix="/trolltech/assistant">
<file>images/trolltech-logo.png</file>
<file>images/assistant-128.png</file>
<file>images/assistant.png</file>
<file>images/wrap.png</file>
<file>images/bookmark.png</file>
-#mac
<file>images/mac/addtab.png</file>
<file>images/mac/book.png</file>
<file>images/mac/closetab.png</file>
@@ -19,7 +18,6 @@
<file>images/mac/zoomin.png</file>
<file>images/mac/zoomout.png</file>
<file>images/mac/resetzoom.png</file>
-#win
<file>images/win/addtab.png</file>
<file>images/win/book.png</file>
<file>images/win/closetab.png</file>
@@ -33,5 +31,7 @@
<file>images/win/zoomin.png</file>
<file>images/win/zoomout.png</file>
<file>images/win/resetzoom.png</file>
+ <file>images/closebutton.png</file>
+ <file>images/darkclosebutton.png</file>
</qresource>
</RCC>
diff --git a/tools/assistant/tools/assistant/bookmarkfiltermodel.cpp b/tools/assistant/tools/assistant/bookmarkfiltermodel.cpp
index 7a7c2e3..fe510a5 100644
--- a/tools/assistant/tools/assistant/bookmarkfiltermodel.cpp
+++ b/tools/assistant/tools/assistant/bookmarkfiltermodel.cpp
@@ -50,11 +50,30 @@ BookmarkFilterModel::BookmarkFilterModel(QObject *parent)
{
}
-void
-BookmarkFilterModel::setSourceModel(QAbstractItemModel *_sourceModel)
+void BookmarkFilterModel::setSourceModel(QAbstractItemModel *_sourceModel)
{
beginResetModel();
+ disconnect(sourceModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this,
+ SLOT(changed(QModelIndex, QModelIndex)));
+
+ disconnect(sourceModel, SIGNAL(rowsInserted(QModelIndex, int, int)),
+ this, SLOT(rowsInserted(QModelIndex, int, int)));
+
+ disconnect(sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)),
+ this, SLOT(rowsAboutToBeRemoved(QModelIndex, int, int)));
+ disconnect(sourceModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), this,
+ SLOT(rowsRemoved(QModelIndex, int, int)));
+
+ disconnect(sourceModel, SIGNAL(layoutAboutToBeChanged()), this,
+ SLOT(layoutAboutToBeChanged()));
+ disconnect(sourceModel, SIGNAL(layoutChanged()), this,
+ SLOT(layoutChanged()));
+
+ disconnect(sourceModel, SIGNAL(modelAboutToBeReset()), this,
+ SLOT(modelAboutToBeReset()));
+ disconnect(sourceModel, SIGNAL(modelReset()), this, SLOT(modelReset()));
+
QAbstractProxyModel::setSourceModel(sourceModel);
sourceModel = qobject_cast<BookmarkModel*> (_sourceModel);
@@ -79,20 +98,18 @@ BookmarkFilterModel::setSourceModel(QAbstractItemModel *_sourceModel)
connect(sourceModel, SIGNAL(modelReset()), this, SLOT(modelReset()));
if (sourceModel)
- setupCache(sourceModel->index(0, 0, QModelIndex()));
+ setupCache(sourceModel->index(0, 0, QModelIndex()).parent());
endResetModel();
}
-int
-BookmarkFilterModel::rowCount(const QModelIndex &index) const
+int BookmarkFilterModel::rowCount(const QModelIndex &index) const
{
Q_UNUSED(index)
return cache.count();
}
-int
-BookmarkFilterModel::columnCount(const QModelIndex &index) const
+int BookmarkFilterModel::columnCount(const QModelIndex &index) const
{
Q_UNUSED(index)
if (sourceModel)
@@ -100,8 +117,7 @@ BookmarkFilterModel::columnCount(const QModelIndex &index) const
return 0;
}
-QModelIndex
-BookmarkFilterModel::mapToSource(const QModelIndex &proxyIndex) const
+QModelIndex BookmarkFilterModel::mapToSource(const QModelIndex &proxyIndex) const
{
const int row = proxyIndex.row();
if (proxyIndex.isValid() && row >= 0 && row < cache.count())
@@ -109,21 +125,19 @@ BookmarkFilterModel::mapToSource(const QModelIndex &proxyIndex) const
return QModelIndex();
}
-QModelIndex
-BookmarkFilterModel::mapFromSource(const QModelIndex &sourceIndex) const
+QModelIndex BookmarkFilterModel::mapFromSource(const QModelIndex &sourceIndex) const
{
return index(cache.indexOf(sourceIndex), 0, QModelIndex());
}
-QModelIndex
-BookmarkFilterModel::parent(const QModelIndex &child) const
+QModelIndex BookmarkFilterModel::parent(const QModelIndex &child) const
{
Q_UNUSED(child)
return QModelIndex();
}
-QModelIndex
-BookmarkFilterModel::index(int row, int column, const QModelIndex &index) const
+QModelIndex BookmarkFilterModel::index(int row, int column,
+ const QModelIndex &index) const
{
Q_UNUSED(index)
if (row < 0 || column < 0 || cache.count() <= row
@@ -133,32 +147,28 @@ BookmarkFilterModel::index(int row, int column, const QModelIndex &index) const
return createIndex(row, 0);
}
-Qt::DropActions
-BookmarkFilterModel::supportedDropActions () const
+Qt::DropActions BookmarkFilterModel::supportedDropActions () const
{
if (sourceModel)
return sourceModel->supportedDropActions();
return Qt::IgnoreAction;
}
-Qt::ItemFlags
-BookmarkFilterModel::flags(const QModelIndex &index) const
+Qt::ItemFlags BookmarkFilterModel::flags(const QModelIndex &index) const
{
if (sourceModel)
return sourceModel->flags(index);
return Qt::NoItemFlags;
}
-QVariant
-BookmarkFilterModel::data(const QModelIndex &index, int role) const
+QVariant BookmarkFilterModel::data(const QModelIndex &index, int role) const
{
if (sourceModel)
return sourceModel->data(mapToSource(index), role);
return QVariant();
}
-bool
-BookmarkFilterModel::setData(const QModelIndex &index, const QVariant &value,
+bool BookmarkFilterModel::setData(const QModelIndex &index, const QVariant &value,
int role)
{
if (sourceModel)
@@ -166,37 +176,34 @@ BookmarkFilterModel::setData(const QModelIndex &index, const QVariant &value,
return false;
}
-void
-BookmarkFilterModel::filterBookmarks()
+void BookmarkFilterModel::filterBookmarks()
{
if (sourceModel) {
beginResetModel();
hideBookmarks = true;
- setupCache(sourceModel->index(0, 0, QModelIndex()));
+ setupCache(sourceModel->index(0, 0, QModelIndex()).parent());
endResetModel();
}
}
-void
-BookmarkFilterModel::filterBookmarkFolders()
+void BookmarkFilterModel::filterBookmarkFolders()
{
if (sourceModel) {
beginResetModel();
hideBookmarks = false;
- setupCache(sourceModel->index(0, 0, QModelIndex()));
+ setupCache(sourceModel->index(0, 0, QModelIndex()).parent());
endResetModel();
}
}
-void
-BookmarkFilterModel::changed(const QModelIndex &topLeft,
+void BookmarkFilterModel::changed(const QModelIndex &topLeft,
const QModelIndex &bottomRight)
{
emit dataChanged(mapFromSource(topLeft), mapFromSource(bottomRight));
}
-void
-BookmarkFilterModel::rowsInserted(const QModelIndex &parent, int start, int end)
+void BookmarkFilterModel::rowsInserted(const QModelIndex &parent, int start,
+ int end)
{
if (!sourceModel)
return;
@@ -218,15 +225,16 @@ BookmarkFilterModel::rowsInserted(const QModelIndex &parent, int start, int end)
const bool isFolder = newIndex.data(UserRoleFolder).toBool();
if ((isFolder && hideBookmarks) || (!isFolder && !hideBookmarks)) {
beginInsertRows(mapFromSource(parent), start, end);
- cache.insert(cache.indexOf(cachePrevious) + 1, newIndex);
+ const int index = cache.indexOf(cachePrevious) + 1;
+ if (cache.value(index, QPersistentModelIndex()) != newIndex)
+ cache.insert(index, newIndex);
endInsertRows();
}
}
}
-void
-BookmarkFilterModel::rowsAboutToBeRemoved(const QModelIndex &parent, int start,
- int end)
+void BookmarkFilterModel::rowsAboutToBeRemoved(const QModelIndex &parent,
+ int start, int end)
{
if (!sourceModel)
return;
@@ -240,8 +248,7 @@ BookmarkFilterModel::rowsAboutToBeRemoved(const QModelIndex &parent, int start,
}
}
-void
-BookmarkFilterModel::rowsRemoved(const QModelIndex &/*parent*/, int, int)
+void BookmarkFilterModel::rowsRemoved(const QModelIndex &/*parent*/, int, int)
{
if (cache.contains(indexToRemove)) {
cache.removeAll(indexToRemove);
@@ -249,41 +256,36 @@ BookmarkFilterModel::rowsRemoved(const QModelIndex &/*parent*/, int, int)
}
}
-void
-BookmarkFilterModel::layoutAboutToBeChanged()
+void BookmarkFilterModel::layoutAboutToBeChanged()
{
// TODO: ???
}
-void
-BookmarkFilterModel::layoutChanged()
+void BookmarkFilterModel::layoutChanged()
{
// TODO: ???
}
-void
-BookmarkFilterModel::modelAboutToBeReset()
+void BookmarkFilterModel::modelAboutToBeReset()
{
beginResetModel();
}
-void
-BookmarkFilterModel::modelReset()
+void BookmarkFilterModel::modelReset()
{
if (sourceModel)
- setupCache(sourceModel->index(0, 0, QModelIndex()));
+ setupCache(sourceModel->index(0, 0, QModelIndex()).parent());
endResetModel();
}
-void
-BookmarkFilterModel::setupCache(const QModelIndex &parent)
+void BookmarkFilterModel::setupCache(const QModelIndex &parent)
{
cache.clear();
- collectItems(parent);
+ for (int i = 0; i < sourceModel->rowCount(parent); ++i)
+ collectItems(sourceModel->index(i, 0, parent));
}
-void
-BookmarkFilterModel::collectItems(const QModelIndex &parent)
+void BookmarkFilterModel::collectItems(const QModelIndex &parent)
{
if (parent.isValid()) {
bool isFolder = sourceModel->data(parent, UserRoleFolder).toBool();
@@ -304,14 +306,12 @@ BookmarkTreeModel::BookmarkTreeModel(QObject *parent)
{
}
-int
-BookmarkTreeModel::columnCount(const QModelIndex &parent) const
+int BookmarkTreeModel::columnCount(const QModelIndex &parent) const
{
return qMin(1, QSortFilterProxyModel::columnCount(parent));
}
-bool
-BookmarkTreeModel::filterAcceptsRow(int row, const QModelIndex &parent) const
+bool BookmarkTreeModel::filterAcceptsRow(int row, const QModelIndex &parent) const
{
Q_UNUSED(row)
BookmarkModel *model = qobject_cast<BookmarkModel*> (sourceModel());
diff --git a/tools/assistant/tools/assistant/bookmarkmanager.cpp b/tools/assistant/tools/assistant/bookmarkmanager.cpp
index 23632b1..7a11ffe 100644
--- a/tools/assistant/tools/assistant/bookmarkmanager.cpp
+++ b/tools/assistant/tools/assistant/bookmarkmanager.cpp
@@ -53,6 +53,7 @@
#include <QtGui/QKeyEvent>
#include <QtGui/QMessageBox>
#include <QtGui/QSortFilterProxyModel>
+#include <QtGui/QToolBar>
QT_BEGIN_NAMESPACE
@@ -136,11 +137,18 @@ QWidget* BookmarkManager::bookmarkDockWidget() const
return 0;
}
-void BookmarkManager::takeBookmarksMenu(QMenu* menu)
+void BookmarkManager::setBookmarksMenu(QMenu* menu)
{
TRACE_OBJ
bookmarkMenu = menu;
- refeshBookmarkMenu();
+ refreshBookmarkMenu();
+}
+
+void BookmarkManager::setBookmarksToolbar(QToolBar *toolBar)
+{
+ TRACE_OBJ
+ m_toolBar = toolBar;
+ refreshBookmarkToolBar();
}
// -- public slots
@@ -157,7 +165,10 @@ void BookmarkManager::addBookmark(const QString &title, const QString &url)
BookmarkManager::BookmarkManager()
: typeAndSearch(false)
, bookmarkMenu(0)
+ , m_toolBar(0)
, bookmarkModel(new BookmarkModel)
+ , bookmarkFilterModel(0)
+ , typeAndSearchModel(0)
, bookmarkWidget(new BookmarkWidget)
, bookmarkTreeView(new BookmarkTreeView)
, bookmarkManagerWidget(0)
@@ -186,11 +197,18 @@ BookmarkManager::BookmarkManager()
connect(&HelpEngineWrapper::instance(), SIGNAL(setupFinished()), this,
SLOT(setupFinished()));
connect(bookmarkModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), this,
- SLOT(refeshBookmarkMenu()));
+ SLOT(refreshBookmarkMenu()));
+ connect(bookmarkModel, SIGNAL(rowsInserted(QModelIndex, int, int)), this,
+ SLOT(refreshBookmarkMenu()));
+ connect(bookmarkModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this,
+ SLOT(refreshBookmarkMenu()));
+
+ connect(bookmarkModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), this,
+ SLOT(refreshBookmarkToolBar()));
connect(bookmarkModel, SIGNAL(rowsInserted(QModelIndex, int, int)), this,
- SLOT(refeshBookmarkMenu()));
+ SLOT(refreshBookmarkToolBar()));
connect(bookmarkModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this,
- SLOT(refeshBookmarkMenu()));
+ SLOT(refreshBookmarkToolBar()));
}
BookmarkManager::~BookmarkManager()
@@ -283,7 +301,7 @@ void BookmarkManager::buildBookmarksMenu(const QModelIndex &index, QMenu* menu)
return;
const QString &text = index.data().toString();
- const QIcon &icon = qVariantValue<QIcon>(index.data(Qt::DecorationRole));
+ const QIcon &icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
if (index.data(UserRoleFolder).toBool()) {
if (QMenu* subMenu = menu->addMenu(icon, text)) {
for (int i = 0; i < bookmarkModel->rowCount(index); ++i)
@@ -310,17 +328,20 @@ void BookmarkManager::setupFinished()
bookmarkModel->setBookmarks(HelpEngineWrapper::instance().bookmarks());
bookmarkModel->expandFoldersIfNeeeded(bookmarkTreeView);
- refeshBookmarkMenu();
+ refreshBookmarkMenu();
+ refreshBookmarkToolBar();
bookmarkTreeView->hideColumn(1);
bookmarkTreeView->header()->setVisible(false);
bookmarkTreeView->header()->setStretchLastSection(true);
- bookmarkFilterModel = new BookmarkFilterModel(this);
+ if (!bookmarkFilterModel)
+ bookmarkFilterModel = new BookmarkFilterModel(this);
bookmarkFilterModel->setSourceModel(bookmarkModel);
bookmarkFilterModel->filterBookmarkFolders();
- typeAndSearchModel = new QSortFilterProxyModel(this);
+ if (!typeAndSearchModel)
+ typeAndSearchModel = new QSortFilterProxyModel(this);
typeAndSearchModel->setDynamicSortFilter(true);
typeAndSearchModel->setSourceModel(bookmarkFilterModel);
}
@@ -354,7 +375,7 @@ void BookmarkManager::manageBookmarks()
bookmarkManagerWidget->raise();
}
-void BookmarkManager::refeshBookmarkMenu()
+void BookmarkManager::refreshBookmarkMenu()
{
TRACE_OBJ
if (!bookmarkMenu)
@@ -365,11 +386,16 @@ void BookmarkManager::refeshBookmarkMenu()
bookmarkMenu->addAction(tr("Manage Bookmarks..."), this,
SLOT(manageBookmarks()));
bookmarkMenu->addAction(QIcon::fromTheme("bookmark-new"),
- tr("Add Bookmark..."), this, SLOT(addBookmark()),
- QKeySequence(tr("Ctrl+D")));
+ tr("Add Bookmark..."), this, SLOT(addBookmark()), QKeySequence(tr("Ctrl+D")));
+
bookmarkMenu->addSeparator();
- const QModelIndex &root = bookmarkModel->index(0, 0, QModelIndex());
+ QModelIndex root = bookmarkModel->index(0, 0, QModelIndex()).parent();
+ buildBookmarksMenu(bookmarkModel->index(0, 0, root), bookmarkMenu);
+
+ bookmarkMenu->addSeparator();
+
+ root = bookmarkModel->index(1, 0, QModelIndex());
for (int i = 0; i < bookmarkModel->rowCount(root); ++i)
buildBookmarksMenu(bookmarkModel->index(i, 0, root), bookmarkMenu);
@@ -377,6 +403,41 @@ void BookmarkManager::refeshBookmarkMenu()
SLOT(setSourceFromAction(QAction*)));
}
+void BookmarkManager::refreshBookmarkToolBar()
+{
+ TRACE_OBJ
+ if (!m_toolBar)
+ return;
+
+ m_toolBar->clear();
+ m_toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+
+ const QModelIndex &root = bookmarkModel->index(0, 0, QModelIndex());
+ for (int i = 0; i < bookmarkModel->rowCount(root); ++i) {
+ const QModelIndex &index = bookmarkModel->index(i, 0, root);
+ if (index.data(UserRoleFolder).toBool()) {
+ QToolButton *button = new QToolButton(m_toolBar);
+ button->setPopupMode(QToolButton::InstantPopup);
+ button->setText(index.data().toString());
+ QMenu *menu = new QMenu(button);
+ for (int j = 0; j < bookmarkModel->rowCount(index); ++j)
+ buildBookmarksMenu(bookmarkModel->index(j, 0, index), menu);
+ connect(menu, SIGNAL(triggered(QAction*)), this,
+ SLOT(setSourceFromAction(QAction*)));
+ button->setMenu(menu);
+ button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+ button->setIcon(qvariant_cast<QIcon>(index.data(Qt::DecorationRole)));
+ QAction *a = m_toolBar->addWidget(button);
+ a->setText(index.data().toString());
+ } else {
+ QAction *action = m_toolBar->addAction(
+ qvariant_cast<QIcon>(index.data(Qt::DecorationRole)),
+ index.data().toString(), this, SLOT(setSourceFromAction()));
+ action->setData(index.data(UserRoleUrl).toString());
+ }
+ }
+}
+
void BookmarkManager::renameBookmark(const QModelIndex &index)
{
// check if we should rename the "Bookmarks Menu", bail
@@ -388,13 +449,21 @@ void BookmarkManager::renameBookmark(const QModelIndex &index)
bookmarkModel->setItemsEditable(false);
}
-void BookmarkManager::setSourceFromAction(QAction *action)
+
+void BookmarkManager::setSourceFromAction()
{
TRACE_OBJ
- const QVariant &data = action->data();
+ setSourceFromAction(qobject_cast<QAction*> (sender()));
+}
- if (data.canConvert<QUrl>())
- emit setSource(data.toUrl());
+void BookmarkManager::setSourceFromAction(QAction *action)
+{
+ TRACE_OBJ
+ if (action) {
+ const QVariant &data = action->data();
+ if (data.canConvert<QUrl>())
+ emit setSource(data.toUrl());
+ }
}
void BookmarkManager::setSourceFromIndex(const QModelIndex &index, bool newTab)
diff --git a/tools/assistant/tools/assistant/bookmarkmanager.h b/tools/assistant/tools/assistant/bookmarkmanager.h
index c26dad8..ae27b59 100644
--- a/tools/assistant/tools/assistant/bookmarkmanager.h
+++ b/tools/assistant/tools/assistant/bookmarkmanager.h
@@ -53,6 +53,7 @@ class BookmarkModel;
class BookmarkFilterModel;
class QKeyEvent;
class QSortFilterProxyModel;
+class QToolBar;
class BookmarkManager : public QObject
{
@@ -67,7 +68,8 @@ public:
static void destroy();
QWidget* bookmarkDockWidget() const;
- void takeBookmarksMenu(QMenu* menu);
+ void setBookmarksMenu(QMenu* menu);
+ void setBookmarksToolbar(QToolBar *toolBar);
public slots:
void addBookmark(const QString &title, const QString &url);
@@ -92,9 +94,11 @@ private slots:
void addBookmark();
void removeBookmark();
void manageBookmarks();
- void refeshBookmarkMenu();
+ void refreshBookmarkMenu();
+ void refreshBookmarkToolBar();
void renameBookmark(const QModelIndex &index);
+ void setSourceFromAction();
void setSourceFromAction(QAction *action);
void setSourceFromIndex(const QModelIndex &index, bool newTab = false);
@@ -110,6 +114,7 @@ private:
static BookmarkManager *bookmarkManager;
QMenu *bookmarkMenu;
+ QToolBar *m_toolBar;
BookmarkModel *bookmarkModel;
BookmarkFilterModel *bookmarkFilterModel;
diff --git a/tools/assistant/tools/assistant/bookmarkmodel.cpp b/tools/assistant/tools/assistant/bookmarkmodel.cpp
index 4c30b42..320b233 100644
--- a/tools/assistant/tools/assistant/bookmarkmodel.cpp
+++ b/tools/assistant/tools/assistant/bookmarkmodel.cpp
@@ -48,6 +48,7 @@
#include <QtGui/QStyle>
#include <QtGui/QTreeView>
+const quint32 VERSION = 0xe53798;
const QLatin1String MIMETYPE("application/bookmarks.assistant");
BookmarkModel::BookmarkModel()
@@ -68,8 +69,9 @@ BookmarkModel::bookmarks() const
{
QByteArray ba;
QDataStream stream(&ba, QIODevice::WriteOnly);
+ stream << qint32(VERSION);
- const QModelIndex &root = index(0,0, QModelIndex());
+ const QModelIndex &root = index(0,0, QModelIndex()).parent();
for (int i = 0; i < rowCount(root); ++i)
collectItems(index(i, 0, root), 0, &stream);
@@ -87,24 +89,35 @@ BookmarkModel::setBookmarks(const QByteArray &bookmarks)
rootItem = new BookmarkItem(DataVector() << tr("Name") << tr("Address")
<< true);
- BookmarkItem* item = new BookmarkItem(DataVector() << tr("Bookmarks Menu")
- << QLatin1String("Folder") << true);
- rootItem->addChild(item);
QStack<BookmarkItem*> parents;
- parents.push(item);
+ QDataStream stream(bookmarks);
+
+ qint32 version;
+ stream >> version;
+ if (version < VERSION) {
+ stream.device()->seek(0);
+ BookmarkItem* toolbar = new BookmarkItem(DataVector() << tr("Toolbar Menu")
+ << QLatin1String("Folder") << true);
+ rootItem->addChild(toolbar);
+
+ BookmarkItem* menu = new BookmarkItem(DataVector() << tr("Bookmarks Menu")
+ << QLatin1String("Folder") << true);
+ rootItem->addChild(menu);
+ parents.push(menu);
+ } else {
+ parents.push(rootItem);
+ }
qint32 depth;
bool expanded;
QString name, url;
- QDataStream stream(bookmarks);
while (!stream.atEnd()) {
stream >> depth >> name >> url >> expanded;
-
while ((parents.count() - 1) != depth)
parents.pop();
- item = new BookmarkItem(DataVector() << name << url << expanded);
+ BookmarkItem *item = new BookmarkItem(DataVector() << name << url << expanded);
if (url == QLatin1String("Folder")) {
parents.top()->addChild(item);
parents.push(item);
@@ -114,11 +127,7 @@ BookmarkModel::setBookmarks(const QByteArray &bookmarks)
}
cache.clear();
- const QModelIndex &root = index(0,0, QModelIndex());
-
- setupCache(root);
- cache.insert(static_cast<BookmarkItem*> (root.internalPointer()), root);
-
+ setupCache(index(0,0, QModelIndex().parent()));
endResetModel();
}
diff --git a/tools/assistant/tools/assistant/centralwidget.cpp b/tools/assistant/tools/assistant/centralwidget.cpp
index f42dfdf..a232383 100644
--- a/tools/assistant/tools/assistant/centralwidget.cpp
+++ b/tools/assistant/tools/assistant/centralwidget.cpp
@@ -38,966 +38,514 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "tracer.h"
#include "centralwidget.h"
+
#include "findwidget.h"
#include "helpenginewrapper.h"
-#include "searchwidget.h"
-#include "mainwindow.h"
+#include "helpviewer.h"
+#include "openpagesmanager.h"
+#include "tracer.h"
#include "../shared/collectionconfiguration.h"
-#if defined(QT_NO_WEBKIT)
-#include "helpviewer_qtb.h"
-#else
-#include "helpviewer_qwv.h"
-#endif // QT_NO_WEBKIT
-
#include <QtCore/QTimer>
-#include <QtGui/QApplication>
#include <QtGui/QKeyEvent>
-#include <QtGui/QLayout>
#include <QtGui/QMenu>
-#include <QtGui/QPrinter>
-#include <QtGui/QTabBar>
-#include <QtGui/QTabWidget>
-#include <QtGui/QTextBrowser>
-#include <QtGui/QToolButton>
#include <QtGui/QPageSetupDialog>
#include <QtGui/QPrintDialog>
#include <QtGui/QPrintPreviewDialog>
+#include <QtGui/QPrinter>
+#include <QtGui/QStackedWidget>
+#include <QtGui/QTextBrowser>
+#include <QtGui/QVBoxLayout>
#include <QtHelp/QHelpSearchEngine>
QT_BEGIN_NAMESPACE
namespace {
- HelpViewer* helpViewerFromTabPosition(const QTabWidget *widget,
- const QPoint &point)
- {
- TRACE_OBJ
- 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;
- }
CentralWidget *staticCentralWidget = 0;
}
-// -- CentralWidget
+// -- TabBar
-CentralWidget::CentralWidget(MainWindow *parent)
- : QWidget(parent)
- , lastTabPage(0)
- , tabWidget(0)
- , findWidget(0)
- , printer(0)
- , usesDefaultCollection(parent->usesDefaultCollection())
- , m_searchWidget(0)
+TabBar::TabBar(QWidget *parent)
+ : QTabBar(parent)
{
TRACE_OBJ
- globalActionList.clear();
- staticCentralWidget = this;
- QVBoxLayout *vboxLayout = new QVBoxLayout(this);
- QString resourcePath = QLatin1String(":/trolltech/assistant/images/");
-
- vboxLayout->setMargin(0);
- tabWidget = new QTabWidget(this);
-#ifndef Q_OS_MAC
- resourcePath.append(QLatin1String("win"));
-#else
- resourcePath.append(QLatin1String("mac"));
- tabWidget->setDocumentMode(true);
-#endif
-
- 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(resourcePath + QLatin1String("/addtab.png")));
-
- tabWidget->setCornerWidget(newTabButton, Qt::TopLeftCorner);
- connect(newTabButton, SIGNAL(clicked()), this, SLOT(newTab()));
-
- QToolButton *closeTabButton = new QToolButton(this);
- closeTabButton->setEnabled(false);
- closeTabButton->setAutoRaise(true);
- closeTabButton->setToolTip(tr("Close current page"));
- closeTabButton->setIcon(QIcon(resourcePath + QLatin1String("/closetab.png")));
-
- tabWidget->setCornerWidget(closeTabButton, Qt::TopRightCorner);
- connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeTab()));
-
- vboxLayout->addWidget(tabWidget);
-
- findWidget = new FindWidget(this);
- vboxLayout->addWidget(findWidget);
- findWidget->hide();
-
- connect(findWidget, SIGNAL(findNext()), this, SLOT(findNext()));
- connect(findWidget, SIGNAL(findPrevious()), this, SLOT(findPrevious()));
- connect(findWidget, SIGNAL(find(QString, bool)), this,
- SLOT(find(QString, bool)));
- connect(findWidget, SIGNAL(escapePressed()), this, SLOT(activateTab()));
-
- QTabBar *tabBar = qFindChild<QTabBar*>(tabWidget);
- if (tabBar) {
- tabBar->installEventFilter(this);
- tabBar->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(tabBar, SIGNAL(customContextMenuRequested(QPoint)), this,
- SLOT(showTabBarContextMenu(QPoint)));
- }
-
-#if defined(QT_NO_WEBKIT)
- QPalette p = palette();
- p.setColor(QPalette::Inactive, QPalette::Highlight,
- p.color(QPalette::Active, QPalette::Highlight));
- p.setColor(QPalette::Inactive, QPalette::HighlightedText,
- p.color(QPalette::Active, QPalette::HighlightedText));
- setPalette(p);
+#ifdef Q_OS_MAC
+ setDocumentMode(true);
#endif
+ setMovable(true);
+ setShape(QTabBar::RoundedNorth);
+ setContextMenuPolicy(Qt::CustomContextMenu);
+ setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred,
+ QSizePolicy::TabWidget));
+ connect(this, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentChanged(int)));
+ connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(slotTabCloseRequested(int)));
+ connect(this, SIGNAL(customContextMenuRequested(QPoint)), this,
+ SLOT(slotCustomContextMenuRequested(QPoint)));
}
-CentralWidget::~CentralWidget()
+TabBar::~TabBar()
{
TRACE_OBJ
-#ifndef QT_NO_PRINTER
- delete printer;
-#endif
-
- QStringList zoomFactors;
- QStringList currentPages;
- bool searchAttached = m_searchWidget->isAttached();
-
- int i = searchAttached ? 1 : 0;
- for (; i < tabWidget->count(); ++i) {
- HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i));
- if (viewer && viewer->source().isValid()) {
- currentPages << viewer->source().toString();
- zoomFactors << QString::number(viewer->scale());
- }
- }
-
- HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
- helpEngine.setLastTabPage(tabWidget->currentIndex());
- helpEngine.setLastShownPages(currentPages);
- helpEngine.setSearchWasAttached(searchAttached);
- helpEngine.setLastZoomFactors(zoomFactors);
}
-CentralWidget *CentralWidget::instance()
+int TabBar::addNewTab(const QString &title)
{
TRACE_OBJ
- return staticCentralWidget;
+ const int index = addTab(title);
+ setTabsClosable(count() > 1);
+ return index;
}
-void CentralWidget::newTab()
+void TabBar::setCurrent(HelpViewer *viewer)
{
TRACE_OBJ
- HelpViewer *viewer = currentHelpViewer();
-#if !defined(QT_NO_WEBKIT)
- if (viewer && viewer->hasLoadFinished())
-#else
- if (viewer)
-#endif
- setSourceInNewTab(viewer->source());
-}
-
-void CentralWidget::zoomIn()
-{
- TRACE_OBJ
- HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- viewer->scaleUp();
-
- if (tabWidget->currentWidget() == m_searchWidget)
- m_searchWidget->zoomIn();
+ for (int i = 0; i < count(); ++i) {
+ HelpViewer *data = tabData(i).value<HelpViewer*>();
+ if (data == viewer) {
+ setCurrentIndex(i);
+ break;
+ }
+ }
}
-void CentralWidget::zoomOut()
+void TabBar::removeTabAt(HelpViewer *viewer)
{
TRACE_OBJ
- HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- viewer->scaleDown();
-
- if (tabWidget->currentWidget() == m_searchWidget)
- m_searchWidget->zoomOut();
+ for (int i = 0; i < count(); ++i) {
+ HelpViewer *data = tabData(i).value<HelpViewer*>();
+ if (data == viewer) {
+ removeTab(i);
+ break;
+ }
+ }
+ setTabsClosable(count() > 1);
}
-void CentralWidget::nextPage()
+void TabBar::titleChanged()
{
TRACE_OBJ
- int index = tabWidget->currentIndex() + 1;
- if (index >= tabWidget->count())
- index = 0;
- tabWidget->setCurrentIndex(index);
+ for (int i = 0; i < count(); ++i) {
+ HelpViewer *data = tabData(i).value<HelpViewer*>();
+ QString title = data->title();
+ title.replace(QLatin1Char('&'), QLatin1String("&&"));
+ setTabText(i, title.isEmpty() ? tr("(Untitled)") : title);
+ }
}
-void CentralWidget::resetZoom()
+void TabBar::slotCurrentChanged(int index)
{
TRACE_OBJ
- if (HelpViewer *viewer = currentHelpViewer())
- viewer->resetScale();
-
- if (tabWidget->currentWidget() == m_searchWidget)
- m_searchWidget->resetZoom();
+ emit currentTabChanged(tabData(index).value<HelpViewer*>());
}
-void CentralWidget::previousPage()
+void TabBar::slotTabCloseRequested(int index)
{
TRACE_OBJ
- int index = tabWidget->currentIndex() -1;
- if (index < 0)
- index = tabWidget->count() -1;
- tabWidget->setCurrentIndex(index);
+ OpenPagesManager::instance()->closePage(tabData(index).value<HelpViewer*>());
}
-void CentralWidget::closeTab()
+void TabBar::slotCustomContextMenuRequested(const QPoint &pos)
{
TRACE_OBJ
- HelpViewer *viewer = currentHelpViewer();
- if (!viewer|| tabWidget->count() == 1)
+ const int tab = tabAt(pos);
+ if (tab < 0)
return;
- tabWidget->removeTab(tabWidget->indexOf(viewer));
- QTimer::singleShot(0, viewer, SLOT(deleteLater()));
+ QMenu menu(QLatin1String(""), this);
+ menu.addAction(tr("New &Tab"), OpenPagesManager::instance(), SLOT(createPage()));
+
+ const bool enableAction = count() > 1;
+ QAction *closePage = menu.addAction(tr("&Close Tab"));
+ closePage->setEnabled(enableAction);
+
+ QAction *closePages = menu.addAction(tr("Close Other Tabs"));
+ closePages->setEnabled(enableAction);
+
+ menu.addSeparator();
+
+ HelpViewer *viewer = tabData(tab).value<HelpViewer*>();
+ 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(mapToGlobal(pos));
+ if (pickedAction == closePage)
+ slotTabCloseRequested(tab);
+ else if (pickedAction == closePages) {
+ for (int i = count() - 1; i >= 0; --i) {
+ if (i != tab)
+ slotTabCloseRequested(i);
+ }
+ } else if (pickedAction == newBookmark)
+ emit addBookmark(viewer->title(), url);
}
-void CentralWidget::setSource(const QUrl &url)
+// -- CentralWidget
+
+CentralWidget::CentralWidget(QWidget *parent)
+ : QWidget(parent)
+#ifndef QT_NO_PRINTER
+ , m_printer(0)
+#endif
+ , m_findWidget(new FindWidget(this))
+ , m_stackedWidget(new QStackedWidget(this))
+ , m_tabBar(new TabBar(this))
{
TRACE_OBJ
- HelpViewer *viewer = currentHelpViewer();
- HelpViewer *lastViewer =
- qobject_cast<HelpViewer*>(tabWidget->widget(lastTabPage));
-
- if (!viewer && !lastViewer) {
- viewer = new HelpViewer(this);
- viewer->installEventFilter(this);
- lastTabPage = tabWidget->addTab(viewer, QString());
- tabWidget->setCurrentIndex(lastTabPage);
- connectSignals();
- } else {
- viewer = lastViewer;
- }
+ staticCentralWidget = this;
+ QVBoxLayout *vboxLayout = new QVBoxLayout(this);
- viewer->setSource(url);
- currentPageChanged(lastTabPage);
- viewer->setFocus(Qt::OtherFocusReason);
- tabWidget->setCurrentIndex(lastTabPage);
- tabWidget->setTabText(lastTabPage, quoteTabTitle(viewer->documentTitle()));
+ vboxLayout->setMargin(0);
+ vboxLayout->setSpacing(0);
+ vboxLayout->addWidget(m_tabBar);
+ m_tabBar->setVisible(HelpEngineWrapper::instance().showTabs());
+ vboxLayout->addWidget(m_stackedWidget);
+ vboxLayout->addWidget(m_findWidget);
+ m_findWidget->hide();
+
+ connect(m_findWidget, SIGNAL(findNext()), this, SLOT(findNext()));
+ connect(m_findWidget, SIGNAL(findPrevious()), this, SLOT(findPrevious()));
+ connect(m_findWidget, SIGNAL(find(QString, bool, bool)), this,
+ SLOT(find(QString, bool, bool)));
+ connect(m_findWidget, SIGNAL(escapePressed()), this, SLOT(activateTab()));
+ connect(m_tabBar, SIGNAL(addBookmark(QString, QString)), this,
+ SIGNAL(addBookmark(QString, QString)));
}
-void CentralWidget::setupWidget()
+CentralWidget::~CentralWidget()
{
TRACE_OBJ
- HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
- int option = helpEngine.startOption();
- if (option != ShowLastPages) {
- QString homePage;
- if (option == ShowHomePage)
- homePage = helpEngine.homePage();
- else if (option == ShowBlankPage)
- homePage = QLatin1String("about:blank");
- setSource(homePage);
- } else {
- setLastShownPages();
+ QStringList zoomFactors;
+ QStringList currentPages;
+ 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();
+ zoomFactors << QString::number(viewer->scale());
+ }
}
-}
-void CentralWidget::setLastShownPages()
-{
- TRACE_OBJ
HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
- const QStringList &lastShownPageList = helpEngine.lastShownPages();
- const int pageCount = lastShownPageList.count();
- if (pageCount == 0) {
- if (usesDefaultCollection)
- setSource(QUrl(QLatin1String("help")));
- else
- setSource(QUrl(QLatin1String("about:blank")));
- return;
- }
- QStringList zoomFactors = helpEngine.lastZoomFactors();
- while (zoomFactors.count() < pageCount)
- zoomFactors.append(CollectionConfiguration::DefaultZoomFactor);
-
- const bool searchIsAttached = m_searchWidget->isAttached();
- const bool searchWasAttached = helpEngine.searchWasAttached();
- int tabToShow = helpEngine.lastTabPage();
- if (searchWasAttached && !searchIsAttached && tabToShow != 0)
- --tabToShow;
- else if (!searchWasAttached && searchIsAttached)
- ++tabToShow;
-
- for (int curTab = 0; curTab < pageCount; ++curTab) {
- const QString &curFile = lastShownPageList.at(curTab);
- if (helpEngine.findFile(curFile).isValid()
- || curFile == QLatin1String("about:blank")) {
- setSourceInNewTab(curFile, zoomFactors.at(curTab).toFloat());
- } else if (curTab + searchIsAttached <= tabToShow)
- --tabToShow;
- }
+ helpEngine.setLastShownPages(currentPages);
+ helpEngine.setLastZoomFactors(zoomFactors);
+ helpEngine.setLastTabPage(m_stackedWidget->currentIndex());
- tabWidget->setCurrentIndex(tabToShow);
+#ifndef QT_NO_PRINTER
+ delete m_printer;
+#endif
}
-bool CentralWidget::hasSelection() const
+CentralWidget *CentralWidget::instance()
{
TRACE_OBJ
- const HelpViewer *viewer = currentHelpViewer();
- return viewer ? viewer->hasSelection() : false;
+ return staticCentralWidget;
}
QUrl CentralWidget::currentSource() const
{
TRACE_OBJ
- const HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- return viewer->source();
-
- return QUrl();
+ return currentHelpViewer()->source();
}
QString CentralWidget::currentTitle() const
{
TRACE_OBJ
- const HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- return viewer->documentTitle();
-
- return QString();
+ return currentHelpViewer()->title();
}
-void CentralWidget::copySelection()
+bool CentralWidget::hasSelection() const
{
TRACE_OBJ
- HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- viewer->copy();
+ return !currentHelpViewer()->selectedText().isEmpty();
}
-void CentralWidget::showTextSearch()
+bool CentralWidget::isForwardAvailable() const
{
TRACE_OBJ
- findWidget->show();
+ return currentHelpViewer()->isForwardAvailable();
}
-void CentralWidget::initPrinter()
+bool CentralWidget::isBackwardAvailable() const
{
TRACE_OBJ
-#ifndef QT_NO_PRINTER
- if (!printer)
- printer = new QPrinter(QPrinter::HighResolution);
-#endif
+ return currentHelpViewer()->isBackwardAvailable();
}
-void CentralWidget::print()
+HelpViewer* CentralWidget::viewerAt(int index) const
{
TRACE_OBJ
-#ifndef QT_NO_PRINTER
- HelpViewer *viewer = currentHelpViewer();
- if (!viewer)
- return;
-
- initPrinter();
-
- QPrintDialog dlg(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);
- }
-#endif
+ return static_cast<HelpViewer*>(m_stackedWidget->widget(index));
}
-void CentralWidget::printPreview()
+HelpViewer* CentralWidget::currentHelpViewer() const
{
TRACE_OBJ
-#ifndef QT_NO_PRINTER
- initPrinter();
- QPrintPreviewDialog preview(printer, this);
- connect(&preview, SIGNAL(paintRequested(QPrinter*)),
- SLOT(printPreview(QPrinter*)));
- preview.exec();
-#endif
+ return static_cast<HelpViewer *>(m_stackedWidget->currentWidget());
}
-void CentralWidget::printPreview(QPrinter *p)
+void CentralWidget::addPage(HelpViewer *page, bool fromSearch)
{
TRACE_OBJ
-#ifndef QT_NO_PRINTER
- HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- viewer->print(p);
-#endif
-}
+ page->installEventFilter(this);
+ page->setFocus(Qt::OtherFocusReason);
+ connectSignals(page);
+ const int index = m_stackedWidget->addWidget(page);
+ m_tabBar->setTabData(m_tabBar->addNewTab(page->title()),
+ QVariant::fromValue(viewerAt(index)));
+ connect (page, SIGNAL(titleChanged()), m_tabBar, SLOT(titleChanged()));
-void CentralWidget::pageSetup()
-{
- TRACE_OBJ
-#ifndef QT_NO_PRINTER
- initPrinter();
- QPageSetupDialog dlg(printer);
- dlg.exec();
-#endif
+ if (fromSearch) {
+ connect(currentHelpViewer(), SIGNAL(loadFinished(bool)), this,
+ SLOT(highlightSearchTerms()));
+ }
}
-bool CentralWidget::isHomeAvailable() const
+void CentralWidget::removePage(int index)
{
TRACE_OBJ
- return currentHelpViewer() ? true : false;
+ const bool currentChanged = index == currentIndex();
+ m_tabBar->removeTabAt(viewerAt(index));
+ m_stackedWidget->removeWidget(m_stackedWidget->widget(index));
+ if (currentChanged)
+ emit currentViewerChanged();
}
-void CentralWidget::home()
+int CentralWidget::currentIndex() const
{
TRACE_OBJ
- HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- viewer->home();
+ return m_stackedWidget->currentIndex();
}
-bool CentralWidget::isForwardAvailable() const
+void CentralWidget::setCurrentPage(HelpViewer *page)
{
TRACE_OBJ
- const HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- return viewer->isForwardAvailable();
-
- return false;
+ m_tabBar->setCurrent(page);
+ m_stackedWidget->setCurrentWidget(page);
+ emit currentViewerChanged();
}
-void CentralWidget::forward()
+void CentralWidget::connectTabBar()
{
TRACE_OBJ
- HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- viewer->forward();
+ connect(m_tabBar, SIGNAL(currentTabChanged(HelpViewer*)),
+ OpenPagesManager::instance(), SLOT(setCurrentPage(HelpViewer*)));
}
-bool CentralWidget::isBackwardAvailable() const
-{
- TRACE_OBJ
- const HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- return viewer->isBackwardAvailable();
-
- return false;
-}
+// -- public slots
-void CentralWidget::backward()
+void CentralWidget::copy()
{
TRACE_OBJ
- HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- viewer->backward();
+ currentHelpViewer()->copy();
}
-
-QList<QAction*> CentralWidget::globalActions() const
+void CentralWidget::home()
{
TRACE_OBJ
- return globalActionList;
+ currentHelpViewer()->home();
}
-void CentralWidget::setGlobalActions(const QList<QAction*> &actions)
+void CentralWidget::zoomIn()
{
TRACE_OBJ
- globalActionList = actions;
+ currentHelpViewer()->scaleUp();
}
-void CentralWidget::setSourceInNewTab(const QUrl &url, qreal zoom)
+void CentralWidget::zoomOut()
{
TRACE_OBJ
- if (HelpViewer *viewer = currentHelpViewer()) {
- if (viewer->launchWithExternalApp(url))
- return;
- }
-
- HelpViewer *viewer = new HelpViewer(this, zoom);
- viewer->installEventFilter(this);
- viewer->setSource(url);
- viewer->setFocus(Qt::OtherFocusReason);
- tabWidget->setCurrentIndex(tabWidget->addTab(viewer,
- quoteTabTitle(viewer->documentTitle())));
- connectSignals();
+ currentHelpViewer()->scaleDown();
}
-HelpViewer *CentralWidget::newEmptyTab()
+void CentralWidget::resetZoom()
{
TRACE_OBJ
- HelpViewer *viewer = new HelpViewer(this);
- viewer->installEventFilter(this);
- viewer->setFocus(Qt::OtherFocusReason);
-#if defined(QT_NO_WEBKIT)
- viewer->setDocumentTitle(tr("unknown"));
-#endif
- tabWidget->setCurrentIndex(tabWidget->addTab(viewer, tr("unknown")));
-
- connectSignals();
- return viewer;
+ currentHelpViewer()->resetScale();
}
-void CentralWidget::connectSignals()
+void CentralWidget::forward()
{
TRACE_OBJ
- 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)));
- connect(viewer, SIGNAL(printRequested()), this, SLOT(print()));
- }
+ currentHelpViewer()->forward();
}
-HelpViewer* CentralWidget::viewerAt(int index) const
+void CentralWidget::nextPage()
{
TRACE_OBJ
- return qobject_cast<HelpViewer*>(tabWidget->widget(index));
+ m_stackedWidget->setCurrentIndex((m_stackedWidget->currentIndex() + 1)
+ % m_stackedWidget->count());
}
-HelpViewer* CentralWidget::currentHelpViewer() const
+void CentralWidget::backward()
{
TRACE_OBJ
- return qobject_cast<HelpViewer*>(tabWidget->currentWidget());
+ currentHelpViewer()->backward();
}
-void CentralWidget::activateTab(bool onlyHelpViewer)
+void CentralWidget::previousPage()
{
TRACE_OBJ
- if (currentHelpViewer()) {
- currentHelpViewer()->setFocus();
- } else {
- int idx = 0;
- if (onlyHelpViewer)
- idx = lastTabPage;
- tabWidget->setCurrentIndex(idx);
- tabWidget->currentWidget()->setFocus();
- }
+ m_stackedWidget->setCurrentIndex((m_stackedWidget->currentIndex() - 1)
+ % m_stackedWidget->count());
}
-void CentralWidget::setTabTitle(const QUrl &url)
+void CentralWidget::print()
{
TRACE_OBJ
- Q_UNUSED(url)
-#if !defined(QT_NO_WEBKIT)
- QTabBar *tabBar = qFindChild<QTabBar*>(tabWidget);
- for (int tab = 0; tab < tabBar->count(); ++tab) {
- HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(tab));
- if (viewer) {
- tabWidget->setTabText(tab,
- quoteTabTitle(viewer->documentTitle().trimmed()));
- }
- }
-#else
- HelpViewer *viewer = currentHelpViewer();
- if (viewer) {
- tabWidget->setTabText(lastTabPage,
- quoteTabTitle(viewer->documentTitle().trimmed()));
- }
+#ifndef QT_NO_PRINTER
+ initPrinter();
+ QPrintDialog dlg(m_printer, this);
+
+ if (!currentHelpViewer()->selectedText().isEmpty())
+ dlg.addEnabledOption(QAbstractPrintDialog::PrintSelection);
+ dlg.addEnabledOption(QAbstractPrintDialog::PrintPageRange);
+ dlg.addEnabledOption(QAbstractPrintDialog::PrintCollateCopies);
+ dlg.setWindowTitle(tr("Print Document"));
+ if (dlg.exec() == QDialog::Accepted)
+ currentHelpViewer()->print(m_printer);
#endif
}
-void CentralWidget::currentPageChanged(int index)
+void CentralWidget::pageSetup()
{
TRACE_OBJ
- const HelpViewer *viewer = currentHelpViewer();
- if (viewer)
- lastTabPage = index;
-
- QWidget *widget = tabWidget->cornerWidget(Qt::TopRightCorner);
- widget->setEnabled(viewer && enableTabCloseAction());
-
- widget = tabWidget->cornerWidget(Qt::TopLeftCorner);
- widget->setEnabled(viewer ? true : false);
-
- emit currentViewerChanged();
+#ifndef QT_NO_PRINTER
+ initPrinter();
+ QPageSetupDialog dlg(m_printer);
+ dlg.exec();
+#endif
}
-void CentralWidget::showTabBarContextMenu(const QPoint &point)
+void CentralWidget::printPreview()
{
TRACE_OBJ
- 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 = enableTabCloseAction();
- QAction *closePage = menu.addAction(tr("Close This Page"));
- closePage->setEnabled(enableAction);
-
- QAction *closePages = menu.addAction(tr("Close Other Pages"));
- closePages->setEnabled(enableAction);
-
- menu.addSeparator();
-
- 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 addBookmark(viewer->documentTitle(), viewer->source().toString());
+#ifndef QT_NO_PRINTER
+ initPrinter();
+ QPrintPreviewDialog preview(m_printer, this);
+ connect(&preview, SIGNAL(paintRequested(QPrinter*)),
+ SLOT(printPreview(QPrinter*)));
+ preview.exec();
+#endif
}
-bool CentralWidget::eventFilter(QObject *object, QEvent *e)
+void CentralWidget::setSource(const QUrl &url)
{
TRACE_OBJ
- if (e->type() == QEvent::KeyPress) {
- QKeyEvent *ke = static_cast<QKeyEvent*>(e);
- switch (ke->key()) {
- default: {
- return QWidget::eventFilter(object, e);
- } break;
-
- case Qt::Key_Backspace: {
- HelpViewer *viewer = currentHelpViewer();
- if (viewer == object) {
-#if defined(QT_NO_WEBKIT)
- if (viewer->isBackwardAvailable()) {
-#else
- if (viewer->isBackwardAvailable() && !viewer->hasFocus()) {
-#endif
- viewer->backward();
- return true;
- }
- }
- } break;
- }
- }
-
- if (qobject_cast<QTabBar*>(object)) {
- const bool dblClick = e->type() == QEvent::MouseButtonDblClick;
- if ((e->type() == QEvent::MouseButtonRelease) || dblClick) {
- QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(e);
- HelpViewer *viewer = helpViewerFromTabPosition(tabWidget,
- mouseEvent->pos());
- if (viewer) {
- if ((mouseEvent->button() == Qt::MidButton) || dblClick) {
- if (availableHelpViewer() > 1) {
- tabWidget->removeTab(tabWidget->indexOf(viewer));
- QTimer::singleShot(0, viewer, SLOT(deleteLater()));
- currentPageChanged(tabWidget->currentIndex());
- return true;
- }
- }
- }
- }
- }
-
- return QWidget::eventFilter(object, e);
+ HelpViewer *viewer = currentHelpViewer();
+ viewer->setSource(url);
+ viewer->setFocus(Qt::OtherFocusReason);
}
-void CentralWidget::keyPressEvent(QKeyEvent *e)
+void CentralWidget::setSourceFromSearch(const QUrl &url)
{
TRACE_OBJ
- const QString &text = e->text();
- if (text.startsWith(QLatin1Char('/'))) {
- if (!findWidget->isVisible()) {
- findWidget->showAndClear();
- } else {
- findWidget->show();
- }
- } else {
- QWidget::keyPressEvent(e);
- }
+ connect(currentHelpViewer(), SIGNAL(loadFinished(bool)), this,
+ SLOT(highlightSearchTerms()));
+ currentHelpViewer()->setSource(url);
+ currentHelpViewer()->setFocus(Qt::OtherFocusReason);
}
void CentralWidget::findNext()
{
TRACE_OBJ
- find(findWidget->text(), true);
+ find(m_findWidget->text(), true, false);
}
void CentralWidget::findPrevious()
{
TRACE_OBJ
- find(findWidget->text(), false);
+ find(m_findWidget->text(), false, false);
}
-void CentralWidget::find(const QString &ttf, bool forward)
+void CentralWidget::find(const QString &ttf, bool forward, bool incremental)
{
TRACE_OBJ
bool found = false;
-#if defined(QT_NO_WEBKIT)
- found = findInTextBrowser(ttf, forward);
-#else
- found = findInWebPage(ttf, forward);
-#endif
+ if (HelpViewer *viewer = currentHelpViewer()) {
+ HelpViewer::FindFlags flags = 0;
+ if (!forward)
+ flags |= HelpViewer::FindBackward;
+ if (m_findWidget->caseSensitive())
+ flags |= HelpViewer::FindCaseSensitively;
+ found = viewer->findText(ttf, flags, incremental, false);
+ }
if (!found && ttf.isEmpty())
found = true; // the line edit is empty, no need to mark it red...
- if (!findWidget->isVisible())
- findWidget->show();
- findWidget->setPalette(found);
+ if (!m_findWidget->isVisible())
+ m_findWidget->show();
+ m_findWidget->setPalette(found);
}
-bool CentralWidget::findInWebPage(const QString &ttf, bool forward)
+void CentralWidget::activateTab()
{
TRACE_OBJ
-#if !defined(QT_NO_WEBKIT)
- if (HelpViewer *viewer = currentHelpViewer()) {
- bool found = false;
- QWebPage::FindFlags options;
- if (!ttf.isEmpty()) {
- if (!forward)
- options |= QWebPage::FindBackward;
-
- if (findWidget->caseSensitive())
- options |= QWebPage::FindCaseSensitively;
-
- found = viewer->findText(ttf, options);
- findWidget->setTextWrappedVisible(false);
-
- if (!found) {
- options |= QWebPage::FindWrapsAroundDocument;
- found = viewer->findText(ttf, options);
- if (found)
- findWidget->setTextWrappedVisible(true);
- }
- }
- // force highlighting of all other matches, also when empty (clear)
- options = QWebPage::HighlightAllOccurrences;
- if (findWidget->caseSensitive())
- options |= QWebPage::FindCaseSensitively;
- viewer->findText(QLatin1String(""), options);
- viewer->findText(ttf, options);
- return found;
- }
-
- // this needs to stay, case for active search results page
- return findInTextBrowser(ttf, forward);
-#else
- Q_UNUSED(ttf);
- Q_UNUSED(forward);
-#endif
- return false;
+ currentHelpViewer()->setFocus();
}
-bool CentralWidget::findInTextBrowser(const QString &ttf, bool forward)
+void CentralWidget::showTextSearch()
{
TRACE_OBJ
- QTextBrowser *browser = qobject_cast<QTextBrowser*>(currentHelpViewer());
- if (tabWidget->currentWidget() == m_searchWidget)
- browser = qFindChild<QTextBrowser*>(m_searchWidget);
-
- if (!browser || ttf.isEmpty())
- return false;
-
- QTextDocument *doc = browser->document();
- QTextCursor cursor = browser->textCursor();
-
- if (!doc || cursor.isNull())
- return false;
-
- QTextDocument::FindFlags options;
-
- if (cursor.hasSelection()) {
- cursor.setPosition(forward ? cursor.position() : cursor.anchor(),
- QTextCursor::MoveAnchor);
- }
-
- if (!forward)
- options |= QTextDocument::FindBackward;
-
- if (findWidget->caseSensitive())
- options |= QTextDocument::FindCaseSensitively;
-
- findWidget->setTextWrappedVisible(false);
-
- bool found = true;
- QTextCursor newCursor = doc->find(ttf, cursor, options);
- if (newCursor.isNull()) {
- QTextCursor ac(doc);
- ac.movePosition(options & QTextDocument::FindBackward
- ? QTextCursor::End : QTextCursor::Start);
- newCursor = doc->find(ttf, ac, options);
- if (newCursor.isNull()) {
- found = false;
- newCursor = cursor;
- } else {
- findWidget->setTextWrappedVisible(true);
- }
- }
- browser->setTextCursor(newCursor);
- return found;
+ m_findWidget->show();
}
void CentralWidget::updateBrowserFont()
{
TRACE_OBJ
- const bool searchAttached = searchWidgetAttached();
- if (searchAttached) {
- HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
- m_searchWidget->setFont(helpEngine.usesBrowserFont()
- ? helpEngine.browserFont() : qApp->font());
- }
-
- const int count = tabWidget->count();
- if (HelpViewer* viewer = viewerAt(count - 1)) {
- const QFont &font = viewer->viewerFont();
- for (int i = searchAttached ? 1 : 0; i < count; ++i)
- viewerAt(i)->setViewerFont(font);
- }
-}
-
-bool CentralWidget::searchWidgetAttached() const
-{
- TRACE_OBJ
- return m_searchWidget && m_searchWidget->isAttached();
+ const int count = m_stackedWidget->count();
+ const QFont &font = viewerAt(count - 1)->viewerFont();
+ for (int i = 0; i < count; ++i)
+ viewerAt(i)->setViewerFont(font);
}
-void CentralWidget::createSearchWidget(QHelpSearchEngine *searchEngine)
+void CentralWidget::updateUserInterface()
{
- TRACE_OBJ
- if (m_searchWidget)
- return;
-
- m_searchWidget = new SearchWidget(searchEngine, this);
- connect(m_searchWidget, SIGNAL(requestShowLink(QUrl)), this,
- SLOT(setSourceFromSearch(QUrl)));
- connect(m_searchWidget, SIGNAL(requestShowLinkInNewTab(QUrl)), this,
- SLOT(setSourceFromSearchInNewTab(QUrl)));
-
- HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
- m_searchWidget->setFont(!helpEngine.usesBrowserFont() ? qApp->font()
- : helpEngine.browserFont());
+ m_tabBar->setVisible(HelpEngineWrapper::instance().showTabs());
}
-void CentralWidget::activateSearchWidget(bool updateLastTabPage)
-{
- TRACE_OBJ
- if (!m_searchWidget)
- createSearchWidget(HelpEngineWrapper::instance().searchEngine());
-
- if (!m_searchWidget->isAttached()) {
- tabWidget->insertTab(0, m_searchWidget, tr("Search"));
- m_searchWidget->setAttached(true);
+// -- protected
- if (updateLastTabPage)
- lastTabPage++;
- }
-
- tabWidget->setCurrentWidget(m_searchWidget);
- m_searchWidget->setFocus();
-}
-
-void CentralWidget::removeSearchWidget()
+void CentralWidget::keyPressEvent(QKeyEvent *e)
{
TRACE_OBJ
- if (searchWidgetAttached()) {
- tabWidget->removeTab(0);
- m_searchWidget->setAttached(false);
+ const QString &text = e->text();
+ if (text.startsWith(QLatin1Char('/'))) {
+ if (!m_findWidget->isVisible()) {
+ m_findWidget->showAndClear();
+ } else {
+ m_findWidget->show();
+ }
+ } else {
+ QWidget::keyPressEvent(e);
}
}
-int CentralWidget::availableHelpViewer() const
-{
- TRACE_OBJ
- int count = tabWidget->count();
- if (searchWidgetAttached())
- count--;
- return count;
-}
-
-bool CentralWidget::enableTabCloseAction() const
-{
- TRACE_OBJ
- int minTabCount = 1;
- if (searchWidgetAttached())
- minTabCount = 2;
-
- return (tabWidget->count() > minTabCount);
-}
-
-QString CentralWidget::quoteTabTitle(const QString &title) const
-{
- TRACE_OBJ
- QString s = title;
- return s.replace(QLatin1Char('&'), QLatin1String("&&"));
-}
-
-void
-CentralWidget::setSourceFromSearch(const QUrl &url)
+void CentralWidget::focusInEvent(QFocusEvent * /* event */)
{
TRACE_OBJ
- setSource(url);
-#if defined(QT_NO_WEBKIT)
- highlightSearchTerms();
-#else
- connect(currentHelpViewer(), SIGNAL(loadFinished(bool)), this,
- SLOT(highlightSearchTerms()));
-#endif
+ // 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()));
}
-void
-CentralWidget::setSourceFromSearchInNewTab(const QUrl &url)
-{
- TRACE_OBJ
- setSourceInNewTab(url);
-#if defined(QT_NO_WEBKIT)
- highlightSearchTerms();
-#else
- connect(currentHelpViewer(), SIGNAL(loadFinished(bool)), this,
- SLOT(highlightSearchTerms()));
-#endif
-}
+// -- private slots
-void
-CentralWidget::highlightSearchTerms()
+void CentralWidget::highlightSearchTerms()
{
TRACE_OBJ
- HelpViewer *viewer = currentHelpViewer();
- if (!viewer)
- return;
-
QHelpSearchEngine *searchEngine =
HelpEngineWrapper::instance().searchEngine();
QList<QHelpSearchQuery> queryList = searchEngine->query();
@@ -1016,91 +564,73 @@ CentralWidget::highlightSearchTerms()
}
}
-#if defined(QT_NO_WEBKIT)
- viewer->viewport()->setUpdatesEnabled(false);
-
- QTextCharFormat marker;
- marker.setForeground(Qt::red);
-
- QTextCursor firstHit;
-
- QTextCursor c = viewer->textCursor();
- c.beginEditBlock();
- foreach (const QString& term, terms) {
- c.movePosition(QTextCursor::Start);
- viewer->setTextCursor(c);
-
- while (viewer->find(term, QTextDocument::FindWholeWords)) {
- QTextCursor hit = viewer->textCursor();
- if (firstHit.isNull() || hit.position() < firstHit.position())
- firstHit = hit;
-
- hit.mergeCharFormat(marker);
- }
- }
-
- if (firstHit.isNull()) {
- firstHit = viewer->textCursor();
- firstHit.movePosition(QTextCursor::Start);
- }
- firstHit.clearSelection();
- c.endEditBlock();
- viewer->setTextCursor(firstHit);
-
- viewer->viewport()->setUpdatesEnabled(true);
-#else
- viewer->findText("", QWebPage::HighlightAllOccurrences);
- // clears existing selections
+ HelpViewer *viewer = currentHelpViewer();
foreach (const QString& term, terms)
- viewer->findText(term, QWebPage::HighlightAllOccurrences);
-
+ viewer->findText(term, 0, false, true);
disconnect(viewer, SIGNAL(loadFinished(bool)), this,
SLOT(highlightSearchTerms()));
+}
+
+void CentralWidget::printPreview(QPrinter *p)
+{
+ TRACE_OBJ
+#ifndef QT_NO_PRINTER
+ currentHelpViewer()->print(p);
#endif
}
+void CentralWidget::handleSourceChanged(const QUrl &url)
+{
+ TRACE_OBJ
+ if (sender() == currentHelpViewer())
+ emit sourceChanged(url);
+}
-void CentralWidget::closeOrReloadTabs(const QList<int> &indices, bool tryReload)
+// -- private
+
+void CentralWidget::initPrinter()
{
TRACE_OBJ
- QList<int> sortedIndices = indices;
- qSort(sortedIndices);
- for (int i = sortedIndices.count(); --i >= 0;) {
- const int tab = sortedIndices.at(i);
- bool close = true;
- if (tryReload) {
- HelpViewer *viewer =
- qobject_cast<HelpViewer*>(tabWidget->widget(tab));
- if (HelpEngineWrapper::instance().findFile(viewer->source()).isValid()) {
- viewer->reload();
- close = false;
- }
- }
- if (close)
- closeTabAt(tab);
- }
- if (availableHelpViewer() == 0)
- setSource(QUrl(QLatin1String("about:blank")));
+#ifndef QT_NO_PRINTER
+ if (!m_printer)
+ m_printer = new QPrinter(QPrinter::HighResolution);
+#endif
}
-void CentralWidget::closeTabAt(int index)
+void CentralWidget::connectSignals(HelpViewer *page)
{
TRACE_OBJ
- HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(index));
- tabWidget->removeTab(index);
- QTimer::singleShot(0, viewer, SLOT(deleteLater()));
+ connect(page, SIGNAL(copyAvailable(bool)), this,
+ SIGNAL(copyAvailable(bool)));
+ connect(page, SIGNAL(forwardAvailable(bool)), this,
+ SIGNAL(forwardAvailable(bool)));
+ connect(page, SIGNAL(backwardAvailable(bool)), this,
+ SIGNAL(backwardAvailable(bool)));
+ connect(page, SIGNAL(sourceChanged(QUrl)), this,
+ SLOT(handleSourceChanged(QUrl)));
+ connect(page, SIGNAL(highlighted(QString)), this,
+ SIGNAL(highlighted(QString)));
+ connect(page, SIGNAL(printRequested()), this, SLOT(print()));
}
-QMap<int, QString> CentralWidget::currentSourceFileList() const
+bool CentralWidget::eventFilter(QObject *object, QEvent *e)
{
TRACE_OBJ
- QMap<int, QString> sourceList;
- for (int i = 0; i < tabWidget->count(); ++i) {
- HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i));
- if (viewer && viewer->source().isValid())
- sourceList.insert(i, viewer->source().host());
+ 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 sourceList;
+ return QWidget::eventFilter(object, e);
}
QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/centralwidget.h b/tools/assistant/tools/assistant/centralwidget.h
index f286ff7..bcadcf4 100644
--- a/tools/assistant/tools/assistant/centralwidget.h
+++ b/tools/assistant/tools/assistant/centralwidget.h
@@ -38,80 +38,102 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+
#ifndef CENTRALWIDGET_H
#define CENTRALWIDGET_H
#include <QtCore/QUrl>
+
+#include <QtGui/QTabBar>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class FindWidget;
class HelpViewer;
-class MainWindow;
-class QHelpSearchEngine;
-class QTabWidget;
-class SearchWidget;
+class QStackedWidget;
+
+class TabBar : public QTabBar
+{
+ Q_OBJECT
+public:
+ TabBar(QWidget *parent = 0);
+ ~TabBar();
+
+ int addNewTab(const QString &title);
+ void setCurrent(HelpViewer *viewer);
+ void removeTabAt(HelpViewer *viewer);
+
+public slots:
+ void titleChanged();
+
+signals:
+ void currentTabChanged(HelpViewer *viewer);
+ void addBookmark(const QString &title, const QString &url);
+
+private slots:
+ void slotCurrentChanged(int index);
+ void slotTabCloseRequested(int index);
+ void slotCustomContextMenuRequested(const QPoint &pos);
+};
class CentralWidget : public QWidget
{
Q_OBJECT
public:
- CentralWidget(MainWindow *parent);
+ CentralWidget(QWidget *parent = 0);
~CentralWidget();
- void setupWidget();
- bool hasSelection() const;
+ static CentralWidget *instance();
+
QUrl currentSource() const;
QString currentTitle() const;
- bool isHomeAvailable() const;
+
+ bool hasSelection() 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;
- bool searchWidgetAttached() const;
- void createSearchWidget(QHelpSearchEngine *searchEngine);
- void activateSearchWidget(bool updateLastTabPage = false);
- void removeSearchWidget();
-
- int availableHelpViewer() const;
- bool enableTabCloseAction() const;
+ void addPage(HelpViewer *page, bool fromSearch = false);
+ void removePage(int index);
- void closeOrReloadTabs(const QList<int> &indices, bool tryReload);
- void closeTabAt(int index);
- QMap<int, QString> currentSourceFileList() const;
+ int currentIndex() const;
+ void setCurrentPage(HelpViewer *page);
- static CentralWidget *instance();
+ void connectTabBar();
public slots:
+ void copy();
+ void home();
+
void zoomIn();
void zoomOut();
- void nextPage();
void resetZoom();
+
+ void forward();
+ void nextPage();
+
+ void backward();
void previousPage();
- void copySelection();
- void showTextSearch();
+
void print();
void pageSetup();
void printPreview();
- void updateBrowserFont();
- void setSource(const QUrl &url);
- void setSourceInNewTab(const QUrl &url, qreal zoom = 0.0);
- HelpViewer *newEmptyTab();
- void home();
- void forward();
- void backward();
- void activateTab(bool onlyHelpViewer = false);
+ void setSource(const QUrl &url);
+ void setSourceFromSearch(const QUrl &url);
void findNext();
void findPrevious();
- void find(const QString &text, bool forward);
+ void find(const QString &text, bool forward, bool incremental);
+
+ void activateTab();
+ void showTextSearch();
+ void updateBrowserFont();
+ void updateUserInterface();
signals:
void currentViewerChanged();
@@ -124,37 +146,25 @@ signals:
protected:
void keyPressEvent(QKeyEvent *);
+ void focusInEvent(QFocusEvent *event);
private slots:
- void newTab();
- void closeTab();
- void setTabTitle(const QUrl& url);
- void currentPageChanged(int index);
- void showTabBarContextMenu(const QPoint &point);
- void printPreview(QPrinter *printer);
- void setSourceFromSearch(const QUrl &url);
- void setSourceFromSearchInNewTab(const QUrl &url);
void highlightSearchTerms();
+ void printPreview(QPrinter *printer);
+ void handleSourceChanged(const QUrl &url);
private:
- void connectSignals();
- bool eventFilter(QObject *object, QEvent *e);
- bool findInWebPage(const QString &ttf, bool forward);
- bool findInTextBrowser(const QString &ttf, bool forward);
void initPrinter();
- QString quoteTabTitle(const QString &title) const;
- void setLastShownPages();
+ void connectSignals(HelpViewer *page);
+ bool eventFilter(QObject *object, QEvent *e);
private:
- int lastTabPage;
- QList<QAction*> globalActionList;
-
- QTabWidget *tabWidget;
- FindWidget *findWidget;
- QPrinter *printer;
- bool usesDefaultCollection;
-
- SearchWidget *m_searchWidget;
+#ifndef QT_NO_PRINTER
+ QPrinter *m_printer;
+#endif
+ FindWidget *m_findWidget;
+ QStackedWidget *m_stackedWidget;
+ TabBar *m_tabBar;
};
QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/contentwindow.cpp b/tools/assistant/tools/assistant/contentwindow.cpp
index 8afa1df..d966cf0 100644
--- a/tools/assistant/tools/assistant/contentwindow.cpp
+++ b/tools/assistant/tools/assistant/contentwindow.cpp
@@ -38,12 +38,14 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "tracer.h"
#include "contentwindow.h"
+
#include "centralwidget.h"
#include "helpenginewrapper.h"
#include "helpviewer.h"
+#include "openpagesmanager.h"
+#include "tracer.h"
#include <QtGui/QLayout>
#include <QtGui/QFocusEvent>
@@ -146,8 +148,8 @@ bool ContentWindow::eventFilter(QObject *o, QEvent *e)
qobject_cast<QHelpContentModel*>(m_contentWidget->model());
if (contentModel) {
QHelpContentItem *itm = contentModel->contentItemAt(index);
- if (itm && AbstractHelpViewer::canOpenPage(itm->url().path()))
- CentralWidget::instance()->setSourceInNewTab(itm->url());
+ if (itm && HelpViewer::canOpenPage(itm->url().path()))
+ OpenPagesManager::instance()->createPage(itm->url());
}
} else if (button == Qt::LeftButton) {
itemClicked(index);
@@ -172,7 +174,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"));
- if (!AbstractHelpViewer::canOpenPage(itm->url().path()))
+ if (!HelpViewer::canOpenPage(itm->url().path()))
newTab->setEnabled(false);
menu.move(m_contentWidget->mapToGlobal(pos));
@@ -181,7 +183,7 @@ void ContentWindow::showContextMenu(const QPoint &pos)
if (curTab == action)
emit linkActivated(itm->url());
else if (newTab == action)
- CentralWidget::instance()->setSourceInNewTab(itm->url());
+ OpenPagesManager::instance()->createPage(itm->url());
}
void ContentWindow::itemClicked(const QModelIndex &index)
diff --git a/tools/assistant/tools/assistant/contentwindow.h b/tools/assistant/tools/assistant/contentwindow.h
index 62855dd..658e74e 100644
--- a/tools/assistant/tools/assistant/contentwindow.h
+++ b/tools/assistant/tools/assistant/contentwindow.h
@@ -76,7 +76,6 @@ private:
void focusInEvent(QFocusEvent *e);
void keyPressEvent(QKeyEvent *e);
bool eventFilter(QObject *o, QEvent *e);
- bool isPdfFile(QHelpContentItem *item) const;
QHelpContentWidget * const m_contentWidget;
int m_expandDepth;
diff --git a/tools/assistant/tools/assistant/doc/assistant.qdocconf b/tools/assistant/tools/assistant/doc/assistant.qdocconf
index 26cdafb..491f159 100644
--- a/tools/assistant/tools/assistant/doc/assistant.qdocconf
+++ b/tools/assistant/tools/assistant/doc/assistant.qdocconf
@@ -12,5 +12,5 @@ HTML.footer = "<p /><address><hr /><div align=\"center\">\n" \
"<table width=\"100%\" cellspacing=\"0\" border=\"0\"><tr class=\"address\">\n" \
"<td width=\"30%\" align=\"left\">Copyright &copy; 2010 Nokia Corporation and/or its subsidiary(-ies)</td>\n" \
"<td width=\"40%\" align=\"center\">Trademarks</td>\n" \
- "<td width=\"30%\" align=\"right\"><div align=\"right\">Qt 4.7.1</div></td>\n" \
+ "<td width=\"30%\" align=\"right\"><div align=\"right\">Qt 4.8.0</div></td>\n" \
"</tr></table></div></address>"
diff --git a/tools/assistant/tools/assistant/findwidget.cpp b/tools/assistant/tools/assistant/findwidget.cpp
index 60318d4..e46be61 100644
--- a/tools/assistant/tools/assistant/findwidget.cpp
+++ b/tools/assistant/tools/assistant/findwidget.cpp
@@ -203,7 +203,7 @@ void FindWidget::updateButtons()
void FindWidget::textChanged(const QString &text)
{
TRACE_OBJ
- emit find(text, true);
+ emit find(text, true, true);
}
bool FindWidget::eventFilter(QObject *object, QEvent *e)
diff --git a/tools/assistant/tools/assistant/findwidget.h b/tools/assistant/tools/assistant/findwidget.h
index cf78003..85e1959 100644
--- a/tools/assistant/tools/assistant/findwidget.h
+++ b/tools/assistant/tools/assistant/findwidget.h
@@ -67,11 +67,10 @@ public:
void setTextWrappedVisible(bool visible);
signals:
- void escapePressed();
-
void findNext();
void findPrevious();
- void find(const QString &text, bool forward);
+ void escapePressed();
+ void find(const QString &text, bool forward, bool incremental);
protected:
void hideEvent(QHideEvent* event);
diff --git a/tools/assistant/tools/assistant/globalactions.cpp b/tools/assistant/tools/assistant/globalactions.cpp
new file mode 100644
index 0000000..0eeab21
--- /dev/null
+++ b/tools/assistant/tools/assistant/globalactions.cpp
@@ -0,0 +1,246 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "globalactions.h"
+
+#include "centralwidget.h"
+#include "helpviewer.h"
+#include "tracer.h"
+
+#include <QtGui/QAction>
+#include <QtGui/QMenu>
+
+#if !defined(QT_NO_WEBKIT)
+#include <QtWebKit/QWebHistory>
+#endif
+
+GlobalActions *GlobalActions::instance(QObject *parent)
+{
+ Q_ASSERT(!m_instance != !parent);
+ if (!m_instance)
+ m_instance = new GlobalActions(parent);
+ return m_instance;
+}
+
+GlobalActions::GlobalActions(QObject *parent) : QObject(parent)
+{
+ TRACE_OBJ
+
+ // TODO: Put resource path in misc class
+ QString resourcePath = QLatin1String(":/trolltech/assistant/images/");
+#ifdef Q_OS_MAC
+ resourcePath.append(QLatin1String("mac"));
+#else
+ resourcePath.append(QLatin1String("win"));
+#endif
+ CentralWidget *centralWidget = CentralWidget::instance();
+
+ m_backAction = new QAction(tr("&Back"), parent);
+ m_backAction->setEnabled(false);
+ m_backAction->setShortcuts(QKeySequence::Back);
+ m_backAction->setIcon(QIcon(resourcePath + QLatin1String("/previous.png")));
+ connect(m_backAction, SIGNAL(triggered()), centralWidget, SLOT(backward()));
+ m_actionList << m_backAction;
+
+ m_nextAction = new QAction(tr("&Forward"), parent);
+ m_nextAction->setPriority(QAction::LowPriority);
+ m_nextAction->setEnabled(false);
+ m_nextAction->setShortcuts(QKeySequence::Forward);
+ m_nextAction->setIcon(QIcon(resourcePath + QLatin1String("/next.png")));
+ connect(m_nextAction, SIGNAL(triggered()), centralWidget, SLOT(forward()));
+ m_actionList << m_nextAction;
+
+ setupNavigationMenus(m_backAction, m_nextAction, centralWidget);
+
+ m_homeAction = new QAction(tr("&Home"), parent);
+ m_homeAction->setShortcut(tr("ALT+Home"));
+ m_homeAction->setIcon(QIcon(resourcePath + QLatin1String("/home.png")));
+ connect(m_homeAction, SIGNAL(triggered()), centralWidget, SLOT(home()));
+ m_actionList << m_homeAction;
+
+ QAction *separator = new QAction(parent);
+ separator->setSeparator(true);
+ m_actionList << separator;
+
+ m_zoomInAction = new QAction(tr("Zoom &in"), parent);
+ m_zoomInAction->setPriority(QAction::LowPriority);
+ m_zoomInAction->setIcon(QIcon(resourcePath + QLatin1String("/zoomin.png")));
+ m_zoomInAction->setShortcut(QKeySequence::ZoomIn);
+ connect(m_zoomInAction, SIGNAL(triggered()), centralWidget, SLOT(zoomIn()));
+ m_actionList << m_zoomInAction;
+
+ m_zoomOutAction = new QAction(tr("Zoom &out"), parent);
+ m_zoomOutAction->setPriority(QAction::LowPriority);
+ m_zoomOutAction->setIcon(QIcon(resourcePath + QLatin1String("/zoomout.png")));
+ m_zoomOutAction->setShortcut(QKeySequence::ZoomOut);
+ connect(m_zoomOutAction, SIGNAL(triggered()), centralWidget, SLOT(zoomOut()));
+ m_actionList << m_zoomOutAction;
+
+ separator = new QAction(parent);
+ separator->setSeparator(true);
+ m_actionList << separator;
+
+ m_copyAction = new QAction(tr("&Copy selected Text"), parent);
+ m_copyAction->setPriority(QAction::LowPriority);
+ m_copyAction->setIconText("&Copy");
+ m_copyAction->setIcon(QIcon(resourcePath + QLatin1String("/editcopy.png")));
+ m_copyAction->setShortcuts(QKeySequence::Copy);
+ m_copyAction->setEnabled(false);
+ connect(m_copyAction, SIGNAL(triggered()), centralWidget, SLOT(copy()));
+ m_actionList << m_copyAction;
+
+ m_printAction = new QAction(tr("&Print..."), parent);
+ m_printAction->setPriority(QAction::LowPriority);
+ m_printAction->setIcon(QIcon(resourcePath + QLatin1String("/print.png")));
+ m_printAction->setShortcut(QKeySequence::Print);
+ connect(m_printAction, SIGNAL(triggered()), centralWidget, SLOT(print()));
+ m_actionList << m_printAction;
+
+ m_findAction = new QAction(tr("&Find in Text..."), parent);
+ m_findAction->setIconText(tr("&Find"));
+ m_findAction->setIcon(QIcon(resourcePath + QLatin1String("/find.png")));
+ m_findAction->setShortcuts(QKeySequence::Find);
+ connect(m_findAction, SIGNAL(triggered()), centralWidget, SLOT(showTextSearch()));
+ m_actionList << m_findAction;
+
+#ifdef Q_WS_X11
+ m_backAction->setIcon(QIcon::fromTheme("go-previous" , m_backAction->icon()));
+ m_nextAction->setIcon(QIcon::fromTheme("go-next" , m_nextAction->icon()));
+ m_zoomInAction->setIcon(QIcon::fromTheme("zoom-in" , m_zoomInAction->icon()));
+ m_zoomOutAction->setIcon(QIcon::fromTheme("zoom-out" , m_zoomOutAction->icon()));
+ m_copyAction->setIcon(QIcon::fromTheme("edit-copy" , m_copyAction->icon()));
+ m_findAction->setIcon(QIcon::fromTheme("edit-find" , m_findAction->icon()));
+ m_homeAction->setIcon(QIcon::fromTheme("go-home" , m_homeAction->icon()));
+ m_printAction->setIcon(QIcon::fromTheme("document-print" , m_printAction->icon()));
+#endif
+}
+
+void GlobalActions::updateActions()
+{
+ TRACE_OBJ
+ CentralWidget *centralWidget = CentralWidget::instance();
+ m_copyAction->setEnabled(centralWidget->hasSelection());
+ m_nextAction->setEnabled(centralWidget->isForwardAvailable());
+ m_backAction->setEnabled(centralWidget->isBackwardAvailable());
+}
+
+void GlobalActions::setCopyAvailable(bool available)
+{
+ TRACE_OBJ
+ m_copyAction->setEnabled(available);
+}
+
+#if !defined(QT_NO_WEBKIT)
+
+void GlobalActions::slotAboutToShowBackMenu()
+{
+ TRACE_OBJ
+ m_backMenu->clear();
+ if (QWebHistory *history = CentralWidget::instance()->currentHelpViewer()->history()) {
+ const int currentItemIndex = history->currentItemIndex();
+ QList<QWebHistoryItem> items = history->backItems(history->count());
+ for (int i = items.count() - 1; i >= 0; --i) {
+ QAction *action = new QAction(this);
+ action->setText(items.at(i).title());
+ action->setData(-1 * (currentItemIndex - i));
+ m_backMenu->addAction(action);
+ }
+ }
+}
+
+void GlobalActions::slotAboutToShowNextMenu()
+{
+ TRACE_OBJ
+ m_nextMenu->clear();
+ if (QWebHistory *history = CentralWidget::instance()->currentHelpViewer()->history()) {
+ const int count = history->count();
+ QList<QWebHistoryItem> items = history->forwardItems(count);
+ for (int i = 0; i < items.count(); ++i) {
+ QAction *action = new QAction(this);
+ action->setData(count - i);
+ action->setText(items.at(i).title());
+ m_nextMenu->addAction(action);
+ }
+ }
+}
+
+void GlobalActions::slotOpenActionUrl(QAction *action)
+{
+ TRACE_OBJ
+ if (HelpViewer* viewer = CentralWidget::instance()->currentHelpViewer()) {
+ const int offset = action->data().toInt();
+ QWebHistory *history = viewer->history();
+ if (offset > 0) {
+ history->goToItem(history->forwardItems(history->count()
+ - offset + 1).back()); // forward
+ } else if (offset < 0) {
+ history->goToItem(history->backItems(-1 * offset).first()); // back
+ }
+ }
+}
+
+#endif
+
+void GlobalActions::setupNavigationMenus(QAction *back, QAction *next,
+ QWidget *parent)
+{
+#if !defined(QT_NO_WEBKIT)
+ m_backMenu = new QMenu(parent);
+ connect(m_backMenu, SIGNAL(aboutToShow()), this,
+ SLOT(slotAboutToShowBackMenu()));
+ connect(m_backMenu, SIGNAL(triggered(QAction*)), this,
+ SLOT(slotOpenActionUrl(QAction*)));
+ back->setMenu(m_backMenu);
+
+ m_nextMenu = new QMenu(parent);
+ connect(m_nextMenu, SIGNAL(aboutToShow()), this,
+ SLOT(slotAboutToShowNextMenu()));
+ connect(m_nextMenu, SIGNAL(triggered(QAction*)), this,
+ SLOT(slotOpenActionUrl(QAction*)));
+ next->setMenu(m_nextMenu);
+#else
+ Q_UNUSED(back)
+ Q_UNUSED(next)
+ Q_UNUSED(parent)
+#endif
+}
+
+GlobalActions *GlobalActions::m_instance = 0;
diff --git a/tools/assistant/tools/assistant/globalactions.h b/tools/assistant/tools/assistant/globalactions.h
new file mode 100644
index 0000000..ca8d7eb
--- /dev/null
+++ b/tools/assistant/tools/assistant/globalactions.h
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLOBALACTION_H
+#define GLOBALACTION_H
+
+#include <QtCore/QList>
+#include <QtCore/QObject>
+
+QT_BEGIN_NAMESPACE
+
+class QAction;
+class QMenu;
+
+class GlobalActions : public QObject
+{
+ Q_OBJECT
+ Q_DISABLE_COPY(GlobalActions)
+public:
+ static GlobalActions *instance(QObject *parent = 0);
+
+ QList<QAction *> actionList() const { return m_actionList; }
+ QAction *backAction() const { return m_backAction; }
+ QAction *nextAction() const { return m_nextAction; }
+ QAction *homeAction() const { return m_homeAction; }
+ QAction *zoomInAction() const { return m_zoomInAction; }
+ QAction *zoomOutAction() const { return m_zoomOutAction; }
+ QAction *copyAction() const { return m_copyAction; }
+ QAction *printAction() const { return m_printAction; }
+ QAction *findAction() const { return m_findAction; }
+
+ Q_SLOT void updateActions();
+ Q_SLOT void setCopyAvailable(bool available);
+
+#if !defined(QT_NO_WEBKIT)
+private slots:
+ void slotAboutToShowBackMenu();
+ void slotAboutToShowNextMenu();
+ void slotOpenActionUrl(QAction *action);
+#endif
+
+private:
+ void setupNavigationMenus(QAction *back, QAction *next, QWidget *parent);
+
+private:
+ GlobalActions(QObject *parent);
+
+ static GlobalActions *m_instance;
+
+ QAction *m_backAction;
+ QAction *m_nextAction;
+ QAction *m_homeAction;
+ QAction *m_zoomInAction;
+ QAction *m_zoomOutAction;
+ QAction *m_copyAction;
+ QAction *m_printAction;
+ QAction *m_findAction;
+
+ QList<QAction *> m_actionList;
+
+ QMenu *m_backMenu;
+ QMenu *m_nextMenu;
+};
+
+QT_END_NAMESPACE
+
+#endif // GLOBALACTION_H
diff --git a/tools/assistant/tools/assistant/helpenginewrapper.cpp b/tools/assistant/tools/assistant/helpenginewrapper.cpp
index a53a9ee..ba54dd6 100644
--- a/tools/assistant/tools/assistant/helpenginewrapper.cpp
+++ b/tools/assistant/tools/assistant/helpenginewrapper.cpp
@@ -72,6 +72,7 @@ namespace {
const QString UseBrowserFontKey(QLatin1String("useBrowserFont"));
const QString VersionKey(QString(QLatin1String("qtVersion%1$$$%2")).
arg(QLatin1String(QT_VERSION_STR)));
+ const QString ShowTabsKey(QLatin1String("showTabs"));
} // anonymous namespace
class TimeoutForwarder : public QObject
@@ -147,7 +148,7 @@ HelpEngineWrapper::HelpEngineWrapper(const QString &collectionFile)
* because we will start to index them, only to be interupted
* by the next request. Also, there is a nasty SQLITE bug that will
* cause the application to hang for minutes in that case.
- * This call is reverted by initalDocSetupDone(), which must be
+ * This call is reverted by initialDocSetupDone(), which must be
* called after the new docs have been installed.
*/
disconnect(d->m_helpEngine, SIGNAL(setupFinished()),
@@ -569,18 +570,6 @@ void HelpEngineWrapper::setLastTabPage(int lastPage)
CollectionConfiguration::setLastTabPage(*d->m_helpEngine, lastPage);
}
-bool HelpEngineWrapper::searchWasAttached() const
-{
- TRACE_OBJ
- return d->m_helpEngine->customValue(SearchWasAttachedKey).toBool();
-}
-
-void HelpEngineWrapper::setSearchWasAttached(bool attached)
-{
- TRACE_OBJ
- d->m_helpEngine->setCustomValue(SearchWasAttachedKey, attached);
-}
-
int HelpEngineWrapper::startOption() const
{
TRACE_OBJ
@@ -655,7 +644,7 @@ void HelpEngineWrapper::setUseBrowserFont(bool useBrowserFont)
const QFont HelpEngineWrapper::appFont() const
{
TRACE_OBJ
- return qVariantValue<QFont>(d->m_helpEngine->customValue(AppFontKey));
+ return qvariant_cast<QFont>(d->m_helpEngine->customValue(AppFontKey));
}
void HelpEngineWrapper::setAppFont(const QFont &font)
@@ -680,7 +669,7 @@ void HelpEngineWrapper::setAppWritingSystem(QFontDatabase::WritingSystem system)
const QFont HelpEngineWrapper::browserFont() const
{
TRACE_OBJ
- return qVariantValue<QFont>(d->m_helpEngine->customValue(BrowserFontKey));
+ return qvariant_cast<QFont>(d->m_helpEngine->customValue(BrowserFontKey));
}
void HelpEngineWrapper::setBrowserFont(const QFont &font)
@@ -704,11 +693,31 @@ void HelpEngineWrapper::setBrowserWritingSystem(QFontDatabase::WritingSystem sys
void HelpEngineWrapper::handleCurrentFilterChanged(const QString &filter)
{
+ TRACE_OBJ
const QString &filterToReport
= filter == Unfiltered ? TrUnfiltered : filter;
emit currentFilterChanged(filterToReport);
}
+bool HelpEngineWrapper::showTabs() const
+{
+ TRACE_OBJ
+ return d->m_helpEngine->customValue(ShowTabsKey, false).toBool();
+}
+
+void HelpEngineWrapper::setShowTabs(bool show)
+{
+ TRACE_OBJ
+ d->m_helpEngine->setCustomValue(ShowTabsKey, show);
+}
+
+bool HelpEngineWrapper::fullTextSearchFallbackEnabled() const
+{
+ TRACE_OBJ
+ return CollectionConfiguration::fullTextSearchFallbackEnabled(*d->m_helpEngine);
+}
+
+// -- TimeoutForwarder
TimeoutForwarder::TimeoutForwarder(const QString &fileName)
: m_fileName(fileName)
@@ -722,6 +731,7 @@ void TimeoutForwarder::forward()
HelpEngineWrapper::instance().d->qchFileChanged(m_fileName, true);
}
+// -- HelpEngineWrapperPrivate
HelpEngineWrapperPrivate::HelpEngineWrapperPrivate(const QString &collectionFile)
: m_helpEngine(new QHelpEngine(collectionFile, this)),
@@ -829,7 +839,6 @@ void HelpEngineWrapperPrivate::qchFileChanged(const QString &fileName,
m_recentQchUpdates.erase(it);
}
-
QT_END_NAMESPACE
#include "helpenginewrapper.moc"
diff --git a/tools/assistant/tools/assistant/helpenginewrapper.h b/tools/assistant/tools/assistant/helpenginewrapper.h
index c1041b6..38bde9b 100644
--- a/tools/assistant/tools/assistant/helpenginewrapper.h
+++ b/tools/assistant/tools/assistant/helpenginewrapper.h
@@ -170,9 +170,6 @@ public:
int startOption() const;
void setStartOption(int option);
- bool searchWasAttached() const;
- void setSearchWasAttached(bool attached);
-
bool hasFontSettings() const;
bool usesAppFont() const;
void setUseAppFont(bool useAppFont);
@@ -187,8 +184,13 @@ public:
QFontDatabase::WritingSystem browserWritingSystem() const;
void setBrowserWritingSystem(QFontDatabase::WritingSystem system);
+ bool showTabs() const;
+ void setShowTabs(bool show);
+
static const QString TrUnfiltered;
+ bool fullTextSearchFallbackEnabled() const;
+
signals:
// For asynchronous doc updates triggered by external actions.
diff --git a/tools/assistant/tools/assistant/helpviewer.cpp b/tools/assistant/tools/assistant/helpviewer.cpp
index 6499139..2e4b60c 100644
--- a/tools/assistant/tools/assistant/helpviewer.cpp
+++ b/tools/assistant/tools/assistant/helpviewer.cpp
@@ -38,7 +38,10 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+
#include "helpviewer.h"
+#include "helpviewer_p.h"
+
#include "helpenginewrapper.h"
#include "tracer.h"
@@ -49,18 +52,21 @@
#include <QtCore/QUrl>
#include <QtGui/QDesktopServices>
+#include <QtGui/QMouseEvent>
+
+#include <QtHelp/QHelpEngineCore>
QT_BEGIN_NAMESPACE
-const QLatin1String AbstractHelpViewer::DocPath("qthelp://com.trolltech.");
+const QString HelpViewer::DocPath = QLatin1String("qthelp://com.trolltech.");
-const QString AbstractHelpViewer::AboutBlank =
+const QString HelpViewer::AboutBlank =
QCoreApplication::translate("HelpViewer", "<title>about:blank</title>");
-const QString AbstractHelpViewer::LocalHelpFile = QLatin1String("qthelp://"
+const QString HelpViewer::LocalHelpFile = QLatin1String("qthelp://"
"com.trolltech.com.assistantinternal-1.0.0/assistant/assistant.html");
-const QString AbstractHelpViewer::PageNotFoundMessage =
+const QString HelpViewer::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>");
@@ -102,17 +108,13 @@ struct ExtensionMap {
{ 0, 0 }
};
-// -- AbstractHelpViewer
-
-AbstractHelpViewer::AbstractHelpViewer()
-{
-}
-
-AbstractHelpViewer::~AbstractHelpViewer()
+HelpViewer::~HelpViewer()
{
+ TRACE_OBJ
+ delete d;
}
-bool AbstractHelpViewer::isLocalUrl(const QUrl &url)
+bool HelpViewer::isLocalUrl(const QUrl &url)
{
TRACE_OBJ
const QString &scheme = url.scheme();
@@ -124,13 +126,13 @@ bool AbstractHelpViewer::isLocalUrl(const QUrl &url)
|| scheme == QLatin1String("about");
}
-bool AbstractHelpViewer::canOpenPage(const QString &url)
+bool HelpViewer::canOpenPage(const QString &url)
{
TRACE_OBJ
return !mimeFromUrl(url).isEmpty();
}
-QString AbstractHelpViewer::mimeFromUrl(const QUrl &url)
+QString HelpViewer::mimeFromUrl(const QUrl &url)
{
TRACE_OBJ
const QString &path = url.path();
@@ -146,7 +148,7 @@ QString AbstractHelpViewer::mimeFromUrl(const QUrl &url)
return QLatin1String("");
}
-bool AbstractHelpViewer::launchWithExternalApp(const QUrl &url)
+bool HelpViewer::launchWithExternalApp(const QUrl &url)
{
TRACE_OBJ
if (isLocalUrl(url)) {
@@ -177,4 +179,43 @@ bool AbstractHelpViewer::launchWithExternalApp(const QUrl &url)
return false;
}
+// -- public slots
+
+void HelpViewer::home()
+{
+ TRACE_OBJ
+ setSource(HelpEngineWrapper::instance().homePage());
+}
+
+// -- private slots
+
+void HelpViewer::setLoadStarted()
+{
+ d->m_loadFinished = false;
+}
+
+void HelpViewer::setLoadFinished(bool ok)
+{
+ d->m_loadFinished = ok;
+ emit sourceChanged(source());
+}
+
+// -- private
+
+bool HelpViewer::handleForwardBackwardMouseButtons(QMouseEvent *event)
+{
+ TRACE_OBJ
+ if (event->button() == Qt::XButton1) {
+ backward();
+ return true;
+ }
+
+ if (event->button() == Qt::XButton2) {
+ forward();
+ return true;
+ }
+
+ return false;
+}
+
QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/helpviewer.h b/tools/assistant/tools/assistant/helpviewer.h
index def9418..e2aefca 100644
--- a/tools/assistant/tools/assistant/helpviewer.h
+++ b/tools/assistant/tools/assistant/helpviewer.h
@@ -38,36 +38,69 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+
#ifndef HELPVIEWER_H
#define HELPVIEWER_H
+#include <QtCore/qglobal.h>
#include <QtCore/QString>
+#include <QtCore/QUrl>
+#include <QtCore/QVariant>
+#include <QtGui/QAction>
#include <QtGui/QFont>
-QT_BEGIN_NAMESPACE
+#if defined(QT_NO_WEBKIT)
+#include <QtGui/QTextBrowser>
+#else
+#include <QtWebKit/QWebView>
+#endif
-class QMouseEvent;
-class QUrl;
+QT_BEGIN_NAMESPACE
-class AbstractHelpViewer
+#if !defined(QT_NO_WEBKIT)
+class HelpViewer : public QWebView
+#else
+class HelpViewer : public QTextBrowser
+#endif
{
+ Q_OBJECT
+ class HelpViewerPrivate;
+ Q_DISABLE_COPY(HelpViewer)
+
public:
- AbstractHelpViewer();
- virtual ~AbstractHelpViewer();
+ enum FindFlag {
+ FindBackward = 0x01,
+ FindCaseSensitively = 0x02
+ };
+ Q_DECLARE_FLAGS(FindFlags, FindFlag)
+
+ HelpViewer(qreal zoom, QWidget *parent = 0);
+ ~HelpViewer();
+
+ QFont viewerFont() const;
+ void setViewerFont(const QFont &font);
+
+ void scaleUp();
+ void scaleDown();
+
+ void resetScale();
+ qreal scale() const;
- virtual QFont viewerFont() const = 0;
- virtual void setViewerFont(const QFont &font) = 0;
+ QString title() const;
+ void setTitle(const QString &title);
- virtual void scaleUp() = 0;
- virtual void scaleDown() = 0;
-
- virtual void resetScale() = 0;
- virtual qreal scale() const = 0;
+ QUrl source() const;
+ void setSource(const QUrl &url);
- virtual bool handleForwardBackwardMouseButtons(QMouseEvent *e) = 0;
+ QString selectedText() const;
+ bool isForwardAvailable() const;
+ bool isBackwardAvailable() const;
- static const QLatin1String DocPath;
+ bool findText(const QString &text, FindFlags flags, bool incremental,
+ bool fromSearch);
+
+ static const QString DocPath;
static const QString AboutBlank;
static const QString LocalHelpFile;
static const QString PageNotFoundMessage;
@@ -76,8 +109,50 @@ public:
static bool canOpenPage(const QString &url);
static QString mimeFromUrl(const QUrl &url);
static bool launchWithExternalApp(const QUrl &url);
+
+public slots:
+ void copy();
+ void home();
+
+ void forward();
+ void backward();
+
+signals:
+ void titleChanged();
+#if !defined(QT_NO_WEBKIT)
+ void copyAvailable(bool yes);
+ void sourceChanged(const QUrl &url);
+ void forwardAvailable(bool enabled);
+ void backwardAvailable(bool enabled);
+ void highlighted(const QString &link);
+ void printRequested();
+#else
+ void loadStarted();
+ void loadFinished(bool finished);
+#endif
+
+protected:
+ void keyPressEvent(QKeyEvent *e);
+ void wheelEvent(QWheelEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
+
+private slots:
+ void actionChanged();
+ void setLoadStarted();
+ void setLoadFinished(bool ok);
+
+private:
+ bool eventFilter(QObject *obj, QEvent *event);
+ void contextMenuEvent(QContextMenuEvent *event);
+ QVariant loadResource(int type, const QUrl &name);
+ bool handleForwardBackwardMouseButtons(QMouseEvent *e);
+
+private:
+ HelpViewerPrivate *d;
};
QT_END_NAMESPACE
+Q_DECLARE_METATYPE(HelpViewer*)
#endif // HELPVIEWER_H
diff --git a/tools/assistant/tools/assistant/helpviewer_qtb.h b/tools/assistant/tools/assistant/helpviewer_p.h
index 58aacd7..d65bab5 100644
--- a/tools/assistant/tools/assistant/helpviewer_qtb.h
+++ b/tools/assistant/tools/assistant/helpviewer_p.h
@@ -38,76 +38,86 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef HELPVIEWERQTB_H
-#define HELPVIEWERQTB_H
-#include "helpviewer.h"
+#ifndef HELPVIEWERPRIVATE_H
+#define HELPVIEWERPRIVATE_H
-#include <QtCore/QUrl>
-#include <QtCore/QVariant>
+#include "centralwidget.h"
+#include "helpviewer.h"
+#include "openpagesmanager.h"
+#include <QtCore/QObject>
+#ifdef QT_NO_WEBKIT
#include <QtGui/QTextBrowser>
+#endif
QT_BEGIN_NAMESPACE
-class CentralWidget;
-class HelpEngineWrapper;
-class QContextMenuEvent;
-class QKeyEvent;
-class QMouseEvent;
-
-class HelpViewer : public QTextBrowser, public AbstractHelpViewer
+class HelpViewer::HelpViewerPrivate : public QObject
{
Q_OBJECT
public:
- explicit HelpViewer(CentralWidget *parent, qreal zoom = 0.0);
- ~HelpViewer();
-
- QFont viewerFont() const;
- void setViewerFont(const QFont &font);
-
- void scaleUp();
- void scaleDown();
- void resetScale();
- qreal scale() const { return zoomCount; }
-
- bool handleForwardBackwardMouseButtons(QMouseEvent *e);
-
- void setSource(const QUrl &url);
-
- inline bool hasSelection() const
- { return textCursor().hasSelection(); }
+#ifdef QT_NO_WEBKIT
+ HelpViewerPrivate(int zoom)
+ : zoomCount(zoom)
+ , forceFont(false)
+ , lastAnchor(QString())
+#else
+ HelpViewerPrivate()
+#endif
+ {
+ m_loadFinished = false;
+ }
+
+#ifdef QT_NO_WEBKIT
+ bool hasAnchorAt(QTextBrowser *browser, const QPoint& pos)
+ {
+ lastAnchor = browser->anchorAt(pos);
+ if (lastAnchor.isEmpty())
+ return false;
+
+ lastAnchor = browser->source().resolved(lastAnchor).toString();
+ if (lastAnchor.at(0) == QLatin1Char('#')) {
+ QString src = browser->source().toString();
+ int hsh = src.indexOf(QLatin1Char('#'));
+ lastAnchor = (hsh >= 0 ? src.left(hsh) : src) + lastAnchor;
+ }
+ return true;
+ }
+
+ void openLink(bool newPage)
+ {
+ if(lastAnchor.isEmpty())
+ return;
+ if (newPage)
+ OpenPagesManager::instance()->createPage(lastAnchor);
+ else
+ CentralWidget::instance()->setSource(lastAnchor);
+ lastAnchor.clear();
+ }
+
+public slots:
+ void openLink()
+ {
+ openLink(false);
+ }
+
+ void openLinkInNewPage()
+ {
+ openLink(true);
+ }
-public Q_SLOTS:
- void home();
-
-protected:
- void wheelEvent(QWheelEvent *e);
- bool eventFilter(QObject *obj, QEvent *event);
-
-private:
- QVariant loadResource(int type, const QUrl &name);
- void openLinkInNewTab(const QString &link);
- bool hasAnchorAt(const QPoint& pos);
- void contextMenuEvent(QContextMenuEvent *e);
- void mouseReleaseEvent(QMouseEvent *e);
- void keyPressEvent(QKeyEvent *e);
- void mousePressEvent(QMouseEvent *e);
-
-private slots:
- void openLinkInNewTab();
-
-private:
+public:
int zoomCount;
- bool controlPressed;
+ bool forceFont;
QString lastAnchor;
- CentralWidget* parentWidget;
- HelpEngineWrapper &helpEngine;
+#endif // QT_NO_WEBKIT
- bool forceFont;
+public:
+ bool m_loadFinished;
};
QT_END_NAMESPACE
-#endif // HELPVIEWERQTB_H
+#endif // HELPVIEWERPRIVATE_H
diff --git a/tools/assistant/tools/assistant/helpviewer_qtb.cpp b/tools/assistant/tools/assistant/helpviewer_qtb.cpp
index 7f82b56..af744b7 100644
--- a/tools/assistant/tools/assistant/helpviewer_qtb.cpp
+++ b/tools/assistant/tools/assistant/helpviewer_qtb.cpp
@@ -38,10 +38,13 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "helpviewer_qtb.h"
-#include "centralwidget.h"
+#include "helpviewer.h"
+
+#include "globalactions.h"
#include "helpenginewrapper.h"
+#include "helpviewer_p.h"
+#include "openpagesmanager.h"
#include "tracer.h"
#include <QtCore/QStringBuilder>
@@ -53,34 +56,34 @@
QT_BEGIN_NAMESPACE
-HelpViewer::HelpViewer(CentralWidget *parent, qreal zoom)
+HelpViewer::HelpViewer(qreal zoom, QWidget *parent)
: QTextBrowser(parent)
- , zoomCount(zoom)
- , controlPressed(false)
- , lastAnchor(QString())
- , parentWidget(parent)
- , helpEngine(HelpEngineWrapper::instance())
- , forceFont(false)
+ , d(new HelpViewerPrivate(zoom))
{
TRACE_OBJ
+ QPalette p = palette();
+ p.setColor(QPalette::Inactive, QPalette::Highlight,
+ p.color(QPalette::Active, QPalette::Highlight));
+ p.setColor(QPalette::Inactive, QPalette::HighlightedText,
+ p.color(QPalette::Active, QPalette::HighlightedText));
+ setPalette(p);
+
installEventFilter(this);
document()->setDocumentMargin(8);
QFont font = viewerFont();
font.setPointSize(int(font.pointSize() + zoom));
setViewerFont(font);
-}
-HelpViewer::~HelpViewer()
-{
- TRACE_OBJ
+ connect(this, SIGNAL(sourceChanged(QUrl)), this, SIGNAL(titleChanged()));
+ connect(this, SIGNAL(loadFinished(bool)), this, SLOT(setLoadFinished(bool)));
}
QFont HelpViewer::viewerFont() const
{
TRACE_OBJ
if (HelpEngineWrapper::instance().usesBrowserFont())
- return helpEngine.browserFont();
+ return HelpEngineWrapper::instance().browserFont();
return qApp->font();
}
@@ -88,185 +91,183 @@ void HelpViewer::setViewerFont(const QFont &newFont)
{
TRACE_OBJ
if (font() != newFont) {
- forceFont = true;
+ d->forceFont = true;
setFont(newFont);
- forceFont = false;
+ d->forceFont = false;
}
}
void HelpViewer::scaleUp()
{
TRACE_OBJ
- if (zoomCount < 10) {
- ++zoomCount;
- forceFont = true;
+ if (d->zoomCount < 10) {
+ d->zoomCount++;
+ d->forceFont = true;
zoomIn();
- forceFont = false;
+ d->forceFont = false;
}
}
void HelpViewer::scaleDown()
{
TRACE_OBJ
- if (zoomCount > -5) {
- --zoomCount;
- forceFont = true;
+ if (d->zoomCount > -5) {
+ d->zoomCount--;
+ d->forceFont = true;
zoomOut();
- forceFont = false;
+ d->forceFont = false;
}
}
void HelpViewer::resetScale()
{
TRACE_OBJ
- if (zoomCount != 0) {
- forceFont = true;
- zoomOut(zoomCount);
- forceFont = false;
+ if (d->zoomCount != 0) {
+ d->forceFont = true;
+ zoomOut(d->zoomCount);
+ d->forceFont = false;
}
- zoomCount = 0;
+ d->zoomCount = 0;
}
-bool HelpViewer::handleForwardBackwardMouseButtons(QMouseEvent *e)
+qreal HelpViewer::scale() const
{
- if (e->button() == Qt::XButton1) {
- QTextBrowser::backward();
- return true;
- }
+ TRACE_OBJ
+ return d->zoomCount;
+}
- if (e->button() == Qt::XButton2) {
- QTextBrowser::forward();
- return true;
- }
- return false;
+QString HelpViewer::title() const
+{
+ TRACE_OBJ
+ return documentTitle();
+}
+
+void HelpViewer::setTitle(const QString &title)
+{
+ TRACE_OBJ
+ setDocumentTitle(title);
+}
+
+QUrl HelpViewer::source() const
+{
+ TRACE_OBJ
+ return QTextBrowser::source();
}
void HelpViewer::setSource(const QUrl &url)
{
TRACE_OBJ
- const QString &string = url.toString();
- if (url.isValid() && string != QLatin1String("help")) {
- if (launchWithExternalApp(url))
- return;
-
- const QUrl &resolvedUrl = helpEngine.findFile(url);
- if (resolvedUrl.isValid()) {
- QTextBrowser::setSource(resolvedUrl);
- return;
- }
- }
+ if (launchWithExternalApp(url))
+ return;
- if (string != QLatin1String("help")) {
- QTextBrowser::setSource(url);
+ emit loadStarted();
+ QString string = url.toString();
+ const HelpEngineWrapper &engine = HelpEngineWrapper::instance();
+ const QUrl &resolvedUrl = (string == QLatin1String("help") ? LocalHelpFile :
+ engine.findFile(string));
+ QTextBrowser::setSource(resolvedUrl);
+ if (!url.isValid()) {
setHtml(string == QLatin1String("about:blank") ? AboutBlank
: PageNotFoundMessage.arg(url.toString()));
- emit sourceChanged(url);
- } else {
- QTextBrowser::setSource(LocalHelpFile);
}
+ emit loadFinished(true);
}
-QVariant HelpViewer::loadResource(int type, const QUrl &name)
+QString HelpViewer::selectedText() const
{
TRACE_OBJ
- QByteArray ba;
- if (type < 4) {
- ba = helpEngine.fileData(name);
- if (name.toString().endsWith(QLatin1String(".svg"), Qt::CaseInsensitive)) {
- QImage image;
- image.loadFromData(ba, "svg");
- if (!image.isNull())
- return image;
- }
- }
- return ba;
+ return textCursor().selectedText();
}
-void HelpViewer::openLinkInNewTab()
+bool HelpViewer::isForwardAvailable() const
{
TRACE_OBJ
- if(lastAnchor.isEmpty())
- return;
-
- parentWidget->setSourceInNewTab(QUrl(lastAnchor));
- lastAnchor.clear();
+ return QTextBrowser::isForwardAvailable();
}
-void HelpViewer::openLinkInNewTab(const QString &link)
+bool HelpViewer::isBackwardAvailable() const
{
TRACE_OBJ
- lastAnchor = link;
- openLinkInNewTab();
+ return QTextBrowser::isBackwardAvailable();
}
-bool HelpViewer::hasAnchorAt(const QPoint& pos)
+bool HelpViewer::findText(const QString &text, FindFlags flags, bool incremental,
+ bool fromSearch)
{
TRACE_OBJ
- lastAnchor = anchorAt(pos);
- if (lastAnchor.isEmpty())
+ QTextDocument *doc = document();
+ QTextCursor cursor = textCursor();
+ if (!doc || cursor.isNull())
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;
+ const int position = cursor.selectionStart();
+ if (incremental)
+ cursor.setPosition(position);
+
+ QTextDocument::FindFlags textDocFlags;
+ if (flags & HelpViewer::FindBackward)
+ textDocFlags |= QTextDocument::FindBackward;
+ if (flags & HelpViewer::FindCaseSensitively)
+ textDocFlags |= QTextDocument::FindCaseSensitively;
+
+ QTextCursor found = doc->find(text, cursor, textDocFlags);
+ if (found.isNull()) {
+ if ((flags & HelpViewer::FindBackward) == 0)
+ cursor.movePosition(QTextCursor::Start);
+ else
+ cursor.movePosition(QTextCursor::End);
+ found = doc->find(text, cursor, textDocFlags);
}
- return true;
-}
+ if (fromSearch) {
+ cursor.beginEditBlock();
+ viewport()->setUpdatesEnabled(false);
-void HelpViewer::contextMenuEvent(QContextMenuEvent *e)
-{
- TRACE_OBJ
- QMenu menu(QLatin1String(""), 0);
+ QTextCharFormat marker;
+ marker.setForeground(Qt::red);
+ cursor.movePosition(QTextCursor::Start);
+ setTextCursor(cursor);
- 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());
+ while (find(text)) {
+ QTextCursor hit = textCursor();
+ hit.mergeCharFormat(marker);
+ }
- menu.addAction(tr("Open Link in New Tab\tCtrl+LMB"), this,
- SLOT(openLinkInNewTab()));
- menu.addSeparator();
+ viewport()->setUpdatesEnabled(true);
+ cursor.endEditBlock();
}
- menu.addActions(parentWidget->globalActions());
- QAction *action = menu.exec(e->globalPos());
- if (action == copyAnchorAction)
- QApplication::clipboard()->setText(link.toString());
+
+ bool cursorIsNull = found.isNull();
+ if (cursorIsNull) {
+ found = textCursor();
+ found.setPosition(position);
+ }
+ setTextCursor(found);
+ return !cursorIsNull;
}
-void HelpViewer::mouseReleaseEvent(QMouseEvent *e)
+// -- public slots
+
+void HelpViewer::copy()
{
TRACE_OBJ
-#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::copy();
+}
- QTextBrowser::mouseReleaseEvent(e);
+void HelpViewer::forward()
+{
+ TRACE_OBJ
+ QTextBrowser::forward();
}
-void HelpViewer::mousePressEvent(QMouseEvent *e)
+void HelpViewer::backward()
{
-#ifdef Q_OS_LINUX
- if (handleForwardBackwardMouseButtons(e))
- return;
-#endif
- QTextBrowser::mousePressEvent(e);
+ TRACE_OBJ
+ QTextBrowser::backward();
}
+// -- protected
+
void HelpViewer::keyPressEvent(QKeyEvent *e)
{
TRACE_OBJ
@@ -279,11 +280,6 @@ void HelpViewer::keyPressEvent(QKeyEvent *e)
QTextBrowser::keyPressEvent(e);
}
-void HelpViewer::home()
-{
- TRACE_OBJ
- setSource(helpEngine.homePage());
-}
void HelpViewer::wheelEvent(QWheelEvent *e)
{
@@ -296,12 +292,93 @@ void HelpViewer::wheelEvent(QWheelEvent *e)
}
}
+void HelpViewer::mousePressEvent(QMouseEvent *e)
+{
+ TRACE_OBJ
+#ifdef Q_OS_LINUX
+ if (handleForwardBackwardMouseButtons(e))
+ return;
+#endif
+
+ QTextBrowser::mousePressEvent(e);
+}
+
+void HelpViewer::mouseReleaseEvent(QMouseEvent *e)
+{
+ TRACE_OBJ
+#ifndef Q_OS_LINUX
+ if (handleForwardBackwardMouseButtons(e))
+ return;
+#endif
+
+ bool controlPressed = e->modifiers() & Qt::ControlModifier;
+ if ((controlPressed && d->hasAnchorAt(this, e->pos())) ||
+ (e->button() == Qt::MidButton && d->hasAnchorAt(this, e->pos()))) {
+ d->openLinkInNewPage();
+ return;
+ }
+
+ QTextBrowser::mouseReleaseEvent(e);
+}
+
+// -- private slots
+
+void HelpViewer::actionChanged()
+{
+ // stub
+ TRACE_OBJ
+}
+
+// -- private
+
bool HelpViewer::eventFilter(QObject *obj, QEvent *event)
{
TRACE_OBJ
- if (event->type() == QEvent::FontChange && !forceFont)
+ if (event->type() == QEvent::FontChange && !d->forceFont)
return true;
return QTextBrowser::eventFilter(obj, event);
}
+void HelpViewer::contextMenuEvent(QContextMenuEvent *event)
+{
+ TRACE_OBJ
+
+ QMenu menu(QString(), 0);
+ QUrl link;
+ QAction *copyAnchorAction = 0;
+ if (d->hasAnchorAt(this, event->pos())) {
+ link = anchorAt(event->pos());
+ if (link.isRelative())
+ link = source().resolved(link);
+ menu.addAction(tr("Open Link"), d, SLOT(openLink()));
+ menu.addAction(tr("Open Link in New Tab\tCtrl+LMB"), d, SLOT(openLinkInNewPage()));
+
+ if (!link.isEmpty() && link.isValid())
+ copyAnchorAction = menu.addAction(tr("Copy &Link Location"));
+ } else if (!selectedText().isEmpty()) {
+ menu.addAction(tr("Copy"), this, SLOT(copy()));
+ } else {
+ menu.addAction(tr("Reload"), this, SLOT(reload()));
+ }
+
+ if (copyAnchorAction == menu.exec(event->globalPos()))
+ QApplication::clipboard()->setText(link.toString());
+}
+
+QVariant HelpViewer::loadResource(int type, const QUrl &name)
+{
+ TRACE_OBJ
+ QByteArray ba;
+ if (type < 4) {
+ ba = HelpEngineWrapper::instance().fileData(name);
+ if (name.toString().endsWith(QLatin1String(".svg"), Qt::CaseInsensitive)) {
+ QImage image;
+ image.loadFromData(ba, "svg");
+ if (!image.isNull())
+ return image;
+ }
+ }
+ return ba;
+}
+
QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/helpviewer_qwv.cpp b/tools/assistant/tools/assistant/helpviewer_qwv.cpp
index 221e1b8..87973c0 100644
--- a/tools/assistant/tools/assistant/helpviewer_qwv.cpp
+++ b/tools/assistant/tools/assistant/helpviewer_qwv.cpp
@@ -39,25 +39,31 @@
**
****************************************************************************/
-#include "helpviewer_qwv.h"
+#include "helpviewer.h"
+#include "helpviewer_p.h"
#include "centralwidget.h"
#include "helpenginewrapper.h"
+#include "openpagesmanager.h"
#include "tracer.h"
#include <QtCore/QFileInfo>
#include <QtCore/QString>
-#include <QtCore/QStringBuilder>
#include <QtCore/QTimer>
+#include <QtGui/QApplication>
#include <QtGui/QWheelEvent>
+#include <QtHelp/QHelpEngineCore>
+
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
QT_BEGIN_NAMESPACE
+// -- HelpNetworkReply
+
class HelpNetworkReply : public QNetworkReply
{
public:
@@ -109,6 +115,8 @@ qint64 HelpNetworkReply::readData(char *buffer, qint64 maxlen)
return len;
}
+// -- HelpNetworkAccessManager
+
class HelpNetworkAccessManager : public QNetworkAccessManager
{
public:
@@ -130,15 +138,14 @@ QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/,
{
TRACE_OBJ
QString url = request.url().toString();
- HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
-
+ const HelpEngineWrapper &engine = HelpEngineWrapper::instance();
// TODO: For some reason the url to load is already wrong (passed from webkit)
// though the css file and the references inside should work that way. One
// possible problem might be that the css is loaded at the same level as the
// html, thus a path inside the css like (../images/foo.png) might cd out of
// the virtual folder
- if (!helpEngine.findFile(url).isValid()) {
- if (url.startsWith(AbstractHelpViewer::DocPath)) {
+ if (!engine.findFile(url).isValid()) {
+ if (url.startsWith(HelpViewer::DocPath)) {
QUrl newUrl = request.url();
if (!newUrl.path().startsWith(QLatin1String("/qdoc/"))) {
newUrl.setPath(QLatin1String("qdoc") + newUrl.path());
@@ -147,18 +154,20 @@ QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/,
}
}
- const QString &mimeType = AbstractHelpViewer::mimeFromUrl(url);
- const QByteArray &data = helpEngine.findFile(url).isValid()
- ? helpEngine.fileData(url)
- : AbstractHelpViewer::PageNotFoundMessage.arg(url).toUtf8();
+ const QString &mimeType = HelpViewer::mimeFromUrl(url);
+ const QByteArray &data = engine.findFile(url).isValid() ? engine.fileData(url)
+ : HelpViewer::PageNotFoundMessage.arg(url).toUtf8();
+
return new HelpNetworkReply(request, data, mimeType.isEmpty()
? QLatin1String("application/octet-stream") : mimeType);
}
+// -- HelpPage
+
class HelpPage : public QWebPage
{
public:
- HelpPage(CentralWidget *central, QObject *parent);
+ HelpPage(QObject *parent);
protected:
virtual QWebPage *createWindow(QWebPage::WebWindowType);
@@ -168,7 +177,6 @@ protected:
const QNetworkRequest &request, NavigationType type);
private:
- CentralWidget *centralWidget;
bool closeNewTabIfNeeded;
friend class HelpViewer;
@@ -177,9 +185,8 @@ private:
Qt::KeyboardModifiers m_keyboardModifiers;
};
-HelpPage::HelpPage(CentralWidget *central, QObject *parent)
+HelpPage::HelpPage(QObject *parent)
: QWebPage(parent)
- , centralWidget(central)
, closeNewTabIfNeeded(false)
, m_pressedButtons(Qt::NoButton)
, m_keyboardModifiers(Qt::NoModifier)
@@ -190,9 +197,9 @@ HelpPage::HelpPage(CentralWidget *central, QObject *parent)
QWebPage *HelpPage::createWindow(QWebPage::WebWindowType)
{
TRACE_OBJ
- HelpPage* newPage = static_cast<HelpPage*>(centralWidget->newEmptyTab()->page());
- if (newPage)
- newPage->closeNewTabIfNeeded = closeNewTabIfNeeded;
+ HelpPage* newPage = static_cast<HelpPage*>(OpenPagesManager::instance()
+ ->createPage()->page());
+ newPage->closeNewTabIfNeeded = closeNewTabIfNeeded;
closeNewTabIfNeeded = false;
return newPage;
}
@@ -217,19 +224,17 @@ bool HelpPage::acceptNavigationRequest(QWebFrame *,
closeNewTabIfNeeded = false;
const QUrl &url = request.url();
- if (AbstractHelpViewer::launchWithExternalApp(url)) {
+ if (HelpViewer::launchWithExternalApp(url)) {
if (closeNewTab)
- QMetaObject::invokeMethod(centralWidget, "closeTab");
+ QMetaObject::invokeMethod(OpenPagesManager::instance(), "closeCurrentPage");
return false;
}
if (type == QWebPage::NavigationTypeLinkClicked
- && (m_keyboardModifiers & Qt::ControlModifier
- || m_pressedButtons == Qt::MidButton)) {
- if (centralWidget->newEmptyTab())
- centralWidget->setSource(url);
+ && (m_keyboardModifiers & Qt::ControlModifier || m_pressedButtons == Qt::MidButton)) {
m_pressedButtons = Qt::NoButton;
m_keyboardModifiers = Qt::NoModifier;
+ OpenPagesManager::instance()->createPage(url);
return false;
}
@@ -243,23 +248,20 @@ bool HelpPage::acceptNavigationRequest(QWebFrame *,
// -- HelpViewer
-HelpViewer::HelpViewer(CentralWidget *parent, qreal zoom)
+HelpViewer::HelpViewer(qreal zoom, QWidget *parent)
: QWebView(parent)
- , parentWidget(parent)
- , loadFinished(false)
- , helpEngine(HelpEngineWrapper::instance())
+ , d(new HelpViewerPrivate)
{
TRACE_OBJ
setAcceptDrops(false);
+ settings()->setAttribute(QWebSettings::JavaEnabled, false);
+ settings()->setAttribute(QWebSettings::PluginsEnabled, false);
- setPage(new HelpPage(parent, this));
-
+ setPage(new HelpPage(this));
page()->setNetworkAccessManager(new HelpNetworkAccessManager(this));
QAction* action = pageAction(QWebPage::OpenLinkInNewWindow);
- action->setText(tr("Open Link in New Tab"));
- if (!parent)
- action->setVisible(false);
+ action->setText(tr("Open Link in New Page"));
pageAction(QWebPage::DownloadLinkToDisk)->setVisible(false);
pageAction(QWebPage::DownloadImageToDisk)->setVisible(false);
@@ -271,27 +273,23 @@ HelpViewer::HelpViewer(CentralWidget *parent, qreal zoom)
SLOT(actionChanged()));
connect(pageAction(QWebPage::Forward), SIGNAL(changed()), this,
SLOT(actionChanged()));
- connect(page(), SIGNAL(linkHovered(QString,QString,QString)), this,
+ connect(page(), SIGNAL(linkHovered(QString, QString, QString)), this,
SIGNAL(highlighted(QString)));
connect(this, SIGNAL(urlChanged(QUrl)), this, SIGNAL(sourceChanged(QUrl)));
connect(this, SIGNAL(loadStarted()), this, SLOT(setLoadStarted()));
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(setLoadFinished(bool)));
+ connect(this, SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged()));
connect(page(), SIGNAL(printRequested(QWebFrame*)), this, SIGNAL(printRequested()));
setFont(viewerFont());
setTextSizeMultiplier(zoom == 0.0 ? 1.0 : zoom);
}
-HelpViewer::~HelpViewer()
-{
- TRACE_OBJ
-}
-
QFont HelpViewer::viewerFont() const
{
TRACE_OBJ
- if (helpEngine.usesBrowserFont())
- return helpEngine.browserFont();
+ if (HelpEngineWrapper::instance().usesBrowserFont())
+ return HelpEngineWrapper::instance().browserFont();
QWebSettings *webSettings = QWebSettings::globalSettings();
return QFont(webSettings->fontFamily(QWebSettings::StandardFont),
@@ -324,26 +322,29 @@ void HelpViewer::resetScale()
setTextSizeMultiplier(1.0);
}
-bool HelpViewer::handleForwardBackwardMouseButtons(QMouseEvent *e)
+qreal HelpViewer::scale() const
{
TRACE_OBJ
- if (e->button() == Qt::XButton1) {
- triggerPageAction(QWebPage::Back);
- return true;
- }
+ return textSizeMultiplier();
+}
- if (e->button() == Qt::XButton2) {
- triggerPageAction(QWebPage::Forward);
- return true;
- }
+QString HelpViewer::title() const
+{
+ TRACE_OBJ
+ return QWebView::title();
+}
- return false;
+void HelpViewer::setTitle(const QString &title)
+{
+ TRACE_OBJ
+ Q_UNUSED(title)
}
QUrl HelpViewer::source() const
{
+ TRACE_OBJ
HelpPage *currentPage = static_cast<HelpPage*> (page());
- if (currentPage && !hasLoadFinished()) {
+ if (currentPage && !d->m_loadFinished) {
// see HelpPage::acceptNavigationRequest(...)
return currentPage->m_loadingUrl;
}
@@ -356,44 +357,84 @@ void HelpViewer::setSource(const QUrl &url)
load(url.toString() == QLatin1String("help") ? LocalHelpFile : url);
}
-void HelpViewer::home()
+QString HelpViewer::selectedText() const
{
TRACE_OBJ
- setSource(helpEngine.homePage());
+ return QWebView::selectedText();
}
-void HelpViewer::wheelEvent(QWheelEvent *e)
+bool HelpViewer::isForwardAvailable() const
{
TRACE_OBJ
- if (e->modifiers()& Qt::ControlModifier) {
- e->accept();
- e->delta() > 0 ? scaleUp() : scaleDown();
- } else {
- QWebView::wheelEvent(e);
- }
+ return pageAction(QWebPage::Forward)->isEnabled();
}
-void HelpViewer::mouseReleaseEvent(QMouseEvent *e)
+bool HelpViewer::isBackwardAvailable() const
{
TRACE_OBJ
-#ifndef Q_OS_LINUX
- if (handleForwardBackwardMouseButtons(e))
- return;
-#endif
+ return pageAction(QWebPage::Back)->isEnabled();
+}
- QWebView::mouseReleaseEvent(e);
+bool HelpViewer::findText(const QString &text, FindFlags flags, bool incremental,
+ bool fromSearch)
+{
+ TRACE_OBJ
+ Q_UNUSED((incremental && fromSearch))
+ QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument;
+ if (flags & FindBackward)
+ options |= QWebPage::FindBackward;
+ if (flags & FindCaseSensitively)
+ options |= QWebPage::FindCaseSensitively;
+
+ bool found = QWebView::findText(text, options);
+ options = QWebPage::HighlightAllOccurrences;
+ QWebView::findText(QLatin1String(""), options); // clear first
+ QWebView::findText(text, options); // force highlighting of all other matches
+ return found;
}
-void HelpViewer::actionChanged()
+// -- public slots
+
+void HelpViewer::copy()
{
TRACE_OBJ
- 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());
+ triggerPageAction(QWebPage::Copy);
+}
+
+void HelpViewer::forward()
+{
+ TRACE_OBJ
+ QWebView::forward();
+}
+
+void HelpViewer::backward()
+{
+ TRACE_OBJ
+ back();
+}
+
+// -- protected
+
+void HelpViewer::keyPressEvent(QKeyEvent *e)
+{
+ TRACE_OBJ
+ // TODO: remove this once we support multiple keysequences per command
+ if (e->key() == Qt::Key_Insert && e->modifiers() == Qt::CTRL) {
+ if (!selectedText().isEmpty())
+ copy();
+ }
+ QWebView::keyPressEvent(e);
+}
+
+void HelpViewer::wheelEvent(QWheelEvent *event)
+{
+ TRACE_OBJ
+ if (event->modifiers()& Qt::ControlModifier) {
+ event->accept();
+ event->delta() > 0 ? scaleUp() : scaleDown();
+ } else {
+ QWebView::wheelEvent(event);
+ }
}
void HelpViewer::mousePressEvent(QMouseEvent *event)
@@ -404,24 +445,51 @@ void HelpViewer::mousePressEvent(QMouseEvent *event)
return;
#endif
- HelpPage *currentPage = static_cast<HelpPage*>(page());
- if (currentPage) {
+ if (HelpPage *currentPage = static_cast<HelpPage*> (page())) {
currentPage->m_pressedButtons = event->buttons();
currentPage->m_keyboardModifiers = event->modifiers();
}
+
QWebView::mousePressEvent(event);
}
-void HelpViewer::setLoadStarted()
+void HelpViewer::mouseReleaseEvent(QMouseEvent *event)
{
- loadFinished = false;
+ TRACE_OBJ
+#ifndef Q_OS_LINUX
+ if (handleForwardBackwardMouseButtons(event))
+ return;
+#endif
+
+ QWebView::mouseReleaseEvent(event);
+}
+
+// -- private slots
+
+void HelpViewer::actionChanged()
+{
+ TRACE_OBJ
+ 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());
+}
+
+// -- private
+
+bool HelpViewer::eventFilter(QObject *obj, QEvent *event)
+{
+ TRACE_OBJ
+ return QWebView::eventFilter(obj, event);
}
-void HelpViewer::setLoadFinished(bool ok)
+void HelpViewer::contextMenuEvent(QContextMenuEvent *event)
{
TRACE_OBJ
- loadFinished = ok;
- emit sourceChanged(url());
+ QWebView::contextMenuEvent(event);
}
QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/helpviewer_qwv.h b/tools/assistant/tools/assistant/helpviewer_qwv.h
deleted file mode 100644
index d4a27a2..0000000
--- a/tools/assistant/tools/assistant/helpviewer_qwv.h
+++ /dev/null
@@ -1,123 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Qt Assistant of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** 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.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef HELPVIEWERQWV_H
-#define HELPVIEWERQWV_H
-
-#include "helpviewer.h"
-
-#include <QtGui/QAction>
-#include <QtWebKit/QWebView>
-
-QT_BEGIN_NAMESPACE
-
-class CentralWidget;
-class HelpEngineWrapper;
-class QMouseEvent;
-
-class HelpViewer : public QWebView, public AbstractHelpViewer
-{
- Q_OBJECT
-
-public:
- explicit HelpViewer(CentralWidget *parent, qreal zoom = 0.0);
- ~HelpViewer();
-
- QFont viewerFont() const;
- void setViewerFont(const QFont &font);
-
- void scaleUp();
- void scaleDown();
- void resetScale();
- qreal scale() const { return textSizeMultiplier(); }
-
- bool handleForwardBackwardMouseButtons(QMouseEvent *e);
-
- QUrl source() const;
- void setSource(const QUrl &url);
-
- inline QString documentTitle() const
- { return title(); }
-
- inline bool hasSelection() const
- { return !selectedText().isEmpty(); } // ### this is suboptimal
-
- inline void copy()
- { return triggerPageAction(QWebPage::Copy); }
-
- 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(); }
-
-Q_SIGNALS:
- void copyAvailable(bool enabled);
- void forwardAvailable(bool enabled);
- void backwardAvailable(bool enabled);
- void highlighted(const QString &);
- void sourceChanged(const QUrl &);
- void printRequested();
-
-protected:
- virtual void wheelEvent(QWheelEvent *);
- void mouseReleaseEvent(QMouseEvent *e);
- void mousePressEvent(QMouseEvent *event);
-
-private Q_SLOTS:
- void actionChanged();
- void setLoadStarted();
- void setLoadFinished(bool ok);
-
-private:
- CentralWidget* parentWidget;
- bool loadFinished;
- HelpEngineWrapper &helpEngine;
-};
-
-QT_END_NAMESPACE
-
-#endif // HELPVIEWERQWV_H
diff --git a/tools/assistant/tools/assistant/images/closebutton.png b/tools/assistant/tools/assistant/images/closebutton.png
new file mode 100644
index 0000000..c978cf5
--- /dev/null
+++ b/tools/assistant/tools/assistant/images/closebutton.png
Binary files differ
diff --git a/tools/assistant/tools/assistant/images/darkclosebutton.png b/tools/assistant/tools/assistant/images/darkclosebutton.png
new file mode 100644
index 0000000..1077663
--- /dev/null
+++ b/tools/assistant/tools/assistant/images/darkclosebutton.png
Binary files differ
diff --git a/tools/assistant/tools/assistant/indexwindow.cpp b/tools/assistant/tools/assistant/indexwindow.cpp
index 63ddbe4..00f61f2 100644
--- a/tools/assistant/tools/assistant/indexwindow.cpp
+++ b/tools/assistant/tools/assistant/indexwindow.cpp
@@ -38,13 +38,15 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "tracer.h"
#include "indexwindow.h"
+
#include "centralwidget.h"
#include "helpenginewrapper.h"
#include "helpviewer.h"
+#include "openpagesmanager.h"
#include "topicchooser.h"
+#include "tracer.h"
#include <QtGui/QLayout>
#include <QtGui/QLabel>
@@ -219,10 +221,10 @@ void IndexWindow::open(QHelpIndexWidget* indexWidget, const QModelIndex &index)
return;
}
- if (!AbstractHelpViewer::canOpenPage(url.path()))
+ if (!HelpViewer::canOpenPage(url.path()))
CentralWidget::instance()->setSource(url);
else
- CentralWidget::instance()->setSourceInNewTab(url);
+ OpenPagesManager::instance()->createPage(url);
}
}
diff --git a/tools/assistant/tools/assistant/mainwindow.cpp b/tools/assistant/tools/assistant/mainwindow.cpp
index 68343a4..48469d4 100644
--- a/tools/assistant/tools/assistant/mainwindow.cpp
+++ b/tools/assistant/tools/assistant/mainwindow.cpp
@@ -38,57 +38,58 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "tracer.h"
#include "mainwindow.h"
+#include "aboutdialog.h"
#include "bookmarkmanager.h"
#include "centralwidget.h"
-#include "indexwindow.h"
-#include "topicchooser.h"
+#include "cmdlineparser.h"
#include "contentwindow.h"
-#include "preferencesdialog.h"
+#include "globalactions.h"
#include "helpenginewrapper.h"
+#include "indexwindow.h"
+#include "openpagesmanager.h"
+#include "preferencesdialog.h"
+#include "qtdocinstaller.h"
#include "remotecontrol.h"
-#include "cmdlineparser.h"
-#include "aboutdialog.h"
#include "searchwidget.h"
-#include "qtdocinstaller.h"
-
-// #define TRACING_REQUESTED
+#include "topicchooser.h"
+#include "tracer.h"
-#include <QtCore/QDir>
-#include <QtCore/QTimer>
+#include <QtCore/QByteArray>
#include <QtCore/QDateTime>
#include <QtCore/QDebug>
-#include <QtCore/QFileSystemWatcher>
+#include <QtCore/QDir>
#include <QtCore/QPair>
#include <QtCore/QResource>
-#include <QtCore/QByteArray>
#include <QtCore/QTextStream>
-#include <QtCore/QCoreApplication>
+#include <QtCore/QTimer>
-#include <QtGui/QMenuBar>
#include <QtGui/QAction>
-#include <QtGui/QToolBar>
-#include <QtGui/QStatusBar>
+#include <QtGui/QComboBox>
+#include <QtGui/QDesktopServices>
+#include <QtGui/QDesktopWidget>
+#include <QtGui/QDockWidget>
+#include <QtGui/QFontDatabase>
+#include <QtGui/QFileDialog>
#include <QtGui/QLabel>
-#include <QtGui/QLineEdit>
#include <QtGui/QLayout>
-#include <QtGui/QDockWidget>
-#include <QtGui/QTreeView>
+#include <QtGui/QLineEdit>
+#include <QtGui/QMenuBar>
#include <QtGui/QMessageBox>
-#include <QtGui/QFontDatabase>
-#include <QtGui/QComboBox>
#include <QtGui/QProgressBar>
-#include <QtGui/QDesktopServices>
+#include <QtGui/QShortcut>
+#include <QtGui/QStatusBar>
+#include <QtGui/QToolBar>
#include <QtGui/QToolButton>
-#include <QtGui/QFileDialog>
-#include <QtHelp/QHelpEngineCore>
-#include <QtHelp/QHelpSearchEngine>
#include <QtHelp/QHelpContentModel>
+#include <QtHelp/QHelpEngineCore>
#include <QtHelp/QHelpIndexModel>
+#include <QtHelp/QHelpSearchEngine>
+
+#include <cstdlib>
QT_BEGIN_NAMESPACE
@@ -105,6 +106,7 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent)
TRACE_OBJ
setToolButtonStyle(Qt::ToolButtonFollowStyle);
+ setDockOptions(ForceTabbedDocks); // Has no effect; Qt bug?
QString collectionFile;
if (usesDefaultCollection()) {
@@ -115,6 +117,14 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent)
}
HelpEngineWrapper &helpEngineWrapper =
HelpEngineWrapper::instance(collectionFile);
+ BookmarkManager *bookMarkManager = BookmarkManager::instance();
+
+ if (!initHelpDB(!cmdLine->collectionFileGiven())) {
+ qDebug("Fatal error: Help engine initialization failed. "
+ "Error message was: %s\nAssistant will now exit.",
+ qPrintable(HelpEngineWrapper::instance().error()));
+ std::exit(1);
+ }
m_centralWidget = new CentralWidget(this);
setCentralWidget(m_centralWidget);
@@ -131,132 +141,154 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent)
contentDock->setWidget(m_contentWindow);
addDockWidget(Qt::LeftDockWidgetArea, contentDock);
- QDockWidget *bookmarkDock = 0;
- if (BookmarkManager *manager = BookmarkManager::instance()) {
- bookmarkDock = new QDockWidget(tr("Bookmarks"), this);
- bookmarkDock->setObjectName(QLatin1String("BookmarkWindow"));
- bookmarkDock->setWidget(m_bookmarkWidget = manager->bookmarkDockWidget());
- addDockWidget(Qt::LeftDockWidgetArea, bookmarkDock);
-
- connect(manager, SIGNAL(escapePressed()), this,
+ m_searchWindow = new SearchWidget(helpEngineWrapper.searchEngine());
+ m_searchWindow->setFont(!helpEngineWrapper.usesBrowserFont() ? qApp->font()
+ : helpEngineWrapper.browserFont());
+ QDockWidget *searchDock = new QDockWidget(tr("Search"), this);
+ searchDock->setObjectName(QLatin1String("SearchWindow"));
+ searchDock->setWidget(m_searchWindow);
+ addDockWidget(Qt::LeftDockWidgetArea, searchDock);
+
+ QDockWidget *bookmarkDock = new QDockWidget(tr("Bookmarks"), this);
+ bookmarkDock->setObjectName(QLatin1String("BookmarkWindow"));
+ bookmarkDock->setWidget(m_bookmarkWidget
+ = bookMarkManager->bookmarkDockWidget());
+ addDockWidget(Qt::LeftDockWidgetArea, bookmarkDock);
+
+ QDockWidget *openPagesDock = new QDockWidget(tr("Open Pages"), this);
+ openPagesDock->setObjectName(QLatin1String("Open Pages"));
+ OpenPagesManager *openPagesManager
+ = OpenPagesManager::createInstance(this, usesDefaultCollection(), m_cmdLine->url());
+ openPagesDock->setWidget(openPagesManager->openPagesWidget());
+ addDockWidget(Qt::LeftDockWidgetArea, openPagesDock);
+
+ connect(m_centralWidget, SIGNAL(addBookmark(QString, QString)),
+ bookMarkManager, SLOT(addBookmark(QString, QString)));
+ connect(bookMarkManager, SIGNAL(escapePressed()), this,
SLOT(activateCurrentCentralWidgetTab()));
- connect(manager, SIGNAL(setSource(QUrl)), m_centralWidget,
+ connect(bookMarkManager, SIGNAL(setSource(QUrl)), m_centralWidget,
SLOT(setSource(QUrl)));
- connect(manager, SIGNAL(setSourceInNewTab(QUrl)), m_centralWidget,
- SLOT(setSourceInNewTab(QUrl)));
- connect(m_centralWidget, SIGNAL(addBookmark(QString, QString)), manager,
- SLOT(addBookmark(QString, QString)));
- }
+ connect(bookMarkManager, SIGNAL(setSourceInNewTab(QUrl)),
+ openPagesManager, SLOT(createPage(QUrl)));
QHelpSearchEngine *searchEngine = helpEngineWrapper.searchEngine();
connect(searchEngine, SIGNAL(indexingStarted()), this, SLOT(indexingStarted()));
connect(searchEngine, SIGNAL(indexingFinished()), this, SLOT(indexingFinished()));
- m_centralWidget->createSearchWidget(searchEngine);
- m_centralWidget->activateSearchWidget();
-
QString defWindowTitle = tr("Qt Assistant");
setWindowTitle(defWindowTitle);
setupActions();
statusBar()->show();
+ m_centralWidget->connectTabBar();
- if (initHelpDB(!cmdLine->collectionFileGiven())) {
- setupFilterToolbar();
- setupAddressToolbar();
-
- const QString windowTitle = helpEngineWrapper.windowTitle();
- setWindowTitle(windowTitle.isEmpty() ? defWindowTitle : windowTitle);
- QByteArray iconArray = helpEngineWrapper.applicationIcon();
- if (iconArray.size() > 0) {
- QPixmap pix;
- pix.loadFromData(iconArray);
- QIcon appIcon(pix);
- qApp->setWindowIcon(appIcon);
- } else {
- QIcon appIcon(QLatin1String(":/trolltech/assistant/images/assistant-128.png"));
- qApp->setWindowIcon(appIcon);
- }
+ setupFilterToolbar();
+ setupAddressToolbar();
- // Show the widget here, otherwise the restore geometry and state won't work
- // on x11.
- show();
- QByteArray ba(helpEngineWrapper.mainWindow());
- if (!ba.isEmpty())
- restoreState(ba);
-
- ba = helpEngineWrapper.mainWindowGeometry();
- if (!ba.isEmpty()) {
- restoreGeometry(ba);
- } else {
- tabifyDockWidget(contentDock, indexDock);
- if (bookmarkDock)
- tabifyDockWidget(indexDock, bookmarkDock);
- contentDock->raise();
- resize(QSize(800, 600));
- }
+ const QString windowTitle = helpEngineWrapper.windowTitle();
+ setWindowTitle(windowTitle.isEmpty() ? defWindowTitle : windowTitle);
+ QByteArray iconArray = helpEngineWrapper.applicationIcon();
+ if (iconArray.size() > 0) {
+ QPixmap pix;
+ pix.loadFromData(iconArray);
+ QIcon appIcon(pix);
+ qApp->setWindowIcon(appIcon);
+ } else {
+ QIcon appIcon(QLatin1String(":/trolltech/assistant/images/assistant-128.png"));
+ qApp->setWindowIcon(appIcon);
+ }
- if (!helpEngineWrapper.hasFontSettings()) {
- helpEngineWrapper.setUseAppFont(false);
- helpEngineWrapper.setUseBrowserFont(false);
- helpEngineWrapper.setAppFont(qApp->font());
- helpEngineWrapper.setAppWritingSystem(QFontDatabase::Latin);
- helpEngineWrapper.setBrowserFont(qApp->font());
- helpEngineWrapper.setBrowserWritingSystem(QFontDatabase::Latin);
- } else {
- updateApplicationFont();
- }
+ QToolBar *toolBar = addToolBar(tr("Bookmark Toolbar"));
+ bookMarkManager->setBookmarksToolbar(toolBar);
- updateAboutMenuText();
-
- QTimer::singleShot(0, this, SLOT(insertLastPages()));
- if (m_cmdLine->enableRemoteControl())
- (void)new RemoteControl(this);
-
- if (m_cmdLine->contents() == CmdLineParser::Show)
- showContents();
- else if (m_cmdLine->contents() == CmdLineParser::Hide)
- hideContents();
-
- if (m_cmdLine->index() == CmdLineParser::Show)
- showIndex();
- else if (m_cmdLine->index() == CmdLineParser::Hide)
- hideIndex();
-
- if (m_cmdLine->bookmarks() == CmdLineParser::Show)
- showBookmarksDockWidget();
- else if (m_cmdLine->bookmarks() == CmdLineParser::Hide)
- hideBookmarksDockWidget();
-
- if (m_cmdLine->search() == CmdLineParser::Show)
- showSearch();
- else if (m_cmdLine->search() == CmdLineParser::Hide)
- hideSearch();
-
- if (m_cmdLine->contents() == CmdLineParser::Activate)
- showContents();
- else if (m_cmdLine->index() == CmdLineParser::Activate)
- showIndex();
- else if (m_cmdLine->bookmarks() == CmdLineParser::Activate)
- showBookmarksDockWidget();
-
- if (!m_cmdLine->currentFilter().isEmpty()) {
- const QString &curFilter = m_cmdLine->currentFilter();
- if (helpEngineWrapper.customFilters().contains(curFilter))
- helpEngineWrapper.setCurrentFilter(curFilter);
- }
+ // Show the widget here, otherwise the restore geometry and state won't work
+ // on x11.
+ show();
- if (usesDefaultCollection())
- QTimer::singleShot(0, this, SLOT(lookForNewQtDocumentation()));
- else
- checkInitState();
+ toolBar->hide();
+ toolBarMenu()->addAction(toolBar->toggleViewAction());
+
+ QByteArray ba(helpEngineWrapper.mainWindow());
+ if (!ba.isEmpty())
+ restoreState(ba);
+
+ ba = helpEngineWrapper.mainWindowGeometry();
+ if (!ba.isEmpty()) {
+ restoreGeometry(ba);
+ } else {
+ tabifyDockWidget(contentDock, indexDock);
+ tabifyDockWidget(indexDock, bookmarkDock);
+ tabifyDockWidget(bookmarkDock, openPagesDock);
+ tabifyDockWidget(openPagesDock, searchDock);
+ contentDock->raise();
+ const QRect screen = QApplication::desktop()->screenGeometry();
+ resize(4*screen.width()/5, 4*screen.height()/5);
+ }
- connect(&helpEngineWrapper, SIGNAL(documentationRemoved(QString)),
- this, SLOT(documentationRemoved(QString)));
- connect(&helpEngineWrapper, SIGNAL(documentationUpdated(QString)),
- this, SLOT(documentationUpdated(QString)));
+ if (!helpEngineWrapper.hasFontSettings()) {
+ helpEngineWrapper.setUseAppFont(false);
+ helpEngineWrapper.setUseBrowserFont(false);
+ helpEngineWrapper.setAppFont(qApp->font());
+ helpEngineWrapper.setAppWritingSystem(QFontDatabase::Latin);
+ helpEngineWrapper.setBrowserFont(qApp->font());
+ helpEngineWrapper.setBrowserWritingSystem(QFontDatabase::Latin);
+ } else {
+ updateApplicationFont();
}
+
+ updateAboutMenuText();
+
+ QTimer::singleShot(0, this, SLOT(insertLastPages()));
+ if (m_cmdLine->enableRemoteControl())
+ (void)new RemoteControl(this);
+
+ if (m_cmdLine->contents() == CmdLineParser::Show)
+ showContents();
+ else if (m_cmdLine->contents() == CmdLineParser::Hide)
+ hideContents();
+
+ if (m_cmdLine->index() == CmdLineParser::Show)
+ showIndex();
+ else if (m_cmdLine->index() == CmdLineParser::Hide)
+ hideIndex();
+
+ if (m_cmdLine->bookmarks() == CmdLineParser::Show)
+ showBookmarksDockWidget();
+ else if (m_cmdLine->bookmarks() == CmdLineParser::Hide)
+ hideBookmarksDockWidget();
+
+ if (m_cmdLine->search() == CmdLineParser::Show)
+ showSearch();
+ else if (m_cmdLine->search() == CmdLineParser::Hide)
+ hideSearch();
+
+ if (m_cmdLine->contents() == CmdLineParser::Activate)
+ showContents();
+ else if (m_cmdLine->index() == CmdLineParser::Activate)
+ showIndex();
+ else if (m_cmdLine->bookmarks() == CmdLineParser::Activate)
+ showBookmarksDockWidget();
+
+ if (!m_cmdLine->currentFilter().isEmpty()) {
+ const QString &curFilter = m_cmdLine->currentFilter();
+ if (helpEngineWrapper.customFilters().contains(curFilter))
+ helpEngineWrapper.setCurrentFilter(curFilter);
+ }
+
+ if (usesDefaultCollection())
+ QTimer::singleShot(0, this, SLOT(lookForNewQtDocumentation()));
+ else
+ checkInitState();
+
+ connect(&helpEngineWrapper, SIGNAL(documentationRemoved(QString)),
+ this, SLOT(documentationRemoved(QString)));
+ connect(&helpEngineWrapper, SIGNAL(documentationUpdated(QString)),
+ this, SLOT(documentationUpdated(QString)));
+
setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North);
+ GlobalActions::instance()->updateActions();
+ if (helpEngineWrapper.addressBarEnabled())
+ showNewAddress();
}
MainWindow::~MainWindow()
@@ -392,11 +424,6 @@ void MainWindow::checkInitState()
void MainWindow::insertLastPages()
{
TRACE_OBJ
- if (m_cmdLine->url().isValid())
- m_centralWidget->setSource(m_cmdLine->url());
- else
- m_centralWidget->setupWidget();
-
if (m_cmdLine->search() == CmdLineParser::Activate)
showSearch();
}
@@ -414,8 +441,13 @@ void MainWindow::setupActions()
QMenu *menu = menuBar()->addMenu(tr("&File"));
- m_newTabAction = menu->addAction(tr("New &Tab"), m_centralWidget, SLOT(newTab()));
+ OpenPagesManager * const openPages = OpenPagesManager::instance();
+ m_newTabAction
+ = menu->addAction(tr("New &Tab"), openPages, SLOT(createPage()));
m_newTabAction->setShortcut(QKeySequence::AddTab);
+ m_closeTabAction = menu->addAction(tr("&Close Tab"),
+ openPages, SLOT(closeCurrentPage()));
+ m_closeTabAction->setShortcuts(QKeySequence::Close);
menu->addSeparator();
@@ -424,17 +456,10 @@ void MainWindow::setupActions()
m_printPreviewAction = menu->addAction(tr("Print Preview..."), m_centralWidget,
SLOT(printPreview()));
- m_printAction = menu->addAction(tr("&Print..."), m_centralWidget, SLOT(print()));
- m_printAction->setPriority(QAction::LowPriority);
- m_printAction->setIcon(QIcon(resourcePath + QLatin1String("/print.png")));
- m_printAction->setShortcut(QKeySequence::Print);
-
+ GlobalActions *globalActions = GlobalActions::instance(this);
+ menu->addAction(globalActions->printAction());
menu->addSeparator();
- m_closeTabAction = menu->addAction(tr("&Close Tab"), m_centralWidget,
- SLOT(closeTab()));
- m_closeTabAction->setShortcuts(QKeySequence::Close);
-
QAction *tmp = menu->addAction(QIcon::fromTheme("application-exit"),
tr("&Quit"), this, SLOT(close()));
tmp->setMenuRole(QAction::QuitRole);
@@ -445,19 +470,8 @@ void MainWindow::setupActions()
#endif
menu = menuBar()->addMenu(tr("&Edit"));
- m_copyAction = menu->addAction(tr("&Copy selected Text"), m_centralWidget,
- SLOT(copySelection()));
- m_copyAction->setPriority(QAction::LowPriority);
- m_copyAction->setIconText("&Copy");
- m_copyAction->setIcon(QIcon(resourcePath + QLatin1String("/editcopy.png")));
- m_copyAction->setShortcuts(QKeySequence::Copy);
- m_copyAction->setEnabled(false);
-
- m_findAction = menu->addAction(tr("&Find in Text..."), m_centralWidget,
- SLOT(showTextSearch()));
- m_findAction->setIconText(tr("&Find"));
- m_findAction->setIcon(QIcon(resourcePath + QLatin1String("/find.png")));
- m_findAction->setShortcuts(QKeySequence::Find);
+ menu->addAction(globalActions->copyAction());
+ menu->addAction(globalActions->findAction());
QAction *findNextAction = menu->addAction(tr("Find &Next"), m_centralWidget,
SLOT(findNext()));
@@ -472,17 +486,8 @@ void MainWindow::setupActions()
tmp->setMenuRole(QAction::PreferencesRole);
m_viewMenu = menuBar()->addMenu(tr("&View"));
- m_zoomInAction = m_viewMenu->addAction(tr("Zoom &in"), m_centralWidget,
- SLOT(zoomIn()));
- m_zoomInAction->setPriority(QAction::LowPriority);
- m_zoomInAction->setIcon(QIcon(resourcePath + QLatin1String("/zoomin.png")));
- m_zoomInAction->setShortcut(QKeySequence::ZoomIn);
-
- m_zoomOutAction = m_viewMenu->addAction(tr("Zoom &out"), m_centralWidget,
- SLOT(zoomOut()));
- m_zoomOutAction->setPriority(QAction::LowPriority);
- m_zoomOutAction->setIcon(QIcon(resourcePath + QLatin1String("/zoomout.png")));
- m_zoomOutAction->setShortcut(QKeySequence::ZoomOut);
+ m_viewMenu->addAction(globalActions->zoomInAction());
+ m_viewMenu->addAction(globalActions->zoomOutAction());
m_resetZoomAction = m_viewMenu->addAction(tr("Normal &Size"), m_centralWidget,
SLOT(resetZoom()));
@@ -498,24 +503,15 @@ void MainWindow::setupActions()
QKeySequence(tr("ALT+I")));
m_viewMenu->addAction(tr("Bookmarks"), this, SLOT(showBookmarksDockWidget()),
QKeySequence(tr("ALT+O")));
- m_viewMenu->addAction(tr("Search"), this, SLOT(showSearchWidget()),
+ m_viewMenu->addAction(tr("Search"), this, SLOT(showSearch()),
QKeySequence(tr("ALT+S")));
+ m_viewMenu->addAction(tr("Open Pages"), this, SLOT(showOpenPages()),
+ QKeySequence(tr("ALT+P")));
menu = menuBar()->addMenu(tr("&Go"));
- m_homeAction = menu->addAction(tr("&Home"), m_centralWidget, SLOT(home()));
- m_homeAction->setShortcut(tr("ALT+Home"));
- m_homeAction->setIcon(QIcon(resourcePath + QLatin1String("/home.png")));
-
- m_backAction = menu->addAction(tr("&Back"), m_centralWidget, SLOT(backward()));
- m_backAction->setEnabled(false);
- m_backAction->setShortcuts(QKeySequence::Back);
- m_backAction->setIcon(QIcon(resourcePath + QLatin1String("/previous.png")));
-
- m_nextAction = menu->addAction(tr("&Forward"), m_centralWidget, SLOT(forward()));
- m_nextAction->setPriority(QAction::LowPriority);
- m_nextAction->setEnabled(false);
- m_nextAction->setShortcuts(QKeySequence::Forward);
- m_nextAction->setIcon(QIcon(resourcePath + QLatin1String("/next.png")));
+ menu->addAction(globalActions->homeAction());
+ menu->addAction(globalActions->backAction());
+ menu->addAction(globalActions->nextAction());
m_syncAction = menu->addAction(tr("Sync with Table of Contents"), this,
SLOT(syncContents()));
@@ -524,60 +520,52 @@ void MainWindow::setupActions()
menu->addSeparator();
- tmp = menu->addAction(tr("Next Page"), m_centralWidget, SLOT(nextPage()));
+ tmp = menu->addAction(tr("Next Page"), openPages, SLOT(nextPage()));
tmp->setShortcuts(QList<QKeySequence>() << QKeySequence(tr("Ctrl+Alt+Right"))
<< QKeySequence(Qt::CTRL + Qt::Key_PageDown));
- tmp = menu->addAction(tr("Previous Page"), m_centralWidget, SLOT(previousPage()));
+ tmp = menu->addAction(tr("Previous Page"), openPages, SLOT(previousPage()));
tmp->setShortcuts(QList<QKeySequence>() << QKeySequence(tr("Ctrl+Alt+Left"))
<< QKeySequence(Qt::CTRL + Qt::Key_PageUp));
- if (BookmarkManager *manager = BookmarkManager::instance())
- manager->takeBookmarksMenu(menuBar()->addMenu(tr("&Bookmarks")));
+#ifdef Q_WS_MAC
+ QShortcut *sct = new QShortcut(QKeySequence(Qt::ALT + Qt::Key_Tab), this);
+ connect(sct, SIGNAL(activated()), openPages, SLOT(nextPageWithSwitcher()));
+ sct = new QShortcut(QKeySequence(Qt::ALT + Qt::SHIFT + Qt::Key_Tab), this);
+ connect(sct, SIGNAL(activated()), openPages, SLOT(previousPageWithSwitcher()));
+#else
+ QShortcut *sct = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Tab), this);
+ connect(sct, SIGNAL(activated()), openPages, SLOT(nextPageWithSwitcher()));
+ sct = new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab), this);
+ connect(sct, SIGNAL(activated()), openPages, SLOT(previousPageWithSwitcher()));
+#endif
+
+ BookmarkManager::instance()->setBookmarksMenu(menuBar()->addMenu(tr("&Bookmarks")));
menu = menuBar()->addMenu(tr("&Help"));
m_aboutAction = menu->addAction(tr("About..."), this, SLOT(showAboutDialog()));
m_aboutAction->setMenuRole(QAction::AboutRole);
#ifdef Q_WS_X11
- m_newTabAction->setIcon(QIcon::fromTheme("tab-new", m_newTabAction->icon()));
- m_closeTabAction->setIcon(QIcon::fromTheme("window-close", m_closeTabAction->icon()));
- m_backAction->setIcon(QIcon::fromTheme("go-previous" , m_backAction->icon()));
- m_nextAction->setIcon(QIcon::fromTheme("go-next" , m_nextAction->icon()));
- m_zoomInAction->setIcon(QIcon::fromTheme("zoom-in" , m_zoomInAction->icon()));
- m_zoomOutAction->setIcon(QIcon::fromTheme("zoom-out" , m_zoomOutAction->icon()));
m_resetZoomAction->setIcon(QIcon::fromTheme("zoom-original" , m_resetZoomAction->icon()));
m_syncAction->setIcon(QIcon::fromTheme("view-refresh" , m_syncAction->icon()));
- m_copyAction->setIcon(QIcon::fromTheme("edit-copy" , m_copyAction->icon()));
- m_findAction->setIcon(QIcon::fromTheme("edit-find" , m_findAction->icon()));
- m_homeAction->setIcon(QIcon::fromTheme("go-home" , m_homeAction->icon()));
- m_pageSetupAction->setIcon(QIcon::fromTheme("document-page-setup", m_pageSetupAction->icon()));
- m_printPreviewAction->setIcon(QIcon::fromTheme("document-print-preview", m_printPreviewAction->icon()));
- m_printAction->setIcon(QIcon::fromTheme("document-print" , m_printAction->icon()));
- m_aboutAction->setIcon(QIcon::fromTheme("help-about", m_aboutAction->icon()));
#endif
QToolBar *navigationBar = addToolBar(tr("Navigation Toolbar"));
navigationBar->setObjectName(QLatin1String("NavigationToolBar"));
- navigationBar->addAction(m_backAction);
- navigationBar->addAction(m_nextAction);
- navigationBar->addAction(m_homeAction);
+ navigationBar->addAction(globalActions->backAction());
+ navigationBar->addAction(globalActions->nextAction());
+ navigationBar->addAction(globalActions->homeAction());
navigationBar->addAction(m_syncAction);
- QAction *sep = navigationBar->addSeparator();
- navigationBar->addAction(m_copyAction);
- navigationBar->addAction(m_printAction);
- navigationBar->addAction(m_findAction);
- QAction *sep2 = navigationBar->addSeparator();
- navigationBar->addAction(m_zoomInAction);
- navigationBar->addAction(m_zoomOutAction);
+ navigationBar->addSeparator();
+ navigationBar->addAction(globalActions->copyAction());
+ navigationBar->addAction(globalActions->printAction());
+ navigationBar->addAction(globalActions->findAction());
+ navigationBar->addSeparator();
+ navigationBar->addAction(globalActions->zoomInAction());
+ navigationBar->addAction(globalActions->zoomOutAction());
navigationBar->addAction(m_resetZoomAction);
- QList<QAction*> actionList;
- actionList << m_backAction << m_nextAction << m_homeAction << sep
- << m_zoomInAction << m_zoomOutAction << sep2 << m_copyAction
- << m_printAction << m_findAction;
- m_centralWidget->setGlobalActions(actionList);
-
#if defined(Q_WS_MAC)
QMenu *windowMenu = new QMenu(tr("&Window"), this);
menuBar()->insertMenu(menu->menuAction(), windowMenu);
@@ -587,16 +575,14 @@ void MainWindow::setupActions()
#endif
// content viewer connections
- connect(m_centralWidget, SIGNAL(copyAvailable(bool)), this,
- SLOT(copyAvailable(bool)));
- connect(m_centralWidget, SIGNAL(currentViewerChanged()), this,
- SLOT(updateNavigationItems()));
- connect(m_centralWidget, SIGNAL(currentViewerChanged()), this,
- SLOT(updateTabCloseAction()));
- connect(m_centralWidget, SIGNAL(forwardAvailable(bool)), this,
- SLOT(updateNavigationItems()));
- connect(m_centralWidget, SIGNAL(backwardAvailable(bool)), this,
- SLOT(updateNavigationItems()));
+ connect(m_centralWidget, SIGNAL(copyAvailable(bool)), globalActions,
+ SLOT(setCopyAvailable(bool)));
+ connect(m_centralWidget, SIGNAL(currentViewerChanged()), globalActions,
+ SLOT(updateActions()));
+ connect(m_centralWidget, SIGNAL(forwardAvailable(bool)), globalActions,
+ SLOT(updateActions()));
+ connect(m_centralWidget, SIGNAL(backwardAvailable(bool)), globalActions,
+ SLOT(updateActions()));
connect(m_centralWidget, SIGNAL(highlighted(QString)), statusBar(),
SLOT(showMessage(QString)));
@@ -614,6 +600,12 @@ void MainWindow::setupActions()
connect(m_contentWindow, SIGNAL(escapePressed()), this,
SLOT(activateCurrentCentralWidgetTab()));
+ // search window
+ connect(m_searchWindow, SIGNAL(requestShowLink(QUrl)),
+ CentralWidget::instance(), SLOT(setSourceFromSearch(QUrl)));
+ connect(m_searchWindow, SIGNAL(requestShowLinkInNewTab(QUrl)),
+ OpenPagesManager::instance(), SLOT(createNewPageFromSearch(QUrl)));
+
#if defined(QT_NO_PRINTER)
m_pageSetupAction->setVisible(false);
m_printPreviewAction->setVisible(false);
@@ -737,26 +729,6 @@ void MainWindow::gotoAddress()
m_centralWidget->setSource(m_addressLineEdit->text());
}
-void MainWindow::updateNavigationItems()
-{
- TRACE_OBJ
- bool hasCurrentViewer = m_centralWidget->isHomeAvailable();
- m_copyAction->setEnabled(m_centralWidget->hasSelection());
- m_homeAction->setEnabled(hasCurrentViewer);
- m_syncAction->setEnabled(hasCurrentViewer);
- m_printPreviewAction->setEnabled(hasCurrentViewer);
- m_printAction->setEnabled(hasCurrentViewer);
- m_nextAction->setEnabled(m_centralWidget->isForwardAvailable());
- m_backAction->setEnabled(m_centralWidget->isBackwardAvailable());
- m_newTabAction->setEnabled(hasCurrentViewer);
-}
-
-void MainWindow::updateTabCloseAction()
-{
- TRACE_OBJ
- m_closeTabAction->setEnabled(m_centralWidget->enableTabCloseAction());
-}
-
void MainWindow::showTopicChooser(const QMap<QString, QUrl> &links,
const QString &keyword)
{
@@ -775,6 +747,8 @@ void MainWindow::showPreferences()
SLOT(updateApplicationFont()));
connect(&dia, SIGNAL(updateBrowserFont()), m_centralWidget,
SLOT(updateBrowserFont()));
+ connect(&dia, SIGNAL(updateUserInterface()), m_centralWidget,
+ SLOT(updateUserInterface()));
dia.showDialog();
}
@@ -790,12 +764,6 @@ void MainWindow::syncContents()
qApp->restoreOverrideCursor();
}
-void MainWindow::copyAvailable(bool yes)
-{
- TRACE_OBJ
- m_copyAction->setEnabled(yes);
-}
-
void MainWindow::showAboutDialog()
{
TRACE_OBJ
@@ -904,15 +872,13 @@ void MainWindow::setBookmarksVisible(bool visible)
void MainWindow::showBookmarksDockWidget()
{
TRACE_OBJ
- if (m_bookmarkWidget)
- activateDockWidget(m_bookmarkWidget);
+ activateDockWidget(m_bookmarkWidget);
}
void MainWindow::hideBookmarksDockWidget()
{
TRACE_OBJ
- if (m_bookmarkWidget)
- m_bookmarkWidget->parentWidget()->hide();
+ m_bookmarkWidget->parentWidget()->hide();
}
void MainWindow::setSearchVisible(bool visible)
@@ -927,13 +893,19 @@ void MainWindow::setSearchVisible(bool visible)
void MainWindow::showSearch()
{
TRACE_OBJ
- m_centralWidget->activateSearchWidget();
+ activateDockWidget(m_searchWindow);
+}
+
+void MainWindow::showOpenPages()
+{
+ TRACE_OBJ
+ activateDockWidget(OpenPagesManager::instance()->openPagesWidget());
}
void MainWindow::hideSearch()
{
TRACE_OBJ
- m_centralWidget->removeSearchWidget();
+ m_searchWindow->parentWidget()->hide();
}
void MainWindow::activateDockWidget(QWidget *w)
@@ -953,10 +925,7 @@ void MainWindow::setIndexString(const QString &str)
void MainWindow::activateCurrentBrowser()
{
TRACE_OBJ
- CentralWidget *cw = CentralWidget::instance();
- if (cw) {
- cw->activateTab(true);
- }
+ CentralWidget::instance()->activateTab();
}
void MainWindow::activateCurrentCentralWidgetTab()
@@ -965,12 +934,6 @@ void MainWindow::activateCurrentCentralWidgetTab()
m_centralWidget->activateTab();
}
-void MainWindow::showSearchWidget()
-{
- TRACE_OBJ
- m_centralWidget->activateSearchWidget(true);
-}
-
void MainWindow::updateApplicationFont()
{
TRACE_OBJ
@@ -1092,17 +1055,13 @@ void MainWindow::currentFilterChanged(const QString &filter)
void MainWindow::documentationRemoved(const QString &namespaceName)
{
TRACE_OBJ
- CentralWidget* widget = CentralWidget::instance();
- widget->closeOrReloadTabs(widget->currentSourceFileList().
- keys(namespaceName), false);
+ OpenPagesManager::instance()->closePages(namespaceName);
}
void MainWindow::documentationUpdated(const QString &namespaceName)
{
TRACE_OBJ
- CentralWidget* widget = CentralWidget::instance();
- widget->closeOrReloadTabs(widget->currentSourceFileList().
- keys(namespaceName), true);
+ OpenPagesManager::instance()->reloadPages(namespaceName);
}
void MainWindow::resetQtDocInfo(const QString &component)
diff --git a/tools/assistant/tools/assistant/mainwindow.h b/tools/assistant/tools/assistant/mainwindow.h
index 26726ee..9b4dbce 100644
--- a/tools/assistant/tools/assistant/mainwindow.h
+++ b/tools/assistant/tools/assistant/mainwindow.h
@@ -42,24 +42,27 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
+#include <QtCore/QList>
#include <QtCore/QUrl>
#include <QtGui/QMainWindow>
QT_BEGIN_NAMESPACE
class QAction;
+class QComboBox;
class QFileSystemWatcher;
class QLineEdit;
-class QComboBox;
class QMenu;
-class IndexWindow;
-class QHelpEngineCore;
-class QHelpEngine;
class CentralWidget;
-class ContentWindow;
class CmdLineParser;
+class ContentWindow;
+class IndexWindow;
+class OpenPagesWindow;
class QtDocInstaller;
+class QHelpEngineCore;
+class QHelpEngine;
+class SearchWidget;
class MainWindow : public QMainWindow
{
@@ -87,7 +90,6 @@ public slots:
void setIndexVisible(bool visible);
void setBookmarksVisible(bool visible);
void setSearchVisible(bool visible);
- void showSearchWidget();
void syncContents();
void activateCurrentCentralWidgetTab();
void currentFilterChanged(const QString &filter);
@@ -96,14 +98,12 @@ private slots:
void showContents();
void showIndex();
void showSearch();
+ void showOpenPages();
void insertLastPages();
void gotoAddress();
void showPreferences();
void showNewAddress();
void showAboutDialog();
- void copyAvailable(bool yes);
- void updateNavigationItems();
- void updateTabCloseAction();
void showNewAddress(const QUrl &url);
void showTopicChooser(const QMap<QString, QUrl> &links, const QString &keyword);
void updateApplicationFont();
@@ -144,20 +144,13 @@ private:
CentralWidget *m_centralWidget;
IndexWindow *m_indexWindow;
ContentWindow *m_contentWindow;
+ SearchWidget *m_searchWindow;
QLineEdit *m_addressLineEdit;
QComboBox *m_filterCombo;
- QAction *m_backAction;
- QAction *m_nextAction;
- QAction *m_homeAction;
QAction *m_syncAction;
- QAction *m_copyAction;
- QAction *m_findAction;
- QAction *m_printAction;
QAction *m_printPreviewAction;
QAction *m_pageSetupAction;
- QAction *m_zoomInAction;
- QAction *m_zoomOutAction;
QAction *m_resetZoomAction;
QAction *m_aboutAction;
QAction *m_closeTabAction;
diff --git a/tools/assistant/tools/assistant/openpagesmanager.cpp b/tools/assistant/tools/assistant/openpagesmanager.cpp
new file mode 100644
index 0000000..75b8653
--- /dev/null
+++ b/tools/assistant/tools/assistant/openpagesmanager.cpp
@@ -0,0 +1,378 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "openpagesmanager.h"
+
+#include "centralwidget.h"
+#include "helpenginewrapper.h"
+#include "helpviewer.h"
+#include "openpagesmodel.h"
+#include "openpagesswitcher.h"
+#include "openpageswidget.h"
+#include "tracer.h"
+#include "../shared/collectionconfiguration.h"
+
+#include <QtGui/QApplication>
+#include <QtGui/QTreeView>
+
+QT_BEGIN_NAMESPACE
+
+OpenPagesManager *OpenPagesManager::m_instance = 0;
+
+OpenPagesManager *OpenPagesManager::createInstance(QObject *parent,
+ bool defaultCollection, const QUrl &cmdLineUrl)
+{
+ TRACE_OBJ
+ Q_ASSERT(!m_instance);
+ m_instance = new OpenPagesManager(parent, defaultCollection, cmdLineUrl);
+ return m_instance;
+}
+
+OpenPagesManager *OpenPagesManager::instance()
+{
+ TRACE_OBJ
+ Q_ASSERT(m_instance);
+ return m_instance;
+}
+
+OpenPagesManager::OpenPagesManager(QObject *parent, bool defaultCollection,
+ const QUrl &cmdLineUrl)
+ : QObject(parent)
+ , m_model(new OpenPagesModel(this))
+ , m_openPagesWidget(0)
+ , m_openPagesSwitcher(0)
+{
+ TRACE_OBJ
+ m_openPagesWidget = new OpenPagesWidget(m_model);
+ m_openPagesWidget->setFrameStyle(QFrame::NoFrame);
+ connect(m_openPagesWidget, SIGNAL(setCurrentPage(QModelIndex)), this,
+ SLOT(setCurrentPage(QModelIndex)));
+ connect(m_openPagesWidget, SIGNAL(closePage(QModelIndex)), this,
+ SLOT(closePage(QModelIndex)));
+ connect(m_openPagesWidget, SIGNAL(closePagesExcept(QModelIndex)), this,
+ SLOT(closePagesExcept(QModelIndex)));
+
+ m_openPagesSwitcher = new OpenPagesSwitcher(m_model);
+ connect(m_openPagesSwitcher, SIGNAL(closePage(QModelIndex)), this,
+ SLOT(closePage(QModelIndex)));
+ connect(m_openPagesSwitcher, SIGNAL(setCurrentPage(QModelIndex)), this,
+ SLOT(setCurrentPage(QModelIndex)));
+
+ setupInitialPages(defaultCollection, cmdLineUrl);
+}
+
+OpenPagesManager ::~OpenPagesManager()
+{
+ TRACE_OBJ
+ m_instance = 0;
+ delete m_openPagesSwitcher;
+}
+
+int OpenPagesManager::pageCount() const
+{
+ TRACE_OBJ
+ return m_model->rowCount();
+}
+
+void OpenPagesManager::setupInitialPages(bool defaultCollection,
+ const QUrl &cmdLineUrl)
+{
+ TRACE_OBJ
+ if (cmdLineUrl.isValid()) {
+ createPage(cmdLineUrl);
+ return;
+ }
+
+ HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
+ int initialPage = 0;
+ switch (helpEngine.startOption()) {
+ case ShowHomePage:
+ m_model->addPage(helpEngine.homePage());
+ break;
+ case ShowBlankPage:
+ m_model->addPage(QUrl(QLatin1String("about:blank")));
+ break;
+ case ShowLastPages: {
+ const QStringList &lastShownPageList = helpEngine.lastShownPages();
+ const int pageCount = lastShownPageList.count();
+ if (pageCount == 0) {
+ if (defaultCollection)
+ m_model->addPage(QUrl(QLatin1String("help")));
+ else
+ m_model->addPage(QUrl(QLatin1String("about:blank")));
+ } else {
+ QStringList zoomFactors = helpEngine.lastZoomFactors();
+ while (zoomFactors.count() < pageCount)
+ zoomFactors.append(CollectionConfiguration::DefaultZoomFactor);
+ initialPage = helpEngine.lastTabPage();
+ if (initialPage >= pageCount) {
+ qWarning("Initial page set to %d, maximum possible value is %d",
+ initialPage, pageCount - 1);
+ initialPage = 0;
+ }
+ for (int curPage = 0; curPage < pageCount; ++curPage) {
+ const QString &curFile = lastShownPageList.at(curPage);
+ if (helpEngine.findFile(curFile).isValid()
+ || curFile == QLatin1String("about:blank")) {
+ m_model->addPage(curFile, zoomFactors.at(curPage).toFloat());
+ } else if (curPage <= initialPage && initialPage > 0)
+ --initialPage;
+ }
+ }
+ break;
+ }
+ default:
+ Q_ASSERT(!"Unhandled option");
+ }
+
+ if (m_model->rowCount() == 0)
+ m_model->addPage(helpEngine.homePage());
+ for (int i = 0; i < m_model->rowCount(); ++i)
+ CentralWidget::instance()->addPage(m_model->pageAt(i));
+ setCurrentPage((initialPage >= m_model->rowCount())
+ ? m_model->rowCount() - 1 : initialPage);
+ m_openPagesSwitcher->selectCurrentPage();
+}
+
+HelpViewer *OpenPagesManager::createPage()
+{
+ TRACE_OBJ
+ return createPage(QUrl(QLatin1String("about:blank")));
+}
+
+void OpenPagesManager::closeCurrentPage()
+{
+ TRACE_OBJ
+ Q_ASSERT(m_model->rowCount() > 1);
+ const QModelIndexList selectedIndexes
+ = m_openPagesWidget->selectionModel()->selectedRows();
+ if (selectedIndexes.isEmpty())
+ return;
+ Q_ASSERT(selectedIndexes.count() == 1);
+ removePage(selectedIndexes.first().row());
+}
+
+HelpViewer *OpenPagesManager::createPage(const QUrl &url, bool fromSearch)
+{
+ TRACE_OBJ
+ if (HelpViewer::launchWithExternalApp(url))
+ return 0;
+
+ m_model->addPage(url);
+ const int index = m_model->rowCount() - 1;
+ HelpViewer * const page = m_model->pageAt(index);
+ CentralWidget::instance()->addPage(page, fromSearch);
+ setCurrentPage(index);
+ return page;
+}
+
+HelpViewer *OpenPagesManager::createNewPageFromSearch(const QUrl &url)
+{
+ TRACE_OBJ
+ return createPage(url, true);
+}
+
+void OpenPagesManager::closePage(HelpViewer *viewer)
+{
+ TRACE_OBJ
+ for (int i = 0; i < m_model->rowCount(); ++i) {
+ if (m_model->pageAt(i) == viewer) {
+ removePage(i);
+ break;
+ }
+ }
+}
+
+void OpenPagesManager::closePage(const QModelIndex &index)
+{
+ TRACE_OBJ
+ if (index.isValid())
+ removePage(index.row());
+}
+
+void OpenPagesManager::closePages(const QString &nameSpace)
+{
+ TRACE_OBJ
+ closeOrReloadPages(nameSpace, false);
+}
+
+void OpenPagesManager::reloadPages(const QString &nameSpace)
+{
+ TRACE_OBJ
+ closeOrReloadPages(nameSpace, true);
+ m_openPagesWidget->selectCurrentPage();
+}
+
+void OpenPagesManager::closeOrReloadPages(const QString &nameSpace, bool tryReload)
+{
+ TRACE_OBJ
+ for (int i = m_model->rowCount() - 1; i >= 0; --i) {
+ HelpViewer *page = m_model->pageAt(i);
+ if (page->source().host() != nameSpace)
+ continue;
+ if (tryReload && HelpEngineWrapper::instance().findFile(page->source()).isValid())
+ page->reload();
+ else if (m_model->rowCount() == 1)
+ page->setSource(QUrl(QLatin1String("about:blank")));
+ else
+ removePage(i);
+ }
+}
+
+bool OpenPagesManager::pagesOpenForNamespace(const QString &nameSpace) const
+{
+ TRACE_OBJ
+ for (int i = 0; i < m_model->rowCount(); ++i)
+ if (m_model->pageAt(i)->source().host() == nameSpace)
+ return true;
+ return false;
+}
+
+void OpenPagesManager::setCurrentPage(const QModelIndex &index)
+{
+ TRACE_OBJ
+ if (index.isValid())
+ setCurrentPage(index.row());
+}
+
+void OpenPagesManager::setCurrentPage(int index)
+{
+ TRACE_OBJ
+ setCurrentPage(m_model->pageAt(index));
+}
+
+void OpenPagesManager::setCurrentPage(HelpViewer *page)
+{
+ TRACE_OBJ
+ CentralWidget::instance()->setCurrentPage(page);
+ m_openPagesWidget->selectCurrentPage();
+}
+
+void OpenPagesManager::removePage(int index)
+{
+ TRACE_OBJ
+ CentralWidget::instance()->removePage(index);
+ m_model->removePage(index);
+ m_openPagesWidget->selectCurrentPage();
+}
+
+
+void OpenPagesManager::closePagesExcept(const QModelIndex &index)
+{
+ TRACE_OBJ
+ if (!index.isValid())
+ return;
+
+ int i = 0;
+ HelpViewer *viewer = m_model->pageAt(index.row());
+ while (m_model->rowCount() > 1) {
+ if (m_model->pageAt(i) != viewer)
+ removePage(i);
+ else
+ ++i;
+ }
+}
+
+QAbstractItemView *OpenPagesManager::openPagesWidget() const
+{
+ TRACE_OBJ
+ return m_openPagesWidget;
+}
+
+void OpenPagesManager::nextPage()
+{
+ TRACE_OBJ
+ nextOrPreviousPage(1);
+}
+
+void OpenPagesManager::nextPageWithSwitcher()
+{
+ TRACE_OBJ
+ if (!m_openPagesSwitcher->isVisible()) {
+ m_openPagesSwitcher->selectCurrentPage();
+ m_openPagesSwitcher->gotoNextPage();
+ showSwitcherOrSelectPage();
+ } else {
+ m_openPagesSwitcher->gotoNextPage();
+ }
+}
+
+void OpenPagesManager::previousPage()
+{
+ TRACE_OBJ
+ nextOrPreviousPage(-1);
+}
+
+void OpenPagesManager::previousPageWithSwitcher()
+{
+ TRACE_OBJ
+ if (!m_openPagesSwitcher->isVisible()) {
+ m_openPagesSwitcher->selectCurrentPage();
+ m_openPagesSwitcher->gotoPreviousPage();
+ showSwitcherOrSelectPage();
+ } else {
+ m_openPagesSwitcher->gotoPreviousPage();
+ }
+}
+
+void OpenPagesManager::nextOrPreviousPage(int offset)
+{
+ TRACE_OBJ
+ setCurrentPage((CentralWidget::instance()->currentIndex() + offset
+ + m_model->rowCount()) % m_model->rowCount());
+}
+
+void OpenPagesManager::showSwitcherOrSelectPage() const
+{
+ TRACE_OBJ
+ if (QApplication::keyboardModifiers() != Qt::NoModifier) {
+ const int width = CentralWidget::instance()->width();
+ const int height = CentralWidget::instance()->height();
+ const QPoint p(CentralWidget::instance()->mapToGlobal(QPoint(0, 0)));
+ m_openPagesSwitcher->move((width - m_openPagesSwitcher->width()) / 2 + p.x(),
+ (height - m_openPagesSwitcher->height()) / 2 + p.y());
+ m_openPagesSwitcher->setVisible(true);
+ } else {
+ m_openPagesSwitcher->selectAndHide();
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/openpagesmanager.h b/tools/assistant/tools/assistant/openpagesmanager.h
new file mode 100644
index 0000000..5837392
--- /dev/null
+++ b/tools/assistant/tools/assistant/openpagesmanager.h
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef OPENPAGESMANAGER_H
+#define OPENPAGESMANAGER_H
+
+#include <QtCore/QObject>
+
+QT_BEGIN_NAMESPACE
+
+class QAbstractItemView;
+class QModelIndex;
+class QUrl;
+
+class HelpViewer;
+class OpenPagesModel;
+class OpenPagesSwitcher;
+class OpenPagesWidget;
+
+class OpenPagesManager : public QObject
+{
+ Q_OBJECT
+public:
+ static OpenPagesManager *createInstance(QObject *parent,
+ bool defaultCollection, const QUrl &cmdLineUrl);
+ static OpenPagesManager *instance();
+
+ bool pagesOpenForNamespace(const QString &nameSpace) const;
+ void closePages(const QString &nameSpace);
+ void reloadPages(const QString &nameSpace);
+
+ QAbstractItemView* openPagesWidget() const;
+
+ int pageCount() const;
+ void setCurrentPage(int index);
+
+public slots:
+ HelpViewer *createPage(const QUrl &url, bool fromSearch = false);
+ HelpViewer *createNewPageFromSearch(const QUrl &url);
+ HelpViewer *createPage();
+ void closeCurrentPage();
+
+ void nextPage();
+ void nextPageWithSwitcher();
+ void previousPage();
+ void previousPageWithSwitcher();
+
+ void closePage(HelpViewer *page);
+ void setCurrentPage(HelpViewer *page);
+
+private slots:
+ void setCurrentPage(const QModelIndex &index);
+ void closePage(const QModelIndex &index);
+ void closePagesExcept(const QModelIndex &index);
+
+private:
+ OpenPagesManager(QObject *parent, bool defaultCollection,
+ const QUrl &cmdLineUrl);
+ ~OpenPagesManager();
+
+ void setupInitialPages(bool defaultCollection, const QUrl &cmdLineUrl);
+ void closeOrReloadPages(const QString &nameSpace, bool tryReload);
+ void removePage(int index);
+
+ void nextOrPreviousPage(int offset);
+ void showSwitcherOrSelectPage() const;
+
+ OpenPagesModel *m_model;
+ OpenPagesWidget *m_openPagesWidget;
+ OpenPagesSwitcher *m_openPagesSwitcher;
+
+ static OpenPagesManager *m_instance;
+};
+
+QT_END_NAMESPACE
+
+#endif // OPENPAGESMANAGER_H
diff --git a/tools/assistant/tools/assistant/openpagesmodel.cpp b/tools/assistant/tools/assistant/openpagesmodel.cpp
new file mode 100644
index 0000000..2663b85
--- /dev/null
+++ b/tools/assistant/tools/assistant/openpagesmodel.cpp
@@ -0,0 +1,119 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "openpagesmodel.h"
+
+#include "helpenginewrapper.h"
+#include "helpviewer.h"
+#include "tracer.h"
+
+#include <QtCore/QStringList>
+#include <QtCore/QUrl>
+
+QT_BEGIN_NAMESPACE
+
+OpenPagesModel::OpenPagesModel(QObject *parent) : QAbstractTableModel(parent)
+{
+ TRACE_OBJ
+}
+
+int OpenPagesModel::rowCount(const QModelIndex &parent) const
+{
+ TRACE_OBJ
+ return parent.isValid() ? 0 : m_pages.count();
+}
+
+int OpenPagesModel::columnCount(const QModelIndex &/*parent*/) const
+{
+ TRACE_OBJ
+ return 2;
+}
+
+QVariant OpenPagesModel::data(const QModelIndex &index, int role) const
+{
+ TRACE_OBJ
+ if (!index.isValid() || index.row() >= rowCount() || index.column() > 0
+ || role != Qt::DisplayRole)
+ return QVariant();
+ QString title = m_pages.at(index.row())->title();
+ title.replace(QLatin1Char('&'), QLatin1String("&&"));
+ return title.isEmpty() ? QLatin1String("(Untitled)") : title;
+}
+
+void OpenPagesModel::addPage(const QUrl &url, qreal zoom)
+{
+ TRACE_OBJ
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ HelpViewer *page = new HelpViewer(zoom);
+ connect(page, SIGNAL(titleChanged()), this, SLOT(handleTitleChanged()));
+ m_pages << page;
+ endInsertRows();
+ page->setSource(url);
+}
+
+void OpenPagesModel::removePage(int index)
+{
+ TRACE_OBJ
+ Q_ASSERT(index >= 0 && index < rowCount());
+ beginRemoveRows(QModelIndex(), index, index);
+ HelpViewer *page = m_pages.at(index);
+ m_pages.removeAt(index);
+ endRemoveRows();
+ page->deleteLater();
+}
+
+HelpViewer *OpenPagesModel::pageAt(int index) const
+{
+ TRACE_OBJ
+ Q_ASSERT(index >= 0 && index < rowCount());
+ return m_pages.at(index);
+}
+
+void OpenPagesModel::handleTitleChanged()
+{
+ TRACE_OBJ
+ HelpViewer *page = static_cast<HelpViewer *>(sender());
+ const int row = m_pages.indexOf(page);
+ Q_ASSERT(row != -1 );
+ const QModelIndex &item = index(row, 0);
+ emit dataChanged(item, item);
+}
+
+QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/openpagesmodel.h b/tools/assistant/tools/assistant/openpagesmodel.h
new file mode 100644
index 0000000..64013a6
--- /dev/null
+++ b/tools/assistant/tools/assistant/openpagesmodel.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef OPENPAGESMODEL_H
+#define OPENPAGESMODEL_H
+
+#include <QtCore/QAbstractTableModel>
+#include <QtCore/QList>
+
+QT_BEGIN_NAMESPACE
+
+class HelpViewer;
+class QUrl;
+
+class OpenPagesModel : public QAbstractTableModel
+{
+ Q_OBJECT
+public:
+ OpenPagesModel(QObject *parent);
+
+ virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+
+ void addPage(const QUrl &url, qreal zoom = 0);
+ void removePage(int index);
+ HelpViewer *pageAt(int index) const;
+
+private slots:
+ void handleTitleChanged();
+
+private:
+ QList<HelpViewer *> m_pages;
+};
+
+QT_END_NAMESPACE
+
+#endif // OPENPAGESMODEL_H
diff --git a/tools/assistant/tools/assistant/openpagesswitcher.cpp b/tools/assistant/tools/assistant/openpagesswitcher.cpp
new file mode 100644
index 0000000..d4b7d82
--- /dev/null
+++ b/tools/assistant/tools/assistant/openpagesswitcher.cpp
@@ -0,0 +1,194 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "openpagesswitcher.h"
+
+#include "centralwidget.h"
+#include "openpagesmodel.h"
+#include "openpageswidget.h"
+#include "tracer.h"
+
+#include <QtCore/QEvent>
+
+#include <QtGui/QKeyEvent>
+#include <QtGui/QVBoxLayout>
+
+QT_BEGIN_NAMESPACE
+
+const int gWidth = 300;
+const int gHeight = 200;
+
+OpenPagesSwitcher::OpenPagesSwitcher(OpenPagesModel *model)
+ : QFrame(0, Qt::Popup)
+ , m_openPagesModel(model)
+{
+ TRACE_OBJ
+ resize(gWidth, gHeight);
+
+ m_openPagesWidget = new OpenPagesWidget(m_openPagesModel);
+
+ // We disable the frame on this list view and use a QFrame around it instead.
+ // This improves the look with QGTKStyle.
+#ifndef Q_WS_MAC
+ setFrameStyle(m_openPagesWidget->frameStyle());
+#endif
+ m_openPagesWidget->setFrameStyle(QFrame::NoFrame);
+
+ m_openPagesWidget->allowContextMenu(false);
+ m_openPagesWidget->installEventFilter(this);
+
+ QVBoxLayout *layout = new QVBoxLayout(this);
+ layout->setMargin(0);
+ layout->addWidget(m_openPagesWidget);
+
+ connect(m_openPagesWidget, SIGNAL(closePage(QModelIndex)), this,
+ SIGNAL(closePage(QModelIndex)));
+ connect(m_openPagesWidget, SIGNAL(setCurrentPage(QModelIndex)), this,
+ SIGNAL(setCurrentPage(QModelIndex)));
+}
+
+OpenPagesSwitcher::~OpenPagesSwitcher()
+{
+ TRACE_OBJ
+}
+
+void OpenPagesSwitcher::gotoNextPage()
+{
+ TRACE_OBJ
+ selectPageUpDown(1);
+}
+
+void OpenPagesSwitcher::gotoPreviousPage()
+{
+ TRACE_OBJ
+ selectPageUpDown(-1);
+}
+
+void OpenPagesSwitcher::selectAndHide()
+{
+ TRACE_OBJ
+ setVisible(false);
+ emit setCurrentPage(m_openPagesWidget->currentIndex());
+}
+
+void OpenPagesSwitcher::selectCurrentPage()
+{
+ TRACE_OBJ
+ m_openPagesWidget->selectCurrentPage();
+}
+
+void OpenPagesSwitcher::setVisible(bool visible)
+{
+ TRACE_OBJ
+ QWidget::setVisible(visible);
+ if (visible)
+ setFocus();
+}
+
+void OpenPagesSwitcher::focusInEvent(QFocusEvent *event)
+{
+ TRACE_OBJ
+ Q_UNUSED(event)
+ m_openPagesWidget->setFocus();
+}
+
+bool OpenPagesSwitcher::eventFilter(QObject *object, QEvent *event)
+{
+ TRACE_OBJ
+ if (object == m_openPagesWidget) {
+ if (event->type() == QEvent::KeyPress) {
+ QKeyEvent *ke = static_cast<QKeyEvent*>(event);
+ if (ke->key() == Qt::Key_Escape) {
+ setVisible(false);
+ return true;
+ }
+
+ const int key = ke->key();
+ if (key == Qt::Key_Return || key == Qt::Key_Enter || key == Qt::Key_Space) {
+ emit setCurrentPage(m_openPagesWidget->currentIndex());
+ return true;
+ }
+
+ Qt::KeyboardModifier modifier = Qt::ControlModifier;
+#ifdef Q_WS_MAC
+ modifier = Qt::AltModifier;
+#endif
+ if (key == Qt::Key_Backtab
+ && (ke->modifiers() == (modifier | Qt::ShiftModifier)))
+ gotoPreviousPage();
+ else if (key == Qt::Key_Tab && (ke->modifiers() == modifier))
+ gotoNextPage();
+ } else if (event->type() == QEvent::KeyRelease) {
+ QKeyEvent *ke = static_cast<QKeyEvent*>(event);
+ if (ke->modifiers() == 0
+ /*HACK this is to overcome some event inconsistencies between platforms*/
+ || (ke->modifiers() == Qt::AltModifier
+ && (ke->key() == Qt::Key_Alt || ke->key() == -1))) {
+ selectAndHide();
+ }
+ }
+ }
+ return QWidget::eventFilter(object, event);
+}
+
+void OpenPagesSwitcher::selectPageUpDown(int summand)
+{
+ TRACE_OBJ
+ const int pageCount = m_openPagesModel->rowCount();
+ if (pageCount < 2)
+ return;
+
+ const QModelIndexList &list = m_openPagesWidget->selectionModel()->selectedIndexes();
+ if (list.isEmpty())
+ return;
+
+ QModelIndex index = list.first();
+ if (!index.isValid())
+ return;
+
+ index = m_openPagesModel->index((index.row() + summand + pageCount) % pageCount, 0);
+ if (index.isValid()) {
+ m_openPagesWidget->setCurrentIndex(index);
+ m_openPagesWidget->scrollTo(index, QAbstractItemView::PositionAtCenter);
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/openpagesswitcher.h b/tools/assistant/tools/assistant/openpagesswitcher.h
new file mode 100644
index 0000000..e27db6b
--- /dev/null
+++ b/tools/assistant/tools/assistant/openpagesswitcher.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef OPENPAGESSWITCHER_H
+#define OPENPAGESSWITCHER_H
+
+#include <QtGui/QFrame>
+
+QT_BEGIN_NAMESPACE
+
+class OpenPagesModel;
+class OpenPagesWidget;
+class QModelIndex;
+
+class OpenPagesSwitcher : public QFrame
+{
+ Q_OBJECT
+
+public:
+ OpenPagesSwitcher(OpenPagesModel *model);
+ ~OpenPagesSwitcher();
+
+ void gotoNextPage();
+ void gotoPreviousPage();
+
+ void selectAndHide();
+ void selectCurrentPage();
+
+ void setVisible(bool visible);
+ void focusInEvent(QFocusEvent *event);
+ bool eventFilter(QObject *object, QEvent *event);
+
+signals:
+ void closePage(const QModelIndex &index);
+ void setCurrentPage(const QModelIndex &index);
+
+private:
+ void selectPageUpDown(int summand);
+
+private:
+ OpenPagesModel *m_openPagesModel;
+ OpenPagesWidget *m_openPagesWidget;
+};
+
+QT_END_NAMESPACE
+
+#endif // OPENPAGESSWITCHER_H
diff --git a/tools/assistant/tools/assistant/openpageswidget.cpp b/tools/assistant/tools/assistant/openpageswidget.cpp
new file mode 100644
index 0000000..b7ac33e
--- /dev/null
+++ b/tools/assistant/tools/assistant/openpageswidget.cpp
@@ -0,0 +1,237 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "openpageswidget.h"
+
+#include "centralwidget.h"
+#include "openpagesmodel.h"
+#include "tracer.h"
+
+#include <QtGui/QApplication>
+#include <QtGui/QHeaderView>
+#include <QtGui/QKeyEvent>
+#include <QtGui/QMouseEvent>
+#include <QtGui/QMenu>
+#include <QtGui/QPainter>
+
+#ifdef Q_WS_MAC
+#include <qmacstyle_mac.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+OpenPagesDelegate::OpenPagesDelegate(QObject *parent)
+ : QStyledItemDelegate(parent)
+{
+ TRACE_OBJ
+}
+
+void OpenPagesDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+ TRACE_OBJ
+ if (option.state & QStyle::State_MouseOver) {
+ if ((QApplication::mouseButtons() & Qt::LeftButton) == 0)
+ pressedIndex = QModelIndex();
+ QBrush brush = option.palette.alternateBase();
+ if (index == pressedIndex)
+ brush = option.palette.dark();
+ painter->fillRect(option.rect, brush);
+ }
+
+ QStyledItemDelegate::paint(painter, option, index);
+
+ if (index.column() == 1 && index.model()->rowCount() > 1
+ && option.state & QStyle::State_MouseOver) {
+ QIcon icon((option.state & QStyle::State_Selected)
+ ? ":/trolltech/assistant/images/closebutton.png"
+ : ":/trolltech/assistant/images/darkclosebutton.png");
+
+ const QRect iconRect(option.rect.right() - option.rect.height(),
+ option.rect.top(), option.rect.height(), option.rect.height());
+ icon.paint(painter, iconRect, Qt::AlignRight | Qt::AlignVCenter);
+ }
+}
+
+// -- OpenPagesWidget
+
+OpenPagesWidget::OpenPagesWidget(OpenPagesModel *model)
+ : m_allowContextMenu(true)
+{
+ TRACE_OBJ
+ setModel(model);
+ setIndentation(0);
+ setItemDelegate((m_delegate = new OpenPagesDelegate(this)));
+
+ setTextElideMode(Qt::ElideMiddle);
+ setAttribute(Qt::WA_MacShowFocusRect, false);
+
+ viewport()->setAttribute(Qt::WA_Hover);
+ setSelectionBehavior(QAbstractItemView::SelectRows);
+ setSelectionMode(QAbstractItemView::SingleSelection);
+
+ header()->hide();
+ header()->setStretchLastSection(false);
+ header()->setResizeMode(0, QHeaderView::Stretch);
+ header()->setResizeMode(1, QHeaderView::Fixed);
+ header()->resizeSection(1, 18);
+
+ installEventFilter(this);
+ setUniformRowHeights(true);
+ setContextMenuPolicy(Qt::CustomContextMenu);
+
+ connect(this, SIGNAL(clicked(QModelIndex)), this,
+ SLOT(handleClicked(QModelIndex)));
+ connect(this, SIGNAL(pressed(QModelIndex)), this,
+ SLOT(handlePressed(QModelIndex)));
+ connect(this, SIGNAL(customContextMenuRequested(QPoint)), this,
+ SLOT(contextMenuRequested(QPoint)));
+}
+
+OpenPagesWidget::~OpenPagesWidget()
+{
+ TRACE_OBJ
+}
+
+void OpenPagesWidget::selectCurrentPage()
+{
+ TRACE_OBJ
+ const QModelIndex &current =
+ model()->index(CentralWidget::instance()->currentIndex(), 0);
+
+ QItemSelectionModel * const selModel = selectionModel();
+ selModel->select(current,
+ QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
+ selModel->clearSelection();
+
+ setCurrentIndex(current);
+ scrollTo(currentIndex());
+}
+
+void OpenPagesWidget::allowContextMenu(bool ok)
+{
+ TRACE_OBJ
+ m_allowContextMenu = ok;
+}
+
+void OpenPagesWidget::contextMenuRequested(QPoint pos)
+{
+ TRACE_OBJ
+ QModelIndex index = indexAt(pos);
+ if (!index.isValid() || !m_allowContextMenu)
+ return;
+
+ if (index.column() == 1)
+ index = index.sibling(index.row(), 0);
+ QMenu contextMenu;
+ QAction *closeEditor = contextMenu.addAction(tr("Close %1").arg(index.data()
+ .toString()));
+ QAction *closeOtherEditors = contextMenu.addAction(tr("Close All Except %1")
+ .arg(index.data().toString()));
+
+ if (model()->rowCount() == 1) {
+ closeEditor->setEnabled(false);
+ closeOtherEditors->setEnabled(false);
+ }
+
+ QAction *action = contextMenu.exec(mapToGlobal(pos));
+ if (action == closeEditor)
+ emit closePage(index);
+ else if (action == closeOtherEditors)
+ emit closePagesExcept(index);
+}
+
+void OpenPagesWidget::handlePressed(const QModelIndex &index)
+{
+ TRACE_OBJ
+ if (index.column() == 0)
+ emit setCurrentPage(index);
+
+ if (index.column() == 1)
+ m_delegate->pressedIndex = index;
+}
+
+void OpenPagesWidget::handleClicked(const QModelIndex &index)
+{
+ TRACE_OBJ
+ // implemented here to handle the funky close button and to work around a
+ // bug in item views where the delegate wouldn't get the QStyle::State_MouseOver
+ if (index.column() == 1) {
+ if (model()->rowCount() > 1)
+ emit closePage(index);
+
+ QWidget *vp = viewport();
+ const QPoint &cursorPos = QCursor::pos();
+ QMouseEvent e(QEvent::MouseMove, vp->mapFromGlobal(cursorPos), cursorPos,
+ Qt::NoButton, 0, 0);
+ QCoreApplication::sendEvent(vp, &e);
+ }
+}
+
+bool OpenPagesWidget::eventFilter(QObject *obj, QEvent *event)
+{
+ TRACE_OBJ
+ if (obj != this)
+ return QWidget::eventFilter(obj, event);
+
+ if (event->type() == QEvent::KeyPress) {
+ QKeyEvent *ke = static_cast<QKeyEvent*>(event);
+ if (currentIndex().isValid() && ke->modifiers() == 0) {
+ const int key = ke->key();
+ if (key == Qt::Key_Return || key == Qt::Key_Enter
+ || key == Qt::Key_Space) {
+ emit setCurrentPage(currentIndex());
+ } else if ((key == Qt::Key_Delete || key == Qt::Key_Backspace)
+ && model()->rowCount() > 1) {
+ emit closePage(currentIndex());
+ }
+ }
+ } else if (event->type() == QEvent::KeyRelease) {
+ QKeyEvent *ke = static_cast<QKeyEvent*>(event);
+ if (ke->modifiers() == 0
+ && (ke->key() == Qt::Key_Up || ke->key() == Qt::Key_Down)) {
+ emit setCurrentPage(currentIndex());
+ }
+ }
+ return QWidget::eventFilter(obj, event);
+}
+
+QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/openpageswidget.h b/tools/assistant/tools/assistant/openpageswidget.h
new file mode 100644
index 0000000..4b972f3
--- /dev/null
+++ b/tools/assistant/tools/assistant/openpageswidget.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef OPENPAGESWIDGET_H
+#define OPENPAGESWIDGET_H
+
+#include <QtGui/QStyledItemDelegate>
+#include <QtGui/QTreeView>
+
+QT_BEGIN_NAMESPACE
+
+class OpenPagesModel;
+
+class OpenPagesDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+public:
+ explicit OpenPagesDelegate(QObject *parent = 0);
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const;
+
+ mutable QModelIndex pressedIndex;
+};
+
+class OpenPagesWidget : public QTreeView
+{
+ Q_OBJECT
+public:
+ OpenPagesWidget(OpenPagesModel *model);
+ ~OpenPagesWidget();
+
+ void selectCurrentPage();
+ void allowContextMenu(bool ok);
+
+signals:
+ void setCurrentPage(const QModelIndex &index);
+ void closePage(const QModelIndex &index);
+ void closePagesExcept(const QModelIndex &index);
+
+private slots:
+ void contextMenuRequested(QPoint pos);
+ void handlePressed(const QModelIndex &index);
+ void handleClicked(const QModelIndex &index);
+
+private:
+ bool eventFilter(QObject *obj, QEvent *event);
+
+ bool m_allowContextMenu;
+ OpenPagesDelegate *m_delegate;
+};
+
+QT_END_NAMESPACE
+
+#endif // OPENPAGESWIDGET_H
diff --git a/tools/assistant/tools/assistant/preferencesdialog.cpp b/tools/assistant/tools/assistant/preferencesdialog.cpp
index 0e1d719..495dad9 100644
--- a/tools/assistant/tools/assistant/preferencesdialog.cpp
+++ b/tools/assistant/tools/assistant/preferencesdialog.cpp
@@ -45,6 +45,7 @@
#include "fontpanel.h"
#include "helpenginewrapper.h"
#include "installdialog.h"
+#include "openpagesmanager.h"
#include "tracer.h"
#include <QtCore/QtAlgorithms>
@@ -302,15 +303,12 @@ void PreferencesDialog::addDocumentationLocal()
void PreferencesDialog::removeDocumentation()
{
TRACE_OBJ
- bool foundBefore = false;
- CentralWidget* widget = CentralWidget::instance();
- QMap<int, QString> openedDocList = widget->currentSourceFileList();
- QStringList values(openedDocList.values());
+ bool foundBefore = false;
QList<QListWidgetItem*> l = m_ui.registeredDocsListWidget->selectedItems();
foreach (QListWidgetItem* item, l) {
const QString& ns = item->text();
- if (!foundBefore && values.contains(ns)) {
+ if (!foundBefore && OpenPagesManager::instance()->pagesOpenForNamespace(ns)) {
if (0 == QMessageBox::information(this, tr("Remove Documentation"),
tr("Some documents currently opened in Assistant reference the "
"documentation you are attempting to remove. Removing the "
@@ -320,7 +318,6 @@ void PreferencesDialog::removeDocumentation()
}
m_unregDocs.append(ns);
- m_TabsToClose += openedDocList.keys(ns);
delete m_ui.registeredDocsListWidget->takeItem(
m_ui.registeredDocsListWidget->row(item));
}
@@ -374,14 +371,18 @@ void PreferencesDialog::applyChanges()
}
}
- CentralWidget::instance()->closeOrReloadTabs(m_TabsToClose, false);
-
- foreach (const QString &doc, m_unregDocs)
+ foreach (const QString &doc, m_unregDocs) {
+ OpenPagesManager::instance()->closePages(doc);
helpEngine.unregisterDocumentation(doc);
+ }
if (filtersWereChanged || !m_regDocs.isEmpty() || !m_unregDocs.isEmpty())
helpEngine.setupData();
+ helpEngine.setShowTabs(m_ui.showTabs->isChecked());
+ if (m_showTabs != m_ui.showTabs->isChecked())
+ emit updateUserInterface();
+
accept();
}
@@ -424,13 +425,13 @@ void PreferencesDialog::updateFontSettingsPage()
connect(m_browserFontPanel, SIGNAL(toggled(bool)), this,
SLOT(browserFontSettingToggled(bool)));
- QList<QComboBox*> allCombos = qFindChildren<QComboBox*>(m_appFontPanel);
+ QList<QComboBox*> allCombos = m_appFontPanel->findChildren<QComboBox*>();
foreach (QComboBox* box, allCombos) {
connect(box, SIGNAL(currentIndexChanged(int)), this,
SLOT(appFontSettingChanged(int)));
}
- allCombos = qFindChildren<QComboBox*>(m_browserFontPanel);
+ allCombos = m_browserFontPanel->findChildren<QComboBox*>();
foreach (QComboBox* box, allCombos) {
connect(box, SIGNAL(currentIndexChanged(int)), this,
SLOT(browserFontSettingChanged(int)));
@@ -473,6 +474,9 @@ void PreferencesDialog::updateOptionsPage()
int option = helpEngine.startOption();
m_ui.helpStartComboBox->setCurrentIndex(option);
+ m_showTabs = helpEngine.showTabs();
+ m_ui.showTabs->setChecked(m_showTabs);
+
connect(m_ui.blankPageButton, SIGNAL(clicked()), this, SLOT(setBlankPage()));
connect(m_ui.currentPageButton, SIGNAL(clicked()), this, SLOT(setCurrentPage()));
connect(m_ui.defaultPageButton, SIGNAL(clicked()), this, SLOT(setDefaultPage()));
diff --git a/tools/assistant/tools/assistant/preferencesdialog.h b/tools/assistant/tools/assistant/preferencesdialog.h
index 2894494..22cf8c9 100644
--- a/tools/assistant/tools/assistant/preferencesdialog.h
+++ b/tools/assistant/tools/assistant/preferencesdialog.h
@@ -81,6 +81,7 @@ private slots:
signals:
void updateBrowserFont();
void updateApplicationFont();
+ void updateUserInterface();
private:
void updateFilterPage();
@@ -96,12 +97,12 @@ private:
QStringList m_docsBackup;
QStringList m_regDocs;
QStringList m_unregDocs;
- QList<int> m_TabsToClose;
FontPanel *m_appFontPanel;
FontPanel *m_browserFontPanel;
bool m_appFontChanged;
bool m_browserFontChanged;
HelpEngineWrapper &helpEngine;
+ bool m_showTabs;
};
QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/preferencesdialog.ui b/tools/assistant/tools/assistant/preferencesdialog.ui
index 279084d..1c6833a 100644
--- a/tools/assistant/tools/assistant/preferencesdialog.ui
+++ b/tools/assistant/tools/assistant/preferencesdialog.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>375</width>
- <height>266</height>
+ <height>275</height>
</rect>
</property>
<property name="windowTitle">
@@ -187,7 +187,7 @@
<attribute name="title">
<string>Options</string>
</attribute>
- <layout class="QVBoxLayout" name="verticalLayout_2">
+ <layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
@@ -310,6 +310,22 @@
</widget>
</item>
<item>
+ <widget class="QGroupBox" name="groupBox_3">
+ <property name="title">
+ <string>Appearance</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QCheckBox" name="showTabs">
+ <property name="text">
+ <string>Show tabs for each individual page</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
diff --git a/tools/assistant/tools/assistant/remotecontrol.cpp b/tools/assistant/tools/assistant/remotecontrol.cpp
index 5ecdd69..51bc733 100644
--- a/tools/assistant/tools/assistant/remotecontrol.cpp
+++ b/tools/assistant/tools/assistant/remotecontrol.cpp
@@ -38,12 +38,13 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "tracer.h"
-
#include "remotecontrol.h"
-#include "mainwindow.h"
+
#include "centralwidget.h"
#include "helpenginewrapper.h"
+#include "mainwindow.h"
+#include "openpagesmanager.h"
+#include "tracer.h"
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
@@ -57,6 +58,7 @@
#include <QtHelp/QHelpEngine>
#include <QtHelp/QHelpIndexWidget>
+#include <QtHelp/QHelpSearchQueryWidget>
#ifdef Q_OS_WIN
# include "remotecontrol_win.h"
@@ -259,8 +261,25 @@ void RemoteControl::handleActivateKeywordCommand(const QString &arg)
m_activateKeyword = arg;
} else {
m_mainWindow->setIndexString(arg);
- if (!arg.isEmpty())
- helpEngine.indexWidget()->activateCurrentItem();
+ if (!arg.isEmpty()) {
+ if (!helpEngine.indexWidget()->currentIndex().isValid()
+ && helpEngine.fullTextSearchFallbackEnabled()) {
+ if (QHelpSearchEngine *se = helpEngine.searchEngine()) {
+ m_mainWindow->setSearchVisible(true);
+ if (QHelpSearchQueryWidget *w = se->queryWidget()) {
+ w->collapseExtendedSearch();
+ QList<QHelpSearchQuery> queryList;
+ queryList << QHelpSearchQuery(QHelpSearchQuery::DEFAULT,
+ QStringList(arg));
+ w->setQuery(queryList);
+ se->search(queryList);
+ }
+ }
+ } else {
+ m_mainWindow->setIndexVisible(true);
+ helpEngine.indexWidget()->activateCurrentItem();
+ }
+ }
}
}
@@ -323,8 +342,7 @@ void RemoteControl::handleUnregisterCommand(const QString &arg)
const QString &absFileName = QFileInfo(arg).absoluteFilePath();
const QString &ns = QHelpEngineCore::namespaceName(absFileName);
if (helpEngine.registeredDocumentations().contains(ns)) {
- CentralWidget* widget = CentralWidget::instance();
- widget->closeOrReloadTabs(widget->currentSourceFileList().keys(ns), false);
+ OpenPagesManager::instance()->closePages(ns);
if (helpEngine.unregisterDocumentation(ns))
helpEngine.setupData();
}
diff --git a/tools/assistant/tools/assistant/searchwidget.cpp b/tools/assistant/tools/assistant/searchwidget.cpp
index d83790d..bb5bdeb 100644
--- a/tools/assistant/tools/assistant/searchwidget.cpp
+++ b/tools/assistant/tools/assistant/searchwidget.cpp
@@ -63,7 +63,6 @@ QT_BEGIN_NAMESPACE
SearchWidget::SearchWidget(QHelpSearchEngine *engine, QWidget *parent)
: QWidget(parent)
, zoomCount(0)
- , attached(false)
, searchEngine(engine)
{
TRACE_OBJ
@@ -86,7 +85,7 @@ SearchWidget::SearchWidget(QHelpSearchEngine *engine, QWidget *parent)
connect(searchEngine, SIGNAL(searchingFinished(int)), this,
SLOT(searchingFinished(int)));
- QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
+ QTextBrowser* browser = resultWidget->findChild<QTextBrowser*>();
if (browser) // Will be null if lib was configured not to use CLucene.
browser->viewport()->installEventFilter(this);
}
@@ -100,7 +99,7 @@ SearchWidget::~SearchWidget()
void SearchWidget::zoomIn()
{
TRACE_OBJ
- QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
+ QTextBrowser* browser = resultWidget->findChild<QTextBrowser*>();
if (browser && zoomCount != 10) {
zoomCount++;
browser->zoomIn();
@@ -110,7 +109,7 @@ void SearchWidget::zoomIn()
void SearchWidget::zoomOut()
{
TRACE_OBJ
- QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
+ QTextBrowser* browser = resultWidget->findChild<QTextBrowser*>();
if (browser && zoomCount != -5) {
zoomCount--;
browser->zoomOut();
@@ -123,25 +122,13 @@ void SearchWidget::resetZoom()
if (zoomCount == 0)
return;
- QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
+ QTextBrowser* browser = resultWidget->findChild<QTextBrowser*>();
if (browser) {
browser->zoomOut(zoomCount);
zoomCount = 0;
}
}
-bool SearchWidget::isAttached() const
-{
- TRACE_OBJ
- return attached;
-}
-
-void SearchWidget::setAttached(bool state)
-{
- TRACE_OBJ
- attached = state;
-}
-
void SearchWidget::search() const
{
TRACE_OBJ
@@ -165,7 +152,7 @@ void SearchWidget::searchingFinished(int hits)
bool SearchWidget::eventFilter(QObject* o, QEvent *e)
{
TRACE_OBJ
- QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
+ QTextBrowser* browser = resultWidget->findChild<QTextBrowser*>();
if (browser && o == browser->viewport()
&& e->type() == QEvent::MouseButtonRelease){
QMouseEvent *me = static_cast<QMouseEvent*>(e);
@@ -196,7 +183,7 @@ void SearchWidget::contextMenuEvent(QContextMenuEvent *contextMenuEvent)
QMenu menu;
QPoint point = contextMenuEvent->globalPos();
- QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
+ QTextBrowser* browser = resultWidget->findChild<QTextBrowser*>();
if (!browser)
return;
diff --git a/tools/assistant/tools/assistant/searchwidget.h b/tools/assistant/tools/assistant/searchwidget.h
index 750497b..04d3e28 100644
--- a/tools/assistant/tools/assistant/searchwidget.h
+++ b/tools/assistant/tools/assistant/searchwidget.h
@@ -65,9 +65,6 @@ public:
void zoomOut();
void resetZoom();
- bool isAttached() const;
- void setAttached(bool state);
-
signals:
void requestShowLink(const QUrl &url);
void requestShowLinkInNewTab(const QUrl &url);
@@ -84,7 +81,6 @@ private:
private:
int zoomCount;
- bool attached;
QHelpSearchEngine *searchEngine;
QHelpSearchResultWidget *resultWidget;
};
diff --git a/tools/assistant/tools/qcollectiongenerator/main.cpp b/tools/assistant/tools/qcollectiongenerator/main.cpp
index fc9dc67..7abbad1 100644
--- a/tools/assistant/tools/qcollectiongenerator/main.cpp
+++ b/tools/assistant/tools/qcollectiongenerator/main.cpp
@@ -97,6 +97,10 @@ public:
QString cacheDirectory() const { return m_cacheDirectory; }
bool cacheDirRelativeToCollection() const { return m_cacheDirRelativeToCollection; }
+ bool fullTextSearchFallbackEnabled() const {
+ return m_enableFullTextSearchFallback;
+ }
+
private:
void raiseErrorWithLine();
void readConfig();
@@ -125,6 +129,7 @@ private:
QStringList m_filesToRegister;
QString m_cacheDirectory;
bool m_cacheDirRelativeToCollection;
+ bool m_enableFullTextSearchFallback;
};
void CollectionConfigReader::raiseErrorWithLine()
@@ -139,6 +144,7 @@ void CollectionConfigReader::readData(const QByteArray &contents)
m_enableAddressBar = true;
m_hideAddressBar = true;
m_enableDocumentationManager = true;
+ m_enableFullTextSearchFallback = false;
addData(contents);
while (!atEnd()) {
@@ -212,6 +218,9 @@ void CollectionConfigReader::readAssistantSettings()
attributes().value(QLatin1String("base"))
== QLatin1String("collection");
m_cacheDirectory = readElementText();
+ } else if (name() == QLatin1String("enableFullTextSearchFallback")) {
+ if (readElementText() == QLatin1String("true"))
+ m_enableFullTextSearchFallback = true;
} else {
raiseErrorWithLine();
}
@@ -513,6 +522,8 @@ int main(int argc, char *argv[])
!config.hideAddressBar());
CollectionConfiguration::setCreationTime(helpEngine,
QDateTime::currentDateTime().toTime_t());
+ CollectionConfiguration::setFullTextSearchFallbackEnabled(helpEngine,
+ config.fullTextSearchFallbackEnabled());
if (!config.applicationIcon().isEmpty()) {
QFile icon(absoluteFileName(basePath, config.applicationIcon()));
diff --git a/tools/assistant/tools/shared/collectionconfiguration.cpp b/tools/assistant/tools/shared/collectionconfiguration.cpp
index e3944b6..2272c64 100644
--- a/tools/assistant/tools/shared/collectionconfiguration.cpp
+++ b/tools/assistant/tools/shared/collectionconfiguration.cpp
@@ -71,6 +71,7 @@ namespace {
#endif
));
const QString WindowTitleKey(QLatin1String("WindowTitle"));
+ const QString FullTextSearchFallbackKey(QLatin1String("FullTextSearchFallback"));
} // anonymous namespace
const QString CollectionConfiguration::DefaultZoomFactor(QLatin1String("0.0"));
@@ -308,6 +309,19 @@ void CollectionConfiguration::copyConfiguration(const QHelpEngineCore &source,
setAboutTexts(target, aboutTexts(source));
setAboutImages(target, aboutImages(source));
setDefaultHomePage(target, defaultHomePage(source));
+ setFullTextSearchFallbackEnabled(target, fullTextSearchFallbackEnabled(source));
+}
+
+bool CollectionConfiguration:: fullTextSearchFallbackEnabled(
+ const QHelpEngineCore &helpEngine)
+{
+ return helpEngine.customValue(FullTextSearchFallbackKey, false).toBool();
+}
+
+void CollectionConfiguration::setFullTextSearchFallbackEnabled(
+ QHelpEngineCore &helpEngine, bool on)
+{
+ helpEngine.setCustomValue(FullTextSearchFallbackKey, on);
}
QT_END_NAMESPACE
diff --git a/tools/assistant/tools/shared/collectionconfiguration.h b/tools/assistant/tools/shared/collectionconfiguration.h
index b7bf247..aeb636f 100644
--- a/tools/assistant/tools/shared/collectionconfiguration.h
+++ b/tools/assistant/tools/shared/collectionconfiguration.h
@@ -136,6 +136,10 @@ public:
static const QDateTime lastRegisterTime(const QHelpEngineCore &helpEngine);
static void updateLastRegisterTime(QHelpEngineCore &helpEngine);
+ static bool fullTextSearchFallbackEnabled(const QHelpEngineCore &helpEngine);
+ static void setFullTextSearchFallbackEnabled(QHelpEngineCore &helpEngine,
+ bool on);
+
static const QString DefaultZoomFactor;
static const QString ListSeparator;
};