2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
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
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, 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
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
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"
|
|
|
|
|
|
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"
|
2010-09-10 14:13:19 +02:00
|
|
|
#include "uniqueidmanager.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 *)
|
|
|
|
|
|
|
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Core::Internal;
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
NavigationWidget::instance()->setParent(0);
|
|
|
|
|
NavigationWidget::instance()->hide();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationWidget *NavigationWidget::m_instance = 0;
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
NavigationWidget::NavigationWidget(QAction *toggleSideBarAction) :
|
|
|
|
|
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-09 14:35:26 +02:00
|
|
|
m_factoryModel->setSortRole(FactoryPriorityRole);
|
2008-12-02 12:01:29 +01:00
|
|
|
setOrientation(Qt::Vertical);
|
2010-07-15 12:24:03 +02:00
|
|
|
insertSubItem(0, -1); // we don't have any entry to show yet
|
2008-12-02 12:01:29 +01:00
|
|
|
m_instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationWidget::~NavigationWidget()
|
|
|
|
|
{
|
|
|
|
|
m_instance = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationWidget *NavigationWidget::instance()
|
|
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
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()));
|
|
|
|
|
m_shortcutMap.insert(shortcut, id);
|
|
|
|
|
|
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());
|
|
|
|
|
m_commandMap.insert(id, cmd);
|
|
|
|
|
|
|
|
|
|
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-07-15 12:24:03 +02:00
|
|
|
m_factoryModel->appendRow(newRow);
|
|
|
|
|
}
|
2010-09-09 14:35:26 +02:00
|
|
|
m_factoryModel->sort(0);
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
int NavigationWidget::storedWidth()
|
|
|
|
|
{
|
|
|
|
|
return m_width;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
QAbstractItemModel *NavigationWidget::factoryModel() const
|
|
|
|
|
{
|
|
|
|
|
return m_factoryModel;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-08 18:29:44 +01:00
|
|
|
void NavigationWidget::updateToggleText()
|
|
|
|
|
{
|
|
|
|
|
if (isShown())
|
|
|
|
|
m_toggleSideBarAction->setText(tr("Hide Sidebar"));
|
|
|
|
|
else
|
|
|
|
|
m_toggleSideBarAction->setText(tr("Show Sidebar"));
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void NavigationWidget::placeHolderChanged(NavigationWidgetPlaceHolder *holder)
|
|
|
|
|
{
|
|
|
|
|
m_toggleSideBarAction->setEnabled(holder);
|
2009-01-06 17:03:08 +01:00
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
if (m_width && re->size().width())
|
|
|
|
|
m_width = re->size().width();
|
|
|
|
|
MiniSplitter::resizeEvent(re);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
NavigationSubWidget *NavigationWidget::insertSubItem(int position,int index)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-15 12:24:03 +02:00
|
|
|
for (int pos = position + 1; pos < m_subWidgets.size(); ++pos) {
|
|
|
|
|
m_subWidgets.at(pos)->setPosition(pos + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationSubWidget *nsw = new 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);
|
|
|
|
|
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-01-27 19:03:20 +01:00
|
|
|
QString id = 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-07-15 12:24:03 +02:00
|
|
|
foreach (NavigationSubWidget *subWidget, 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) {
|
|
|
|
|
m_subWidgets.first()->setFactoryIndex(index);
|
|
|
|
|
m_subWidgets.first()->setFocusWidget();
|
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
|
NavigationSubWidget *original = qobject_cast<NavigationSubWidget *>(sender());
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
if (m_subWidgets.count() != 1) {
|
|
|
|
|
NavigationSubWidget *subWidget = qobject_cast<NavigationSubWidget *>(sender());
|
2010-07-15 12:24:03 +02:00
|
|
|
subWidget->saveSettings();
|
2008-12-02 12:01:29 +01:00
|
|
|
m_subWidgets.removeOne(subWidget);
|
|
|
|
|
subWidget->hide();
|
|
|
|
|
subWidget->deleteLater();
|
|
|
|
|
} else {
|
|
|
|
|
setShown(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationWidget::saveSettings(QSettings *settings)
|
|
|
|
|
{
|
2010-07-15 12:24:03 +02:00
|
|
|
QStringList viewIds;
|
2008-12-02 12:01:29 +01:00
|
|
|
for (int i=0; i<m_subWidgets.count(); ++i) {
|
2010-07-15 12:24:03 +02:00
|
|
|
m_subWidgets.at(i)->saveSettings();
|
|
|
|
|
viewIds.append(m_subWidgets.at(i)->factory()->id());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-07-15 12:24:03 +02:00
|
|
|
settings->setValue("Navigation/Views", viewIds);
|
2008-12-02 12:01:29 +01:00
|
|
|
settings->setValue("Navigation/Visible", isShown());
|
|
|
|
|
settings->setValue("Navigation/VerticalPosition", saveState());
|
|
|
|
|
settings->setValue("Navigation/Width", m_width);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-11 14:35:14 +01:00
|
|
|
void NavigationWidget::restoreSettings(QSettings *settings)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-03-26 15:54:05 +01:00
|
|
|
int version = settings->value("Navigation/Version", 1).toInt();
|
2010-07-15 12:24:03 +02:00
|
|
|
QStringList viewIds = settings->value("Navigation/Views").toStringList();
|
2009-03-26 15:54:05 +01:00
|
|
|
|
|
|
|
|
bool restoreSplitterState = true;
|
|
|
|
|
if (version == 1) {
|
2010-07-15 12:24:03 +02:00
|
|
|
if (viewIds.isEmpty())
|
|
|
|
|
viewIds += "Projects";
|
|
|
|
|
if (!viewIds.contains("Open Documents")) {
|
|
|
|
|
viewIds += "Open Documents";
|
2009-03-26 15:54:05 +01:00
|
|
|
restoreSplitterState = false;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-03-26 15:54:05 +01:00
|
|
|
settings->setValue("Navigation/Version", 2);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
for (int i=0; i<viewIds.count(); ++i) {
|
|
|
|
|
const QString &view = viewIds.at(i);
|
|
|
|
|
int index = factoryIndex(view);
|
|
|
|
|
|
|
|
|
|
if (i >= m_subWidgets.size()) {
|
|
|
|
|
insertSubItem(i, index);
|
|
|
|
|
} else {
|
|
|
|
|
m_subWidgets.at(i)->setFactoryIndex(index);
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (settings->contains("Navigation/Visible")) {
|
|
|
|
|
setShown(settings->value("Navigation/Visible").toBool());
|
|
|
|
|
} else {
|
|
|
|
|
setShown(true);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-26 15:54:05 +01:00
|
|
|
if (restoreSplitterState && settings->contains("Navigation/VerticalPosition")) {
|
2008-12-02 12:01:29 +01:00
|
|
|
restoreState(settings->value("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
|
|
|
|
|
|
|
|
if (settings->contains("Navigation/Width")) {
|
|
|
|
|
m_width = settings->value("Navigation/Width").toInt();
|
|
|
|
|
if (!m_width)
|
|
|
|
|
m_width = 240;
|
|
|
|
|
} else {
|
|
|
|
|
m_width = 240; //pixel
|
|
|
|
|
}
|
|
|
|
|
// Apply
|
|
|
|
|
if (NavigationWidgetPlaceHolder::m_current) {
|
|
|
|
|
NavigationWidgetPlaceHolder::m_current->applyStoredSize(m_width);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:59:04 +02:00
|
|
|
void NavigationWidget::closeSubWidgets()
|
|
|
|
|
{
|
|
|
|
|
foreach (NavigationSubWidget *subWidget, m_subWidgets) {
|
|
|
|
|
subWidget->saveSettings();
|
|
|
|
|
delete subWidget;
|
|
|
|
|
}
|
|
|
|
|
m_subWidgets.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void NavigationWidget::setShown(bool b)
|
|
|
|
|
{
|
|
|
|
|
if (m_shown == b)
|
|
|
|
|
return;
|
|
|
|
|
m_shown = b;
|
2009-01-06 17:03:08 +01:00
|
|
|
if (NavigationWidgetPlaceHolder::m_current) {
|
2008-12-02 12:01:29 +01:00
|
|
|
NavigationWidgetPlaceHolder::m_current->setVisible(m_shown && !m_suppressed);
|
2009-01-06 17:03:08 +01:00
|
|
|
m_toggleSideBarAction->setChecked(m_shown);
|
|
|
|
|
} else {
|
|
|
|
|
m_toggleSideBarAction->setChecked(false);
|
|
|
|
|
}
|
2009-12-08 18:29:44 +01:00
|
|
|
updateToggleText();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NavigationWidget::isShown() const
|
|
|
|
|
{
|
|
|
|
|
return m_shown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NavigationWidget::isSuppressed() const
|
|
|
|
|
{
|
|
|
|
|
return m_suppressed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationWidget::setSuppressed(bool b)
|
|
|
|
|
{
|
|
|
|
|
if (m_suppressed == b)
|
|
|
|
|
return;
|
|
|
|
|
m_suppressed = b;
|
|
|
|
|
if (NavigationWidgetPlaceHolder::m_current)
|
|
|
|
|
NavigationWidgetPlaceHolder::m_current->setVisible(m_shown && !m_suppressed);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
int NavigationWidget::factoryIndex(const QString &id)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-15 12:24:03 +02:00
|
|
|
for (int row = 0; row < m_factoryModel->rowCount(); ++row) {
|
|
|
|
|
if (m_factoryModel->data(m_factoryModel->index(row, 0), FactoryIdRole).toString() == id) {
|
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////
|
|
|
|
|
// NavigationSubWidget
|
|
|
|
|
////
|
|
|
|
|
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
NavigationSubWidget::NavigationSubWidget(NavigationWidget *parentWidget, int position, int factoryIndex)
|
|
|
|
|
: m_parentWidget(parentWidget),
|
2010-09-09 14:35:26 +02:00
|
|
|
m_position(position)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
m_navigationComboBox = new NavComboBox(this);
|
2009-07-16 15:00:29 +02:00
|
|
|
m_navigationComboBox->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
2010-03-01 14:51:48 +01:00
|
|
|
m_navigationComboBox->setFocusPolicy(Qt::TabFocus);
|
2009-07-16 15:00:29 +02:00
|
|
|
m_navigationComboBox->setMinimumContentsLength(0);
|
2010-07-15 12:24:03 +02:00
|
|
|
m_navigationComboBox->setModel(parentWidget->factoryModel());
|
2008-12-02 12:01:29 +01:00
|
|
|
m_navigationWidget = 0;
|
2010-09-09 14:35:26 +02:00
|
|
|
m_navigationWidgetFactory = 0;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
m_toolBar = new Utils::StyledBar(this);
|
2009-07-16 15:00:29 +02:00
|
|
|
QHBoxLayout *toolBarLayout = new QHBoxLayout;
|
|
|
|
|
toolBarLayout->setMargin(0);
|
|
|
|
|
toolBarLayout->setSpacing(0);
|
|
|
|
|
m_toolBar->setLayout(toolBarLayout);
|
|
|
|
|
toolBarLayout->addWidget(m_navigationComboBox);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-07-16 15:00:29 +02:00
|
|
|
QToolButton *splitAction = new QToolButton();
|
2010-07-30 22:16:59 +02:00
|
|
|
splitAction->setIcon(QIcon(QLatin1String(Constants::ICON_SPLIT_HORIZONTAL)));
|
2009-07-16 15:00:29 +02:00
|
|
|
splitAction->setToolTip(tr("Split"));
|
|
|
|
|
QToolButton *close = new QToolButton();
|
2010-07-30 22:16:59 +02:00
|
|
|
close->setIcon(QIcon(QLatin1String(Constants::ICON_CLOSE)));
|
2009-07-16 15:00:29 +02:00
|
|
|
close->setToolTip(tr("Close"));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-07-16 15:00:29 +02:00
|
|
|
toolBarLayout->addWidget(splitAction);
|
|
|
|
|
toolBarLayout->addWidget(close);
|
2009-02-05 12:44:46 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QVBoxLayout *lay = new QVBoxLayout();
|
|
|
|
|
lay->setMargin(0);
|
|
|
|
|
lay->setSpacing(0);
|
|
|
|
|
setLayout(lay);
|
2009-02-05 12:44:46 +01:00
|
|
|
lay->addWidget(m_toolBar);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-08-20 17:27:33 +02:00
|
|
|
connect(splitAction, SIGNAL(clicked()), this, SIGNAL(splitMe()));
|
|
|
|
|
connect(close, SIGNAL(clicked()), this, SIGNAL(closeMe()));
|
2010-07-15 12:24:03 +02:00
|
|
|
|
|
|
|
|
setFactoryIndex(factoryIndex);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
connect(m_navigationComboBox, SIGNAL(currentIndexChanged(int)),
|
2010-07-15 12:24:03 +02:00
|
|
|
this, SLOT(comboBoxIndexChanged(int)));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
comboBoxIndexChanged(factoryIndex);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationSubWidget::~NavigationSubWidget()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
void NavigationSubWidget::comboBoxIndexChanged(int factoryIndex)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-15 12:24:03 +02:00
|
|
|
saveSettings();
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// Remove toolbutton
|
2009-01-20 11:52:04 +01:00
|
|
|
foreach (QWidget *w, m_additionalToolBarWidgets)
|
2008-12-02 12:01:29 +01:00
|
|
|
delete w;
|
2010-09-09 14:35:26 +02:00
|
|
|
m_additionalToolBarWidgets.clear();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Remove old Widget
|
|
|
|
|
delete m_navigationWidget;
|
2010-09-09 14:35:26 +02:00
|
|
|
m_navigationWidget = 0;
|
|
|
|
|
m_navigationWidgetFactory = 0;
|
2010-07-15 12:24:03 +02:00
|
|
|
if (factoryIndex == -1)
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Get new stuff
|
2010-09-09 14:35:26 +02:00
|
|
|
m_navigationWidgetFactory = m_navigationComboBox->itemData(factoryIndex,
|
|
|
|
|
NavigationWidget::FactoryObjectRole).value<INavigationWidgetFactory *>();
|
|
|
|
|
NavigationView n = m_navigationWidgetFactory->createWidget();
|
2008-12-02 12:01:29 +01:00
|
|
|
m_navigationWidget = n.widget;
|
|
|
|
|
layout()->addWidget(m_navigationWidget);
|
|
|
|
|
|
|
|
|
|
// Add Toolbutton
|
2009-10-09 17:41:09 +02:00
|
|
|
m_additionalToolBarWidgets = n.dockToolBarWidgets;
|
2009-07-16 15:00:29 +02:00
|
|
|
QHBoxLayout *layout = qobject_cast<QHBoxLayout *>(m_toolBar->layout());
|
2008-12-02 12:01:29 +01:00
|
|
|
foreach (QToolButton *w, m_additionalToolBarWidgets) {
|
2009-07-16 15:00:29 +02:00
|
|
|
layout->insertWidget(layout->count()-2, w);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-07-15 12:24:03 +02:00
|
|
|
|
|
|
|
|
restoreSettings();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationSubWidget::setFocusWidget()
|
|
|
|
|
{
|
|
|
|
|
if (m_navigationWidget)
|
|
|
|
|
m_navigationWidget->setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
INavigationWidgetFactory *NavigationSubWidget::factory()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-09 14:35:26 +02:00
|
|
|
return m_navigationWidgetFactory;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
|
|
|
|
|
void NavigationSubWidget::saveSettings()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-15 12:24:03 +02:00
|
|
|
if (!m_navigationWidget || !factory())
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
2010-07-15 12:24:03 +02:00
|
|
|
factory()->saveSettings(position(), m_navigationWidget);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
void NavigationSubWidget::restoreSettings()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-15 12:24:03 +02:00
|
|
|
if (!m_navigationWidget || !factory())
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
2010-07-15 12:24:03 +02:00
|
|
|
factory()->restoreSettings(position(), m_navigationWidget);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
Core::Command *NavigationSubWidget::command(const QString &title) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-15 12:24:03 +02:00
|
|
|
const QHash<QString, Core::Command*> commandMap = m_parentWidget->commandMap();
|
|
|
|
|
QHash<QString, Core::Command*>::const_iterator r = commandMap.find(title);
|
|
|
|
|
if (r != commandMap.end())
|
|
|
|
|
return r.value();
|
|
|
|
|
return 0;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
int NavigationSubWidget::factoryIndex() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-09 14:35:26 +02:00
|
|
|
return m_navigationComboBox->currentIndex();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
void NavigationSubWidget::setFactoryIndex(int i)
|
2008-12-11 14:35:14 +01:00
|
|
|
{
|
2010-07-15 12:24:03 +02:00
|
|
|
m_navigationComboBox->setCurrentIndex(i);
|
2008-12-11 14:35:14 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
int NavigationSubWidget::position() const
|
2008-12-11 14:35:14 +01:00
|
|
|
{
|
2010-07-15 12:24:03 +02:00
|
|
|
return m_position;
|
2008-12-11 14:35:14 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
void NavigationSubWidget::setPosition(int position)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-15 12:24:03 +02:00
|
|
|
m_position = position;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavComboBox::NavComboBox(NavigationSubWidget *navSubWidget)
|
|
|
|
|
: m_navSubWidget(navSubWidget)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NavComboBox::event(QEvent *e)
|
|
|
|
|
{
|
|
|
|
|
if (e->type() == QEvent::ToolTip) {
|
|
|
|
|
QString txt = currentText();
|
2009-01-14 13:17:53 +01:00
|
|
|
Core::Command *cmd = m_navSubWidget->command(txt);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (cmd) {
|
|
|
|
|
txt = tr("Activate %1").arg(txt);
|
|
|
|
|
setToolTip(cmd->stringWithAppendedShortcut(txt));
|
|
|
|
|
} else {
|
|
|
|
|
setToolTip(txt);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QComboBox::event(e);
|
|
|
|
|
}
|