Selection with alpha transparency
Daniel
xracoonx at gmx.de
Tue Aug 4 20:19:59 UTC 2020
Qt supports color alpha transparency. This can be used, for example, for
semi-transparent selection boxes as is used in Libre and MS Office. The
attached patch is only a very rough attempt. The screen captures show
contrast the result.
The alpha transparency is applied only when "Use system colors" is
enabled in Preferences > Color. This leaves it still possible for people
to set their own selection color.
One still unresolved bug of the patch is, for example, that in certain
situations certain elements, like pictures and insets start blinking
together with the caret. Is the re-painting of certain elements when the
caret blinks is on purpose?
Daniel
-------------- next part --------------
diff --git a/src/MetricsInfo.cpp b/src/MetricsInfo.cpp
index e7de5d0ea5..77abf30a01 100644
--- a/src/MetricsInfo.cpp
+++ b/src/MetricsInfo.cpp
@@ -153,7 +153,7 @@ void PainterInfo::draw(int x, int y, docstring const & str)
ColorCode PainterInfo::backgroundColor(Inset const * inset, bool sel) const
{
- if (selected && sel)
+ if (selected && sel && !lyxrc.use_system_colors)
// This inset is in a selection
return Color_selection;
diff --git a/src/RowPainter.cpp b/src/RowPainter.cpp
index 6e4cf31ac1..9d55b38cb9 100644
--- a/src/RowPainter.cpp
+++ b/src/RowPainter.cpp
@@ -69,8 +69,9 @@ FontInfo RowPainter::labelFont(bool end) const
{
FontInfo f = text_.labelFont(par_);
// selected text?
- if ((end ? row_.end_margin_sel : row_.begin_margin_sel)
- || pi_.selected)
+ if (!lyxrc.use_system_colors && (
+ (end ? row_.end_margin_sel : row_.begin_margin_sel)
+ || pi_.selected))
f.setPaintColor(Color_selectiontext);
return f;
}
@@ -250,13 +251,13 @@ void RowPainter::paintStringAndSel(Row::Element const & e) const
bool const all_sel = (e.pos >= row_.sel_beg && e.endpos < row_.sel_end)
|| pi_.selected;
- if (all_sel || e.change.changed()) {
+ if (!lyxrc.use_system_colors && (all_sel || e.change.changed())) {
Font copy = e.font;
Color const col = e.change.changed() ? e.change.color()
: Color_selectiontext;
copy.fontInfo().setPaintColor(col);
pi_.pain.text(int(x_), yo_, e.str, copy, e.extra, e.full_width());
- } else if (!some_sel) {
+ } else if (lyxrc.use_system_colors || !some_sel) {
pi_.pain.text(int(x_), yo_, e.str, e.font, e.extra, e.full_width());
} else {
pi_.pain.text(int(x_), yo_, e.str, e.font, Color_selectiontext,
@@ -273,7 +274,7 @@ void RowPainter::paintTextDecoration(Row::Element const & e) const
bool const sel = (e.pos >= row_.sel_beg && e.endpos <= row_.sel_end)
|| pi_.selected;
FontInfo copy = e.font.fontInfo();
- if (sel || e.change.changed()) {
+ if (!lyxrc.use_system_colors && (sel || e.change.changed())) {
Color const col = e.change.changed() ? e.change.color()
: Color_selectiontext;
copy.setPaintColor(col);
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index 88ea65541f..4dfd7163d6 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -1953,7 +1953,8 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
bool tmp = pi.full_repaint;
pi.full_repaint = true;
- rp.paintSelection();
+ if (!lyxrc.use_system_colors)
+ rp.paintSelection();
rp.paintAppendix();
rp.paintDepthBar();
if (row.needsChangeBar())
@@ -1965,6 +1966,8 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
rp.paintText();
rp.paintTooLargeMarks(row_x + row.left_x() < 0,
row_x + row.right_x() > bv_->workWidth());
+ if (lyxrc.use_system_colors)
+ rp.paintSelection();
y += row.descent();
#if 0
diff --git a/src/frontends/qt/ColorCache.cpp b/src/frontends/qt/ColorCache.cpp
index 6036099e47..7e4523a8eb 100644
--- a/src/frontends/qt/ColorCache.cpp
+++ b/src/frontends/qt/ColorCache.cpp
@@ -86,6 +86,11 @@ QColor ColorCache::get(Color const & color, bool syscolors) const
QColor const c = pal_.brush(QPalette::Active, cr).color();
if (cr == QPalette::Base && c == white)
return lcolors_[color.baseColor];
+ else if (cr == QPalette::Highlight) {
+ QColor c2 = c;
+ c2.setAlpha(128);
+ return c2;
+ }
else
return c;
} else
-------------- next part --------------
A non-text attachment was scrubbed...
Name: classic_selection.png
Type: image/png
Size: 107012 bytes
Desc: not available
URL: <http://lists.lyx.org/pipermail/lyx-devel/attachments/20200804/31e24efa/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: alpha_transparency_selection.png
Type: image/png
Size: 104782 bytes
Desc: not available
URL: <http://lists.lyx.org/pipermail/lyx-devel/attachments/20200804/31e24efa/attachment-0003.png>
More information about the lyx-devel
mailing list