2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
|
|
|
|
**
|
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
|
|
|
|
|
** contact the sales department at qt-sales@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"
|
|
|
|
|
|
2009-01-23 13:03:36 +01:00
|
|
|
#include "icore.h"
|
|
|
|
|
#include "coreconstants.h"
|
|
|
|
|
#include "inavigationwidgetfactory.h"
|
|
|
|
|
#include "modemanager.h"
|
|
|
|
|
#include "uniqueidmanager.h"
|
|
|
|
|
#include "actionmanager/actionmanager.h"
|
|
|
|
|
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
|
|
|
|
#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/QToolBar>
|
|
|
|
|
#include <QtGui/QToolButton>
|
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;
|
|
|
|
|
|
|
|
|
|
NavigationWidget::NavigationWidget(QAction *toggleSideBarAction)
|
2008-12-02 14:09:21 +01:00
|
|
|
: m_shown(true),
|
|
|
|
|
m_suppressed(false),
|
|
|
|
|
m_width(0),
|
|
|
|
|
m_toggleSideBarAction(toggleSideBarAction)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
connect(ExtensionSystem::PluginManager::instance(), SIGNAL(objectAdded(QObject*)),
|
|
|
|
|
this, SLOT(objectAdded(QObject*)));
|
|
|
|
|
|
|
|
|
|
setOrientation(Qt::Vertical);
|
|
|
|
|
insertSubItem(0);
|
|
|
|
|
m_instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationWidget::~NavigationWidget()
|
|
|
|
|
{
|
|
|
|
|
m_instance = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationWidget *NavigationWidget::instance()
|
|
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int NavigationWidget::storedWidth()
|
|
|
|
|
{
|
|
|
|
|
return m_width;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationWidget::placeHolderChanged(NavigationWidgetPlaceHolder *holder)
|
|
|
|
|
{
|
|
|
|
|
m_toggleSideBarAction->setEnabled(holder);
|
2009-01-06 17:03:08 +01:00
|
|
|
m_toggleSideBarAction->setChecked(holder && isShown());
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationSubWidget *NavigationWidget::insertSubItem(int position)
|
|
|
|
|
{
|
|
|
|
|
NavigationSubWidget *nsw = new NavigationSubWidget(this);
|
|
|
|
|
connect(nsw, SIGNAL(split()), this, SLOT(split()));
|
|
|
|
|
connect(nsw, SIGNAL(close()), this, SLOT(close()));
|
|
|
|
|
insertWidget(position, nsw);
|
|
|
|
|
m_subWidgets.insert(position, nsw);
|
|
|
|
|
return nsw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationWidget::activateSubWidget()
|
|
|
|
|
{
|
2009-06-11 11:43:57 +02:00
|
|
|
setShown(true);
|
2008-12-02 12:01:29 +01:00
|
|
|
QShortcut *original = qobject_cast<QShortcut *>(sender());
|
|
|
|
|
QString title = m_shortcutMap[original];
|
|
|
|
|
|
|
|
|
|
foreach (NavigationSubWidget *subWidget, m_subWidgets)
|
|
|
|
|
if (subWidget->factory()->displayName() == title) {
|
|
|
|
|
subWidget->setFocusWidget();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_subWidgets.first()->setFactory(title);
|
|
|
|
|
m_subWidgets.first()->setFocusWidget();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationWidget::split()
|
|
|
|
|
{
|
|
|
|
|
NavigationSubWidget *original = qobject_cast<NavigationSubWidget *>(sender());
|
|
|
|
|
int pos = indexOf(original) + 1;
|
|
|
|
|
NavigationSubWidget *newnsw = insertSubItem(pos);
|
|
|
|
|
newnsw->setFactory(original->factory());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationWidget::close()
|
|
|
|
|
{
|
|
|
|
|
if (m_subWidgets.count() != 1) {
|
|
|
|
|
NavigationSubWidget *subWidget = qobject_cast<NavigationSubWidget *>(sender());
|
|
|
|
|
m_subWidgets.removeOne(subWidget);
|
|
|
|
|
subWidget->hide();
|
|
|
|
|
subWidget->deleteLater();
|
|
|
|
|
} else {
|
|
|
|
|
setShown(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-11 14:35:14 +01:00
|
|
|
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void NavigationWidget::saveSettings(QSettings *settings)
|
|
|
|
|
{
|
|
|
|
|
QStringList views;
|
|
|
|
|
for (int i=0; i<m_subWidgets.count(); ++i) {
|
|
|
|
|
views.append(m_subWidgets.at(i)->factory()->displayName());
|
|
|
|
|
}
|
|
|
|
|
settings->setValue("Navigation/Views", views);
|
|
|
|
|
settings->setValue("Navigation/Visible", isShown());
|
|
|
|
|
settings->setValue("Navigation/VerticalPosition", saveState());
|
|
|
|
|
settings->setValue("Navigation/Width", m_width);
|
2008-12-11 14:35:14 +01:00
|
|
|
|
|
|
|
|
for (int i=0; i<m_subWidgets.count(); ++i)
|
|
|
|
|
m_subWidgets.at(i)->saveSettings(i);
|
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
|
|
|
{
|
2009-03-26 15:54:05 +01:00
|
|
|
int version = settings->value("Navigation/Version", 1).toInt();
|
|
|
|
|
QStringList views = settings->value("Navigation/Views").toStringList();
|
|
|
|
|
|
|
|
|
|
bool restoreSplitterState = true;
|
|
|
|
|
if (version == 1) {
|
|
|
|
|
if (views.isEmpty())
|
|
|
|
|
views += "Projects";
|
|
|
|
|
if (!views.contains("Open Documents")) {
|
|
|
|
|
views += "Open Documents";
|
|
|
|
|
restoreSplitterState = false;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-03-26 15:54:05 +01:00
|
|
|
settings->setValue("Navigation/Version", 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i=0; i<views.count()-1; ++i) {
|
|
|
|
|
insertSubItem(0);
|
|
|
|
|
}
|
|
|
|
|
for (int i=0; i<views.count(); ++i) {
|
|
|
|
|
const QString &view = views.at(i);
|
|
|
|
|
NavigationSubWidget *nsw = m_subWidgets.at(i);
|
|
|
|
|
nsw->setFactory(view);
|
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;
|
2009-04-02 18:54:14 +02:00
|
|
|
for (int i = views.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);
|
|
|
|
|
}
|
2008-12-11 14:35:14 +01:00
|
|
|
|
|
|
|
|
for (int i=0; i<m_subWidgets.count(); ++i)
|
|
|
|
|
m_subWidgets.at(i)->restoreSettings(i);
|
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);
|
|
|
|
|
}
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationWidget::objectAdded(QObject * obj)
|
|
|
|
|
{
|
|
|
|
|
INavigationWidgetFactory *factory = Aggregation::query<INavigationWidgetFactory>(obj);
|
|
|
|
|
if (!factory)
|
|
|
|
|
return;
|
|
|
|
|
|
2009-01-20 11:52:04 +01:00
|
|
|
ICore *core = ICore::instance();
|
|
|
|
|
ActionManager *am = core->actionManager();
|
2008-12-02 12:01:29 +01:00
|
|
|
QList<int> navicontext = QList<int>() << core->uniqueIDManager()->
|
|
|
|
|
uniqueIdentifier(Core::Constants::C_NAVIGATION_PANE);
|
|
|
|
|
|
|
|
|
|
QString displayName = factory->displayName();
|
|
|
|
|
QShortcut *shortcut = new QShortcut(this);
|
|
|
|
|
shortcut->setWhatsThis(tr("Activate %1 Pane").arg(displayName));
|
2009-01-14 13:17:53 +01:00
|
|
|
Core::Command *cmd = am->registerShortcut(shortcut,
|
2009-02-20 17:22:16 +01:00
|
|
|
QLatin1String("QtCreator.Sidebar.") + displayName, navicontext);
|
2008-12-02 12:01:29 +01:00
|
|
|
cmd->setDefaultKeySequence(factory->activationSequence());
|
|
|
|
|
connect(shortcut, SIGNAL(activated()), this, SLOT(activateSubWidget()));
|
|
|
|
|
|
|
|
|
|
m_shortcutMap.insert(shortcut, displayName);
|
|
|
|
|
m_commandMap.insert(displayName, cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////
|
|
|
|
|
// NavigationSubWidget
|
|
|
|
|
////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NavigationSubWidget::NavigationSubWidget(NavigationWidget *parentWidget)
|
|
|
|
|
: m_parentWidget(parentWidget)
|
|
|
|
|
{
|
|
|
|
|
connect(ExtensionSystem::PluginManager::instance(), SIGNAL(objectAdded(QObject*)),
|
|
|
|
|
this, SLOT(objectAdded(QObject*)));
|
|
|
|
|
connect(ExtensionSystem::PluginManager::instance(), SIGNAL(aboutToRemoveObject(QObject*)),
|
|
|
|
|
this, SLOT(aboutToRemoveObject(QObject*)));
|
|
|
|
|
|
|
|
|
|
m_navigationComboBox = new NavComboBox(this);
|
|
|
|
|
m_navigationWidget = 0;
|
2009-06-03 20:45:49 +02:00
|
|
|
#ifdef Q_WS_MAC
|
2008-12-11 15:07:14 +01:00
|
|
|
// this is to avoid ugly tool bar behavior
|
|
|
|
|
m_navigationComboBox->setMaximumWidth(130);
|
|
|
|
|
#endif
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-02-05 12:44:46 +01:00
|
|
|
m_toolBar = new QToolBar(this);
|
|
|
|
|
m_toolBar->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
m_toolBar->addWidget(m_navigationComboBox);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-02-05 12:44:46 +01:00
|
|
|
m_splitAction = new QAction(QIcon(":/core/images/splitbutton_horizontal.png"), tr("Split"), this);
|
|
|
|
|
QAction *close = new QAction(QIcon(":/core/images/closebutton.png"), tr("Close"), this);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QWidget *spacerItem = new QWidget(this);
|
|
|
|
|
spacerItem->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
2009-02-05 12:44:46 +01:00
|
|
|
m_toolBar->addWidget(spacerItem);
|
|
|
|
|
m_toolBar->addAction(m_splitAction);
|
|
|
|
|
m_toolBar->addAction(close);
|
|
|
|
|
|
|
|
|
|
m_toolBar->widgetForAction(m_splitAction)->setProperty("type", QLatin1String("dockbutton"));
|
|
|
|
|
m_toolBar->widgetForAction(close)->setProperty("type", QLatin1String("dockbutton"));
|
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-02-05 12:44:46 +01:00
|
|
|
connect(m_splitAction, SIGNAL(triggered()), this, SIGNAL(split()));
|
|
|
|
|
connect(close, SIGNAL(triggered()), this, SIGNAL(close()));
|
2008-12-02 12:01:29 +01:00
|
|
|
connect(m_navigationComboBox, SIGNAL(currentIndexChanged(int)),
|
|
|
|
|
this, SLOT(setCurrentIndex(int)));
|
|
|
|
|
|
|
|
|
|
foreach (INavigationWidgetFactory *factory, ExtensionSystem::PluginManager::instance()->getObjects<INavigationWidgetFactory>()) {
|
|
|
|
|
QVariant v;
|
|
|
|
|
v.setValue(factory);
|
|
|
|
|
m_navigationComboBox->addItem(factory->displayName(), v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationSubWidget::~NavigationSubWidget()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationSubWidget::setCurrentIndex(int index)
|
|
|
|
|
{
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
// Remove old Widget
|
|
|
|
|
delete m_navigationWidget;
|
|
|
|
|
if (index == -1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Get new stuff
|
|
|
|
|
INavigationWidgetFactory *factory = m_navigationComboBox->itemData(index).value<INavigationWidgetFactory *>();
|
|
|
|
|
NavigationView n = factory->createWidget();
|
|
|
|
|
m_navigationWidget = n.widget;
|
|
|
|
|
layout()->addWidget(m_navigationWidget);
|
|
|
|
|
|
|
|
|
|
// Add Toolbutton
|
|
|
|
|
m_additionalToolBarWidgets = n.doockToolBarWidgets;
|
|
|
|
|
foreach (QToolButton *w, m_additionalToolBarWidgets) {
|
2009-02-05 12:44:46 +01:00
|
|
|
m_toolBar->insertWidget(m_splitAction, w);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationSubWidget::setFocusWidget()
|
|
|
|
|
{
|
|
|
|
|
if (m_navigationWidget)
|
|
|
|
|
m_navigationWidget->setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationSubWidget::objectAdded(QObject * obj)
|
|
|
|
|
{
|
|
|
|
|
INavigationWidgetFactory *factory = Aggregation::query<INavigationWidgetFactory>(obj);
|
|
|
|
|
if (!factory)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QVariant v;
|
|
|
|
|
v.setValue(factory);
|
|
|
|
|
m_navigationComboBox->addItem(factory->displayName(), v);
|
|
|
|
|
//qDebug()<<"added factory :"<<factory<<m_navigationComboBox->findData(v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationSubWidget::aboutToRemoveObject(QObject *obj)
|
|
|
|
|
{
|
|
|
|
|
INavigationWidgetFactory *factory = Aggregation::query<INavigationWidgetFactory>(obj);
|
|
|
|
|
if (!factory)
|
|
|
|
|
return;
|
|
|
|
|
QVariant v;
|
|
|
|
|
v.setValue(factory);
|
|
|
|
|
int index = m_navigationComboBox->findData(v);
|
|
|
|
|
if (index == -1) {
|
|
|
|
|
qDebug()<<"factory not found not removing" << factory;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_navigationComboBox->removeItem(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationSubWidget::setFactory(INavigationWidgetFactory *factory)
|
|
|
|
|
{
|
|
|
|
|
QVariant v;
|
|
|
|
|
v.setValue(factory);
|
|
|
|
|
int index = m_navigationComboBox->findData(v);
|
|
|
|
|
if (index == -1)
|
|
|
|
|
return;
|
|
|
|
|
m_navigationComboBox->setCurrentIndex(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationSubWidget::setFactory(const QString &name)
|
|
|
|
|
{
|
2009-01-20 11:52:04 +01:00
|
|
|
for (int i = 0; i < m_navigationComboBox->count(); ++i) {
|
2008-12-02 12:01:29 +01:00
|
|
|
INavigationWidgetFactory *factory =
|
|
|
|
|
m_navigationComboBox->itemData(i).value<INavigationWidgetFactory *>();
|
|
|
|
|
if (factory->displayName() == name)
|
|
|
|
|
m_navigationComboBox->setCurrentIndex(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
INavigationWidgetFactory *NavigationSubWidget::factory()
|
|
|
|
|
{
|
|
|
|
|
int index = m_navigationComboBox->currentIndex();
|
|
|
|
|
if (index == -1)
|
|
|
|
|
return 0;
|
|
|
|
|
return m_navigationComboBox->itemData(index).value<INavigationWidgetFactory *>();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-11 14:35:14 +01:00
|
|
|
void NavigationSubWidget::saveSettings(int position)
|
|
|
|
|
{
|
|
|
|
|
factory()->saveSettings(position, m_navigationWidget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationSubWidget::restoreSettings(int position)
|
|
|
|
|
{
|
|
|
|
|
factory()->restoreSettings(position, m_navigationWidget);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 13:17:53 +01:00
|
|
|
Core::Command *NavigationSubWidget::command(const QString &title) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-14 13:17:53 +01:00
|
|
|
const QHash<QString, Core::Command*> commandMap = m_parentWidget->commandMap();
|
|
|
|
|
QHash<QString, Core::Command*>::const_iterator r = commandMap.find(title);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (r != commandMap.end())
|
|
|
|
|
return r.value();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|