Commit f4add2b8 authored by mae's avatar mae
Browse files

On Mac, toggle run/debug with the open button (Qt::Key_Alt)

parent 2933f41b
......@@ -45,8 +45,9 @@
#include <QtGui/QStatusBar>
#include <QtGui/QStyle>
#include <QtGui/QStyleOption>
#include <QtCore/QEvent>
#include <QtGui/QMouseEvent>
#include <QtGui/QApplication>
#include <QtCore/QEvent>
#include <QtCore/QAnimationGroup>
#include <QtCore/QPropertyAnimation>
#include <QtCore/QDebug>
......@@ -267,11 +268,29 @@ FancyActionBar::FancyActionBar(QWidget *parent)
setContentsMargins(0,2,0,0);
m_runButton = m_debugButton = 0;
m_inDebugMode = false;
connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode*)),
this, SLOT(modeChanged(Core::IMode*)));
#ifdef Q_WS_MAC
qApp->installEventFilter(this);
#endif
}
#ifdef Q_WS_MAC
bool FancyActionBar::eventFilter(QObject *, QEvent *e)
{
if (e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease) {
if (static_cast<QKeyEvent *>(e)->key() == Qt::Key_Alt)
updateRunDebug();
} else if (e->type() == QEvent::WindowDeactivate)
updateRunDebug();
return false;
}
#endif
void FancyActionBar::addProjectSelector(QAction *action)
{
FancyToolButton* toolButton = new FancyToolButton(this);
......@@ -295,15 +314,27 @@ void FancyActionBar::insertAction(int index, QAction *action)
void FancyActionBar::modeChanged(Core::IMode *mode)
{
if (m_runButton && m_debugButton) {
bool inDebugMode = (mode->id() == QLatin1String("Debugger.Mode.Debug"));
layout()->setEnabled(false);
m_runButton->forceVisible(!inDebugMode);
m_debugButton->forceVisible(inDebugMode);
layout()->setEnabled(true);
}
m_inDebugMode = (mode->id() == QLatin1String("Debugger.Mode.Debug"));
updateRunDebug();
}
void FancyActionBar::updateRunDebug()
{
if (!m_runButton || !m_debugButton)
return;
bool doDebug = m_inDebugMode;
#ifdef Q_WS_MAC
if (QApplication::keyboardModifiers() && Qt::AltModifier)
doDebug = !doDebug;
#endif
layout()->setEnabled(false);
m_runButton->forceVisible(!doDebug);
m_debugButton->forceVisible(doDebug);
layout()->setEnabled(true);
}
QLayout *FancyActionBar::actionsLayout() const
{
......
......@@ -75,6 +75,9 @@ class FancyActionBar : public QWidget
public:
FancyActionBar(QWidget *parent = 0);
#ifdef Q_WS_MAC
bool eventFilter(QObject *, QEvent *);
#endif
void paintEvent(QPaintEvent *event);
void insertAction(int index, QAction *action);
void addProjectSelector(QAction *action);
......@@ -84,6 +87,8 @@ private slots:
void modeChanged(Core::IMode *mode);
private:
void updateRunDebug();
bool m_inDebugMode;
QVBoxLayout *m_actionsLayout;
FancyToolButton *m_runButton;
FancyToolButton *m_debugButton;
......
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