forked from qt-creator/qt-creator
Clenaup, sync with Assistant source.
This commit is contained in:
@@ -31,7 +31,6 @@
|
|||||||
#include "helpviewer.h"
|
#include "helpviewer.h"
|
||||||
#include "topicchooser.h"
|
#include "topicchooser.h"
|
||||||
|
|
||||||
#include <QtCore/QDir>
|
|
||||||
#include <QtCore/QEvent>
|
#include <QtCore/QEvent>
|
||||||
#include <QtCore/QTimer>
|
#include <QtCore/QTimer>
|
||||||
|
|
||||||
@@ -62,7 +61,8 @@
|
|||||||
using namespace Help::Internal;
|
using namespace Help::Internal;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
HelpViewer* helpViewerFromTabPosition(const QTabWidget *widget, const QPoint &point)
|
HelpViewer* helpViewerFromTabPosition(const QTabWidget *widget,
|
||||||
|
const QPoint &point)
|
||||||
{
|
{
|
||||||
QTabBar *tabBar = qFindChild<QTabBar*>(widget);
|
QTabBar *tabBar = qFindChild<QTabBar*>(widget);
|
||||||
for (int i = 0; i < tabBar->count(); ++i) {
|
for (int i = 0; i < tabBar->count(); ++i) {
|
||||||
@@ -85,22 +85,22 @@ CentralWidget::CentralWidget(QHelpEngine *engine, QWidget *parent)
|
|||||||
globalActionList.clear();
|
globalActionList.clear();
|
||||||
collectionFile = helpEngine->collectionFile();
|
collectionFile = helpEngine->collectionFile();
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
|
||||||
# define SYSTEM "mac"
|
|
||||||
#else
|
|
||||||
# define SYSTEM "win"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
tabWidget = new QTabWidget;
|
tabWidget = new QTabWidget;
|
||||||
tabWidget->setDocumentMode(true);
|
tabWidget->setDocumentMode(true);
|
||||||
tabWidget->setMovable(true);
|
tabWidget->setMovable(true);
|
||||||
connect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
|
connect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
|
||||||
connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentPageChanged(int)));
|
connect(tabWidget, SIGNAL(currentChanged(int)), this,
|
||||||
|
SLOT(currentPageChanged(int)));
|
||||||
|
|
||||||
QToolButton *newTabButton = new QToolButton(this);
|
QToolButton *newTabButton = new QToolButton(this);
|
||||||
newTabButton->setAutoRaise(true);
|
newTabButton->setAutoRaise(true);
|
||||||
newTabButton->setToolTip(tr("Add new page"));
|
newTabButton->setToolTip(tr("Add new page"));
|
||||||
newTabButton->setIcon(QIcon(QString::fromLatin1(":/trolltech/assistant/images/" SYSTEM "/addtab.png")));
|
newTabButton->setIcon(QIcon(
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
QLatin1String(":/trolltech/assistant/images/mac/addtab.png")));
|
||||||
|
#else
|
||||||
|
QLatin1String(":/trolltech/assistant/images/win/addtab.png")));
|
||||||
|
#endif
|
||||||
|
|
||||||
tabWidget->setCornerWidget(newTabButton, Qt::TopLeftCorner);
|
tabWidget->setCornerWidget(newTabButton, Qt::TopLeftCorner);
|
||||||
connect(newTabButton, SIGNAL(clicked()), this, SLOT(newTab()));
|
connect(newTabButton, SIGNAL(clicked()), this, SLOT(newTab()));
|
||||||
@@ -122,19 +122,23 @@ CentralWidget::CentralWidget(QHelpEngine *engine, QWidget *parent)
|
|||||||
|
|
||||||
CentralWidget::~CentralWidget()
|
CentralWidget::~CentralWidget()
|
||||||
{
|
{
|
||||||
QDir dir;
|
#ifndef QT_NO_PRINTER
|
||||||
QString currentPages;
|
delete printer;
|
||||||
QHelpEngineCore engine(collectionFile, 0);
|
#endif
|
||||||
|
|
||||||
if (engine.setupData()) {
|
|
||||||
|
QHelpEngineCore engine(collectionFile, 0);
|
||||||
|
if (!engine.setupData())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString currentPages;
|
||||||
for (int i = 0; i < tabWidget->count(); ++i) {
|
for (int i = 0; i < tabWidget->count(); ++i) {
|
||||||
HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i));
|
HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i));
|
||||||
if (viewer && viewer->source().isValid())
|
if (viewer && viewer->source().isValid())
|
||||||
currentPages.append(viewer->source().toString()).append(QLatin1Char('|'));
|
currentPages += (viewer->source().toString() + QLatin1Char('|'));
|
||||||
}
|
}
|
||||||
engine.setCustomValue(QLatin1String("LastTabPage"), lastTabPage);
|
engine.setCustomValue(QLatin1String("LastTabPage"), lastTabPage);
|
||||||
engine.setCustomValue(QLatin1String("LastShownPages"), currentPages);
|
engine.setCustomValue(QLatin1String("LastShownPages"), currentPages);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CentralWidget *CentralWidget::instance()
|
CentralWidget *CentralWidget::instance()
|
||||||
@@ -165,10 +169,10 @@ void CentralWidget::zoomOut()
|
|||||||
|
|
||||||
void CentralWidget::nextPage()
|
void CentralWidget::nextPage()
|
||||||
{
|
{
|
||||||
if (tabWidget->currentIndex() < tabWidget->count() -1)
|
int index = tabWidget->currentIndex() + 1;
|
||||||
tabWidget->setCurrentIndex(tabWidget->currentIndex() +1);
|
if (index >= tabWidget->count())
|
||||||
else
|
index = 0;
|
||||||
tabWidget->setCurrentIndex(0);
|
tabWidget->setCurrentIndex(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CentralWidget::resetZoom()
|
void CentralWidget::resetZoom()
|
||||||
@@ -181,10 +185,9 @@ void CentralWidget::resetZoom()
|
|||||||
void CentralWidget::previousPage()
|
void CentralWidget::previousPage()
|
||||||
{
|
{
|
||||||
int index = tabWidget->currentIndex() -1;
|
int index = tabWidget->currentIndex() -1;
|
||||||
if (index >= 0)
|
if (index < 0)
|
||||||
|
index = tabWidget->count() -1;
|
||||||
tabWidget->setCurrentIndex(index);
|
tabWidget->setCurrentIndex(index);
|
||||||
else
|
|
||||||
tabWidget->setCurrentIndex(tabWidget->count() -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CentralWidget::closeTab()
|
void CentralWidget::closeTab()
|
||||||
@@ -205,7 +208,8 @@ void CentralWidget::closeTab(int index)
|
|||||||
void CentralWidget::setSource(const QUrl &url)
|
void CentralWidget::setSource(const QUrl &url)
|
||||||
{
|
{
|
||||||
HelpViewer* viewer = currentHelpViewer();
|
HelpViewer* viewer = currentHelpViewer();
|
||||||
HelpViewer* lastViewer = qobject_cast<HelpViewer*>(tabWidget->widget(lastTabPage));
|
HelpViewer* lastViewer =
|
||||||
|
qobject_cast<HelpViewer*>(tabWidget->widget(lastTabPage));
|
||||||
|
|
||||||
if (!viewer && !lastViewer) {
|
if (!viewer && !lastViewer) {
|
||||||
viewer = new HelpViewer(helpEngine, this);
|
viewer = new HelpViewer(helpEngine, this);
|
||||||
@@ -214,8 +218,9 @@ void CentralWidget::setSource(const QUrl &url)
|
|||||||
tabWidget->setCurrentIndex(lastTabPage);
|
tabWidget->setCurrentIndex(lastTabPage);
|
||||||
connectSignals();
|
connectSignals();
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
} else
|
} else {
|
||||||
viewer = lastViewer;
|
viewer = lastViewer;
|
||||||
|
}
|
||||||
|
|
||||||
viewer->setSource(url);
|
viewer->setSource(url);
|
||||||
currentPageChanged(lastTabPage);
|
currentPageChanged(lastTabPage);
|
||||||
@@ -226,24 +231,28 @@ void CentralWidget::setSource(const QUrl &url)
|
|||||||
|
|
||||||
void CentralWidget::setLastShownPages()
|
void CentralWidget::setLastShownPages()
|
||||||
{
|
{
|
||||||
const QStringList lastShownPageList =
|
QString value = helpEngine->customValue(QLatin1String("LastShownPages"),
|
||||||
helpEngine->customValue(QLatin1String("LastShownPages")). toString().
|
QString()).toString();
|
||||||
split(QLatin1Char('|'), QString::SkipEmptyParts);
|
const QStringList lastShownPageList = value.split(QLatin1Char('|'),
|
||||||
|
QString::SkipEmptyParts);
|
||||||
|
|
||||||
if (!lastShownPageList.isEmpty()) {
|
const int pageCount = lastShownPageList.count();
|
||||||
foreach (const QString& page, lastShownPageList)
|
if (pageCount <= 0) {
|
||||||
setSourceInNewTab(page);
|
QUrl url = helpEngine->findFile(QString::fromLatin1("qthelp://com."
|
||||||
|
"trolltech.qt.440/qdoc/index.html"));
|
||||||
tabWidget->setCurrentIndex(helpEngine->
|
|
||||||
customValue(QLatin1String("LastTabPage"), 0).toInt());
|
|
||||||
} else {
|
|
||||||
QUrl url(helpEngine->findFile(QUrl("qthelp://com.trolltech.qt.440/qdoc/index.html")));
|
|
||||||
if (!url.isValid()) {
|
if (!url.isValid()) {
|
||||||
url.setUrl(QString("qthelp://com.nokia.qtcreator.%1%2/doc/index.html").
|
url.setUrl(QString("qthelp://com.nokia.qtcreator.%1%2/doc/index.html").
|
||||||
arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR));
|
arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR));
|
||||||
|
url.setUrl(QString::fromLatin1("qthelp://com.nokia.qtcreator.%1%2/"
|
||||||
|
"doc/index.html").arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR));
|
||||||
}
|
}
|
||||||
setSource(url);
|
setSource(url);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList::const_iterator it = lastShownPageList.constBegin();
|
||||||
|
for (; it != lastShownPageList.constEnd(); ++it)
|
||||||
|
setSourceInNewTab((*it));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CentralWidget::hasSelection() const
|
bool CentralWidget::hasSelection() const
|
||||||
@@ -326,6 +335,8 @@ void CentralWidget::printPreview(QPrinter *p)
|
|||||||
HelpViewer *viewer = currentHelpViewer();
|
HelpViewer *viewer = currentHelpViewer();
|
||||||
if (viewer)
|
if (viewer)
|
||||||
viewer->print(p);
|
viewer->print(p);
|
||||||
|
#else
|
||||||
|
Q_UNUSED(p);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,6 +486,8 @@ void CentralWidget::setTabTitle(const QUrl& url)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
Q_UNUSED(url);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (viewer) {
|
if (viewer) {
|
||||||
@@ -485,16 +498,9 @@ void CentralWidget::setTabTitle(const QUrl& url)
|
|||||||
|
|
||||||
void CentralWidget::currentPageChanged(int index)
|
void CentralWidget::currentPageChanged(int index)
|
||||||
{
|
{
|
||||||
const HelpViewer *viewer = currentHelpViewer();
|
|
||||||
|
|
||||||
if (viewer || tabWidget->count() == 1)
|
|
||||||
lastTabPage = index;
|
lastTabPage = index;
|
||||||
|
|
||||||
bool enabled = false;
|
tabWidget->setTabsClosable(tabWidget->count() > 1);
|
||||||
if (viewer)
|
|
||||||
enabled = tabWidget->count() > 1;
|
|
||||||
|
|
||||||
tabWidget->setTabsClosable(enabled);
|
|
||||||
tabWidget->cornerWidget(Qt::TopLeftCorner)->setEnabled(true);
|
tabWidget->cornerWidget(Qt::TopLeftCorner)->setEnabled(true);
|
||||||
|
|
||||||
emit currentViewerChanged();
|
emit currentViewerChanged();
|
||||||
@@ -509,34 +515,32 @@ void CentralWidget::showTabBarContextMenu(const QPoint &point)
|
|||||||
QTabBar *tabBar = qFindChild<QTabBar*>(tabWidget);
|
QTabBar *tabBar = qFindChild<QTabBar*>(tabWidget);
|
||||||
|
|
||||||
QMenu menu(QLatin1String(""), tabBar);
|
QMenu menu(QLatin1String(""), tabBar);
|
||||||
QAction *new_page = menu.addAction(tr("Add New Page"));
|
QAction *newPage = menu.addAction(tr("Add New Page"));
|
||||||
QAction *close_page = menu.addAction(tr("Close This Page"));
|
|
||||||
QAction *close_pages = menu.addAction(tr("Close Other Pages"));
|
bool enableAction = tabBar->count() > 1;
|
||||||
|
QAction *closePage = menu.addAction(tr("Close This Page"));
|
||||||
|
closePage->setEnabled(enableAction);
|
||||||
|
|
||||||
|
QAction *closePages = menu.addAction(tr("Close Other Pages"));
|
||||||
|
closePages->setEnabled(enableAction);
|
||||||
|
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
|
||||||
QAction *newBookmark = menu.addAction(tr("Add Bookmark for this Page..."));
|
QAction *newBookmark = menu.addAction(tr("Add Bookmark for this Page..."));
|
||||||
|
|
||||||
if (tabBar->count() == 1) {
|
|
||||||
close_page->setEnabled(false);
|
|
||||||
close_pages->setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString &url = viewer->source().toString();
|
const QString &url = viewer->source().toString();
|
||||||
if (url.isEmpty() || url == QLatin1String("about:blank"))
|
if (url.isEmpty() || url == QLatin1String("about:blank"))
|
||||||
newBookmark->setEnabled(false);
|
newBookmark->setEnabled(false);
|
||||||
|
|
||||||
QAction *picked_action = menu.exec(tabBar->mapToGlobal(point));
|
QAction *pickedAction = menu.exec(tabBar->mapToGlobal(point));
|
||||||
if (!picked_action)
|
if (pickedAction == newPage)
|
||||||
return;
|
|
||||||
|
|
||||||
if (picked_action == new_page)
|
|
||||||
setSourceInNewTab(viewer->source());
|
setSourceInNewTab(viewer->source());
|
||||||
|
|
||||||
if (picked_action == close_page) {
|
if (pickedAction == closePage) {
|
||||||
tabWidget->removeTab(tabWidget->indexOf(viewer));
|
tabWidget->removeTab(tabWidget->indexOf(viewer));
|
||||||
QTimer::singleShot(0, viewer, SLOT(deleteLater()));
|
QTimer::singleShot(0, viewer, SLOT(deleteLater()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (picked_action == close_pages) {
|
if (pickedAction == closePages) {
|
||||||
int currentPage = tabWidget->indexOf(viewer);
|
int currentPage = tabWidget->indexOf(viewer);
|
||||||
for (int i = tabBar->count() -1; i >= 0; --i) {
|
for (int i = tabBar->count() -1; i >= 0; --i) {
|
||||||
viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i));
|
viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i));
|
||||||
@@ -550,7 +554,7 @@ void CentralWidget::showTabBarContextMenu(const QPoint &point)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (picked_action == newBookmark)
|
if (pickedAction == newBookmark)
|
||||||
emit addNewBookmark(viewer->documentTitle(), url);
|
emit addNewBookmark(viewer->documentTitle(), url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -568,33 +572,42 @@ void CentralWidget::focusInEvent(QFocusEvent * /* event */)
|
|||||||
|
|
||||||
bool CentralWidget::eventFilter(QObject *object, QEvent *e)
|
bool CentralWidget::eventFilter(QObject *object, QEvent *e)
|
||||||
{
|
{
|
||||||
if (currentHelpViewer() == object && e->type() == QEvent::KeyPress){
|
if (e->type() == QEvent::KeyPress){
|
||||||
QKeyEvent *ke = static_cast<QKeyEvent*>(e);
|
if ((static_cast<QKeyEvent*>(e))->key() == Qt::Key_Backspace) {
|
||||||
if (ke->key() == Qt::Key_Backspace) {
|
|
||||||
HelpViewer *viewer = currentHelpViewer();
|
HelpViewer *viewer = currentHelpViewer();
|
||||||
if (viewer && viewer->isBackwardAvailable())
|
if (viewer == object) {
|
||||||
|
if (viewer->isBackwardAvailable()) {
|
||||||
|
#if !defined(QT_NO_WEBKIT)
|
||||||
|
// this helps in case there is an html <input> field
|
||||||
|
if (!viewer->hasFocus())
|
||||||
|
#endif
|
||||||
viewer->backward();
|
viewer->backward();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QTabBar *tabBar = qobject_cast<QTabBar*>(object);
|
if (qobject_cast<QTabBar*>(object)) {
|
||||||
bool mousRel = e->type() == QEvent::MouseButtonRelease;
|
|
||||||
bool dblClick = e->type() == QEvent::MouseButtonDblClick;
|
bool dblClick = e->type() == QEvent::MouseButtonDblClick;
|
||||||
|
if((e->type() == QEvent::MouseButtonRelease) || dblClick) {
|
||||||
if (tabBar && (mousRel || dblClick)) {
|
|
||||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(e);
|
|
||||||
HelpViewer *viewer = helpViewerFromTabPosition(tabWidget, mouseEvent->pos());
|
|
||||||
if (tabWidget->count() <= 1)
|
if (tabWidget->count() <= 1)
|
||||||
return QWidget::eventFilter(object, e);
|
return QWidget::eventFilter(object, e);
|
||||||
|
|
||||||
if (viewer && (mouseEvent->button() == Qt::MidButton || dblClick)) {
|
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(e);
|
||||||
|
HelpViewer *viewer = helpViewerFromTabPosition(tabWidget,
|
||||||
|
mouseEvent->pos());
|
||||||
|
|
||||||
|
if (viewer) {
|
||||||
|
if ((mouseEvent->button() == Qt::MidButton) || dblClick) {
|
||||||
tabWidget->removeTab(tabWidget->indexOf(viewer));
|
tabWidget->removeTab(tabWidget->indexOf(viewer));
|
||||||
QTimer::singleShot(0, viewer, SLOT(deleteLater()));
|
QTimer::singleShot(0, viewer, SLOT(deleteLater()));
|
||||||
currentPageChanged(tabWidget->currentIndex());
|
currentPageChanged(tabWidget->currentIndex());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return QWidget::eventFilter(object, e);
|
return QWidget::eventFilter(object, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user