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:36 -0500 (EST)

branch: old/qt-info
commit e36ed1fa6fdabc9f6cc28e19f215ff82376d5aa2
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Wed Apr 10 01:27:52 2019 +0100

    Add a text input.  This will be needed because datalist doesn't work
    with QtWebEngine: see https://bugreports.qt.io/browse/QTBUG-54433.
---
 js/docbrowser/core.cpp       | 21 +++++++++++++
 js/docbrowser/core.h         |  4 ++-
 js/docbrowser/mainwindow.cpp | 12 +++++++-
 js/docbrowser/mainwindow.h   |  1 +
 js/docbrowser/mainwindow.ui  | 71 ++++++++++++++++++++++++++++++++++++++++++--
 5 files changed, 104 insertions(+), 5 deletions(-)

diff --git a/js/docbrowser/core.cpp b/js/docbrowser/core.cpp
index c5f58f93b9..d401cfe7de 100644
--- a/js/docbrowser/core.cpp
+++ b/js/docbrowser/core.cpp
@@ -51,3 +51,24 @@ Core::load_manual (const char *manual)
     return false;
 }
 
+/* Show the text prompt. */
+void
+Core::show_text_input (const QString &input)
+{
+  ui->promptLabel->setVisible(true);
+  ui->promptCombo->setVisible(true);
+  ui->promptCombo->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
+Core::hide_prompt()
+{
+    ui->promptLabel->setVisible(false);
+    ui->promptCombo->setVisible(false);
+}
+
+
diff --git a/js/docbrowser/core.h b/js/docbrowser/core.h
index 0b05f36b01..b77a218303 100644
--- a/js/docbrowser/core.h
+++ b/js/docbrowser/core.h
@@ -16,14 +16,16 @@ public:
     explicit Core(Ui::MainWindow *ui, QObject *parent = nullptr);
 
     bool load_manual (const char *manual);
+    void hide_prompt ();
 
 signals:
     // Signals emitted from the C++ side and received on the HTML client side.
     void setUrl (const QString &text);
 
 public slots:
-    // Signals emitted from the HTML client side and received on the HTML side.
+    // Signals emitted from the HTML client side and received on the C++ side.
     void external_manual (const QString &url);
+    void show_text_input (const QString &input);
 
 private:
     Ui::MainWindow *ui;
diff --git a/js/docbrowser/mainwindow.cpp b/js/docbrowser/mainwindow.cpp
index 756c8be7ac..7939dca0fd 100644
--- a/js/docbrowser/mainwindow.cpp
+++ b/js/docbrowser/mainwindow.cpp
@@ -14,19 +14,23 @@
 #include <QtDebug>
 #include <QWebChannel>
 #include <QWebEngineProfile>
+#include <QCoreApplication>
 
 MainWindow::MainWindow(QWidget *parent) :
     QMainWindow(parent),
     ui(new Ui::MainWindow)
 {
     ui->setupUi(this);
+
     connect(ui->actionQuit, &QAction::triggered, this, &MainWindow::quit);
+    connect(qApp, &QApplication::focusChanged, this, 
&MainWindow::focusChanged);
 
     this->datadir = getenv ("QTINFO_DATADIR");
     if (!this->datadir)
       QCoreApplication::quit();
 
     setup_channel ();
+    core->hide_prompt();
 
     auto *profile = new QWebEngineProfile(this);
     setup_profile(profile);
@@ -41,6 +45,7 @@ MainWindow::MainWindow(QWidget *parent) :
                                     "/test/hello/index.html"));
 }
 
+/* Initialize "core" object. */
 void
 MainWindow::setup_channel()
 {
@@ -66,7 +71,6 @@ MainWindow::setup_channel()
 
     this->core = new Core(ui, this);
     channel->registerObject(QStringLiteral("core"), core);
-
 }
 
 /* Load info.js and qwebchannel.js into the current page. */
@@ -198,3 +202,9 @@ void MainWindow::on_loadButton_clicked()
 {
     core->load_manual (qPrintable(ui->manualEdit->text()));
 }
+
+void MainWindow::focusChanged (QWidget *old, QWidget *now)
+{
+    if (now != ui->promptCombo)
+       core->hide_prompt();
+}
diff --git a/js/docbrowser/mainwindow.h b/js/docbrowser/mainwindow.h
index 9f146a1e85..9e46b4387b 100644
--- a/js/docbrowser/mainwindow.h
+++ b/js/docbrowser/mainwindow.h
@@ -40,6 +40,7 @@ private:
     void inject_qwebchannel(bool ok);
     void setup_profile(QWebEngineProfile *profile);
     void setup_channel();
+    void focusChanged (QWidget *old, QWidget *now);
 };
 
 #endif // MAINWINDOW_H
diff --git a/js/docbrowser/mainwindow.ui b/js/docbrowser/mainwindow.ui
index 1a329f29fe..df7cb840e3 100644
--- a/js/docbrowser/mainwindow.ui
+++ b/js/docbrowser/mainwindow.ui
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>735</width>
-    <height>507</height>
+    <width>754</width>
+    <height>407</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -15,6 +15,71 @@
   </property>
   <widget class="QWidget" name="centralWidget">
    <layout class="QVBoxLayout" name="verticalLayout">
+    <item>
+     <layout class="QHBoxLayout" name="horizontalLayout_2">
+      <item>
+       <widget class="QLabel" name="promptLabel">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="text">
+         <string>Prompt:</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QComboBox" name="promptCombo">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="editable">
+         <bool>true</bool>
+        </property>
+        <item>
+         <property name="text">
+          <string>toasters</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>drinks vending machines</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>cans of pickled onions</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>cans of beans</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>cans of tomatoes</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>light goods vehicles</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>dental floss</string>
+         </property>
+        </item>
+       </widget>
+      </item>
+     </layout>
+    </item>
     <item>
      <widget class="QWebEngineView" name="webEngineView">
       <property name="url">
@@ -55,7 +120,7 @@
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>735</width>
+     <width>754</width>
      <height>19</height>
     </rect>
    </property>



reply via email to

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