File indexing completed on 2024-12-22 04:40:17

0001 /*
0002     SPDX-FileCopyrightText: 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar>
0003     SPDX-FileCopyrightText: 2010-2022 Mladen Milinkovic <max@smoothware.net>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef FINDER_H
0009 #define FINDER_H
0010 
0011 #include "core/subtitle.h"
0012 #include "core/subtitleline.h"
0013 
0014 #include <QExplicitlySharedDataPointer>
0015 #include <QObject>
0016 
0017 QT_FORWARD_DECLARE_CLASS(QGroupBox)
0018 QT_FORWARD_DECLARE_CLASS(QRadioButton)
0019 class KFind;
0020 class KFindDialog;
0021 
0022 namespace SubtitleComposer {
0023 class SubtitleIterator;
0024 
0025 class Finder : public QObject
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     explicit Finder(QWidget *parent = 0);
0031     virtual ~Finder();
0032 
0033     QWidget * parentWidget();
0034 
0035 public slots:
0036     void setSubtitle(Subtitle *subtitle = 0);
0037     void setTranslationMode(bool enabled);
0038 
0039     void find(const RangeList &selectionRanges, int currentIndex, const QString &text = QString(), bool findBackwards = false);
0040     bool findNext();
0041     bool findPrevious();
0042 
0043 signals:
0044     void found(SubtitleLine *line, bool primary, int startIndex, int endIndex);
0045 
0046 private slots:
0047     void invalidate();
0048 
0049     void onLinePrimaryTextChanged();
0050     void onLineSecondaryTextChanged();
0051 
0052     void onHighlight(const QString &text, int matchingIndex, int matchedLength);
0053 
0054     void onIteratorSynchronized(int firstIndex, int lastIndex, bool inserted);
0055 
0056 private:
0057     void advance();
0058 
0059 private:
0060     QExplicitlySharedDataPointer<const Subtitle> m_subtitle;
0061     bool m_translationMode;
0062     bool m_feedingPrimary;
0063 
0064     KFind *m_find;
0065     KFindDialog *m_dialog;
0066     QGroupBox *m_targetGroupBox;
0067     QRadioButton *m_targetRadioButtons[SubtitleTargetSize];
0068     SubtitleIterator *m_iterator;
0069     SubtitleLine *m_dataLine;
0070     bool m_instancesFound;
0071     int m_allSearchedIndex;
0072 };
0073 }
0074 #endif