summaryrefslogtreecommitdiffstats
path: root/tools/assistant
diff options
context:
space:
mode:
authorkh1 <qt-info@nokia.com>2010-08-26 10:17:47 (GMT)
committerkh1 <qt-info@nokia.com>2010-08-26 10:20:24 (GMT)
commitfd493419a62a60873213aadf7df3e958bf0c8d8e (patch)
treec9c7168adf74a12121ceb84b36a9b828117beae5 /tools/assistant
parenta4515ec14fdc772eb6b5c4801cddaddc26b94d84 (diff)
downloadQt-fd493419a62a60873213aadf7df3e958bf0c8d8e.zip
Qt-fd493419a62a60873213aadf7df3e958bf0c8d8e.tar.gz
Qt-fd493419a62a60873213aadf7df3e958bf0c8d8e.tar.bz2
Make tabbed pages optional in Assistant.
Task-number: QTBUG-13012 Reviewed-by: ck
Diffstat (limited to 'tools/assistant')
-rw-r--r--tools/assistant/tools/assistant/centralwidget.cpp146
-rw-r--r--tools/assistant/tools/assistant/centralwidget.h30
-rw-r--r--tools/assistant/tools/assistant/helpenginewrapper.cpp14
-rw-r--r--tools/assistant/tools/assistant/helpenginewrapper.h3
-rw-r--r--tools/assistant/tools/assistant/helpviewer.h1
-rw-r--r--tools/assistant/tools/assistant/mainwindow.cpp7
-rw-r--r--tools/assistant/tools/assistant/openpagesmanager.cpp19
-rw-r--r--tools/assistant/tools/assistant/openpagesmanager.h3
-rw-r--r--tools/assistant/tools/assistant/preferencesdialog.cpp7
-rw-r--r--tools/assistant/tools/assistant/preferencesdialog.h2
-rw-r--r--tools/assistant/tools/assistant/preferencesdialog.ui20
11 files changed, 245 insertions, 7 deletions
diff --git a/tools/assistant/tools/assistant/centralwidget.cpp b/tools/assistant/tools/assistant/centralwidget.cpp
index 028463b..a232383 100644
--- a/tools/assistant/tools/assistant/centralwidget.cpp
+++ b/tools/assistant/tools/assistant/centralwidget.cpp
@@ -44,12 +44,14 @@
#include "findwidget.h"
#include "helpenginewrapper.h"
#include "helpviewer.h"
+#include "openpagesmanager.h"
#include "tracer.h"
#include "../shared/collectionconfiguration.h"
#include <QtCore/QTimer>
#include <QtGui/QKeyEvent>
+#include <QtGui/QMenu>
#include <QtGui/QPageSetupDialog>
#include <QtGui/QPrintDialog>
#include <QtGui/QPrintPreviewDialog>
@@ -66,6 +68,124 @@ namespace {
CentralWidget *staticCentralWidget = 0;
}
+// -- TabBar
+
+TabBar::TabBar(QWidget *parent)
+ : QTabBar(parent)
+{
+ TRACE_OBJ
+#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)));
+}
+
+TabBar::~TabBar()
+{
+ TRACE_OBJ
+}
+
+int TabBar::addNewTab(const QString &title)
+{
+ TRACE_OBJ
+ const int index = addTab(title);
+ setTabsClosable(count() > 1);
+ return index;
+}
+
+void TabBar::setCurrent(HelpViewer *viewer)
+{
+ TRACE_OBJ
+ for (int i = 0; i < count(); ++i) {
+ HelpViewer *data = tabData(i).value<HelpViewer*>();
+ if (data == viewer) {
+ setCurrentIndex(i);
+ break;
+ }
+ }
+}
+
+void TabBar::removeTabAt(HelpViewer *viewer)
+{
+ TRACE_OBJ
+ for (int i = 0; i < count(); ++i) {
+ HelpViewer *data = tabData(i).value<HelpViewer*>();
+ if (data == viewer) {
+ removeTab(i);
+ break;
+ }
+ }
+ setTabsClosable(count() > 1);
+}
+
+void TabBar::titleChanged()
+{
+ TRACE_OBJ
+ 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 TabBar::slotCurrentChanged(int index)
+{
+ TRACE_OBJ
+ emit currentTabChanged(tabData(index).value<HelpViewer*>());
+}
+
+void TabBar::slotTabCloseRequested(int index)
+{
+ TRACE_OBJ
+ OpenPagesManager::instance()->closePage(tabData(index).value<HelpViewer*>());
+}
+
+void TabBar::slotCustomContextMenuRequested(const QPoint &pos)
+{
+ TRACE_OBJ
+ const int tab = tabAt(pos);
+ if (tab < 0)
+ return;
+
+ 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);
+}
+
// -- CentralWidget
CentralWidget::CentralWidget(QWidget *parent)
@@ -75,12 +195,16 @@ CentralWidget::CentralWidget(QWidget *parent)
#endif
, m_findWidget(new FindWidget(this))
, m_stackedWidget(new QStackedWidget(this))
+ , m_tabBar(new TabBar(this))
{
TRACE_OBJ
staticCentralWidget = this;
QVBoxLayout *vboxLayout = new QVBoxLayout(this);
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();
@@ -90,6 +214,8 @@ CentralWidget::CentralWidget(QWidget *parent)
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)));
}
CentralWidget::~CentralWidget()
@@ -170,7 +296,11 @@ void CentralWidget::addPage(HelpViewer *page, bool fromSearch)
page->installEventFilter(this);
page->setFocus(Qt::OtherFocusReason);
connectSignals(page);
- m_stackedWidget->addWidget(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()));
+
if (fromSearch) {
connect(currentHelpViewer(), SIGNAL(loadFinished(bool)), this,
SLOT(highlightSearchTerms()));
@@ -181,6 +311,7 @@ void CentralWidget::removePage(int index)
{
TRACE_OBJ
const bool currentChanged = index == currentIndex();
+ m_tabBar->removeTabAt(viewerAt(index));
m_stackedWidget->removeWidget(m_stackedWidget->widget(index));
if (currentChanged)
emit currentViewerChanged();
@@ -195,10 +326,18 @@ int CentralWidget::currentIndex() const
void CentralWidget::setCurrentPage(HelpViewer *page)
{
TRACE_OBJ
+ m_tabBar->setCurrent(page);
m_stackedWidget->setCurrentWidget(page);
emit currentViewerChanged();
}
+void CentralWidget::connectTabBar()
+{
+ TRACE_OBJ
+ connect(m_tabBar, SIGNAL(currentTabChanged(HelpViewer*)),
+ OpenPagesManager::instance(), SLOT(setCurrentPage(HelpViewer*)));
+}
+
// -- public slots
void CentralWidget::copy()
@@ -367,6 +506,11 @@ void CentralWidget::updateBrowserFont()
viewerAt(i)->setViewerFont(font);
}
+void CentralWidget::updateUserInterface()
+{
+ m_tabBar->setVisible(HelpEngineWrapper::instance().showTabs());
+}
+
// -- protected
void CentralWidget::keyPressEvent(QKeyEvent *e)
diff --git a/tools/assistant/tools/assistant/centralwidget.h b/tools/assistant/tools/assistant/centralwidget.h
index 69e334a..bcadcf4 100644
--- a/tools/assistant/tools/assistant/centralwidget.h
+++ b/tools/assistant/tools/assistant/centralwidget.h
@@ -43,6 +43,8 @@
#define CENTRALWIDGET_H
#include <QtCore/QUrl>
+
+#include <QtGui/QTabBar>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
@@ -51,6 +53,30 @@ class FindWidget;
class HelpViewer;
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
@@ -77,6 +103,8 @@ public:
int currentIndex() const;
void setCurrentPage(HelpViewer *page);
+ void connectTabBar();
+
public slots:
void copy();
void home();
@@ -105,6 +133,7 @@ public slots:
void activateTab();
void showTextSearch();
void updateBrowserFont();
+ void updateUserInterface();
signals:
void currentViewerChanged();
@@ -135,6 +164,7 @@ private:
#endif
FindWidget *m_findWidget;
QStackedWidget *m_stackedWidget;
+ TabBar *m_tabBar;
};
QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/helpenginewrapper.cpp b/tools/assistant/tools/assistant/helpenginewrapper.cpp
index 0a5445a..fb67551 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
@@ -697,6 +698,17 @@ void HelpEngineWrapper::handleCurrentFilterChanged(const QString &filter)
emit currentFilterChanged(filterToReport);
}
+bool HelpEngineWrapper::showTabs() const
+{
+ return d->m_helpEngine->customValue(ShowTabsKey, false).toBool();
+}
+
+void HelpEngineWrapper::setShowTabs(bool show)
+{
+ d->m_helpEngine->setCustomValue(ShowTabsKey, show);
+}
+
+// -- TimeoutForwarder
TimeoutForwarder::TimeoutForwarder(const QString &fileName)
: m_fileName(fileName)
@@ -710,6 +722,7 @@ void TimeoutForwarder::forward()
HelpEngineWrapper::instance().d->qchFileChanged(m_fileName, true);
}
+// -- HelpEngineWrapperPrivate
HelpEngineWrapperPrivate::HelpEngineWrapperPrivate(const QString &collectionFile)
: m_helpEngine(new QHelpEngine(collectionFile, this)),
@@ -817,7 +830,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 f1a381a..7349015 100644
--- a/tools/assistant/tools/assistant/helpenginewrapper.h
+++ b/tools/assistant/tools/assistant/helpenginewrapper.h
@@ -184,6 +184,9 @@ public:
QFontDatabase::WritingSystem browserWritingSystem() const;
void setBrowserWritingSystem(QFontDatabase::WritingSystem system);
+ bool showTabs() const;
+ void setShowTabs(bool show);
+
static const QString TrUnfiltered;
signals:
diff --git a/tools/assistant/tools/assistant/helpviewer.h b/tools/assistant/tools/assistant/helpviewer.h
index 939096d..e2aefca 100644
--- a/tools/assistant/tools/assistant/helpviewer.h
+++ b/tools/assistant/tools/assistant/helpviewer.h
@@ -153,5 +153,6 @@ private:
};
QT_END_NAMESPACE
+Q_DECLARE_METATYPE(HelpViewer*)
#endif // HELPVIEWER_H
diff --git a/tools/assistant/tools/assistant/mainwindow.cpp b/tools/assistant/tools/assistant/mainwindow.cpp
index e436201..b27d5a1 100644
--- a/tools/assistant/tools/assistant/mainwindow.cpp
+++ b/tools/assistant/tools/assistant/mainwindow.cpp
@@ -155,6 +155,8 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent)
openPagesDock->setWidget(openPagesManager->openPagesWidget());
addDockWidget(Qt::LeftDockWidgetArea, openPagesDock);
+ connect(m_centralWidget, SIGNAL(addBookmark(QString, QString)),
+ bookMarkManager, SLOT(addBookmark(QString, QString)));
#if 0
connect(bookMarkManager, SIGNAL(escapePressed()), this,
SLOT(activateCurrentCentralWidgetTab()));
@@ -162,8 +164,6 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent)
SLOT(setSource(QUrl)));
connect(bookMarkManager, SIGNAL(setSourceInNewTab(QUrl)),
openPagesManager, SLOT(createPage(QUrl)));
- connect(m_centralWidget, SIGNAL(addBookmark(QString, QString)),
- bookMarkManager, SLOT(addBookmark(QString, QString)));
QHelpSearchEngine *searchEngine = helpEngineWrapper.searchEngine();
connect(searchEngine, SIGNAL(indexingStarted()), this, SLOT(indexingStarted()));
@@ -175,6 +175,7 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent)
setupActions();
statusBar()->show();
+ m_centralWidget->connectTabBar();
if (!initHelpDB()) {
qDebug("Fatal error: Help engine initialization failed. "
@@ -736,6 +737,8 @@ void MainWindow::showPreferences()
SLOT(updateApplicationFont()));
connect(&dia, SIGNAL(updateBrowserFont()), m_centralWidget,
SLOT(updateBrowserFont()));
+ connect(&dia, SIGNAL(updateUserInterface()), m_centralWidget,
+ SLOT(updateUserInterface()));
dia.showDialog();
}
diff --git a/tools/assistant/tools/assistant/openpagesmanager.cpp b/tools/assistant/tools/assistant/openpagesmanager.cpp
index 6b08c46..3b69b50 100644
--- a/tools/assistant/tools/assistant/openpagesmanager.cpp
+++ b/tools/assistant/tools/assistant/openpagesmanager.cpp
@@ -209,6 +209,17 @@ HelpViewer *OpenPagesManager::createNewPageFromSearch(const QUrl &url)
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
@@ -264,7 +275,13 @@ void OpenPagesManager::setCurrentPage(const QModelIndex &index)
void OpenPagesManager::setCurrentPage(int index)
{
TRACE_OBJ
- CentralWidget::instance()->setCurrentPage(m_model->pageAt(index));
+ setCurrentPage(m_model->pageAt(index));
+}
+
+void OpenPagesManager::setCurrentPage(HelpViewer *page)
+{
+ TRACE_OBJ
+ CentralWidget::instance()->setCurrentPage(page);
m_openPagesWidget->selectCurrentPage();
}
diff --git a/tools/assistant/tools/assistant/openpagesmanager.h b/tools/assistant/tools/assistant/openpagesmanager.h
index 56a1ce7..5837392 100644
--- a/tools/assistant/tools/assistant/openpagesmanager.h
+++ b/tools/assistant/tools/assistant/openpagesmanager.h
@@ -83,6 +83,9 @@ public slots:
void previousPage();
void previousPageWithSwitcher();
+ void closePage(HelpViewer *page);
+ void setCurrentPage(HelpViewer *page);
+
private slots:
void setCurrentPage(const QModelIndex &index);
void closePage(const QModelIndex &index);
diff --git a/tools/assistant/tools/assistant/preferencesdialog.cpp b/tools/assistant/tools/assistant/preferencesdialog.cpp
index 40a449e..495dad9 100644
--- a/tools/assistant/tools/assistant/preferencesdialog.cpp
+++ b/tools/assistant/tools/assistant/preferencesdialog.cpp
@@ -379,6 +379,10 @@ void PreferencesDialog::applyChanges()
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();
}
@@ -470,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 7a17275..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();
@@ -101,6 +102,7 @@ private:
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>