File indexing completed on 2024-04-21 03:57:42

0001 /*
0002     SPDX-FileCopyrightText: 2003 Zack Rusin <zack@kde.org>
0003     SPDX-FileCopyrightText: 2009-2010 Michel Ludwig <michel.ludwig@kdemail.net>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef SPELLCHECK_BAR_H
0009 #define SPELLCHECK_BAR_H
0010 
0011 #include "kateviewhelpers.h"
0012 
0013 class QListWidgetItem;
0014 class QModelIndex;
0015 
0016 namespace Sonnet
0017 {
0018 class BackgroundChecker;
0019 }
0020 
0021 /**
0022  * @short Spellcheck dialog
0023  *
0024  * \code
0025  * Sonnet::SpellCheckBar dlg = new Sonnet::SpellCheckBar(
0026  *       new Sonnet::BackgroundChecker(this), this);
0027  * //connect signals
0028  * ...
0029  * dlg->setBuffer( someText );
0030  * dlg->show();
0031  * \endcode
0032  *
0033  * You can change buffer inside a slot connected to done() signal
0034  * and spellcheck will continue with new data automatically.
0035  */
0036 class SpellCheckBar : public KateViewBarWidget
0037 {
0038     Q_OBJECT
0039 public:
0040     SpellCheckBar(Sonnet::BackgroundChecker *checker, QWidget *parent);
0041     ~SpellCheckBar() override;
0042 
0043     QString originalBuffer() const;
0044     QString buffer() const;
0045 
0046     void closed() override;
0047 
0048     void show();
0049     void activeAutoCorrect(bool _active);
0050 
0051     /**
0052      * Controls whether an (indefinite) progress dialog is shown when the spell
0053      * checking takes longer than the given time to complete. By default no
0054      * progress dialog is shown. If the progress dialog is set to be shown, no
0055      * time consuming operation (for example, showing a notification message) should
0056      * be performed in a slot connected to the 'done' signal as this might trigger
0057      * the progress dialog unnecessarily.
0058      *
0059      * @param timeout time after which the progress dialog should appear; a negative
0060      *                value can be used to hide it
0061      * @since 4.4
0062      */
0063     void showProgressDialog(int timeout = 500);
0064 
0065     /**
0066      * Controls whether a message box indicating the completion of the spell checking
0067      * is shown or not. By default it is not shown.
0068      *
0069      * @since 4.4
0070      */
0071     void showSpellCheckCompletionMessage(bool b = true);
0072 
0073     /**
0074      * Controls whether the spell checking is continued after the replacement of a
0075      * misspelled word has been performed. By default it is continued.
0076      *
0077      * @since 4.4
0078      */
0079     void setSpellCheckContinuedAfterReplacement(bool b);
0080 
0081 public Q_SLOTS:
0082     void setBuffer(const QString &);
0083 
0084 Q_SIGNALS:
0085     /**
0086      * The dialog won't be closed if you setBuffer() in slot connected to this signal
0087      *
0088      * Also emitted after stop() signal
0089      */
0090     void done(const QString &newBuffer);
0091     void misspelling(const QString &word, int start);
0092     void replace(const QString &oldWord, int start, const QString &newWord);
0093 
0094     void stop();
0095     void cancel();
0096     void autoCorrect(const QString &currentWord, const QString &replaceWord);
0097 
0098     /**
0099      * Signal sends when spell checking is finished/stopped/completed
0100      * @since 4.1
0101      */
0102     void spellCheckStatus(const QString &);
0103 
0104     /**
0105      * Emitted when the user changes the language used for spellchecking,
0106      * which is shown in a combobox of this dialog.
0107      *
0108      * @param language the new language the user selected
0109      * @since 4.1
0110      */
0111     void languageChanged(const QString &language);
0112 
0113 private Q_SLOTS:
0114     void slotMisspelling(const QString &word, int start);
0115     void slotDone();
0116 
0117     void slotCancel();
0118 
0119     void slotAddWord();
0120     void slotReplaceWord();
0121     void slotReplaceAll();
0122     void slotSkip();
0123     void slotSkipAll();
0124     void slotSuggest();
0125     void slotChangeLanguage(const QString &);
0126     void slotAutocorrect();
0127 
0128     void setGuiEnabled(bool b);
0129     void setProgressDialogVisible(bool b);
0130 
0131 private:
0132     void updateDialog(const QString &word);
0133     void fillDictionaryComboBox();
0134     void updateDictionaryComboBox();
0135     void fillSuggestions(const QStringList &suggs);
0136     void initConnections();
0137     void initGui();
0138     void continueChecking();
0139 
0140 private:
0141     class Private;
0142     Private *const d;
0143 };
0144 
0145 #endif