Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve splitter animation handling #2487

Merged
merged 3 commits into from
Dec 13, 2024
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
4 changes: 4 additions & 0 deletions src/dfm-base/widgets/dfmwindow/filemanagerwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ void FileManagerWindowPrivate::connectAnimationSignals()
bool expanded = curSplitterAnimation->endValue().toInt() > 1;
if (expanded)
resetSideBarSize();
// set the handle to be disabled when the side bar is collapsed
// because if do not disable the handle, the splitter can be dragged by pressed window left boarder.
if (auto handle = splitter->handle(1))
handle->setEnabled(expanded);
delete curSplitterAnimation;
curSplitterAnimation = nullptr;
});
Expand Down
1 change: 1 addition & 0 deletions src/plugins/filemanager/dfmplugin-titlebar/titlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void TitleBar::onWindowOpened(quint64 windId)
connect(window, &FileManagerWindow::reqCloseCurrentTab, titleBarWidget, &TitleBarWidget::handleHotketCloseCurrentTab);
connect(window, &FileManagerWindow::reqActivateTabByIndex, titleBarWidget, &TitleBarWidget::handleHotketActivateTab);
connect(window, &FileManagerWindow::windowSplitterWidthChanged, titleBarWidget, &TitleBarWidget::handleSplitterAnimation);
connect(window, &FileManagerWindow::aboutToPlaySplitterAnimation, titleBarWidget, &TitleBarWidget::handleAboutToPlaySplitterAnim);
}

void TitleBar::onWindowClosed(quint64 windId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include <QHBoxLayout>
#include <QEvent>
#include <QResizeEvent>

using namespace dfmplugin_titlebar;
DFMBASE_USE_NAMESPACE
Expand Down Expand Up @@ -100,12 +101,29 @@
searchEditWidget->stopSpinner();
}

void TitleBarWidget::handleSplitterAnimation(const QVariant &position)

Check warning on line 104 in src/plugins/filemanager/dfmplugin-titlebar/views/titlebarwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'handleSplitterAnimation' is never used.

Check warning on line 104 in src/plugins/filemanager/dfmplugin-titlebar/views/titlebarwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

The function 'handleSplitterAnimation' is never used.
{
placeholder->setFixedWidth(qMax(0, 95 - position.toInt()));
if (position == splitterEndValue) {
splitterStartValue = -1;
splitterEndValue = -1;
isSplitterAnimating = false;
}

int newWidth = qMax(0, 95 - position.toInt());
if (newWidth == placeholder->width())
return;

placeholder->setFixedWidth(newWidth);
}

void TitleBarWidget::handleAboutToPlaySplitterAnim(int startValue, int endValue)
{
isSplitterAnimating = true;
splitterStartValue = startValue;
splitterEndValue = endValue;
}

void TitleBarWidget::handleHotkeyCtrlF()

Check warning on line 126 in src/plugins/filemanager/dfmplugin-titlebar/views/titlebarwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'handleHotkeyCtrlF' is never used.

Check warning on line 126 in src/plugins/filemanager/dfmplugin-titlebar/views/titlebarwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

The function 'handleHotkeyCtrlF' is never used.
{
searchEditWidget->activateEdit();
}
Expand Down Expand Up @@ -207,6 +225,7 @@

// tabbar
bottomBar = new TabBar;
bottomBar->installEventFilter(this);
topBarCustomLayout->addWidget(bottomBar, 1);

// nav
Expand Down Expand Up @@ -419,6 +438,13 @@
}
}

// if the splitter is animating, do not process the resize event of tabbar
// otherwise, the tabbar width will be changed twice(once by the resizeEvent and once by placeholder size changed)
if (watched == bottomBar && event->type() == QEvent::Resize) {
if (isSplitterAnimating)
return true;
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class TitleBarWidget : public DFMBASE_NAMESPACE::AbstractFrame
void showSearchFilterButton(bool visible);
void setViewModeState(int mode);
void handleSplitterAnimation(const QVariant &position);
void handleAboutToPlaySplitterAnim(int startValue, int endValue);

int calculateRemainingWidth() const;

Expand Down Expand Up @@ -93,6 +94,9 @@ private slots:
QWidget *placeholder { nullptr };

bool searchButtonSwitchState { false };
int splitterStartValue { -1 };
int splitterEndValue { -1 };
bool isSplitterAnimating { false };
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <QVBoxLayout>
#include <QStandardItemModel>
#include <QKeyEvent>
#include <QApplication>
#include <QScreen>

DWIDGET_USE_NAMESPACE
using namespace dfmplugin_titlebar;
Expand Down Expand Up @@ -290,7 +292,32 @@ void ViewOptionsWidget::exec(const QPoint &pos, DFMBASE_NAMESPACE::Global::ViewM
{
d->setUrl(url);
d->switchMode(mode);
move(pos);

// Calculate appropriate display position to ensure widget stays within screen bounds
QPoint showPos = pos;
QRect screenRect = QApplication::screenAt(pos)->availableGeometry();

// Check right boundary
if (pos.x() + width() > screenRect.right()) {
showPos.setX(screenRect.right() - width());
}

// Check left boundary
if (showPos.x() < screenRect.left()) {
showPos.setX(screenRect.left());
}

// Check bottom boundary
if (pos.y() + height() > screenRect.bottom()) {
showPos.setY(screenRect.bottom() - height());
}

// Check top boundary
if (showPos.y() < screenRect.top()) {
showPos.setY(screenRect.top());
}

move(showPos);
show();

QEventLoop eventLoop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ FileView::FileView(const QUrl &url, QWidget *parent)
: DListView(parent), d(new FileViewPrivate(this))
{
Q_UNUSED(url);
setMinimumHeight(10);
setDragDropMode(QAbstractItemView::DragDrop);
setDropIndicatorShown(false);
setSelectionMode(QAbstractItemView::ExtendedSelection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void WorkspaceWidget::initViewLayout()
viewStackLayout->setContentsMargins(0, 0, 0, 0);

widgetLayout = new QVBoxLayout;
widgetLayout->addLayout(viewStackLayout, 1);
widgetLayout->addLayout(viewStackLayout, 0);
widgetLayout->setSpacing(0);
widgetLayout->setContentsMargins(0, 0, 0, 0);
setLayout(widgetLayout);
Expand Down Expand Up @@ -366,7 +366,7 @@ void WorkspaceWidget::initCustomTopWidgets(const QUrl &url)
} else {
TopWidgetPtr topWidgetPtr = QSharedPointer<QWidget>(interface->create());
if (topWidgetPtr) {
widgetLayout->insertWidget(0, topWidgetPtr.get());
widgetLayout->insertWidget(0, topWidgetPtr.get(), 1, Qt::AlignTop);
topWidgets.insert(scheme, topWidgetPtr);
topWidgetPtr->setVisible(interface->isShowFromUrl(topWidgets[scheme].data(), url) || interface->isKeepShow());
}
Expand Down
Loading