Skip to content

Commit 68b51ce

Browse files
hualetArchieMeng
authored andcommitted
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.
1 parent 3fabbe4 commit 68b51ce

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

3rdparty/terminalwidget/lib/qtermwidget.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,17 @@ void QTermWidget::setTerminalWordCharacters(const QString &wc)
621621
m_impl->m_terminalDisplay->setWordCharacters(wc);
622622
}
623623

624+
const QColor QTermWidget::backgroundColor() const
625+
{
626+
const ColorEntry *table = m_impl->m_terminalDisplay->colorTable();
627+
if (!table) {
628+
qWarning() << "get terminal widget background color failed";
629+
return QColor(); // Return a default color if the table is null
630+
}
631+
const QColor &background_color = table[DEFAULT_BACK_COLOR].color;
632+
return background_color.isValid() ? background_color : QColor(); // Return a default color if the background color is invalid
633+
}
634+
624635
/*******************************************************************************
625636
1. @函数: setColorScheme
626637
2. @作者: ut000125 sunchengxi

3rdparty/terminalwidget/lib/qtermwidget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class TERMINALWIDGET_EXPORT QTermWidget : public QWidget
100100
// Beware of a performance penalty and display/alignment issues when using a proportional font.
101101
void setTerminalFont(const QFont &font);
102102
QFont getTerminalFont();
103+
103104
void setTerminalOpacity(qreal level);
104105
void setTerminalBackgroundImage(QString backgroundImage);
105106

@@ -121,6 +122,8 @@ class TERMINALWIDGET_EXPORT QTermWidget : public QWidget
121122

122123
void setTerminalWordCharacters(const QString &wc);
123124

125+
const QColor backgroundColor() const;
126+
124127
/** @brief Sets the color scheme, default is white on black
125128
*
126129
* @param[in] name The name of the color scheme, either returned from

src/views/termwidgetpage.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "windowsmanager.h"
1212
#include "mainwindow.h"
1313
#include "define.h"
14+
#include "ColorScheme.h"
1415

1516
#include <DLog>
1617
#include <DDialog>
@@ -58,7 +59,9 @@ TermWidgetPage::TermWidgetPage(const TermProperties &properties, QWidget *parent
5859
m_layout = new QVBoxLayout(this);
5960
m_layout->setObjectName("TermPageLayout");//Add by ut001000 renfeixiang 2020-08-13
6061
m_layout->setSpacing(0);
61-
m_layout->setContentsMargins(0, 0, 0, 0);
62+
m_layout->setMargin(0);
63+
// FIXME(hualet): m_MainWindow->windowRadius() returns 0, so we use 8 as default.
64+
m_layout->setContentsMargins(8, 0, 8, 0);
6265
m_layout->addWidget(w);
6366
setLayout(m_layout);
6467

@@ -79,6 +82,7 @@ TermWidgetPage::TermWidgetPage(const TermProperties &properties, QWidget *parent
7982
m_findBar->move(width() - m_findBar->width(), 0);
8083
}, Qt::QueuedConnection);
8184
#endif
85+
updateBackgroundColor();
8286
}
8387

8488
inline void TermWidgetPage::handleKeywordChanged(const QString &keyword)
@@ -453,11 +457,17 @@ void TermWidgetPage::setTerminalOpacity(qreal opacity)
453457
term->setTermOpacity(opacity);
454458
}
455459

456-
void TermWidgetPage::setColorScheme(const QString &name)
460+
void TermWidgetPage::updateBackgroundColor()
457461
{
458-
QList<TermWidget *> termList = findChildren<TermWidget *>();
459-
for (TermWidget *term : termList)
460-
term->setColorScheme(name);
462+
if (currentTerminal()) {
463+
QColor color = currentTerminal()->backgroundColor();
464+
color.setAlphaF(Settings::instance()->opacity());
465+
466+
QPalette palette = this->palette();
467+
palette.setColor(QPalette::Background, color);
468+
this->setPalette(palette);
469+
this->setAutoFillBackground(true);
470+
}
461471
}
462472

463473
void TermWidgetPage::sendTextToCurrentTerm(const QString &text, bool isRemoteConnect)
@@ -709,6 +719,7 @@ void TermWidgetPage::handleUpdateSearchKeyword(const QString &keyword)
709719
void TermWidgetPage::applyTheme()
710720
{
711721
updateSplitStyle();
722+
updateBackgroundColor();
712723
}
713724

714725
void TermWidgetPage::updateSplitStyle()

src/views/termwidgetpage.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,9 @@ class TermWidgetPage : public QWidget
159159
* @param opacity
160160
*/
161161
void setTerminalOpacity(qreal opacity);
162-
/**
163-
* @brief 设置主题
164-
* @author ut000439 wangpeili
165-
* @param name
166-
*/
167-
void setColorScheme(const QString &name);
162+
163+
164+
void updateBackgroundColor();
168165

169166
/**
170167
* @brief 发送文本到当前终端

0 commit comments

Comments
 (0)