Skip to content

Commit

Permalink
fix: shortcut can still do splitting on room left
Browse files Browse the repository at this point in the history
  • Loading branch information
hualet committed Aug 30, 2024
1 parent 9d0f44d commit 886e4a0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/main/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ inline void MainWindow::slotShortcutHorizonzalSplit()
// 判读数量是否允许分屏
if (Service::instance()->isCountEnable()) {
TermWidgetPage *page = currentPage();
if (page) {
if (page && CanSplit(page->currentTerminal(), Qt::Vertical)) {
page->split(Qt::Horizontal);
return ;
}
Expand All @@ -1144,7 +1144,7 @@ inline void MainWindow::slotShortcutVerticalSplit()
// 判读数量是否允许分屏
if (Service::instance()->isCountEnable()) {
TermWidgetPage *page = currentPage();
if (page) {
if (page && CanSplit(page->currentTerminal(), Qt::Horizontal)) {
page->split(Qt::Vertical);
return ;
}
Expand Down
31 changes: 0 additions & 31 deletions src/views/termwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,6 @@

DWIDGET_USE_NAMESPACE
using namespace Konsole;

static bool CanSplit(TermWidget *term, Qt::Orientation ori) {
QSplitter *splitter = qobject_cast<QSplitter *>(term->parentWidget());
int minimumSize = ori == Qt::Horizontal ? TermWidget::MIN_WIDTH : TermWidget::MIN_HEIGHT;
if (splitter) {
if (splitter->orientation() == ori) {
QList<int> sizes = splitter->sizes();
// new term has same size portion as the current one.
sizes.append(sizes.at(splitter->indexOf(term)));

double sum = 0;
for (int i = 0; i < sizes.count(); i++) {
sum += sizes.at(i);
}

for(int i = 0; i < sizes.count(); i++) {
int totalSize = ori == Qt::Horizontal ? splitter->width() : splitter->height();
int actualSize = (totalSize) * (sizes.at(i) / sum);
if (actualSize < minimumSize)
return false;
}
} else {
int splitterSize = ori == Qt::Horizontal ? splitter->width() : splitter->height();
if (splitterSize / 2.0 < minimumSize)
return false;
}
}

return true;
}

TermWidget::TermWidget(const TermProperties &properties, QWidget *parent) : QTermWidget(0, parent), m_properties(properties)
{
Utils::set_Object_Name(this);
Expand Down
31 changes: 31 additions & 0 deletions src/views/termwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,35 @@ private slots:
bool m_remotePasswordIsReady = false;
};

static bool CanSplit(TermWidget *term, Qt::Orientation ori) {
qDebug() << "CanSplit:" << term << ori;
QSplitter *splitter = qobject_cast<QSplitter *>(term->parentWidget());
int minimumSize = ori == Qt::Horizontal ? TermWidget::MIN_WIDTH : TermWidget::MIN_HEIGHT;
if (splitter) {
if (splitter->orientation() == ori) {
QList<int> sizes = splitter->sizes();
// new term has same size portion as the current one.
sizes.append(sizes.at(splitter->indexOf(term)));

double sum = 0;
for (int i = 0; i < sizes.count(); i++) {
sum += sizes.at(i);
}

for(int i = 0; i < sizes.count(); i++) {
int totalSize = ori == Qt::Horizontal ? splitter->width() : splitter->height();
int actualSize = (totalSize) * (sizes.at(i) / sum);
if (actualSize < minimumSize)
return false;
}
} else {
int splitterSize = ori == Qt::Horizontal ? splitter->width() : splitter->height();
if (splitterSize / 2.0 < minimumSize)
return false;
}
}

return true;
}

#endif // TERMWIDGET_H

0 comments on commit 886e4a0

Please sign in to comment.