File indexing completed on 2025-03-09 03:58:42

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2012-14-07
0007  * Description : An embedded view to show the cam item preview widget.
0008  *
0009  * SPDX-FileCopyrightText: 2012 by Islam Wazery  <wazery at ubuntu dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "importpreviewview.h"
0016 
0017 // Qt includes
0018 
0019 #include <QMouseEvent>
0020 #include <QGraphicsSceneContextMenuEvent>
0021 #include <QToolBar>
0022 #include <QMenu>
0023 #include <QApplication>
0024 #include <QIcon>
0025 
0026 // KDE includes
0027 
0028 #include <klocalizedstring.h>
0029 
0030 // Local includes
0031 
0032 #include "dimgpreviewitem.h"
0033 #include "fileactionmngr.h"
0034 #include "importcontextmenu.h"
0035 #include "previewlayout.h"
0036 #include "thememanager.h"
0037 #include "importsettings.h"
0038 #include "previewsettings.h"
0039 
0040 namespace Digikam
0041 {
0042 
0043 class Q_DECL_HIDDEN ImportPreviewViewItem : public DImgPreviewItem
0044 {
0045     Q_OBJECT
0046 
0047 public:
0048 
0049     explicit ImportPreviewViewItem(ImportPreviewView* const view)
0050         : m_view (view)
0051 /*
0052         FIXME
0053         , m_group(0)
0054 */
0055     {
0056         setAcceptHoverEvents(true);
0057     }
0058 
0059 /*
0060     FIXME
0061     void setFaceGroup(FaceGroup* group)
0062     {
0063        m_group = group;
0064     }
0065 */
0066 
0067     void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override
0068     {
0069         m_view->showContextMenu(m_info, event);
0070     }
0071 
0072     void setCamItemInfo(const CamItemInfo& info)
0073     {
0074         m_info = info;
0075 
0076         if (!info.isNull())
0077         {
0078             setPath(info.url().toLocalFile(), true);
0079         }
0080     }
0081 
0082     void hoverEnterEvent(QGraphicsSceneHoverEvent* e) override
0083     {
0084         Q_UNUSED(e)
0085 /*
0086         FIXME
0087         m_group->itemHoverEnterEvent(e);
0088 */
0089     }
0090 
0091     void hoverLeaveEvent(QGraphicsSceneHoverEvent* e) override
0092     {
0093         Q_UNUSED(e)
0094 /*
0095         FIXME:
0096         m_group->itemHoverLeaveEvent(e);
0097 */
0098     }
0099 
0100     void hoverMoveEvent(QGraphicsSceneHoverEvent* e) override
0101     {
0102         Q_UNUSED(e)
0103 /*
0104         FIXME
0105         m_group->itemHoverMoveEvent(e);
0106 */
0107     }
0108 
0109     CamItemInfo camItemInfo() const
0110     {
0111         return m_info;
0112     }
0113 
0114 protected:
0115 
0116     ImportPreviewView*  m_view;
0117 /*
0118     FIXME
0119     FaceGroup*          m_group;
0120 */
0121     CamItemInfo         m_info;
0122 };
0123 
0124 // ---------------------------------------------------------------------
0125 
0126 class Q_DECL_HIDDEN ImportPreviewView::Private
0127 {
0128 public:
0129 
0130     explicit Private()
0131       : fullSize            (false),
0132         scale               (1.0),
0133         isValid             (false),
0134         mode                (ImportPreviewView::IconViewPreview),
0135         item                (nullptr),
0136         escapePreviewAction (nullptr),
0137         prevAction          (nullptr),
0138         nextAction          (nullptr),
0139         rotLeftAction       (nullptr),
0140         rotRightAction      (nullptr),
0141         toolBar             (nullptr)
0142     {
0143 /*
0144         FIXME
0145         peopleTagsShown      = false;
0146         peopleToggleAction   = 0;
0147         addPersonAction      = 0;
0148         faceGroup            = 0;
0149 */
0150     }
0151 
0152     bool                    fullSize;
0153     double                  scale;
0154     bool                    isValid;
0155 
0156     ImportPreviewView::Mode mode;
0157 
0158     ImportPreviewViewItem*  item;
0159 
0160     QAction*                escapePreviewAction;
0161     QAction*                prevAction;
0162     QAction*                nextAction;
0163     QAction*                rotLeftAction;
0164     QAction*                rotRightAction;
0165 
0166     QToolBar*               toolBar;
0167 /*
0168     FIXME
0169     bool                    peopleTagsShown;
0170     QAction*                peopleToggleAction;
0171     QAction*                addPersonAction;
0172     QAction*                forgetFacesAction;
0173     FaceGroup*              faceGroup;
0174 */
0175 };
0176 
0177 ImportPreviewView::ImportPreviewView(QWidget* const parent, Mode mode)
0178     : GraphicsDImgView(parent),
0179       d               (new Private)
0180 {
0181     d->mode = mode;
0182     d->item = new ImportPreviewViewItem(this);
0183     setItem(d->item);
0184 
0185 /*
0186     FIXME
0187     d->faceGroup = new FaceGroup(this);
0188     d->faceGroup->setShowOnHover(true);
0189     d->item->setFaceGroup(d->faceGroup);
0190 */
0191     connect(d->item, SIGNAL(loaded()),
0192             this, SLOT(camItemLoaded()));
0193 
0194     connect(d->item, SIGNAL(loadingFailed()),
0195             this, SLOT(camItemLoadingFailed()));
0196 
0197     // set default zoom
0198 
0199     layout()->fitToWindow();
0200 
0201     // ------------------------------------------------------------
0202 
0203     installPanIcon();
0204 
0205     setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
0206 
0207     // ------------------------------------------------------------
0208 
0209     d->escapePreviewAction = new QAction(QIcon::fromTheme(QLatin1String("folder-pictures")),          i18nc("@action",                       "Escape preview"),                 this);
0210     d->prevAction          = new QAction(QIcon::fromTheme(QLatin1String("go-previous")),              i18nc("@action: go to previous image", "Back"),         this);
0211     d->nextAction          = new QAction(QIcon::fromTheme(QLatin1String("go-next")),                  i18nc("@action: go to next image",     "Forward"),      this);
0212     d->rotLeftAction       = new QAction(QIcon::fromTheme(QLatin1String("object-rotate-left")),       i18nc("@action",                       "Rotate Left"),  this);
0213     d->rotRightAction      = new QAction(QIcon::fromTheme(QLatin1String("object-rotate-right")),      i18nc("@action",                       "Rotate Right"), this);
0214 /*
0215     FIXME
0216     d->addPersonAction    = new QAction(QIcon::fromTheme(QLatin1String("list-add-user")),    i18n("Add a Face Tag"),                 this);
0217     d->forgetFacesAction  = new QAction(QIcon::fromTheme(QLatin1String("list-remove-user")), i18n("Clear all faces on this image"),  this);
0218     d->peopleToggleAction = new Qaction(QIcon::fromTheme(QLatin1String("im-user")),          i18n("Show Face Tags"),                 this);
0219     d->peopleToggleAction->setCheckable(true);
0220 */
0221     d->toolBar = new QToolBar(this);
0222 
0223     if (mode == IconViewPreview)
0224     {
0225         d->toolBar->addAction(d->prevAction);
0226         d->toolBar->addAction(d->nextAction);
0227         d->toolBar->addAction(d->escapePreviewAction);
0228     }
0229 
0230     d->toolBar->addAction(d->rotLeftAction);
0231     d->toolBar->addAction(d->rotRightAction);
0232 /*
0233     FIXME
0234     d->toolBar->addAction(d->peopleToggleAction);
0235     d->toolBar->addAction(d->addPersonAction);
0236 */
0237     connect(d->prevAction, SIGNAL(triggered()),
0238             this, SIGNAL(toPreviousImage()));
0239 
0240     connect(d->nextAction, SIGNAL(triggered()),
0241             this, SIGNAL(toNextImage()));
0242 
0243     connect(d->escapePreviewAction, SIGNAL(triggered()),
0244             this, SIGNAL(signalEscapePreview()));
0245 
0246     connect(d->rotLeftAction, SIGNAL(triggered()),
0247             this, SLOT(slotRotateLeft()));
0248 
0249     connect(d->rotRightAction, SIGNAL(triggered()),
0250             this, SLOT(slotRotateRight()));
0251 /*
0252     FIXME
0253     connect(d->peopleToggleAction, SIGNAL(toggled(bool)),
0254             d->faceGroup, SLOT(setVisible(bool)));
0255 
0256     connect(d->addPersonAction, SIGNAL(triggered()),
0257             d->faceGroup, SLOT(addFace()));
0258 
0259     connect(d->forgetFacesAction, SIGNAL(triggered()),
0260             d->faceGroup, SLOT(rejectAll()));
0261 */
0262     // ------------------------------------------------------------
0263 
0264     connect(this, SIGNAL(toNextImage()),
0265             this, SIGNAL(signalNextItem()));
0266 
0267     connect(this, SIGNAL(toPreviousImage()),
0268             this, SIGNAL(signalPrevItem()));
0269 
0270     connect(this, SIGNAL(activated()),
0271             this, SIGNAL(signalEscapePreview()));
0272 
0273     connect(ThemeManager::instance(), SIGNAL(signalThemeChanged()),
0274             this, SLOT(slotThemeChanged()));
0275 
0276     connect(ImportSettings::instance(), SIGNAL(setupChanged()),
0277             this, SLOT(slotSetupChanged()));
0278 
0279     slotSetupChanged();
0280 }
0281 
0282 ImportPreviewView::~ImportPreviewView()
0283 {
0284     delete d->item;
0285     delete d;
0286 }
0287 
0288 void ImportPreviewView::reload()
0289 {
0290     previewItem()->reload();
0291 }
0292 
0293 void ImportPreviewView::camItemLoaded()
0294 {
0295     Q_EMIT signalPreviewLoaded(true);
0296     d->rotLeftAction->setEnabled(true);
0297     d->rotRightAction->setEnabled(true);
0298 /*
0299     FIXME
0300     d->faceGroup->setInfo(d->item->camItemInfo());
0301 */
0302 }
0303 
0304 void ImportPreviewView::camItemLoadingFailed()
0305 {
0306     Q_EMIT signalPreviewLoaded(false);
0307     d->rotLeftAction->setEnabled(false);
0308     d->rotRightAction->setEnabled(false);
0309 /*
0310     FIXME
0311     d->faceGroup->setInfo(CamItemInfo());
0312 */
0313 }
0314 
0315 void ImportPreviewView::setCamItemInfo(const CamItemInfo& info, const CamItemInfo& previous, const CamItemInfo& next)
0316 {
0317 /*
0318     FIXME
0319     d->faceGroup->aboutToSetInfo(info);
0320 */
0321     d->item->setCamItemInfo(info);
0322 
0323     d->prevAction->setEnabled(!previous.isNull());
0324     d->nextAction->setEnabled(!next.isNull());
0325 
0326     QStringList previewPaths;
0327 
0328     if (identifyCategoryforMime(next.mime) == QLatin1String("image"))
0329     {
0330         previewPaths << next.url().toLocalFile();
0331     }
0332 
0333     if (identifyCategoryforMime(previous.mime) == QLatin1String("image"))
0334     {
0335         previewPaths << previous.url().toLocalFile();
0336     }
0337 
0338     d->item->setPreloadPaths(previewPaths);
0339 }
0340 
0341 QString ImportPreviewView::identifyCategoryforMime(const QString& mime)
0342 {
0343     return mime.split(QLatin1Char('/')).at(0);
0344 }
0345 
0346 CamItemInfo ImportPreviewView::getCamItemInfo() const
0347 {
0348     return d->item->camItemInfo();
0349 }
0350 
0351 bool ImportPreviewView::acceptsMouseClick(QMouseEvent* e)
0352 {
0353     if (!GraphicsDImgView::acceptsMouseClick(e))
0354     {
0355         return false;
0356     }
0357 
0358     return true;
0359 /*
0360     FIXME
0361     return d->faceGroup->acceptsMouseClick(mapToScene(e->pos()));
0362 */
0363 }
0364 
0365 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
0366 
0367 void ImportPreviewView::enterEvent(QEnterEvent* e)
0368 
0369 #else
0370 
0371 void ImportPreviewView::enterEvent(QEvent* e)
0372 
0373 #endif
0374 
0375 {
0376     Q_UNUSED(e)
0377 /*
0378     FIXME
0379     d->faceGroup->enterEvent(e);
0380 */
0381 }
0382 
0383 void ImportPreviewView::leaveEvent(QEvent* e)
0384 {
0385     Q_UNUSED(e)
0386 /*
0387     FIXME
0388     d->faceGroup->leaveEvent(e);
0389 */
0390 }
0391 
0392 void ImportPreviewView::showEvent(QShowEvent* e)
0393 {
0394     GraphicsDImgView::showEvent(e);
0395 /*
0396     FIXME
0397     d->faceGroup->setVisible(d->peopleToggleAction->isChecked());
0398 */
0399 }
0400 
0401 void ImportPreviewView::showContextMenu(const CamItemInfo& info, QGraphicsSceneContextMenuEvent* event)
0402 {
0403     if (info.isNull())
0404     {
0405         return;
0406     }
0407 
0408     event->accept();
0409 
0410     QList<qlonglong> idList;
0411     idList << info.id;
0412     QList<QUrl> selectedItems;
0413     selectedItems << info.url();
0414 
0415     // --------------------------------------------------------
0416 
0417     QMenu popmenu(this);
0418     ImportContextMenuHelper cmhelper(&popmenu);
0419 
0420     cmhelper.addAction(QLatin1String("importui_fullscreen"));
0421     cmhelper.addAction(QLatin1String("options_show_menubar"));
0422     cmhelper.addSeparator();
0423 
0424     // --------------------------------------------------------
0425 
0426     if (d->mode == IconViewPreview)
0427     {
0428         cmhelper.addAction(d->prevAction, true);
0429         cmhelper.addAction(d->nextAction, true);
0430         cmhelper.addAction(QLatin1String("importui_icon_view"));
0431 /*
0432         FIXME
0433         //cmhelper.addGotoMenu(idList);
0434 */
0435         cmhelper.addSeparator();
0436     }
0437 
0438     // --------------------------------------------------------
0439 /*
0440     FIXME
0441     cmhelper.addAction(d->peopleToggleAction, true);
0442     cmhelper.addAction(d->addPersonAction, true);
0443     cmhelper.addAction(d->forgetFacesAction, true);
0444     cmhelper.addSeparator();
0445 */
0446     // --------------------------------------------------------
0447 
0448     cmhelper.addServicesMenu(selectedItems);
0449     cmhelper.addRotateMenu(idList);
0450     cmhelper.addSeparator();
0451 
0452     // --------------------------------------------------------
0453 
0454     cmhelper.addAction(QLatin1String("importui_delete"));
0455     cmhelper.addSeparator();
0456 
0457     // --------------------------------------------------------
0458 /*
0459     FIXME
0460     cmhelper.addAssignTagsMenu(idList);
0461     cmhelper.addRemoveTagsMenu(idList);
0462     cmhelper.addSeparator();
0463 */
0464     // --------------------------------------------------------
0465 
0466     cmhelper.addLabelsAction();
0467 
0468     // special action handling --------------------------------
0469 /*
0470     FIXME
0471     connect(&cmhelper, SIGNAL(signalAssignTag(int)),
0472            this, SLOT(slotAssignTag(int)));
0473 
0474     connect(&cmhelper, SIGNAL(signalPopupTagsView()),
0475             this, SIGNAL(signalPopupTagsView()));
0476 
0477     connect(&cmhelper, SIGNAL(signalRemoveTag(int)),
0478             this, SLOT(slotRemoveTag(int)));
0479 
0480     connect(&cmhelper, SIGNAL(signalAssignPickLabel(int)),
0481             this, SLOT(slotAssignPickLabel(int)));
0482 
0483     connect(&cmhelper, SIGNAL(signalAssignColorLabel(int)),
0484             this, SLOT(slotAssignColorLabel(int)));
0485 */
0486     connect(&cmhelper, SIGNAL(signalAssignPickLabel(int)),
0487             this, SIGNAL(signalAssignPickLabel(int)));
0488 
0489     connect(&cmhelper, SIGNAL(signalAssignColorLabel(int)),
0490             this, SIGNAL(signalAssignColorLabel(int)));
0491 
0492     connect(&cmhelper, SIGNAL(signalAssignRating(int)),
0493             this, SIGNAL(signalAssignRating(int)));
0494 /*
0495     FIXME
0496     connect(&cmhelper, SIGNAL(signalAddToExistingQueue(int)),
0497             this, SIGNAL(signalAddToExistingQueue(int)));
0498 
0499     connect(&cmhelper, SIGNAL(signalGotoTag(int)),
0500             this, SIGNAL(signalGotoTagAndItem(int)));
0501 */
0502     cmhelper.exec(event->screenPos());
0503 }
0504 
0505 /*
0506 FIXME
0507 void ImportPreviewView::slotAssignTag(int tagID)
0508 {
0509    FileActionMngr::instance()->assignTag(d->item->camItemInfo(), tagID);
0510 }
0511 
0512 void ImportPreviewView::slotRemoveTag(int tagID)
0513 {
0514    FileActionMngr::instance()->removeTag(d->item->camItemInfo(), tagID);
0515 }
0516 */
0517 
0518 void ImportPreviewView::slotThemeChanged()
0519 {
0520     QPalette plt(palette());
0521     plt.setColor(backgroundRole(), qApp->palette().color(QPalette::Base));
0522     setPalette(plt);
0523 }
0524 
0525 void ImportPreviewView::slotSetupChanged()
0526 {
0527     PreviewSettings settings;
0528     settings.quality = ImportSettings::instance()->getPreviewLoadFullImageSize() ? PreviewSettings::HighQualityPreview
0529                                                                                  : PreviewSettings::FastPreview;
0530     previewItem()->setPreviewSettings(settings);
0531 
0532     d->toolBar->setVisible(ImportSettings::instance()->getPreviewShowIcons());
0533     setShowText(ImportSettings::instance()->getPreviewShowIcons());
0534 
0535     // pass auto-suggest?
0536 }
0537 
0538 void ImportPreviewView::slotRotateLeft()
0539 {
0540 /*
0541     FIXME
0542     ItemInfo info(d->item->camItemInfo().url().toLocalFile());
0543 
0544     FileActionMngr::instance()->transform(QList<ItemInfo>() << info, MetaEngineRotation::Rotate270);
0545 */
0546 }
0547 
0548 void ImportPreviewView::slotRotateRight()
0549 {
0550 /*
0551     FIXME
0552     ItemInfo info(d->item->camItemInfo().url().toLocalFile());
0553 
0554     FileActionMngr::instance()->transform(QList<ItemInfo>() << info, MetaEngineRotation::Rotate90);
0555 */
0556 }
0557 
0558 void ImportPreviewView::slotDeleteItem()
0559 {
0560     Q_EMIT signalDeleteItem();
0561 }
0562 
0563 } // namespace Digikam
0564 
0565 #include "importpreviewview.moc"
0566 
0567 #include "moc_importpreviewview.cpp"