fix build
This commit is contained in:
parent
982a3dc004
commit
ac86a34c1f
@ -31,15 +31,16 @@
|
|||||||
#include "container_qpainter.h"
|
#include "container_qpainter.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QPaintEvent>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QPaintEvent>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
|
|
||||||
const int kScrollBarStep = 40;
|
const int kScrollBarStep = 40;
|
||||||
|
|
||||||
// TODO copied from litehtml/include/master.css
|
// TODO copied from litehtml/include/master.css
|
||||||
const char mastercss[] = R"RAW(
|
const char mastercss[] =
|
||||||
|
R"RAW(
|
||||||
html {
|
html {
|
||||||
display: block;
|
display: block;
|
||||||
height:100%;
|
height:100%;
|
||||||
@ -84,74 +85,16 @@ display:block;
|
|||||||
margin-bottom:1em;
|
margin-bottom:1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
b, strong {
|
|
||||||
display:inline;
|
|
||||||
font-weight:bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
i, em {
|
|
||||||
display:inline;
|
|
||||||
font-style:italic;
|
|
||||||
}
|
|
||||||
|
|
||||||
center
|
center
|
||||||
{
|
{
|
||||||
text-align:center;
|
text-align:center;
|
||||||
display:block;
|
display:block;
|
||||||
}
|
}
|
||||||
|
|
||||||
a:link
|
|
||||||
{
|
|
||||||
text-decoration: underline;
|
|
||||||
color: #00f;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1, h2, h3, h4, h5, h6, div {
|
h1, h2, h3, h4, h5, h6, div {
|
||||||
display:block;
|
display:block;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-weight:bold;
|
|
||||||
margin-top:0.67em;
|
|
||||||
margin-bottom:0.67em;
|
|
||||||
font-size: 2em;
|
|
||||||
}
|
|
||||||
|
|
||||||
h2 {
|
|
||||||
font-weight:bold;
|
|
||||||
margin-top:0.83em;
|
|
||||||
margin-bottom:0.83em;
|
|
||||||
font-size: 1.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
h3 {
|
|
||||||
font-weight:bold;
|
|
||||||
margin-top:1em;
|
|
||||||
margin-bottom:1em;
|
|
||||||
font-size:1.17em;
|
|
||||||
}
|
|
||||||
|
|
||||||
h4 {
|
|
||||||
font-weight:bold;
|
|
||||||
margin-top:1.33em;
|
|
||||||
margin-bottom:1.33em
|
|
||||||
}
|
|
||||||
|
|
||||||
h5 {
|
|
||||||
font-weight:bold;
|
|
||||||
margin-top:1.67em;
|
|
||||||
margin-bottom:1.67em;
|
|
||||||
font-size:.83em;
|
|
||||||
}
|
|
||||||
|
|
||||||
h6 {
|
|
||||||
font-weight:bold;
|
|
||||||
margin-top:2.33em;
|
|
||||||
margin-bottom:2.33em;
|
|
||||||
font-size:.67em;
|
|
||||||
}
|
|
||||||
|
|
||||||
br {
|
br {
|
||||||
display:inline-block;
|
display:inline-block;
|
||||||
}
|
}
|
||||||
@ -171,14 +114,6 @@ br[clear="right"]
|
|||||||
clear:right;
|
clear:right;
|
||||||
}
|
}
|
||||||
|
|
||||||
span {
|
|
||||||
display:inline
|
|
||||||
}
|
|
||||||
|
|
||||||
img {
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
img[align="right"]
|
img[align="right"]
|
||||||
{
|
{
|
||||||
float: right;
|
float: right;
|
||||||
@ -188,183 +123,6 @@ img[align="left"]
|
|||||||
{
|
{
|
||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr {
|
|
||||||
display: block;
|
|
||||||
margin-top: 0.5em;
|
|
||||||
margin-bottom: 0.5em;
|
|
||||||
margin-left: auto;
|
|
||||||
margin-right: auto;
|
|
||||||
border-style: inset;
|
|
||||||
border-width: 1px
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***************** TABLES ********************/
|
|
||||||
|
|
||||||
table {
|
|
||||||
display: table;
|
|
||||||
border-collapse: separate;
|
|
||||||
border-spacing: 2px;
|
|
||||||
border-top-color:gray;
|
|
||||||
border-left-color:gray;
|
|
||||||
border-bottom-color:black;
|
|
||||||
border-right-color:black;
|
|
||||||
}
|
|
||||||
|
|
||||||
tbody, tfoot, thead {
|
|
||||||
display:table-row-group;
|
|
||||||
vertical-align:middle;
|
|
||||||
}
|
|
||||||
|
|
||||||
tr {
|
|
||||||
display: table-row;
|
|
||||||
vertical-align: inherit;
|
|
||||||
border-color: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
td, th {
|
|
||||||
display: table-cell;
|
|
||||||
vertical-align: inherit;
|
|
||||||
border-width:1px;
|
|
||||||
padding:1px;
|
|
||||||
}
|
|
||||||
|
|
||||||
th {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
table[border] {
|
|
||||||
border-style:solid;
|
|
||||||
}
|
|
||||||
|
|
||||||
table[border|=0] {
|
|
||||||
border-style:none;
|
|
||||||
}
|
|
||||||
|
|
||||||
table[border] td, table[border] th {
|
|
||||||
border-style:solid;
|
|
||||||
border-top-color:black;
|
|
||||||
border-left-color:black;
|
|
||||||
border-bottom-color:gray;
|
|
||||||
border-right-color:gray;
|
|
||||||
}
|
|
||||||
|
|
||||||
table[border|=0] td, table[border|=0] th {
|
|
||||||
border-style:none;
|
|
||||||
}
|
|
||||||
|
|
||||||
caption {
|
|
||||||
display: table-caption;
|
|
||||||
}
|
|
||||||
|
|
||||||
td[nowrap], th[nowrap] {
|
|
||||||
white-space:nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
tt, code, kbd, samp {
|
|
||||||
font-family: monospace
|
|
||||||
}
|
|
||||||
pre, xmp, plaintext, listing {
|
|
||||||
display: block;
|
|
||||||
font-family: monospace;
|
|
||||||
white-space: pre;
|
|
||||||
margin: 1em 0
|
|
||||||
}
|
|
||||||
|
|
||||||
/***************** LISTS ********************/
|
|
||||||
|
|
||||||
ul, menu, dir {
|
|
||||||
display: block;
|
|
||||||
list-style-type: disc;
|
|
||||||
margin-top: 1em;
|
|
||||||
margin-bottom: 1em;
|
|
||||||
margin-left: 0;
|
|
||||||
margin-right: 0;
|
|
||||||
padding-left: 40px
|
|
||||||
}
|
|
||||||
|
|
||||||
ol {
|
|
||||||
display: block;
|
|
||||||
list-style-type: decimal;
|
|
||||||
margin-top: 1em;
|
|
||||||
margin-bottom: 1em;
|
|
||||||
margin-left: 0;
|
|
||||||
margin-right: 0;
|
|
||||||
padding-left: 40px
|
|
||||||
}
|
|
||||||
|
|
||||||
li {
|
|
||||||
display: list-item;
|
|
||||||
}
|
|
||||||
|
|
||||||
ul ul, ol ul {
|
|
||||||
list-style-type: circle;
|
|
||||||
}
|
|
||||||
|
|
||||||
ol ol ul, ol ul ul, ul ol ul, ul ul ul {
|
|
||||||
list-style-type: square;
|
|
||||||
}
|
|
||||||
|
|
||||||
dd {
|
|
||||||
display: block;
|
|
||||||
margin-left: 40px;
|
|
||||||
}
|
|
||||||
|
|
||||||
dl {
|
|
||||||
display: block;
|
|
||||||
margin-top: 1em;
|
|
||||||
margin-bottom: 1em;
|
|
||||||
margin-left: 0;
|
|
||||||
margin-right: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
dt {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
ol ul, ul ol, ul ul, ol ol {
|
|
||||||
margin-top: 0;
|
|
||||||
margin-bottom: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
blockquote {
|
|
||||||
display: block;
|
|
||||||
margin-top: 1em;
|
|
||||||
margin-bottom: 1em;
|
|
||||||
margin-left: 40px;
|
|
||||||
margin-left: 40px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*********** FORM ELEMENTS ************/
|
|
||||||
|
|
||||||
form {
|
|
||||||
display: block;
|
|
||||||
margin-top: 0em;
|
|
||||||
}
|
|
||||||
|
|
||||||
option {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
input, textarea, keygen, select, button, isindex {
|
|
||||||
margin: 0em;
|
|
||||||
color: initial;
|
|
||||||
line-height: normal;
|
|
||||||
text-transform: none;
|
|
||||||
text-indent: 0;
|
|
||||||
text-shadow: none;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
input[type="hidden"] {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
article, aside, footer, header, hgroup, nav, section
|
|
||||||
{
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
)RAW";
|
)RAW";
|
||||||
|
|
||||||
class QLiteHtmlWidgetPrivate
|
class QLiteHtmlWidgetPrivate
|
||||||
@ -386,19 +144,28 @@ QLiteHtmlWidget::QLiteHtmlWidget(QWidget *parent)
|
|||||||
horizontalScrollBar()->setSingleStep(kScrollBarStep);
|
horizontalScrollBar()->setSingleStep(kScrollBarStep);
|
||||||
verticalScrollBar()->setSingleStep(kScrollBarStep);
|
verticalScrollBar()->setSingleStep(kScrollBarStep);
|
||||||
|
|
||||||
d->documentContainer.setCursorCallback([this](const QCursor &c) { viewport()->setCursor(c); });
|
d->documentContainer.setCursorCallback([this](const QCursor& c) {
|
||||||
d->documentContainer.setPaletteCallback([this] { return palette(); });
|
viewport()->setCursor(c);
|
||||||
|
});
|
||||||
|
d->documentContainer.setPaletteCallback([this] {
|
||||||
|
return palette();
|
||||||
|
});
|
||||||
d->documentContainer.setLinkCallback([this](const QUrl& url) {
|
d->documentContainer.setLinkCallback([this](const QUrl& url) {
|
||||||
QUrl fullUrl = url;
|
QUrl fullUrl = url;
|
||||||
if (url.isRelative() && url.path(QUrl::FullyEncoded).isEmpty()) { // fragment/anchor only
|
if (url.isRelative() && url.path(QUrl::FullyEncoded).isEmpty()) { // fragment/anchor only
|
||||||
fullUrl = d->url;
|
fullUrl = d->url;
|
||||||
fullUrl.setFragment(url.fragment(QUrl::FullyEncoded));
|
fullUrl.setFragment(url.fragment(QUrl::FullyEncoded));
|
||||||
}
|
}
|
||||||
|
|
||||||
// delay because document may not be changed directly during this callback
|
// delay because document may not be changed directly during this callback
|
||||||
QMetaObject::invokeMethod(this, [this, fullUrl] { emit linkClicked(fullUrl); },
|
QMetaObject::invokeMethod(this, [this, fullUrl] {
|
||||||
|
emit linkClicked(fullUrl);
|
||||||
|
},
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
});
|
});
|
||||||
d->documentContainer.setClipboardCallback([this](bool yes) { emit copyAvailable(yes); });
|
d->documentContainer.setClipboardCallback([this](bool yes) {
|
||||||
|
emit copyAvailable(yes);
|
||||||
|
});
|
||||||
|
|
||||||
// TODO adapt mastercss to palette (default text & background color)
|
// TODO adapt mastercss to palette (default text & background color)
|
||||||
d->context.setMasterStyleSheet(mastercss);
|
d->context.setMasterStyleSheet(mastercss);
|
||||||
@ -413,13 +180,17 @@ void QLiteHtmlWidget::setUrl(const QUrl &url)
|
|||||||
{
|
{
|
||||||
d->url = url;
|
d->url = url;
|
||||||
QUrl baseUrl = url;
|
QUrl baseUrl = url;
|
||||||
|
|
||||||
baseUrl.setFragment({});
|
baseUrl.setFragment({});
|
||||||
const QString path = baseUrl.path(QUrl::FullyEncoded);
|
const QString path = baseUrl.path(QUrl::FullyEncoded);
|
||||||
const int lastSlash = path.lastIndexOf('/');
|
const int lastSlash = path.lastIndexOf('/');
|
||||||
const QString basePath = lastSlash >= 0 ? path.left(lastSlash) : QString();
|
const QString basePath = lastSlash >= 0 ? path.left(lastSlash) : QString();
|
||||||
|
|
||||||
baseUrl.setPath(basePath);
|
baseUrl.setPath(basePath);
|
||||||
d->documentContainer.setBaseUrl(baseUrl.toString(QUrl::FullyEncoded));
|
d->documentContainer.setBaseUrl(baseUrl.toString(QUrl::FullyEncoded));
|
||||||
QMetaObject::invokeMethod(this, [this] { updateHightlightedLink(); },
|
QMetaObject::invokeMethod(this, [this] {
|
||||||
|
updateHightlightedLink();
|
||||||
|
},
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,7 +207,9 @@ void QLiteHtmlWidget::setHtml(const QString &content)
|
|||||||
verticalScrollBar()->setValue(0);
|
verticalScrollBar()->setValue(0);
|
||||||
horizontalScrollBar()->setValue(0);
|
horizontalScrollBar()->setValue(0);
|
||||||
render();
|
render();
|
||||||
QMetaObject::invokeMethod(this, [this] { updateHightlightedLink(); },
|
QMetaObject::invokeMethod(this, [this] {
|
||||||
|
updateHightlightedLink();
|
||||||
|
},
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,7 +227,9 @@ void QLiteHtmlWidget::setZoomFactor(qreal scale)
|
|||||||
{
|
{
|
||||||
Q_ASSERT(scale != 0);
|
Q_ASSERT(scale != 0);
|
||||||
d->zoomFactor = scale;
|
d->zoomFactor = scale;
|
||||||
withFixedTextPosition([this] { render(); });
|
withFixedTextPosition([this] {
|
||||||
|
render();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal QLiteHtmlWidget::zoomFactor() const
|
qreal QLiteHtmlWidget::zoomFactor() const
|
||||||
@ -470,24 +245,32 @@ bool QLiteHtmlWidget::findText(const QString &text,
|
|||||||
bool success = false;
|
bool success = false;
|
||||||
QVector<QRect> oldSelection;
|
QVector<QRect> oldSelection;
|
||||||
QVector<QRect> newSelection;
|
QVector<QRect> newSelection;
|
||||||
|
|
||||||
d->documentContainer
|
d->documentContainer
|
||||||
.findText(text, flags, incremental, wrapped, &success, &oldSelection, &newSelection);
|
.findText(text, flags, incremental, wrapped, &success, &oldSelection, &newSelection);
|
||||||
|
|
||||||
// scroll to search result position and/or redraw as necessary
|
// scroll to search result position and/or redraw as necessary
|
||||||
QRect newSelectionCombined;
|
QRect newSelectionCombined;
|
||||||
|
|
||||||
for (const QRect& r : qAsConst(newSelection))
|
for (const QRect& r : qAsConst(newSelection))
|
||||||
newSelectionCombined = newSelectionCombined.united(r);
|
newSelectionCombined = newSelectionCombined.united(r);
|
||||||
|
|
||||||
QScrollBar* vBar = verticalScrollBar();
|
QScrollBar* vBar = verticalScrollBar();
|
||||||
const int top = newSelectionCombined.top();
|
const int top = newSelectionCombined.top();
|
||||||
const int bottom = newSelectionCombined.bottom() - toVirtual(viewport()->size()).height();
|
const int bottom = newSelectionCombined.bottom() - toVirtual(viewport()->size()).height();
|
||||||
|
|
||||||
if (success && top < vBar->value() && vBar->minimum() <= top) {
|
if (success && top < vBar->value() && vBar->minimum() <= top) {
|
||||||
vBar->setValue(top);
|
vBar->setValue(top);
|
||||||
} else if (success && vBar->value() < bottom && bottom <= vBar->maximum()) {
|
}
|
||||||
|
else if (success && vBar->value() < bottom && bottom <= vBar->maximum()) {
|
||||||
vBar->setValue(bottom);
|
vBar->setValue(bottom);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
viewport()->update(fromVirtual(newSelectionCombined.translated(-scrollPosition())));
|
viewport()->update(fromVirtual(newSelectionCombined.translated(-scrollPosition())));
|
||||||
for (const QRect& r : qAsConst(oldSelection))
|
for (const QRect& r : qAsConst(oldSelection))
|
||||||
viewport()->update(fromVirtual(r.translated(-scrollPosition())));
|
viewport()->update(fromVirtual(r.translated(-scrollPosition())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -508,12 +291,15 @@ void QLiteHtmlWidget::scrollToAnchor(const QString &name)
|
|||||||
{
|
{
|
||||||
if (!d->documentContainer.hasDocument())
|
if (!d->documentContainer.hasDocument())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
horizontalScrollBar()->setValue(0);
|
horizontalScrollBar()->setValue(0);
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
verticalScrollBar()->setValue(0);
|
verticalScrollBar()->setValue(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int y = d->documentContainer.anchorY(name);
|
const int y = d->documentContainer.anchorY(name);
|
||||||
|
|
||||||
if (y >= 0)
|
if (y >= 0)
|
||||||
verticalScrollBar()->setValue(std::min(y, verticalScrollBar()->maximum()));
|
verticalScrollBar()->setValue(std::min(y, verticalScrollBar()->maximum()));
|
||||||
}
|
}
|
||||||
@ -532,8 +318,10 @@ void QLiteHtmlWidget::paintEvent(QPaintEvent *event)
|
|||||||
{
|
{
|
||||||
if (!d->documentContainer.hasDocument())
|
if (!d->documentContainer.hasDocument())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
d->documentContainer.setScrollPosition(scrollPosition());
|
d->documentContainer.setScrollPosition(scrollPosition());
|
||||||
QPainter p(viewport());
|
QPainter p(viewport());
|
||||||
|
|
||||||
p.setWorldTransform(QTransform().scale(d->zoomFactor, d->zoomFactor));
|
p.setWorldTransform(QTransform().scale(d->zoomFactor, d->zoomFactor));
|
||||||
p.setRenderHint(QPainter::SmoothPixmapTransform, true);
|
p.setRenderHint(QPainter::SmoothPixmapTransform, true);
|
||||||
p.setRenderHint(QPainter::Antialiasing, true);
|
p.setRenderHint(QPainter::Antialiasing, true);
|
||||||
@ -552,8 +340,10 @@ void QLiteHtmlWidget::mouseMoveEvent(QMouseEvent *event)
|
|||||||
{
|
{
|
||||||
QPoint viewportPos;
|
QPoint viewportPos;
|
||||||
QPoint pos;
|
QPoint pos;
|
||||||
|
|
||||||
htmlPos(event->pos(), &viewportPos, &pos);
|
htmlPos(event->pos(), &viewportPos, &pos);
|
||||||
const QVector<QRect> areas = d->documentContainer.mouseMoveEvent(pos, viewportPos);
|
const QVector<QRect> areas = d->documentContainer.mouseMoveEvent(pos, viewportPos);
|
||||||
|
|
||||||
for (const QRect& r : areas)
|
for (const QRect& r : areas)
|
||||||
viewport()->update(fromVirtual(r.translated(-scrollPosition())));
|
viewport()->update(fromVirtual(r.translated(-scrollPosition())));
|
||||||
|
|
||||||
@ -564,8 +354,10 @@ void QLiteHtmlWidget::mousePressEvent(QMouseEvent *event)
|
|||||||
{
|
{
|
||||||
QPoint viewportPos;
|
QPoint viewportPos;
|
||||||
QPoint pos;
|
QPoint pos;
|
||||||
|
|
||||||
htmlPos(event->pos(), &viewportPos, &pos);
|
htmlPos(event->pos(), &viewportPos, &pos);
|
||||||
const QVector<QRect> areas = d->documentContainer.mousePressEvent(pos, viewportPos, event->button());
|
const QVector<QRect> areas = d->documentContainer.mousePressEvent(pos, viewportPos, event->button());
|
||||||
|
|
||||||
for (const QRect& r : areas)
|
for (const QRect& r : areas)
|
||||||
viewport()->update(fromVirtual(r.translated(-scrollPosition())));
|
viewport()->update(fromVirtual(r.translated(-scrollPosition())));
|
||||||
}
|
}
|
||||||
@ -574,8 +366,10 @@ void QLiteHtmlWidget::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
{
|
{
|
||||||
QPoint viewportPos;
|
QPoint viewportPos;
|
||||||
QPoint pos;
|
QPoint pos;
|
||||||
|
|
||||||
htmlPos(event->pos(), &viewportPos, &pos);
|
htmlPos(event->pos(), &viewportPos, &pos);
|
||||||
const QVector<QRect> areas = d->documentContainer.mouseReleaseEvent(pos, viewportPos, event->button());
|
const QVector<QRect> areas = d->documentContainer.mouseReleaseEvent(pos, viewportPos, event->button());
|
||||||
|
|
||||||
for (const QRect& r : areas)
|
for (const QRect& r : areas)
|
||||||
viewport()->update(fromVirtual(r.translated(-scrollPosition())));
|
viewport()->update(fromVirtual(r.translated(-scrollPosition())));
|
||||||
}
|
}
|
||||||
@ -584,8 +378,10 @@ void QLiteHtmlWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
|||||||
{
|
{
|
||||||
QPoint viewportPos;
|
QPoint viewportPos;
|
||||||
QPoint pos;
|
QPoint pos;
|
||||||
|
|
||||||
htmlPos(event->pos(), &viewportPos, &pos);
|
htmlPos(event->pos(), &viewportPos, &pos);
|
||||||
const QVector<QRect> areas = d->documentContainer.mouseDoubleClickEvent(pos, viewportPos, event->button());
|
const QVector<QRect> areas = d->documentContainer.mouseDoubleClickEvent(pos, viewportPos, event->button());
|
||||||
|
|
||||||
for (const QRect& r : areas) {
|
for (const QRect& r : areas) {
|
||||||
viewport()->update(fromVirtual(r.translated(-scrollPosition())));
|
viewport()->update(fromVirtual(r.translated(-scrollPosition())));
|
||||||
}
|
}
|
||||||
@ -595,8 +391,10 @@ void QLiteHtmlWidget::leaveEvent(QEvent *event)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
const QVector<QRect> areas = d->documentContainer.leaveEvent();
|
const QVector<QRect> areas = d->documentContainer.leaveEvent();
|
||||||
|
|
||||||
for (const QRect& r : areas)
|
for (const QRect& r : areas)
|
||||||
viewport()->update(fromVirtual(r.translated(-scrollPosition())));
|
viewport()->update(fromVirtual(r.translated(-scrollPosition())));
|
||||||
|
|
||||||
setHightlightedLink(QUrl());
|
setHightlightedLink(QUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -604,6 +402,7 @@ void QLiteHtmlWidget::contextMenuEvent(QContextMenuEvent *event)
|
|||||||
{
|
{
|
||||||
QPoint viewportPos;
|
QPoint viewportPos;
|
||||||
QPoint pos;
|
QPoint pos;
|
||||||
|
|
||||||
htmlPos(event->pos(), &viewportPos, &pos);
|
htmlPos(event->pos(), &viewportPos, &pos);
|
||||||
emit contextMenuRequested(event->pos(), d->documentContainer.linkAt(pos, viewportPos));
|
emit contextMenuRequested(event->pos(), d->documentContainer.linkAt(pos, viewportPos));
|
||||||
}
|
}
|
||||||
@ -612,12 +411,16 @@ static QAbstractSlider::SliderAction getSliderAction(int key)
|
|||||||
{
|
{
|
||||||
if (key == Qt::Key_Home)
|
if (key == Qt::Key_Home)
|
||||||
return QAbstractSlider::SliderToMinimum;
|
return QAbstractSlider::SliderToMinimum;
|
||||||
|
|
||||||
if (key == Qt::Key_End)
|
if (key == Qt::Key_End)
|
||||||
return QAbstractSlider::SliderToMaximum;
|
return QAbstractSlider::SliderToMaximum;
|
||||||
|
|
||||||
if (key == Qt::Key_PageUp)
|
if (key == Qt::Key_PageUp)
|
||||||
return QAbstractSlider::SliderPageStepSub;
|
return QAbstractSlider::SliderPageStepSub;
|
||||||
|
|
||||||
if (key == Qt::Key_PageDown)
|
if (key == Qt::Key_PageDown)
|
||||||
return QAbstractSlider::SliderPageStepAdd;
|
return QAbstractSlider::SliderPageStepAdd;
|
||||||
|
|
||||||
return QAbstractSlider::SliderNoAction;
|
return QAbstractSlider::SliderNoAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -625,6 +428,7 @@ void QLiteHtmlWidget::keyPressEvent(QKeyEvent *event)
|
|||||||
{
|
{
|
||||||
if (event->modifiers() == Qt::NoModifier || event->modifiers() == Qt::KeypadModifier) {
|
if (event->modifiers() == Qt::NoModifier || event->modifiers() == Qt::KeypadModifier) {
|
||||||
const QAbstractSlider::SliderAction sliderAction = getSliderAction(event->key());
|
const QAbstractSlider::SliderAction sliderAction = getSliderAction(event->key());
|
||||||
|
|
||||||
if (sliderAction != QAbstractSlider::SliderNoAction) {
|
if (sliderAction != QAbstractSlider::SliderNoAction) {
|
||||||
verticalScrollBar()->triggerAction(sliderAction);
|
verticalScrollBar()->triggerAction(sliderAction);
|
||||||
event->accept();
|
event->accept();
|
||||||
@ -638,6 +442,7 @@ void QLiteHtmlWidget::updateHightlightedLink()
|
|||||||
{
|
{
|
||||||
QPoint viewportPos;
|
QPoint viewportPos;
|
||||||
QPoint pos;
|
QPoint pos;
|
||||||
|
|
||||||
htmlPos(mapFromGlobal(QCursor::pos()), &viewportPos, &pos);
|
htmlPos(mapFromGlobal(QCursor::pos()), &viewportPos, &pos);
|
||||||
setHightlightedLink(d->documentContainer.linkAt(pos, viewportPos));
|
setHightlightedLink(d->documentContainer.linkAt(pos, viewportPos));
|
||||||
}
|
}
|
||||||
@ -646,6 +451,7 @@ void QLiteHtmlWidget::setHightlightedLink(const QUrl &url)
|
|||||||
{
|
{
|
||||||
if (d->lastHighlightedLink == url)
|
if (d->lastHighlightedLink == url)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
d->lastHighlightedLink = url;
|
d->lastHighlightedLink = url;
|
||||||
emit linkHighlighted(d->lastHighlightedLink);
|
emit linkHighlighted(d->lastHighlightedLink);
|
||||||
}
|
}
|
||||||
@ -655,8 +461,10 @@ void QLiteHtmlWidget::withFixedTextPosition(const std::function<void()> &action)
|
|||||||
// remember element to which to scroll after re-rendering
|
// remember element to which to scroll after re-rendering
|
||||||
QPoint viewportPos;
|
QPoint viewportPos;
|
||||||
QPoint pos;
|
QPoint pos;
|
||||||
|
|
||||||
htmlPos({}, &viewportPos, &pos); // top-left
|
htmlPos({}, &viewportPos, &pos); // top-left
|
||||||
const int y = d->documentContainer.withFixedElementPosition(pos.y(), action);
|
const int y = d->documentContainer.withFixedElementPosition(pos.y(), action);
|
||||||
|
|
||||||
if (y >= 0)
|
if (y >= 0)
|
||||||
verticalScrollBar()->setValue(std::min(y, verticalScrollBar()->maximum()));
|
verticalScrollBar()->setValue(std::min(y, verticalScrollBar()->maximum()));
|
||||||
}
|
}
|
||||||
@ -665,11 +473,14 @@ void QLiteHtmlWidget::render()
|
|||||||
{
|
{
|
||||||
if (!d->documentContainer.hasDocument())
|
if (!d->documentContainer.hasDocument())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const int fullWidth = width() / d->zoomFactor;
|
const int fullWidth = width() / d->zoomFactor;
|
||||||
const QSize vViewportSize = toVirtual(viewport()->size());
|
const QSize vViewportSize = toVirtual(viewport()->size());
|
||||||
const int scrollbarWidth = style()->pixelMetric(QStyle::PM_ScrollBarExtent, nullptr, this);
|
const int scrollbarWidth = style()->pixelMetric(QStyle::PM_ScrollBarExtent, nullptr, this);
|
||||||
const int w = fullWidth - scrollbarWidth - 2;
|
const int w = fullWidth - scrollbarWidth - 2;
|
||||||
|
|
||||||
d->documentContainer.render(w, vViewportSize.height());
|
d->documentContainer.render(w, vViewportSize.height());
|
||||||
|
|
||||||
// scroll bars reflect virtual/scaled size of html document
|
// scroll bars reflect virtual/scaled size of html document
|
||||||
horizontalScrollBar()->setPageStep(vViewportSize.width());
|
horizontalScrollBar()->setPageStep(vViewportSize.width());
|
||||||
horizontalScrollBar()->setRange(0, std::max(0, d->documentContainer.documentWidth() - w));
|
horizontalScrollBar()->setRange(0, std::max(0, d->documentContainer.documentWidth() - w));
|
||||||
@ -708,8 +519,10 @@ QRect QLiteHtmlWidget::toVirtual(const QRect &r) const
|
|||||||
QRect QLiteHtmlWidget::fromVirtual(const QRect& r) const
|
QRect QLiteHtmlWidget::fromVirtual(const QRect& r) const
|
||||||
{
|
{
|
||||||
const QPoint tl{ int(r.x() * d->zoomFactor), int(r.y() * d->zoomFactor) };
|
const QPoint tl{ int(r.x() * d->zoomFactor), int(r.y() * d->zoomFactor) };
|
||||||
|
|
||||||
// round size up, and add one since the topleft point was rounded down
|
// round size up, and add one since the topleft point was rounded down
|
||||||
const QSize s{ int(r.width() * d->zoomFactor + 0.5) + 1,
|
const QSize s{ int(r.width() * d->zoomFactor + 0.5) + 1,
|
||||||
int(r.height() * d->zoomFactor + 0.5) + 1 };
|
int(r.height() * d->zoomFactor + 0.5) + 1 };
|
||||||
|
|
||||||
return { tl, s };
|
return { tl, s };
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ WebBrowser::WebBrowser(WebViewer* viewer, QWidget* parent) : TabContent(parent),
|
|||||||
this)) {
|
this)) {
|
||||||
if (m_webView == nullptr) {
|
if (m_webView == nullptr) {
|
||||||
#if !defined(USE_WEBENGINE)
|
#if !defined(USE_WEBENGINE)
|
||||||
m_webView = new LiteHtmlViewer(this),
|
m_webView = new LiteHtmlViewer(this);
|
||||||
#else
|
#else
|
||||||
if (qApp->forcedNoWebEngine()) {
|
if (qApp->forcedNoWebEngine()) {
|
||||||
m_webView = new LiteHtmlViewer(this);
|
m_webView = new LiteHtmlViewer(this);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user