1 /**
2  * \file timeeventeditor.h
3  * Editor for time events (synchronized lyrics and event timing codes).
4  *
5  * \b Project: Kid3
6  * \author Urs Fleisch
7  * \date 15 Mar 2014
8  *
9  * Copyright (C) 2014-2018  Urs Fleisch
10  *
11  * This file is part of Kid3.
12  *
13  * Kid3 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * Kid3 is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25  */
26 
27 #pragma once
28 
29 #include <QWidget>
30 #include "frame.h"
31 
32 class QLabel;
33 class QModelIndex;
34 class IPlatformTools;
35 class Kid3Application;
36 class TimeEventModel;
37 class EventCodeDelegate;
38 class TaggedFile;
39 class TimeEventTableView;
40 
41 /**
42  * Editor for time events (synchronized lyrics and event timing codes).
43  */
44 class TimeEventEditor : public QWidget {
45   Q_OBJECT
46 public:
47   /**
48    * Constructor.
49    *
50    * @param platformTools platform tools
51    * @param app application context
52    * @param parent parent widget
53    * @param field  field containing binary data
54    * @param taggedFile tagged file
55    * @param tagNr tag number
56    */
57   TimeEventEditor(IPlatformTools* platformTools, Kid3Application* app,
58                   QWidget* parent, const Frame::Field& field,
59                   const TaggedFile* taggedFile, Frame::TagNumber tagNr);
60 
61   /**
62    * Destructor.
63    */
64   virtual ~TimeEventEditor() override = default;
65 
66   /**
67    * Set time event model.
68    * @param model time event model
69    */
70   void setModel(TimeEventModel* model);
71 
72 protected:
73   /**
74    * Connect to player when editor is shown.
75    * @param event event
76    */
77   virtual void showEvent(QShowEvent* event) override;
78 
79   /**
80    * Disconnect from player when editor is hidden.
81    * @param event event
82    */
83   virtual void hideEvent(QHideEvent* event) override;
84 
85 private slots:
86   /**
87    * Make sure that player is visible and in the edited file.
88    */
89   void preparePlayer();
90 
91   /**
92    * Add a time event at the current player position.
93    */
94   void addItem();
95 
96   /**
97    * Load LRC data from clipboard.
98    */
99   void clipData();
100 
101   /**
102    * Import data in LRC format.
103    */
104   void importData();
105 
106   /**
107    * Export data in LRC format.
108    */
109   void exportData();
110 
111   /**
112    * Insert a new row after the current row.
113    */
114   void insertRow();
115 
116   /**
117    * Delete the selected rows.
118    */
119   void deleteRows();
120 
121   /**
122    * Clear the selected cells.
123    */
124   void clearCells();
125 
126   /**
127    * Add offset to time stamps.
128    */
129   void addOffset();
130 
131   /**
132    * Seek to position of current time stamp.
133    */
134   void seekPosition();
135 
136   /**
137    * Display custom context menu.
138    *
139    * @param pos position where context menu is drawn on screen
140    */
141   void customContextMenu(const QPoint& pos);
142 
143   /**
144    * Called when the played track changed.
145    * @param filePath path to file being played
146    */
147   void onTrackChanged(const QString& filePath);
148 
149   /**
150    * Called when the player position changed.
151    * @param position time in ms
152    */
153   void onPositionChanged(qint64 position);
154 
155   /**
156    * Show help.
157    */
158   void showHelp();
159 
160 private:
161   QString getLrcNameFilter() const;
162 
163   IPlatformTools* m_platformTools;
164   Kid3Application* m_app;
165   QLabel* m_label;
166   TimeEventTableView* m_tableView;
167   EventCodeDelegate* m_eventCodeDelegate;
168   TimeEventModel* m_model;
169   const TaggedFile* m_taggedFile;
170   Frame::TagNumber m_tagNr;
171   QByteArray m_byteArray;
172   bool m_fileIsPlayed;
173 };
174