From 6f4054222ce42ee49294e7a778842c3ff1ceaabe Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sat, 13 Jan 2024 11:58:35 +0100 Subject: [PATCH] Only fix simple search height if there are no other widgets in the dock area (#13005) --- src/frontends/qt/DockView.cpp | 3 ++ src/frontends/qt/GuiSearch.cpp | 50 ++++++++++++++++++++++++++++------ src/frontends/qt/GuiSearch.h | 3 ++ src/frontends/qt/GuiView.h | 4 +++ 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/frontends/qt/DockView.cpp b/src/frontends/qt/DockView.cpp index ef204e2793..81696c9efb 100644 --- a/src/frontends/qt/DockView.cpp +++ b/src/frontends/qt/DockView.cpp @@ -31,6 +31,9 @@ DockView::DockView(GuiView & parent, QString const & name, hide(); connect(&parent, SIGNAL(bufferViewChanged()), this, SLOT(onBufferViewChanged())); + connect(this, SIGNAL(visibilityChanged(bool)), + &parent, SLOT(onDockWidgetVisibilityChanged())); + // Make dock widgets sub windows to prevent focusNextPrevChild // (Tab key) switching to the parent rather than to the next diff --git a/src/frontends/qt/GuiSearch.cpp b/src/frontends/qt/GuiSearch.cpp index 3ca4f4904d..c702287635 100644 --- a/src/frontends/qt/GuiSearch.cpp +++ b/src/frontends/qt/GuiSearch.cpp @@ -67,9 +67,6 @@ GuiSearchWidget::GuiSearchWidget(QWidget * parent, GuiView & view) { setupUi(this); - // fix height to minimum - setFixedHeight(sizeHint().height()); - // align items in grid on top gridLayout->setAlignment(Qt::AlignTop); @@ -126,6 +123,9 @@ GuiSearchWidget::GuiSearchWidget(QWidget * parent, GuiView & view) replacePB->setEnabled(false); replacePrevPB->setEnabled(false); replaceallPB->setEnabled(false); + + connect(&view_, SIGNAL(dockWidgetVisibilityChanged()), + this, SLOT(onDockWidgetVisibilityChanged())); } @@ -568,6 +568,25 @@ void GuiSearchWidget::restoreSession(QString const & session_key) } +bool GuiSearchWidget::hasCoWidgets(QDockWidget * dw) +{ + int res = 0; + QList dockWidgets = view_.findChildren(); + for (int i = 0; i < dockWidgets.size(); ++i) { + if (dockWidgets.at(i)->isVisible() + && view_.dockWidgetArea(dockWidgets.at(i)) == view_.dockWidgetArea(dw)) + ++res; + } + return res > 1; +} + + +void GuiSearchWidget::onDockWidgetVisibilityChanged() +{ + Q_EMIT needSizeUpdate(); +} + + GuiSearch::GuiSearch(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags) : DockView(parent, "findreplace", qt_("Search and Replace"), area, flags), widget_(new GuiSearchWidget(this, parent)) @@ -661,13 +680,28 @@ void GuiSearch::updateTitle() void GuiSearch::updateSize() { - widget_->setFixedHeight(widget_->sizeHint().height()); - if (widget_->isMinimized()) - setFixedHeight(widget_->sizeHint().height()); - else { - // undo setFixedHeight + // This can be triggered before the search widget is visible + // Nothing to do in that case + if (!widget_->isVisible()) + return; + + // if we have more than this widget in the current dock + // we do not fix the size as other widgets might want to + // remain resizable + if (widget_->hasCoWidgets(this)) { + widget_->setMaximumHeight(QWIDGETSIZE_MAX); + widget_->setMinimumHeight(0); setMaximumHeight(QWIDGETSIZE_MAX); setMinimumHeight(0); + } else { + widget_->setFixedHeight(widget_->sizeHint().height()); + if (widget_->isMinimized()) + setFixedHeight(widget_->sizeHint().height()); + else { + // undo setFixedHeight + setMaximumHeight(QWIDGETSIZE_MAX); + setMinimumHeight(0); + } } update(); } diff --git a/src/frontends/qt/GuiSearch.h b/src/frontends/qt/GuiSearch.h index 89234fe444..bb3b5237aa 100644 --- a/src/frontends/qt/GuiSearch.h +++ b/src/frontends/qt/GuiSearch.h @@ -43,6 +43,8 @@ public: bool initialiseParams(std::string const &); /// bool isMinimized() { return minimized_; } + /// + bool hasCoWidgets(QDockWidget * dw); private Q_SLOTS: void findChanged(); @@ -59,6 +61,7 @@ private Q_SLOTS: void immediateActTriggered(); void immediateClicked(); void wrapActTriggered(); + void onDockWidgetVisibilityChanged(); Q_SIGNALS: void needTitleBarUpdate() const; void needSizeUpdate() const; diff --git a/src/frontends/qt/GuiView.h b/src/frontends/qt/GuiView.h index d55472d267..ac6d293aaf 100644 --- a/src/frontends/qt/GuiView.h +++ b/src/frontends/qt/GuiView.h @@ -232,6 +232,8 @@ Q_SIGNALS: void scriptKilled(); /// emitted when track changes status toggled void changeTrackingToggled(bool); + /// + void dockWidgetVisibilityChanged(); public Q_SLOTS: /// @@ -245,6 +247,8 @@ public Q_SLOTS: void updateWindowTitle(GuiWorkArea * wa); /// void disableShellEscape(); + /// + void onDockWidgetVisibilityChanged() { Q_EMIT dockWidgetVisibilityChanged(); } private Q_SLOTS: /// -- 2.39.5