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
This commit is contained in:
kh1
2010-01-18 15:18:23 +01:00
parent f88bc5f3cd
commit a0af55e7bd
4 changed files with 70 additions and 5 deletions

View File

@@ -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;

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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;