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 "imageviewerconstants.h"
|
||||||
|
|
||||||
#include <QtCore/QList>
|
#include <QtCore/QList>
|
||||||
#include <QtCore/QPointer>
|
|
||||||
#include <QtCore/QSignalMapper>
|
#include <QtCore/QSignalMapper>
|
||||||
#include <QtGui/QAction>
|
#include <QtGui/QAction>
|
||||||
|
|
||||||
@@ -51,33 +50,10 @@ namespace Internal {
|
|||||||
|
|
||||||
enum SupportedActions { ZoomIn = 0, ZoomOut, OriginalSize, FitToScreen, Background, Outline };
|
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) :
|
ImageViewerActionHandler::ImageViewerActionHandler(QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent), m_signalMapper(new QSignalMapper(this))
|
||||||
d(new ImageViewerActionHandlerPrivate)
|
|
||||||
{
|
|
||||||
d->signalMapper = new QSignalMapper(this);
|
|
||||||
connect(d->signalMapper, SIGNAL(mapped(int)), SLOT(actionTriggered(int)));
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageViewerActionHandler::~ImageViewerActionHandler()
|
|
||||||
{
|
{
|
||||||
|
connect(m_signalMapper, SIGNAL(mapped(int)), SLOT(actionTriggered(int)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageViewerActionHandler::actionTriggered(int supportedAction)
|
void ImageViewerActionHandler::actionTriggered(int supportedAction)
|
||||||
@@ -116,33 +92,30 @@ void ImageViewerActionHandler::actionTriggered(int supportedAction)
|
|||||||
void ImageViewerActionHandler::createActions()
|
void ImageViewerActionHandler::createActions()
|
||||||
{
|
{
|
||||||
registerNewAction(ZoomIn, Constants::ACTION_ZOOM_IN, tr("Zoom In"),
|
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"),
|
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"),
|
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"),
|
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"),
|
registerNewAction(Background, Constants::ACTION_BACKGROUND, tr("Switch Background"),
|
||||||
d->context, QKeySequence(tr("Ctrl+[")));
|
QKeySequence(tr("Ctrl+[")));
|
||||||
registerNewAction(Outline, Constants::ACTION_OUTLINE, tr("Switch Outline"),
|
registerNewAction(Outline, Constants::ACTION_OUTLINE, tr("Switch Outline"),
|
||||||
d->context, QKeySequence(tr("Ctrl+]")));
|
QKeySequence(tr("Ctrl+]")));
|
||||||
}
|
}
|
||||||
|
|
||||||
QAction *ImageViewerActionHandler::registerNewAction(int actionId, const QString &id,
|
void ImageViewerActionHandler::registerNewAction(int actionId, const Core::Id &id,
|
||||||
const QString &title, const Core::Context &context, const QKeySequence &key)
|
const QString &title, const QKeySequence &key)
|
||||||
{
|
{
|
||||||
|
Core::Context context(Constants::IMAGEVIEWER_ID);
|
||||||
Core::ActionManager *actionManager = Core::ICore::instance()->actionManager();
|
Core::ActionManager *actionManager = Core::ICore::instance()->actionManager();
|
||||||
Core::Command *command = 0;
|
|
||||||
|
|
||||||
QAction *action = new QAction(title, this);
|
QAction *action = new QAction(title, this);
|
||||||
command = actionManager->registerAction(action, id, context);
|
Core::Command *command = actionManager->registerAction(action, id, context);
|
||||||
if (command)
|
if (command)
|
||||||
command->setDefaultKeySequence(key);
|
command->setDefaultKeySequence(key);
|
||||||
connect(action, SIGNAL(triggered()), d->signalMapper, SLOT(map()));
|
connect(action, SIGNAL(triggered()), m_signalMapper, SLOT(map()));
|
||||||
d->signalMapper->setMapping(action, actionId);
|
m_signalMapper->setMapping(action, actionId);
|
||||||
|
|
||||||
return action;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -34,14 +34,14 @@
|
|||||||
#ifndef IMAGEVIEWERACTIONHANDLER_H
|
#ifndef IMAGEVIEWERACTIONHANDLER_H
|
||||||
#define IMAGEVIEWERACTIONHANDLER_H
|
#define IMAGEVIEWERACTIONHANDLER_H
|
||||||
|
|
||||||
#include "coreplugin/icontext.h"
|
#include "coreplugin/uniqueidmanager.h"
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QScopedPointer>
|
#include <QtCore/QScopedPointer>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QAction;
|
|
||||||
class QKeySequence;
|
class QKeySequence;
|
||||||
|
class QSignalMapper;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace ImageViewer {
|
namespace ImageViewer {
|
||||||
@@ -53,8 +53,6 @@ class ImageViewerActionHandler : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ImageViewerActionHandler(QObject *parent = 0);
|
explicit ImageViewerActionHandler(QObject *parent = 0);
|
||||||
~ImageViewerActionHandler();
|
|
||||||
|
|
||||||
void createActions();
|
void createActions();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
@@ -70,11 +68,11 @@ protected:
|
|||||||
\param key Key sequence for the command
|
\param key Key sequence for the command
|
||||||
\return Created and registered action, 0 if something goes wrong
|
\return Created and registered action, 0 if something goes wrong
|
||||||
*/
|
*/
|
||||||
QAction *registerNewAction(int actionId, const QString &id, const QString &title,
|
void registerNewAction(int actionId, const Core::Id &id, const QString &title,
|
||||||
const Core::Context &context, const QKeySequence &key);
|
const QKeySequence &key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<struct ImageViewerActionHandlerPrivate> d;
|
QSignalMapper *m_signalMapper;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user