texteditfindbarbase.h 2.91 KB
Newer Older
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
   Copyright (C) 2013-2020 Laurent Montel <montel@kde.org>
Laurent Montel's avatar
Laurent Montel committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
18 19 20 21 22 23 24 25
*/

#ifndef TEXTEDITFINDBARBASE_H
#define TEXTEDITFINDBARBASE_H

#include "kpimtextedit_export.h"
#include <QWidget>
#include <QTextDocument>
26
#include <QRegularExpression>
Laurent Montel's avatar
Laurent Montel committed
27
namespace KPIMTextEdit {
28 29
class TextFindWidget;
class TextReplaceWidget;
30 31
/**
 * @brief The TextEditFindBarBase class
Laurent Montel's avatar
Laurent Montel committed
32
 * @author Laurent Montel <montel@kde.org>
33
 */
34 35 36 37 38
class KPIMTEXTEDIT_EXPORT TextEditFindBarBase : public QWidget
{
    Q_OBJECT

public:
Laurent Montel's avatar
Laurent Montel committed
39
    explicit TextEditFindBarBase(QWidget *parent = nullptr);
Laurent Montel's avatar
Laurent Montel committed
40
    ~TextEditFindBarBase() override;
41

Laurent Montel's avatar
Laurent Montel committed
42
    Q_REQUIRED_RESULT QString text() const;
43 44 45 46 47 48 49 50 51 52 53 54 55
    void setText(const QString &text);

    void focusAndSetCursor();

    void showReplace();
    void showFind();
    void setHideWhenClose(bool hide);

Q_SIGNALS:
    void displayMessageIndicator(const QString &message);
    void hideFindBar();

protected:
Laurent Montel's avatar
Laurent Montel committed
56 57 58 59
    virtual Q_REQUIRED_RESULT bool viewIsReadOnly() const = 0;
    virtual Q_REQUIRED_RESULT bool documentIsEmpty() const = 0;
    virtual Q_REQUIRED_RESULT bool searchInDocument(const QString &text, QTextDocument::FindFlags searchOptions) = 0;
    virtual Q_REQUIRED_RESULT bool searchInDocument(const QRegularExpression &regExp, QTextDocument::FindFlags searchOptions) = 0;
60 61
    virtual void autoSearchMoveCursor() = 0;

62
    bool event(QEvent *e) override;
63 64
    void clearSelections();
    void updateHighLight(bool);
Laurent Montel's avatar
Laurent Montel committed
65
    bool searchText(bool backward, bool isAutoSearch);
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    void updateSensitivity(bool);

    void setFoundMatch(bool match);
    void messageInfo(bool backward, bool isAutoSearch, bool found);

public Q_SLOTS:
    void findNext();
    void findPrev();
    void autoSearch(const QString &str);
    virtual void slotSearchText(bool backward = false, bool isAutoSearch = true) = 0;
    void closeBar();

private Q_SLOTS:
    void slotClearSearch();
    void slotUpdateSearchOptions();
    virtual void slotReplaceText() = 0;
    virtual void slotReplaceAllText() = 0;

protected:
    QString mLastSearchStr;
86
    QRegularExpression mLastSearchRegExp;
Laurent Montel's avatar
Laurent Montel committed
87 88 89
    TextFindWidget *mFindWidget = nullptr;
    TextReplaceWidget *mReplaceWidget = nullptr;
    bool mHideWhenClose = true;
90 91 92 93
};
}

#endif // TEXTEDITFINDBARBASE_H