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 97 98 99 100 101 102 103 104
|
/***************************************************************************
* copyright : (C) 2009-2019 by Pascal Brachet *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "algowebpage.h"
#include <QMessageBox>
#include <QInputDialog>
#include <QDebug>
AlgoWebPage::AlgoWebPage(QObject* parent, AlgoConsole* cons):QWebEnginePage(parent)
{
result=false;
stop=false;
QObject::connect(&timer, SIGNAL(timeout()), &loop_aff, SLOT(quit()));
console=cons;
}
AlgoWebPage::~AlgoWebPage(){
loop_pause.quit();
loop_aff.quit();
timer.disconnect();
stop=true;
}
void AlgoWebPage::javaScriptAlert(const QUrl &securityOrigin, const QString& msg)
{
if (!stop) QMessageBox::information(this->view(),"AlgoBox", msg, QMessageBox::Ok);
}
bool AlgoWebPage::javaScriptPrompt(const QUrl &securityOrigin, const QString& msg, const QString& defaultValue, QString* result)
{
if (stop) return true;
// bool ok = false;
QStringList msglist=msg.split("\n");
console->output(msglist.at(0));
QEventLoop loop;
QObject::connect(console, SIGNAL(done()), &loop, SLOT(quit()));
loop.exec();
*result=console->answer;
if (result) return true;
else return false;
// QString texte="<b><span style=\"font-size:13pt;\">"+msglist.at(0)+"</span></b>";
// if (msglist.count()==3) texte+="<br><i>"+msglist.at(1)+"<br>"+msglist.at(2)+"</i>";
// QString x = QInputDialog::getText(this->view(), "AlgoBox", texte , QLineEdit::Normal, defaultValue, &ok);
// if (ok && result) {
// *result = x;
// }
// return ok;
}
bool AlgoWebPage::javaScriptConfirm(const QUrl &securityOrigin, const QString& msg)
{
if (stop) return true;
if (msg=="Pause")
{
loop_pause.exec();
return result;
}
else return QMessageBox::Yes == QMessageBox::information(this->view(),"AlgoBox", msg, QMessageBox::Yes, QMessageBox::No);
}
bool AlgoWebPage::shouldInterruptJavaScript()
{
return false;
}
void AlgoWebPage::continuer()
{
result=true;
loop_pause.quit();
}
void AlgoWebPage::arreter()
{
result=false;
loop_pause.quit();
}
void AlgoWebPage::stopaffichage()
{
stop=true;
}
void AlgoWebPage::minipause()
{
loop_aff.quit();
if (stop) {timer.disconnect();return;}
timer.setSingleShot(true);
timer.start(10);
loop_aff.exec();
}
|