Exemple #1
0
void TitleBar::onCommentsButtonClicked()
{
#ifdef USEWEBENGINE
    QWebEngineView* comments = noteView()->commentView();
#else
    QWebView* comments = noteView()->commentView();
#endif
    if (comments->isVisible()) {
        comments->hide();
        return;
    }

    if (isNetworkAccessible()) {
        if (!m_commentsUrl.isEmpty()) {
            comments->load(m_commentsUrl);
            QSplitter* splitter = qobject_cast<QSplitter*>(comments->parentWidget());
            Q_ASSERT(splitter);
            QList<int> li = splitter->sizes();
            Q_ASSERT(li.size() == 2);
            QList<int> lin;
            lin.push_back(li.value(0) - COMMENT_FRAME_WIDTH);
            lin.push_back(li.value(1) + COMMENT_FRAME_WIDTH);
            splitter->setSizes(lin);
            comments->show();
        } else {
            loadErrorPage();
            comments->show();
        }

    } else {
        m_commentsBtn->setEnabled(false);
    }
}
Exemple #2
0
/*------------------------------------------------------------------------------
|    main
+-----------------------------------------------------------------------------*/
int main(int argc, char* argv[])
{
	QApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
	QApplication a(argc, argv);

	QStringList args = a.arguments();
	const bool opengl = !args.contains("--no-opengl");
	args.removeAll("--no-opengl");

	if (opengl) {
		qDebug("QML QtWebEngine...");

		QQuickView* view = new QQuickView;
		view->setSource(QUrl("qrc:/poc_main.qml"));
		view->showFullScreen();

		QObject* o = view->rootObject()->findChild<QObject*>("webEngineView");
		o->setProperty("url", args.at(1));
	}
	else {
		qDebug("Widget QtWebEngine...");

		QWebEngineView* view = new QWebEngineView;
		view->load(QUrl(args.at(1)));
		view->show();
	}

	return a.exec();
}
Exemple #3
0
void TitleBar::onCommentPageLoaded(bool ok)
{
#ifdef USEWEBENGINE
    QWebEngineView* comments = noteView()->commentView();
#else
    QWebView* comments = noteView()->commentView();
#endif
    if (!ok)
    {
        loadErrorPage();
        comments->show();
    }
#ifdef USEWEBENGINE
    else
    {
        comments->page()->runJavaScript("location.protocol",[this](const QVariant& returnValue) {
            qDebug() << "lcation protocol :  " << returnValue.toString();
            if ("file:" != returnValue.toString())
            {
                registerWebChannel();
            }
        });
    }
#endif
}
Exemple #4
0
int main(int argc, char** argv)
{
	QApplication a(argc, argv);
	QWebEngineView v;
	v.load(QUrl("http://www.baidu.com"));
	v.show();
	return a.exec();
}
void LoginManager::loginInteractive()
      {
      QWebEngineView* webView = new QWebEngineView;
      webView->setWindowModality(Qt::ApplicationModal);
      webView->setAttribute(Qt::WA_DeleteOnClose);

      QWebEnginePage* page = webView->page();
      QWebEngineProfile* profile = page->profile();
      // TODO: logout in editor does not log out in web view
      profile->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
      profile->setRequestInterceptor(new ApiWebEngineRequestInterceptor(profile));

      //workaround for the crashes sometimes happend in Chromium on macOS with Qt 5.12
      connect(webView, &QWebEngineView::renderProcessTerminated, this, [profile, webView](QWebEnginePage::RenderProcessTerminationStatus terminationStatus, int exitCode)
              {
              qDebug() << "Login page loading terminated" << terminationStatus << " " << exitCode;
              profile->clearHttpCache();
              webView->show();
              });
      
      connect(page, &QWebEnginePage::loadFinished, this, [this, page, webView](bool ok) {
            if (!ok)
                  return;
            constexpr QUrl::FormattingOptions cmpOpt = QUrl::RemoveQuery | QUrl::RemoveFragment | QUrl::StripTrailingSlash;
            if (!page->url().matches(ApiInfo::loginSuccessUrl, cmpOpt))
                  return;

            page->runJavaScript("JSON.stringify(muGetAuthInfo())", [this, page, webView](const QVariant& v) {
                  onLoginReply(nullptr, HTTP_OK, QJsonDocument::fromJson(v.toString().toUtf8()).object());
                  // We have retrieved an access token, do not remain logged
                  // in with web view profile.
                  page->profile()->cookieStore()->deleteAllCookies();
                  webView->close();
                  });
            });

      webView->load(ApiInfo::loginUrl);
      webView->show();
      }
void PublisherPage::show()
{
    QWebEngineView *view = new QWebEngineView;
    QDir dir;
    QString cwd = dir.currentPath();
    QString html = "qrc:///vpub/index.html";
    QString fpath = "/src/qt/res/vpub/index.html";
    QString res = cwd + fpath;
    QFile file(res);
    // QFile file("file:////res/pbt/index.html");
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        html = QString("<html><body><p>Cannot read file in ") + res + QString("</p></body></html>");
    } else {
        html = QTextStream(&file).readAll();
    };
    view->setHtml(html, QUrl());
    view->show();
}
Exemple #7
0
QWebChannel * SetupWebView()
{
    QFileInfo jsFileInfo(QDir::currentPath() + QString::fromLatin1("/qwebchannel.js"));

    if (!jsFileInfo.exists())
        QFile::copy(QString::fromLatin1(":/qtwebchannel/qwebchannel.js"), jsFileInfo.absoluteFilePath());

    QtWebEngine::initialize();
    QWebEngineView * view = new QWebEngineView();

    QWebChannel * channel = new QWebChannel(view->page());
    view->page()->setWebChannel(channel);

    view->load(QUrl(QString::fromLatin1("qrc:/demo.html")));
    view->show();

    return channel;
}
Exemple #8
0
int main(int argc, char *argv[])
{
    TaskConfig agent_cfg, config;
    if (!parseArgs(argc, argv, config, agent_cfg))
        return 1;
    agent_cfg.set("Measure.AutoSaveReport", "true");
    std::ofstream log_file;
    if (config.value("logfile") != "-") {
        log_file.open(config.value("logfile"));
        Logger::setLogFile(log_file);
    }

    config.set("listen_pw", MeasurementAgent::createHashKey(12));
    config.set("listen", "0");
    config.set("listen_addr", "127.0.0.1");
    config.set("browser",  "2");
    agent_cfg.set("config_file", config.value("config_file"));

    WebsocketBridge *bridge = new WebsocketBridge(nullptr, config);
    std::thread agent_thread(runAgent, bridge, agent_cfg);

    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QApplication app(argc, argv);
    QWebEngineView view;
    view.resize(700, 950);
    view.show();

    // Wait for a few seconds for the agent to start listening on a port
    for (unsigned int i = 0; bridge->url().empty() && i < 400; ++i)
        std::this_thread::sleep_for(std::chrono::milliseconds(1+i/10));

    int ret;
    if (bridge->url().empty()) {
        std::cerr << "cannot start measurement engine";
        ret = 1;
    } else {
        view.setUrl(QUrl(bridge->url().c_str()));
        ret = app.exec();
    }

    bridge->die();
    agent_thread.join();
    return ret;
}
Exemple #9
0
int main(int argc, char *argv[]) {

    // инициализация окна
    QApplication a(argc, argv);
    QWebEngineView *view = new QWebEngineView();

    // размеры окна
    int WIDTH = 1024;
    int HEIGHT = 520;

    // размеры Desktop
    int screenWidth;
    int screenHeight;

    // centered
    int x, y;

    // расчет значений Desktop
    QDesktopWidget *desktop = QApplication::desktop();
    screenWidth = desktop->width();
    screenHeight = desktop->height();

    // новые значения
    x = (screenWidth - WIDTH) / 2;
    y = (screenHeight - HEIGHT) / 2;

    // центрируем window
    view->resize(WIDTH, HEIGHT);
    view->move(x, y);

    // title window
    view->setWindowTitle("Игра жизнь");

    // отключаем ненужные Qt события
    view->setContextMenuPolicy(Qt::CustomContextMenu);

    // подгружаем визуализацию
    view->load(QUrl("qrc:live.html"));
    view->show();

    return a.exec();
}
Exemple #10
0
void MainWindow::openPDFWindow(QString url){
    QWebEngineView * pdfView;
    if(!pdfViewList.contains(url)){
        pdfView = new QWebEngineView(0);
        QUrl theurl = QUrl(url);
        pdfView->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);

        pdfView->load( theurl );
        pdfView->show();
        pdfViewList.insert(url, pdfView);
        pdfView->setAttribute(Qt::WA_DeleteOnClose);
        pdfView->showNormal();

        int frameHeight = pdfView->frameGeometry().height()-pdfView->geometry().height();
        pdfView->move( (screenRect.width() - 640)/2, screenRect.y() );
        pdfView->resize( 640, screenRect.height()-frameHeight );

        connect(pdfView, SIGNAL(destroyed(QObject*)), this, SLOT(onPDFViewClose(QObject*)) );
        //pdfView->settings()->enablePersistentStorage(QDir::tempPath());
        QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);

    }else{
void GUIHelpViewer::show()
{
	QWebEngineView *view = new QWebEngineView();
	view->load(QUrl(this->currentUrl));
	view->show();
}
Exemple #12
0
// ============= QWebEngine ====================
extern "C" MSVC_API void qteQWebEng_init() {
    QWebEngineView *view = new QWebEngineView(NULL);
    view->load(QUrl("http://qt-project.org/"));
    view->show();
}
Exemple #13
-1
void QRestClient::displayHtml(QByteArray html)
{
    QWebEngineView *view = new QWebEngineView();
    view->setAttribute(Qt::WA_DeleteOnClose);
    view->setHtml(html);
    view->show();
}