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
44 changes: 30 additions & 14 deletions src/controls/tabbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,17 @@ void Tabbar::addTabWithIndex(int index, const QString &filePath, const QString &
// 除去空白符 梁卫东 2020-08-26 14:49:15 ;适配助记符
QString trimmedName = replaceMnemonic(tabName.simplified());
qDebug() << "trimmedName:" << trimmedName;

// Batch all layout-triggering operations to avoid jitter:
// 1. Disable visual updates
// 2. Insert tab (triggers QTabBar layout with old width → may overflow)
// 3. Force DTabBar layout to resize inner QTabBar to correct width
// 4. Force QTabBar to recalculate tab positions with correct width
// 5. Re-enable visual updates → single paint with final state
setUpdatesEnabled(false);
DTabBar::insertTab(index, trimmedName);
DTabBar::setCurrentIndex(index);

qDebug() << "filePath.contains(Utils::localDataPath())";
if (filePath.contains(Utils::localDataPath())) {
if (Utils::isBackupFile(filePath) && !tipPath.isNull() && tipPath.length() > 0) {
Expand Down Expand Up @@ -159,6 +168,16 @@ void Tabbar::addTabWithIndex(int index, const QString &filePath, const QString &
qDebug() << "path:" << path;
setTabToolTip(index, path);
}

// Force DTabBar's layout to resize inner QTabBar to its new sizeHint
layout()->activate();
// Force QTabBar internal layout recalculation with correct width
setIconSize(iconSize());
// activate() may trigger scroll button show/hide cascade which
// invalidates layout again; run a second time to settle completely
layout()->activate();

setUpdatesEnabled(true);
}

void Tabbar::resizeEvent(QResizeEvent *event)
Expand Down Expand Up @@ -826,23 +845,20 @@ QSize Tabbar::tabSizeHint(int index) const
qDebug() << "Enter tabSizeHint, index:" << index;
if (index >= 0) {
int total = this->width();
qDebug() << "total:" << total;
//计算每个tab平均宽度 返回 100到160
int aveargeWidth = 160;
aveargeWidth = total / DTabBar::count();
qDebug() << "aveargeWidth:" << aveargeWidth;
if (aveargeWidth >= 160) {
qDebug() << "aveargeWidth >= 160";
aveargeWidth = 160;
} else if (aveargeWidth <= 110) {
qDebug() << "aveargeWidth <= 110";
aveargeWidth = 110;
// 计算每个tab宽度:标签数未溢出时使用固定最大宽度,溢出时等分
const int maxTabWidth = 160;
const int minTabWidth = 110;
int tabCount = DTabBar::count();
int tabWidth = maxTabWidth;

if (tabCount * maxTabWidth > total) {
tabWidth = total / tabCount;
tabWidth = qBound(minTabWidth, tabWidth, maxTabWidth);
}
qDebug() << "aveargeWidth:" << aveargeWidth;
#ifdef DTKWIDGET_CLASS_DSizeMode
return QSize(aveargeWidth, DGuiApplicationHelper::isCompactMode() ? s_TabbarHeightCompact : s_TabbarHeight);
return QSize(tabWidth, DGuiApplicationHelper::isCompactMode() ? s_TabbarHeightCompact : s_TabbarHeight);
#else
return QSize(aveargeWidth, 40);
return QSize(tabWidth, 40);
#endif
}
qDebug() << "Exit tabSizeHint";
Expand Down
8 changes: 6 additions & 2 deletions src/widgets/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3914,12 +3914,16 @@ void Window::checkTabbarForReload()
if (fi.exists() && !fi.isWritable()) {
qDebug() << "check tabbar for reload backup-files not writable";
tabName.append(readOnlyStr);
m_tabbar->setTabText(m_tabbar->currentIndex(), tabName);
if (m_tabbar->currentName() != tabName) {
m_tabbar->setTabText(m_tabbar->currentIndex(), tabName);
}
wrapper->textEditor()->setReadOnlyPermission(true);
} else {
qDebug() << "check tabbar for reload backup-files writable";
tabName.remove(readOnlyStr);
m_tabbar->setTabText(m_tabbar->currentIndex(), tabName);
if (m_tabbar->currentName() != tabName) {
m_tabbar->setTabText(m_tabbar->currentIndex(), tabName);
}
wrapper->textEditor()->setReadOnlyPermission(false);
}

Expand Down
Loading