From 8ef31807ded337b5543979c67d4b1c3bf0ff4fa5 Mon Sep 17 00:00:00 2001 From: reionwong Date: Thu, 2 Sep 2021 00:29:32 +0800 Subject: [PATCH] Support blur --- qmltermwidget/lib/TerminalDisplay.cpp | 37 ++++++++++++++++++++++++--- qmltermwidget/lib/TerminalDisplay.h | 8 ++++++ src/qml/GlobalSettings.qml | 3 +++ src/qml/Terminal.qml | 8 +++++- src/qml/main.qml | 16 +++++++++--- 5 files changed, 63 insertions(+), 9 deletions(-) diff --git a/qmltermwidget/lib/TerminalDisplay.cpp b/qmltermwidget/lib/TerminalDisplay.cpp index af91ab1..09b289e 100644 --- a/qmltermwidget/lib/TerminalDisplay.cpp +++ b/qmltermwidget/lib/TerminalDisplay.cpp @@ -336,6 +336,7 @@ TerminalDisplay::TerminalDisplay(QQuickItem *parent) , m_font("Monospace", 12) , m_colorRole(QPalette::Background) , m_full_cursor_height(false) + , m_backgroundOpacity(1.0) { // terminal applications are not designed with Right-To-Left in mind, // so the layout is forced to Left-To-Right @@ -2843,11 +2844,37 @@ bool TerminalDisplay::handleShortcutOverrideEvent(QKeyEvent* keyEvent) return false; } +qreal TerminalDisplay::backgroundOpacity() const +{ + return m_backgroundOpacity; +} + +void TerminalDisplay::setBackgroundOpacity(const qreal &backgroundOpacity) +{ + if (m_backgroundOpacity != backgroundOpacity) { + m_backgroundOpacity = backgroundOpacity; + + const ColorScheme *cs; + if (!availableColorSchemes().contains(_colorScheme)) + cs = ColorSchemeManager::instance()->defaultColorScheme(); + else + cs = ColorSchemeManager::instance()->findColorScheme(_colorScheme); + + if (cs) { + QColor color = cs->backgroundColor(); + color.setAlphaF(m_backgroundOpacity); + setFillColor(color); + } + + emit backgroundOpacityChanged(); + } +} + bool TerminalDisplay::event(QEvent* event) { - bool eventHandled = false; - switch (event->type()) - { + bool eventHandled = false; + switch (event->type()) + { case QEvent::ShortcutOverride: eventHandled = handleShortcutOverrideEvent((QKeyEvent*)event); break; @@ -3259,7 +3286,9 @@ void TerminalDisplay::setColorScheme(const QString &name) cs->getColorTable(table); setColorTable(table); - setFillColor(cs->backgroundColor()); + QColor bgColor = cs->backgroundColor(); + bgColor.setAlphaF(m_backgroundOpacity); + setFillColor(bgColor); _colorScheme = name; emit colorSchemeChanged(); } diff --git a/qmltermwidget/lib/TerminalDisplay.h b/qmltermwidget/lib/TerminalDisplay.h index 013e874..f084468 100644 --- a/qmltermwidget/lib/TerminalDisplay.h +++ b/qmltermwidget/lib/TerminalDisplay.h @@ -97,6 +97,8 @@ class TerminalDisplay : public QQuickPaintedItem Q_PROPERTY(bool selectedText READ selectedText CONSTANT) + Q_PROPERTY(qreal backgroundOpacity READ backgroundOpacity WRITE setBackgroundOpacity NOTIFY backgroundOpacityChanged) + public: /** Constructs a new terminal display widget with the specified parent. */ explicit TerminalDisplay(QQuickItem *parent = nullptr); @@ -120,6 +122,9 @@ public: /** Sets the opacity of the terminal display. */ void setOpacity(qreal opacity); + qreal backgroundOpacity() const; + void setBackgroundOpacity(const qreal &backgroundOpacity); + /** * This enum describes the location where the scroll bar is positioned in the display widget. */ @@ -553,6 +558,7 @@ public slots: void simulateMouseDoubleClick(int x, int y, int button, int buttons, int modifiers); signals: + void backgroundOpacityChanged(); /** * Emitted when the user presses a key whilst the terminal widget has focus. @@ -888,6 +894,8 @@ private: KSession *m_session; bool m_full_cursor_height; + qreal m_backgroundOpacity; + QFont font() const { return m_font; } const QPalette palette() { return m_palette; } diff --git a/src/qml/GlobalSettings.qml b/src/qml/GlobalSettings.qml index 63f5759..83bb9f9 100644 --- a/src/qml/GlobalSettings.qml +++ b/src/qml/GlobalSettings.qml @@ -25,4 +25,7 @@ Settings { property int height: 500 property int fontPointSize: 10 property bool blinkingCursor: true + + property real opacity: 0.8 + property bool blur: true } diff --git a/src/qml/Terminal.qml b/src/qml/Terminal.qml index f3264e6..6ad20e6 100644 --- a/src/qml/Terminal.qml +++ b/src/qml/Terminal.qml @@ -33,7 +33,12 @@ Page { focus: true // Drop effect - opacity: _dropArea.containsDrag ? 0.8 : 1 + // opacity: _dropArea.containsDrag ? 0.8 : 1 +// opacity: 0.5 + + background: Rectangle { + color: "transparent" + } signal urlsDropped(var urls) signal keyPressed(var event) @@ -106,6 +111,7 @@ Page { font.pointSize: settings.fontPointSize blinkingCursor: settings.blinkingCursor fullCursorHeight: true + backgroundOpacity: 0 Keys.enabled: true Keys.onPressed: control.keyPressed(event) diff --git a/src/qml/main.qml b/src/qml/main.qml index abfe30e..13e938c 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -34,7 +34,8 @@ FishUI.Window { height: settings.height title: currentItem && currentItem.terminal ? currentItem.terminal.session.title : "" - background.color: FishUI.Theme.secondBackgroundColor + background.color: FishUI.Theme.backgroundColor + background.opacity: settings.opacity header.height: 45 property int currentIndex: -1 @@ -49,6 +50,13 @@ FishUI.Window { onOkBtnClicked: Qt.quit() } + FishUI.WindowBlur { + view: root + geometry: Qt.rect(root.x, root.y, root.width, root.height) + windowRadius: root.background.radius + enabled: settings.blur + } + onClosing: { if (!root.isMaximized) { settings.width = root.width @@ -92,7 +100,7 @@ FishUI.Window { highlight: Rectangle { color: FishUI.Theme.highlightColor - opacity: FishUI.Theme.darkMode ? 0.2 : 0.1 + opacity: 1 border.width: 0 radius: FishUI.Theme.smallRadius } @@ -136,7 +144,7 @@ FishUI.Window { elide: Label.ElideRight font.pointSize: 9 font.family: "Noto Sans Mono" - color: isCurrent ? FishUI.Theme.highlightColor : FishUI.Theme.textColor + color: isCurrent ? FishUI.Theme.highlightedTextColor : FishUI.Theme.textColor } Item { @@ -147,7 +155,7 @@ FishUI.Window { Layout.preferredHeight: 24 Layout.preferredWidth: 24 size: 24 - source: "qrc:/images/" + (FishUI.Theme.darkMode ? "dark/" : "light/") + "close.svg" + source: "qrc:/images/" + (FishUI.Theme.darkMode || isCurrent ? "dark/" : "light/") + "close.svg" onClicked: closeTab(index) } }