Commit 58a6a7e4 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Add "presentation mode"



Presentation mode can be entered by passing -presentationMode when
starting Qt Creator.

It displays a popup with the keyboard shortcut of the commands
that are triggered. Great for the DevDays;-)

Change-Id: I897966aab491f98e2a5abc4433c40b04e2a8db57
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
Reviewed-by: default avatarLiang Qi <liang.qi@nokia.com>
parent a558cedc
......@@ -15,5 +15,6 @@ Alternatively, this plugin may be used under the terms of the GNU Lesser General
<url>http://qt.nokia.com</url>
<argumentList>
<argument name=\"-color\" parameter=\"color\">Override selected UI color</argument>
<argument name=\"-presentationMode\">Enable presentation mode with pop-ups for key combos</argument>
</argumentList>
</plugin>
......@@ -42,6 +42,8 @@
#include <QtCore/QDebug>
#include <QtCore/QSettings>
#include <QtGui/QDesktopWidget>
#include <QtGui/QLabel>
#include <QtGui/QMenu>
#include <QtGui/QAction>
#include <QtGui/QShortcut>
......@@ -239,8 +241,10 @@ ActionManagerPrivate* ActionManagerPrivate::m_instance = 0;
ActionManagerPrivate::ActionManagerPrivate(MainWindow *mainWnd)
: ActionManager(mainWnd),
m_mainWnd(mainWnd)
m_mainWnd(mainWnd),
m_presentationLabel(0)
{
m_presentationLabelTimer.setInterval(1000);
m_instance = this;
}
......@@ -344,6 +348,36 @@ void ActionManagerPrivate::containerDestroyed()
m_idContainerMap.remove(m_idContainerMap.key(container));
}
void ActionManagerPrivate::actionTriggered()
{
QAction *action = qobject_cast<QAction *>(QObject::sender());
if (action)
showShortcutPopup(action->shortcut().toString());
}
void ActionManagerPrivate::shortcutTriggered()
{
QShortcut *sc = qobject_cast<QShortcut *>(QObject::sender());
if (sc)
showShortcutPopup(sc->key().toString());
}
void ActionManagerPrivate::showShortcutPopup(const QString &shortcut)
{
if (shortcut.isEmpty() || !isPresentationModeEnabled())
return;
m_presentationLabel->setText(shortcut);
m_presentationLabel->adjustSize();
QPoint p = m_mainWnd->mapToGlobal(m_mainWnd->rect().center() - m_presentationLabel->rect().center());
m_presentationLabel->move(p);
m_presentationLabel->show();
m_presentationLabel->raise();
m_presentationLabelTimer.start();
}
Command *ActionManagerPrivate::registerAction(QAction *action, const Id &id, const Context &context, bool scriptable)
{
Action *a = overridableAction(id);
......@@ -373,6 +407,9 @@ Action *ActionManagerPrivate::overridableAction(const Id &id)
a->action()->setObjectName(id.toString());
a->action()->setShortcutContext(Qt::ApplicationShortcut);
a->setCurrentContext(m_context);
if (isPresentationModeEnabled())
connect(a->action(), SIGNAL(triggered()), this, SLOT(actionTriggered()));
}
return a;
......@@ -437,6 +474,9 @@ Command *ActionManagerPrivate::registerShortcut(QShortcut *shortcut, const Id &i
emit commandListChanged();
emit commandAdded(id.toString());
if (isPresentationModeEnabled())
connect(sc->shortcut(), SIGNAL(activated()), this, SLOT(shortcutTriggered()));
return sc;
}
......@@ -550,3 +590,46 @@ void ActionManagerPrivate::unregisterShortcut(const Core::Id &id)
delete sc;
emit commandListChanged();
}
void ActionManagerPrivate::setPresentationModeEnabled(bool enabled)
{
if (enabled == isPresentationModeEnabled())
return;
// Signal/slots to commands:
foreach (Command *c, commands()) {
if (c->action()) {
if (enabled)
connect(c->action(), SIGNAL(triggered()), this, SLOT(actionTriggered()));
else
disconnect(c->action(), SIGNAL(triggered()), this, SLOT(actionTriggered()));
}
if (c->shortcut()) {
if (enabled)
connect(c->shortcut(), SIGNAL(activated()), this, SLOT(shortcutTriggered()));
else
disconnect(c->shortcut(), SIGNAL(activated()), this, SLOT(shortcutTriggered()));
}
}
// The label for the shortcuts:
if (!m_presentationLabel) {
m_presentationLabel = new QLabel(0, Qt::ToolTip | Qt::WindowStaysOnTopHint);
QFont font = m_presentationLabel->font();
font.setPixelSize(45);
m_presentationLabel->setFont(font);
m_presentationLabel->setAlignment(Qt::AlignCenter);
m_presentationLabel->setMargin(5);
connect(&m_presentationLabelTimer, SIGNAL(timeout()), m_presentationLabel, SLOT(hide()));
} else {
m_presentationLabelTimer.stop();
delete m_presentationLabel;
m_presentationLabel = 0;
}
}
bool ActionManagerPrivate::isPresentationModeEnabled()
{
return m_presentationLabel;
}
......@@ -41,8 +41,10 @@
#include <QtCore/QMap>
#include <QtCore/QHash>
#include <QtCore/QMultiHash>
#include <QtCore/QTimer>
QT_BEGIN_NAMESPACE
class QLabel;
class QSettings;
QT_END_NAMESPACE
......@@ -89,9 +91,16 @@ public:
void unregisterAction(QAction *action, const Id &id);
void unregisterShortcut(const Id &id);
void setPresentationModeEnabled(bool enabled);
bool isPresentationModeEnabled();
private slots:
void containerDestroyed();
void actionTriggered();
void shortcutTriggered();
private:
void showShortcutPopup(const QString &shortcut);
bool hasContext(const Context &context) const;
Action *overridableAction(const Id &id);
......@@ -109,6 +118,9 @@ private:
Context m_context;
MainWindow *m_mainWnd;
QLabel *m_presentationLabel;
QTimer m_presentationLabelTimer;
};
} // namespace Internal
......
......@@ -73,12 +73,14 @@ CorePlugin::~CorePlugin()
void CorePlugin::parseArguments(const QStringList &arguments)
{
for (int i = 0; i < arguments.size() - 1; i++) {
for (int i = 0; i < arguments.size(); ++i) {
if (arguments.at(i) == QLatin1String("-color")) {
const QString colorcode(arguments.at(i + 1));
m_mainWindow->setOverrideColor(QColor(colorcode));
i++; // skip the argument
}
if (arguments.at(i) == QLatin1String("-presentationMode"))
m_mainWindow->setPresentationModeEnabled(true);
}
}
......
......@@ -252,6 +252,16 @@ void MainWindow::setOverrideColor(const QColor &color)
m_overrideColor = color;
}
bool MainWindow::isPresentationModeEnabled()
{
return m_actionManager->isPresentationModeEnabled();
}
void MainWindow::setPresentationModeEnabled(bool enabled)
{
m_actionManager->setPresentationModeEnabled(enabled);
}
MainWindow::~MainWindow()
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
......
......@@ -125,6 +125,9 @@ public:
void setOverrideColor(const QColor &color);
bool isPresentationModeEnabled();
void setPresentationModeEnabled(bool);
signals:
void windowActivated();
......
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