Only fix simple search height if there are no other widgets in the dock area (#13005)

This commit is contained in:
Juergen Spitzmueller 2024-01-13 11:58:35 +01:00
parent 8899e4d6cc
commit 6f4054222c
4 changed files with 52 additions and 8 deletions

View File

@ -31,6 +31,9 @@ DockView::DockView(GuiView & parent, QString const & name,
hide(); hide();
connect(&parent, SIGNAL(bufferViewChanged()), connect(&parent, SIGNAL(bufferViewChanged()),
this, SLOT(onBufferViewChanged())); this, SLOT(onBufferViewChanged()));
connect(this, SIGNAL(visibilityChanged(bool)),
&parent, SLOT(onDockWidgetVisibilityChanged()));
// Make dock widgets sub windows to prevent focusNextPrevChild // Make dock widgets sub windows to prevent focusNextPrevChild
// (Tab key) switching to the parent rather than to the next // (Tab key) switching to the parent rather than to the next

View File

@ -67,9 +67,6 @@ GuiSearchWidget::GuiSearchWidget(QWidget * parent, GuiView & view)
{ {
setupUi(this); setupUi(this);
// fix height to minimum
setFixedHeight(sizeHint().height());
// align items in grid on top // align items in grid on top
gridLayout->setAlignment(Qt::AlignTop); gridLayout->setAlignment(Qt::AlignTop);
@ -126,6 +123,9 @@ GuiSearchWidget::GuiSearchWidget(QWidget * parent, GuiView & view)
replacePB->setEnabled(false); replacePB->setEnabled(false);
replacePrevPB->setEnabled(false); replacePrevPB->setEnabled(false);
replaceallPB->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<QDockWidget *> dockWidgets = view_.findChildren<QDockWidget *>();
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) GuiSearch::GuiSearch(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
: DockView(parent, "findreplace", qt_("Search and Replace"), area, flags), : DockView(parent, "findreplace", qt_("Search and Replace"), area, flags),
widget_(new GuiSearchWidget(this, parent)) widget_(new GuiSearchWidget(this, parent))
@ -661,6 +680,20 @@ void GuiSearch::updateTitle()
void GuiSearch::updateSize() void GuiSearch::updateSize()
{ {
// 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()); widget_->setFixedHeight(widget_->sizeHint().height());
if (widget_->isMinimized()) if (widget_->isMinimized())
setFixedHeight(widget_->sizeHint().height()); setFixedHeight(widget_->sizeHint().height());
@ -669,6 +702,7 @@ void GuiSearch::updateSize()
setMaximumHeight(QWIDGETSIZE_MAX); setMaximumHeight(QWIDGETSIZE_MAX);
setMinimumHeight(0); setMinimumHeight(0);
} }
}
update(); update();
} }

View File

@ -43,6 +43,8 @@ public:
bool initialiseParams(std::string const &); bool initialiseParams(std::string const &);
/// ///
bool isMinimized() { return minimized_; } bool isMinimized() { return minimized_; }
///
bool hasCoWidgets(QDockWidget * dw);
private Q_SLOTS: private Q_SLOTS:
void findChanged(); void findChanged();
@ -59,6 +61,7 @@ private Q_SLOTS:
void immediateActTriggered(); void immediateActTriggered();
void immediateClicked(); void immediateClicked();
void wrapActTriggered(); void wrapActTriggered();
void onDockWidgetVisibilityChanged();
Q_SIGNALS: Q_SIGNALS:
void needTitleBarUpdate() const; void needTitleBarUpdate() const;
void needSizeUpdate() const; void needSizeUpdate() const;

View File

@ -232,6 +232,8 @@ Q_SIGNALS:
void scriptKilled(); void scriptKilled();
/// emitted when track changes status toggled /// emitted when track changes status toggled
void changeTrackingToggled(bool); void changeTrackingToggled(bool);
///
void dockWidgetVisibilityChanged();
public Q_SLOTS: public Q_SLOTS:
/// ///
@ -245,6 +247,8 @@ public Q_SLOTS:
void updateWindowTitle(GuiWorkArea * wa); void updateWindowTitle(GuiWorkArea * wa);
/// ///
void disableShellEscape(); void disableShellEscape();
///
void onDockWidgetVisibilityChanged() { Q_EMIT dockWidgetVisibilityChanged(); }
private Q_SLOTS: private Q_SLOTS:
/// ///