File indexing completed on 2024-04-14 03:56:07

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2001 S.R. Haque <srhaque@iee.org>.
0004     SPDX-FileCopyrightText: 2002 David Faure <david@mandrakesoft.com>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-only
0007 */
0008 
0009 #ifndef KREPLACEDIALOG_H
0010 #define KREPLACEDIALOG_H
0011 
0012 #include "ktextwidgets_export.h"
0013 
0014 #include "kfinddialog.h"
0015 
0016 class KReplaceDialogPrivate;
0017 
0018 /**
0019  * @class KReplaceDialog kreplace.h <KReplaceDialog>
0020  *
0021  * @short A generic "replace" dialog.
0022  *
0023  * @author S.R.Haque <srhaque@iee.org>
0024  *
0025  * \b Detail:
0026  *
0027  * This widget inherits from KFindDialog and implements
0028  * the following additional functionalities:  a replacement string
0029  * object and an area for a user-defined widget to extend the dialog.
0030  *
0031  * \b Example:
0032  *
0033  * To use the basic replace dialog:
0034  *
0035  * \code
0036  * \endcode
0037  *
0038  * To use your own extensions:
0039  *
0040  * \code
0041  * \endcode
0042  *
0043  * \image html kreplacedialog.png "KReplaceDialog Widget"
0044  */
0045 class KTEXTWIDGETS_EXPORT KReplaceDialog : public KFindDialog
0046 {
0047     Q_OBJECT
0048 
0049 public:
0050     /// Options.
0051 
0052     enum Options {
0053         /// Should the user be prompted before the replace operation?
0054         PromptOnReplace = 256,
0055         BackReference = 512,
0056     };
0057 
0058     /**
0059      * Construct a replace dialog.read-only or rather select-only combo box with a
0060      * parent object and a name.
0061      *
0062      * @param parent The parent object of this widget
0063      * @param options A bitfield of the Options to be enabled.
0064      * @param findStrings A QStringList to insert in the combo box of text to find
0065      * @param replaceStrings A QStringList to insert in the combo box of text to
0066      *        replace with
0067      * @param hasSelection Whether a selection exists
0068      */
0069     explicit KReplaceDialog(QWidget *parent = nullptr,
0070                             long options = 0,
0071                             const QStringList &findStrings = QStringList(),
0072                             const QStringList &replaceStrings = QStringList(),
0073                             bool hasSelection = true);
0074 
0075     /**
0076      * Destructor.
0077      */
0078     ~KReplaceDialog() override;
0079 
0080     /**
0081      * Provide the list of @p strings to be displayed as the history
0082      * of replacement strings. @p strings might get truncated if it is
0083      * too long.
0084      *
0085      * @param history The replacement history.
0086      * @see replacementHistory
0087      */
0088     void setReplacementHistory(const QStringList &history);
0089 
0090     /**
0091      * Returns the list of history items.
0092      *
0093      * @see setReplacementHistory
0094      */
0095     QStringList replacementHistory() const;
0096 
0097     /**
0098      * Set the options which are enabled.
0099      *
0100      * @param options The setting of the Options.
0101      */
0102     void setOptions(long options);
0103 
0104     /**
0105      * Returns the state of the options. Disabled options may be returned in
0106      * an indeterminate state.
0107      *
0108      * @see setOptions
0109      */
0110     long options() const;
0111 
0112     /**
0113      * Returns the replacement string.
0114      */
0115     QString replacement() const;
0116 
0117     /**
0118      * Returns an empty widget which the user may fill with additional UI
0119      * elements as required. The widget occupies the width of the dialog,
0120      * and is positioned immediately the regular expression support widgets
0121      * for the replacement string.
0122      */
0123     QWidget *replaceExtension() const;
0124 
0125 protected:
0126     void showEvent(QShowEvent *) override;
0127 
0128 private:
0129     Q_DECLARE_PRIVATE(KReplaceDialog)
0130 };
0131 
0132 #endif // KREPLACEDIALOG_H