Vagyojaka 5.5.7
Loading...
Searching...
No Matches
editor.h
Go to the documentation of this file.
1#pragma once
2
3#include "blockandword.h"
4#include "texteditor.h"
5#include "wordeditor.h"
9
10#include <QXmlStreamReader>
11#include <QRegularExpression>
12#include <QSyntaxHighlighter>
13#include <QTextDocument>
14#include <QCompleter>
15#include <QAbstractItemModel>
16#include <qcompleter.h>
17#include <set>
18#include <QNetworkAccessManager>
19#include <QNetworkRequest>
20#include <QNetworkReply>
21#include <QTimer>
22#include <QUndoCommand>
23#include <QSettings>
24class Highlighter;
25
31class Editor : public TextEditor
32{
33 Q_OBJECT
34
35public:
36
42 explicit Editor(QWidget *parent = nullptr);
43
52 void setWordEditor(WordEditor* wordEditor)
53 {
54 m_wordEditor = wordEditor;
55 connect(m_wordEditor, &QTableWidget::itemChanged, this, &Editor::wordEditorChanged);
56 }
57
63 void setEditorFont(const QFont& font);
64
65 QRegularExpression timeStampExp;
66 QRegularExpression speakerExp;
67
68
73
77 void setShowTimeStamp();
78
79 QVector<block> m_blocks;
81 bool showTimeStamp=false;
82
88 void loadTranscriptData(QFile& file);
89
93 void setContent();
94
100 bool timestampVisibility();
101
110 QList<QTime> getTimeStamps();
111
112 friend class Highlighter;
113
119 void loadTranscriptFromUrl(QUrl* fileUrl);
120
127 void showWaveform();
128
129 // QUndoStack *undoStack=nullptr;
130protected:
131
141 void mousePressEvent(QMouseEvent *e) override;
142
158 void keyPressEvent(QKeyEvent *event) override;
159
171 void contextMenuEvent(QContextMenuEvent *event) override;
172
173signals:
174
180 void jumpToPlayer(const QTime& time);
181
187 void refreshTagList(const QStringList& tagList);
188
192 void replyCame();
193
199 void openMessage(const QString& text);
200
206 void sendBlockTime(QVector<QTime> timeArray);
207
213 void sendBlockText(QString blockText);
214
215public slots:
216
223 void transcriptOpen();
224
225
233 void transcriptSave();
234
241 void transcriptSaveAs();
242
249 void transcriptClose();
250
260 void highlightTranscript(const QTime& elapsedTime);
261
268 void addCustomDictonary();
269
275 void showBlocksFromData();
276
282
289 void splitLine(const QTime& elapsedTime);
290
295 void mergeUp();
296
301 void mergeDown();
302
309
316
322
328 void insertTimeStamp(const QTime& elapsedTime);
329
335
342 void speakerWiseJump(const QString& jumpDirection);
343
349 void wordWiseJump(const QString& jumpDirection);
350
356 void blockWiseJump(const QString& jumpDirection);
357
364 void useTransliteration(bool value, const QString& langCode = "en");
365
374 void useAutoSave(bool value) {m_autoSave = value;}
375
381 void suggest(QString suggest);
382
388
396 void saveAsPDF();
397
404 void saveAsTXT();
405
415 void updateTimeStamp(int block_num, QTime endTime);
416
427 void updateTimeStampsBlock(QVector<int> blks);
428
429private slots:
430 void contentChanged(int position, int charsRemoved, int charsAdded);
431 void wordEditorChanged();
432
439 void updateWordEditor();
440
452 void changeSpeaker(const QString& newSpeaker, bool replaceAllOccurrences);
453
465 void propagateTime(const QTime& time, int start, int end, bool negateTime);
466
475 void selectTags(const QStringList& newTagList);
476
487 void markWordAsCorrect(int blockNumber, int wordNumber);
488
497 void insertSpeakerCompletion(const QString& completion);
498
507 void insertTextCompletion(const QString& completion);
508
517 void insertTransliterationCompletion(const QString &completion);
518
530 void handleReply();
531
541 void sendRequest(const QString& input, const QString& langCode);
542
543private:
544
555 static QTime getTime(const QString& text);
556
569 static word makeWord(const QTime& t, const QString& s, const QStringList& tagList, const QString& isEdited);
570
579 QCompleter* makeCompleter();
580
591 void saveXml(QFile* file);
592
601 void helpJumpToPlayer();
602
610 void loadDictionary();
611
624 block fromEditor(qint64 blockNumber) const;
625
638 static QStringList listFromFile(const QString& fileName) ;
639
640 // State flags
641 bool settingContent{false};
642 bool updatingWordEditor{false};
644
645 // Configuration options
646 bool m_transliterate{false};
647 bool m_autoSave{false};
648
649 // Transcript language and punctuation settings
651 QString m_punctuation{",.!;:?"};
652
653 // UI and settings components
654 QSettings* settings;
656
657 // Highlighting information
658 qint64 highlightedBlock = -1;
659 qint64 highlightedWord = -1;
660
661 // UI components for editing
666
667 // Auto-completion features
668 QCompleter *m_speakerCompleter = nullptr;
669 QCompleter *m_textCompleter = nullptr;
670 QCompleter *m_transliterationCompleter = nullptr;
671
672 // Dictionaries
673 QStringList m_dictionary;
675 QString m_customDictonaryPath = nullptr;
676 std::set<QString> m_correctedWords;
678
679 // Network management
680 QStringList m_lastReplyList;
681 QNetworkAccessManager m_manager;
682 QNetworkReply* m_reply = nullptr;
683
684 // Auto-saving configuration
685 QTimer* m_saveTimer = nullptr;
687
688 // Clipboard management
689 QStringList clipboardTexts;
690 QString fileBeforeSave = "initial.txt";
691 QString fileAfterSave = "final.txt";
692 QString ComparedOutputFile = "ComparedDictonary.json";
693
694 // Real-time data settings
695 bool realTimeDataSaver = false;
696 QStringList allClips;
697
698 // Highlighting state
701 QStringList supportedFormats;
702
703public:
704
705};
706
707
708
709
710class Highlighter : public QSyntaxHighlighter
711{
712 Q_OBJECT
713public:
714 explicit Highlighter(QTextDocument *parent = nullptr) : QSyntaxHighlighter(parent) {};
715
717 {
718 blockToHighlight = -1;
719 wordToHighlight = -1;
720 }
721 void setBlockToHighlight(qint64 blockNumber)
722 {
723 blockToHighlight = blockNumber;
724 rehighlight();
725 }
726 void setWordToHighlight(int wordNumber)
727 {
728 wordToHighlight = wordNumber;
729 rehighlight();
730 }
731 void setInvalidBlocks(const QList<int>& invalidBlocks)
732 {
733 invalidBlockNumbers = invalidBlocks;
734 rehighlight();
735 }
736 void setTaggedBlocks(const QList<int>& taggedBlock)
737 {
738 taggedBlockNumbers = taggedBlock;
739 rehighlight();
740 }
742 {
743 taggedBlockNumbers.clear();
744 }
745 void setInvalidWords(const QMultiMap<int, int>& invalidWordsMap)
746 {
747 invalidWords = invalidWordsMap;
748 rehighlight();
749 }
750 void setTaggedWords(const QMultiMap<int, int>& taggedWordsMap)
751 {
752 taggedWords = taggedWordsMap;
753 rehighlight();
754 }
755 void setEditedWords(const QMultiMap<int, int>& editedWordsMap) {
756 editedWords = editedWordsMap;
757 rehighlight();
758 }
760 {
761 invalidBlockNumbers.clear();
762 }
763
764 void highlightBlock(const QString&) override;
765
766
767private:
772
773 QMultiMap<int, int> invalidWords;
774 QMultiMap<int, int> taggedWords;
775 QMultiMap<int, int> editedWords;
776};
Definition changespeakerdialog.h:11
Manages the editing functionalities of transcripts, including time stamps, speaker changes,...
Definition editor.h:32
void loadDictionary()
Loads a dictionary for the editor to use for word suggestions and spell-checking.
Definition editor.cpp:1308
void mergeDown()
Merges the current block with the next block, transferring word list and text. Only merges if the spe...
Definition editor.cpp:2099
std::set< QString > m_correctedWords
Set of words that have been corrected.
Definition editor.h:676
ChangeSpeakerDialog * m_changeSpeaker
Dialog for changing speakers.
Definition editor.h:663
QCompleter * makeCompleter()
Creates and configures a QCompleter for use in the editor.
Definition editor.cpp:1021
qint64 highlightedWord
Index of the currently highlighted word in the editor.
Definition editor.h:659
Highlighter * m_highlighter
Pointer to the syntax highlighter.
Definition editor.h:655
QString fileBeforeSave
File path for the initial state before saving.
Definition editor.h:690
void jumpToHighlightedLine()
Moves the cursor to the highlighted line in the editor. If no block is highlighted,...
Definition editor.cpp:1932
bool realTimeDataSaver
Flag to indicate if real-time data saving is enabled.
Definition editor.h:695
void setShowTimeStamp()
Toggles the visibility of timestamps in the editor.
Definition editor.cpp:1427
void transcriptOpen()
Opens a transcript file, allowing the user to select a file from the file dialog.
Definition editor.cpp:760
void saveXml(QFile *file)
Saves the current transcript data to an XML file.
Definition editor.cpp:1218
void createChangeSpeakerDialog()
Opens a dialog to select a new speaker for the highlighted block. Displays a modal dialog with a list...
Definition editor.cpp:2130
void insertTimeStamp(const QTime &elapsedTime)
Inserts a timestamp at the current cursor position within a block. Updates the timestamp associated w...
Definition editor.cpp:2201
bool updatingWordEditor
Indicates if the word editor is being updated.
Definition editor.h:642
void propagateTime(const QTime &time, int start, int end, bool negateTime)
Propagates a specified time adjustment to a range of blocks.
Definition editor.cpp:2552
void saveAsPDF()
Exports the transcript as a PDF file.
Definition editor.cpp:2394
void useAutoSave(bool value)
Enables or disables the auto-save feature for the editor.
Definition editor.h:374
QStringList clipboardTexts
List of text items in the clipboard.
Definition editor.h:689
void setContent()
Sets the content of the editor.
Definition editor.cpp:1444
void selectTags(const QStringList &newTagList)
Selects tags for the current block.
Definition editor.cpp:2596
void jumpToPlayer(const QTime &time)
Signal emitted to jump to a specific time in the MediaPlayer.
qint64 highlightedBlock
Index of the currently highlighted block in the editor.
Definition editor.h:658
TagSelectionDialog * m_selectTag
Dialog for selecting tags.
Definition editor.h:665
void saveAsTXT()
Exports the transcript as a text file.
Definition editor.cpp:2447
void addCustomDictonary()
Opens a file dialog to add a custom dictionary.
Definition editor.cpp:988
QSettings * settings
Pointer to application settings.
Definition editor.h:654
bool settingContent
Indicates if the editor is currently in a setting content mode.
Definition editor.h:641
int lastHighlightedBlock
Index of the last highlighted block.
Definition editor.h:699
QStringList allClips
List of all clipboard contents.
Definition editor.h:696
void transcriptSave()
Saves the current transcript.
Definition editor.cpp:775
QString m_transcriptLang
Language of the transcript.
Definition editor.h:650
void loadTranscriptFromUrl(QUrl *fileUrl)
Loads transcript data from a given URL.
Definition editor.cpp:1032
void setWordEditor(WordEditor *wordEditor)
Sets the word editor for the current Editor instance.
Definition editor.h:52
void wordEditorChanged()
Definition editor.cpp:2492
void insertSpeakerCompletion(const QString &completion)
Inserts speaker name completion into the editor.
Definition editor.cpp:2674
void highlightTranscript(const QTime &elapsedTime)
Highlights a transcript block and word based on the provided elapsed time.
Definition editor.cpp:931
void mergeUp()
Merges the current block with the previous one, combining text and word lists. Only merges if the spe...
Definition editor.cpp:2069
bool dontUpdateWordEditor
Flag to prevent updates to the word editor.
Definition editor.h:643
QStringList m_lastReplyList
List of the last replies from network requests.
Definition editor.h:680
QCompleter * m_textCompleter
Completer for text suggestions.
Definition editor.h:669
bool timestampVisibility()
Checks the visibility status of timestamps.
Definition editor.cpp:1616
void helpJumpToPlayer()
Sends the current text block to the MediaPlayer, allowing a jump to the relevant timestamp with Media...
Definition editor.cpp:1267
void useTransliteration(bool value, const QString &langCode="en")
Enables or disables transliteration for the editor. Sets the transliteration state and language code.
Definition editor.cpp:2362
void handleReply()
Processes the response received from a network reply and extracts tokens.
Definition editor.cpp:2716
QString m_punctuation
Default punctuation characters used in the editor.
Definition editor.h:651
QRegularExpression timeStampExp
Regular expression for timestamps.
Definition editor.h:65
QCompleter * m_speakerCompleter
Completer for speaker names.
Definition editor.h:668
void createTagSelectionDialog()
Opens a dialog for selecting and marking tags in the current block. Allows users to add tags to a blo...
Definition editor.cpp:2180
void openMessage(const QString &text)
Signal emitted to open a message box or display a message in the UI.
void insertTextCompletion(const QString &completion)
Inserts text completion into the editor.
Definition editor.cpp:2690
void refreshTagList(const QStringList &tagList)
Signal emitted to refresh the tag list display in the UI.
QStringList m_english_dictionary
List of English dictionary entries.
Definition editor.h:674
void splitLine(const QTime &elapsedTime)
Splits the current text line at the cursor's position. Divides the block into two based on cursor pos...
Definition editor.cpp:1940
void setEditorFont(const QFont &font)
Sets the font for the editor.
Definition editor.cpp:87
QStringList m_dictionary
List of user-defined dictionary entries.
Definition editor.h:673
void showWaveform()
Shows the waveform based on the current blocks.
Definition editor.cpp:2823
void realTimeDataSavingToggle()
Toggles real-time data saving on or off. Enables or disables the data-saving feature in real-time.
Definition editor.cpp:2384
void updateTimeStampsBlock(QVector< int > blks)
Updates timestamps for a range of blocks based on a provided vector of seconds.
Definition editor.cpp:2793
QString m_transliterateLangCode
Language code for transliteration.
Definition editor.h:677
void insertTransliterationCompletion(const QString &completion)
Inserts transliteration completion into the editor.
Definition editor.cpp:2704
QStringList supportedFormats
List of supported file formats.
Definition editor.h:701
QString m_customDictonaryPath
Path to the custom dictionary file.
Definition editor.h:675
QNetworkAccessManager m_manager
Network manager for handling requests.
Definition editor.h:681
void markWordAsCorrect(int blockNumber, int wordNumber)
Marks a word as correct and updates the dictionary.
Definition editor.cpp:2608
void loadTranscriptData(QFile &file)
Loads transcript data from a given file.
Definition editor.cpp:1125
bool m_transliterate
Indicates if transliteration is enabled.
Definition editor.h:646
WordEditor * m_wordEditor
Pointer to the word editor instance.
Definition editor.h:662
QVector< block > m_blocks
Stores the blocks of text and their associated data.
Definition editor.h:79
void setMoveAlongTimeStamps()
Configures the editor to move along timestamps.
Definition editor.cpp:96
QNetworkReply * m_reply
Pointer to the current network reply.
Definition editor.h:682
bool moveAlongTimeStamps
Flag to determine if the editor should move along timestamps.
Definition editor.h:700
void transcriptClose()
Closes the current transcript file.
Definition editor.cpp:904
Editor(QWidget *parent=nullptr)
Constructs an Editor instance.
Definition editor.cpp:24
void sendRequest(const QString &input, const QString &langCode)
Sends a request to an external service for text completion.
Definition editor.cpp:2733
int m_saveInterval
Interval in seconds for auto-saving documents.
Definition editor.h:686
static word makeWord(const QTime &t, const QString &s, const QStringList &tagList, const QString &isEdited)
Creates a word object with the given attributes.
Definition editor.cpp:1015
QString fileAfterSave
File path for the final state after saving.
Definition editor.h:691
void createTimePropagationDialog()
Opens a dialog for propagating time across a range of blocks. Sets up a dialog allowing users to sele...
Definition editor.cpp:2156
void blockWiseJump(const QString &jumpDirection)
Jumps to the next or previous block. Moves the cursor up or down to adjacent blocks and jumps to the ...
Definition editor.cpp:2329
QTimer * m_saveTimer
Timer for managing save intervals.
Definition editor.h:685
void sendBlockText(QString blockText)
Signal emitted to send the text content of a specific block.
bool showTimeStamp
Flag indicating whether to show timestamps.
Definition editor.h:81
void contextMenuEvent(QContextMenuEvent *event) override
Creates and displays a customized context menu with additional options.
Definition editor.cpp:649
static QStringList listFromFile(const QString &fileName)
Loads transcript data from an XML file into the editor.
Definition editor.cpp:1408
void updateWordEditor()
Updates the word editor with the current block's words.
Definition editor.cpp:2475
void mousePressEvent(QMouseEvent *e) override
Handles mouse press events, enabling specific behavior with Ctrl key.
Definition editor.cpp:393
void suggest(QString suggest)
Provides word suggestions and replaces the selected word. Highlights the current word under the curso...
Definition editor.cpp:2368
void changeTranscriptLang()
Changes the language of the transcript. Prompts the user to enter a new language, then loads the rele...
Definition editor.cpp:2223
void showBlocksFromData()
Displays all blocks and their content in the QDebug (Saved in Logfile). Iterates through each block a...
Definition editor.cpp:921
void changeSpeaker(const QString &newSpeaker, bool replaceAllOccurrences)
Changes the speaker's name in the transcript.
Definition editor.cpp:2525
void speakerWiseJump(const QString &jumpDirection)
Navigates to the next or previous block by the same speaker. Searches for the closest block in the sp...
Definition editor.cpp:2231
block fromEditor(qint64 blockNumber) const
Converts a block number into a block structure containing the timestamp, text, speaker,...
Definition editor.cpp:1083
void transcriptSaveAs()
Saves the current transcript with a new file name.
Definition editor.cpp:869
QString ComparedOutputFile
File path for compared dictionary output.
Definition editor.h:692
QUrl m_transcriptUrl
URL of the loaded transcript.
Definition editor.h:80
void updateTimeStamp(int block_num, QTime endTime)
Updates the current block's timestamp with a new value.
Definition editor.cpp:2774
void replyCame()
Signal emitted when a reply is received from an external source.
QRegularExpression speakerExp
Regular expression for speaker identification.
Definition editor.h:66
void sendBlockTime(QVector< QTime > timeArray)
Signal emitted to send a vector of block timestamps for display in the AudioWaveForm.
QCompleter * m_transliterationCompleter
Completer for transliteration suggestions.
Definition editor.h:670
QList< QTime > getTimeStamps()
Retrieves timestamps from the blocks.
Definition editor.cpp:2755
static QTime getTime(const QString &text)
Parses a time string and converts it into a QTime object.
Definition editor.cpp:1003
void contentChanged(int position, int charsRemoved, int charsAdded)
Definition editor.cpp:1621
TimePropagationDialog * m_propagateTime
Dialog for propagating time changes.
Definition editor.h:664
bool m_autoSave
Indicates if auto-save functionality is enabled.
Definition editor.h:647
void keyPressEvent(QKeyEvent *event) override
Handles key press events and provides custom shortcuts and suggestions.
Definition editor.cpp:400
void wordWiseJump(const QString &jumpDirection)
Jumps to the next or previous word in the highlighted block. Adjusts position based on direction and ...
Definition editor.cpp:2275
Definition editor.h:711
Highlighter(QTextDocument *parent=nullptr)
Definition editor.h:714
QList< int > taggedBlockNumbers
Definition editor.h:771
void setInvalidBlocks(const QList< int > &invalidBlocks)
Definition editor.h:731
QMultiMap< int, int > invalidWords
Definition editor.h:773
QList< int > invalidBlockNumbers
Definition editor.h:770
void setInvalidWords(const QMultiMap< int, int > &invalidWordsMap)
Definition editor.h:745
int blockToHighlight
Definition editor.h:768
void setWordToHighlight(int wordNumber)
Definition editor.h:726
void clearTaggedBlocks()
Definition editor.h:741
void setTaggedBlocks(const QList< int > &taggedBlock)
Definition editor.h:736
void setEditedWords(const QMultiMap< int, int > &editedWordsMap)
Definition editor.h:755
int wordToHighlight
Definition editor.h:769
void setBlockToHighlight(qint64 blockNumber)
Definition editor.h:721
void highlightBlock(const QString &) override
Definition editor.cpp:107
void clearInvalidBlocks()
Definition editor.h:759
void setTaggedWords(const QMultiMap< int, int > &taggedWordsMap)
Definition editor.h:750
QMultiMap< int, int > taggedWords
Definition editor.h:774
QMultiMap< int, int > editedWords
Definition editor.h:775
void clearHighlight()
Definition editor.h:716
Definition tagselectiondialog.h:10
Definition texteditor.h:10
Definition timepropagationdialog.h:12
Definition wordeditor.h:7
Definition blockandword.h:27
Definition blockandword.h:7