[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:37 -0500 (EST) |
branch: old/qt-info
commit e06e85a0032b6c5ec5054bc0604cfc61c4429a5b
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Wed Apr 10 23:22:54 2019 +0100
Implement index search box
This didn't work before because it was lacking in QWebEngineView. Get
the index data via the QWebChannel as a QJsonObject and populate the
combo box with suggestions. Pass back selected index entry into info.js
via the QWebChannel.
---
js/docbrowser/core.cpp | 27 +++++++++++++++++++++++++--
js/docbrowser/core.h | 6 +++++-
js/docbrowser/mainwindow.cpp | 13 ++++++++++---
js/docbrowser/mainwindow.h | 1 +
4 files changed, 41 insertions(+), 6 deletions(-)
diff --git a/js/docbrowser/core.cpp b/js/docbrowser/core.cpp
index d401cfe7de..a595f317c2 100644
--- a/js/docbrowser/core.cpp
+++ b/js/docbrowser/core.cpp
@@ -5,6 +5,8 @@
#include <QtGlobal>
#include <QCoreApplication>
#include <QDebug>
+#include <QJsonObject>
+#include <QMapIterator>
Core::Core(Ui::MainWindow *ui, QObject *parent)
: QObject(parent),
@@ -45,6 +47,9 @@ Core::load_manual (const char *manual)
{
qDebug() << "got path" << path;
ui->webEngineView->load(QUrl("file:" + QString(path)));
+
+ this->index_data.clear(); // FIXME: this should be done automatically,
maybe by having a separate map for each window.
+
free (path);
return true;
}
@@ -53,11 +58,23 @@ Core::load_manual (const char *manual)
/* Show the text prompt. */
void
-Core::show_text_input (const QString &input)
+Core::show_text_input (const QString &input, const QJsonObject &data)
{
+ if (index_data.isEmpty())
+ {
+ index_data = data.toVariantMap();
+ QMapIterator<QString, QVariant> i(index_data);
+ while (i.hasNext())
+ {
+ i.next();
+ ui->promptCombo->addItem(i.key());
+ }
+ }
+
ui->promptLabel->setVisible(true);
ui->promptCombo->setVisible(true);
ui->promptCombo->setFocus();
+ ui->promptCombo->setEditText("");
}
/* Hide the text prompt.
@@ -71,4 +88,10 @@ Core::hide_prompt()
ui->promptCombo->setVisible(false);
}
-
+void
+Core::activate_input (const QString &arg)
+{
+ emit set_current_url (index_data[arg].toString());
+ hide_prompt();
+ ui->webEngineView->setFocus();
+}
diff --git a/js/docbrowser/core.h b/js/docbrowser/core.h
index b77a218303..fa146f5527 100644
--- a/js/docbrowser/core.h
+++ b/js/docbrowser/core.h
@@ -4,6 +4,7 @@
#include "infopath.h"
#include <QObject>
+#include <QVariantMap>
namespace Ui {
class MainWindow;
@@ -17,18 +18,21 @@ public:
bool load_manual (const char *manual);
void hide_prompt ();
+ void activate_input (const QString &arg);
signals:
// Signals emitted from the C++ side and received on the HTML client side.
void setUrl (const QString &text);
+ void set_current_url (const QString &text);
public slots:
// 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);
+ void show_text_input (const QString &input, const QJsonObject &data);
private:
Ui::MainWindow *ui;
+ QVariantMap index_data;
};
diff --git a/js/docbrowser/mainwindow.cpp b/js/docbrowser/mainwindow.cpp
index 7939dca0fd..17ff185313 100644
--- a/js/docbrowser/mainwindow.cpp
+++ b/js/docbrowser/mainwindow.cpp
@@ -192,6 +192,13 @@ void MainWindow::quit()
QCoreApplication::quit();
}
+
+void MainWindow::focusChanged (QWidget *old, QWidget *now)
+{
+ if (now != ui->promptCombo)
+ core->hide_prompt();
+}
+
void MainWindow::on_quitButton_clicked()
{
QCoreApplication::quit();
@@ -203,8 +210,8 @@ void MainWindow::on_loadButton_clicked()
core->load_manual (qPrintable(ui->manualEdit->text()));
}
-void MainWindow::focusChanged (QWidget *old, QWidget *now)
+
+void MainWindow::on_promptCombo_activated(const QString &arg1)
{
- if (now != ui->promptCombo)
- core->hide_prompt();
+ core->activate_input(arg1);
}
diff --git a/js/docbrowser/mainwindow.h b/js/docbrowser/mainwindow.h
index 9e46b4387b..5082548c7c 100644
--- a/js/docbrowser/mainwindow.h
+++ b/js/docbrowser/mainwindow.h
@@ -23,6 +23,7 @@ public:
private slots:
void on_quitButton_clicked();
void on_loadButton_clicked();
+ void on_promptCombo_activated(const QString &arg1);
private:
Ui::MainWindow *ui;
- [no subject], (continued)
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject],
Gavin D. Smith <=
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30