forked from qt-creator/qt-creator
imageviewer: simplify ImageViewerActionHandler
Change-Id: Iccd651c960cced8432e50bd861992c3240109bce Reviewed-on: http://codereview.qt.nokia.com/4132 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Robert Löhning <robert.loehning@nokia.com>
This commit is contained in:
@@ -36,7 +36,6 @@
|
||||
#include "imageviewerconstants.h"
|
||||
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QPointer>
|
||||
#include <QtCore/QSignalMapper>
|
||||
#include <QtGui/QAction>
|
||||
|
||||
@@ -51,33 +50,10 @@ namespace Internal {
|
||||
|
||||
enum SupportedActions { ZoomIn = 0, ZoomOut, OriginalSize, FitToScreen, Background, Outline };
|
||||
|
||||
struct ImageViewerActionHandlerPrivate
|
||||
{
|
||||
ImageViewerActionHandlerPrivate()
|
||||
: context(Constants::IMAGEVIEWER_ID)
|
||||
{}
|
||||
|
||||
QPointer<QAction> actionZoomIn;
|
||||
QPointer<QAction> actionZoomOut;
|
||||
QPointer<QAction> actionOriginalSize;
|
||||
QPointer<QAction> actionFitToScreen;
|
||||
QPointer<QAction> actionBackground;
|
||||
QPointer<QAction> actionOutline;
|
||||
|
||||
Core::Context context;
|
||||
QPointer<QSignalMapper> signalMapper;
|
||||
};
|
||||
|
||||
ImageViewerActionHandler::ImageViewerActionHandler(QObject *parent) :
|
||||
QObject(parent),
|
||||
d(new ImageViewerActionHandlerPrivate)
|
||||
{
|
||||
d->signalMapper = new QSignalMapper(this);
|
||||
connect(d->signalMapper, SIGNAL(mapped(int)), SLOT(actionTriggered(int)));
|
||||
}
|
||||
|
||||
ImageViewerActionHandler::~ImageViewerActionHandler()
|
||||
QObject(parent), m_signalMapper(new QSignalMapper(this))
|
||||
{
|
||||
connect(m_signalMapper, SIGNAL(mapped(int)), SLOT(actionTriggered(int)));
|
||||
}
|
||||
|
||||
void ImageViewerActionHandler::actionTriggered(int supportedAction)
|
||||
@@ -116,33 +92,30 @@ void ImageViewerActionHandler::actionTriggered(int supportedAction)
|
||||
void ImageViewerActionHandler::createActions()
|
||||
{
|
||||
registerNewAction(ZoomIn, Constants::ACTION_ZOOM_IN, tr("Zoom In"),
|
||||
d->context, QKeySequence(tr("Ctrl++")));
|
||||
QKeySequence(tr("Ctrl++")));
|
||||
registerNewAction(ZoomOut, Constants::ACTION_ZOOM_OUT, tr("Zoom Out"),
|
||||
d->context, QKeySequence(tr("Ctrl+-")));
|
||||
QKeySequence(tr("Ctrl+-")));
|
||||
registerNewAction(OriginalSize, Constants::ACTION_ORIGINAL_SIZE, tr("Original Size"),
|
||||
d->context, QKeySequence(tr("Ctrl+0")));
|
||||
QKeySequence(tr("Ctrl+0")));
|
||||
registerNewAction(FitToScreen, Constants::ACTION_FIT_TO_SCREEN, tr("Fit To Screen"),
|
||||
d->context, QKeySequence(tr("Ctrl+=")));
|
||||
QKeySequence(tr("Ctrl+=")));
|
||||
registerNewAction(Background, Constants::ACTION_BACKGROUND, tr("Switch Background"),
|
||||
d->context, QKeySequence(tr("Ctrl+[")));
|
||||
QKeySequence(tr("Ctrl+[")));
|
||||
registerNewAction(Outline, Constants::ACTION_OUTLINE, tr("Switch Outline"),
|
||||
d->context, QKeySequence(tr("Ctrl+]")));
|
||||
QKeySequence(tr("Ctrl+]")));
|
||||
}
|
||||
|
||||
QAction *ImageViewerActionHandler::registerNewAction(int actionId, const QString &id,
|
||||
const QString &title, const Core::Context &context, const QKeySequence &key)
|
||||
void ImageViewerActionHandler::registerNewAction(int actionId, const Core::Id &id,
|
||||
const QString &title, const QKeySequence &key)
|
||||
{
|
||||
Core::Context context(Constants::IMAGEVIEWER_ID);
|
||||
Core::ActionManager *actionManager = Core::ICore::instance()->actionManager();
|
||||
Core::Command *command = 0;
|
||||
|
||||
QAction *action = new QAction(title, this);
|
||||
command = actionManager->registerAction(action, id, context);
|
||||
Core::Command *command = actionManager->registerAction(action, id, context);
|
||||
if (command)
|
||||
command->setDefaultKeySequence(key);
|
||||
connect(action, SIGNAL(triggered()), d->signalMapper, SLOT(map()));
|
||||
d->signalMapper->setMapping(action, actionId);
|
||||
|
||||
return action;
|
||||
connect(action, SIGNAL(triggered()), m_signalMapper, SLOT(map()));
|
||||
m_signalMapper->setMapping(action, actionId);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -34,14 +34,14 @@
|
||||
#ifndef IMAGEVIEWERACTIONHANDLER_H
|
||||
#define IMAGEVIEWERACTIONHANDLER_H
|
||||
|
||||
#include "coreplugin/icontext.h"
|
||||
#include "coreplugin/uniqueidmanager.h"
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QScopedPointer>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QAction;
|
||||
class QKeySequence;
|
||||
class QSignalMapper;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace ImageViewer {
|
||||
@@ -53,8 +53,6 @@ class ImageViewerActionHandler : public QObject
|
||||
|
||||
public:
|
||||
explicit ImageViewerActionHandler(QObject *parent = 0);
|
||||
~ImageViewerActionHandler();
|
||||
|
||||
void createActions();
|
||||
|
||||
public slots:
|
||||
@@ -70,11 +68,11 @@ protected:
|
||||
\param key Key sequence for the command
|
||||
\return Created and registered action, 0 if something goes wrong
|
||||
*/
|
||||
QAction *registerNewAction(int actionId, const QString &id, const QString &title,
|
||||
const Core::Context &context, const QKeySequence &key);
|
||||
void registerNewAction(int actionId, const Core::Id &id, const QString &title,
|
||||
const QKeySequence &key);
|
||||
|
||||
private:
|
||||
QScopedPointer<struct ImageViewerActionHandlerPrivate> d;
|
||||
QSignalMapper *m_signalMapper;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user