Commit 863ae897 authored by Laurent Montel's avatar Laurent Montel 😁

Generate some colors

parent 331c11cf
......@@ -19,6 +19,7 @@
#include "languagetoolgrammarerror.h"
#include "liblanguagetool_debug.h"
#include "languagetoolmanager.h"
#include <QJsonArray>
......@@ -38,8 +39,6 @@ void LanguageToolGrammarError::parse(const QJsonObject &obj, int blockindex)
mStart = obj[QStringLiteral("offset")].toInt(-1);
mLength = obj[QStringLiteral("length")].toInt(-1);
mSuggestions = parseSuggestion(obj);
//TODO generate specific color!
mColor = QColor(Qt::red);
const QJsonObject rulesObj = obj[QStringLiteral("rule")].toObject();
if (!rulesObj.isEmpty()) {
mRule = rulesObj[QStringLiteral("id")].toString();
......@@ -52,10 +51,11 @@ void LanguageToolGrammarError::parse(const QJsonObject &obj, int blockindex)
//qDebug() << " mUrl" << mUrl;
}
}
//TODO ???
// mRule = obj[QStringLiteral("sRuleId")].toString();
// mOption = obj[QStringLiteral("sType")].toString();
if (!mRule.isEmpty()) {
mColor = LanguageToolManager::self()->grammarColorForError(mRule);
} else {
mColor = QColor(Qt::red);
}
}
QStringList LanguageToolGrammarError::parseSuggestion(const QJsonObject &obj)
......
......@@ -22,6 +22,7 @@
#include <KConfigGroup>
#include <KSharedConfig>
#include <QNetworkAccessManager>
#include <QColor>
LanguageToolManager::LanguageToolManager(QObject *parent)
: QObject(parent)
......@@ -66,6 +67,18 @@ QString LanguageToolManager::convertToLanguagePath(const QString &path)
return path + QStringLiteral("/languages");
}
QColor LanguageToolManager::grammarColorForError(const QString &error)
{
QColor col = mGrammarColor.value(error);
if (col.isValid()) {
return col;
}
col.setRgb(qrand() % 256, qrand() % 256, qrand() % 256);
//Generate color.
mGrammarColor.insert(error, col);
return col;
}
QString LanguageToolManager::languageToolPath() const
{
return mLanguageToolPath;
......
......@@ -21,7 +21,9 @@
#define LANGUAGETOOLMANAGER_H
#include <QObject>
#include <QHash>
#include "libkmaillanguagetool_export.h"
class QColor;
class QNetworkAccessManager;
class LIBKMAILLANGUAGETOOL_EXPORT LanguageToolManager : public QObject
{
......@@ -50,8 +52,11 @@ public:
Q_REQUIRED_RESULT QString languageToolLanguagesPath() const;
static QString convertToLanguagePath(const QString &path);
Q_REQUIRED_RESULT QColor grammarColorForError(const QString &error);
private:
Q_DISABLE_COPY(LanguageToolManager)
QHash<QString, QColor> mGrammarColor;
QString mLanguage;
QString mLanguageToolPath;
QNetworkAccessManager *mNetworkAccessManager = nullptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment