WebView::WebView(QWidget *parent) : QWebView(parent) , m_progress(0) , m_currentZoom(100) , m_page(new WebPage(this)) #if QT_VERSION >= 0x040600 || defined(WEBKIT_TRUNK) , m_enableAccessKeys(true) , m_accessKeysPressed(false) #endif { setPage(m_page); #if QT_VERSION >= 0x040600 QPalette p; if (p.color(QPalette::Window) != Qt::white) { QWindowsStyle s; p = s.standardPalette(); setPalette(p); } #endif connect(page(), SIGNAL(statusBarMessage(const QString&)), SLOT(setStatusBarText(const QString&))); connect(this, SIGNAL(loadProgress(int)), this, SLOT(setProgress(int))); connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished())); connect(page(), SIGNAL(aboutToLoadUrl(const QUrl &)), this, SIGNAL(urlChanged(const QUrl &))); connect(page(), SIGNAL(downloadRequested(const QNetworkRequest &)), this, SLOT(downloadRequested(const QNetworkRequest &))); connect(BrowserApplication::instance(), SIGNAL(zoomTextOnlyChanged(bool)), this, SLOT(applyZoom())); page()->setForwardUnsupportedContent(true); setAcceptDrops(true); // the zoom values (in percent) are chosen to be like in Mozilla Firefox 3 m_zoomLevels << 30 << 50 << 67 << 80 << 90; m_zoomLevels << 100; m_zoomLevels << 110 << 120 << 133 << 150 << 170 << 200 << 240 << 300; #if QT_VERSION >= 0x040600 || defined(WEBKIT_TRUNK) connect(m_page, SIGNAL(loadStarted()), this, SLOT(hideAccessKeys())); connect(m_page, SIGNAL(scrollRequested(int, int, const QRect &)), this, SLOT(hideAccessKeys())); #endif loadSettings(); FlickCharm* flickCharm = new FlickCharm(this); flickCharm->activateOn(this); }
WebView::WebView(KWebKitPart* part, QWidget* parent) :KWebView(parent, false), m_actionCollection(new KActionCollection(this)), m_part(part), m_webInspector(0), m_autoScrollTimerId(-1), m_verticalAutoScrollSpeed(0), m_horizontalAutoScrollSpeed(0), m_accessKeyActivated(NotActivated) { setAcceptDrops(true); // Create the custom page... setPage(new WebPage(part, this)); connect(this, SIGNAL(loadStarted()), this, SLOT(slotStopAutoScroll())); connect(this, SIGNAL(loadStarted()), this, SLOT(hideAccessKeys())); connect(page(), SIGNAL(scrollRequested(int,int,QRect)), this, SLOT(hideAccessKeys())); if (WebKitSettings::self()->zoomToDPI()) setZoomFactor(logicalDpiY() / 96.0f); }
void WebView::loadStarted() { hideAccessKeys(); }
void WebView::keyPressEvent(QKeyEvent* e) { if (e && hasFocus()) { const int key = e->key(); if (WebKitSettings::self()->accessKeysEnabled()) { if (m_accessKeyActivated == Activated) { if (checkForAccessKey(e)) { hideAccessKeys(); e->accept(); return; } hideAccessKeys(); } else if (e->key() == Qt::Key_Control && e->modifiers() == Qt::ControlModifier && !isEditableElement(page())) { m_accessKeyActivated = PreActivated; // Only preactive here, it will be actually activated in key release. } } if (e->modifiers() & Qt::ShiftModifier) { switch (key) { case Qt::Key_Up: if (!isEditableElement(page())) { m_verticalAutoScrollSpeed--; if (m_autoScrollTimerId == -1) m_autoScrollTimerId = startTimer(100); e->accept(); return; } break; case Qt::Key_Down: if (!isEditableElement(page())) { m_verticalAutoScrollSpeed++; if (m_autoScrollTimerId == -1) m_autoScrollTimerId = startTimer(100); e->accept(); return; } break; case Qt::Key_Left: if (!isEditableElement(page())) { m_horizontalAutoScrollSpeed--; if (m_autoScrollTimerId == -1) m_autoScrollTimerId = startTimer(100); e->accept(); return; } break; case Qt::Key_Right: if (!isEditableElement(page())) { m_horizontalAutoScrollSpeed--; if (m_autoScrollTimerId == -1) m_autoScrollTimerId = startTimer(100); e->accept(); return; } break; default: break; } } else if (m_autoScrollTimerId != -1) { // kDebug() << "scroll timer id:" << m_autoScrollTimerId; slotStopAutoScroll(); e->accept(); return; } } KWebView::keyPressEvent(e); }