Make the run and debug buttons in the FancyActionBar mutual exclusive

Debug is now only available in debug mode, run is available in all
other modes.
This commit is contained in:
mae
2010-03-12 14:22:26 +01:00
parent 1ffa2ffcd0
commit d61a7f59b2
2 changed files with 30 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
/********************Q****************************************************** /**************************************************************************
** **
** This file is part of Qt Creator ** This file is part of Qt Creator
** **
@@ -33,6 +33,8 @@
#include <utils/stylehelper.h> #include <utils/stylehelper.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/imode.h>
#include <coreplugin/modemanager.h>
#include <coreplugin/mainwindow.h> #include <coreplugin/mainwindow.h>
#include <QtGui/QHBoxLayout> #include <QtGui/QHBoxLayout>
@@ -47,6 +49,7 @@
#include <QtGui/QMouseEvent> #include <QtGui/QMouseEvent>
#include <QtCore/QAnimationGroup> #include <QtCore/QAnimationGroup>
#include <QtCore/QPropertyAnimation> #include <QtCore/QPropertyAnimation>
#include <QtCore/QDebug>
using namespace Core; using namespace Core;
using namespace Internal; using namespace Internal;
@@ -234,6 +237,11 @@ FancyActionBar::FancyActionBar(QWidget *parent)
spacerLayout->setSpacing(0); spacerLayout->setSpacing(0);
setLayout(spacerLayout); setLayout(spacerLayout);
setContentsMargins(0,2,0,0); setContentsMargins(0,2,0,0);
m_runButton = m_debugButton = 0;
connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode*)),
this, SLOT(modeChanged(Core::IMode*)));
} }
void FancyActionBar::addProjectSelector(QAction *action) void FancyActionBar::addProjectSelector(QAction *action)
@@ -247,11 +255,26 @@ void FancyActionBar::addProjectSelector(QAction *action)
void FancyActionBar::insertAction(int index, QAction *action) void FancyActionBar::insertAction(int index, QAction *action)
{ {
FancyToolButton *toolButton = new FancyToolButton(this); FancyToolButton *toolButton = new FancyToolButton(this);
if (action->objectName() == QLatin1String("ProjectExplorer.Run"))
m_runButton = toolButton;
if (action->objectName() == QLatin1String("ProjectExplorer.Debug"))
m_debugButton = toolButton;
toolButton->setDefaultAction(action); toolButton->setDefaultAction(action);
connect(action, SIGNAL(changed()), toolButton, SLOT(actionChanged())); connect(action, SIGNAL(changed()), toolButton, SLOT(actionChanged()));
m_actionsLayout->insertWidget(index, toolButton); m_actionsLayout->insertWidget(index, toolButton);
} }
void FancyActionBar::modeChanged(Core::IMode *mode)
{
if (m_runButton && m_debugButton) {
bool inDebugMode = (mode->id() == QLatin1String("Debugger.Mode.Debug"));
m_runButton->setVisible(!inDebugMode);
m_debugButton->setVisible(inDebugMode);
}
}
QLayout *FancyActionBar::actionsLayout() const QLayout *FancyActionBar::actionsLayout() const
{ {
return m_actionsLayout; return m_actionsLayout;

View File

@@ -39,6 +39,7 @@ class QVBoxLayout;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Core { namespace Core {
class IMode;
namespace Internal { namespace Internal {
class FancyToolButton : public QToolButton class FancyToolButton : public QToolButton
@@ -75,8 +76,13 @@ public:
void addProjectSelector(QAction *action); void addProjectSelector(QAction *action);
QLayout *actionsLayout() const; QLayout *actionsLayout() const;
private slots:
void modeChanged(Core::IMode *mode);
private: private:
QVBoxLayout *m_actionsLayout; QVBoxLayout *m_actionsLayout;
FancyToolButton *m_runButton;
FancyToolButton *m_debugButton;
}; };
} // namespace Internal } // namespace Internal