mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
Added context menu controls for Html 5 video/audio
- also fixed little issue when restoring tabs (bad order of restored tabs)
This commit is contained in:
parent
dfc667e785
commit
f8fea1f32e
@ -344,14 +344,20 @@ void TabbedWebView::contextMenuEvent(QContextMenuEvent* event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QWebElement element = r.element();
|
QWebElement element = r.element();
|
||||||
if (!element.isNull() && (element.tagName().toLower() == "input" || element.tagName().toLower() == "textarea" ||
|
if (!element.isNull() && (element.tagName().toLower() == "input" || element.tagName().toLower() == "textarea")) {
|
||||||
element.tagName().toLower() == "video" || element.tagName().toLower() == "audio")) {
|
|
||||||
if (m_menu->isEmpty()) {
|
if (m_menu->isEmpty()) {
|
||||||
page()->createStandardContextMenu()->popup(QCursor::pos());
|
page()->createStandardContextMenu()->popup(QCursor::pos());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isMediaElement(element)) {
|
||||||
|
if (m_menu->isEmpty()) {
|
||||||
|
createMediaContextMenu(r)->popup(QCursor::pos());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (m_menu->isEmpty() && selectedText().isEmpty()) {
|
if (m_menu->isEmpty() && selectedText().isEmpty()) {
|
||||||
QAction* action = m_menu->addAction(tr("&Back"), this, SLOT(back()));
|
QAction* action = m_menu->addAction(tr("&Back"), this, SLOT(back()));
|
||||||
action->setIcon(IconProvider::standardIcon(QStyle::SP_ArrowBack));
|
action->setIcon(IconProvider::standardIcon(QStyle::SP_ArrowBack));
|
||||||
|
@ -515,7 +515,7 @@ void TabWidget::restoreAllClosedTabs()
|
|||||||
|
|
||||||
QList<ClosedTabsManager::Tab> closedTabs = m_closedTabsManager->allClosedTabs();
|
QList<ClosedTabsManager::Tab> closedTabs = m_closedTabsManager->allClosedTabs();
|
||||||
foreach(ClosedTabsManager::Tab tab, closedTabs) {
|
foreach(ClosedTabsManager::Tab tab, closedTabs) {
|
||||||
int index = addView(QUrl(), tab.title, Qz::NT_CleanNotSelectedTab);
|
int index = addView(QUrl(), tab.title, Qz::NT_CleanSelectedTab);
|
||||||
QDataStream historyStream(tab.history);
|
QDataStream historyStream(tab.history);
|
||||||
historyStream >> *weView(index)->history();
|
historyStream >> *weView(index)->history();
|
||||||
|
|
||||||
@ -608,7 +608,7 @@ void TabWidget::restorePinnedTabs()
|
|||||||
QByteArray historyState = tabHistory.value(i);
|
QByteArray historyState = tabHistory.value(i);
|
||||||
int addedIndex;
|
int addedIndex;
|
||||||
if (!historyState.isEmpty()) {
|
if (!historyState.isEmpty()) {
|
||||||
addedIndex = addView(QUrl(), Qz::NT_CleanNotSelectedTab);
|
addedIndex = addView(QUrl(), Qz::NT_CleanSelectedTab);
|
||||||
QDataStream historyStream(historyState);
|
QDataStream historyStream(historyState);
|
||||||
historyStream >> *weView(addedIndex)->history();
|
historyStream >> *weView(addedIndex)->history();
|
||||||
weView(addedIndex)->load(url);
|
weView(addedIndex)->load(url);
|
||||||
@ -684,7 +684,7 @@ bool TabWidget::restoreState(const QByteArray &state)
|
|||||||
|
|
||||||
QByteArray historyState = tabHistory.value(i);
|
QByteArray historyState = tabHistory.value(i);
|
||||||
if (!historyState.isEmpty()) {
|
if (!historyState.isEmpty()) {
|
||||||
int index = addView(QUrl(), Qz::NT_CleanNotSelectedTab);
|
int index = addView(QUrl(), Qz::NT_CleanSelectedTab);
|
||||||
QDataStream historyStream(historyState);
|
QDataStream historyStream(historyState);
|
||||||
historyStream >> *weView(index)->history();
|
historyStream >> *weView(index)->history();
|
||||||
weView(index)->load(url);
|
weView(index)->load(url);
|
||||||
|
@ -366,6 +366,65 @@ QUrl WebView::lastUrl()
|
|||||||
return m_lastUrl;
|
return m_lastUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WebView::isMediaElement(const QWebElement &element)
|
||||||
|
{
|
||||||
|
return (element.tagName().toLower() == "video" || element.tagName().toLower() == "audio");
|
||||||
|
}
|
||||||
|
|
||||||
|
QMenu *WebView::createMediaContextMenu(const QWebHitTestResult &hitTest)
|
||||||
|
{
|
||||||
|
QMenu* menu = new QMenu(this);
|
||||||
|
m_mediaElement = hitTest.element();
|
||||||
|
|
||||||
|
bool paused = m_mediaElement.evaluateJavaScript("this.paused").toBool();
|
||||||
|
bool muted = m_mediaElement.evaluateJavaScript("this.muted").toBool();
|
||||||
|
QUrl videoUrl = m_mediaElement.evaluateJavaScript("this.currentSrc").toUrl();
|
||||||
|
|
||||||
|
menu->addAction(paused ? tr("Un&pause") : tr("&Pause"), this, SLOT(pauseMedia()));
|
||||||
|
menu->addAction(muted ? tr("Un&mute") : tr("&Mute"), this, SLOT(muteMedia()));
|
||||||
|
menu->addSeparator();
|
||||||
|
menu->addAction(tr("Copy Media &Address"), this, SLOT(copyLinkToClipboard()))->setData(videoUrl);
|
||||||
|
menu->addAction(tr("&Download Media To Disk"), this, SLOT(downloadLinkToDisk()))->setData(videoUrl);
|
||||||
|
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebView::pauseMedia()
|
||||||
|
{
|
||||||
|
bool paused = m_mediaElement.evaluateJavaScript("this.paused").toBool();
|
||||||
|
|
||||||
|
if (paused) {
|
||||||
|
m_mediaElement.evaluateJavaScript("this.play()");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_mediaElement.evaluateJavaScript("this.pause()");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebView::muteMedia()
|
||||||
|
{
|
||||||
|
bool muted = m_mediaElement.evaluateJavaScript("this.muted").toBool();
|
||||||
|
|
||||||
|
if (muted) {
|
||||||
|
m_mediaElement.evaluateJavaScript("this.muted = false");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_mediaElement.evaluateJavaScript("this.muted = true");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebView::controlsMedia()
|
||||||
|
{
|
||||||
|
bool controls= m_mediaElement.evaluateJavaScript("this.controls").toBool();
|
||||||
|
|
||||||
|
if (controls) {
|
||||||
|
m_mediaElement.evaluateJavaScript("this.controls = false");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_mediaElement.evaluateJavaScript("this.controls = true");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WebView::wheelEvent(QWheelEvent* event)
|
void WebView::wheelEvent(QWheelEvent* event)
|
||||||
{
|
{
|
||||||
if (event->modifiers() & Qt::ControlModifier) {
|
if (event->modifiers() & Qt::ControlModifier) {
|
||||||
|
@ -95,6 +95,15 @@ protected:
|
|||||||
void copyText();
|
void copyText();
|
||||||
QUrl lastUrl();
|
QUrl lastUrl();
|
||||||
|
|
||||||
|
bool isMediaElement(const QWebElement &element);
|
||||||
|
|
||||||
|
QMenu* createMediaContextMenu(const QWebHitTestResult &hitTest);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void pauseMedia();
|
||||||
|
void muteMedia();
|
||||||
|
void controlsMedia();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<int> m_zoomLevels;
|
QList<int> m_zoomLevels;
|
||||||
int m_currentZoom;
|
int m_currentZoom;
|
||||||
@ -107,6 +116,8 @@ private:
|
|||||||
QUrl m_aboutToLoadUrl;
|
QUrl m_aboutToLoadUrl;
|
||||||
QUrl m_lastUrl;
|
QUrl m_lastUrl;
|
||||||
|
|
||||||
|
QWebElement m_mediaElement;
|
||||||
|
|
||||||
QList<QTouchEvent::TouchPoint> m_touchPoints;
|
QList<QTouchEvent::TouchPoint> m_touchPoints;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user