MainWindow::MainWindow() { setupUi(this); webView->page()->networkAccessManager()->setCookieJar(new CookieJar); // Enable the web inspector and local storage webView->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); webView->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true); connect(webView, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished())); connect(webView, SIGNAL(loadFinished(bool)), progressBar, SLOT(hide())); connect(webView, SIGNAL(loadProgress(int)), progressBar, SLOT(setValue(int))); connect(webView, SIGNAL(loadStarted()), progressBar, SLOT(show())); connect(webView, SIGNAL(urlChanged(QUrl)), this, SLOT(onUrlChanged(QUrl))); connect(webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(onJavaScriptWindowObjectCleared())); connect(urlEdit, SIGNAL(returnPressed()), this, SLOT(loadUrl())); connect(goButton, SIGNAL(clicked()), this, SLOT(loadUrl())); // Load the JavaScript from the resource file QFile file(":/bridge.js"); file.open(QIODevice::ReadOnly); mJavaScript = file.readAll(); }
void MyWebView::initEvents() { // 委托页面所有连接在当前视图中打开 myPage->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); connect(myPage, SIGNAL(linkClicked(QUrl)), this, SLOT(onOpenUrl(QUrl))); // 对所有事件添加信号槽 connect(myFrame, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); connect(myFrame, SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(onJavaScriptWindowObjectCleared())); connect(myFrame, SIGNAL(initialLayoutCompleted()), this, SLOT(onInitialLayoutCompleted())); connect(myFrame, SIGNAL(pageChanged()), this, SLOT(onPageChanged())); connect(myFrame, SIGNAL(contentsSizeChanged(const QSize)), this, SLOT(onContentsSizeChanged(const QSize))); connect(myFrame, SIGNAL(iconChanged()), this, SLOT(onIconChanged())); connect(myFrame, SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); connect(myFrame, SIGNAL(titleChanged(const QString)), this, SLOT(onTitleChanged(const QString))); connect(myFrame, SIGNAL(urlChanged(const QUrl)), this, SLOT(onUrlChanged(const QUrl))); connect(myPage, SIGNAL(loadProgress(int)), this, SLOT(onLoadProgress(int))); connect(myPage, SIGNAL(repaintRequested(const QRect)), this, SLOT(onRepaintRequested(const QRect))); connect(myPage, SIGNAL(geometryChangeRequested(const QRect)), this, SLOT(onGeometryChangeRequested(const QRect))); connect(newManager, SIGNAL(requestFinished(QString)), this, SLOT(onRequestFinished(QString))); connect(newManager, SIGNAL(requestStart(QString)), this, SLOT(onRequestStart(QString))); };
GSuperWebPage::GSuperWebPage(WebPageWrapper *page, ChromeWidget *chromeWidget) : GWebPage(page), m_chromeWidget(chromeWidget) { if (!m_page) { m_page = new WebPageWrapper(this, "Superpage javascript error"); } //qDebug() << "GSuperWebPage::GSuperWebPage: page=" << GWebPage::page(); connect(GWebPage::page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(onJavaScriptWindowObjectCleared())); }
Kludget::Kludget(KClient *parent) : QObject(parent), client(parent), window(new KWindow), settings(new KSettings(this)), system(new KSystem(this)), prefWindow(0), aboutWindow(0), firstShow(true) { setObjectName("Kludget"); settings->setRootKey("kludget"); connect(system, SIGNAL(execUpdate(long)), this, SLOT(onSystemExecUpdate(long))); connect(system, SIGNAL(execFinish(long)), this, SLOT(onSystemExecFinish(long))); connect(window, SIGNAL(destroyed()), this, SLOT(onWindowDestroyed())); connect(window, SIGNAL(onShow()), this, SLOT(onShow())); connect(window, SIGNAL(onHide()), this, SLOT(onHide())); connect(window, SIGNAL(onStartDrag()), this, SLOT(onStartDrag())); connect(window, SIGNAL(onEndDrag()), this, SLOT(onEndDrag())); connect(window, SIGNAL(onSettingsChanged()), this, SLOT(onSettingsChanged())); connect(window->view(), SIGNAL(contextMenuRequested()), this, SLOT(onContextMenu())); connect(window->view(), SIGNAL(urlReceived(const QUrl*)), this, SLOT(onUrlReceived(const QUrl*))); connect(window->view()->page(), SIGNAL(loadFinished(bool)), this, SLOT(show())); connect(window->view()->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(onJavaScriptWindowObjectCleared())); connect(window->view()->page(), SIGNAL(frameCreated(QWebFrame*)), this, SLOT(onFrameCreated(QWebFrame*))); connect(this, SIGNAL(evaluate(const QString &)), this, SLOT(onEvaluate(const QString &))); connect(&customMenuMapper, SIGNAL(mapped(const QString &)), this, SIGNAL(evaluate(const QString &))); connect(&ipcClient, SIGNAL(messageReceived(QString,QString,QString)), this, SLOT(messageReceived(QString,QString,QString))); KLog::log("Kludget::created"); }