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