浏览代码

Editor: fix smart table cell crossing lines

Le Tan 6 年之前
父节点
当前提交
37c415f732
共有 6 个文件被更改,包括 33 次插入9 次删除
  1. 1 1
      README.md
  2. 1 1
      README_zh.md
  3. 1 1
      src/resources/docs/welcome_en.md
  4. 1 1
      src/resources/docs/welcome_zh.md
  5. 3 1
      src/vmainwindow.cpp
  6. 26 4
      src/vtable.cpp

+ 1 - 1
README.md

@@ -125,7 +125,7 @@ You could help VNote's development in many ways.
 
 <img src="screenshots/wechat_pay.png" width="256px" height="256px" />
 
-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

+ 1 - 1
README_zh.md

@@ -126,7 +126,7 @@ VNote不是一个简单的Markdown编辑器。通过提供笔记管理功能,V
 
 <img src="screenshots/wechat_pay.png" width="256px" height="256px" />
 
-非常感谢这些VNote的 [捐赠者](https://github.com/tamlok/vnote/wiki/Donate-List) !
+非常感谢[这些用户](https://github.com/tamlok/vnote/wiki/Donate-List)对VNote的捐赠!
 
 # 开发VNote的动机
 ## Markdown编辑器与笔记管理

+ 1 - 1
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:

+ 1 - 1
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有两种使用方式:

+ 3 - 1
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);

+ 26 - 4
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