forked from qt-creator/qt-creator
NavigationWidget: Add menu to split button
This is more consistent with the split button that we have for the editors, and the default split behavior, which duplicated the current view, seldomly resulted in what was wanted anyhow. Change-Id: Iaba62151edbf11f6bbfaf45d68371532bff48dd5 Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
#include <QDebug>
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QMenu>
|
||||
#include <QResizeEvent>
|
||||
#include <QToolButton>
|
||||
|
||||
@@ -75,6 +76,12 @@ NavigationSubWidget::NavigationSubWidget(NavigationWidget *parentWidget, int pos
|
||||
QToolButton *splitAction = new QToolButton();
|
||||
splitAction->setIcon(QIcon(QLatin1String(Constants::ICON_SPLIT_HORIZONTAL)));
|
||||
splitAction->setToolTip(tr("Split"));
|
||||
splitAction->setPopupMode(QToolButton::InstantPopup);
|
||||
splitAction->setProperty("noArrow", true);
|
||||
m_splitMenu = new QMenu(splitAction);
|
||||
splitAction->setMenu(m_splitMenu);
|
||||
connect(m_splitMenu, &QMenu::aboutToShow, this, &NavigationSubWidget::populateSplitMenu);
|
||||
|
||||
QToolButton *close = new QToolButton();
|
||||
close->setIcon(QIcon(QLatin1String(Constants::ICON_BUTTON_CLOSE)));
|
||||
close->setToolTip(tr("Close"));
|
||||
@@ -88,7 +95,6 @@ NavigationSubWidget::NavigationSubWidget(NavigationWidget *parentWidget, int pos
|
||||
setLayout(lay);
|
||||
lay->addWidget(m_toolBar);
|
||||
|
||||
connect(splitAction, SIGNAL(clicked()), this, SIGNAL(splitMe()));
|
||||
connect(close, SIGNAL(clicked()), this, SIGNAL(closeMe()));
|
||||
|
||||
setFactoryIndex(factoryIndex);
|
||||
@@ -136,6 +142,18 @@ void NavigationSubWidget::comboBoxIndexChanged(int factoryIndex)
|
||||
restoreSettings();
|
||||
}
|
||||
|
||||
void NavigationSubWidget::populateSplitMenu()
|
||||
{
|
||||
m_splitMenu->clear();
|
||||
QAbstractItemModel *factoryModel = m_parentWidget->factoryModel();
|
||||
int count = factoryModel->rowCount();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
QModelIndex index = factoryModel->index(i, 0);
|
||||
QAction *action = m_splitMenu->addAction(factoryModel->data(index).toString());
|
||||
connect(action, &QAction::triggered, this, [this, i]() { emit splitMe(i); });
|
||||
}
|
||||
}
|
||||
|
||||
void NavigationSubWidget::setFocusWidget()
|
||||
{
|
||||
if (m_navigationWidget)
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <QList>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QMenu;
|
||||
class QToolButton;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
@@ -71,15 +72,18 @@ public:
|
||||
Command *command(const QString &title) const;
|
||||
|
||||
signals:
|
||||
void splitMe();
|
||||
void splitMe(int factoryIndex);
|
||||
void closeMe();
|
||||
|
||||
private slots:
|
||||
void comboBoxIndexChanged(int);
|
||||
|
||||
private:
|
||||
void populateSplitMenu();
|
||||
|
||||
NavigationWidget *m_parentWidget;
|
||||
QComboBox *m_navigationComboBox;
|
||||
QMenu *m_splitMenu;
|
||||
QWidget *m_navigationWidget;
|
||||
INavigationWidgetFactory *m_navigationWidgetFactory;
|
||||
Utils::StyledBar *m_toolBar;
|
||||
|
||||
@@ -247,7 +247,8 @@ Internal::NavigationSubWidget *NavigationWidget::insertSubItem(int position,int
|
||||
}
|
||||
|
||||
Internal::NavigationSubWidget *nsw = new Internal::NavigationSubWidget(this, position, index);
|
||||
connect(nsw, SIGNAL(splitMe()), this, SLOT(splitSubWidget()));
|
||||
connect(nsw, &Internal::NavigationSubWidget::splitMe,
|
||||
this, &NavigationWidget::splitSubWidget);
|
||||
connect(nsw, SIGNAL(closeMe()), this, SLOT(closeSubWidget()));
|
||||
insertWidget(position, nsw);
|
||||
d->m_subWidgets.insert(position, nsw);
|
||||
@@ -281,11 +282,11 @@ void NavigationWidget::activateSubWidget(Id factoryId)
|
||||
}
|
||||
}
|
||||
|
||||
void NavigationWidget::splitSubWidget()
|
||||
void NavigationWidget::splitSubWidget(int factoryIndex)
|
||||
{
|
||||
Internal::NavigationSubWidget *original = qobject_cast<Internal::NavigationSubWidget *>(sender());
|
||||
int pos = indexOf(original) + 1;
|
||||
insertSubItem(pos, original->factoryIndex());
|
||||
insertSubItem(pos, factoryIndex);
|
||||
}
|
||||
|
||||
void NavigationWidget::closeSubWidget()
|
||||
|
||||
@@ -111,7 +111,7 @@ protected:
|
||||
|
||||
private slots:
|
||||
void activateSubWidget();
|
||||
void splitSubWidget();
|
||||
void splitSubWidget(int factoryIndex);
|
||||
void closeSubWidget();
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user