2010-06-18 11:02:50 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Denis Mingulov.
|
|
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2010-06-18 11:02:50 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-06-18 11:02:50 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2010-06-18 11:02:50 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-06-18 11:02:50 +02:00
|
|
|
|
|
|
|
|
#include "imagevieweractionhandler.h"
|
|
|
|
|
#include "imageviewer.h"
|
|
|
|
|
#include "imageviewerconstants.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2011-09-05 16:10:37 +02:00
|
|
|
#include <coreplugin/id.h>
|
2010-06-18 11:02:50 +02:00
|
|
|
|
2014-02-24 18:29:27 +01:00
|
|
|
#include <QAction>
|
|
|
|
|
#include <QList>
|
|
|
|
|
#include <QSignalMapper>
|
|
|
|
|
|
2010-06-18 11:02:50 +02:00
|
|
|
namespace ImageViewer {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2012-06-25 19:01:47 +04:00
|
|
|
enum SupportedActions {
|
|
|
|
|
ZoomIn = 0,
|
|
|
|
|
ZoomOut,
|
|
|
|
|
OriginalSize,
|
|
|
|
|
FitToScreen,
|
|
|
|
|
Background,
|
|
|
|
|
Outline,
|
|
|
|
|
ToggleAnimation
|
|
|
|
|
};
|
2010-06-18 11:02:50 +02:00
|
|
|
|
|
|
|
|
ImageViewerActionHandler::ImageViewerActionHandler(QObject *parent) :
|
2011-09-02 12:37:53 +02:00
|
|
|
QObject(parent), m_signalMapper(new QSignalMapper(this))
|
2010-06-18 11:02:50 +02:00
|
|
|
{
|
2011-09-02 12:37:53 +02:00
|
|
|
connect(m_signalMapper, SIGNAL(mapped(int)), SLOT(actionTriggered(int)));
|
2010-06-18 11:02:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageViewerActionHandler::actionTriggered(int supportedAction)
|
|
|
|
|
{
|
2012-05-08 09:43:14 +02:00
|
|
|
Core::IEditor *editor = Core::EditorManager::currentEditor();
|
2010-06-18 11:02:50 +02:00
|
|
|
ImageViewer *viewer = qobject_cast<ImageViewer *>(editor);
|
|
|
|
|
if (!viewer)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
SupportedActions action = static_cast<SupportedActions>(supportedAction);
|
2012-11-28 20:44:03 +02:00
|
|
|
switch (action) {
|
2010-06-18 11:02:50 +02:00
|
|
|
case ZoomIn:
|
|
|
|
|
viewer->zoomIn();
|
|
|
|
|
break;
|
|
|
|
|
case ZoomOut:
|
|
|
|
|
viewer->zoomOut();
|
|
|
|
|
break;
|
|
|
|
|
case OriginalSize:
|
|
|
|
|
viewer->resetToOriginalSize();
|
|
|
|
|
break;
|
|
|
|
|
case FitToScreen:
|
|
|
|
|
viewer->fitToScreen();
|
|
|
|
|
break;
|
|
|
|
|
case Background:
|
|
|
|
|
viewer->switchViewBackground();
|
|
|
|
|
break;
|
|
|
|
|
case Outline:
|
|
|
|
|
viewer->switchViewOutline();
|
|
|
|
|
break;
|
2012-06-25 19:01:47 +04:00
|
|
|
case ToggleAnimation:
|
|
|
|
|
viewer->togglePlay();
|
|
|
|
|
break;
|
2010-06-18 11:02:50 +02:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageViewerActionHandler::createActions()
|
|
|
|
|
{
|
|
|
|
|
registerNewAction(ZoomIn, Constants::ACTION_ZOOM_IN, tr("Zoom In"),
|
2011-09-02 12:37:53 +02:00
|
|
|
QKeySequence(tr("Ctrl++")));
|
2010-06-18 11:02:50 +02:00
|
|
|
registerNewAction(ZoomOut, Constants::ACTION_ZOOM_OUT, tr("Zoom Out"),
|
2011-09-02 12:37:53 +02:00
|
|
|
QKeySequence(tr("Ctrl+-")));
|
2010-06-18 11:02:50 +02:00
|
|
|
registerNewAction(OriginalSize, Constants::ACTION_ORIGINAL_SIZE, tr("Original Size"),
|
2012-05-23 15:20:38 +02:00
|
|
|
QKeySequence(Core::UseMacShortcuts ? tr("Meta+0") : tr("Ctrl+0")));
|
2010-06-18 11:02:50 +02:00
|
|
|
registerNewAction(FitToScreen, Constants::ACTION_FIT_TO_SCREEN, tr("Fit To Screen"),
|
2011-09-02 12:37:53 +02:00
|
|
|
QKeySequence(tr("Ctrl+=")));
|
2011-03-21 16:16:19 +01:00
|
|
|
registerNewAction(Background, Constants::ACTION_BACKGROUND, tr("Switch Background"),
|
2011-09-02 12:37:53 +02:00
|
|
|
QKeySequence(tr("Ctrl+[")));
|
2011-03-21 16:16:19 +01:00
|
|
|
registerNewAction(Outline, Constants::ACTION_OUTLINE, tr("Switch Outline"),
|
2011-09-02 12:37:53 +02:00
|
|
|
QKeySequence(tr("Ctrl+]")));
|
2012-06-25 19:01:47 +04:00
|
|
|
registerNewAction(ToggleAnimation, Constants::ACTION_TOGGLE_ANIMATION, tr("Toggle Animation"),
|
|
|
|
|
QKeySequence());
|
2010-06-18 11:02:50 +02:00
|
|
|
}
|
|
|
|
|
|
2013-06-07 10:38:26 +02:00
|
|
|
/*!
|
|
|
|
|
Creates a new action with the internal id \a actionId, command id \a id,
|
|
|
|
|
and keyboard shortcut \a key, and registers it in the action manager.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-09-02 12:37:53 +02:00
|
|
|
void ImageViewerActionHandler::registerNewAction(int actionId, const Core::Id &id,
|
|
|
|
|
const QString &title, const QKeySequence &key)
|
2010-06-18 11:02:50 +02:00
|
|
|
{
|
2011-09-02 12:37:53 +02:00
|
|
|
Core::Context context(Constants::IMAGEVIEWER_ID);
|
2010-06-18 11:02:50 +02:00
|
|
|
QAction *action = new QAction(title, this);
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::Command *command = Core::ActionManager::registerAction(action, id, context);
|
|
|
|
|
command->setDefaultKeySequence(key);
|
2011-09-02 12:37:53 +02:00
|
|
|
connect(action, SIGNAL(triggered()), m_signalMapper, SLOT(map()));
|
|
|
|
|
m_signalMapper->setMapping(action, actionId);
|
2010-06-18 11:02:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ImageViewer
|