Fixed syntax highlight of ifdefed-out code.

Done with mae
This commit is contained in:
Roberto Raggi
2009-10-08 12:57:26 +02:00
parent 37a713bc6d
commit 1bb9a24517
3 changed files with 19 additions and 26 deletions

View File

@@ -1918,23 +1918,6 @@ void BaseTextEditorPrivate::moveCursorVisible(bool ensureVisible)
q->ensureCursorVisible(); q->ensureCursorVisible();
} }
static QColor calcBlendColor(const QColor &baseColor, int factor = 1)
{
const int blendBase = (baseColor.value() > 128) ? 0 : 255;
// Darker backgrounds may need a bit more contrast
const int blendFactor = (baseColor.value() > 128) ? 16 : 32;
QColor blendColor = baseColor;
while (factor--) {
blendColor = QColor(
(blendBase * blendFactor + blendColor.red() * (256 - blendFactor)) / 256,
(blendBase * blendFactor + blendColor.green() * (256 - blendFactor)) / 256,
(blendBase * blendFactor + blendColor.blue() * (256 - blendFactor)) / 256);
}
return blendColor;
}
static QColor calcBlendColor(const QColor &baseColor, int level, int count) static QColor calcBlendColor(const QColor &baseColor, int level, int count)
{ {
QColor color80; QColor color80;
@@ -1997,13 +1980,13 @@ void BaseTextEditor::paintEvent(QPaintEvent *e)
QRect viewportRect = viewport()->rect(); QRect viewportRect = viewport()->rect();
const QColor baseColor = palette().base().color(); const QColor baseColor = palette().base().color();
const QColor blendColor = calcBlendColor(baseColor);
qreal lineX = 0; qreal lineX = 0;
if (d->m_visibleWrapColumn > 0) { if (d->m_visibleWrapColumn > 0) {
lineX = fontMetrics().averageCharWidth() * d->m_visibleWrapColumn + offset.x() + 4; lineX = fontMetrics().averageCharWidth() * d->m_visibleWrapColumn + offset.x() + 4;
painter.fillRect(QRectF(lineX, 0, viewportRect.width() - lineX, viewportRect.height()), blendColor); painter.fillRect(QRectF(lineX, 0, viewportRect.width() - lineX, viewportRect.height()),
d->m_ifdefedOutFormat.background());
} }
// // keep right margin clean from full-width selection // // keep right margin clean from full-width selection
@@ -2051,6 +2034,15 @@ void BaseTextEditor::paintEvent(QPaintEvent *e)
QRectF r = blockBoundingRect(block).translated(offset); QRectF r = blockBoundingRect(block).translated(offset);
if (TextEditDocumentLayout::ifdefedOut(block)) {
QRectF rr = r;
rr.setWidth(viewport()->width());
if (lineX > 0)
rr.setRight(qMin(lineX, rr.right()));
painter.fillRect(rr, d->m_ifdefedOutFormat.background());
}
if (!d->m_highlightBlocksInfo.isEmpty()) { if (!d->m_highlightBlocksInfo.isEmpty()) {
int n = block.blockNumber(); int n = block.blockNumber();
@@ -2077,15 +2069,17 @@ void BaseTextEditor::paintEvent(QPaintEvent *e)
QTextLayout *layout = block.layout(); QTextLayout *layout = block.layout();
#if 0
QTextOption option = layout->textOption(); QTextOption option = layout->textOption();
if (TextEditDocumentLayout::ifdefedOut(block)) { if (TextEditDocumentLayout::ifdefedOut(block)) {
option.setFlags(option.flags() | QTextOption::SuppressColors); option.setFlags(option.flags() /*| QTextOption::SuppressColors*/);
painter.setPen(d->m_ifdefedOutFormat.foreground().color()); painter.setPen(d->m_ifdefedOutFormat.foreground().color());
} else { } else {
option.setFlags(option.flags() & ~QTextOption::SuppressColors); option.setFlags(option.flags() & ~QTextOption::SuppressColors);
painter.setPen(context.palette.text().color()); painter.setPen(context.palette.text().color());
} }
layout->setTextOption(option); layout->setTextOption(option);
#endif
if (r.bottom() >= er.top() && r.top() <= er.bottom()) { if (r.bottom() >= er.top() && r.top() <= er.bottom()) {
@@ -2342,9 +2336,7 @@ void BaseTextEditor::paintEvent(QPaintEvent *e)
painter.save(); painter.save();
painter.setRenderHint(QPainter::Antialiasing, true); painter.setRenderHint(QPainter::Antialiasing, true);
painter.translate(.5, .5); painter.translate(.5, .5);
QColor color = blendColor; painter.setBrush(d->m_ifdefedOutFormat.background());
// color.setAlpha(240); // someone thinks alpha blending looks messy
painter.setBrush(color);
painter.drawRoundedRect(QRectF(visibleCollapsedBlockOffset.x(), painter.drawRoundedRect(QRectF(visibleCollapsedBlockOffset.x(),
visibleCollapsedBlockOffset.y(), visibleCollapsedBlockOffset.y(),
maxWidth, blockHeight).adjusted(0, 0, 0, 0), 3, 3); maxWidth, blockHeight).adjusted(0, 0, 0, 0), 3, 3);
@@ -4159,8 +4151,7 @@ void BaseTextEditor::setIfdefedOutBlocks(const QList<BaseTextEditor::BlockRange>
bool set = false; bool set = false;
if (rangeNumber < blocks.size()) { if (rangeNumber < blocks.size()) {
const BlockRange &range = blocks.at(rangeNumber); const BlockRange &range = blocks.at(rangeNumber);
if (block.position() >= range.first && ((block.position() + block.length() - 1) <= range.last || !range.last)) {
if (block.position() >= range.first && (block.position() <= range.last || !range.last)) {
set = TextEditDocumentLayout::setIfdefedOut(block); set = TextEditDocumentLayout::setIfdefedOut(block);
} else { } else {
cleared = TextEditDocumentLayout::clearIfdefedOut(block); cleared = TextEditDocumentLayout::clearIfdefedOut(block);

View File

@@ -298,6 +298,8 @@ QColor FormatDescription::background() const
return QColor(220, 220, 220); return QColor(220, 220, 220);
} else if (m_name == QLatin1String(Constants::C_OCCURRENCES_RENAME)) { } else if (m_name == QLatin1String(Constants::C_OCCURRENCES_RENAME)) {
return QColor(255, 200, 200); return QColor(255, 200, 200);
} else if (m_name == QLatin1String(Constants::C_DISABLED_CODE)) {
return QColor(239, 239, 239);
} }
return QColor(); // invalid color return QColor(); // invalid color
} }

View File

@@ -93,7 +93,7 @@ TextEditorSettings::TextEditorSettings(QObject *parent)
formatDescriptions.append(FormatDescription(QLatin1String(C_DOXYGEN_COMMENT), tr("Doxygen Comment"), Qt::darkBlue)); formatDescriptions.append(FormatDescription(QLatin1String(C_DOXYGEN_COMMENT), tr("Doxygen Comment"), Qt::darkBlue));
formatDescriptions.append(FormatDescription(QLatin1String(C_DOXYGEN_TAG), tr("Doxygen Tag"), Qt::blue)); formatDescriptions.append(FormatDescription(QLatin1String(C_DOXYGEN_TAG), tr("Doxygen Tag"), Qt::blue));
formatDescriptions.append(FormatDescription(QLatin1String(C_VISUAL_WHITESPACE), tr("Visual Whitespace"), Qt::lightGray)); formatDescriptions.append(FormatDescription(QLatin1String(C_VISUAL_WHITESPACE), tr("Visual Whitespace"), Qt::lightGray));
formatDescriptions.append(FormatDescription(QLatin1String(C_DISABLED_CODE), tr("Disabled Code"), Qt::gray)); formatDescriptions.append(FormatDescription(QLatin1String(C_DISABLED_CODE), tr("Disabled Code")));
// Diff categories // Diff categories
formatDescriptions.append(FormatDescription(QLatin1String(C_ADDED_LINE), tr("Added Line"), QColor(0, 170, 0))); formatDescriptions.append(FormatDescription(QLatin1String(C_ADDED_LINE), tr("Added Line"), QColor(0, 170, 0)));