Commit 5864d9d7 authored by con's avatar con

Make it possible to disable modes.

parent 0ac0d532
......@@ -78,7 +78,8 @@ SOURCES += mainwindow.cpp \
dialogs/ioptionspage.cpp \
dialogs/iwizard.cpp \
settingsdatabase.cpp \
eventfilteringmainwindow.cpp
eventfilteringmainwindow.cpp \
imode.cpp
HEADERS += mainwindow.h \
editmode.h \
tabpositionindicator.h \
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** 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.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "imode.h"
using namespace Core;
IMode::IMode(QObject *parent)
: IContext(parent),
m_isEnabled(true)
{
}
void IMode::setEnabled(bool enabled)
{
if (m_isEnabled == enabled)
return;
m_isEnabled = enabled;
emit enabledStateChanged(m_isEnabled);
}
bool IMode::isEnabled() const
{
return m_isEnabled;
}
......@@ -43,14 +43,24 @@ namespace Core {
class CORE_EXPORT IMode : public IContext
{
Q_OBJECT
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
public:
IMode(QObject *parent = 0) : IContext(parent) {}
IMode(QObject *parent = 0);
virtual ~IMode() {}
virtual QString displayName() const = 0;
virtual QIcon icon() const = 0;
virtual int priority() const = 0;
virtual QString id() const = 0;
void setEnabled(bool enabled);
bool isEnabled() const;
signals:
void enabledStateChanged(bool enabled);
private:
bool m_isEnabled;
};
} // namespace Core
......
......@@ -140,6 +140,7 @@ void ModeManager::objectAdded(QObject *obj)
m_modes.insert(index, mode);
m_modeStack->insertTab(index, mode->widget(), mode->icon(), mode->displayName());
m_modeStack->setTabEnabled(index, mode->isEnabled());
// Register mode shortcut
ActionManager *am = m_mainWindow->actionManager();
......@@ -165,6 +166,8 @@ void ModeManager::objectAdded(QObject *obj)
m_signalMapper->setMapping(shortcut, mode->id());
connect(shortcut, SIGNAL(activated()), m_signalMapper, SLOT(map()));
connect(mode, SIGNAL(enabledStateChanged(bool)),
this, SLOT(enabledStateChanged()));
}
void ModeManager::updateModeToolTip()
......@@ -177,6 +180,15 @@ void ModeManager::updateModeToolTip()
}
}
void ModeManager::enabledStateChanged()
{
IMode *mode = qobject_cast<IMode *>(sender());
QTC_ASSERT(mode, return);
int index = m_modes.indexOf(mode);
QTC_ASSERT(index >= 0, return);
m_modeStack->setTabEnabled(index, mode->isEnabled());
}
void ModeManager::aboutToRemoveObject(QObject *obj)
{
IMode *mode = Aggregation::query<IMode>(obj);
......
......@@ -86,6 +86,7 @@ private slots:
void currentTabAboutToChange(int index);
void currentTabChanged(int index);
void updateModeToolTip();
void enabledStateChanged();
private:
int indexOf(const QString &id) const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment