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

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 print 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 "printplugin.h"
0016 
0017 // Qt includes
0018 
0019 #include <QPointer>
0020 
0021 // KDE includes
0022 
0023 #include <klocalizedstring.h>
0024 
0025 // Local includes
0026 
0027 #include "imageiface.h"
0028 #include "editorwindow.h"
0029 #include "printhelper.h"
0030 
0031 namespace DigikamEditorPrintToolPlugin
0032 {
0033 
0034 PrintToolPlugin::PrintToolPlugin(QObject* const parent)
0035     : DPluginEditor(parent)
0036 {
0037 }
0038 
0039 PrintToolPlugin::~PrintToolPlugin()
0040 {
0041 }
0042 
0043 QString PrintToolPlugin::name() const
0044 {
0045     return i18nc("@title", "Print Image");
0046 }
0047 
0048 QString PrintToolPlugin::iid() const
0049 {
0050     return QLatin1String(DPLUGIN_IID);
0051 }
0052 
0053 QIcon PrintToolPlugin::icon() const
0054 {
0055     return QIcon::fromTheme(QLatin1String("document-print-frame"));
0056 }
0057 
0058 QString PrintToolPlugin::description() const
0059 {
0060     return i18nc("@info", "A tool to print an image");
0061 }
0062 
0063 QString PrintToolPlugin::details() const
0064 {
0065     return i18nc("@info", "This Image Editor tool can print an image.");
0066 }
0067 
0068 QString PrintToolPlugin::handbookSection() const
0069 {
0070     return QLatin1String("image_editor");
0071 }
0072 
0073 QString PrintToolPlugin::handbookChapter() const
0074 {
0075     return QLatin1String("basic_operations");
0076 }
0077 
0078 QString PrintToolPlugin::handbookReference() const
0079 {
0080     return QLatin1String("printing-images");
0081 }
0082 
0083 QList<DPluginAuthor> PrintToolPlugin::authors() const
0084 {
0085     return QList<DPluginAuthor>()
0086             << DPluginAuthor(QString::fromUtf8("Angelo Naselli"),
0087                              QString::fromUtf8("anaselli at linux dot it"),
0088                              QString::fromUtf8("(C) 2009"))
0089             << DPluginAuthor(QString::fromUtf8("Gilles Caulier"),
0090                              QString::fromUtf8("caulier dot gilles at gmail dot com"),
0091                              QString::fromUtf8("(C) 2009-2023"))
0092             ;
0093 }
0094 
0095 void PrintToolPlugin::setup(QObject* const parent)
0096 {
0097     DPluginAction* const ac = new DPluginAction(parent);
0098     ac->setIcon(icon());
0099     ac->setText(i18nc("@action", "Print Image..."));
0100     ac->setObjectName(QLatin1String("editorwindow_print"));
0101     ac->setShortcut(Qt::CTRL | Qt::Key_P);
0102     ac->setActionCategory(DPluginAction::EditorFile);
0103 
0104     connect(ac, SIGNAL(triggered(bool)),
0105             this, SLOT(slotPrint()));
0106 
0107     addAction(ac);
0108 }
0109 
0110 void PrintToolPlugin::slotPrint()
0111 {
0112     EditorWindow* const editor = dynamic_cast<EditorWindow*>(sender()->parent());
0113 
0114     if (editor)
0115     {
0116         ImageIface iface;
0117         DImg* const image = iface.original();
0118 
0119         if (!image || image->isNull())
0120         {
0121             return;
0122         }
0123 
0124         PrintHelper printHelp(editor);
0125         printHelp.print(*image);
0126     }
0127 }
0128 
0129 } // namespace DigikamEditorPrintToolPlugin
0130 
0131 #include "moc_printplugin.cpp"