File indexing completed on 2025-01-19 03:51:13

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2018-07-30
0007  * Description : image editor plugin to rotate an image.
0008  *
0009  * SPDX-FileCopyrightText: 2018-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "freerotationtoolplugin.h"
0016 
0017 // Qt includes
0018 
0019 #include <QPointer>
0020 
0021 // KDE includes
0022 
0023 #include <klocalizedstring.h>
0024 #include <kactioncollection.h>
0025 #include <kxmlguiwindow.h>
0026 
0027 // Local includes
0028 
0029 #include "editorwindow.h"
0030 #include "freerotationtool.h"
0031 
0032 namespace DigikamEditorFreeRotationToolPlugin
0033 {
0034 
0035 FreeRotationToolPlugin::FreeRotationToolPlugin(QObject* const parent)
0036     : DPluginEditor(parent)
0037 {
0038 }
0039 
0040 FreeRotationToolPlugin::~FreeRotationToolPlugin()
0041 {
0042 }
0043 
0044 QString FreeRotationToolPlugin::name() const
0045 {
0046     return i18nc("@title", "Free Rotation");
0047 }
0048 
0049 QString FreeRotationToolPlugin::iid() const
0050 {
0051     return QLatin1String(DPLUGIN_IID);
0052 }
0053 
0054 QIcon FreeRotationToolPlugin::icon() const
0055 {
0056     return QIcon::fromTheme(QLatin1String("transform-rotate"));
0057 }
0058 
0059 QString FreeRotationToolPlugin::description() const
0060 {
0061     return i18nc("@info", "A tool to rotate an image");
0062 }
0063 
0064 QString FreeRotationToolPlugin::details() const
0065 {
0066     return i18nc("@info", "This Image Editor tool can rotate an image with an arbitrary angle.");
0067 }
0068 
0069 QString FreeRotationToolPlugin::handbookSection() const
0070 {
0071     return QLatin1String("image_editor");
0072 }
0073 
0074 QString FreeRotationToolPlugin::handbookChapter() const
0075 {
0076     return QLatin1String("transform_tools");
0077 }
0078 
0079 QString FreeRotationToolPlugin::handbookReference() const
0080 {
0081     return QLatin1String("transform-freerotation");
0082 }
0083 
0084 QList<DPluginAuthor> FreeRotationToolPlugin::authors() const
0085 {
0086     return QList<DPluginAuthor>()
0087             << DPluginAuthor(QString::fromUtf8("Andi Clemens"),
0088                              QString::fromUtf8("andi dot clemens at gmail dot com"),
0089                              QString::fromUtf8("(C) 2009-2010"))
0090             << DPluginAuthor(QString::fromUtf8("Gilles Caulier"),
0091                              QString::fromUtf8("caulier dot gilles at gmail dot com"),
0092                              QString::fromUtf8("(C) 2004-2021"))
0093             ;
0094 }
0095 
0096 void FreeRotationToolPlugin::setup(QObject* const parent)
0097 {
0098     DPluginAction* const ac = new DPluginAction(parent);
0099     ac->setIcon(icon());
0100     ac->setText(i18nc("@action", "Free Rotation..."));
0101     ac->setObjectName(QLatin1String("editorwindow_transform_freerotation"));
0102     ac->setActionCategory(DPluginAction::EditorTransform);
0103 
0104     connect(ac, SIGNAL(triggered(bool)),
0105             this, SLOT(slotFreeRotation()));
0106 
0107     addAction(ac);
0108 
0109     QAction* const point1Action = new QAction(i18nc("@action", "Free Rotation Set Point 1"), parent);
0110     point1Action->setObjectName(QLatin1String("editorwindow_transform_freerotation_point1"));
0111 
0112     connect(point1Action, SIGNAL(triggered(bool)),
0113             this, SIGNAL(signalPoint1Action()));
0114 
0115     QAction* const point2Action = new QAction(i18nc("@action", "Free Rotation Set Point 2"), parent);
0116     point2Action->setObjectName(QLatin1String("editorwindow_transform_freerotation_point2"));
0117 
0118     connect(point2Action, SIGNAL(triggered(bool)),
0119             this, SIGNAL(signalPoint2Action()));
0120 
0121     QAction* const autoAdjustAction = new QAction(i18nc("@action", "Free Rotation Auto Adjust"), parent);
0122     autoAdjustAction->setObjectName(QLatin1String("editorwindow_transform_freerotation_autoadjust"));
0123 
0124     connect(autoAdjustAction, SIGNAL(triggered(bool)),
0125             this, SIGNAL(signalAutoAdjustAction()));
0126 
0127     KXmlGuiWindow* const gui = dynamic_cast<KXmlGuiWindow*>(parent);
0128 
0129     if (gui)
0130     {
0131         KActionCollection* const collection = gui->actionCollection();
0132 
0133         collection->addAction(point1Action->objectName(),     point1Action);
0134         collection->addAction(point2Action->objectName(),     point2Action);
0135         collection->addAction(autoAdjustAction->objectName(), autoAdjustAction);
0136 
0137         collection->setDefaultShortcut(point1Action,     Qt::CTRL | Qt::SHIFT | Qt::Key_1);
0138         collection->setDefaultShortcut(point2Action,     Qt::CTRL | Qt::SHIFT | Qt::Key_2);
0139         collection->setDefaultShortcut(autoAdjustAction, Qt::CTRL | Qt::SHIFT | Qt::Key_R);
0140     }
0141 }
0142 
0143 void FreeRotationToolPlugin::slotFreeRotation()
0144 {
0145     EditorWindow* const editor = dynamic_cast<EditorWindow*>(sender()->parent());
0146 
0147     if (editor)
0148     {
0149         FreeRotationTool* const tool = new FreeRotationTool(editor);
0150         tool->setPlugin(this);
0151 
0152         connect(this, SIGNAL(signalPoint1Action()),
0153                 tool, SLOT(slotAutoAdjustP1Clicked()));
0154 
0155         connect(this, SIGNAL(signalPoint2Action()),
0156                 tool, SLOT(slotAutoAdjustP2Clicked()));
0157 
0158         connect(this, SIGNAL(signalAutoAdjustAction()),
0159                 tool, SLOT(slotAutoAdjustClicked()));
0160 
0161         editor->loadTool(tool);
0162     }
0163 }
0164 
0165 } // namespace DigikamEditorFreeRotationToolPlugin
0166 
0167 #include "moc_freerotationtoolplugin.cpp"