Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add left/right padding to the main window #360

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -8,12 +8,13 @@
#include "settings.h"
#include "utils.h"
#include "service.h"
#include "windowsmanager.h"

Check warning on line 11 in src/views/termwidgetpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "windowsmanager.h" not found.

Check warning on line 11 in src/views/termwidgetpage.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "windowsmanager.h" not found.
#include "mainwindow.h"

Check warning on line 12 in src/views/termwidgetpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "mainwindow.h" not found.

Check warning on line 12 in src/views/termwidgetpage.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "mainwindow.h" not found.
#include "define.h"

Check warning on line 13 in src/views/termwidgetpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "define.h" not found.

Check warning on line 13 in src/views/termwidgetpage.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "define.h" not found.
#include "ColorScheme.h"

Check warning on line 14 in src/views/termwidgetpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "ColorScheme.h" not found.

Check warning on line 14 in src/views/termwidgetpage.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "ColorScheme.h" not found.

#include <DLog>

Check warning on line 16 in src/views/termwidgetpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DLog> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 16 in src/views/termwidgetpage.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <DLog> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DDialog>

Check warning on line 17 in src/views/termwidgetpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DDialog> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 17 in src/views/termwidgetpage.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <DDialog> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DPaletteHelper>

#include <QVBoxLayout>
Expand Down Expand Up @@ -58,7 +59,9 @@
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 @@
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 @@
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::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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

得用这个替换setColorScheme才能实现是吗?


/**
* @brief 发送文本到当前终端
Expand Down
Loading