Skip to content

Commit

Permalink
chore: add left/right padding to the main window
Browse files Browse the repository at this point in the history
add left/right padding to the main window, or it looks like the
term content is cut.
  • Loading branch information
hualet authored and ArchieMeng committed Dec 7, 2024
1 parent 3fabbe4 commit 68b51ce
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
11 changes: 11 additions & 0 deletions 3rdparty/terminalwidget/lib/qtermwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions 3rdparty/terminalwidget/lib/qtermwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down
21 changes: 16 additions & 5 deletions src/views/termwidgetpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "windowsmanager.h"
#include "mainwindow.h"
#include "define.h"
#include "ColorScheme.h"

#include <DLog>
#include <DDialog>
Expand Down Expand Up @@ -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);

Expand All @@ -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)
Expand Down Expand Up @@ -453,11 +457,17 @@ void TermWidgetPage::setTerminalOpacity(qreal opacity)
term->setTermOpacity(opacity);
}

void TermWidgetPage::setColorScheme(const QString &name)
void TermWidgetPage::updateBackgroundColor()
{
QList<TermWidget *> termList = findChildren<TermWidget *>();
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)
Expand Down Expand Up @@ -709,6 +719,7 @@ void TermWidgetPage::handleUpdateSearchKeyword(const QString &keyword)
void TermWidgetPage::applyTheme()
{
updateSplitStyle();
updateBackgroundColor();
}

void TermWidgetPage::updateSplitStyle()
Expand Down
9 changes: 3 additions & 6 deletions src/views/termwidgetpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 发送文本到当前终端
Expand Down

0 comments on commit 68b51ce

Please sign in to comment.