Пример #1
0
ShibbolethWebView::ShibbolethWebView(Account* account, QWidget* parent)
    : QWebView(parent)
    , _account(account)
    , _accepted(false)
    , _cursorOverriden(false)
{
    // no minimize
    setWindowFlags(Qt::Dialog);
    setAttribute(Qt::WA_DeleteOnClose);
    QWebPage* page = new QWebPage(this);
    page->setNetworkAccessManager(account->networkAccessManager());
    connect(page, SIGNAL(loadStarted()),
            this, SLOT(slotLoadStarted()));
    connect(page, SIGNAL(loadFinished(bool)),
            this, SLOT(slotLoadFinished(bool)));


    connect(page->networkAccessManager()->cookieJar(),
            SIGNAL(newCookiesForUrl (QList<QNetworkCookie>, QUrl)),
            this, SLOT(onNewCookiesForUrl (QList<QNetworkCookie>, QUrl)));
    page->mainFrame()->load(account->url());
    this->setPage(page);
    setWindowTitle(tr("%1 - Authenticate").arg(Theme::instance()->appNameGUI()));

    // If we have a valid cookie, it's most likely expired. We can use this as
    // as a criteria to tell the user why the browser window pops up
    QNetworkCookie shibCookie = ShibbolethCredentials::findShibCookie(_account, ShibbolethCredentials::accountCookies(_account));
    if (shibCookie != QNetworkCookie()) {
        Logger::instance()->postOptionalGuiLog(tr("Reauthentication required"), tr("Your session has expired. You need to re-login to continue to use the client."));
    }
}
Пример #2
0
void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
{
  Q_UNUSED( itemStyle );
  Q_UNUSED( pWidget );
  if ( !painter )
  {
    return;
  }
  if ( !shouldDrawItem() )
  {
    return;
  }

  drawBackground( painter );
  painter->save();

  //antialiasing on
  painter->setRenderHint( QPainter::Antialiasing, true );

  double penWidth = hasFrame() ? pen().widthF() : 0;
  QRectF painterRect( penWidth + mMargin, penWidth + mMargin, rect().width() - 2 * penWidth - 2 * mMargin, rect().height() - 2 * penWidth - 2 * mMargin );

  QString textToDraw = displayText();

  if ( mHtmlState )
  {
    painter->scale( 1.0 / mHtmlUnitsToMM / 10.0, 1.0 / mHtmlUnitsToMM / 10.0 );
    QWebPage *webPage = new QWebPage();
    webPage->setNetworkAccessManager( QgsNetworkAccessManager::instance() );

    //Setup event loop and timeout for rendering html
    QEventLoop loop;
    QTimer timeoutTimer;
    timeoutTimer.setSingleShot( true );

    //This makes the background transparent. Found on http://blog.qt.digia.com/blog/2009/06/30/transparent-qwebview-or-qwebpage/
    QPalette palette = webPage->palette();
    palette.setBrush( QPalette::Base, Qt::transparent );
    webPage->setPalette( palette );
    //webPage->setAttribute(Qt::WA_OpaquePaintEvent, false); //this does not compile, why ?

    webPage->setViewportSize( QSize( painterRect.width() * mHtmlUnitsToMM * 10.0, painterRect.height() * mHtmlUnitsToMM * 10.0 ) );
    webPage->mainFrame()->setZoomFactor( 10.0 );
    webPage->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
    webPage->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );

    // QGIS segfaults when rendering web page while in composer if html
    // contains images. So if we are not printing the composition, then
    // disable image loading
    if ( mComposition->plotStyle() != QgsComposition::Print &&
         mComposition->plotStyle() != QgsComposition::Postscript )
    {
      webPage->settings()->setAttribute( QWebSettings::AutoLoadImages, false );
    }

    //Connect timeout and webpage loadFinished signals to loop
    connect( &timeoutTimer, SIGNAL( timeout() ), &loop, SLOT( quit() ) );
    connect( webPage, SIGNAL( loadFinished( bool ) ), &loop, SLOT( quit() ) );

    //mHtmlLoaded tracks whether the QWebPage has completed loading
    //its html contents, set it initially to false. The loadingHtmlFinished slot will
    //set this to true after html is loaded.
    mHtmlLoaded = false;
    connect( webPage, SIGNAL( loadFinished( bool ) ), SLOT( loadingHtmlFinished( bool ) ) );

    webPage->mainFrame()->setHtml( textToDraw );

    //For very basic html labels with no external assets, the html load will already be
    //complete before we even get a chance to start the QEventLoop. Make sure we check
    //this before starting the loop
    if ( !mHtmlLoaded )
    {
      // Start a 20 second timeout in case html loading will never complete
      timeoutTimer.start( 20000 );
      // Pause until html is loaded
      loop.exec();
    }
    webPage->mainFrame()->render( painter );//DELETE WEBPAGE ?
  }
  else
  {
Пример #3
0
void MainWindow::init(bool is_development) {
    //qApp->installEventFilter(this);
  
    setWindowTitle(settings->value("window_title").toString());

    if (settings->value("minified_state").toString() == "true") {
        setWindowState(Qt::WindowMinimized);
    }

    this->setMinimumWidth(430);
    this->setMinimumHeight(430);

    webView = new QWebView(this);
    if (settings->value("context_menu").toString() == "false") {
        webView->setContextMenuPolicy(Qt::NoContextMenu);
    }
    this->setCentralWidget(webView);

    m_network_manager = new QNetworkAccessManager(this);

    QWebPage *webPage = webView->page();
    webPage->setNetworkAccessManager(m_network_manager);
    webPage->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
    connect(webPage, &QWebPage::linkClicked, this, &MainWindow::onLinkClicked);
    connect(webPage->mainFrame(), &QWebFrame::javaScriptWindowObjectCleared, this, &MainWindow::attachJsApi);

    webView->show();

    bootstrap(is_development);

    // restore saved window geometry from .ini file
    QVariant size = settings->value("main_window_geometry");
    if ( size.isNull() ) {
        this->setGeometry(QRect(500, 100, 700, 500));
    } else {
        this->setGeometry(size.toRect());
    }

    // restore saved zoom factor from .ini file
    qreal z = settings->value("zoom_factor").toReal();
    if ( z ) webView->page()->mainFrame()->setZoomFactor(z);

    m_jsApi = new JsApi(this);

    optionsDialog = new OptionsDialog(this);
    optionsDialog->m_version = m_version;
    connect(optionsDialog, SIGNAL(accepting()), m_jsApi, SLOT(onOptionsDialogAccepted()));

    QShortcut *zoomin = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Plus), this);
    connect(zoomin, &QShortcut::activated, this, &MainWindow::onZoomIn);

    QShortcut *zoomout = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Minus), this);
    connect(zoomout, &QShortcut::activated, this, &MainWindow::onZoomOut);

    QShortcut *shutdown = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this);
    connect(shutdown, &QShortcut::activated, m_jsApi, &JsApi::shutdown);

    QWebSettings::setObjectCacheCapacities(0, 0, 0);

    if (settings->value("webinspector").toString() == "true") {
        QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);

        QWebInspector *inspector;
        inspector = new QWebInspector();
        inspector->setPage(webView->page());
        inspector->setGeometry(QRect(500, 10, 1000, 700));
        inspector->show();
    }

    QIcon icon = QIcon(application_path + "/" + APPNAME + ".png");
    m_trayIcon = new QSystemTrayIcon(this);
    m_trayIcon->setIcon(icon);
    m_trayIcon->show();
    connect(m_trayIcon, &QSystemTrayIcon::messageClicked, m_jsApi, &JsApi::onTrayMessageClicked);
    connect(m_trayIcon, &QSystemTrayIcon::activated, m_jsApi, &JsApi::onTrayIconActivated);
}
Пример #4
0
void QWebPageProto::setNetworkAccessManager(QNetworkAccessManager * manager)
{
  QWebPage *item = qscriptvalue_cast<QWebPage*>(thisObject());
  if (item)
    item->setNetworkAccessManager(manager);
}