Commit 4b366303 authored by Tobias Hunger's avatar Tobias Hunger

VCS: Make dark color schemes work with annotation highlighter

Task-number: QTCREATORBUG-6257

Change-Id: Ied01cf6773b5114100afccbac33f359cc72c0889
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent 5e365686
......@@ -37,8 +37,9 @@ using namespace Bazaar::Internal;
using namespace Bazaar;
BazaarAnnotationHighlighter::BazaarAnnotationHighlighter(const ChangeNumbers &changeNumbers,
const QColor &bg,
QTextDocument *document)
: VcsBase::BaseAnnotationHighlighter(changeNumbers, document),
: VcsBase::BaseAnnotationHighlighter(changeNumbers, bg, document),
m_changeset(QLatin1String(Constants::CHANGESET_ID))
{
}
......
......@@ -42,7 +42,7 @@ namespace Internal {
class BazaarAnnotationHighlighter : public VcsBase::BaseAnnotationHighlighter
{
public:
explicit BazaarAnnotationHighlighter(const ChangeNumbers &changeNumbers,
explicit BazaarAnnotationHighlighter(const ChangeNumbers &changeNumbers, const QColor &bg,
QTextDocument *document = 0);
private:
......
......@@ -101,9 +101,10 @@ VcsBase::DiffHighlighter *BazaarEditor::createDiffHighlighter() const
return new VcsBase::DiffHighlighter(m_diffFileId);
}
VcsBase::BaseAnnotationHighlighter *BazaarEditor::createAnnotationHighlighter(const QSet<QString> &changes) const
VcsBase::BaseAnnotationHighlighter *BazaarEditor::createAnnotationHighlighter(const QSet<QString> &changes,
const QColor &bg) const
{
return new BazaarAnnotationHighlighter(changes);
return new BazaarAnnotationHighlighter(changes, bg);
}
QString BazaarEditor::fileNameFromDiffSpecification(const QTextBlock &inBlock) const
......
......@@ -51,7 +51,7 @@ private:
virtual QSet<QString> annotationChanges() const;
virtual QString changeUnderCursor(const QTextCursor &cursor) const;
virtual VcsBase::DiffHighlighter *createDiffHighlighter() const;
virtual VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes) const;
virtual VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes, const QColor &bg) const;
virtual QString fileNameFromDiffSpecification(const QTextBlock &diffFileSpec) const;
const QRegExp m_exactChangesetId;
......
......@@ -36,8 +36,9 @@ using namespace Cvs;
using namespace Cvs::Internal;
CvsAnnotationHighlighter::CvsAnnotationHighlighter(const ChangeNumbers &changeNumbers,
const QColor &bg,
QTextDocument *document) :
VcsBase::BaseAnnotationHighlighter(changeNumbers, document),
VcsBase::BaseAnnotationHighlighter(changeNumbers, bg, document),
m_blank(QLatin1Char(' '))
{
}
......
......@@ -44,7 +44,7 @@ class CvsAnnotationHighlighter : public VcsBase::BaseAnnotationHighlighter
Q_OBJECT
public:
explicit CvsAnnotationHighlighter(const ChangeNumbers &changeNumbers,
explicit CvsAnnotationHighlighter(const ChangeNumbers &changeNumbers, const QColor &bg,
QTextDocument *document = 0);
private:
......
......@@ -131,9 +131,10 @@ VcsBase::DiffHighlighter *CvsEditor::createDiffHighlighter() const
return new VcsBase::DiffHighlighter(filePattern);
}
VcsBase::BaseAnnotationHighlighter *CvsEditor::createAnnotationHighlighter(const QSet<QString> &changes) const
VcsBase::BaseAnnotationHighlighter *CvsEditor::createAnnotationHighlighter(const QSet<QString> &changes,
const QColor &bg) const
{
return new CvsAnnotationHighlighter(changes);
return new CvsAnnotationHighlighter(changes, bg);
}
QString CvsEditor::fileNameFromDiffSpecification(const QTextBlock &inBlock) const
......
......@@ -52,7 +52,7 @@ private:
QSet<QString> annotationChanges() const;
QString changeUnderCursor(const QTextCursor &) const;
VcsBase::DiffHighlighter *createDiffHighlighter() const;
VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes) const;
VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes, const QColor &bg) const;
QString fileNameFromDiffSpecification(const QTextBlock &diffFileName) const;
QStringList annotationPreviousVersions(const QString &revision) const;
......
......@@ -38,8 +38,9 @@ namespace Git {
namespace Internal {
GitAnnotationHighlighter::GitAnnotationHighlighter(const ChangeNumbers &changeNumbers,
QTextDocument *document) :
VcsBase::BaseAnnotationHighlighter(changeNumbers, document),
const QColor &bg,
QTextDocument *document) :
VcsBase::BaseAnnotationHighlighter(changeNumbers, bg, document),
m_blank(QLatin1Char(' '))
{
}
......
......@@ -43,7 +43,7 @@ class GitAnnotationHighlighter : public VcsBase::BaseAnnotationHighlighter
{
Q_OBJECT
public:
explicit GitAnnotationHighlighter(const ChangeNumbers &changeNumbers,
explicit GitAnnotationHighlighter(const ChangeNumbers &changeNumbers, const QColor &bg,
QTextDocument *document = 0);
private:
......
......@@ -116,9 +116,10 @@ VcsBase::DiffHighlighter *GitEditor::createDiffHighlighter() const
return new VcsBase::DiffHighlighter(filePattern);
}
VcsBase::BaseAnnotationHighlighter *GitEditor::createAnnotationHighlighter(const QSet<QString> &changes) const
VcsBase::BaseAnnotationHighlighter *GitEditor::createAnnotationHighlighter(const QSet<QString> &changes,
const QColor &bg) const
{
return new GitAnnotationHighlighter(changes);
return new GitAnnotationHighlighter(changes, bg);
}
QString GitEditor::fileNameFromDiffSpecification(const QTextBlock &inBlock) const
......
......@@ -61,7 +61,7 @@ private:
virtual QSet<QString> annotationChanges() const;
virtual QString changeUnderCursor(const QTextCursor &) const;
virtual VcsBase::DiffHighlighter *createDiffHighlighter() const;
virtual VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes) const;
virtual VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes, const QColor &bg) const;
virtual QString fileNameFromDiffSpecification(const QTextBlock &diffFileName) const;
virtual QStringList annotationPreviousVersions(const QString &revision) const;
......
......@@ -37,8 +37,9 @@ using namespace Mercurial::Internal;
using namespace Mercurial;
MercurialAnnotationHighlighter::MercurialAnnotationHighlighter(const ChangeNumbers &changeNumbers,
const QColor &bg,
QTextDocument *document)
: VcsBase::BaseAnnotationHighlighter(changeNumbers, document),
: VcsBase::BaseAnnotationHighlighter(changeNumbers, bg, document),
changeset(QLatin1String(Constants::CHANGESETID12))
{
}
......
......@@ -42,7 +42,7 @@ namespace Internal {
class MercurialAnnotationHighlighter : public VcsBase::BaseAnnotationHighlighter
{
public:
explicit MercurialAnnotationHighlighter(const ChangeNumbers &changeNumbers,
explicit MercurialAnnotationHighlighter(const ChangeNumbers &changeNumbers, const QColor &bg,
QTextDocument *document = 0);
private:
......
......@@ -96,9 +96,10 @@ VcsBase::DiffHighlighter *MercurialEditor::createDiffHighlighter() const
return new VcsBase::DiffHighlighter(diffIdentifier);
}
VcsBase::BaseAnnotationHighlighter *MercurialEditor::createAnnotationHighlighter(const QSet<QString> &changes) const
VcsBase::BaseAnnotationHighlighter *MercurialEditor::createAnnotationHighlighter(const QSet<QString> &changes,
const QColor &bg) const
{
return new MercurialAnnotationHighlighter(changes);
return new MercurialAnnotationHighlighter(changes, bg);
}
QString MercurialEditor::fileNameFromDiffSpecification(const QTextBlock &inBlock) const
......
......@@ -50,7 +50,7 @@ private:
virtual QSet<QString> annotationChanges() const;
virtual QString changeUnderCursor(const QTextCursor &cursor) const;
virtual VcsBase::DiffHighlighter *createDiffHighlighter() const;
virtual VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes) const;
virtual VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes, const QColor &bg) const;
virtual QString fileNameFromDiffSpecification(const QTextBlock &diffFileSpec) const;
virtual QStringList annotationPreviousVersions(const QString &revision) const;
......
......@@ -36,8 +36,9 @@ namespace Perforce {
namespace Internal {
PerforceAnnotationHighlighter::PerforceAnnotationHighlighter(const ChangeNumbers &changeNumbers,
const QColor &bg,
QTextDocument *document) :
VcsBase::BaseAnnotationHighlighter(changeNumbers, document),
VcsBase::BaseAnnotationHighlighter(changeNumbers, bg, document),
m_colon(QLatin1Char(':'))
{
}
......
......@@ -44,6 +44,7 @@ class PerforceAnnotationHighlighter : public VcsBase::BaseAnnotationHighlighter
Q_OBJECT
public:
explicit PerforceAnnotationHighlighter(const ChangeNumbers &changeNumbers,
const QColor &bg,
QTextDocument *document = 0);
private:
......
......@@ -112,9 +112,10 @@ VcsBase::DiffHighlighter *PerforceEditor::createDiffHighlighter() const
return new VcsBase::DiffHighlighter(filePattern);
}
VcsBase::BaseAnnotationHighlighter *PerforceEditor::createAnnotationHighlighter(const QSet<QString> &changes) const
VcsBase::BaseAnnotationHighlighter *PerforceEditor::createAnnotationHighlighter(const QSet<QString> &changes,
const QColor &bg) const
{
return new PerforceAnnotationHighlighter(changes);
return new PerforceAnnotationHighlighter(changes, bg);
}
QString PerforceEditor::fileNameFromDiffSpecification(const QTextBlock &inBlock) const
......
......@@ -54,7 +54,7 @@ private:
virtual QSet<QString> annotationChanges() const;
virtual QString changeUnderCursor(const QTextCursor &) const;
virtual VcsBase::DiffHighlighter *createDiffHighlighter() const;
virtual VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes) const;
virtual VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes, const QColor &bg) const;
virtual QString fileNameFromDiffSpecification(const QTextBlock &diffFileName) const;
virtual QStringList annotationPreviousVersions(const QString &v) const;
......
......@@ -36,8 +36,9 @@ using namespace Subversion;
using namespace Subversion::Internal;
SubversionAnnotationHighlighter::SubversionAnnotationHighlighter(const ChangeNumbers &changeNumbers,
QTextDocument *document) :
VcsBase::BaseAnnotationHighlighter(changeNumbers, document),
const QColor &bg,
QTextDocument *document) :
VcsBase::BaseAnnotationHighlighter(changeNumbers, bg, document),
m_blank(QLatin1Char(' '))
{
}
......
......@@ -43,7 +43,7 @@ class SubversionAnnotationHighlighter : public VcsBase::BaseAnnotationHighlighte
{
Q_OBJECT
public:
explicit SubversionAnnotationHighlighter(const ChangeNumbers &changeNumbers,
explicit SubversionAnnotationHighlighter(const ChangeNumbers &changeNumbers, const QColor &bg,
QTextDocument *document = 0);
private:
......
......@@ -117,9 +117,10 @@ VcsBase::DiffHighlighter *SubversionEditor::createDiffHighlighter() const
return new VcsBase::DiffHighlighter(filePattern);
}
VcsBase::BaseAnnotationHighlighter *SubversionEditor::createAnnotationHighlighter(const QSet<QString> &changes) const
VcsBase::BaseAnnotationHighlighter *SubversionEditor::createAnnotationHighlighter(const QSet<QString> &changes,
const QColor &bg) const
{
return new SubversionAnnotationHighlighter(changes);
return new SubversionAnnotationHighlighter(changes, bg);
}
QString SubversionEditor::fileNameFromDiffSpecification(const QTextBlock &inBlock) const
......
......@@ -52,7 +52,7 @@ private:
virtual QSet<QString> annotationChanges() const;
virtual QString changeUnderCursor(const QTextCursor &) const;
virtual VcsBase::DiffHighlighter *createDiffHighlighter() const;
virtual VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes) const;
virtual VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes, const QColor &bg) const;
virtual QString fileNameFromDiffSpecification(const QTextBlock &diffFileName) const;
virtual QStringList annotationPreviousVersions(const QString &) const;
......
......@@ -62,15 +62,18 @@ class BaseAnnotationHighlighterPrivate
{
public:
ChangeNumberFormatMap m_changeNumberMap;
QColor m_background;
};
} // namespace Internal
BaseAnnotationHighlighter::BaseAnnotationHighlighter(const ChangeNumbers &changeNumbers,
QTextDocument *document) :
const QColor &bg,
QTextDocument *document) :
TextEditor::SyntaxHighlighter(document),
d(new Internal::BaseAnnotationHighlighterPrivate)
{
d->m_background = bg;
setChangeNumbers(changeNumbers);
}
......@@ -81,6 +84,7 @@ BaseAnnotationHighlighter::~BaseAnnotationHighlighter()
void BaseAnnotationHighlighter::setChangeNumbers(const ChangeNumbers &changeNumbers)
{
QColor bg = d->m_background;
d->m_changeNumberMap.clear();
if (!changeNumbers.isEmpty()) {
// Assign a color gradient to annotation change numbers. Give
......@@ -89,10 +93,16 @@ void BaseAnnotationHighlighter::setChangeNumbers(const ChangeNumbers &changeNumb
const int step = qRound(ceil(pow(double(changeNumbers.count()), oneThird)));
QList<QColor> colors;
const int factor = 255 / step;
for (int i=0; i<step; ++i)
for (int j=0; j<step; ++j)
for (int k=0; k<step; ++k)
colors.append(QColor(i*factor, j*factor, k*factor));
int half = factor / 2;
for (int i=0; i<=step; ++i)
for (int j=0; j<=step; ++j)
for (int k=0; k<=step; ++k) {
QColor c(i*factor, j*factor, k*factor);
if ((bg.red() - half > c.red() ||bg.red() + half <= c.red())
&& (bg.green() - half > c.green() || bg.green() + half <= c.green())
&& (bg.blue() - half > c.blue() || bg.blue() + half <= c.blue()))
colors.prepend(c);
}
int m = 0;
const int cstep = colors.count() / changeNumbers.count();
......@@ -116,4 +126,10 @@ void BaseAnnotationHighlighter::highlightBlock(const QString &text)
setFormat(0, text.length(), it.value());
}
void BaseAnnotationHighlighter::setBackgroundColor(const QColor &color)
{
d->m_background = color;
setChangeNumbers(d->m_changeNumberMap.keys().toSet());
}
} // namespace VcsBase
......@@ -48,7 +48,7 @@ class VCSBASE_EXPORT BaseAnnotationHighlighter : public TextEditor::SyntaxHighli
public:
typedef QSet<QString> ChangeNumbers;
explicit BaseAnnotationHighlighter(const ChangeNumbers &changeNumbers,
explicit BaseAnnotationHighlighter(const ChangeNumbers &changeNumbers, const QColor &bg,
QTextDocument *document = 0);
virtual ~BaseAnnotationHighlighter();
......@@ -56,6 +56,8 @@ public:
virtual void highlightBlock(const QString &text);
void setBackgroundColor(const QColor &color);
private:
// Implement this to return the change number of a line
virtual QString changeNumber(const QString &block) const = 0;
......
......@@ -605,6 +605,8 @@ public:
bool m_revertChunkEnabled;
bool m_mouseDragging;
QList<AbstractTextCursorHandler *> m_textCursorHandlers;
QColor m_backgroundColor;
};
VcsBaseEditorWidgetPrivate::VcsBaseEditorWidgetPrivate(VcsBaseEditorWidget *editorWidget,
......@@ -1017,7 +1019,7 @@ void VcsBaseEditorWidget::slotActivateAnnotation()
ah->setChangeNumbers(changes);
ah->rehighlight();
} else {
baseTextDocument()->setSyntaxHighlighter(createAnnotationHighlighter(changes));
baseTextDocument()->setSyntaxHighlighter(createAnnotationHighlighter(changes, d->m_backgroundColor));
}
}
......@@ -1149,6 +1151,9 @@ void VcsBaseEditorWidget::setPlainTextData(const QByteArray &data)
void VcsBaseEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
{
TextEditor::BaseTextEditorWidget::setFontSettings(fs);
d->m_backgroundColor = fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_TEXT))
.brushProperty(QTextFormat::BackgroundBrush).color();
if (d->m_parameters->type == DiffOutput) {
if (DiffHighlighter *highlighter = qobject_cast<DiffHighlighter*>(baseTextDocument()->syntaxHighlighter())) {
static QVector<QString> categories;
......@@ -1162,6 +1167,11 @@ void VcsBaseEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
highlighter->setFormats(fs.toTextCharFormats(categories));
highlighter->rehighlight();
}
} else if (d->m_parameters->type == AnnotateOutput) {
if (BaseAnnotationHighlighter *highlighter = qobject_cast<BaseAnnotationHighlighter *>(baseTextDocument()->syntaxHighlighter())) {
highlighter->setBackgroundColor(d->m_backgroundColor);
highlighter->rehighlight();
}
}
}
......
......@@ -249,7 +249,8 @@ private:
virtual QString changeUnderCursor(const QTextCursor &) const = 0;
// Factory functions for highlighters
virtual DiffHighlighter *createDiffHighlighter() const = 0;
virtual BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes) const = 0;
virtual BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes,
const QColor &bg) const = 0;
// Implement to return a local file name from the diff file specification
// (text cursor at position above change hunk)
virtual QString fileNameFromDiffSpecification(const QTextBlock &diffFileSpec) const = 0;
......
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