File indexing completed on 2025-01-19 03:50:37
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-02-15 0007 * Description : contextmenu helper class - Actions methods. 0008 * 0009 * SPDX-FileCopyrightText: 2009-2011 by Andi Clemens <andi dot clemens at gmail dot com> 0010 * SPDX-FileCopyrightText: 2010-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "contextmenuhelper_p.h" 0017 0018 namespace Digikam 0019 { 0020 0021 QAction* ContextMenuHelper::exec(const QPoint& pos, QAction* const at) 0022 { 0023 QAction* const choice = d->parent->exec(pos, at); 0024 0025 Q_FOREACH (DPluginAction* const ac, d->exportPluginActions()) 0026 { 0027 ac->setData((int)DPluginAction::NoData); 0028 } 0029 0030 if (choice) 0031 { 0032 if (d->selectedIds.count() == 1) 0033 { 0034 ItemInfo selectedItem(d->selectedIds.first()); 0035 0036 if (choice == d->gotoAlbumAction) 0037 { 0038 Q_EMIT signalGotoAlbum(selectedItem); 0039 } 0040 else if (choice == d->gotoDateAction) 0041 { 0042 Q_EMIT signalGotoDate(selectedItem); 0043 } 0044 else if (choice == d->setThumbnailAction) 0045 { 0046 Q_EMIT signalSetThumbnail(selectedItem); 0047 } 0048 } 0049 0050 // check if a BQM action has been triggered 0051 0052 for (QMap<int, QAction*>::const_iterator it = d->queueActions.constBegin() ; 0053 it != d->queueActions.constEnd() ; ++it) 0054 { 0055 if (choice == it.value()) 0056 { 0057 Q_EMIT signalAddToExistingQueue(it.key()); 0058 0059 return choice; 0060 } 0061 } 0062 } 0063 0064 return choice; 0065 } 0066 0067 void ContextMenuHelper::addAction(const QString& name, bool addDisabled) 0068 { 0069 QAction* const action = d->stdActionCollection->action(name); 0070 addAction(action, addDisabled); 0071 } 0072 0073 void ContextMenuHelper::addAction(QAction* const action, bool addDisabled) 0074 { 0075 if (!action) 0076 { 0077 return; 0078 } 0079 0080 if (action->isEnabled() || addDisabled) 0081 { 0082 d->parent->addAction(action); 0083 } 0084 } 0085 0086 void ContextMenuHelper::addSubMenu(QMenu* const subMenu) 0087 { 0088 d->parent->addMenu(subMenu); 0089 } 0090 0091 void ContextMenuHelper::addSeparator() 0092 { 0093 d->parent->addSeparator(); 0094 } 0095 0096 void ContextMenuHelper::addAction(QAction* const action, QObject* const recv, const char* const slot, bool addDisabled) 0097 { 0098 if (!action) 0099 { 0100 return; 0101 } 0102 0103 connect(action, SIGNAL(triggered()), 0104 recv, slot); 0105 0106 addAction(action, addDisabled); 0107 } 0108 0109 void ContextMenuHelper::addStandardActionLightTable() 0110 { 0111 QAction* action = nullptr; 0112 QStringList ltActionNames; 0113 ltActionNames << QLatin1String("image_add_to_lighttable") 0114 << QLatin1String("image_lighttable"); 0115 0116 if (LightTableWindow::lightTableWindowCreated() && 0117 !LightTableWindow::lightTableWindow()->isEmpty()) 0118 { 0119 action = d->stdActionCollection->action(ltActionNames.at(0)); 0120 } 0121 else 0122 { 0123 action = d->stdActionCollection->action(ltActionNames.at(1)); 0124 } 0125 0126 addAction(action); 0127 } 0128 0129 void ContextMenuHelper::addStandardActionThumbnail(const imageIds& ids, Album* const album) 0130 { 0131 if (d->setThumbnailAction) 0132 { 0133 return; 0134 } 0135 0136 setSelectedIds(ids); 0137 0138 if (album && (ids.count() == 1)) 0139 { 0140 if (album->type() == Album::PHYSICAL) 0141 { 0142 d->setThumbnailAction = new QAction(i18nc("@action: context menu", "Set as Album Thumbnail"), this); 0143 } 0144 else if (album->type() == Album::TAG) 0145 { 0146 d->setThumbnailAction = new QAction(i18nc("@action: context menu", "Set as Tag Thumbnail"), this); 0147 } 0148 0149 addAction(d->setThumbnailAction); 0150 d->parent->addSeparator(); 0151 } 0152 } 0153 0154 void ContextMenuHelper::addStandardActionCut(QObject* const recv, const char* const slot) 0155 { 0156 QAction* const cut = DXmlGuiWindow::buildStdAction(StdCutAction, recv, slot, d->parent); 0157 addAction(cut); 0158 } 0159 0160 void ContextMenuHelper::addStandardActionCopy(QObject* const recv, const char* const slot) 0161 { 0162 QAction* const copy = DXmlGuiWindow::buildStdAction(StdCopyAction, recv, slot, d->parent); 0163 addAction(copy); 0164 } 0165 0166 void ContextMenuHelper::addStandardActionPaste(QObject* const recv, const char* const slot) 0167 { 0168 QAction* const paste = DXmlGuiWindow::buildStdAction(StdPasteAction, recv, slot, d->parent); 0169 const QMimeData* const data = qApp->clipboard()->mimeData(QClipboard::Clipboard); 0170 0171 if (!data || !data->hasUrls()) 0172 { 0173 paste->setEnabled(false); 0174 } 0175 0176 addAction(paste, true); 0177 } 0178 0179 void ContextMenuHelper::addStandardActionItemDelete(QObject* const recv, const char* const slot, int quantity) 0180 { 0181 QAction* const trashAction = new QAction(QIcon::fromTheme(QLatin1String("user-trash")), 0182 i18ncp("@action:inmenu Pluralized", 0183 "Move to Trash", "Move %1 Files to Trash", 0184 quantity), d->parent); 0185 connect(trashAction, SIGNAL(triggered()), 0186 recv, slot); 0187 0188 addAction(trashAction); 0189 } 0190 0191 void ContextMenuHelper::addIQSAction(QObject* const recv, const char* const slot) 0192 { 0193 QAction* const IQSAction = new QAction(QIcon::fromTheme(QLatin1String("")), 0194 i18ncp("@action:inmenu Pluralized", 0195 "Image Quality Sort", "Image Quality Sort", 0196 1), d->parent); 0197 connect(IQSAction, SIGNAL(triggered()), 0198 recv, slot); 0199 0200 addAction(IQSAction); 0201 } 0202 0203 } // namespace Digikam