File indexing completed on 2024-03-24 04:03:39

0001 // krazy:excludeall=spelling
0002 /**
0003  * test_textedit.cpp
0004  *
0005  * SPDX-FileCopyrightText: 2013 Aurélien Gâteau <agateau@kde.org>
0006  *
0007  * SPDX-License-Identifier: LGPL-2.1-or-later
0008  */
0009 // Local
0010 #include <dictionarycombobox.h>
0011 #include <highlighter.h>
0012 #include <spellcheckdecorator.h>
0013 
0014 // Qt
0015 #include <QApplication>
0016 #include <QDebug>
0017 #include <QTextEdit>
0018 #include <QVBoxLayout>
0019 
0020 //@@snippet_begin(simple_email_example)
0021 class MailSpellCheckDecorator : public Sonnet::SpellCheckDecorator
0022 {
0023 public:
0024     explicit MailSpellCheckDecorator(QTextEdit *edit)
0025         : Sonnet::SpellCheckDecorator(edit)
0026     {
0027     }
0028 
0029 protected:
0030     bool isSpellCheckingEnabledForBlock(const QString &blockText) const override
0031     {
0032         qDebug() << blockText;
0033         return !blockText.startsWith(QLatin1Char('>'));
0034     }
0035 };
0036 //@@snippet_end
0037 
0038 int main(int argc, char **argv)
0039 {
0040     QApplication app(argc, argv);
0041 
0042     QWidget window;
0043 
0044     Sonnet::DictionaryComboBox *comboBox = new Sonnet::DictionaryComboBox;
0045 
0046     //@@snippet_begin(simple_textedit_example)
0047     QTextEdit *textEdit = new QTextEdit;
0048     textEdit->setText(
0049         QString::fromLatin1("This is a sample buffer. Whih this thingg will "
0050                             "be checkin for misstakes. Whih, Enviroment, govermant. Whih."));
0051 
0052     Sonnet::SpellCheckDecorator *installer = new Sonnet::SpellCheckDecorator(textEdit);
0053     installer->highlighter()->setCurrentLanguage(QStringLiteral("en_US"));
0054     //@@snippet_end
0055 
0056     QObject::connect(comboBox, &Sonnet::DictionaryComboBox::dictionaryChanged, installer->highlighter(), &Sonnet::Highlighter::setCurrentLanguage);
0057 
0058     QTextEdit *mailTextEdit = new QTextEdit;
0059     mailTextEdit->setText(QStringLiteral("John Doe said:\n> Hello how aree you?\nI am ffine thanks"));
0060 
0061     installer = new MailSpellCheckDecorator(mailTextEdit);
0062     installer->highlighter()->setCurrentLanguage(QStringLiteral("en_US"));
0063     QObject::connect(comboBox, &Sonnet::DictionaryComboBox::dictionaryChanged, installer->highlighter(), &Sonnet::Highlighter::setCurrentLanguage);
0064 
0065     QVBoxLayout *layout = new QVBoxLayout(&window);
0066     layout->addWidget(comboBox);
0067     layout->addWidget(textEdit);
0068     layout->addWidget(mailTextEdit);
0069 
0070     window.show();
0071     return app.exec();
0072 }