2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
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.
|
2008-12-02 14:17:16 +01: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-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "navigationwidget.h"
|
2010-09-16 12:26:28 +02:00
|
|
|
#include "navigationsubwidget.h"
|
2009-01-23 13:03:36 +01:00
|
|
|
#include "icore.h"
|
2010-06-25 12:56:16 +02:00
|
|
|
#include "icontext.h"
|
2009-01-23 13:03:36 +01:00
|
|
|
#include "coreconstants.h"
|
|
|
|
|
#include "inavigationwidgetfactory.h"
|
|
|
|
|
#include "modemanager.h"
|
|
|
|
|
#include "actionmanager/actionmanager.h"
|
2010-03-18 10:59:06 +01:00
|
|
|
#include "actionmanager/command.h"
|
2011-09-05 16:10:37 +02:00
|
|
|
#include "id.h"
|
2009-01-23 13:03:36 +01:00
|
|
|
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
2009-10-01 16:38:08 +02:00
|
|
|
#include <utils/styledbar.h>
|
|
|
|
|
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
#include <QtCore/QSettings>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include <QtGui/QAction>
|
|
|
|
|
#include <QtGui/QHBoxLayout>
|
|
|
|
|
#include <QtGui/QResizeEvent>
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <QtGui/QToolButton>
|
2009-10-01 16:38:08 +02:00
|
|
|
#include <QtGui/QShortcut>
|
2010-07-15 12:24:03 +02:00
|
|
|
#include <QtGui/QStandardItemModel>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(Core::INavigationWidgetFactory *)
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
namespace Core {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
NavigationWidgetPlaceHolder *NavigationWidgetPlaceHolder::m_current = 0;
|
|
|
|
|
|
|
|
|
|
NavigationWidgetPlaceHolder* NavigationWidgetPlaceHolder::current()
|
|
|
|
|
{
|
|
|
|
|
return m_current;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationWidgetPlaceHolder::NavigationWidgetPlaceHolder(Core::IMode *mode, QWidget *parent)
|
|
|
|
|
:QWidget(parent), m_mode(mode)
|
|
|
|
|
{
|
|
|
|
|
setLayout(new QVBoxLayout);
|
|
|
|
|
layout()->setMargin(0);
|
|
|
|
|
connect(Core::ModeManager::instance(), SIGNAL(currentModeAboutToChange(Core::IMode *)),
|
|
|
|
|
this, SLOT(currentModeAboutToChange(Core::IMode *)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationWidgetPlaceHolder::~NavigationWidgetPlaceHolder()
|
|
|
|
|
{
|
|
|
|
|
if (m_current == this) {
|
2011-03-15 14:52:35 +01:00
|
|
|
if (NavigationWidget *nw = NavigationWidget::instance()) {
|
|
|
|
|
nw->setParent(0);
|
|
|
|
|
nw->hide();
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationWidgetPlaceHolder::applyStoredSize(int width)
|
|
|
|
|
{
|
|
|
|
|
if (width) {
|
|
|
|
|
QSplitter *splitter = qobject_cast<QSplitter *>(parentWidget());
|
|
|
|
|
if (splitter) {
|
|
|
|
|
// A splitter we need to resize the splitter sizes
|
|
|
|
|
QList<int> sizes = splitter->sizes();
|
|
|
|
|
int index = splitter->indexOf(this);
|
|
|
|
|
int diff = width - sizes.at(index);
|
2008-12-09 11:07:24 +01:00
|
|
|
int adjust = sizes.count() > 1 ? (diff / (sizes.count() - 1)) : 0;
|
|
|
|
|
for (int i = 0; i < sizes.count(); ++i) {
|
2008-12-02 12:01:29 +01:00
|
|
|
if (i != index)
|
|
|
|
|
sizes[i] += adjust;
|
|
|
|
|
}
|
|
|
|
|
sizes[index]= width;
|
|
|
|
|
splitter->setSizes(sizes);
|
|
|
|
|
} else {
|
|
|
|
|
QSize s = size();
|
|
|
|
|
s.setWidth(width);
|
|
|
|
|
resize(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This function does work even though the order in which
|
|
|
|
|
// the placeHolder get the signal is undefined.
|
|
|
|
|
// It does ensure that after all PlaceHolders got the signal
|
|
|
|
|
// m_current points to the current PlaceHolder, or zero if there
|
|
|
|
|
// is no PlaceHolder in this mode
|
|
|
|
|
// And that the parent of the NavigationWidget gets the correct parent
|
|
|
|
|
void NavigationWidgetPlaceHolder::currentModeAboutToChange(Core::IMode *mode)
|
|
|
|
|
{
|
|
|
|
|
NavigationWidget *navigationWidget = NavigationWidget::instance();
|
|
|
|
|
|
|
|
|
|
if (m_current == this) {
|
|
|
|
|
m_current = 0;
|
|
|
|
|
navigationWidget->setParent(0);
|
|
|
|
|
navigationWidget->hide();
|
|
|
|
|
navigationWidget->placeHolderChanged(m_current);
|
|
|
|
|
}
|
|
|
|
|
if (m_mode == mode) {
|
|
|
|
|
m_current = this;
|
|
|
|
|
|
|
|
|
|
int width = navigationWidget->storedWidth();
|
|
|
|
|
|
|
|
|
|
layout()->addWidget(navigationWidget);
|
|
|
|
|
navigationWidget->show();
|
|
|
|
|
|
|
|
|
|
applyStoredSize(width);
|
|
|
|
|
setVisible(navigationWidget->isShown());
|
|
|
|
|
navigationWidget->placeHolderChanged(m_current);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
struct NavigationWidgetPrivate {
|
|
|
|
|
explicit NavigationWidgetPrivate(QAction *toggleSideBarAction);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
QList<Internal::NavigationSubWidget *> m_subWidgets;
|
|
|
|
|
QHash<QShortcut *, QString> m_shortcutMap;
|
|
|
|
|
QHash<QString, Core::Command*> m_commandMap;
|
|
|
|
|
QStandardItemModel *m_factoryModel;
|
|
|
|
|
|
|
|
|
|
bool m_shown;
|
|
|
|
|
bool m_suppressed;
|
|
|
|
|
int m_width;
|
|
|
|
|
static NavigationWidget* m_instance;
|
|
|
|
|
QAction *m_toggleSideBarAction;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
NavigationWidgetPrivate::NavigationWidgetPrivate(QAction *toggleSideBarAction) :
|
2010-07-15 12:24:03 +02:00
|
|
|
m_factoryModel(new QStandardItemModel),
|
|
|
|
|
m_shown(true),
|
|
|
|
|
m_suppressed(false),
|
|
|
|
|
m_width(0),
|
|
|
|
|
m_toggleSideBarAction(toggleSideBarAction)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationWidget *NavigationWidgetPrivate::m_instance = 0;
|
|
|
|
|
|
|
|
|
|
NavigationWidget::NavigationWidget(QAction *toggleSideBarAction) :
|
|
|
|
|
d(new NavigationWidgetPrivate(toggleSideBarAction))
|
|
|
|
|
{
|
|
|
|
|
d->m_factoryModel->setSortRole(FactoryPriorityRole);
|
2008-12-02 12:01:29 +01:00
|
|
|
setOrientation(Qt::Vertical);
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_instance = this;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationWidget::~NavigationWidget()
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
NavigationWidgetPrivate::m_instance = 0;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationWidget *NavigationWidget::instance()
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
return NavigationWidgetPrivate::m_instance;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
void NavigationWidget::setFactories(const QList<INavigationWidgetFactory *> factories)
|
|
|
|
|
{
|
|
|
|
|
ICore *core = ICore::instance();
|
|
|
|
|
ActionManager *am = core->actionManager();
|
|
|
|
|
Context navicontext(Core::Constants::C_NAVIGATION_PANE);
|
|
|
|
|
|
|
|
|
|
foreach (INavigationWidgetFactory *factory, factories) {
|
|
|
|
|
const QString id = factory->id();
|
|
|
|
|
|
|
|
|
|
QShortcut *shortcut = new QShortcut(this);
|
|
|
|
|
shortcut->setWhatsThis(tr("Activate %1 Pane").arg(factory->displayName()));
|
|
|
|
|
connect(shortcut, SIGNAL(activated()), this, SLOT(activateSubWidget()));
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_shortcutMap.insert(shortcut, id);
|
2010-07-15 12:24:03 +02:00
|
|
|
|
2010-09-10 14:13:19 +02:00
|
|
|
Command *cmd = am->registerShortcut(shortcut,
|
|
|
|
|
Id(QLatin1String("QtCreator.Sidebar.") + id), navicontext);
|
2010-07-15 12:24:03 +02:00
|
|
|
cmd->setDefaultKeySequence(factory->activationSequence());
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_commandMap.insert(id, cmd);
|
2010-07-15 12:24:03 +02:00
|
|
|
|
|
|
|
|
QStandardItem *newRow = new QStandardItem(factory->displayName());
|
|
|
|
|
newRow->setData(qVariantFromValue(factory), FactoryObjectRole);
|
|
|
|
|
newRow->setData(factory->id(), FactoryIdRole);
|
2010-09-09 14:35:26 +02:00
|
|
|
newRow->setData(factory->priority(), FactoryPriorityRole);
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_factoryModel->appendRow(newRow);
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_factoryModel->sort(0);
|
2011-01-31 15:18:16 +01:00
|
|
|
updateToggleText();
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
int NavigationWidget::storedWidth()
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_width;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
QAbstractItemModel *NavigationWidget::factoryModel() const
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_factoryModel;
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
2009-12-08 18:29:44 +01:00
|
|
|
void NavigationWidget::updateToggleText()
|
|
|
|
|
{
|
2010-10-21 17:49:19 +02:00
|
|
|
bool haveData = d->m_factoryModel->rowCount();
|
|
|
|
|
d->m_toggleSideBarAction->setVisible(haveData);
|
2011-01-31 15:18:16 +01:00
|
|
|
d->m_toggleSideBarAction->setEnabled(haveData && NavigationWidgetPlaceHolder::m_current);
|
2010-10-21 17:49:19 +02:00
|
|
|
|
2009-12-08 18:29:44 +01:00
|
|
|
if (isShown())
|
2010-10-19 17:28:52 +02:00
|
|
|
d->m_toggleSideBarAction->setToolTip(tr("Hide Sidebar"));
|
2009-12-08 18:29:44 +01:00
|
|
|
else
|
2010-10-19 17:28:52 +02:00
|
|
|
d->m_toggleSideBarAction->setToolTip(tr("Show Sidebar"));
|
2009-12-08 18:29:44 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void NavigationWidget::placeHolderChanged(NavigationWidgetPlaceHolder *holder)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_toggleSideBarAction->setChecked(holder && isShown());
|
2009-12-08 18:29:44 +01:00
|
|
|
updateToggleText();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationWidget::resizeEvent(QResizeEvent *re)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_width && re->size().width())
|
|
|
|
|
d->m_width = re->size().width();
|
2008-12-02 12:01:29 +01:00
|
|
|
MiniSplitter::resizeEvent(re);
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
Internal::NavigationSubWidget *NavigationWidget::insertSubItem(int position,int index)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
for (int pos = position + 1; pos < d->m_subWidgets.size(); ++pos) {
|
|
|
|
|
d->m_subWidgets.at(pos)->setPosition(pos + 1);
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
Internal::NavigationSubWidget *nsw = new Internal::NavigationSubWidget(this, position, index);
|
2009-08-20 17:27:33 +02:00
|
|
|
connect(nsw, SIGNAL(splitMe()), this, SLOT(splitSubWidget()));
|
|
|
|
|
connect(nsw, SIGNAL(closeMe()), this, SLOT(closeSubWidget()));
|
2008-12-02 12:01:29 +01:00
|
|
|
insertWidget(position, nsw);
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_subWidgets.insert(position, nsw);
|
2010-07-15 12:24:03 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
return nsw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationWidget::activateSubWidget()
|
|
|
|
|
{
|
|
|
|
|
QShortcut *original = qobject_cast<QShortcut *>(sender());
|
2010-09-16 12:26:28 +02:00
|
|
|
QString id = d->m_shortcutMap[original];
|
2010-08-13 10:10:43 +02:00
|
|
|
activateSubWidget(id);
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-08-13 10:10:43 +02:00
|
|
|
void NavigationWidget::activateSubWidget(const QString &factoryId)
|
|
|
|
|
{
|
|
|
|
|
setShown(true);
|
2010-09-16 12:26:28 +02:00
|
|
|
foreach (Internal::NavigationSubWidget *subWidget, d->m_subWidgets) {
|
2010-08-13 10:10:43 +02:00
|
|
|
if (subWidget->factory()->id() == factoryId) {
|
2008-12-02 12:01:29 +01:00
|
|
|
subWidget->setFocusWidget();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-08-13 10:10:43 +02:00
|
|
|
int index = factoryIndex(factoryId);
|
2010-07-15 12:24:03 +02:00
|
|
|
if (index >= 0) {
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_subWidgets.first()->setFactoryIndex(index);
|
|
|
|
|
d->m_subWidgets.first()->setFocusWidget();
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-08-20 17:27:33 +02:00
|
|
|
void NavigationWidget::splitSubWidget()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
Internal::NavigationSubWidget *original = qobject_cast<Internal::NavigationSubWidget *>(sender());
|
2008-12-02 12:01:29 +01:00
|
|
|
int pos = indexOf(original) + 1;
|
2010-07-15 12:24:03 +02:00
|
|
|
insertSubItem(pos, original->factoryIndex());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-08-20 17:27:33 +02:00
|
|
|
void NavigationWidget::closeSubWidget()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_subWidgets.count() != 1) {
|
|
|
|
|
Internal::NavigationSubWidget *subWidget = qobject_cast<Internal::NavigationSubWidget *>(sender());
|
2010-07-15 12:24:03 +02:00
|
|
|
subWidget->saveSettings();
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_subWidgets.removeOne(subWidget);
|
2008-12-02 12:01:29 +01:00
|
|
|
subWidget->hide();
|
|
|
|
|
subWidget->deleteLater();
|
|
|
|
|
} else {
|
|
|
|
|
setShown(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationWidget::saveSettings(QSettings *settings)
|
|
|
|
|
{
|
2010-07-15 12:24:03 +02:00
|
|
|
QStringList viewIds;
|
2010-09-16 12:26:28 +02:00
|
|
|
for (int i=0; i<d->m_subWidgets.count(); ++i) {
|
|
|
|
|
d->m_subWidgets.at(i)->saveSettings();
|
|
|
|
|
viewIds.append(d->m_subWidgets.at(i)->factory()->id());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-10-21 11:56:25 +02:00
|
|
|
settings->setValue(QLatin1String("Navigation/Views"), viewIds);
|
|
|
|
|
settings->setValue(QLatin1String("Navigation/Visible"), isShown());
|
|
|
|
|
settings->setValue(QLatin1String("Navigation/VerticalPosition"), saveState());
|
|
|
|
|
settings->setValue(QLatin1String("Navigation/Width"), d->m_width);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-11 14:35:14 +01:00
|
|
|
void NavigationWidget::restoreSettings(QSettings *settings)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-10-21 17:49:19 +02:00
|
|
|
if (!d->m_factoryModel->rowCount()) {
|
|
|
|
|
// We have no widgets to show!
|
|
|
|
|
setShown(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-21 11:56:25 +02:00
|
|
|
int version = settings->value(QLatin1String("Navigation/Version"), 1).toInt();
|
|
|
|
|
QStringList viewIds = settings->value(QLatin1String("Navigation/Views"),
|
|
|
|
|
QStringList("Projects")).toStringList();
|
2009-03-26 15:54:05 +01:00
|
|
|
|
|
|
|
|
bool restoreSplitterState = true;
|
|
|
|
|
if (version == 1) {
|
2010-10-21 11:56:25 +02:00
|
|
|
if (!viewIds.contains(QLatin1String("Open Documents"))) {
|
|
|
|
|
viewIds += QLatin1String("Open Documents");
|
2009-03-26 15:54:05 +01:00
|
|
|
restoreSplitterState = false;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-10-21 11:56:25 +02:00
|
|
|
settings->setValue(QLatin1String("Navigation/Version"), 2);
|
2009-03-26 15:54:05 +01:00
|
|
|
}
|
|
|
|
|
|
2010-10-21 11:54:11 +02:00
|
|
|
int position = 0;
|
|
|
|
|
foreach (const QString &id, viewIds) {
|
|
|
|
|
int index = factoryIndex(id);
|
|
|
|
|
if (index >= 0) {
|
|
|
|
|
// Only add if the id was actually found!
|
|
|
|
|
insertSubItem(position, index);
|
|
|
|
|
++position;
|
2010-07-15 12:24:03 +02:00
|
|
|
} else {
|
2010-10-21 11:54:11 +02:00
|
|
|
restoreSplitterState = false;
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-10-21 11:54:11 +02:00
|
|
|
if (d->m_subWidgets.isEmpty())
|
|
|
|
|
// Make sure we have at least the projects widget
|
|
|
|
|
insertSubItem(0, qMax(0, factoryIndex(QLatin1String("Projects"))));
|
|
|
|
|
|
2010-10-21 11:56:25 +02:00
|
|
|
setShown(settings->value(QLatin1String("Navigation/Visible"), true).toBool());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-10-21 11:56:25 +02:00
|
|
|
if (restoreSplitterState && settings->contains(QLatin1String("Navigation/VerticalPosition"))) {
|
|
|
|
|
restoreState(settings->value(QLatin1String("Navigation/VerticalPosition")).toByteArray());
|
2009-03-26 15:54:05 +01:00
|
|
|
} else {
|
|
|
|
|
QList<int> sizes;
|
|
|
|
|
sizes += 256;
|
2010-07-15 12:24:03 +02:00
|
|
|
for (int i = viewIds.size()-1; i > 0; --i)
|
2009-03-26 15:54:05 +01:00
|
|
|
sizes.prepend(512);
|
|
|
|
|
setSizes(sizes);
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-10-21 11:56:25 +02:00
|
|
|
d->m_width = settings->value(QLatin1String("Navigation/Width"), 240).toInt();
|
2010-10-25 12:06:14 +02:00
|
|
|
if (d->m_width < 40)
|
|
|
|
|
d->m_width = 40;
|
2010-10-21 11:56:25 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// Apply
|
2010-10-21 11:56:25 +02:00
|
|
|
if (NavigationWidgetPlaceHolder::m_current)
|
2010-09-16 12:26:28 +02:00
|
|
|
NavigationWidgetPlaceHolder::m_current->applyStoredSize(d->m_width);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:59:04 +02:00
|
|
|
void NavigationWidget::closeSubWidgets()
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
foreach (Internal::NavigationSubWidget *subWidget, d->m_subWidgets) {
|
2010-08-11 14:59:04 +02:00
|
|
|
subWidget->saveSettings();
|
|
|
|
|
delete subWidget;
|
|
|
|
|
}
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_subWidgets.clear();
|
2010-08-11 14:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void NavigationWidget::setShown(bool b)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_shown == b)
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
2010-10-21 17:49:19 +02:00
|
|
|
bool haveData = d->m_factoryModel->rowCount();
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_shown = b;
|
2009-01-06 17:03:08 +01:00
|
|
|
if (NavigationWidgetPlaceHolder::m_current) {
|
2010-10-21 17:49:19 +02:00
|
|
|
NavigationWidgetPlaceHolder::m_current->setVisible(d->m_shown && !d->m_suppressed && haveData);
|
|
|
|
|
d->m_toggleSideBarAction->setChecked(d->m_shown && !d->m_suppressed && haveData);
|
2009-01-06 17:03:08 +01:00
|
|
|
} else {
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_toggleSideBarAction->setChecked(false);
|
2009-01-06 17:03:08 +01:00
|
|
|
}
|
2009-12-08 18:29:44 +01:00
|
|
|
updateToggleText();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NavigationWidget::isShown() const
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_shown;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NavigationWidget::isSuppressed() const
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_suppressed;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationWidget::setSuppressed(bool b)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_suppressed == b)
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_suppressed = b;
|
2008-12-02 12:01:29 +01:00
|
|
|
if (NavigationWidgetPlaceHolder::m_current)
|
2010-09-16 12:26:28 +02:00
|
|
|
NavigationWidgetPlaceHolder::m_current->setVisible(d->m_shown && !d->m_suppressed);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
int NavigationWidget::factoryIndex(const QString &id)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
for (int row = 0; row < d->m_factoryModel->rowCount(); ++row) {
|
|
|
|
|
if (d->m_factoryModel->data(d->m_factoryModel->index(row, 0), FactoryIdRole).toString() == id) {
|
2010-07-15 12:24:03 +02:00
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
QHash<QString, Core::Command*> NavigationWidget::commandMap() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_commandMap;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
} // namespace Core
|