forked from qt-creator/qt-creator
ImageViewer: Remove class ImageViewerActionHandler.
Create the actions in ImageViewerPlugin and use lambdas instead of a QSignalMapper. Change-Id: Ic74622ca5e9daf6f0d367d00b709d732153dc62e Reviewed-by: Alessandro Portale <alessandro.portale@theqtcompany.com>
This commit is contained in:
@@ -25,12 +25,18 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "imageviewerplugin.h"
|
||||
#include "imageviewer.h"
|
||||
#include "imageviewerfactory.h"
|
||||
#include "imageviewerconstants.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/id.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <utils/mimetypes/mimedatabase.h>
|
||||
@@ -52,9 +58,71 @@ bool ImageViewerPlugin::initialize(const QStringList &arguments, QString *errorM
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline ImageViewer *currentImageViewer()
|
||||
{
|
||||
return qobject_cast<ImageViewer *>(Core::EditorManager::currentEditor());
|
||||
}
|
||||
|
||||
void ImageViewerPlugin::extensionsInitialized()
|
||||
{
|
||||
m_factory->extensionsInitialized();
|
||||
QAction *a = registerNewAction(Constants::ACTION_ZOOM_IN, tr("Zoom In"),
|
||||
QKeySequence(tr("Ctrl++")));
|
||||
connect(a, &QAction::triggered, this, [this]() {
|
||||
if (ImageViewer *iv = currentImageViewer())
|
||||
iv->zoomIn();
|
||||
});
|
||||
|
||||
a = registerNewAction(Constants::ACTION_ZOOM_OUT, tr("Zoom Out"),
|
||||
QKeySequence(tr("Ctrl+-")));
|
||||
connect(a, &QAction::triggered, this, [this]() {
|
||||
if (ImageViewer *iv = currentImageViewer())
|
||||
iv->zoomOut();
|
||||
});
|
||||
|
||||
a = registerNewAction(Constants::ACTION_ORIGINAL_SIZE, tr("Original Size"),
|
||||
QKeySequence(Core::UseMacShortcuts ? tr("Meta+0") : tr("Ctrl+0")));
|
||||
connect(a, &QAction::triggered, this, [this]() {
|
||||
if (ImageViewer *iv = currentImageViewer())
|
||||
iv->resetToOriginalSize();
|
||||
});
|
||||
|
||||
a = registerNewAction(Constants::ACTION_FIT_TO_SCREEN, tr("Fit To Screen"),
|
||||
QKeySequence(tr("Ctrl+=")));
|
||||
connect(a, &QAction::triggered, this, [this]() {
|
||||
if (ImageViewer *iv = currentImageViewer())
|
||||
iv->fitToScreen();
|
||||
});
|
||||
|
||||
a = registerNewAction(Constants::ACTION_BACKGROUND, tr("Switch Background"),
|
||||
QKeySequence(tr("Ctrl+[")));
|
||||
connect(a, &QAction::triggered, this, [this]() {
|
||||
if (ImageViewer *iv = currentImageViewer())
|
||||
iv->switchViewBackground();
|
||||
});
|
||||
|
||||
a = registerNewAction(Constants::ACTION_OUTLINE, tr("Switch Outline"),
|
||||
QKeySequence(tr("Ctrl+]")));
|
||||
connect(a, &QAction::triggered, this, [this]() {
|
||||
if (ImageViewer *iv = currentImageViewer())
|
||||
iv->switchViewOutline();
|
||||
});
|
||||
|
||||
a = registerNewAction(Constants::ACTION_TOGGLE_ANIMATION, tr("Toggle Animation"),
|
||||
QKeySequence());
|
||||
connect(a, &QAction::triggered, this, [this]() {
|
||||
if (ImageViewer *iv = currentImageViewer())
|
||||
iv->togglePlay();
|
||||
});
|
||||
}
|
||||
|
||||
QAction *ImageViewerPlugin::registerNewAction(Core::Id id,
|
||||
const QString &title, const QKeySequence &key)
|
||||
{
|
||||
Core::Context context(Constants::IMAGEVIEWER_ID);
|
||||
QAction *action = new QAction(title, this);
|
||||
Core::Command *command = Core::ActionManager::registerAction(action, id, context);
|
||||
command->setDefaultKeySequence(key);
|
||||
return action;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user