texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Gavin D. Smith
Date: Wed, 30 Nov 2022 13:36:40 -0500 (EST)

branch: old/qt-info
commit 76e873d1504e69284e366270dec17108163c7afb
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Fri Apr 12 23:29:26 2019 +0100

    remove ui member from Core
---
 js/docbrowser/core.cpp       | 47 ++++++++++++++-----------------------
 js/docbrowser/core.h         |  9 ++++---
 js/docbrowser/mainwindow.cpp | 56 +++++++++++++++++++++++++++++++++++++++-----
 js/docbrowser/mainwindow.h   |  7 ++++++
 4 files changed, 78 insertions(+), 41 deletions(-)

diff --git a/js/docbrowser/core.cpp b/js/docbrowser/core.cpp
index 24cdc9126e..81f3be38d0 100644
--- a/js/docbrowser/core.cpp
+++ b/js/docbrowser/core.cpp
@@ -1,5 +1,5 @@
 #include "core.h"
-#include "ui_mainwindow.h"
+#include "mainwindow.h"
 
 #include <QMessageBox>
 #include <QtGlobal>
@@ -8,9 +8,9 @@
 #include <QJsonObject>
 #include <QMapIterator>
 
-Core::Core(Ui::MainWindow *ui, QObject *parent)
+Core::Core(MainWindow *main_window, QObject *parent)
       : QObject(parent),
-        ui(ui)
+        main_window (main_window)
 {
 }
 
@@ -19,14 +19,15 @@ Core::load_manual (const char *manual)
 {
     char *path = locate_manual (manual);
 
-    // TODO: we should send it back into the browser for the JavaScript code 
to 
-    // track multiple manuals at once.
+    /* TODO: we should send it back into the browser for the JavaScript code 
to 
+       track multiple manuals at once. */
     // emit setUrl (url);
 
     if (path)
       {
         qDebug() << "got path" << path;
-        ui->webEngineView->load(QUrl("file:" + QString(path)));
+
+        main_window->load_url(QString("file:") + path);
 
         this->index_data.clear(); // FIXME: this should be done automatically, 
maybe by having a separate map for each window.
 
@@ -37,17 +38,6 @@ Core::load_manual (const char *manual)
 }
 
 
-/* Hide the text prompt.
-   Allegedly you can put these two as children of a widget, and then
-   just hide a single widget.  I couldn't get it to look right in
-   qtcreator, though. */
-void
-Core::hide_prompt()
-{
-    ui->promptLabel->setVisible(false);
-    ui->promptCombo->setVisible(false);
-}
-
 /* Return has been pressed in the input box. */
 void
 Core::activate_input (const QString &arg)
@@ -56,9 +46,6 @@ Core::activate_input (const QString &arg)
     emit search (arg);
   else
     emit set_current_url (index_data[arg].toString());
-
-  hide_prompt();
-  ui->webEngineView->setFocus();
 }
 
 /********************* Public Slots **********************/
@@ -67,6 +54,8 @@ Core::activate_input (const QString &arg)
 void
 Core::show_text_input (const QString &input, const QJsonObject &data)
 {
+  bool populate_combo = false;
+
   if (input == "regexp-search")
     {
       input_search = true;
@@ -74,21 +63,18 @@ Core::show_text_input (const QString &input, const 
QJsonObject &data)
   else if (index_data.isEmpty())
     {
       input_search = false;
+      populate_combo = true;
+    }
+  if (populate_combo)
+    {
       index_data = data.toVariantMap();
-      QMapIterator<QString, QVariant> i(index_data);
-      while (i.hasNext())
-        {
-          i.next();
-          ui->promptCombo->addItem(i.key());
-        }
+      main_window->populate_combo(index_data);
     }
 
-  ui->promptLabel->setVisible(true);
-  ui->promptCombo->setVisible(true);
-  ui->promptCombo->setFocus();
+  main_window->show_prompt();
 
   if (!input_search)
-    ui->promptCombo->setEditText("");
+    main_window->clear_prompt();
 }
 
 
@@ -111,3 +97,4 @@ Core::external_manual (const QString &url)
 
     free (manual); free (node);
 }
+
diff --git a/js/docbrowser/core.h b/js/docbrowser/core.h
index 91e282ce37..15ea47a76f 100644
--- a/js/docbrowser/core.h
+++ b/js/docbrowser/core.h
@@ -2,22 +2,21 @@
 #define CORE_H
 
 #include "infopath.h"
+#include "mainwindow.h"
 
 #include <QObject>
 #include <QVariantMap>
 
-namespace Ui {
 class MainWindow;
-}
+
 
 class Core : public QObject
 {
     Q_OBJECT
 public:
-    explicit Core(Ui::MainWindow *ui, QObject *parent = nullptr);
+    explicit Core(MainWindow *main_window, QObject *parent = nullptr);
 
     bool load_manual (const char *manual);
-    void hide_prompt ();
     void activate_input (const QString &arg);
 
 signals:
@@ -32,7 +31,7 @@ public slots:
     void show_text_input (const QString &input, const QJsonObject &data);
 
 private:
-    Ui::MainWindow *ui;
+    MainWindow *main_window;
     QVariantMap index_data;
     bool input_search;
 
diff --git a/js/docbrowser/mainwindow.cpp b/js/docbrowser/mainwindow.cpp
index 4886755b5d..2357497ba1 100644
--- a/js/docbrowser/mainwindow.cpp
+++ b/js/docbrowser/mainwindow.cpp
@@ -30,7 +30,7 @@ MainWindow::MainWindow(QWidget *parent) :
       QCoreApplication::quit();
 
     setup_channel ();
-    core->hide_prompt();
+    hide_prompt();
 
     auto *profile = new QWebEngineProfile(this);
     setup_profile(profile);
@@ -38,8 +38,13 @@ MainWindow::MainWindow(QWidget *parent) :
 
     ui->webEngineView->setPage(page);
 
-    ui->webEngineView->page()->load(QUrl(QString("file:") + this->datadir +
-                                    "/test/hello/index.html"));
+    load_url (QString("file:") + this->datadir + "/test/hello/index.html");
+}
+
+void
+MainWindow::load_url(const QString &string)
+{
+  ui->webEngineView->page()->load(QUrl(string));
 }
 
 /* Initialize "core" object. */
@@ -66,7 +71,7 @@ MainWindow::setup_channel()
     QObject::connect(clientWrapper, &WebSocketClientWrapper::clientConnected,
                          channel, &QWebChannel::connectTo);
 
-    this->core = new Core(ui, this);
+    this->core = new Core(this, this);
     channel->registerObject(QStringLiteral("core"), core);
 }
 
@@ -176,7 +181,7 @@ void MainWindow::quit()
 void MainWindow::focusChanged (QWidget *old, QWidget *now)
 {
     if (now == ui->webEngineView)
-       core->hide_prompt();
+       hide_prompt();
 }
 
 void MainWindow::on_quitButton_clicked()
@@ -193,5 +198,44 @@ void MainWindow::on_loadButton_clicked()
 
 void MainWindow::on_promptCombo_activated(const QString &arg1)
 {
-    core->activate_input(arg1);
+  core->activate_input(arg1);
+  hide_prompt();
+  ui->webEngineView->setFocus();
+}
+
+/* Hide the text prompt.
+   Allegedly you can put these two as children of a widget, and then
+   just hide a single widget.  I couldn't get it to look right in
+   qtcreator, though. */
+void
+MainWindow::hide_prompt()
+{
+  ui->promptLabel->setVisible(false);
+  ui->promptCombo->setVisible(false);
+}
+
+void
+MainWindow::show_prompt()
+{
+  ui->promptLabel->setVisible(true);
+  ui->promptCombo->setVisible(true);
+  ui->promptCombo->setFocus();
+}
+
+
+void
+MainWindow::clear_prompt()
+{
+  ui->promptCombo->setEditText("");
+}
+
+void
+MainWindow::populate_combo (const QMap<QString, QVariant> &data)
+{
+  QMapIterator<QString, QVariant> i(data);
+  while (i.hasNext())
+    {
+      i.next();
+      ui->promptCombo->addItem(i.key());
+    }
 }
diff --git a/js/docbrowser/mainwindow.h b/js/docbrowser/mainwindow.h
index 464fd82a67..b218e23a42 100644
--- a/js/docbrowser/mainwindow.h
+++ b/js/docbrowser/mainwindow.h
@@ -7,6 +7,8 @@
 #include <QMainWindow>
 #include <QWebEngineProfile>
 
+class Core;
+
 namespace Ui {
 class MainWindow;
 }
@@ -19,6 +21,11 @@ class MainWindow : public QMainWindow
 public:
     explicit MainWindow(QWidget *parent = 0);
     ~MainWindow();
+    void hide_prompt ();
+    void show_prompt ();
+    void clear_prompt ();
+    void populate_combo (const QMap<QString, QVariant> &data);
+    void load_url (const QString &string);
 
 private slots:
     void on_quitButton_clicked();



reply via email to

[Prev in Thread] Current Thread [Next in Thread]