File indexing completed on 2024-05-19 04:56:04
0001 /** 0002 * \file frameeditorobject.h 0003 * IFrameEditor interface to QObject bridge. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 20 Sep 2014 0008 * 0009 * Copyright (C) 2014-2024 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 <QObject> 0030 #include <QMap> 0031 #include "iframeeditor.h" 0032 #include "frame.h" 0033 0034 class FrameObjectModel; 0035 0036 /** 0037 * IFrameEditor interface to QObject bridge. 0038 * 0039 * A FrameEditorObject can be used to use a QObject (e.g. a QML component) as a 0040 * frame editor. An instance is registered with FrameList::setFrameEditor() and 0041 * will communicate with the editor component using its 0042 * frameSelectionRequested() and frameEditRequested() signals and 0043 * onFrameSelectionFinished() and onFrameEditFinished() slots. 0044 */ 0045 class KID3_CORE_EXPORT FrameEditorObject : public QObject, public IFrameEditor { 0046 Q_OBJECT 0047 public: 0048 /** 0049 * Constructor. 0050 * @param parent parent object 0051 */ 0052 explicit FrameEditorObject(QObject* parent = nullptr); 0053 0054 /** 0055 * Destructor. 0056 */ 0057 ~FrameEditorObject() override = default; 0058 0059 // IFrameEditor implementation 0060 0061 /** 0062 * Let user edit a frame and then update the fields 0063 * when the edits are accepted. 0064 * frameEdited() is emitted when the edit dialog is closed with the edited 0065 * frame as a parameter if it was accepted. 0066 * 0067 * @param frame frame to edit 0068 * @param taggedFile tagged file where frame has to be set 0069 */ 0070 void editFrameOfTaggedFile(const Frame* frame, 0071 TaggedFile* taggedFile) override; 0072 0073 /** 0074 * Let user select a frame type. 0075 * frameSelected() is emitted when the edit dialog is closed with the selected 0076 * frame as a parameter if a frame is selected. 0077 * 0078 * @param frame is filled with the selected frame 0079 * @param taggedFile tagged file for which frame has to be selected 0080 */ 0081 void selectFrame(Frame* frame, const TaggedFile* taggedFile) override; 0082 0083 /** 0084 * Return object which emits frameSelected(), frameEdited() signals. 0085 * 0086 * @return object which emits signals. 0087 */ 0088 QObject* qobject() override; 0089 0090 /** 0091 * Get the tag number of the edited frame. 0092 * @return tag number, default is Frame::Tag_2. 0093 */ 0094 Frame::TagNumber tagNumber() const override { return m_tagNr; } 0095 0096 /** 0097 * Set the tag number of the edited frame. 0098 * @param tagNr tag number 0099 */ 0100 void setTagNumber(Frame::TagNumber tagNr) override { m_tagNr = tagNr; } 0101 0102 // End of IFrameEditor implementation 0103 0104 public slots: 0105 /** 0106 * Called when the frame selection dialog is closed. 0107 * 0108 * @param displayName name of selected frame, empty if canceled 0109 * 0110 * @see frameSelectionRequested() 0111 */ 0112 void onFrameSelectionFinished(const QString& displayName); 0113 0114 /** 0115 * Called when the frame edit dialog is closed. 0116 * 0117 * @param frame frame object model, null if canceled 0118 * 0119 * @see frameEditRequested() 0120 */ 0121 void onFrameEditFinished(const FrameObjectModel* frame); 0122 0123 signals: 0124 // IFrameEditor implementation 0125 0126 /** 0127 * Emitted when the dialog to add and edit a frame is closed. 0128 * @param tagNr tag number 0129 * @param frame edited frame if dialog was accepted, else 0 0130 */ 0131 void frameEdited(Frame::TagNumber tagNr, const Frame* frame); 0132 0133 /** 0134 * Emitted when the dialog to select a frame is closed. 0135 * @param tagNr tag number 0136 * @param frame selected frame if dialog was accepted, else 0 0137 */ 0138 void frameSelected(Frame::TagNumber tagNr, const Frame* frame); 0139 0140 // End of IFrameEditor implementation 0141 0142 /** 0143 * Emitted to request a frame selection from the frame editor. 0144 * When the frame selection is accepted or canceled, 0145 * onFrameSelectionFinished() shall be called. 0146 * 0147 * @param frameNames list of possible frame names 0148 */ 0149 void frameSelectionRequested(const QStringList& frameNames); 0150 0151 /** 0152 * Emitted to request a frame edit from the frame editor. 0153 * When the frame editing is finished, onFrameEditFinished() shall be called. 0154 * 0155 * @param frame frame object model 0156 */ 0157 void frameEditRequested(FrameObjectModel* frame); 0158 0159 private: 0160 Frame* m_selectFrame; 0161 TaggedFile* m_editFrameTaggedFile; 0162 FrameObjectModel* m_frameObjectModel; 0163 Frame m_editFrame; 0164 QMap<QString, QString> m_displayNameMap; 0165 Frame::TagNumber m_tagNr; 0166 };