浏览代码

refine line number area

Le Tan 8 年之前
父节点
当前提交
0d0f6d4e47
共有 3 个文件被更改,包括 37 次插入8 次删除
  1. 35 6
      src/vedit.cpp
  2. 1 1
      src/vedit.h
  3. 1 1
      src/vnotebookselector.cpp

+ 35 - 6
src/vedit.cpp

@@ -908,15 +908,44 @@ void VEdit::lineNumberAreaPaintEvent(QPaintEvent *p_event)
     const int curBlockNumber = textCursor().block().blockNumber();
     const int curBlockNumber = textCursor().block().blockNumber();
     const bool relative = vconfig.getEditorLineNumber() == 2;
     const bool relative = vconfig.getEditorLineNumber() == 2;
     const QString &fg = vconfig.getEditorLineNumberFg();
     const QString &fg = vconfig.getEditorLineNumberFg();
+    painter.setPen(fg);
 
 
     while (block.isValid() && top <= eventBtm) {
     while (block.isValid() && top <= eventBtm) {
         if (block.isVisible() && bottom >= eventTop) {
         if (block.isVisible() && bottom >= eventTop) {
-            QString number = QString::number(relative ? blockNumber - curBlockNumber
-                                                      : blockNumber + 1);
-            painter.setPen(fg);
-            painter.drawText(0, top + 2,
+            bool currentLine = false;
+            int number = blockNumber + 1;
+            if (relative) {
+                number = blockNumber - curBlockNumber;
+                if (number == 0) {
+                    currentLine = true;
+                    number = blockNumber + 1;
+                } else if (number < 0) {
+                    number = -number;
+                }
+            } else if (blockNumber == curBlockNumber) {
+                currentLine = true;
+            }
+
+            QString numberStr = QString::number(number);
+
+            if (currentLine) {
+                QFont font = painter.font();
+                font.setBold(true);
+                painter.setFont(font);
+            }
+
+            painter.drawText(0,
+                             top + 2,
                              m_lineNumberArea->width(),
                              m_lineNumberArea->width(),
-                             digitHeight, Qt::AlignRight, number);
+                             digitHeight,
+                             Qt::AlignRight,
+                             numberStr);
+
+            if (currentLine) {
+                QFont font = painter.font();
+                font.setBold(false);
+                painter.setFont(font);
+            }
         }
         }
 
 
         block = block.next();
         block = block.next();
@@ -999,7 +1028,7 @@ int LineNumberArea::calculateWidth() const
         ++digits;
         ++digits;
     }
     }
 
 
-    int width = 2 + m_digitWidth * digits;
+    int width = m_digitWidth * digits;
     const_cast<LineNumberArea *>(this)->m_width = width;
     const_cast<LineNumberArea *>(this)->m_width = width;
 
 
     return m_width;
     return m_width;

+ 1 - 1
src/vedit.h

@@ -231,7 +231,7 @@ public:
           m_document(p_editor->document()),
           m_document(p_editor->document()),
           m_width(0), m_blockCount(-1)
           m_width(0), m_blockCount(-1)
     {
     {
-        m_digitWidth = m_editor->fontMetrics().width(QLatin1Char('9'));
+        m_digitWidth = m_editor->fontMetrics().width(QLatin1Char('1'));
         m_digitHeight = m_editor->fontMetrics().height();
         m_digitHeight = m_editor->fontMetrics().height();
     }
     }
 
 

+ 1 - 1
src/vnotebookselector.cpp

@@ -163,7 +163,7 @@ void VNotebookSelector::update()
 bool VNotebookSelector::newNotebook()
 bool VNotebookSelector::newNotebook()
 {
 {
     QString info(tr("Please type the name of the notebook and "
     QString info(tr("Please type the name of the notebook and "
-                    "choose an existing folder as Root Folder of the notebook."));
+                    "choose a folder as the Root Folder of the notebook."));
     info += "\n";
     info += "\n";
     info += tr("The root folder should be used EXCLUSIVELY by VNote and "
     info += tr("The root folder should be used EXCLUSIVELY by VNote and "
                "it is recommended to be EMPTY.");
                "it is recommended to be EMPTY.");