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:
Eike Ziller
2014-12-04 13:07:01 +01:00
parent 95c13a230e
commit a1f8be4471
4 changed files with 29 additions and 6 deletions

View File

@@ -41,6 +41,7 @@
#include <QDebug> #include <QDebug>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QMenu>
#include <QResizeEvent> #include <QResizeEvent>
#include <QToolButton> #include <QToolButton>
@@ -75,6 +76,12 @@ NavigationSubWidget::NavigationSubWidget(NavigationWidget *parentWidget, int pos
QToolButton *splitAction = new QToolButton(); QToolButton *splitAction = new QToolButton();
splitAction->setIcon(QIcon(QLatin1String(Constants::ICON_SPLIT_HORIZONTAL))); splitAction->setIcon(QIcon(QLatin1String(Constants::ICON_SPLIT_HORIZONTAL)));
splitAction->setToolTip(tr("Split")); 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(); QToolButton *close = new QToolButton();
close->setIcon(QIcon(QLatin1String(Constants::ICON_BUTTON_CLOSE))); close->setIcon(QIcon(QLatin1String(Constants::ICON_BUTTON_CLOSE)));
close->setToolTip(tr("Close")); close->setToolTip(tr("Close"));
@@ -88,7 +95,6 @@ NavigationSubWidget::NavigationSubWidget(NavigationWidget *parentWidget, int pos
setLayout(lay); setLayout(lay);
lay->addWidget(m_toolBar); lay->addWidget(m_toolBar);
connect(splitAction, SIGNAL(clicked()), this, SIGNAL(splitMe()));
connect(close, SIGNAL(clicked()), this, SIGNAL(closeMe())); connect(close, SIGNAL(clicked()), this, SIGNAL(closeMe()));
setFactoryIndex(factoryIndex); setFactoryIndex(factoryIndex);
@@ -136,6 +142,18 @@ void NavigationSubWidget::comboBoxIndexChanged(int factoryIndex)
restoreSettings(); 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() void NavigationSubWidget::setFocusWidget()
{ {
if (m_navigationWidget) if (m_navigationWidget)

View File

@@ -36,6 +36,7 @@
#include <QList> #include <QList>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QMenu;
class QToolButton; class QToolButton;
QT_END_NAMESPACE QT_END_NAMESPACE
@@ -71,15 +72,18 @@ public:
Command *command(const QString &title) const; Command *command(const QString &title) const;
signals: signals:
void splitMe(); void splitMe(int factoryIndex);
void closeMe(); void closeMe();
private slots: private slots:
void comboBoxIndexChanged(int); void comboBoxIndexChanged(int);
private: private:
void populateSplitMenu();
NavigationWidget *m_parentWidget; NavigationWidget *m_parentWidget;
QComboBox *m_navigationComboBox; QComboBox *m_navigationComboBox;
QMenu *m_splitMenu;
QWidget *m_navigationWidget; QWidget *m_navigationWidget;
INavigationWidgetFactory *m_navigationWidgetFactory; INavigationWidgetFactory *m_navigationWidgetFactory;
Utils::StyledBar *m_toolBar; Utils::StyledBar *m_toolBar;

View File

@@ -247,7 +247,8 @@ Internal::NavigationSubWidget *NavigationWidget::insertSubItem(int position,int
} }
Internal::NavigationSubWidget *nsw = new Internal::NavigationSubWidget(this, position, index); 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())); connect(nsw, SIGNAL(closeMe()), this, SLOT(closeSubWidget()));
insertWidget(position, nsw); insertWidget(position, nsw);
d->m_subWidgets.insert(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()); Internal::NavigationSubWidget *original = qobject_cast<Internal::NavigationSubWidget *>(sender());
int pos = indexOf(original) + 1; int pos = indexOf(original) + 1;
insertSubItem(pos, original->factoryIndex()); insertSubItem(pos, factoryIndex);
} }
void NavigationWidget::closeSubWidget() void NavigationWidget::closeSubWidget()

View File

@@ -111,7 +111,7 @@ protected:
private slots: private slots:
void activateSubWidget(); void activateSubWidget();
void splitSubWidget(); void splitSubWidget(int factoryIndex);
void closeSubWidget(); void closeSubWidget();
private: private: