From 37c415f7328df2f85f557246b1055bd3d13f2108 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Wed, 19 Dec 2018 20:04:47 +0800 Subject: [PATCH] Editor: fix smart table cell crossing lines --- README.md | 2 +- README_zh.md | 2 +- src/resources/docs/welcome_en.md | 2 +- src/resources/docs/welcome_zh.md | 2 +- src/vmainwindow.cpp | 4 +++- src/vtable.cpp | 30 ++++++++++++++++++++++++++---- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c04c17d9..ce404061 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ You could help VNote's development in many ways. -Thanks very much to [them](https://github.com/tamlok/vnote/wiki/Donate-List) who donated to VNote! +Thank [users who donated to VNote](https://github.com/tamlok/vnote/wiki/Donate-List)! # Why VNote ## Markdown Editor & Notes Management diff --git a/README_zh.md b/README_zh.md index 9514eb66..a4eea8fc 100644 --- a/README_zh.md +++ b/README_zh.md @@ -126,7 +126,7 @@ VNote不是一个简单的Markdown编辑器。通过提供笔记管理功能,V -非常感谢这些VNote的 [捐赠者](https://github.com/tamlok/vnote/wiki/Donate-List) ! +非常感谢[这些用户](https://github.com/tamlok/vnote/wiki/Donate-List)对VNote的捐赠! # 开发VNote的动机 ## Markdown编辑器与笔记管理 diff --git a/src/resources/docs/welcome_en.md b/src/resources/docs/welcome_en.md index fb26c481..2b7b1a44 100644 --- a/src/resources/docs/welcome_en.md +++ b/src/resources/docs/welcome_en.md @@ -5,7 +5,7 @@ [VNote](https://tamlok.github.io/vnote) provides fancy Markdown experience as well as powerful notes management. -VNote is **open source** and currently mainly developed and maintained by one single person in spare time. Hence, please don't hesitate to give VNote a hand if she does improve your productivity. +VNote is **open source** and currently mainly developed and maintained by one single person in spare time. Hence, please don't hesitate to give VNote a hand if she does improve your productivity. Thank [users who donated to VNote](https://github.com/tamlok/vnote/wiki/Donate-List)! ## Troubleshooting Guide VNote could be used in two ways: diff --git a/src/resources/docs/welcome_zh.md b/src/resources/docs/welcome_zh.md index 7accd234..41a950b7 100644 --- a/src/resources/docs/welcome_zh.md +++ b/src/resources/docs/welcome_zh.md @@ -5,7 +5,7 @@ [VNote](https://tamlok.github.io/vnote) 提供了美妙的Markdown体验以及强大的笔记管理。 -VNote是**开源**的,当前主要由个人在业余时间进行开发和维护。因此,如果VNote给您的效率带来了提升,请考虑帮助VNote成长。 +VNote是**开源**的,当前主要由个人在业余时间进行开发和维护。因此,如果VNote给您的效率带来了提升,请考虑帮助VNote成长。非常感谢[这些用户](https://github.com/tamlok/vnote/wiki/Donate-List)对VNote的捐赠! ## 问题解决指南 VNote有两种使用方式: diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index 42cd53f3..b9be214e 100644 --- a/src/vmainwindow.cpp +++ b/src/vmainwindow.cpp @@ -3405,7 +3405,9 @@ void VMainWindow::kickOffStartUpTimer(const QStringList &p_files) QCoreApplication::sendPostedEvents(); openStartupPages(); openFiles(p_files, false, g_config->getNoteOpenMode(), false, true); - if (g_config->versionChanged()) { + + if (g_config->versionChanged() + || (QDate::currentDate().dayOfYear() % 64 == 1)) { QString docFile = VUtils::getDocFile("welcome.md"); VFile *file = vnote->getFile(docFile, true); m_editArea->openFile(file, OpenFileMode::Read); diff --git a/src/vtable.cpp b/src/vtable.cpp index ade3572a..ec9eb1cc 100644 --- a/src/vtable.cpp +++ b/src/vtable.cpp @@ -325,6 +325,12 @@ void VTable::formatOneColumn(int p_idx, int p_cursorRowIdx, int p_cursorPib) QString core = cell.m_text.mid(info.m_coreOffset, info.m_coreLength); int nr = (targetWidth - info.m_coreWidth + m_spaceWidth / 2) / m_spaceWidth; cell.m_formattedText = generateFormattedText(core, nr, fakeAlign); + + // For cells crossing lines and having spaces at the end of one line, + // Qt will collapse those spaces, which make it not well formatted. + if (cell.m_text == cell.m_formattedText) { + cell.m_formattedText.clear(); + } } } } @@ -407,12 +413,28 @@ void VTable::calculateBasicWidths(const QTextBlock &p_block, int p_borderPos) int VTable::calculateTextWidth(const QTextBlock &p_block, int p_pib, int p_length) const { - QTextLine line = p_block.layout()->lineForTextPosition(p_pib); - if (line.isValid()) { - return line.cursorToX(p_pib + p_length) - line.cursorToX(p_pib); + // The block may cross multiple lines. + int width = 0; + QTextLayout *layout = p_block.layout(); + QTextLine line = layout->lineForTextPosition(p_pib); + while (line.isValid()) { + int lineEnd = line.textStart() + line.textLength(); + if (lineEnd >= p_pib + p_length) { + // The last line. + width += line.cursorToX(p_pib + p_length) - line.cursorToX(p_pib); + break; + } else { + // Cross lines. + width += line.cursorToX(lineEnd) - line.cursorToX(p_pib); + + // Move to next line. + p_length = p_length - (lineEnd - p_pib); + p_pib = lineEnd; + line = layout->lineForTextPosition(p_pib + 1); + } } - return -1; + return width > 0 ? width : -1; } bool VTable::isHeaderRow(int p_idx) const