File indexing completed on 2024-04-28 11:21:00

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2012 Martin Kuettler <martin.kuettler@gmail.com>
0004 */
0005 
0006 #ifndef SEARCHBAR_H
0007 #define SEARCHBAR_H
0008 
0009 #include <QWidget>
0010 #include <QTextDocument>
0011 
0012 #include "ui_standardsearchbar.h"
0013 #include "ui_extendedsearchbar.h"
0014 
0015 #include "worksheetcursor.h"
0016 
0017 class Worksheet;
0018 class WorksheetEntry;
0019 class WorksheetTextItem;
0020 
0021 class QMenu;
0022 
0023 class SearchBar : public QWidget
0024 {
0025   Q_OBJECT
0026   public:
0027     SearchBar(QWidget*, Worksheet*);
0028     ~SearchBar() override;
0029 
0030     void showStandard();
0031     void showExtended();
0032 
0033     void next();
0034     void prev();
0035 
0036     void searchForward(bool skipFirstChar = false);
0037     void searchBackward(bool skipFirstChar = false);
0038 
0039   public Q_SLOTS:
0040     void on_close_clicked();
0041     void on_openExtended_clicked();
0042     void on_openStandard_clicked();
0043     void on_next_clicked();
0044     void on_previous_clicked();
0045     void on_replace_clicked();
0046     void on_replaceAll_clicked();
0047     void on_pattern_textChanged(const QString&);
0048     void on_replacement_textChanged(const QString&);
0049     void on_addFlag_clicked();
0050     void on_removeFlag_clicked();
0051     void on_matchCase_toggled(bool b);
0052 
0053     void invalidateStartCursor();
0054     void invalidateCurrentCursor();
0055 
0056   protected Q_SLOTS:
0057     void toggleFlag();
0058 
0059   private:
0060 
0061     void updateSearchLocations();
0062     void fillLocationsMenu(QMenu*, int flags);
0063 
0064     void setupStdUi();
0065     void setupExtUi();
0066 
0067     void setStatus(QString);
0068     void clearStatus();
0069 
0070     void setStartCursor(WorksheetCursor);
0071     void setCurrentCursor(WorksheetCursor);
0072 
0073     Worksheet* worksheet();
0074 
0075     QPushButton* nextButton();
0076     QPushButton* previousButton();
0077 
0078   private:
0079     Ui::StandardSearchBar* m_stdUi;
0080     Ui::ExtendedSearchBar* m_extUi{nullptr};
0081 
0082     WorksheetCursor m_startCursor;
0083     WorksheetCursor m_currentCursor;
0084 
0085     Worksheet* m_worksheet;
0086     QString m_pattern;
0087     QString m_replacement;
0088     QTextDocument::FindFlags m_qtFlags;
0089     unsigned int m_searchFlags;
0090 
0091     bool m_atBeginning{false};
0092     bool m_atEnd{false};
0093     bool m_notFound{false};
0094 };
0095 
0096 #endif // SEARCHBAR_H
0097