From 886e4a062556e2986851401007453fdaa4e20b00 Mon Sep 17 00:00:00 2001 From: Hualet Wang Date: Fri, 30 Aug 2024 23:38:44 +0800 Subject: [PATCH] fix: shortcut can still do splitting on room left --- src/main/mainwindow.cpp | 4 ++-- src/views/termwidget.cpp | 31 ------------------------------- src/views/termwidget.h | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/main/mainwindow.cpp b/src/main/mainwindow.cpp index d516030b5..a5dd7308c 100644 --- a/src/main/mainwindow.cpp +++ b/src/main/mainwindow.cpp @@ -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 ; } @@ -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 ; } diff --git a/src/views/termwidget.cpp b/src/views/termwidget.cpp index 9cf18ef96..bdd9d259c 100644 --- a/src/views/termwidget.cpp +++ b/src/views/termwidget.cpp @@ -38,37 +38,6 @@ DWIDGET_USE_NAMESPACE using namespace Konsole; - -static bool CanSplit(TermWidget *term, Qt::Orientation ori) { - QSplitter *splitter = qobject_cast(term->parentWidget()); - int minimumSize = ori == Qt::Horizontal ? TermWidget::MIN_WIDTH : TermWidget::MIN_HEIGHT; - if (splitter) { - if (splitter->orientation() == ori) { - QList 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); diff --git a/src/views/termwidget.h b/src/views/termwidget.h index b32db22f0..86ca80450 100644 --- a/src/views/termwidget.h +++ b/src/views/termwidget.h @@ -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(term->parentWidget()); + int minimumSize = ori == Qt::Horizontal ? TermWidget::MIN_WIDTH : TermWidget::MIN_HEIGHT; + if (splitter) { + if (splitter->orientation() == ori) { + QList 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