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

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 auto-crop 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 "autocroptoolplugin.h"
0016 
0017 // Qt includes
0018 
0019 #include <QApplication>
0020 
0021 // KDE includes
0022 
0023 #include <klocalizedstring.h>
0024 
0025 // Local includes
0026 
0027 #include "imageiface.h"
0028 #include "autocrop.h"
0029 
0030 namespace DigikamEditorAutoCropToolPlugin
0031 {
0032 
0033 AutoCropToolPlugin::AutoCropToolPlugin(QObject* const parent)
0034     : DPluginEditor(parent)
0035 {
0036 }
0037 
0038 AutoCropToolPlugin::~AutoCropToolPlugin()
0039 {
0040 }
0041 
0042 QString AutoCropToolPlugin::name() const
0043 {
0044     return i18nc("@title", "Auto-Crop");
0045 }
0046 
0047 QString AutoCropToolPlugin::iid() const
0048 {
0049     return QLatin1String(DPLUGIN_IID);
0050 }
0051 
0052 QIcon AutoCropToolPlugin::icon() const
0053 {
0054     return QIcon::fromTheme(QLatin1String("transform-crop"));
0055 }
0056 
0057 QString AutoCropToolPlugin::description() const
0058 {
0059     return i18nc("@info", "A tool to auto-crop an image");
0060 }
0061 
0062 QString AutoCropToolPlugin::details() const
0063 {
0064     return i18nc("@info", "This Image Editor tool can crop automatically an image by detection of inner black border, "
0065                           "generated while panorama stitching for example.");
0066 }
0067 
0068 QString AutoCropToolPlugin::handbookSection() const
0069 {
0070     return QLatin1String("image_editor");
0071 }
0072 
0073 QString AutoCropToolPlugin::handbookChapter() const
0074 {
0075     return QLatin1String("transform_tools");
0076 }
0077 
0078 QString AutoCropToolPlugin::handbookReference() const
0079 {
0080     return QLatin1String("transform-autocrop");
0081 }
0082 
0083 QList<DPluginAuthor> AutoCropToolPlugin::authors() const
0084 {
0085     return QList<DPluginAuthor>()
0086             << DPluginAuthor(QString::fromUtf8("Sayantan Datta"),
0087                              QString::fromUtf8("sayantan dot knz at gmail dot com"),
0088                              QString::fromUtf8("(C) 2013"))
0089             << DPluginAuthor(QString::fromUtf8("Gilles Caulier"),
0090                              QString::fromUtf8("caulier dot gilles at gmail dot com"),
0091                              QString::fromUtf8("(C) 2013-2021"))
0092             ;
0093 }
0094 
0095 void AutoCropToolPlugin::setup(QObject* const parent)
0096 {
0097     DPluginAction* const ac = new DPluginAction(parent);
0098     ac->setIcon(icon());
0099     ac->setText(i18nc("@action", "&Auto-Crop"));
0100     ac->setObjectName(QLatin1String("editorwindow_transform_autocrop"));
0101     ac->setWhatsThis(i18nc("@info", "This option can be used to crop automatically the image."));
0102     ac->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_X);
0103     ac->setActionCategory(DPluginAction::EditorTransform);
0104 
0105     connect(ac, SIGNAL(triggered(bool)),
0106             this, SLOT(slotAutoCrop()));
0107 
0108     addAction(ac);
0109 }
0110 
0111 void AutoCropToolPlugin::slotAutoCrop()
0112 {
0113     QApplication::setOverrideCursor(Qt::WaitCursor);
0114 
0115     ImageIface iface;
0116     AutoCrop ac(iface.original());
0117     ac.startFilterDirectly();
0118     QRect rect = ac.autoInnerCrop();
0119     iface.crop(rect);
0120 
0121     QApplication::restoreOverrideCursor();
0122 }
0123 
0124 } // namespace DigikamEditorAutoCropToolPlugin
0125 
0126 #include "moc_autocroptoolplugin.cpp"