aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor/syntaxhighlighter.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2012-11-15 16:57:11 +0100
committerhjk <qthjk@ovi.com>2012-11-15 17:06:22 +0100
commit0767aab4b9eed386f72ec67722f4a9241708639e (patch)
treef6a54e8685c654ba3c0604d01a9f4ea2981496ad /src/plugins/texteditor/syntaxhighlighter.cpp
parent4cc11497fe449f5cf384c7573597866a287e0817 (diff)
Improve color highlighting of memory view.
Factor out and streamline code from the annotation highlighter to create a list of colors suitable for highlighting and use that in memory view. Task-number: QTCREATORBUG-8250 Change-Id: Iefd408847897ddc98e3aecd6e4f084d1415b80c0 Reviewed-by: hjk <qthjk@ovi.com>
Diffstat (limited to 'src/plugins/texteditor/syntaxhighlighter.cpp')
-rw-r--r--src/plugins/texteditor/syntaxhighlighter.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/plugins/texteditor/syntaxhighlighter.cpp b/src/plugins/texteditor/syntaxhighlighter.cpp
index f39e8c6d2fc..4f9c8f8704f 100644
--- a/src/plugins/texteditor/syntaxhighlighter.cpp
+++ b/src/plugins/texteditor/syntaxhighlighter.cpp
@@ -40,6 +40,8 @@
#include <qtextedit.h>
#include <qtimer.h>
+#include <math.h>
+
using namespace TextEditor;
class TextEditor::SyntaxHighlighterPrivate
@@ -755,4 +757,38 @@ void SyntaxHighlighter::setExtraAdditionalFormats(const QTextBlock& block,
d->inReformatBlocks = wasInReformatBlocks;
}
+/* Generate at least n different colors for highlighting, excluding background
+ * color. */
+
+QList<QColor> SyntaxHighlighter::generateColors(int n, const QColor &background)
+{
+ QList<QColor> result;
+ // Assign a color gradient. Generate a sufficient number of colors
+ // by using ceil and looping from 0..step.
+ const double oneThird = 1.0 / 3.0;
+ const int step = qRound(ceil(pow(double(n), oneThird)));
+ result.reserve(step * step * step);
+ const int factor = 255 / step;
+ const int half = factor / 2;
+ const int bgRed = background.red();
+ const int bgGreen = background.green();
+ const int bgBlue = background.blue();
+ for (int r = step; r >= 0; --r) {
+ const int red = r * factor;
+ if (bgRed - half > red || bgRed + half <= red) {
+ for (int g = step; g >= 0; --g) {
+ const int green = g * factor;
+ if (bgGreen - half > green || bgGreen + half <= green) {
+ for (int b = step; b >= 0 ; --b) {
+ const int blue = b * factor;
+ if (bgBlue - half > blue || bgBlue + half <= blue)
+ result.append(QColor(red, green, blue));
+ }
+ }
+ }
+ }
+ }
+ return result;
+}
+
#include "moc_syntaxhighlighter.cpp"