mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-26 15:34:59 +01:00
clipboard integrate
This commit is contained in:
parent
d617273e6a
commit
0976ddb7b1
@ -12,6 +12,7 @@
|
||||
#include "network-web/webfactory.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QClipboard>
|
||||
#include <QScrollBar>
|
||||
#include <QWheelEvent>
|
||||
|
||||
@ -20,6 +21,18 @@ LiteHtmlViewer::LiteHtmlViewer(QWidget* parent) : QLiteHtmlWidget(parent) {
|
||||
emit loadProgress(-1);
|
||||
return handleResource(url);
|
||||
});
|
||||
|
||||
connect(this, &LiteHtmlViewer::copyAvailable, this, [this](bool available) {
|
||||
if (!available) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString sel_text = QLiteHtmlWidget::selectedText();
|
||||
|
||||
if (!sel_text.isEmpty()) {
|
||||
QGuiApplication::clipboard()->setText(sel_text, QClipboard::Mode::Selection);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void LiteHtmlViewer::bindToBrowser(WebBrowser* browser) {
|
||||
@ -28,6 +41,14 @@ void LiteHtmlViewer::bindToBrowser(WebBrowser* browser) {
|
||||
browser->m_actionReload = new QAction(this);
|
||||
browser->m_actionStop = new QAction(this);
|
||||
|
||||
browser->m_actionBack->setEnabled(false);
|
||||
browser->m_actionForward->setEnabled(false);
|
||||
browser->m_actionReload->setEnabled(false);
|
||||
|
||||
// TODO: When clicked "Stop", save the "Stop" state and return {} from "handleResource(...)"
|
||||
// right away.
|
||||
browser->m_actionStop->setEnabled(false);
|
||||
|
||||
connect(this, &LiteHtmlViewer::zoomFactorChanged, browser, &WebBrowser::onZoomFactorChanged);
|
||||
connect(this, &LiteHtmlViewer::linkHighlighted, browser, [browser](const QUrl& url) {
|
||||
browser->onLinkHovered(url.toString());
|
||||
@ -260,3 +281,15 @@ QByteArray LiteHtmlViewer::handleResource(const QUrl& url) {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
void LiteHtmlViewer::keyPressEvent(QKeyEvent* event) {
|
||||
if (event->matches(QKeySequence::StandardKey::Copy)) {
|
||||
QString sel_text = QLiteHtmlWidget::selectedText();
|
||||
|
||||
if (!sel_text.isEmpty()) {
|
||||
QGuiApplication::clipboard()->setText(sel_text, QClipboard::Mode::Clipboard);
|
||||
}
|
||||
}
|
||||
|
||||
QLiteHtmlWidget::keyPressEvent(event);
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ class LiteHtmlViewer : public QLiteHtmlWidget, public WebViewer {
|
||||
void loadFinished(bool success);
|
||||
|
||||
protected:
|
||||
virtual void keyPressEvent(QKeyEvent* event);
|
||||
virtual void wheelEvent(QWheelEvent* event);
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user