mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
preview: bug fix with no-update issue
This commit is contained in:
parent
16399ded29
commit
99cf497ddc
@ -14,8 +14,8 @@ version=9
|
|||||||
base_fg=#000000
|
base_fg=#000000
|
||||||
base_bg=#F5F5F5
|
base_bg=#F5F5F5
|
||||||
|
|
||||||
title_fg=#000000
|
title_fg=@base_fg
|
||||||
title_bg=#DADBDB
|
title_bg=transparent
|
||||||
|
|
||||||
hover_fg=#000000
|
hover_fg=#000000
|
||||||
hover_bg=#C0C0C0
|
hover_bg=#C0C0C0
|
||||||
|
@ -323,7 +323,7 @@ int VPreviewManager::calculateBlockMargin(const QTextBlock &p_block, int p_tabSt
|
|||||||
void VPreviewManager::updateBlockPreviewInfo(TS p_timeStamp,
|
void VPreviewManager::updateBlockPreviewInfo(TS p_timeStamp,
|
||||||
const QVector<ImageLinkInfo> &p_imageLinks)
|
const QVector<ImageLinkInfo> &p_imageLinks)
|
||||||
{
|
{
|
||||||
QSet<int> affectedBlocks;
|
OrderedIntSet affectedBlocks;
|
||||||
for (auto const & link : p_imageLinks) {
|
for (auto const & link : p_imageLinks) {
|
||||||
QTextBlock block = m_document->findBlockByNumber(link.m_blockNumber);
|
QTextBlock block = m_document->findBlockByNumber(link.m_blockNumber);
|
||||||
if (!block.isValid()) {
|
if (!block.isValid()) {
|
||||||
@ -350,7 +350,7 @@ void VPreviewManager::updateBlockPreviewInfo(TS p_timeStamp,
|
|||||||
imageCache(PreviewSource::ImageLink).insert(name, p_timeStamp);
|
imageCache(PreviewSource::ImageLink).insert(name, p_timeStamp);
|
||||||
if (!tsUpdated) {
|
if (!tsUpdated) {
|
||||||
// No need to relayout the block if only timestamp is updated.
|
// No need to relayout the block if only timestamp is updated.
|
||||||
affectedBlocks.insert(link.m_blockNumber);
|
affectedBlocks.insert(link.m_blockNumber, QMapDummyValue());
|
||||||
m_highlighter->addPossiblePreviewBlock(link.m_blockNumber);
|
m_highlighter->addPossiblePreviewBlock(link.m_blockNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,15 +359,14 @@ void VPreviewManager::updateBlockPreviewInfo(TS p_timeStamp,
|
|||||||
<< blockData->toString();
|
<< blockData->toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_editor->relayout(affectedBlocks);
|
relayoutEditor(affectedBlocks);
|
||||||
m_editor->update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VPreviewManager::updateBlockPreviewInfo(TS p_timeStamp,
|
void VPreviewManager::updateBlockPreviewInfo(TS p_timeStamp,
|
||||||
PreviewSource p_source,
|
PreviewSource p_source,
|
||||||
const QVector<QSharedPointer<VImageToPreview> > &p_images)
|
const QVector<QSharedPointer<VImageToPreview> > &p_images)
|
||||||
{
|
{
|
||||||
QSet<int> affectedBlocks;
|
OrderedIntSet affectedBlocks;
|
||||||
for (auto const & img : p_images) {
|
for (auto const & img : p_images) {
|
||||||
if (img.isNull()) {
|
if (img.isNull()) {
|
||||||
continue;
|
continue;
|
||||||
@ -397,14 +396,13 @@ void VPreviewManager::updateBlockPreviewInfo(TS p_timeStamp,
|
|||||||
imageCache(p_source).insert(name, p_timeStamp);
|
imageCache(p_source).insert(name, p_timeStamp);
|
||||||
if (!tsUpdated) {
|
if (!tsUpdated) {
|
||||||
// No need to relayout the block if only timestamp is updated.
|
// No need to relayout the block if only timestamp is updated.
|
||||||
affectedBlocks.insert(img->m_blockNumber);
|
affectedBlocks.insert(img->m_blockNumber, QMapDummyValue());
|
||||||
m_highlighter->addPossiblePreviewBlock(img->m_blockNumber);
|
m_highlighter->addPossiblePreviewBlock(img->m_blockNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Relayout these blocks since they may not have been changed.
|
// Relayout these blocks since they may not have been changed.
|
||||||
m_editor->relayout(affectedBlocks);
|
relayoutEditor(affectedBlocks);
|
||||||
m_editor->update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VPreviewManager::clearObsoleteImages(long long p_timeStamp, PreviewSource p_source)
|
void VPreviewManager::clearObsoleteImages(long long p_timeStamp, PreviewSource p_source)
|
||||||
@ -424,7 +422,7 @@ void VPreviewManager::clearObsoleteImages(long long p_timeStamp, PreviewSource p
|
|||||||
void VPreviewManager::clearBlockObsoletePreviewInfo(long long p_timeStamp,
|
void VPreviewManager::clearBlockObsoletePreviewInfo(long long p_timeStamp,
|
||||||
PreviewSource p_source)
|
PreviewSource p_source)
|
||||||
{
|
{
|
||||||
QSet<int> affectedBlocks;
|
OrderedIntSet affectedBlocks;
|
||||||
QVector<int> obsoleteBlocks;
|
QVector<int> obsoleteBlocks;
|
||||||
const QSet<int> &blocks = m_highlighter->getPossiblePreviewBlocks();
|
const QSet<int> &blocks = m_highlighter->getPossiblePreviewBlocks();
|
||||||
for (auto i : blocks) {
|
for (auto i : blocks) {
|
||||||
@ -440,7 +438,7 @@ void VPreviewManager::clearBlockObsoletePreviewInfo(long long p_timeStamp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (blockData->clearObsoletePreview(p_timeStamp, p_source)) {
|
if (blockData->clearObsoletePreview(p_timeStamp, p_source)) {
|
||||||
affectedBlocks.insert(i);
|
affectedBlocks.insert(i, QMapDummyValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blockData->getPreviews().isEmpty()) {
|
if (blockData->getPreviews().isEmpty()) {
|
||||||
@ -501,7 +499,7 @@ void VPreviewManager::checkBlocksForObsoletePreview(const QList<int> &p_blocks)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSet<int> affectedBlocks;
|
OrderedIntSet affectedBlocks;
|
||||||
for (auto i : p_blocks) {
|
for (auto i : p_blocks) {
|
||||||
QTextBlock block = m_document->findBlockByNumber(i);
|
QTextBlock block = m_document->findBlockByNumber(i);
|
||||||
if (!block.isValid()) {
|
if (!block.isValid()) {
|
||||||
@ -524,10 +522,22 @@ void VPreviewManager::checkBlocksForObsoletePreview(const QList<int> &p_blocks)
|
|||||||
|
|
||||||
PreviewSource ps = static_cast<PreviewSource>(i);
|
PreviewSource ps = static_cast<PreviewSource>(i);
|
||||||
if (blockData->clearObsoletePreview(timeStamp(ps), ps)) {
|
if (blockData->clearObsoletePreview(timeStamp(ps), ps)) {
|
||||||
affectedBlocks.insert(i);
|
affectedBlocks.insert(i, QMapDummyValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_editor->relayout(affectedBlocks);
|
m_editor->relayout(affectedBlocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VPreviewManager::relayoutEditor(const OrderedIntSet &p_blocks)
|
||||||
|
{
|
||||||
|
OrderedIntSet bs(p_blocks);
|
||||||
|
int first, last;
|
||||||
|
m_editor->visibleBlockRange(first, last);
|
||||||
|
for (int i = first; i <= last; ++i) {
|
||||||
|
bs.insert(i, QMapDummyValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
m_editor->relayout(bs);
|
||||||
|
}
|
||||||
|
@ -180,6 +180,8 @@ private:
|
|||||||
|
|
||||||
TS &timeStamp(PreviewSource p_source);
|
TS &timeStamp(PreviewSource p_source);
|
||||||
|
|
||||||
|
void relayoutEditor(const OrderedIntSet &p_blocks);
|
||||||
|
|
||||||
VMdEditor *m_editor;
|
VMdEditor *m_editor;
|
||||||
|
|
||||||
QTextDocument *m_document;
|
QTextDocument *m_document;
|
||||||
|
@ -985,7 +985,7 @@ void VTextDocumentLayout::relayout()
|
|||||||
emit update(QRectF(0., 0., 1000000000., 1000000000.));
|
emit update(QRectF(0., 0., 1000000000., 1000000000.));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VTextDocumentLayout::relayout(const QSet<int> &p_blocks)
|
void VTextDocumentLayout::relayout(const OrderedIntSet &p_blocks)
|
||||||
{
|
{
|
||||||
if (p_blocks.isEmpty()) {
|
if (p_blocks.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
@ -993,8 +993,9 @@ void VTextDocumentLayout::relayout(const QSet<int> &p_blocks)
|
|||||||
|
|
||||||
QTextDocument *doc = document();
|
QTextDocument *doc = document();
|
||||||
|
|
||||||
for (auto bn : p_blocks) {
|
// Need to relayout and update blocks in ascending order.
|
||||||
QTextBlock block = doc->findBlockByNumber(bn);
|
for (auto bn = p_blocks.keyBegin(); bn != p_blocks.keyEnd(); ++bn) {
|
||||||
|
QTextBlock block = doc->findBlockByNumber(*bn);
|
||||||
if (block.isValid()) {
|
if (block.isValid()) {
|
||||||
clearBlockLayout(block);
|
clearBlockLayout(block);
|
||||||
layoutBlock(block);
|
layoutBlock(block);
|
||||||
|
@ -4,13 +4,19 @@
|
|||||||
#include <QAbstractTextDocumentLayout>
|
#include <QAbstractTextDocumentLayout>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
#include <QSet>
|
#include <QMap>
|
||||||
|
|
||||||
#include "vconstants.h"
|
#include "vconstants.h"
|
||||||
|
|
||||||
class VImageResourceManager2;
|
class VImageResourceManager2;
|
||||||
struct VPreviewedImageInfo;
|
struct VPreviewedImageInfo;
|
||||||
struct VPreviewInfo;
|
struct VPreviewInfo;
|
||||||
|
|
||||||
|
struct QMapDummyValue
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef QMap<int, QMapDummyValue> OrderedIntSet;
|
||||||
|
|
||||||
class VTextDocumentLayout : public QAbstractTextDocumentLayout
|
class VTextDocumentLayout : public QAbstractTextDocumentLayout
|
||||||
{
|
{
|
||||||
@ -51,7 +57,7 @@ public:
|
|||||||
void relayout();
|
void relayout();
|
||||||
|
|
||||||
// Relayout @p_blocks.
|
// Relayout @p_blocks.
|
||||||
void relayout(const QSet<int> &p_blocks);
|
void relayout(const OrderedIntSet &p_blocks);
|
||||||
|
|
||||||
void setImageLineColor(const QColor &p_color);
|
void setImageLineColor(const QColor &p_color);
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
|
|
||||||
#include "vtextdocumentlayout.h"
|
|
||||||
#include "vimageresourcemanager2.h"
|
#include "vimageresourcemanager2.h"
|
||||||
|
|
||||||
#define VIRTUAL_CURSOR_BLOCK_WIDTH 8
|
#define VIRTUAL_CURSOR_BLOCK_WIDTH 8
|
||||||
@ -286,6 +285,22 @@ QTextBlock VTextEdit::firstVisibleBlock() const
|
|||||||
return document()->findBlockByNumber(blockNumber);
|
return document()->findBlockByNumber(blockNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTextBlock VTextEdit::lastVisibleBlock() const
|
||||||
|
{
|
||||||
|
VTextDocumentLayout *layout = getLayout();
|
||||||
|
Q_ASSERT(layout);
|
||||||
|
int blockNumber = layout->findBlockByPosition(QPointF(0, -contentOffsetY() + contentsRect().height()));
|
||||||
|
return document()->findBlockByNumber(blockNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VTextEdit::visibleBlockRange(int &p_first, int &p_last) const
|
||||||
|
{
|
||||||
|
VTextDocumentLayout *layout = getLayout();
|
||||||
|
Q_ASSERT(layout);
|
||||||
|
p_first = layout->findBlockByPosition(QPointF(0, -contentOffsetY()));
|
||||||
|
p_last = layout->findBlockByPosition(QPointF(0, -contentOffsetY() + contentsRect().height()));
|
||||||
|
}
|
||||||
|
|
||||||
int VTextEdit::contentOffsetY() const
|
int VTextEdit::contentOffsetY() const
|
||||||
{
|
{
|
||||||
QScrollBar *sb = verticalScrollBar();
|
QScrollBar *sb = verticalScrollBar();
|
||||||
@ -299,11 +314,24 @@ void VTextEdit::clearBlockImages()
|
|||||||
getLayout()->relayout();
|
getLayout()->relayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VTextEdit::relayout(const QSet<int> &p_blocks)
|
void VTextEdit::relayout(const OrderedIntSet &p_blocks)
|
||||||
{
|
{
|
||||||
getLayout()->relayout(p_blocks);
|
getLayout()->relayout(p_blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VTextEdit::relayoutVisibleBlocks()
|
||||||
|
{
|
||||||
|
int first, last;
|
||||||
|
visibleBlockRange(first, last);
|
||||||
|
OrderedIntSet blocks;
|
||||||
|
|
||||||
|
for (int i = first; i <= last; ++i) {
|
||||||
|
blocks.insert(i, QMapDummyValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
getLayout()->relayout(blocks);
|
||||||
|
}
|
||||||
|
|
||||||
bool VTextEdit::containsImage(const QString &p_imageName) const
|
bool VTextEdit::containsImage(const QString &p_imageName) const
|
||||||
{
|
{
|
||||||
return m_imageMgr->contains(p_imageName);
|
return m_imageMgr->contains(p_imageName);
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
|
|
||||||
#include "vlinenumberarea.h"
|
#include "vlinenumberarea.h"
|
||||||
#include "vconstants.h"
|
#include "vtextdocumentlayout.h"
|
||||||
|
|
||||||
class VTextDocumentLayout;
|
class VTextDocumentLayout;
|
||||||
class QPainter;
|
class QPainter;
|
||||||
@ -35,6 +35,10 @@ public:
|
|||||||
|
|
||||||
QTextBlock firstVisibleBlock() const;
|
QTextBlock firstVisibleBlock() const;
|
||||||
|
|
||||||
|
QTextBlock lastVisibleBlock() const;
|
||||||
|
|
||||||
|
void visibleBlockRange(int &p_first, int &p_last) const;
|
||||||
|
|
||||||
void clearBlockImages();
|
void clearBlockImages();
|
||||||
|
|
||||||
// Whether the resoruce manager contains image of name @p_imageName.
|
// Whether the resoruce manager contains image of name @p_imageName.
|
||||||
@ -55,7 +59,7 @@ public:
|
|||||||
|
|
||||||
void setImageLineColor(const QColor &p_color);
|
void setImageLineColor(const QColor &p_color);
|
||||||
|
|
||||||
void relayout(const QSet<int> &p_blocks);
|
void relayout(const OrderedIntSet &p_blocks);
|
||||||
|
|
||||||
void setCursorBlockMode(CursorBlock p_mode);
|
void setCursorBlockMode(CursorBlock p_mode);
|
||||||
|
|
||||||
@ -65,6 +69,8 @@ public:
|
|||||||
|
|
||||||
void relayout();
|
void relayout();
|
||||||
|
|
||||||
|
void relayoutVisibleBlocks();
|
||||||
|
|
||||||
void setDisplayScaleFactor(qreal p_factor);
|
void setDisplayScaleFactor(qreal p_factor);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user