clipboard integrate
This commit is contained in:
parent
d617273e6a
commit
0976ddb7b1
2 changed files with 34 additions and 0 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include "network-web/webfactory.h"
|
#include "network-web/webfactory.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
#include <QClipboard>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
|
|
||||||
|
@ -20,6 +21,18 @@ LiteHtmlViewer::LiteHtmlViewer(QWidget* parent) : QLiteHtmlWidget(parent) {
|
||||||
emit loadProgress(-1);
|
emit loadProgress(-1);
|
||||||
return handleResource(url);
|
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) {
|
void LiteHtmlViewer::bindToBrowser(WebBrowser* browser) {
|
||||||
|
@ -28,6 +41,14 @@ void LiteHtmlViewer::bindToBrowser(WebBrowser* browser) {
|
||||||
browser->m_actionReload = new QAction(this);
|
browser->m_actionReload = new QAction(this);
|
||||||
browser->m_actionStop = 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::zoomFactorChanged, browser, &WebBrowser::onZoomFactorChanged);
|
||||||
connect(this, &LiteHtmlViewer::linkHighlighted, browser, [browser](const QUrl& url) {
|
connect(this, &LiteHtmlViewer::linkHighlighted, browser, [browser](const QUrl& url) {
|
||||||
browser->onLinkHovered(url.toString());
|
browser->onLinkHovered(url.toString());
|
||||||
|
@ -260,3 +281,15 @@ QByteArray LiteHtmlViewer::handleResource(const QUrl& url) {
|
||||||
return output;
|
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);
|
void loadFinished(bool success);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void keyPressEvent(QKeyEvent* event);
|
||||||
virtual void wheelEvent(QWheelEvent* event);
|
virtual void wheelEvent(QWheelEvent* event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Reference in a new issue