You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

77 lines
2.5 KiB

#include "webwidget.h"
#include "qapplication.h"
#include <QHBoxLayout>
#include <QDebug>
WebWidget::WebWidget(const QString& url, QWidget *_parent) : QWidget(_parent)
{
webView = wkeCreateWebWindow(WKE_WINDOW_TYPE_CONTROL, (HWND)_parent->winId(), 0, 0, this->width(), this->height());
wkeShowWindow(webView, TRUE);
QString _sUrl = url;
if(_sUrl.isEmpty())
_sUrl = "www.baidu.com";
wkeLoadURL(webView, _sUrl.toUtf8());
// connect()
}
WebWidget::~WebWidget()
{
qDebug() << "in del";
}
void WebWidget::loadUrl(const QString& url)
{
QString _sUrl = url;
if(_sUrl.isEmpty())
_sUrl = "www.baidu.com";
wkeLoadURL(webView, _sUrl.toLocal8Bit().data());
}
void WebWidget::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
wkeResize(webView, this->width(), this->height());
QPoint pos = this->mapToGlobal(QPoint(0, 0));
wkeMoveWindow(webView, 0, 0, this->width() + pos.x(), this->height() + pos.y() / 2);
}
void WebWidget::statusFeedbackSlot()
{
}
void WebWidget::callJsFunction(const QString &sFunctionName, const QString &sPara)
{
QString s = sFunctionName + "(\"" + sPara + "\");";
wkeRunJS(webView, s.toUtf8());
}
void WebWidget::onMove()
{
QPoint pos = this->mapToGlobal(QPoint(0, 0));
wkeMoveWindow(webView, pos.x(), pos.y(), this->width(), this->height());
}
void WebWidget::slotProcessQuit(int, QProcess::ExitStatus )
{
if(m_pWmtsProcess)
{
disconnect(m_pWmtsProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotProcessQuit(int, QProcess::ExitStatus)));
// 负责进程间通信
disconnect(m_pWmtsProcess, &QProcess::readyReadStandardError, this, &WebWidget::statusFeedbackSlot);
disconnect(m_pWmtsProcess, &QProcess::readyReadStandardOutput, this, &WebWidget::statusFeedbackSlot);
m_pWmtsProcess->deleteLater();
m_pWmtsProcess = nullptr;
}
}
void WebWidget::startWmts()
{
if(m_pWmtsProcess != nullptr)
return;
m_pWmtsProcess = new QProcess;
QString path = QCoreApplication::applicationDirPath();
m_pWmtsProcess->setProgram(path + "/wmts.exe");
m_pWmtsProcess->start(QProcess::ReadWrite);
connect(m_pWmtsProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotProcessQuit(int, QProcess::ExitStatus)));
// 负责进程间通信
connect(m_pWmtsProcess, &QProcess::readyReadStandardError, this, &WebWidget::statusFeedbackSlot);
connect(m_pWmtsProcess, &QProcess::readyReadStandardOutput, this, &WebWidget::statusFeedbackSlot);
}