Skip to content

Commit

Permalink
fix: new term resized wrongly
Browse files Browse the repository at this point in the history
fix the bug that new term has wrong size after splitting
  • Loading branch information
hualet committed Aug 29, 2024
1 parent 7dc5ab4 commit eee66bc
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/views/termwidgetpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,6 @@
#include <QVBoxLayout>
#include <QApplication>

static void setEqualSizes(QSplitter *splitter)
{
QList<int> sizes = splitter->sizes();
int totalSize = 0;
for (int size : sizes) {
totalSize += size;
}

int equalSize = totalSize / sizes.size();
for (int i = 0; i < sizes.size(); ++i) {
sizes[i] = equalSize;
}

splitter->setSizes(sizes);
}

// Find the previous term widget in the widget tree.
static TermWidget* WidgetTreeReverseFindTerm(QWidget *widget)
{
Expand Down Expand Up @@ -170,7 +154,15 @@ void TermWidgetPage::split(Qt::Orientation orientation)
if (splitter && splitter->orientation() != orientation) {
TermProperties properties(term->workingDirectory());
TermWidget *newTerm = createTerm(properties);

// copy the size of the current term to the new term, so the new term will
// keep the same size portion as the current term after the splitter relayout.
// this behavior is copied form iTerm2.
QList<int> sizes = splitter->sizes();
sizes.insert(index+1, sizes.at(index));
splitter->insertWidget(index+1, newTerm); // insert after the current term
splitter->setSizes(sizes);

setSplitStyle(splitter);
setCurrentTerminal(newTerm);
} else {
Expand All @@ -180,8 +172,12 @@ void TermWidgetPage::split(Qt::Orientation orientation)
QSplitter *newSplitter = createSubSplit(term, orientation);

if (splitter) {
// see above splitter->insertWidget part to know why.
QList<int> sizes = splitter->sizes();
sizes.insert(index, sizes.at(index));
splitter->insertWidget(index, newSplitter);
setEqualSizes(splitter);
splitter->setSizes(sizes);
setSplitStyle(splitter);
} else {
m_layout->insertWidget(index, newSplitter);
}
Expand All @@ -204,6 +200,7 @@ DSplitter *TermWidgetPage::createSubSplit(TermWidget *term, Qt::Orientation orie
TermProperties properties(term->workingDirectory());
term->setParent(nullptr);
TermWidget *newTerm = createTerm(properties);
newTerm->resize(term->size());

// 意义与名称是相反的
DSplitter *subSplit = new DSplitter(orientation == Qt::Horizontal ? Qt::Vertical : Qt::Horizontal,
Expand All @@ -212,7 +209,6 @@ DSplitter *TermWidgetPage::createSubSplit(TermWidget *term, Qt::Orientation orie
subSplit->setFocusPolicy(Qt::NoFocus);
subSplit->insertWidget(0, term);
subSplit->insertWidget(1, newTerm);
subSplit->setSizes({ 1, 1 });
setSplitStyle(subSplit);
setCurrentTerminal(newTerm);
/******** Modify by ut000439 wangpeili 2020-07-27: fix bug 39371: 分屏线可以拉到边****/
Expand Down

0 comments on commit eee66bc

Please sign in to comment.