EmbeddedWebView::EmbeddedWebView(QWidget *parent, QNetworkAccessManager *networkManager) : QWebView(parent) , m_scrollParent(nullptr) , m_resizeInProgress(0) , m_staticWidth(0) , m_colorScheme(ColorScheme::System) { // set to expanding, ie. "freely" - this is important so the widget will attempt to shrink below the sizehint! setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setFocusPolicy(Qt::StrongFocus); // not by the wheel setPage(new ErrorCheckingPage(this)); page()->setNetworkAccessManager(networkManager); QWebSettings *s = settings(); s->setAttribute(QWebSettings::JavascriptEnabled, false); s->setAttribute(QWebSettings::JavaEnabled, false); s->setAttribute(QWebSettings::PluginsEnabled, false); s->setAttribute(QWebSettings::PrivateBrowsingEnabled, true); s->setAttribute(QWebSettings::JavaEnabled, false); s->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, false); s->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, false); s->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, false); s->clearMemoryCaches(); page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); connect(this, &QWebView::linkClicked, this, &EmbeddedWebView::slotLinkClicked); connect(this, &QWebView::loadFinished, this, &EmbeddedWebView::handlePageLoadFinished); connect(page()->mainFrame(), &QWebFrame::contentsSizeChanged, this, &EmbeddedWebView::handlePageLoadFinished); // Scrolling is implemented on upper layers page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); // Setup shortcuts for standard actions QAction *copyAction = page()->action(QWebPage::Copy); copyAction->setShortcut(tr("Ctrl+C")); addAction(copyAction); m_autoScrollTimer = new QTimer(this); m_autoScrollTimer->setInterval(50); connect(m_autoScrollTimer, &QTimer::timeout, this, &EmbeddedWebView::autoScroll); m_sizeContrainTimer = new QTimer(this); m_sizeContrainTimer->setInterval(50); m_sizeContrainTimer->setSingleShot(true); connect(m_sizeContrainTimer, &QTimer::timeout, this, &EmbeddedWebView::constrainSize); setContextMenuPolicy(Qt::NoContextMenu); findScrollParent(); addCustomStylesheet(QString()); }
EmbeddedWebView::EmbeddedWebView(QWidget *parent, QNetworkAccessManager *networkManager): QWebView(parent), m_scrollParent(0L), m_resizeInProgress(0) { // set to expanding, ie. "freely" - this is important so the widget will attempt to shrink below the sizehint! setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setFocusPolicy(Qt::StrongFocus); // not by the wheel setPage(new ErrorCheckingPage(this)); page()->setNetworkAccessManager(networkManager); QWebSettings *s = settings(); s->setAttribute(QWebSettings::JavascriptEnabled, false); s->setAttribute(QWebSettings::JavaEnabled, false); s->setAttribute(QWebSettings::PluginsEnabled, false); s->setAttribute(QWebSettings::PrivateBrowsingEnabled, true); s->setAttribute(QWebSettings::JavaEnabled, false); s->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, false); s->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, false); s->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, false); s->clearMemoryCaches(); page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); connect(this, SIGNAL(linkClicked(QUrl)), this, SLOT(slotLinkClicked(QUrl))); connect(this, SIGNAL(loadFinished(bool)), this, SLOT(handlePageLoadFinished())); connect(page()->mainFrame(), SIGNAL(contentsSizeChanged(QSize)), this, SLOT(handlePageLoadFinished())); // Scrolling is implemented on upper layers page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); // Setup shortcuts for standard actions QAction *copyAction = page()->action(QWebPage::Copy); copyAction->setShortcut(tr("Ctrl+C")); addAction(copyAction); // Redmine#3, the QWebView uses black text color when rendering stuff on dark background QPalette palette = QApplication::palette(); if (palette.background().color().lightness() < 50) { QStyle *style = QStyleFactory::create(QLatin1String("windows")); Q_ASSERT(style); palette = style->standardPalette(); setPalette(palette); } setContextMenuPolicy(Qt::NoContextMenu); findScrollParent(); }