-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
96 lines (72 loc) · 2.97 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtWebEngineWidgets/QWebEngineView>
#include <QtWebEngineWidgets/QWebEnginePage>
#include <QtWebEngineWidgets/QWebEngineSettings>
#include <QWebFrame>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//Add a Google Map to the UI
QWebEngineView *webview = new QWebEngineView();
//Define where the JavaScript resource file is located
QString urlqrc = "qrc:/html/map.html";
QUrl url = QUrl(urlqrc);
checkUrl(url);
//Add the page loaded from the url to the UI
webview->page()->load(url);
ui->verticalLayout->addWidget(webview);
ui->label->setStyleSheet("QLabel { background-color : white; color : black; }");
ui->label->setFixedWidth(150);
ui->label_2->setStyleSheet("QLabel { background-color : white; color : black; }");
ui->label_2->setFixedWidth(150);
}
//***************************************************************************
// Main Window Destructor
//***************************************************************************
MainWindow::~MainWindow()
{
delete ui;
}
//***************************************************************************
// Check that the Google API caller is present and valid
//***************************************************************************
bool MainWindow::checkUrl(const QUrl &url) {
if (!url.isValid()) {
ui->mapStatusMessage->setText("Map Status... Could not fetch URL:");
//Why did the check fail?
//Is there an internet connection?
//Is the JS resource file present?
//Does the JS resource file contain errors?
return false;
}
ui->mapStatusMessage->setText("Map Status... Configured!");
return true;
}
void MainWindow::on_pushButton_clicked()
{
// // print location variables
//Add a Google Map to the UI
// QWebEngineView *webview = new QWebEngineView();
// //Define where the JavaScript resource file is located
// QString urlqrc = "qrc:/html/map.html";
// QUrl url = QUrl(urlqrc);
// checkUrl(url);
// //Add the page loaded from the url to the UI
// webview->page()->load(url);
// QWebFrame* frame = ui->webView->page()->mainFrame();
// // Get latitude and longitude variables from JavaScript
// const QVariant longitude = webview->page()->mainFrame()->evaluateJavaScript("latitude");
// const QVariant latitude = webview->page()->mainFrame()->evaluateJavaScript("latitude");
// // Display new variables on screen
// ui->label->setText(" Latitude: " + longitude);
// ui->label_2->setText(" Longitude: " + latitude);
// const QVariant myvar = webview.page()->mainFrame()->evaluateJavaScript("window.myint");
// bool ok;
// const int myint = myvar.toInt(&ok);
// if (!ok)
// qWarning() << "Error getting int from JS";
}