File indexing completed on 2025-03-09 03:52:04

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2018-07-30
0007  * Description : a plugin to preview image with OpenGL.
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 "glviewerplugin.h"
0016 
0017 // Qt includes
0018 
0019 #include <QPointer>
0020 #include <QMessageBox>
0021 
0022 // KDE includes
0023 
0024 #include <klocalizedstring.h>
0025 
0026 // Local includes
0027 
0028 #include "glviewerwidget.h"
0029 #include "digikam_debug.h"
0030 
0031 namespace DigikamGenericGLViewerPlugin
0032 {
0033 
0034 GLViewerPlugin::GLViewerPlugin(QObject* const parent)
0035     : DPluginGeneric(parent)
0036 {
0037 }
0038 
0039 GLViewerPlugin::~GLViewerPlugin()
0040 {
0041 }
0042 
0043 QString GLViewerPlugin::name() const
0044 {
0045     return i18n("OpenGL Viewer");
0046 }
0047 
0048 QString GLViewerPlugin::iid() const
0049 {
0050     return QLatin1String(DPLUGIN_IID);
0051 }
0052 
0053 QIcon GLViewerPlugin::icon() const
0054 {
0055     return QIcon::fromTheme(QLatin1String("show-gpu-effects"));
0056 }
0057 
0058 QString GLViewerPlugin::description() const
0059 {
0060     return i18n("A tool to preview image with OpenGL");
0061 }
0062 
0063 QString GLViewerPlugin::details() const
0064 {
0065     return i18n("<p>This tool preview a series of items using OpenGL effects.</p>"
0066                 "<p><u>Usage:</u></p>"
0067 
0068                 "<table>"
0069 
0070                     "<tr>"
0071                         "<td colspan=\"2\"><nobr><center>"
0072                             "<b><h1>Item Access</h1></b>"
0073                         "</center></nobr></td>"
0074                     "</tr>"
0075 
0076                     "<tr><td>Previous Item:</td>"                "<td><i>Up</i> key</td></tr>"
0077                     "<tr><td></td>"                              "<td><i>PgUp</i> key</td></tr>"
0078                     "<tr><td></td>"                              "<td><i>Left</i> key</td></tr>"
0079                     "<tr><td></td>"                              "<td>Mouse wheel up</td></tr>"
0080                     "<tr><td>Next Item:</td>"                    "<td><i>Down</i> key</td></tr>"
0081                     "<tr><td></td>"                              "<td><i>PgDown</i> key</td></tr>"
0082                     "<tr><td></td>"                              "<td><i>Right</i> key</td></tr>"
0083                     "<tr><td></td>"                              "<td>Mouse wheel down</td></tr>"
0084                     "<tr><td>Quit:</td>"                         "<td><i>Esc</i> key</td></tr>"
0085 
0086                     "<tr>"
0087                         "<td colspan=\"2\"><nobr><center>"
0088                             "<b><h1>Item Display</h1></b>"
0089                         "</center></nobr></td>"
0090                     "</tr>"
0091 
0092                     "<tr><td>Toggle fullscreen to normal:</td>"  "<td><i>f</i> key</td></tr>"
0093                     "<tr><td>Toggle scroll-wheel action:</td>"   "<td><i>c</i> key (either zoom or change image)</td></tr>"
0094                     "<tr><td>Rotation:</td>"                     "<td><i>r</i> key</td></tr>"
0095                     "<tr><td>Reset view:</td>"                   "<td>double click</td></tr>"
0096                     "<tr><td>Original size:</td>"                "<td><i>o</i> key</td></tr>"
0097 
0098                     "<tr><td>Zooming:</td>"                      "<td>Move mouse in up-down-direction while pressing the right mouse button</td></tr>"
0099                     "<tr><td></td>"                              "<td><i>c</i> key and use the scroll-wheel</td></tr>"
0100                     "<tr><td></td>"                              "<td><i>+</i> and <i>-</i> keys</td></tr>"
0101                     "<tr><td></td>"                              "<td>ctrl + scrollwheel</td></tr>"
0102 
0103                     "<tr><td>Panning:</td>"                      "<td>Move mouse while pressing the left button</td></tr>"
0104 
0105                     "<tr>"
0106                         "<td colspan=\"2\"><nobr><center>"
0107                             "<b><h1>Others</h1></b>"
0108                         "</center></nobr></td>"
0109                     "</tr>"
0110 
0111                     "<tr><td>Show this help:</td>"               "<td><i>F1</i> key</td></tr>"
0112 
0113                 "</table>");
0114 }
0115 
0116 QString GLViewerPlugin::handbookSection() const
0117 {
0118     return QLatin1String("slideshow_tools");
0119 }
0120 
0121 QString GLViewerPlugin::handbookChapter() const
0122 {
0123     return QLatin1String("opengl_viewer");
0124 }
0125 
0126 QList<DPluginAuthor> GLViewerPlugin::authors() const
0127 {
0128     return QList<DPluginAuthor>()
0129             << DPluginAuthor(QString::fromUtf8("Markus Leuthold"),
0130                              QString::fromUtf8("kusi at forum dot titlis dot org"),
0131                              QString::fromUtf8("(C) 2007-2008"))
0132             << DPluginAuthor(QString::fromUtf8("Gilles Caulier"),
0133                              QString::fromUtf8("caulier dot gilles at gmail dot com"),
0134                              QString::fromUtf8("(C) 2008-2023"))
0135             ;
0136 }
0137 
0138 void GLViewerPlugin::setup(QObject* const parent)
0139 {
0140     DPluginAction* const ac = new DPluginAction(parent);
0141     ac->setIcon(icon());
0142     ac->setText(i18nc("@action", "OpenGL Image Viewer"));
0143     ac->setObjectName(QLatin1String("glviewer"));
0144     ac->setActionCategory(DPluginAction::GenericView);
0145 
0146     connect(ac, SIGNAL(triggered(bool)),
0147             this, SLOT(slotGLViewer()));
0148 
0149     addAction(ac);
0150 }
0151 
0152 void GLViewerPlugin::slotGLViewer()
0153 {
0154     DInfoInterface* const iface = infoIface(sender());
0155 
0156     QList<QUrl> myfiles;                                            // pics which are displayed in imageviewer
0157     QList<QUrl> selection       = iface->currentSelectedItems();
0158     QString selectedImage;                                          // selected pic in hostapp
0159 
0160     if      (selection.count() == 0)
0161     {
0162         qCDebug(DIGIKAM_DPLUGIN_GENERIC_LOG) << "no image selected, load entire album";
0163         myfiles = iface->currentAlbumItems();
0164     }
0165     else if (selection.count() == 1)
0166     {
0167         qCDebug(DIGIKAM_DPLUGIN_GENERIC_LOG) << "one image selected, load entire album and start with selected image";
0168         selectedImage = selection.first().toLocalFile();
0169         myfiles       = iface->currentAlbumItems();
0170     }
0171     else if (selection.count() > 1)
0172     {
0173         qCDebug(DIGIKAM_DPLUGIN_GENERIC_LOG) << "load" << selection.count() << "selected images";
0174         myfiles = selection;
0175     }
0176 
0177     if (myfiles.isEmpty())
0178     {
0179         return;
0180     }
0181 
0182     QPointer<GLViewerWidget> view = new GLViewerWidget(this, iface, myfiles, selectedImage);
0183 
0184     switch (view->getOGLstate())
0185     {
0186         case oglOK:
0187         {
0188             view->show();
0189             break;
0190         }
0191 
0192         case oglNoRectangularTexture:
0193         {
0194             qCCritical(DIGIKAM_DPLUGIN_GENERIC_LOG) << "GL_ARB_texture_rectangle not supported";
0195             QMessageBox::critical(nullptr, i18n("OpenGL Error"),
0196                                   i18n("GL_ARB_texture_rectangle OpenGL extension is not supported on your system"));
0197             view->close();
0198             break;
0199         }
0200 
0201         case oglNoContext:
0202         {
0203             qCCritical(DIGIKAM_DPLUGIN_GENERIC_LOG) << "no OpenGL context found";
0204             QMessageBox::critical(nullptr, i18n("OpenGL Error"),
0205                                   i18n("No OpenGL context has been found"));
0206             view->close();
0207             break;
0208         }
0209     }
0210 }
0211 
0212 } // namespace DigikamGenericGLViewerPlugin
0213 
0214 #include "moc_glviewerplugin.cpp"