2010-09-16 12:26:28 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2010-09-16 12:26:28 +02:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2010-09-16 12:26:28 +02:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2010-09-16 12:26:28 +02:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-09-16 12:26:28 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "sidebarwidget.h"
|
|
|
|
|
#include "sidebar.h"
|
|
|
|
|
#include "navigationsubwidget.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QToolBar>
|
|
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QAction>
|
|
|
|
|
#include <QVBoxLayout>
|
2010-09-16 12:26:28 +02:00
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class SideBarComboBox : public CommandComboBox
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
enum DataRoles {
|
|
|
|
|
IdRole = Qt::UserRole
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
explicit SideBarComboBox(SideBarWidget *sideBarWidget) : m_sideBarWidget(sideBarWidget) {}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
virtual const Core::Command *command(const QString &text) const
|
|
|
|
|
{ return m_sideBarWidget->command(text); }
|
|
|
|
|
|
|
|
|
|
SideBarWidget *m_sideBarWidget;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SideBarWidget::SideBarWidget(SideBar *sideBar, const QString &id)
|
|
|
|
|
: m_currentItem(0)
|
|
|
|
|
, m_sideBar(sideBar)
|
|
|
|
|
{
|
|
|
|
|
m_comboBox = new SideBarComboBox(this);
|
|
|
|
|
m_comboBox->setMinimumContentsLength(15);
|
|
|
|
|
|
|
|
|
|
m_toolbar = new QToolBar(this);
|
|
|
|
|
m_toolbar->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
m_toolbar->addWidget(m_comboBox);
|
|
|
|
|
|
|
|
|
|
QWidget *spacerItem = new QWidget(this);
|
|
|
|
|
spacerItem->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
|
m_toolbar->addWidget(spacerItem);
|
|
|
|
|
|
|
|
|
|
m_splitAction = new QAction(tr("Split"), m_toolbar);
|
|
|
|
|
m_splitAction->setToolTip(tr("Split"));
|
|
|
|
|
m_splitAction->setIcon(QIcon(QLatin1String(Constants::ICON_SPLIT_HORIZONTAL)));
|
|
|
|
|
connect(m_splitAction, SIGNAL(triggered()), this, SIGNAL(splitMe()));
|
|
|
|
|
m_toolbar->addAction(m_splitAction);
|
|
|
|
|
|
|
|
|
|
QAction *closeAction = new QAction(tr("Close"), m_toolbar);
|
|
|
|
|
closeAction->setToolTip(tr("Close"));
|
2012-02-01 21:39:05 +01:00
|
|
|
closeAction->setIcon(QIcon(QLatin1String(Constants::ICON_CLOSE_SPLIT_TOP)));
|
2010-09-16 12:26:28 +02:00
|
|
|
connect(closeAction, SIGNAL(triggered()), this, SIGNAL(closeMe()));
|
|
|
|
|
m_toolbar->addAction(closeAction);
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *lay = new QVBoxLayout();
|
|
|
|
|
lay->setMargin(0);
|
|
|
|
|
lay->setSpacing(0);
|
|
|
|
|
setLayout(lay);
|
|
|
|
|
lay->addWidget(m_toolbar);
|
|
|
|
|
|
|
|
|
|
QStringList titleList = m_sideBar->availableItemTitles();
|
|
|
|
|
qSort(titleList);
|
|
|
|
|
QString t = id;
|
|
|
|
|
if (titleList.count()) {
|
|
|
|
|
foreach(const QString &itemTitle, titleList)
|
|
|
|
|
m_comboBox->addItem(itemTitle, m_sideBar->idForTitle(itemTitle));
|
|
|
|
|
|
|
|
|
|
m_comboBox->setCurrentIndex(0);
|
|
|
|
|
if (t.isEmpty())
|
|
|
|
|
t = m_comboBox->itemData(0, SideBarComboBox::IdRole).toString();
|
|
|
|
|
}
|
|
|
|
|
setCurrentItem(t);
|
|
|
|
|
|
|
|
|
|
connect(m_comboBox, SIGNAL(currentIndexChanged(int)),
|
|
|
|
|
this, SLOT(setCurrentIndex(int)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SideBarWidget::~SideBarWidget()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SideBarWidget::currentItemTitle() const
|
|
|
|
|
{
|
|
|
|
|
return m_comboBox->currentText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SideBarWidget::currentItemId() const
|
|
|
|
|
{
|
|
|
|
|
if (m_currentItem)
|
|
|
|
|
return m_currentItem->id();
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SideBarWidget::setCurrentItem(const QString &id)
|
|
|
|
|
{
|
|
|
|
|
if (!id.isEmpty()) {
|
|
|
|
|
int idx = m_comboBox->findData(QVariant(id), SideBarComboBox::IdRole);
|
|
|
|
|
|
|
|
|
|
if (idx < 0)
|
|
|
|
|
idx = 0;
|
|
|
|
|
|
|
|
|
|
bool blocked = m_comboBox->blockSignals(true);
|
|
|
|
|
m_comboBox->setCurrentIndex(idx);
|
|
|
|
|
m_comboBox->blockSignals(blocked);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SideBarItem *item = m_sideBar->item(id);
|
|
|
|
|
if (!item)
|
|
|
|
|
return;
|
|
|
|
|
removeCurrentItem();
|
|
|
|
|
m_currentItem = item;
|
|
|
|
|
|
|
|
|
|
layout()->addWidget(m_currentItem->widget());
|
|
|
|
|
m_currentItem->widget()->show();
|
|
|
|
|
|
|
|
|
|
// Add buttons and remember their actions for later removal
|
|
|
|
|
foreach (QToolButton *b, m_currentItem->createToolBarWidgets())
|
|
|
|
|
m_addedToolBarActions.append(m_toolbar->insertWidget(m_splitAction, b));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SideBarWidget::updateAvailableItems()
|
|
|
|
|
{
|
|
|
|
|
bool blocked = m_comboBox->blockSignals(true);
|
|
|
|
|
QString currentTitle = m_comboBox->currentText();
|
|
|
|
|
m_comboBox->clear();
|
|
|
|
|
QStringList titleList = m_sideBar->availableItemTitles();
|
|
|
|
|
if (!currentTitle.isEmpty() && !titleList.contains(currentTitle))
|
|
|
|
|
titleList.append(currentTitle);
|
|
|
|
|
qSort(titleList);
|
|
|
|
|
|
|
|
|
|
foreach(const QString &itemTitle, titleList)
|
|
|
|
|
m_comboBox->addItem(itemTitle, m_sideBar->idForTitle(itemTitle));
|
|
|
|
|
|
|
|
|
|
int idx = m_comboBox->findText(currentTitle);
|
|
|
|
|
|
|
|
|
|
if (idx < 0)
|
|
|
|
|
idx = 0;
|
|
|
|
|
|
|
|
|
|
m_comboBox->setCurrentIndex(idx);
|
|
|
|
|
m_splitAction->setEnabled(titleList.count() > 1);
|
|
|
|
|
m_comboBox->blockSignals(blocked);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SideBarWidget::removeCurrentItem()
|
|
|
|
|
{
|
|
|
|
|
if (!m_currentItem)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QWidget *w = m_currentItem->widget();
|
|
|
|
|
w->hide();
|
|
|
|
|
layout()->removeWidget(w);
|
|
|
|
|
w->setParent(0);
|
|
|
|
|
m_sideBar->makeItemAvailable(m_currentItem);
|
|
|
|
|
|
|
|
|
|
// Delete custom toolbar widgets
|
|
|
|
|
qDeleteAll(m_addedToolBarActions);
|
|
|
|
|
m_addedToolBarActions.clear();
|
|
|
|
|
|
|
|
|
|
m_currentItem = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SideBarWidget::setCurrentIndex(int)
|
|
|
|
|
{
|
|
|
|
|
setCurrentItem(m_comboBox->itemData(m_comboBox->currentIndex(),
|
|
|
|
|
SideBarComboBox::IdRole).toString());
|
|
|
|
|
emit currentWidgetChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::Command *SideBarWidget::command(const QString &id) const
|
|
|
|
|
{
|
|
|
|
|
const QMap<QString, Core::Command*> shortcutMap = m_sideBar->shortcutMap();
|
|
|
|
|
QMap<QString, Core::Command*>::const_iterator r = shortcutMap.find(id);
|
|
|
|
|
if (r != shortcutMap.end())
|
|
|
|
|
return r.value();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Core
|