From a0af55e7bdd56f3b486176738d5db82478311b44 Mon Sep 17 00:00:00 2001 From: kh1 <qt-info@nokia.com> Date: Mon, 18 Jan 2010 15:18:23 +0100 Subject: [PATCH] Add an combo box to switch between the opened tabs. Follow the text editor and provide a combo box for opened documents. We might consider removing the tabs all together to look more consistent. Task-number: QTCREATORBUG-584 Reviewed-by: ck --- src/plugins/help/centralwidget.cpp | 16 +++++++++- src/plugins/help/centralwidget.h | 7 ++++- src/plugins/help/helpplugin.cpp | 47 ++++++++++++++++++++++++++++-- src/plugins/help/helpplugin.h | 5 ++++ 4 files changed, 70 insertions(+), 5 deletions(-) diff --git a/src/plugins/help/centralwidget.cpp b/src/plugins/help/centralwidget.cpp index 0080f062b85..67dbc09c652 100644 --- a/src/plugins/help/centralwidget.cpp +++ b/src/plugins/help/centralwidget.cpp @@ -209,7 +209,9 @@ void CentralWidget::closeTab(int index) if (!viewer || tabWidget->count() == 1) return; + emit viewerAboutToBeRemoved(index); tabWidget->removeTab(index); + emit viewerRemoved(index); QTimer::singleShot(0, viewer, SLOT(deleteLater())); } @@ -484,6 +486,13 @@ HelpViewer *CentralWidget::helpViewerAtIndex(int index) const return qobject_cast<HelpViewer*>(tabWidget->widget(index)); } +int CentralWidget::indexOf(HelpViewer *viewer) const +{ + if (!viewer) + return -1; + return tabWidget->indexOf(viewer); +} + HelpViewer *CentralWidget::currentHelpViewer() const { return qobject_cast<HelpViewer*>(tabWidget->currentWidget()); @@ -529,7 +538,7 @@ void CentralWidget::currentPageChanged(int index) tabWidget->setTabsClosable(tabWidget->count() > 1); tabWidget->cornerWidget(Qt::TopLeftCorner)->setEnabled(true); - emit currentViewerChanged(); + emit currentViewerChanged(index); } void CentralWidget::showTabBarContextMenu(const QPoint &point) @@ -711,6 +720,11 @@ void CentralWidget::copy() viewer->copy(); } +void CentralWidget::activateTab(int index) +{ + tabWidget->setCurrentIndex(index); +} + QString CentralWidget::quoteTabTitle(const QString &title) const { QString s = title; diff --git a/src/plugins/help/centralwidget.h b/src/plugins/help/centralwidget.h index 001118abc81..78f92318fee 100644 --- a/src/plugins/help/centralwidget.h +++ b/src/plugins/help/centralwidget.h @@ -77,6 +77,7 @@ public: bool find(const QString &txt, QTextDocument::FindFlags findFlags, bool incremental); void setLastShownPages(); HelpViewer *helpViewerAtIndex(int index) const; + int indexOf(HelpViewer *viewer) const; static CentralWidget *instance(); @@ -99,12 +100,13 @@ public slots: void showTopicChooser(const QMap<QString, QUrl> &links, const QString &keyword); void copy(); + void activateTab(int index); protected: void focusInEvent(QFocusEvent *event); signals: - void currentViewerChanged(); + void currentViewerChanged(int index); void copyAvailable(bool yes); void sourceChanged(const QUrl &url); void highlighted(const QString &link); @@ -112,6 +114,9 @@ signals: void backwardAvailable(bool available); void addNewBookmark(const QString &title, const QString &url); + void viewerAboutToBeRemoved(int index); + void viewerRemoved(int index); + private slots: void newTab(); void closeTab(); diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index 367aead0f35..8960f202284 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -522,7 +522,7 @@ void HelpPlugin::createRightPaneSideBar() this)); connect(m_centralWidget, SIGNAL(sourceChanged(QUrl)), this, SLOT(updateSideBarSource(QUrl))); - connect(m_centralWidget, SIGNAL(currentViewerChanged()), this, + connect(m_centralWidget, SIGNAL(currentViewerChanged(int)), this, SLOT(updateSideBarSource())); QAction *copyActionSideBar = new QAction(this); @@ -693,6 +693,13 @@ void HelpPlugin::extensionsInitialized() "index.html").arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR)); } m_helpEngine->setCustomValue(QLatin1String("DefaultHomePage"), url.toString()); + + connect(m_centralWidget, SIGNAL(sourceChanged(QUrl)), this, + SLOT(rebuildViewerComboBox())); + connect(m_centralWidget, SIGNAL(currentViewerChanged(int)), this, + SLOT(updateViewerComboBoxIndex(int))); + connect(m_centralWidget, SIGNAL(viewerAboutToBeRemoved(int)), this, + SLOT(removeViewerFromComboBox(int))); } void HelpPlugin::shutdown() @@ -756,6 +763,31 @@ void HelpPlugin::fontChanged() #endif } +void HelpPlugin::rebuildViewerComboBox() +{ + m_documentsCombo->clear(); + + int i = 0; + while (HelpViewer *viewer = m_centralWidget->helpViewerAtIndex(i++)) + m_documentsCombo->addItem(viewer->documentTitle()); + + int index = m_centralWidget->indexOf(m_centralWidget->currentHelpViewer()); + if (index >= 0) + m_documentsCombo->setCurrentIndex(index); +} + +void HelpPlugin::removeViewerFromComboBox(int index) +{ + if (index >= 0) + m_documentsCombo->removeItem(index); +} + +void HelpPlugin::updateViewerComboBoxIndex(int index) +{ + if (index >= 0) + m_documentsCombo->setCurrentIndex(index); +} + HelpViewer* HelpPlugin::viewerForContextMode() { HelpViewer *viewer = 0; @@ -873,16 +905,25 @@ QToolBar *HelpPlugin::createToolBar() toolWidget->addSeparator(); QWidget *w = new QWidget; + toolWidget->addWidget(w); + QHBoxLayout *layout = new QHBoxLayout(w); layout->setMargin(0); layout->addSpacing(10); + m_documentsCombo = new QComboBox; + m_documentsCombo->setMinimumContentsLength(40); + layout->addWidget(m_documentsCombo); + + connect(m_documentsCombo, SIGNAL(activated(int)), m_centralWidget, + SLOT(activateTab(int))); + layout->addWidget(new QLabel(tr("Filtered by:"))); m_filterComboBox = new QComboBox; m_filterComboBox->setMinimumContentsLength(20); + layout->addWidget(m_filterComboBox); + connect(m_filterComboBox, SIGNAL(activated(QString)), this, SLOT(filterDocumentation(QString))); - layout->addWidget(m_filterComboBox); - toolWidget->addWidget(w); return toolWidget; } diff --git a/src/plugins/help/helpplugin.h b/src/plugins/help/helpplugin.h index 32a7d7428a1..f679b483941 100644 --- a/src/plugins/help/helpplugin.h +++ b/src/plugins/help/helpplugin.h @@ -143,6 +143,10 @@ private slots: void fontChanged(); + void rebuildViewerComboBox(); + void removeViewerFromComboBox(int index); + void updateViewerComboBoxIndex(int index); + private: QToolBar *createToolBar(); void createRightPaneSideBar(); @@ -170,6 +174,7 @@ private: DocSettingsPage *m_docSettingsPage; FilterSettingsPage *m_filterSettingsPage; + QComboBox *m_documentsCombo; QComboBox *m_filterComboBox; Core::SideBar *m_sideBar; QWidget *m_rightPaneSideBar; -- GitLab