aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/imageviewer/imageviewerplugin.cpp
blob: 6c59d9845ef35abf83d06e1e2cf66335f90dee9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright (C) 2016 Denis Mingulov.
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0

#include "imageviewerplugin.h"

#include "imageviewer.h"
#include "imageviewerconstants.h"
#include "imageviewertr.h"

#include <coreplugin/icore.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>

#include <QAction>
#include <QCoreApplication>
#include <QKeySequence>

using namespace Core;
using namespace Utils;

namespace ImageViewer::Internal {

class ImageViewerAction final : public QAction
{
public:
    ImageViewerAction(Id id,
                      const std::function<void(ImageViewer *v)> &onTriggered,
                      const QString &title = {},
                      const QKeySequence &key = {})
        : QAction(title)
    {
        Command *command = ActionManager::registerAction(this, id, Context(Constants::IMAGEVIEWER_ID));
        if (!key.isEmpty())
            command->setDefaultKeySequence(key);

        connect(this, &QAction::triggered, this, [onTriggered] {
            if (auto iv = qobject_cast<ImageViewer *>(EditorManager::currentEditor()))
                onTriggered(iv);
        });
    }
};

class ImageViewerPluginPrivate final
{
public:
    ImageViewerFactory imageViewerFactory;

    ImageViewerAction zoomInAction {
        Core::Constants::ZOOM_IN,
        &ImageViewer::zoomIn
    };

    ImageViewerAction zoomOutAction {
        Core::Constants::ZOOM_OUT,
        &ImageViewer::zoomOut
    };

    ImageViewerAction zoomResetAction {
        Core::Constants::ZOOM_RESET,
        &ImageViewer::resetToOriginalSize
    };

    ImageViewerAction fitToScreenAction {
        Constants::ACTION_FIT_TO_SCREEN,
        &ImageViewer::fitToScreen,
        Tr::tr("Fit to Screen"),
        Tr::tr("Ctrl+=")
    };

    ImageViewerAction switchBackgroundAction {
        Constants::ACTION_BACKGROUND,
        &ImageViewer::switchViewBackground,
        Tr::tr("Switch Background"),
        Tr::tr("Ctrl+[")
    };

    ImageViewerAction switchOutlineAction {
        Constants::ACTION_OUTLINE,
        &ImageViewer::switchViewOutline,
        Tr::tr("Switch Outline"),
        Tr::tr("Ctrl+]")
    };

    ImageViewerAction toggleAnimationAction {
        Constants::ACTION_TOGGLE_ANIMATION,
        &ImageViewer::togglePlay,
        Tr::tr("Toggle Animation")
    };

    ImageViewerAction exportImageAction {
        Constants::ACTION_EXPORT_IMAGE,
        &ImageViewer::exportImage,
        Tr::tr("Export Image")
    };

    ImageViewerAction exportMulitImagesAction {
        Constants::ACTION_EXPORT_MULTI_IMAGES,
        &ImageViewer::exportMultiImages,
        Tr::tr("Export Multiple Images"),
    };

    ImageViewerAction copyDataUrlAction {
        Constants::ACTION_COPY_DATA_URL,
        &ImageViewer::copyDataUrl,
        Tr::tr("Copy as Data URL"),
    };
};

ImageViewerPlugin::~ImageViewerPlugin()
{
    delete  d;
}

bool ImageViewerPlugin::initialize(const QStringList &arguments, QString *errorMessage)
{
    Q_UNUSED(arguments)
    Q_UNUSED(errorMessage)

    d = new ImageViewerPluginPrivate;

    return true;
}

} // ImageViewer::Internal