File indexing completed on 2025-02-23 04:34:22

0001 /**
0002  * \file sectionactions.h
0003  * Actions for section shortcuts.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 22 Mar 2020
0008  *
0009  * Copyright (C) 2020  Urs Fleisch
0010  *
0011  * This file is part of Kid3.
0012  *
0013  * Kid3 is free software; you can redistribute it and/or modify
0014  * it under the terms of the GNU General Public License as published by
0015  * the Free Software Foundation; either version 2 of the License, or
0016  * (at your option) any later version.
0017  *
0018  * Kid3 is distributed in the hope that it will be useful,
0019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0021  * GNU General Public License for more details.
0022  *
0023  * You should have received a copy of the GNU General Public License
0024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0025  */
0026 
0027 #pragma once
0028 
0029 #include <tuple>
0030 #include <QObject>
0031 #include "kid3api.h"
0032 
0033 class QWidget;
0034 class QAction;
0035 
0036 /**
0037  * Actions for section shortcuts.
0038  * Can be used to add actions to a section to navigate to other sections
0039  * and edit. The keyboard shortcuts are only active when the section has the
0040  * focus.
0041  */
0042 class KID3_GUI_EXPORT SectionActions : public QObject {
0043   Q_OBJECT
0044 public:
0045   /** Which actions to include */
0046   enum ActionGroup {
0047     Navigation  = 1 << 0, /**< previous section, next section */
0048     Transfer    = 1 << 1, /**< transfer (from other tag) */
0049     EditSection = 1 << 2, /**< copy, paste, remove */
0050     EditElement = 1 << 3  /**< edit, add, delete */
0051   };
0052   Q_DECLARE_FLAGS(ActionGroups, ActionGroup)
0053 
0054   /**
0055    * Constructor.
0056    * @param groups action groups to add
0057    * @param widget widget to which actions are added
0058    */
0059   SectionActions(ActionGroups groups, QWidget* widget);
0060 
0061   /**
0062    * Set keyboard shortcuts for section actions.
0063    * @param map map of action names to key sequences
0064    */
0065   void setShortcuts(const QMap<QString, QKeySequence>& map);
0066 
0067   /** Get action for previous section. */
0068   QAction* previousSectionAction() const {
0069     return m_previousSectionAction;
0070   }
0071 
0072   /** Get action for next section. */
0073   QAction* nextSectionAction() const {
0074     return m_nextSectionAction;
0075   }
0076 
0077   /** Get action for copy. */
0078   QAction* copyAction() const {
0079     return m_copyAction;
0080   }
0081 
0082   /** Get action for paste. */
0083   QAction* pasteAction() const {
0084     return m_pasteAction;
0085   }
0086 
0087   /** Get action for remove. */
0088   QAction* removeAction() const {
0089     return m_removeAction;
0090   }
0091 
0092   /** Get action for transfer to other tag. */
0093   QAction* transferAction() const {
0094     return m_transferAction;
0095   }
0096 
0097   /** Get action for edit. */
0098   QAction* editAction() const {
0099     return m_editAction;
0100   }
0101 
0102   /** Get action for add. */
0103   QAction* addAction() const {
0104     return m_addAction;
0105   }
0106 
0107   /** Get action for delete. */
0108   QAction* deleteAction() const {
0109     return m_deleteAction;
0110   }
0111 
0112   /**
0113    * Get section action default shortcut information.
0114    * @return list with name, display name, shortcut for all section actions.
0115    */
0116   static QList<std::tuple<QString, QString, QKeySequence>> defaultShortcuts();
0117 
0118 private:
0119   QWidget* m_widget;
0120   QAction* m_previousSectionAction;
0121   QAction* m_nextSectionAction;
0122   QAction* m_copyAction;
0123   QAction* m_pasteAction;
0124   QAction* m_removeAction;
0125   QAction* m_transferAction;
0126   QAction* m_editAction;
0127   QAction* m_addAction;
0128   QAction* m_deleteAction;
0129 };
0130 
0131 Q_DECLARE_OPERATORS_FOR_FLAGS(SectionActions::ActionGroups)