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 - Albums 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 void ContextMenuHelper::addActionNewAlbum(AlbumModificationHelper* const helper, PAlbum* const parentAlbum) 0022 { 0023 QAction* const action = d->copyFromMainCollection(QLatin1String("album_new")); 0024 addAction(action); 0025 helper->bindAlbum(action, parentAlbum); 0026 0027 connect(action, SIGNAL(triggered()), 0028 helper, SLOT(slotAlbumNew())); 0029 } 0030 0031 void ContextMenuHelper::addActionDeleteAlbum(AlbumModificationHelper* const helper, PAlbum* const album) 0032 { 0033 QAction* const action = d->copyFromMainCollection(QLatin1String("album_delete")); 0034 addAction(action, !(album->isRoot() || album->isAlbumRoot())); 0035 helper->bindAlbum(action, album); 0036 0037 connect(action, SIGNAL(triggered()), 0038 helper, SLOT(slotAlbumDelete())); 0039 } 0040 0041 void ContextMenuHelper::addActionEditAlbum(AlbumModificationHelper* const helper, PAlbum* const album) 0042 { 0043 QAction* const action = d->copyFromMainCollection(QLatin1String("album_propsEdit")); 0044 addAction(action, !album->isRoot()); 0045 helper->bindAlbum(action, album); 0046 0047 connect(action, SIGNAL(triggered()), 0048 helper, SLOT(slotAlbumEdit())); 0049 } 0050 0051 void ContextMenuHelper::addActionRenameAlbum(AlbumModificationHelper* const helper, PAlbum* const album) 0052 { 0053 QAction* const action = d->copyFromMainCollection(QLatin1String("album_rename")); 0054 addAction(action, !album->isRoot()); 0055 helper->bindAlbum(action, album); 0056 0057 connect(action, SIGNAL(triggered()), 0058 helper, SLOT(slotAlbumRename())); 0059 } 0060 0061 void ContextMenuHelper::addActionResetAlbumIcon(AlbumModificationHelper* const helper, PAlbum* const album) 0062 { 0063 QAction* const action = new QAction(QIcon::fromTheme(QLatin1String("view-refresh")), 0064 i18nc("@action: context menu", "Reset Album Icon"), this); 0065 addAction(action, !album->isRoot()); 0066 helper->bindAlbum(action, album); 0067 0068 connect(action, SIGNAL(triggered()), 0069 helper, SLOT(slotAlbumResetIcon())); 0070 } 0071 0072 void ContextMenuHelper::slotDeselectAllAlbumItems() 0073 { 0074 QAction* const selectNoneAction = d->stdActionCollection->action(QLatin1String("selectNone")); 0075 QTimer::singleShot(75, selectNoneAction, SIGNAL(triggered())); 0076 } 0077 0078 void ContextMenuHelper::setAlbumModel(AbstractCheckableAlbumModel* model) 0079 { 0080 d->albumModel = model; 0081 } 0082 0083 void ContextMenuHelper::addAlbumCheckUncheckActions(Album* const album) 0084 { 0085 bool enabled = false; 0086 QString allString = i18nc("@action: context menu", "All Albums"); 0087 QVariant albumData; 0088 0089 if (album) 0090 { 0091 enabled = true; 0092 albumData = QVariant::fromValue(AlbumPointer<>(album)); 0093 0094 if (album->type() == Album::TAG) 0095 { 0096 allString = i18nc("@action: context menu", "All Tags"); 0097 } 0098 } 0099 0100 QMenu* const selectTagsMenu = new QMenu(i18nc("@action: select tags menu", "Select")); 0101 addSubMenu(selectTagsMenu); 0102 0103 selectTagsMenu->addAction(allString, d->albumModel, SLOT(checkAllAlbums())); 0104 selectTagsMenu->addSeparator(); 0105 QAction* const selectChildrenAction = selectTagsMenu->addAction(i18nc("@action: context menu", "Children"), this, SLOT(slotSelectChildren())); 0106 QAction* const selectParentsAction = selectTagsMenu->addAction(i18nc("@action: context menu", "Parents"), this, SLOT(slotSelectParents())); 0107 selectChildrenAction->setData(albumData); 0108 selectParentsAction->setData(albumData); 0109 0110 QMenu* const deselectTagsMenu = new QMenu(i18nc("@action: deselect tags menu", "Deselect")); 0111 addSubMenu(deselectTagsMenu); 0112 0113 deselectTagsMenu->addAction(allString, d->albumModel, SLOT(resetAllCheckedAlbums())); 0114 deselectTagsMenu->addSeparator(); 0115 QAction* const deselectChildrenAction = deselectTagsMenu->addAction(i18nc("@action: context menu", "Children"), this, SLOT(slotDeselectChildren())); 0116 QAction* const deselectParentsAction = deselectTagsMenu->addAction(i18nc("@action: context menu", "Parents"), this, SLOT(slotDeselectParents())); 0117 deselectChildrenAction->setData(albumData); 0118 deselectParentsAction->setData(albumData); 0119 0120 d->parent->addAction(i18nc("@action: context menu", "Invert Selection"), d->albumModel, SLOT(invertCheckedAlbums())); 0121 0122 selectChildrenAction->setEnabled(enabled); 0123 selectParentsAction->setEnabled(enabled); 0124 deselectChildrenAction->setEnabled(enabled); 0125 deselectParentsAction->setEnabled(enabled); 0126 } 0127 0128 void ContextMenuHelper::slotSelectChildren() 0129 { 0130 if (!d->albumModel) 0131 { 0132 return; 0133 } 0134 0135 d->albumModel->checkAllAlbums(d->indexForAlbumFromAction(sender())); 0136 } 0137 0138 void ContextMenuHelper::slotDeselectChildren() 0139 { 0140 if (!d->albumModel) 0141 { 0142 return; 0143 } 0144 0145 d->albumModel->resetCheckedAlbums(d->indexForAlbumFromAction(sender())); 0146 } 0147 0148 void ContextMenuHelper::slotSelectParents() 0149 { 0150 if (!d->albumModel) 0151 { 0152 return; 0153 } 0154 0155 d->albumModel->checkAllParentAlbums(d->indexForAlbumFromAction(sender())); 0156 } 0157 0158 void ContextMenuHelper::slotDeselectParents() 0159 { 0160 if (!d->albumModel) 0161 { 0162 return; 0163 } 0164 0165 d->albumModel->resetCheckedParentAlbums(d->indexForAlbumFromAction(sender())); 0166 } 0167 0168 } // namespace Digikam