Changeset View
Changeset View
Standalone View
Standalone View
src/ui/highlighter.cpp
| Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | 73 | HighlighterPrivate(Highlighter *qq, const QColor &col) | |||
|---|---|---|---|---|---|
| 74 | : textEdit(nullptr) | 74 | : textEdit(nullptr) | ||
| 75 | , plainTextEdit(nullptr) | 75 | , plainTextEdit(nullptr) | ||
| 76 | , spellColor(col) | 76 | , spellColor(col) | ||
| 77 | , q(qq) | 77 | , q(qq) | ||
| 78 | { | 78 | { | ||
| 79 | tokenizer = new WordTokenizer(); | 79 | tokenizer = new WordTokenizer(); | ||
| 80 | active = true; | 80 | active = true; | ||
| 81 | automatic = false; | 81 | automatic = false; | ||
| 82 | autoDetectLanguageDisabled = false; | ||||
| 82 | connected = false; | 83 | connected = false; | ||
| 83 | wordCount = 0; | 84 | wordCount = 0; | ||
| 84 | errorCount = 0; | 85 | errorCount = 0; | ||
| 85 | intraWordEditing = false; | 86 | intraWordEditing = false; | ||
| 86 | completeRehighlightRequired = false; | 87 | completeRehighlightRequired = false; | ||
| 87 | spellColor = spellColor.isValid() ? spellColor : Qt::red; | 88 | spellColor = spellColor.isValid() ? spellColor : Qt::red; | ||
| 88 | languageFilter = new LanguageFilter(new SentenceTokenizer()); | 89 | languageFilter = new LanguageFilter(new SentenceTokenizer()); | ||
| 89 | 90 | | |||
| Show All 23 Lines | |||||
| 113 | WordTokenizer *tokenizer = nullptr; | 114 | WordTokenizer *tokenizer = nullptr; | ||
| 114 | LanguageFilter *languageFilter = nullptr; | 115 | LanguageFilter *languageFilter = nullptr; | ||
| 115 | Loader *loader = nullptr; | 116 | Loader *loader = nullptr; | ||
| 116 | Speller *spellchecker = nullptr; | 117 | Speller *spellchecker = nullptr; | ||
| 117 | QTextEdit *textEdit = nullptr; | 118 | QTextEdit *textEdit = nullptr; | ||
| 118 | QPlainTextEdit *plainTextEdit = nullptr; | 119 | QPlainTextEdit *plainTextEdit = nullptr; | ||
| 119 | bool active; | 120 | bool active; | ||
| 120 | bool automatic; | 121 | bool automatic; | ||
| 122 | bool autoDetectLanguageDisabled; | ||||
| 121 | bool completeRehighlightRequired; | 123 | bool completeRehighlightRequired; | ||
| 122 | bool intraWordEditing; | 124 | bool intraWordEditing; | ||
| 123 | bool spellCheckerFound; //cached d->dict->isValid() value | 125 | bool spellCheckerFound; //cached d->dict->isValid() value | ||
| 124 | bool connected; | 126 | bool connected; | ||
| 125 | int disablePercentage = 0; | 127 | int disablePercentage = 0; | ||
| 126 | int disableWordCount = 0; | 128 | int disableWordCount = 0; | ||
| 127 | int wordCount, errorCount; | 129 | int wordCount, errorCount; | ||
| 128 | QTimer *rehighlightRequest = nullptr; | 130 | QTimer *rehighlightRequest = nullptr; | ||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | 172 | { | |||
| 190 | QTimer::singleShot(0, this, SLOT(slotAutoDetection())); | 192 | QTimer::singleShot(0, this, SLOT(slotAutoDetection())); | ||
| 191 | } | 193 | } | ||
| 192 | 194 | | |||
| 193 | bool Highlighter::automatic() const | 195 | bool Highlighter::automatic() const | ||
| 194 | { | 196 | { | ||
| 195 | return d->automatic; | 197 | return d->automatic; | ||
| 196 | } | 198 | } | ||
| 197 | 199 | | |||
| 200 | bool Highlighter::autoDetectLanguageDisabled() const | ||||
| 201 | { | ||||
| 202 | return d->autoDetectLanguageDisabled; | ||||
| 203 | } | ||||
| 204 | | ||||
| 198 | bool Highlighter::intraWordEditing() const | 205 | bool Highlighter::intraWordEditing() const | ||
| 199 | { | 206 | { | ||
| 200 | return d->intraWordEditing; | 207 | return d->intraWordEditing; | ||
| 201 | } | 208 | } | ||
| 202 | 209 | | |||
| 203 | void Highlighter::setIntraWordEditing(bool editing) | 210 | void Highlighter::setIntraWordEditing(bool editing) | ||
| 204 | { | 211 | { | ||
| 205 | d->intraWordEditing = editing; | 212 | d->intraWordEditing = editing; | ||
| 206 | } | 213 | } | ||
| 207 | 214 | | |||
| 208 | void Highlighter::setAutomatic(bool automatic) | 215 | void Highlighter::setAutomatic(bool automatic) | ||
| 209 | { | 216 | { | ||
| 210 | if (automatic == d->automatic) { | 217 | if (automatic == d->automatic) { | ||
| 211 | return; | 218 | return; | ||
| 212 | } | 219 | } | ||
| 213 | 220 | | |||
| 214 | d->automatic = automatic; | 221 | d->automatic = automatic; | ||
| 215 | if (d->automatic) { | 222 | if (d->automatic) { | ||
| 216 | slotAutoDetection(); | 223 | slotAutoDetection(); | ||
| 217 | } | 224 | } | ||
| 218 | } | 225 | } | ||
| 219 | 226 | | |||
| 227 | void Highlighter::setAutoDetectLanguageDisabled(bool autoDetectDisabled) | ||||
| 228 | { | ||||
| 229 | d->autoDetectLanguageDisabled = autoDetectDisabled; | ||||
| 230 | } | ||||
| 231 | | ||||
| 220 | void Highlighter::slotAutoDetection() | 232 | void Highlighter::slotAutoDetection() | ||
| 221 | { | 233 | { | ||
| 222 | bool savedActive = d->active; | 234 | bool savedActive = d->active; | ||
| 223 | 235 | | |||
| 224 | //don't disable just because 1 of 4 is misspelled. | 236 | //don't disable just because 1 of 4 is misspelled. | ||
| 225 | if (d->automatic && d->wordCount >= 10) { | 237 | if (d->automatic && d->wordCount >= 10) { | ||
| 226 | // tme = Too many errors | 238 | // tme = Too many errors | ||
| 227 | bool tme = (d->errorCount >= d->disableWordCount) && ( | 239 | bool tme = (d->errorCount >= d->disableWordCount) && ( | ||
| ▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Line(s) | 328 | if (index != lengthPosition | |||
| 321 | if (!cache) { | 333 | if (!cache) { | ||
| 322 | cache = new LanguageCache; | 334 | cache = new LanguageCache; | ||
| 323 | setCurrentBlockUserData(cache); | 335 | setCurrentBlockUserData(cache); | ||
| 324 | } | 336 | } | ||
| 325 | 337 | | |||
| 326 | const bool autodetectLanguage = d->spellchecker->testAttribute(Speller::AutoDetectLanguage); | 338 | const bool autodetectLanguage = d->spellchecker->testAttribute(Speller::AutoDetectLanguage); | ||
| 327 | while (d->languageFilter->hasNext()) { | 339 | while (d->languageFilter->hasNext()) { | ||
| 328 | QStringRef sentence = d->languageFilter->next(); | 340 | QStringRef sentence = d->languageFilter->next(); | ||
| 329 | if (autodetectLanguage) { | 341 | if (autodetectLanguage && !d->autoDetectLanguageDisabled) { | ||
| 330 | QString lang; | 342 | QString lang; | ||
| 331 | QPair<int, int> spos = QPair<int, int>(sentence.position(), sentence.length()); | 343 | QPair<int, int> spos = QPair<int, int>(sentence.position(), sentence.length()); | ||
| 332 | // try cache first | 344 | // try cache first | ||
| 333 | if (cache->languages.contains(spos)) { | 345 | if (cache->languages.contains(spos)) { | ||
| 334 | lang = cache->languages.value(spos); | 346 | lang = cache->languages.value(spos); | ||
| 335 | } else { | 347 | } else { | ||
| 336 | lang = d->languageFilter->language(); | 348 | lang = d->languageFilter->language(); | ||
| 337 | if (!d->languageFilter->isSpellcheckable()) { | 349 | if (!d->languageFilter->isSpellcheckable()) { | ||
| Show All 40 Lines | 387 | { | |||
| 378 | d->spellCheckerFound = d->spellchecker->isValid(); | 390 | d->spellCheckerFound = d->spellchecker->isValid(); | ||
| 379 | if (!d->spellCheckerFound) { | 391 | if (!d->spellCheckerFound) { | ||
| 380 | qCDebug(SONNET_LOG_UI) << "No dictionary for \"" | 392 | qCDebug(SONNET_LOG_UI) << "No dictionary for \"" | ||
| 381 | << lang | 393 | << lang | ||
| 382 | << "\" staying with the current language."; | 394 | << "\" staying with the current language."; | ||
| 383 | d->spellchecker->setLanguage(prevLang); | 395 | d->spellchecker->setLanguage(prevLang); | ||
| 384 | return; | 396 | return; | ||
| 385 | } | 397 | } | ||
| 398 | d->autoDetectLanguageDisabled = true; | ||||
| 386 | d->wordCount = 0; | 399 | d->wordCount = 0; | ||
| 387 | d->errorCount = 0; | 400 | d->errorCount = 0; | ||
| 388 | if (d->automatic || d->active) { | 401 | if (d->automatic || d->active) { | ||
| 389 | d->rehighlightRequest->start(0); | 402 | d->rehighlightRequest->start(0); | ||
| 390 | } | 403 | } | ||
| 391 | } | 404 | } | ||
| 392 | 405 | | |||
| 393 | void Highlighter::setMisspelled(int start, int count) | 406 | void Highlighter::setMisspelled(int start, int count) | ||
| ▲ Show 20 Lines • Show All 126 Lines • Show Last 20 Lines | |||||