forked from qt-creator/qt-creator
final drop shadow tuning
This commit is contained in:
@@ -2884,6 +2884,10 @@ void BaseTextEditor::slotUpdateRequest(const QRect &r, int dy)
|
|||||||
d->m_extraArea->scroll(0, dy);
|
d->m_extraArea->scroll(0, dy);
|
||||||
else if (r.width() > 4) { // wider than cursor width, not just cursor blinking
|
else if (r.width() > 4) { // wider than cursor width, not just cursor blinking
|
||||||
d->m_extraArea->update(0, r.y(), d->m_extraArea->width(), r.height());
|
d->m_extraArea->update(0, r.y(), d->m_extraArea->width(), r.height());
|
||||||
|
if (!d->m_searchExpr.isEmpty()) {
|
||||||
|
const int m = d->m_searchResultOverlay->dropShadowWidth();
|
||||||
|
viewport()->update(r.adjusted(-m, -m, m, m));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r.contains(viewport()->rect()))
|
if (r.contains(viewport()->rect()))
|
||||||
|
@@ -40,6 +40,7 @@ TextEditorOverlay::TextEditorOverlay(BaseTextEditor *editor)
|
|||||||
:QObject(editor) {
|
:QObject(editor) {
|
||||||
m_visible = false;
|
m_visible = false;
|
||||||
m_borderWidth = 1;
|
m_borderWidth = 1;
|
||||||
|
m_dropShadowWidth = 2;
|
||||||
m_editor = editor;
|
m_editor = editor;
|
||||||
m_viewport = editor->viewport();
|
m_viewport = editor->viewport();
|
||||||
}
|
}
|
||||||
@@ -328,9 +329,9 @@ void TextEditorOverlay::fillSelection(QPainter *painter,
|
|||||||
painter->translate(-.5, -.5);
|
painter->translate(-.5, -.5);
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
if (selection.m_dropShadow) {
|
if (selection.m_dropShadow) {
|
||||||
painter->translate(2, 2);
|
painter->translate(m_dropShadowWidth, m_dropShadowWidth);
|
||||||
painter->fillPath(path, QColor(0, 0, 0, 100));
|
painter->fillPath(path, QColor(0, 0, 0, 100));
|
||||||
painter->translate(-2, -2);
|
painter->translate(-m_dropShadowWidth, -m_dropShadowWidth);
|
||||||
}
|
}
|
||||||
painter->fillPath(path, color);
|
painter->fillPath(path, color);
|
||||||
painter->restore();
|
painter->restore();
|
||||||
@@ -364,65 +365,3 @@ void TextEditorOverlay::fill(QPainter *painter, const QColor &color, const QRect
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorOverlay::paintInverted(QPainter *painter, const QRect &clip, const QColor &color)
|
|
||||||
{
|
|
||||||
QPainterPath path;
|
|
||||||
for (int i = 0; i < m_selections.size(); ++i) {
|
|
||||||
const OverlaySelection &selection = m_selections.at(i);
|
|
||||||
if (selection.m_fixedLength >= 0
|
|
||||||
&& selection.m_cursor_end.position() - selection.m_cursor_begin.position()
|
|
||||||
!= selection.m_fixedLength)
|
|
||||||
continue;
|
|
||||||
path.addPath(createSelectionPath(selection.m_cursor_begin, selection.m_cursor_end, clip));
|
|
||||||
}
|
|
||||||
|
|
||||||
QRect viewportRect = m_editor->viewport()->rect();
|
|
||||||
QColor background = Qt::black;
|
|
||||||
background.setAlpha(30);
|
|
||||||
|
|
||||||
if (path.isEmpty()) {
|
|
||||||
painter->fillRect(viewportRect, background);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// QPainterPath all;
|
|
||||||
// all.addRect(viewportRect);
|
|
||||||
// QPainterPath inversion = all.subtracted(path);
|
|
||||||
|
|
||||||
painter->save();
|
|
||||||
QColor penColor = color;
|
|
||||||
penColor.setAlpha(220);
|
|
||||||
QPen pen(penColor, m_borderWidth);
|
|
||||||
QColor brush = color;
|
|
||||||
brush.setAlpha(30);
|
|
||||||
painter->translate(-.5, -.5);
|
|
||||||
|
|
||||||
// painter->setRenderHint(QPainter::Antialiasing);
|
|
||||||
//pen.setJoinStyle(Qt::RoundJoin);
|
|
||||||
painter->setPen(pen);
|
|
||||||
painter->setBrush(QBrush());
|
|
||||||
painter->drawPath(path);
|
|
||||||
|
|
||||||
painter->translate(.5, .5);
|
|
||||||
|
|
||||||
QPixmap shadow(clip.size());
|
|
||||||
shadow.fill(background);
|
|
||||||
QPainter pmp(&shadow);
|
|
||||||
pmp.translate(-.5, -.5);
|
|
||||||
pmp.setRenderHint(QPainter::Antialiasing);
|
|
||||||
pmp.setCompositionMode(QPainter::CompositionMode_Source);
|
|
||||||
path.translate(-clip.topLeft());
|
|
||||||
pen.setColor(Qt::transparent);
|
|
||||||
pmp.setPen(pen);
|
|
||||||
pmp.setBrush(Qt::transparent);
|
|
||||||
pmp.drawPath(path);
|
|
||||||
pmp.end();
|
|
||||||
|
|
||||||
painter->drawPixmap(clip.topLeft(), shadow);
|
|
||||||
|
|
||||||
// painter->fillPath(inversion, background);
|
|
||||||
painter->restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -58,6 +58,7 @@ private:
|
|||||||
|
|
||||||
bool m_visible;
|
bool m_visible;
|
||||||
int m_borderWidth;
|
int m_borderWidth;
|
||||||
|
int m_dropShadowWidth;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TextEditorOverlay(BaseTextEditor *editor);
|
TextEditorOverlay(BaseTextEditor *editor);
|
||||||
@@ -66,8 +67,6 @@ public:
|
|||||||
void paint(QPainter *painter, const QRect &clip);
|
void paint(QPainter *painter, const QRect &clip);
|
||||||
void fill(QPainter *painter, const QColor &color, const QRect &clip);
|
void fill(QPainter *painter, const QColor &color, const QRect &clip);
|
||||||
|
|
||||||
void paintInverted(QPainter *painter, const QRect &clip, const QColor &color);
|
|
||||||
|
|
||||||
bool isVisible() const { return m_visible; }
|
bool isVisible() const { return m_visible; }
|
||||||
void setVisible(bool b);
|
void setVisible(bool b);
|
||||||
|
|
||||||
@@ -81,6 +80,8 @@ public:
|
|||||||
|
|
||||||
inline bool isEmpty() const { return m_selections.isEmpty(); }
|
inline bool isEmpty() const { return m_selections.isEmpty(); }
|
||||||
|
|
||||||
|
inline int dropShadowWidth() const { return m_dropShadowWidth; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPainterPath createSelectionPath(const QTextCursor &begin, const QTextCursor &end, const QRect& clip);
|
QPainterPath createSelectionPath(const QTextCursor &begin, const QTextCursor &end, const QRect& clip);
|
||||||
void paintSelection(QPainter *painter, const OverlaySelection &selection);
|
void paintSelection(QPainter *painter, const OverlaySelection &selection);
|
||||||
|
Reference in New Issue
Block a user