From 68b51ce0ac321716a6942260ada713dcb309cbba Mon Sep 17 00:00:00 2001 From: Hualet Wang Date: Fri, 20 Sep 2024 14:59:32 +0800 Subject: [PATCH] chore: add left/right padding to the main window add left/right padding to the main window, or it looks like the term content is cut. --- 3rdparty/terminalwidget/lib/qtermwidget.cpp | 11 +++++++++++ 3rdparty/terminalwidget/lib/qtermwidget.h | 3 +++ src/views/termwidgetpage.cpp | 21 ++++++++++++++++----- src/views/termwidgetpage.h | 9 +++------ 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/3rdparty/terminalwidget/lib/qtermwidget.cpp b/3rdparty/terminalwidget/lib/qtermwidget.cpp index 4542ce0b6..a364b36f3 100644 --- a/3rdparty/terminalwidget/lib/qtermwidget.cpp +++ b/3rdparty/terminalwidget/lib/qtermwidget.cpp @@ -621,6 +621,17 @@ void QTermWidget::setTerminalWordCharacters(const QString &wc) m_impl->m_terminalDisplay->setWordCharacters(wc); } +const QColor QTermWidget::backgroundColor() const +{ + const ColorEntry *table = m_impl->m_terminalDisplay->colorTable(); + if (!table) { + qWarning() << "get terminal widget background color failed"; + return QColor(); // Return a default color if the table is null + } + const QColor &background_color = table[DEFAULT_BACK_COLOR].color; + return background_color.isValid() ? background_color : QColor(); // Return a default color if the background color is invalid +} + /******************************************************************************* 1. @函数: setColorScheme 2. @作者: ut000125 sunchengxi diff --git a/3rdparty/terminalwidget/lib/qtermwidget.h b/3rdparty/terminalwidget/lib/qtermwidget.h index 1123a9fed..d1832fd9d 100644 --- a/3rdparty/terminalwidget/lib/qtermwidget.h +++ b/3rdparty/terminalwidget/lib/qtermwidget.h @@ -100,6 +100,7 @@ class TERMINALWIDGET_EXPORT QTermWidget : public QWidget // Beware of a performance penalty and display/alignment issues when using a proportional font. void setTerminalFont(const QFont &font); QFont getTerminalFont(); + void setTerminalOpacity(qreal level); void setTerminalBackgroundImage(QString backgroundImage); @@ -121,6 +122,8 @@ class TERMINALWIDGET_EXPORT QTermWidget : public QWidget void setTerminalWordCharacters(const QString &wc); + const QColor backgroundColor() const; + /** @brief Sets the color scheme, default is white on black * * @param[in] name The name of the color scheme, either returned from diff --git a/src/views/termwidgetpage.cpp b/src/views/termwidgetpage.cpp index 5363a2c69..0ded50725 100644 --- a/src/views/termwidgetpage.cpp +++ b/src/views/termwidgetpage.cpp @@ -11,6 +11,7 @@ #include "windowsmanager.h" #include "mainwindow.h" #include "define.h" +#include "ColorScheme.h" #include #include @@ -58,7 +59,9 @@ TermWidgetPage::TermWidgetPage(const TermProperties &properties, QWidget *parent m_layout = new QVBoxLayout(this); m_layout->setObjectName("TermPageLayout");//Add by ut001000 renfeixiang 2020-08-13 m_layout->setSpacing(0); - m_layout->setContentsMargins(0, 0, 0, 0); + m_layout->setMargin(0); + // FIXME(hualet): m_MainWindow->windowRadius() returns 0, so we use 8 as default. + m_layout->setContentsMargins(8, 0, 8, 0); m_layout->addWidget(w); setLayout(m_layout); @@ -79,6 +82,7 @@ TermWidgetPage::TermWidgetPage(const TermProperties &properties, QWidget *parent m_findBar->move(width() - m_findBar->width(), 0); }, Qt::QueuedConnection); #endif + updateBackgroundColor(); } inline void TermWidgetPage::handleKeywordChanged(const QString &keyword) @@ -453,11 +457,17 @@ void TermWidgetPage::setTerminalOpacity(qreal opacity) term->setTermOpacity(opacity); } -void TermWidgetPage::setColorScheme(const QString &name) +void TermWidgetPage::updateBackgroundColor() { - QList termList = findChildren(); - for (TermWidget *term : termList) - term->setColorScheme(name); + if (currentTerminal()) { + QColor color = currentTerminal()->backgroundColor(); + color.setAlphaF(Settings::instance()->opacity()); + + QPalette palette = this->palette(); + palette.setColor(QPalette::Background, color); + this->setPalette(palette); + this->setAutoFillBackground(true); + } } void TermWidgetPage::sendTextToCurrentTerm(const QString &text, bool isRemoteConnect) @@ -709,6 +719,7 @@ void TermWidgetPage::handleUpdateSearchKeyword(const QString &keyword) void TermWidgetPage::applyTheme() { updateSplitStyle(); + updateBackgroundColor(); } void TermWidgetPage::updateSplitStyle() diff --git a/src/views/termwidgetpage.h b/src/views/termwidgetpage.h index 0a8ac9dc9..3fa88c9b6 100644 --- a/src/views/termwidgetpage.h +++ b/src/views/termwidgetpage.h @@ -159,12 +159,9 @@ class TermWidgetPage : public QWidget * @param opacity */ void setTerminalOpacity(qreal opacity); - /** - * @brief 设置主题 - * @author ut000439 wangpeili - * @param name - */ - void setColorScheme(const QString &name); + + + void updateBackgroundColor(); /** * @brief 发送文本到当前终端