]> git.lyx.org Git - features.git/commitdiff
Only fix simple search height if there are no other widgets in the dock area (#13005)
authorJuergen Spitzmueller <spitz@lyx.org>
Sat, 13 Jan 2024 10:58:35 +0000 (11:58 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Sat, 13 Jan 2024 10:58:35 +0000 (11:58 +0100)
src/frontends/qt/DockView.cpp
src/frontends/qt/GuiSearch.cpp
src/frontends/qt/GuiSearch.h
src/frontends/qt/GuiView.h

index ef204e27932c96fa664c93ed591bd622a7fdce52..81696c9efbff00e55604fcab3c931fbb2da8bc43 100644 (file)
@@ -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
index 3ca4f4904d649bacfcf1cf44cb80791275a733b9..c7022876350de2cf1b339aa35dc6a44fb7862ca6 100644 (file)
@@ -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<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)
        : 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();
 }
index 89234fe4441de657a64f2655fb20cb1a0b61a949..bb3b5237aa97f82829997019ccf4cb7d2b862998 100644 (file)
@@ -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;
index d55472d2670978c5ee29cbe2577555168469c027..ac6d293aaf9f90c7e24c7519e5204802d7b4e10e 100644 (file)
@@ -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:
        ///