File indexing completed on 2024-04-21 04:00:57

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