[plasma-mobile/qmlkonsole/release/26.08] /: Properly implement setting background opacity
Devin Lin <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 8de80665ff2a99c77aa682a2b8ee34fc6d503725 by Devin Lin.
Committed on 19/07/2026 at 17:59.
Pushed by devinlin into branch 'release/26.08'.
Properly implement setting background opacity
Currently the opacity setting sets the entire terminal opacity, including the foreground text. Fix it so that it only sets the background color opacity.
M +17 -6 lib/TerminalDisplay.cpp
M +6 -5 lib/TerminalDisplay.h
M +1 -1 src/contents/ui/TerminalPage.qml
https://invent.kde.org/plasma-mobile/qmlkonsole/-/commit/8de80665ff2a99c77aa682a2b8ee34fc6d503725
diff --git a/lib/TerminalDisplay.cpp b/lib/TerminalDisplay.cpp
index bc5f260..b9768bf 100644
--- a/lib/TerminalDisplay.cpp
+++ b/lib/TerminalDisplay.cpp
@@ -298,7 +298,7 @@ TerminalDisplay::TerminalDisplay(QQuickItem *parent)
, _outputSuspendedLabel(nullptr)
, _lineSpacing(0)
, _colorsInverted(false)
- , _opacity(static_cast<qreal>(1))
+ , _backgroundOpacity(static_cast<qreal>(1))
, _filterChain(std::make_unique<TerminalImageFilterChain>())
, _cursorShape(Emulation::KeyboardCursorShape::BlockCursor)
, mMotionAfterPasting(NoMoveScreenWindow)
@@ -362,6 +362,7 @@ TerminalDisplay::TerminalDisplay(QQuickItem *parent)
// TODO Forcing rendering to Framebuffer. We need to determine if this is ok
// always or if we need to make this customizable.
setRenderTarget(QQuickPaintedItem::FramebufferObject);
+ setFillColor(Qt::transparent);
// setFocusPolicy( Qt::WheelFocus );
@@ -641,10 +642,21 @@ QColor TerminalDisplay::keyboardCursorColor() const
return _cursorColor;
}
-void TerminalDisplay::setOpacity(qreal opacity)
+qreal TerminalDisplay::backgroundOpacity() const
{
- _opacity = qBound(static_cast<qreal>(0), opacity, static_cast<qreal>(1));
+ return _backgroundOpacity;
+}
+
+void TerminalDisplay::setBackgroundOpacity(qreal opacity)
+{
+ const qreal boundedOpacity = qBound(static_cast<qreal>(0), opacity, static_cast<qreal>(1));
+ if (qFuzzyCompare(_backgroundOpacity, boundedOpacity)) {
+ return;
+ }
+
+ _backgroundOpacity = boundedOpacity;
update();
+ Q_EMIT backgroundOpacityChanged();
}
void TerminalDisplay::drawBackground(QPainter &painter, const QRect &rect, const QColor &backgroundColor, bool useOpacitySetting)
@@ -654,7 +666,7 @@ void TerminalDisplay::drawBackground(QPainter &painter, const QRect &rect, const
// left to the widget style for a consistent look.
if (useOpacitySetting) {
QColor color(backgroundColor);
- color.setAlphaF(_opacity);
+ color.setAlphaF(color.alphaF() * _backgroundOpacity);
painter.save();
painter.setCompositionMode(QPainter::CompositionMode_Source);
@@ -1367,7 +1379,7 @@ QRect TerminalDisplay::calculateTextArea(int topLeftX, int topLeftY, int startCo
void TerminalDisplay::drawContents(QPainter &paint, const QRect &rect)
{
- // Draw opaque background
+ // Draw background
drawBackground(paint, contentsRect(), _colorTable[DEFAULT_BACK_COLOR].color, true);
QPoint tL = contentsRect().topLeft();
@@ -2978,7 +2990,6 @@ void TerminalDisplay::setColorScheme(const QString &name)
setColorTable(cs->getColorTable());
- setFillColor(cs->backgroundColor());
_colorScheme = name;
Q_EMIT colorSchemeChanged();
}
diff --git a/lib/TerminalDisplay.h b/lib/TerminalDisplay.h
index 721272a..8448d9c 100644
--- a/lib/TerminalDisplay.h
+++ b/lib/TerminalDisplay.h
@@ -108,7 +108,7 @@ class KONSOLEPRIVATE_EXPORT TerminalDisplay : public QQuickPaintedItem
Q_PROPERTY(bool blinkingCursor READ blinkingCursor WRITE setBlinkingCursor NOTIFY blinkingCursorStateChanged)
Q_PROPERTY(bool antialiasText READ antialias WRITE setAntialias)
Q_PROPERTY(QStringList availableColorSchemes READ availableColorSchemes NOTIFY availableColorSchemesChanged)
- Q_PROPERTY(qreal backgroundOpacity READ opacity WRITE setOpacity NOTIFY opacityChanged)
+ Q_PROPERTY(qreal backgroundOpacity READ backgroundOpacity WRITE setBackgroundOpacity NOTIFY backgroundOpacityChanged)
public:
/** Constructs a new terminal display widget with the specified parent. */
@@ -133,8 +133,8 @@ public:
*/
uint randomSeed() const;
- /** Sets the opacity of the terminal display. */
- void setOpacity(qreal opacity);
+ qreal backgroundOpacity() const;
+ void setBackgroundOpacity(qreal opacity);
/**
* This enum describes the location where the scroll bar is positioned in the display widget.
@@ -698,6 +698,7 @@ Q_SIGNALS:
void fullCursorHeightChanged();
void blinkingCursorStateChanged();
void boldIntenseChanged();
+ void backgroundOpacityChanged();
protected:
bool event(QEvent *) override;
@@ -794,7 +795,7 @@ private:
void drawTextFragment(QPainter &painter, const QRect &rect, const QString &text, const Character *style);
// draws the background for a text fragment
// if useOpacitySetting is true then the color's alpha value will be set to
- // the display's transparency (set with setOpacity()), otherwise the background
+ // the display's transparency (set with setBackgroundOpacity()), otherwise the background
// will be drawn fully opaque
void drawBackground(QPainter &painter, const QRect &rect, const QColor &color, bool useOpacitySetting);
// draws the cursor character
@@ -944,7 +945,7 @@ private:
QSize _size;
- qreal _opacity;
+ qreal _backgroundOpacity;
// list of filters currently applied to the display. used for links and
// search highlight
diff --git a/src/contents/ui/TerminalPage.qml b/src/contents/ui/TerminalPage.qml
index 502b171..0e3dd2f 100644
--- a/src/contents/ui/TerminalPage.qml
+++ b/src/contents/ui/TerminalPage.qml
@@ -468,7 +468,7 @@ Kirigami.Page {
font.pixelSize: TerminalSettings.fontSize
colorScheme: TerminalSettings.colorScheme
- opacity: TerminalSettings.windowOpacity
+ backgroundOpacity: TerminalSettings.windowOpacity
Component.onCompleted: {
if (!root.initialSessionCreated) {