]> gitweb.hamatoma.de Git - reqt/commitdiff
ReEditor: tab handling works
authorhama <hama@siduction.net>
Wed, 2 Sep 2015 19:48:12 +0000 (21:48 +0200)
committerhama <hama@siduction.net>
Wed, 2 Sep 2015 19:48:12 +0000 (21:48 +0200)
appl/reide/projectselection.cpp
cunit/cuReEdit.cpp
gui/ReEdit.cpp
gui/ReEdit.hpp
resources/tab4.txt [new file with mode: 0644]

index 742352f0cb79f1c90fb449323203f58bd8a4a664..e8972a72e1b918aacd928167d2bbc221b24c82f7 100644 (file)
@@ -127,7 +127,7 @@ void ProjectSelection::buildTableInfo(ReSettings* settings, const char* key,
        for (it = files.cbegin(); it != files.cend(); ++it) {
                QFileInfo file(*it);
                if (file.exists()) {
-                       QString info = file.baseName();
+                       QString info = file.fileName();
                        if (withDate)
                                info.append("\t").append(
                                    file.lastModified().toString("yyyy.mm.dd/HH:MM:SS"));
index ea7f7ebbd681cedda78b83ea051c2c27135a03e7..acb57ae384c74ea8b491bf34e6e28c20222ffc7d 100644 (file)
@@ -18,8 +18,8 @@
 class TestReEdit: public ReTest, protected ReEdit {
 public:
        TestReEdit() :
-                   ReTest("ReEdit"),
-                   ReEdit(NULL) {
+                       ReTest("ReEdit"),
+                       ReEdit(NULL) {
                doIt();
        }
 
@@ -31,7 +31,7 @@ public:
                setLines(&m_lines);
        }
        void pushKey(int key, const QString& text = "",
-           Qt::KeyboardModifiers modifiers = Qt::NoModifier) {
+               Qt::KeyboardModifiers modifiers = Qt::NoModifier) {
                QKeyEvent event(QEvent::KeyPress, key, modifiers, text);
                keyPressEvent(&event);
        }
@@ -69,7 +69,7 @@ public:
                checkEqu(expectedCol, m_cursorCol);
        }
        void checkCursorPos(EditorAction action, int expectedLineNo,
-           int expectedCol) {
+               int expectedCol) {
                editorAction(action);
                checkEqu(expectedLineNo, m_cursorLineNo);
                checkEqu(expectedCol, m_cursorCol);
@@ -314,7 +314,39 @@ public:
 
                log("ok");
        }
+       void testIndexToColumn(){
+               /*
+                * <pre>tabulator width: 4
+                * _01230123
+                * _    x       index: 0 blanks: 3
+                * _x   x       index: 1 blanks: 2
+                * _xx  x       index: 2 blanks: 1
+                * _xxx x       index: 3 blanks: 0
+                * </pre>
+                */
+               int tabWidth = 4;
+               checkEqu(0, ReParagraphs::indexToColumn(0, tabWidth, "\tx"));
+               checkEqu(4, ReParagraphs::indexToColumn(1, tabWidth, "\tx"));
+               checkEqu(5, ReParagraphs::indexToColumn(2, tabWidth, "\tx"));
+               checkEqu(5, ReParagraphs::indexToColumn(3, tabWidth, "\tx"));
+
+               checkEqu(1, ReParagraphs::indexToColumn(1, tabWidth, "1\tx"));
+               checkEqu(4, ReParagraphs::indexToColumn(2, tabWidth, "1\tx"));
+               checkEqu(5, ReParagraphs::indexToColumn(3, tabWidth, "1\tx"));
+
+               checkEqu(1, ReParagraphs::indexToColumn(1, tabWidth, "12\tx"));
+               checkEqu(2, ReParagraphs::indexToColumn(2, tabWidth, "12\tx"));
+               checkEqu(4, ReParagraphs::indexToColumn(3, tabWidth, "12\tx"));
+               checkEqu(5, ReParagraphs::indexToColumn(5, tabWidth, "12\tx"));
+
+               checkEqu(1, ReParagraphs::indexToColumn(1, tabWidth, "123\tx"));
+               checkEqu(2, ReParagraphs::indexToColumn(2, tabWidth, "123\tx"));
+               checkEqu(3, ReParagraphs::indexToColumn(3, tabWidth, "123\tx"));
+               checkEqu(4, ReParagraphs::indexToColumn(4, tabWidth, "123\tx"));
+       }
+
        virtual void run() {
+               testIndexToColumn();
                testDeleteLine();
                testDeleteText();
                testEnterText();
index a787dc02d375be5d01aa4cd51006246759fd14cb..3007ba89a653dd137eb9a6d6313dcf73e9acf47e 100644 (file)
@@ -16,7 +16,7 @@
 QStringList ReParagraphs::m_tabStrings;
 // RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
 QChar ReParagraphs::m_tabChar = QChar(0xBB);
-int ReParagraphs::m_tabWidth = 3;
+int ReParagraphs::m_tabWidth = 4;
 
 /**
  * Calculates the full line height (with gap between lines)
@@ -140,7 +140,7 @@ ReEdit::ReEdit(QWidget* parent) :
 
        assignColorsStandard();
 
-       setTabStrings(3);
+       setTabStrings(4);
        appendBuilder(new ReParagraphBuilder());
        appendBuilder(new ReCursortLineBuilder());
        assignKeysStandard();
@@ -678,7 +678,7 @@ void ReEdit::paintEvent(QPaintEvent* event) {
        ReLook* lookStd = lookOf(ReLook::FG_STANDARD, ReLook::BG_STANDARD);
        int maxIx = min(m_list.length(), m_lines->lineCount() - m_firstLine);
        for (int ix = 0; ix < maxIx; ix++, lineNo++) {
-               QString number = QString::number(lineNo) + ":";
+               QString number = QString::number(lineNo);
                ReLook* look =
                    lineNo == m_cursorLineNo + 1 ?
                        lookOf(ReLook::FG_CURRENT_LINE, ReLook::BG_CURRENT_LINE) :
@@ -697,11 +697,10 @@ void ReEdit::paintEvent(QPaintEvent* event) {
            && m_cursorLineNo < firstLine + pageSize) {
                ReParagraph* cursorPara = cursorParagraph();
                int col = min(m_cursorCol, cursorPara->m_columns - 1);
-               if (col != -1)
-                       col = indexToColumn(col, m_tabWidth,
-                           m_lines->lineAt(m_cursorLineNo)) - m_firstCol;
+               col = indexToColumn(col + 1, m_tabWidth,
+                   m_lines->lineAt(m_cursorLineNo)) - m_firstCol;
                int x = rect.left() + m_widthLineNumbers + 1
-                   + (col + 1) * lookStd->m_metrics->width('x');
+                   + col * lookStd->m_metrics->width('x');
                int y = rect.top() + (m_cursorLineNo - firstLine) * lineHeight;
                painter.setPen(*look->m_pen);
                painter.drawLine(x, y, x, y + lineHeight);
@@ -764,7 +763,7 @@ void ReEdit::setTabStrings(int tabWidth) {
        m_tabStrings.clear();
        QString blanks;
        blanks.fill(' ', tabWidth);
-       for (int ix = 0; ix <= tabWidth - 1; ix++) {
+       for (int ix = 0; ix < tabWidth; ix++) {
                m_tabStrings.append(m_tabChar + blanks.mid(0, tabWidth - 1 - ix));
        }
 }
@@ -828,6 +827,8 @@ int ReParagraphs::columnToIndex(int column, int tabWidth,
        int rc = 0;
        if (column < 0)
                rc = -1;
+       else if (column == 0)
+               rc = 0;
        else {
                int cursor = 0;
                int length = string.length();
@@ -908,15 +909,15 @@ void ReParagraphs::draw(QPainter& painter, int top, int left) {
 int ReParagraphs::indexToColumn(int index, int tabWidth,
     const QString& string) {
        int rc = 0;
-       if (index >= 0) {
+       if (index > 0) {
                int length = string.length();
                for (int cursor = 0; cursor < index && cursor < length; cursor++) {
-                       if (string.at(cursor) != m_tabChar)
+                       if (string.at(cursor) != '\t')
                                rc++;
                        else {
                                // if the cursor points to the last char (tab): do not expand!
-                               if (cursor < index - 1)
-                                       rc += tabWidth - 1 - (cursor % tabWidth);
+                               if (cursor < index)
+                                       rc += tabWidth - (cursor % tabWidth);
                        }
                }
        }
@@ -1002,7 +1003,7 @@ void ReParagraphBuilder::buildParagraph(ReParagraph& paragraph, int lineNo,
                                }
                                cursor += length;
                        }
-                       QString tabs = ReEdit::tabString(cursor + 1);
+                       QString tabs = ReEdit::tabString(cursor);
                        length = tabs.length();
                        if (cursor + length > firstCol && cursor < maxCol) {
                                if (cursor < firstCol)
index a1d14da503918372a9edf8dd8e650916fac009ea..127be8515e824b64333a04bd1c7aa87d4901528d 100644 (file)
@@ -344,8 +344,7 @@ protected:
        void drawScrollbars(QPainter& painter, const QRect& rect,
            double sizeVertical, double posVertical, double sizeHorizontal,
            double posHorizontal);
-       void ensureCursorVisible();
-protected slots:
+       void ensureCursorVisible();protected slots:
        void keyPressEvent(QKeyEvent* event);
        void paintEvent(QPaintEvent *);
        void mouseMoveEvent(QMouseEvent* event);
diff --git a/resources/tab4.txt b/resources/tab4.txt
new file mode 100644 (file)
index 0000000..4006733
--- /dev/null
@@ -0,0 +1,11 @@
+Tabwidth 4
+       x
+1      x
+12     x
+123    x
+1234   x
+    y
+1   y
+12  y
+123 y
+1234    x