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

Generate some colors

parent 331c11cf
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "languagetoolgrammarerror.h" #include "languagetoolgrammarerror.h"
#include "liblanguagetool_debug.h" #include "liblanguagetool_debug.h"
#include "languagetoolmanager.h"
#include <QJsonArray> #include <QJsonArray>
...@@ -38,8 +39,6 @@ void LanguageToolGrammarError::parse(const QJsonObject &obj, int blockindex) ...@@ -38,8 +39,6 @@ void LanguageToolGrammarError::parse(const QJsonObject &obj, int blockindex)
mStart = obj[QStringLiteral("offset")].toInt(-1); mStart = obj[QStringLiteral("offset")].toInt(-1);
mLength = obj[QStringLiteral("length")].toInt(-1); mLength = obj[QStringLiteral("length")].toInt(-1);
mSuggestions = parseSuggestion(obj); mSuggestions = parseSuggestion(obj);
//TODO generate specific color!
mColor = QColor(Qt::red);
const QJsonObject rulesObj = obj[QStringLiteral("rule")].toObject(); const QJsonObject rulesObj = obj[QStringLiteral("rule")].toObject();
if (!rulesObj.isEmpty()) { if (!rulesObj.isEmpty()) {
mRule = rulesObj[QStringLiteral("id")].toString(); mRule = rulesObj[QStringLiteral("id")].toString();
...@@ -52,10 +51,11 @@ void LanguageToolGrammarError::parse(const QJsonObject &obj, int blockindex) ...@@ -52,10 +51,11 @@ void LanguageToolGrammarError::parse(const QJsonObject &obj, int blockindex)
//qDebug() << " mUrl" << mUrl; //qDebug() << " mUrl" << mUrl;
} }
} }
if (!mRule.isEmpty()) {
//TODO ??? mColor = LanguageToolManager::self()->grammarColorForError(mRule);
// mRule = obj[QStringLiteral("sRuleId")].toString(); } else {
// mOption = obj[QStringLiteral("sType")].toString(); mColor = QColor(Qt::red);
}
} }
QStringList LanguageToolGrammarError::parseSuggestion(const QJsonObject &obj) QStringList LanguageToolGrammarError::parseSuggestion(const QJsonObject &obj)
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <KConfigGroup> #include <KConfigGroup>
#include <KSharedConfig> #include <KSharedConfig>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QColor>
LanguageToolManager::LanguageToolManager(QObject *parent) LanguageToolManager::LanguageToolManager(QObject *parent)
: QObject(parent) : QObject(parent)
...@@ -66,6 +67,18 @@ QString LanguageToolManager::convertToLanguagePath(const QString &path) ...@@ -66,6 +67,18 @@ QString LanguageToolManager::convertToLanguagePath(const QString &path)
return path + QStringLiteral("/languages"); 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 QString LanguageToolManager::languageToolPath() const
{ {
return mLanguageToolPath; return mLanguageToolPath;
......
...@@ -21,7 +21,9 @@ ...@@ -21,7 +21,9 @@
#define LANGUAGETOOLMANAGER_H #define LANGUAGETOOLMANAGER_H
#include <QObject> #include <QObject>
#include <QHash>
#include "libkmaillanguagetool_export.h" #include "libkmaillanguagetool_export.h"
class QColor;
class QNetworkAccessManager; class QNetworkAccessManager;
class LIBKMAILLANGUAGETOOL_EXPORT LanguageToolManager : public QObject class LIBKMAILLANGUAGETOOL_EXPORT LanguageToolManager : public QObject
{ {
...@@ -50,8 +52,11 @@ public: ...@@ -50,8 +52,11 @@ public:
Q_REQUIRED_RESULT QString languageToolLanguagesPath() const; Q_REQUIRED_RESULT QString languageToolLanguagesPath() const;
static QString convertToLanguagePath(const QString &path); static QString convertToLanguagePath(const QString &path);
Q_REQUIRED_RESULT QColor grammarColorForError(const QString &error);
private: private:
Q_DISABLE_COPY(LanguageToolManager) Q_DISABLE_COPY(LanguageToolManager)
QHash<QString, QColor> mGrammarColor;
QString mLanguage; QString mLanguage;
QString mLanguageToolPath; QString mLanguageToolPath;
QNetworkAccessManager *mNetworkAccessManager = nullptr; 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