forked from qt-creator/qt-creator
Unify zooming actions of image viewer and model editor
Change-Id: I5761ab579beda5b2cd0b725869ed216cb97e900c Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -77,6 +77,9 @@ const char CUT[] = "QtCreator.Cut";
|
||||
const char SELECTALL[] = "QtCreator.SelectAll";
|
||||
|
||||
const char GOTO[] = "QtCreator.Goto";
|
||||
const char ZOOM_IN[] = "QtCreator.ZoomIn";
|
||||
const char ZOOM_OUT[] = "QtCreator.ZoomOut";
|
||||
const char ZOOM_RESET[] = "QtCreator.ZoomReset";
|
||||
|
||||
const char NEW[] = "QtCreator.New";
|
||||
const char OPEN[] = "QtCreator.Open";
|
||||
|
@@ -637,6 +637,30 @@ void MainWindow::registerDefaultActions()
|
||||
medit->addAction(cmd, Constants::G_EDIT_OTHER);
|
||||
tmpaction->setEnabled(false);
|
||||
|
||||
// Zoom In Action
|
||||
icon = QIcon::hasThemeIcon("zoom-in") ? QIcon::fromTheme("zoom-in")
|
||||
: Utils::Icons::ZOOMIN_TOOLBAR.icon();
|
||||
tmpaction = new QAction(icon, tr("Zoom In"), this);
|
||||
cmd = ActionManager::registerAction(tmpaction, Constants::ZOOM_IN);
|
||||
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl++")));
|
||||
tmpaction->setEnabled(false);
|
||||
|
||||
// Zoom Out Action
|
||||
icon = QIcon::hasThemeIcon("zoom-out") ? QIcon::fromTheme("zoom-out")
|
||||
: Utils::Icons::ZOOMOUT_TOOLBAR.icon();
|
||||
tmpaction = new QAction(icon, tr("Zoom Out"), this);
|
||||
cmd = ActionManager::registerAction(tmpaction, Constants::ZOOM_OUT);
|
||||
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+-")));
|
||||
tmpaction->setEnabled(false);
|
||||
|
||||
// Zoom Reset Action
|
||||
icon = QIcon::hasThemeIcon("zoom-original") ? QIcon::fromTheme("zoom-original")
|
||||
: Utils::Icons::EYE_OPEN_TOOLBAR.icon();
|
||||
tmpaction = new QAction(icon, tr("Original Size"), this);
|
||||
cmd = ActionManager::registerAction(tmpaction, Constants::ZOOM_RESET);
|
||||
cmd->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+0") : tr("Ctrl+0")));
|
||||
tmpaction->setEnabled(false);
|
||||
|
||||
// Options Action
|
||||
mtools->appendGroup(Constants::G_TOOLS_OPTIONS);
|
||||
mtools->addSeparator(Constants::G_TOOLS_OPTIONS);
|
||||
|
@@ -33,6 +33,7 @@
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/utilsicons.h>
|
||||
@@ -107,14 +108,14 @@ void ImageViewer::ctor()
|
||||
{QLatin1String(":/utils/images/desktopdevicesmall.png"), Utils::Theme::IconsBaseColor}});
|
||||
d->ui_toolbar.toolButtonBackground->setIcon(backgroundIcon.icon());
|
||||
d->ui_toolbar.toolButtonOutline->setIcon(Utils::Icons::BOUNDING_RECT.icon());
|
||||
d->ui_toolbar.toolButtonZoomIn->setIcon(Utils::Icons::ZOOMIN_TOOLBAR.icon());
|
||||
d->ui_toolbar.toolButtonZoomOut->setIcon(Utils::Icons::ZOOMOUT_TOOLBAR.icon());
|
||||
d->ui_toolbar.toolButtonZoomIn->setIcon(
|
||||
Core::ActionManager::command(Core::Constants::ZOOM_IN)->action()->icon());
|
||||
d->ui_toolbar.toolButtonZoomOut->setIcon(
|
||||
Core::ActionManager::command(Core::Constants::ZOOM_OUT)->action()->icon());
|
||||
d->ui_toolbar.toolButtonOriginalSize->setIcon(
|
||||
Core::ActionManager::command(Core::Constants::ZOOM_RESET)->action()->icon());
|
||||
d->ui_toolbar.toolButtonFitToScreen->setIcon(Utils::Icons::FITTOVIEW_TOOLBAR.icon());
|
||||
d->ui_toolbar.toolButtonOriginalSize->setIcon(Utils::Icons::EYE_OPEN_TOOLBAR.icon());
|
||||
// icons update - try to use system theme
|
||||
updateButtonIconByTheme(d->ui_toolbar.toolButtonZoomIn, QLatin1String("zoom-in"));
|
||||
updateButtonIconByTheme(d->ui_toolbar.toolButtonZoomOut, QLatin1String("zoom-out"));
|
||||
updateButtonIconByTheme(d->ui_toolbar.toolButtonOriginalSize, QLatin1String("zoom-original"));
|
||||
updateButtonIconByTheme(d->ui_toolbar.toolButtonFitToScreen, QLatin1String("zoom-fit-best"));
|
||||
// a display - something is on the background
|
||||
updateButtonIconByTheme(d->ui_toolbar.toolButtonBackground, QLatin1String("video-display"));
|
||||
@@ -123,9 +124,9 @@ void ImageViewer::ctor()
|
||||
updateButtonIconByTheme(d->ui_toolbar.toolButtonOutline, QLatin1String("emblem-photos"));
|
||||
|
||||
d->ui_toolbar.toolButtonExportImage->setCommandId(Constants::ACTION_EXPORT_IMAGE);
|
||||
d->ui_toolbar.toolButtonZoomIn->setCommandId(Constants::ACTION_ZOOM_IN);
|
||||
d->ui_toolbar.toolButtonZoomOut->setCommandId(Constants::ACTION_ZOOM_OUT);
|
||||
d->ui_toolbar.toolButtonOriginalSize->setCommandId(Constants::ACTION_ORIGINAL_SIZE);
|
||||
d->ui_toolbar.toolButtonZoomIn->setCommandId(Core::Constants::ZOOM_IN);
|
||||
d->ui_toolbar.toolButtonZoomOut->setCommandId(Core::Constants::ZOOM_OUT);
|
||||
d->ui_toolbar.toolButtonOriginalSize->setCommandId(Core::Constants::ZOOM_RESET);
|
||||
d->ui_toolbar.toolButtonFitToScreen->setCommandId(Constants::ACTION_FIT_TO_SCREEN);
|
||||
d->ui_toolbar.toolButtonBackground->setCommandId(Constants::ACTION_BACKGROUND);
|
||||
d->ui_toolbar.toolButtonOutline->setCommandId(Constants::ACTION_OUTLINE);
|
||||
|
@@ -33,9 +33,6 @@ const char IMAGEVIEWER_ID[] = "Editors.ImageViewer";
|
||||
const char IMAGEVIEWER_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("OpenWith::Editors", "Image Viewer");
|
||||
|
||||
const char ACTION_EXPORT_IMAGE[] = "ImageViewer.ExportImage";
|
||||
const char ACTION_ZOOM_IN[] = "ImageViewer.ZoomIn";
|
||||
const char ACTION_ZOOM_OUT[] = "ImageViewer.ZoomOut";
|
||||
const char ACTION_ORIGINAL_SIZE[] = "ImageViewer.OriginalSize";
|
||||
const char ACTION_FIT_TO_SCREEN[] = "ImageViewer.FitToScreen";
|
||||
const char ACTION_BACKGROUND[] = "ImageViewer.Background";
|
||||
const char ACTION_OUTLINE[] = "ImageViewer.Outline";
|
||||
|
@@ -36,6 +36,7 @@
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/id.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
@@ -62,22 +63,19 @@ static inline ImageViewer *currentImageViewer()
|
||||
|
||||
void ImageViewerPlugin::extensionsInitialized()
|
||||
{
|
||||
QAction *a = registerNewAction(Constants::ACTION_ZOOM_IN, tr("Zoom In"),
|
||||
QKeySequence(tr("Ctrl++")));
|
||||
QAction *a = registerNewAction(Core::Constants::ZOOM_IN);
|
||||
connect(a, &QAction::triggered, this, []() {
|
||||
if (ImageViewer *iv = currentImageViewer())
|
||||
iv->zoomIn();
|
||||
});
|
||||
|
||||
a = registerNewAction(Constants::ACTION_ZOOM_OUT, tr("Zoom Out"),
|
||||
QKeySequence(tr("Ctrl+-")));
|
||||
a = registerNewAction(Core::Constants::ZOOM_OUT);
|
||||
connect(a, &QAction::triggered, 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")));
|
||||
a = registerNewAction(Core::Constants::ZOOM_RESET);
|
||||
connect(a, &QAction::triggered, this, []() {
|
||||
if (ImageViewer *iv = currentImageViewer())
|
||||
iv->resetToOriginalSize();
|
||||
@@ -125,7 +123,8 @@ QAction *ImageViewerPlugin::registerNewAction(Core::Id id,
|
||||
Core::Context context(Constants::IMAGEVIEWER_ID);
|
||||
QAction *action = new QAction(title, this);
|
||||
Core::Command *command = Core::ActionManager::registerAction(action, id, context);
|
||||
command->setDefaultKeySequence(key);
|
||||
if (!key.isEmpty())
|
||||
command->setDefaultKeySequence(key);
|
||||
return action;
|
||||
}
|
||||
|
||||
|
@@ -28,12 +28,12 @@
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
#include <QKeySequence>
|
||||
#include <QPointer>
|
||||
#include <QtPlugin>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QAction;
|
||||
class QKeySequence;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Core { class Id; }
|
||||
@@ -55,7 +55,8 @@ public:
|
||||
void extensionsInitialized();
|
||||
|
||||
private:
|
||||
QAction *registerNewAction(Core::Id id, const QString &title, const QKeySequence &key);
|
||||
QAction *registerNewAction(Core::Id id, const QString &title = QString(),
|
||||
const QKeySequence &key = QKeySequence());
|
||||
|
||||
QPointer<ImageViewerFactory> m_factory;
|
||||
};
|
||||
|
@@ -173,18 +173,15 @@ void ActionHandler::createActions()
|
||||
menuModelEditor->addSeparator(d->context);
|
||||
|
||||
Core::Command *zoomInCommand = registerCommand(
|
||||
Constants::ZOOM_IN, &ModelEditor::zoomIn, d->context, true,
|
||||
tr("Zoom In"), QKeySequence("Ctrl++"));
|
||||
Core::Constants::ZOOM_IN, &ModelEditor::zoomIn, d->context);
|
||||
menuModelEditor->addAction(zoomInCommand);
|
||||
|
||||
Core::Command *zoomOutCommand = registerCommand(
|
||||
Constants::ZOOM_OUT, &ModelEditor::zoomOut, d->context, true,
|
||||
tr("Zoom Out"), QKeySequence("Ctrl+-"));
|
||||
Core::Constants::ZOOM_OUT, &ModelEditor::zoomOut, d->context);
|
||||
menuModelEditor->addAction(zoomOutCommand);
|
||||
|
||||
Core::Command *resetZoomCommand = registerCommand(
|
||||
Constants::RESET_ZOOM, &ModelEditor::resetZoom, d->context, true,
|
||||
tr("Reset Zoom"), QKeySequence("Ctrl+0"));
|
||||
Core::Constants::ZOOM_RESET, &ModelEditor::resetZoom, d->context);
|
||||
menuModelEditor->addAction(resetZoomCommand);
|
||||
|
||||
d->openParentDiagramAction = registerCommand(
|
||||
|
@@ -37,9 +37,6 @@ const char OPEN_PARENT_DIAGRAM[] = "ModelEditor.OpenParentDiagram";
|
||||
const char MENU_ID[] = "ModelEditor.Menu";
|
||||
const char EXPORT_DIAGRAM[] = "ModelEditor.ExportDiagram";
|
||||
const char EXPORT_SELECTED_ELEMENTS[] = "ModelEditor.ExportSelectedElements";
|
||||
const char ZOOM_IN[] = "ModelEditor.ZoomIn";
|
||||
const char ZOOM_OUT[] = "ModelEditor.ZoomOut";
|
||||
const char RESET_ZOOM[] = "ModelEditor.ResetZoom";
|
||||
const char ACTION_ADD_PACKAGE[] = "ModelEditor.Action.AddPackage";
|
||||
const char ACTION_ADD_COMPONENT[] = "ModelEditor.Action.AddComponent";
|
||||
const char ACTION_ADD_CLASS[] = "ModelEditor.Action.AddClass";
|
||||
|
Reference in New Issue
Block a user