changeset 33553:444190b10644

changes in find widget * documentation.cc (documentation): create find widget with close button, create toolbar not before find widget exists; (construct_tool_bar): directly connect activate_find slot of find widget to find action; (activate_find) remove private slot * documentation.h: remove activate_find * find-widget.cc (find_widget): first argument is flag for close button, add close button only if this flag is true * find-widget.h: update comment on usage of find widget, ctor with new argument related to close button, activate_find now public slots
author Torsten Lilge <ttl-octave@mailbox.org>
date Thu, 09 May 2024 20:35:50 +0200
parents 4495e4a23aa6
children 6f33e7ee3c3d
files libgui/src/documentation.cc libgui/src/documentation.h libgui/src/find-widget.cc libgui/src/find-widget.h
diffstat 4 files changed, 27 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/documentation.cc	Wed May 08 14:58:32 2024 -0400
+++ b/libgui/src/documentation.cc	Thu May 09 20:35:50 2024 +0200
@@ -174,11 +174,8 @@
   connect (m_doc_browser, &documentation_browser::cursorPositionChanged,
            this, &documentation::handle_cursor_position_change);
 
-  // Tool bar
-  construct_tool_bar ();
-
   // Find bar
-  m_find_widget = new find_widget (this);
+  m_find_widget = new find_widget (true, this);
   connect (m_find_widget, &find_widget::find_signal,
            this, &documentation::find);
   connect (m_find_widget, &find_widget::find_incremental_signal,
@@ -190,11 +187,14 @@
   v_box_browser_find->addWidget (m_find_widget);
   browser_find->setLayout (v_box_browser_find);
 
-  notice_settings ();
-
   m_find_widget->hide ();
   m_search_anchor_position = 0;
 
+  // Tool bar
+  construct_tool_bar ();
+
+  notice_settings ();
+
   if (m_help_engine)
     {
 #if defined (HAVE_NEW_QHELPINDEXWIDGET_API)
@@ -419,7 +419,7 @@
   m_tool_bar->addSeparator ();
   m_action_find
     = add_action (settings.icon ("edit-find"), tr ("Find"),
-                  SLOT (activate_find ()), this, m_tool_bar);
+                  SLOT (activate_find ()), m_find_widget, m_tool_bar);
 
   // Zoom
   m_tool_bar->addSeparator ();
@@ -757,12 +757,6 @@
 }
 
 void
-documentation::activate_find ()
-{
-  m_find_widget->activate_find ();
-}
-
-void
 documentation::filter_update (const QString& expression)
 {
   if (! m_help_engine)
--- a/libgui/src/documentation.h	Wed May 08 14:58:32 2024 -0400
+++ b/libgui/src/documentation.h	Thu May 09 20:35:50 2024 +0200
@@ -134,7 +134,6 @@
 
 private slots:
 
-  void activate_find ();
   void global_search ();
   void global_search_started ();
   void global_search_finished (int hits);
--- a/libgui/src/find-widget.cc	Wed May 08 14:58:32 2024 -0400
+++ b/libgui/src/find-widget.cc	Thu May 09 20:35:50 2024 +0200
@@ -36,7 +36,7 @@
 
 // The documentation splitter, which is the main widget
 // of the doc dock widget
-find_widget::find_widget (QWidget *p)
+find_widget::find_widget (bool x_button, QWidget *p)
   : QWidget (p),
     m_findnext_shortcut (new QShortcut (this)),
     m_findprev_shortcut (new QShortcut (this))
@@ -65,19 +65,23 @@
   connect (backward_button, &QToolButton::pressed,
            this, &find_widget::find_backward);
 
-  QToolButton *close_button = new QToolButton (this);
-//  close_button->setText (tr ("Close"));
-  close_button->setToolTip (tr ("Close find dialog"));
-  close_button->setIcon (settings.icon ("window-close"));
-  connect (close_button, &QToolButton::pressed,
-           this, [this] () { close (); });
-
   QHBoxLayout *h_box_this = new QHBoxLayout (this);
   h_box_this->addWidget (find_label);
   h_box_this->addWidget (m_find_line_edit);
   h_box_this->addWidget (forward_button);
   h_box_this->addWidget (backward_button);
-  h_box_this->addWidget (close_button);
+
+  if (x_button)
+    {
+      QToolButton *close_button = new QToolButton (this);
+      close_button->setText (tr ("Close"));
+      close_button->setToolTip (tr ("Close find dialog"));
+      close_button->setIcon (settings.icon ("window-close"));
+      connect (close_button, &QToolButton::pressed,
+               this, [this] () { close (); });
+      h_box_this->addWidget (close_button);
+    }
+
   h_box_this->setContentsMargins (2, 2, 2, 2);
   this->setLayout (h_box_this);
 
--- a/libgui/src/find-widget.h	Wed May 08 14:58:32 2024 -0400
+++ b/libgui/src/find-widget.h	Thu May 09 20:35:50 2024 +0200
@@ -38,7 +38,9 @@
 //    3. Provide suitable actions in the slots of the signals above
 //    4. Call the find widget's methods notice_settings when settings
 //       are updated and save_settings when settings are saved
-//    5. Other methods are
+//    5. Other methods or slots are
+//        - file_widget::activate_find (): slot for hiding/showing
+//                                         find widget
 //        - file_widget::text (): get current search text
 //        - file_widget::set_text (const QString& text): set search text
 //
@@ -63,10 +65,10 @@
 
 public:
 
-  find_widget (QWidget *parent = nullptr);
+  // x_button: provide a close button for the widget or not
+  find_widget (bool x_button = true, QWidget *parent = nullptr);
   ~find_widget () = default;
 
-  void activate_find (void);
   QString text (void);
   void set_text (const QString& text);
   void notice_settings (void);
@@ -74,6 +76,8 @@
 
 public slots:
 
+  void activate_find (void);
+
 private slots:
 
   void find (void);