7#include "languagetoolresultwidget.h"
8#include "common/grammarresulttextedit.h"
9#include "languagetoolcombobox.h"
10#include "languagetoolmanager.h"
11#include "languagetoolparser.h"
12#include "languagetoolresultjob.h"
13#include "languagetoolupdatecombobox.h"
15#include <KLocalizedString>
19#include <QJsonDocument>
21using namespace TextGrammarCheck;
22LanguageToolResultWidget::LanguageToolResultWidget(
QWidget *parent)
23 : GrammarResultWidget(parent)
24 , mLanguageToolUpdateCombobox(new LanguageToolUpdateComboBox(this))
27 mLanguageToolUpdateCombobox->setLanguageToolCombobox(mLanguageToolComboBox);
28 mLanguageToolUpdateCombobox->setParentWidget(
this);
29 if (LanguageToolManager::self()->allowToGetListOfLanguages()) {
30 mLanguageToolUpdateCombobox->firstRefreshListOfLanguages();
32 mLanguageToolComboBox->setLanguage(LanguageToolManager::self()->language());
36LanguageToolResultWidget::~LanguageToolResultWidget() =
default;
38void LanguageToolResultWidget::checkGrammar()
40 auto job =
new LanguageToolResultJob(
this);
41 job->setUrl(LanguageToolManager::self()->languageToolCheckPath());
42 job->setNetworkAccessManager(LanguageToolManager::self()->networkAccessManager());
44 job->setLanguage( mLanguageToolComboBox->language());
45 connect(job, &LanguageToolResultJob::finished,
this, &LanguageToolResultWidget::slotCheckGrammarFinished);
46 connect(job, &LanguageToolResultJob::error,
this, &LanguageToolResultWidget::slotError);
50void LanguageToolResultWidget::slotCheckGrammarFinished(
const QString &result)
52 LanguageToolParser parser;
55 applyGrammarResult(parser.parseResult(fields));
58void LanguageToolResultWidget::slotError(
const QString &str)
63void LanguageToolResultWidget::addExtraWidget()
66 extraWidgetLayout->
setObjectName(QStringLiteral(
"extraWidgetLayout"));
67 extraWidgetLayout->setContentsMargins({});
68 mLanguageToolComboBox =
new LanguageToolComboBox(
this);
69 mLanguageToolComboBox->
setObjectName(QStringLiteral(
"languagetoolcombobox"));
70 extraWidgetLayout->addWidget(mLanguageToolComboBox);
73 recheckBtn->setObjectName(QStringLiteral(
"recheck-button"));
75 recheckBtn->setIconSize(
QSize(16, 16));
76 recheckBtn->setToolTip(
i18nc(
"@info:tooltip",
"Check"));
77 recheckBtn->setAutoRaise(
true);
78 extraWidgetLayout->addWidget(recheckBtn);
80 mExtraWidgetLayout->
addLayout(extraWidgetLayout);
84#include "moc_languagetoolresultwidget.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
void addLayout(QLayout *layout, int stretch)
QIcon fromTheme(const QString &name)
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
QJsonObject object() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setObjectName(QAnyStringView name)
QByteArray toUtf8() const const
QString toPlainText() const const