Skip to content
Merged
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
13 changes: 11 additions & 2 deletions src/controls/tabbar.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2017 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -59,6 +59,10 @@ Tabbar::Tabbar(QWidget *parent)

installEventFilter(this);

#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
qApp->installEventFilter(this);
Comment on lines +62 to +63
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (performance): Installing an application-wide event filter on Tabbar may cause excessive event traffic and noisy logging.

With qApp->installEventFilter(this);, Tabbar now sees every application event in addition to its own (you already call installEventFilter(this);). Combined with qDebug() << "Enter eventFilter";, this will produce very noisy logs and extra overhead. Please either narrow the event filter to specific objects or remove/guard this generic debug log for Qt 6 builds.

Suggested implementation:

#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) && defined(QT_DEBUG)
    // In Qt 6, only install an application-wide event filter in debug builds
    // to avoid excessive event traffic and noisy logging in production.
    qApp->installEventFilter(this);
#endif

To fully implement the review comment, you should also:

  1. Locate the eventFilter implementation in src/controls/tabbar.cpp (or its corresponding header/source).
  2. Wrap the generic logging line qDebug() << "Enter eventFilter"; with a debug-only guard, e.g.:
    #if defined(QT_DEBUG)
        qDebug() << "Enter eventFilter";
    #endif
    or remove it entirely if it is no longer useful.
    This will ensure that even in debug builds, the extra logging is controlled, and in release builds there is no unnecessary overhead or log noise.

#endif

setMovable(true);
setTabsClosable(true);
setVisibleAddButton(true);
Expand Down Expand Up @@ -606,7 +610,12 @@ void Tabbar::handleDragActionChanged(Qt::DropAction action)

bool Tabbar::eventFilter(QObject *, QEvent *event)
{
qDebug() << "Enter eventFilter";
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
if (event->type() == QEvent::ApplicationFontChange) {
setFont(qApp->font());
return false;
}
#endif
if (event->type() == QEvent::MouseButtonPress) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);

Expand Down
22 changes: 21 additions & 1 deletion src/widgets/bottombar.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2017 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -56,6 +56,10 @@ BottomBar::BottomBar(QWidget *parent)
DFontSizeManager::instance()->bind(m_scaleLabel, DFontSizeManager::T9);
DFontSizeManager::instance()->bind(m_progressLabel, DFontSizeManager::T9);

#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
qApp->installEventFilter(this);
#endif

initFormatMenu();

QHBoxLayout *layout = new QHBoxLayout(this);
Expand Down Expand Up @@ -281,6 +285,22 @@ DDropdownMenu *BottomBar::getHighlightMenu()
return m_pHighlightMenu;
}

bool BottomBar::eventFilter(QObject *watched, QEvent *event)
{
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
if (event->type() == QEvent::ApplicationFontChange) {
QFont font = qApp->font();
m_pPositionLabel->setFont(font);
m_pCharCountLabel->setFont(font);
m_pCursorStatus->setFont(font);
m_scaleLabel->setFont(font);
m_progressLabel->setFont(font);
return false;
}
#endif
return QWidget::eventFilter(watched, event);
}

void BottomBar::paintEvent(QPaintEvent *)
{
QPainter painter(this);
Expand Down
3 changes: 2 additions & 1 deletion src/widgets/bottombar.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2017 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -53,6 +53,7 @@ class BottomBar : public QWidget

protected:
void paintEvent(QPaintEvent *);
bool eventFilter(QObject *, QEvent *) override;

private:
void initFormatMenu();
Expand Down
10 changes: 6 additions & 4 deletions src/widgets/ddropdownmenu.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2017 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -494,8 +494,11 @@ void DDropdownMenu::OnFontChangedSlot(const QFont &font)
{
qDebug() << "DDropdownMenu OnFontChangedSlot";
m_font = font;
int fontsize =DFontSizeManager::instance()->fontPixelSize(DFontSizeManager::T8);
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
int fontsize = DFontSizeManager::instance()->fontPixelSize(DFontSizeManager::T8);
m_font.setPixelSize(fontsize);
#endif
m_pToolButton->setFont(m_font);
m_pToolButton->setIcon(createIcon());
qDebug() << "DDropdownMenu OnFontChangedSlot end";
}
Expand All @@ -508,8 +511,7 @@ bool DDropdownMenu::eventFilter(QObject *object, QEvent *event)
// 处理字体变化
QFont font = qApp->font(); // 获取当前应用程序字体
OnFontChangedSlot(font); // 调用槽函数更新字体
qDebug() << "DDropdownMenu eventFilter ApplicationFontChange, return true";
return true;
return false;
}
#endif

Expand Down
Loading