]> gitweb.hamatoma.de Git - reqt/commitdiff
CUnit test for ReEdit
authorhama <hama@siduction.net>
Sun, 26 Jul 2015 22:08:28 +0000 (00:08 +0200)
committerhama <hama@siduction.net>
Sun, 26 Jul 2015 22:08:28 +0000 (00:08 +0200)
cunit/allTests.cpp
cunit/cuReEdit.cpp
cunit/cunit.pro
gui/ReEdit.cpp

index 284308885012881ecbe4fea7170f7136f17cd103..947702f4054126aeb954cce1f060ba314a5bd347 100644 (file)
 #include "../math/remath.hpp"
 #include "../net/renet.hpp"
 //#include "os/reos.hpp"
+#include <QApplication>
 
 static bool s_allTest = false;
 
+static void testGui() {
+       char* argv[2] = { (char*) "dummy", NULL };
+       int argc = 1;
+       QApplication a(argc, argv);
+       void testReEdit();
+       testReEdit();
+}
+
 static void testBase() {
        void testReByteStorage();
        void testReCharPtrMap();
@@ -25,7 +34,6 @@ static void testBase() {
        void testReStringUtil();
        void testReWriter();
        void testReFile();
-
        testReFile();
        if (s_allTest) {
                testReQStringUtil();
@@ -71,6 +79,7 @@ static void testOs() {
 
 }
 void allTests() {
+       testGui();
        testBase();
        if (s_allTest) {
                testBase();
index ed0564c541fefa7046efa699fc3c8b7961de3d76..c537501281227c86252c5cad0a1917c9b4efa34f 100644 (file)
@@ -4,9 +4,10 @@
  * There is no warranty.
  * You also can use the licence from http://www.wtfpl.net/.
  * The original sources can be found on https://github.com/republib.
-*/
+ */
 #include "base/rebase.hpp"
 #include "gui/regui.hpp"
+#include "QKeyEvent"
 /** @file
  * @brief Unit test of the basic exceptions.
  */
 class TestReEdit: public ReTest, protected ReEdit {
 public:
        TestReEdit() :
-                       ReTest("ReEdit") {
+                   ReTest("ReEdit"),
+                   ReEdit(NULL) {
                doIt();
        }
 
 public:
        ReLines m_lines;
-       void init(const QString& lines){
+       void init(const QString& lines) {
                m_lines.clear();
-               m_lines.append(lines);
+               m_lines.insertLines(0, lines, false);
                setLines(&m_lines);
        }
+       void pushKey(int key, const QString& text = "",
+           Qt::KeyboardModifiers modifiers = Qt::NoModifier) {
+               QKeyEvent event(QEvent::KeyPress, key, modifiers, text);
+               keyPressEvent(&event);
+       }
+
+       void checkFirstPos(int col, int expectedFirstLine, int expectedFirstCol) {
+               m_cursorCol = col;
+               ensureCursorVisible();
+               checkEqu(expectedFirstLine, m_firstLine);
+               checkEqu(expectedFirstCol, m_firstCol);
+       }
 
        void testEnsureCursorVisible() {
                init("abc\n123456789_12\nxyz");
                m_screenWidth = 5;
                m_firstLine = 0;
                m_firstCol = 0;
-               m_cursorLineNo = -1;
-               ensureCursorVisible();
-               checkEqu(0, m_firstLineNo);
-               checkEqu(-1, m_firstCol);
+               checkFirstPos(0, 0, 0);
 
-               m_cursorLine = 1;
-               for (col = 0; col < m_screenWidth; col++){
-                       m_cursorCol = col;
-                       ensureCursorVisible();
-                       checkEqu(1, m_firstLineNo);
-                       checkEqu(0, m_firstCol);
-               }
-               for (col = m_screenWidth; col < 2* m_screenWidth; col++){
-                       m_cursorCol = col;
-                       ensureCursorVisible();
-                       checkEqu(1, m_firstLineNo);
-                       checkEqu(m_screenWidth, m_firstCol);
+               m_cursorLineNo = 1;
+               int col;
+               for (col = 0; col < m_screenWidth; col++) {
+                       checkFirstPos(col, 1, 0);
                }
-               for (col = 2*m_screenWidth; col < 13; col++){
-                       m_cursorCol = col;
-                       ensureCursorVisible();
-                       checkEqu(1, m_firstLineNo);
-                       checkEqu(2*m_screenWidth, m_firstCol);
+               int lineLength = 12;
+               int colMax = lineLength - m_screenWidth;
+               checkFirstPos(m_screenWidth, 1, m_screenWidth);
+               checkFirstPos(m_screenWidth + 1, 1, m_screenWidth + 1);
+               for (col = colMax; col < lineLength + 2; col++) {
+                       checkFirstPos(col, 1, colMax);
                }
+       }
+       void checkCursorPos(int key, int expectedLineNo, int expectedCol) {
+               pushKey(key);
+               checkEqu(expectedLineNo, m_cursorLineNo);
+               checkEqu(expectedCol, m_cursorCol);
+       }
+       void checkCursorPos(EditorAction action, int expectedLineNo,
+           int expectedCol) {
+               editorAction(action);
+               checkEqu(expectedLineNo, m_cursorLineNo);
+               checkEqu(expectedCol, m_cursorCol);
+       }
+
+       void testCursorMove() {
+               init("abc\n123456789_12\nxy");
+               m_screenWidth = 5;
+               m_firstLine = 0;
+               m_firstCol = 0;
+               m_cursorCol = -1;
+               m_cursorLineNo = 0;
+               // Left, right, pos1 and end:
+               checkCursorPos(Qt::Key_Right, 0, 0);
+               checkCursorPos(Qt::Key_Right, 0, 1);
+               checkCursorPos(Qt::Key_Right, 0, 2);
+               // next line:
+               checkCursorPos(Qt::Key_Right, 1, -1);
+               checkCursorPos(Qt::Key_Right, 1, 0);
+               checkCursorPos(Qt::Key_Right, 1, 1);
+               checkCursorPos(Qt::Key_Home, 1, -1);
+               checkCursorPos(Qt::Key_End, 1, 11);
+               // next line:
+               checkCursorPos(Qt::Key_Right, 2, -1);
+               checkCursorPos(Qt::Key_Right, 2, 0);
+               checkCursorPos(Qt::Key_Right, 2, 1);
+               // EoF reached: position remains
+               checkCursorPos(Qt::Key_Right, 2, 1);
+               checkCursorPos(Qt::Key_Left, 2, 0);
+               checkCursorPos(Qt::Key_Left, 2, -1);
+               // prev. line:
+               checkCursorPos(Qt::Key_Left, 1, 11);
+               checkCursorPos(Qt::Key_Left, 1, 10);
+               checkCursorPos(Qt::Key_Home, 1, -1);
+               // prev. line:
+               checkCursorPos(Qt::Key_Left, 0, 2);
+               checkCursorPos(Qt::Key_Left, 0, 1);
+               checkCursorPos(Qt::Key_Left, 0, 0);
+               checkCursorPos(Qt::Key_Left, 0, -1);
+               // BoF: position remains:
+               checkCursorPos(Qt::Key_Left, 0, -1);
+
+               // Right when column to left:
+               checkCursorPos(Qt::Key_Down, 1, -1);
+               checkCursorPos(Qt::Key_End, 1, 11);
+               // the column remains at 11!
+               checkCursorPos(Qt::Key_Up, 0, 11);
+               // the last index is 2
+               checkCursorPos(Qt::Key_Left, 0, 1);
+               checkCursorPos(Qt::Key_Left, 0, 0);
+               checkCursorPos(Qt::Key_Left, 0, -1);
+
+               // Up and down, first column:
+               // first line: position remains:
+               checkCursorPos(Qt::Key_Up, 0, -1);
+               checkCursorPos(Qt::Key_Down, 1, -1);
+               checkCursorPos(Qt::Key_Down, 2, -1);
+               // last line: position remains:
+               checkCursorPos(Qt::Key_Down, 2, -1);
+               checkCursorPos(Qt::Key_Up, 1, -1);
+               checkCursorPos(Qt::Key_Up, 0, -1);
+               checkCursorPos(Qt::Key_Down, 1, -1);
+               // Up and down, last column:
+               checkCursorPos(Qt::Key_End, 1, 11);
+               checkCursorPos(Qt::Key_Up, 0, 11);
+               checkCursorPos(Qt::Key_Up, 0, 11);
+               checkCursorPos(Qt::Key_Down, 1, 11);
+               checkCursorPos(Qt::Key_Down, 2, 11);
+               checkCursorPos(Qt::Key_Down, 2, 11);
+
+               // BoF and EoF:
+               checkCursorPos(EA_BEGIN_OF_FILE, 0, -1);
+               checkCursorPos(EA_BEGIN_OF_FILE, 0, -1);
+               checkCursorPos(EA_END_OF_FILE, 2, 1);
+               checkCursorPos(EA_END_OF_FILE, 2, 1);
+               checkCursorPos(EA_BEGIN_OF_FILE, 0, -1);
+       }
+
+       void testEnterText() {
+               init("abc\n1234\nxy");
+               m_screenWidth = 5;
+               m_firstLine = 0;
+               m_firstCol = 0;
+
+               // Split line at the end:
+               m_cursorLineNo = 0;
+               m_cursorCol = 2;
+               pushKey(Qt::Key_Enter, "\n");
+               checkEqu("abc", m_lines.lineAt(0));
+               checkEqu("", m_lines.lineAt(1));
+               checkEqu("1234", m_lines.lineAt(2));
+
+               // Split line in the middle of the line:
+               m_cursorLineNo = 0;
+               m_cursorCol = 1;
+               init("abc\n1234\nxy");
+               pushKey(Qt::Key_Enter, "\n");
+               checkEqu("ab", m_lines.lineAt(0));
+               checkEqu("c", m_lines.lineAt(1));
+               checkEqu("1234", m_lines.lineAt(1));
                log("ok");
        }
+
        virtual void run() {
-               testBasic();
+               testEnterText();
+               testCursorMove();
+               testEnsureCursorVisible();
        }
 };
-void TestReEdit() {
+void testReEdit() {
        TestReEdit test;
+       ReUseParameter(&test);
 }
 
-
-
-
index b607cd1b24d4fe5a42d3ef41591cde3d555e9ced..2c38ac6fb774f38b33a3ca6b7006c077fd913667 100644 (file)
@@ -5,6 +5,7 @@
 #-------------------------------------------------
 
 QT       += core network gui
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 
 TARGET = cunit
 CONFIG   += console
@@ -37,8 +38,10 @@ SOURCES += main.cpp \
         cuReWriter.cpp \
         cuReCharPtrMap.cpp \
         cuReFile.cpp \
-       cuReEdit.cpp
+       cuReEdit.cpp \
+    ../gui/ReEdit.cpp
 
 HEADERS += \
         ../base/ReFile.hpp \
-        ../base/rebase.hpp
+        ../base/rebase.hpp \
+    ../gui/ReEdit.hpp
index f20d60958f920381952632d1702cd4e2ea1114be..6b9e7d78a17cd7c9644f71c85fe2063713adfa2d 100644 (file)
@@ -36,11 +36,11 @@ inline int heightToFullHeight(int height) {
  * @param edit          the parent
  */
 ReLook::ReLook() :
-               m_font(NULL),
-               m_metrics(NULL),
-               m_foreground(FG_STANDARD),
-               m_background(BG_STANDARD),
-               m_edit(NULL) {
+           m_font(NULL),
+           m_metrics(NULL),
+           m_foreground(FG_STANDARD),
+           m_background(BG_STANDARD),
+           m_edit(NULL) {
 }
 
 /**
@@ -50,8 +50,8 @@ ReLook::ReLook() :
  * @param look  the presentation of the text
  */
 ReEditText::ReEditText(const QString& text, ReLook* look) :
-               m_text(text),
-               m_look(look) {
+           m_text(text),
+           m_look(look) {
 
 }
 
@@ -64,7 +64,7 @@ ReEditText::ReEditText(const QString& text, ReLook* look) :
  * @param edit      the edit field (parent)
  */
 void ReCursortLineBuilder::buildParagraph(ReParagraph& paragraph, int lineNo,
-       ReEdit* edit) {
+    ReEdit* edit) {
        if (lineNo == edit->cursorLineNo()) {
                for (int ix = 0; ix < paragraph.length(); ix++) {
                        ReEditText* text = paragraph.at(ix);
@@ -100,32 +100,32 @@ void ReCursortLineBuilder::buildParagraph(ReParagraph& paragraph, int lineNo,
  * @param parent    NULL or a widget which destroy the instance
  */
 ReEdit::ReEdit(QWidget* parent) :
-               QWidget(parent),
-               ReMouseCatcher(),
-               m_widthEdit(0),
-               m_heightEdit(0),
-               m_insertMode(true),
-               m_breakLines(false),
-               m_widthLineNumbers(50),
-               m_widthVScrollBar(16),
-               m_heightHScrollBar(16),
-               m_looks(),
-               m_standardBrush(new QBrush(Qt::SolidPattern)),
-               m_scrollbarBrush(new QBrush(Qt::SolidPattern)),
-               m_sliderBrush(new QBrush(Qt::ConicalGradientPattern)),
-               m_brushColors(),
-               m_standardPen(new QPen(Qt::SolidLine)),
-               m_standardFont(NULL),
-               m_standardMetrics(NULL),
-               m_fontColors(),
-               m_keyAlt(),
-               m_keyAltControl(),
-               m_keyAltControlShift(),
-               m_keyAltShift(),
-               m_keyControl(),
-               m_keyControlShift(),
-               m_keyRaw(),
-               m_keyShift() {
+           QWidget(parent),
+           ReMouseCatcher(),
+           m_widthEdit(0),
+           m_heightEdit(0),
+           m_insertMode(true),
+           m_breakLines(false),
+           m_widthLineNumbers(50),
+           m_widthVScrollBar(16),
+           m_heightHScrollBar(16),
+           m_looks(),
+           m_standardBrush(new QBrush(Qt::SolidPattern)),
+           m_scrollbarBrush(new QBrush(Qt::SolidPattern)),
+           m_sliderBrush(new QBrush(Qt::ConicalGradientPattern)),
+           m_brushColors(),
+           m_standardPen(new QPen(Qt::SolidLine)),
+           m_standardFont(NULL),
+           m_standardMetrics(NULL),
+           m_fontColors(),
+           m_keyAlt(),
+           m_keyAltControl(),
+           m_keyAltControlShift(),
+           m_keyAltShift(),
+           m_keyControl(),
+           m_keyControlShift(),
+           m_keyRaw(),
+           m_keyShift() {
        setFocusPolicy(Qt::WheelFocus);
        m_standardFont = new QFont("Courier");
        m_standardFont->setStyleHint(QFont::TypeWriter);
@@ -222,7 +222,7 @@ void ReEdit::assignKeysStandard() {
  * @param length        OUT: the slider length in pixel
  */
 void calcSliderSize(int size, int minSize, double sizeFactor, double posFactor,
-       int& position, int& length) {
+    int& position, int& length) {
        if (sizeFactor > 1.0)
                sizeFactor = 1.0;
        if (posFactor > 100)
@@ -266,8 +266,8 @@ int ReEdit::cursorLineNo() const {
  * @param posHorizontal     the position of the scrollbar as factor [0..1]
  */
 void ReEdit::drawScrollbars(QPainter& painter, const QRect& rect,
-       double sizeVertical, double posVertical, double sizeHorizontal,
-       double posHorizontal) {
+    double sizeVertical, double posVertical, double sizeHorizontal,
+    double posHorizontal) {
        // We paint the vertical scrollbar:
        QBrush brush(*m_brushColors[ReLook::BG_SCROLLBAR], Qt::SolidPattern);
        painter.setBrush(brush);
@@ -276,14 +276,14 @@ void ReEdit::drawScrollbars(QPainter& painter, const QRect& rect,
        static int width = 1;
        static int width2 = 2 * width;
        m_vScrollBar->setRect(x + width2, rect.top(), m_widthVScrollBar - width2,
-               rect.height() - m_heightHScrollBar - width);
+           rect.height() - m_heightHScrollBar - width);
        painter.drawRect(*m_vScrollBar);
 
        // We paint the horizontal scrollbar:
        m_hScrollBar->setRect(rect.left() + m_widthLineNumbers,
-               rect.bottom() - m_heightHScrollBar + width,
-               rect.width() - m_widthVScrollBar - m_widthLineNumbers,
-               m_heightHScrollBar - width2);
+           rect.bottom() - m_heightHScrollBar + width,
+           rect.width() - m_widthVScrollBar - m_widthLineNumbers,
+           m_heightHScrollBar - width2);
        painter.drawRect(*m_hScrollBar);
 
        // Slider (vertical)
@@ -292,17 +292,17 @@ void ReEdit::drawScrollbars(QPainter& painter, const QRect& rect,
        int sliderSize = 0;
        int sliderPos = 0;
        calcSliderSize(rect.height() - m_heightHScrollBar, m_heightHScrollBar,
-               sizeVertical, posVertical, sliderPos, sliderSize);
+           sizeVertical, posVertical, sliderPos, sliderSize);
        m_vSlider->setRect(x + width2, rect.top() + sliderPos + width,
-               m_widthVScrollBar - width2, sliderSize - width2);
+           m_widthVScrollBar - width2, sliderSize - width2);
        painter.drawRect(*m_vSlider);
        // Slider (horizontal)
        calcSliderSize(rect.width() - m_widthLineNumbers - m_widthVScrollBar,
-               m_heightHScrollBar, sizeHorizontal, posHorizontal, sliderPos,
-               sliderSize);
+           m_heightHScrollBar, sizeHorizontal, posHorizontal, sliderPos,
+           sliderSize);
        m_hSlider->setRect(rect.left() + m_widthLineNumbers + sliderPos,
-               rect.bottom() - m_heightHScrollBar + width, sliderSize - width,
-               m_heightHScrollBar - width2);
+           rect.bottom() - m_heightHScrollBar + width, sliderSize - width,
+           m_heightHScrollBar - width2);
        painter.drawRect(*m_hSlider);
 }
 
@@ -317,13 +317,25 @@ void ReEdit::editorAction(ReEdit::EditorAction action) {
        case EA_UNDEF:
                break;
        case EA_CHAR_LEFT:
-               if (--m_cursorCol < -1)
-                       m_cursorCol = -1;
+               if (--m_cursorCol < -1) {
+                       if (m_cursorLineNo == 0)
+                               m_cursorCol = -1;
+                       else {
+                               m_cursorLineNo--;
+                               m_cursorCol = m_lines->lineAt(m_cursorLineNo).length() - 1;
+                       }
+               } else if (m_cursorCol >= m_lines->lineAt(m_cursorLineNo).length() - 1)
+                       m_cursorCol = m_lines->lineAt(m_cursorLineNo).length() - 2;
                ensureCursorVisible();
                break;
        case EA_CHAR_RIGHT:
-               if (++m_cursorCol >= m_lines->lineAt(m_cursorLineNo).length())
-                       m_cursorCol = m_lines->lineAt(m_cursorLineNo).length() - 1;
+               if (++m_cursorCol >= m_lines->lineAt(m_cursorLineNo).length()) {
+                       int oldLine = m_cursorLineNo;
+                       m_cursorCol = -1;
+                       editorAction(EA_LINE_DOWN);
+                       if (m_cursorLineNo == oldLine)
+                               m_cursorCol = m_lines->lineAt(m_cursorLineNo).length() - 1;
+               }
                ensureCursorVisible();
                break;
        case EA_LINE_UP:
@@ -351,6 +363,7 @@ void ReEdit::editorAction(ReEdit::EditorAction action) {
                break;
        case EA_END_OF_FILE:
                m_cursorLineNo = m_lines->lineCount() - 1;
+               m_cursorCol = m_lines->lineAt(m_cursorLineNo).length() - 1;
                ensureCursorVisible();
                break;
        case EA_PAGE_UP:
@@ -362,9 +375,22 @@ void ReEdit::editorAction(ReEdit::EditorAction action) {
                reposition(m_firstLine + pageSize, m_firstCol);
                break;
        case EA_DEL_CHAR:
+               m_lines->removePart(m_cursorLineNo, m_cursorCol + 1, 1, true);
                break;
-       case EA_BACKSPACE:
+       case EA_BACKSPACE: {
+               int currentCol = m_cursorCol;
+               m_cursorCol = max(-1, currentCol - 1);
+               if (currentCol == -1 && m_cursorLineNo > 0) {
+                       // join the previous and the current line:
+                       // the cursor position will be the end of the previous line:
+                       m_cursorCol = m_lines->lineAt(m_cursorLineNo - 1).length() - 1;
+               }
+               if (m_lines->removePart(m_cursorLineNo, columnToIndex(currentCol), 1,
+                   true))
+                       m_cursorLineNo = max(0, m_cursorLineNo - 1);
+
                break;
+       }
        case EA_DEL_END_OF_LINE:
                break;
        case EA_DEL_BEGIN_OF_LINE:
@@ -399,14 +425,14 @@ void ReEdit::editorAction(ReEdit::EditorAction action) {
  */
 void ReEdit::ensureCursorVisible() {
        if (m_cursorLineNo < m_firstLine
-               || m_cursorLineNo >= m_firstLine + pageSize()) {
+           || m_cursorLineNo >= m_firstLine + pageSize()) {
                reposition(m_cursorLineNo, m_cursorCol);
        }
        if (m_cursorCol < 0)
                m_firstCol = 0;
-       else if ( m_cursorCol < m_firstCol) {
+       else if (m_cursorCol < m_firstCol) {
                m_firstCol = m_cursorCol;
-       } else if (m_cursorCol >= m_firstCol + m_screenWidth){
+       } else if (m_cursorCol >= m_firstCol + m_screenWidth) {
                int length = m_lines->lineAt(m_cursorLineNo).length();
                m_firstCol = max(0, min(m_cursorCol, length - m_screenWidth));
        }
@@ -432,20 +458,11 @@ void ReEdit::keyPressEvent(QKeyEvent* event) {
                        m_cursorLineNo++;
                        break;
                case Qt::Key_Backspace: {
-                       int currentCol = m_cursorCol;
-                       m_cursorCol = max(-1, currentCol - 1);
-                       if (currentCol == -1 && m_cursorLineNo > 0) {
-                               // join the previous and the current line:
-                               // the cursor position will be the end of the previous line:
-                               m_cursorCol = m_lines->lineAt(m_cursorLineNo - 1).length() - 1;
-                       }
-                       if (m_lines->removePart(m_cursorLineNo, columnToIndex(currentCol),
-                               1, true))
-                               m_cursorLineNo = max(0, m_cursorLineNo - 1);
+                       editorAction(EA_BACKSPACE);
                        break;
                }
                case Qt::Key_Delete:
-                       m_lines->removePart(m_cursorLineNo, m_cursorCol + 1, 1, true);
+                       editorAction(EA_DEL_CHAR);
                        break;
                default:
                        m_lines->insertText(m_cursorLineNo, m_cursorCol + 1, keyText);
@@ -453,7 +470,7 @@ void ReEdit::keyPressEvent(QKeyEvent* event) {
                        break;
                }
        } else if (shift && !keyText.isEmpty() && key != Qt::Key_Delete
-               && key != Qt::Key_Backspace) {
+           && key != Qt::Key_Backspace) {
                m_lines->insertText(m_cursorLineNo, m_cursorCol + 1, keyText);
                m_cursorCol++;
        } else {
@@ -499,7 +516,7 @@ ReLines& ReEdit::lines() {
  * @return
  */
 ReLook* ReEdit::lookOf(ReLook::ForeGround foreground,
-       ReLook::BackGround background) {
+    ReLook::BackGround background) {
        int index = foreground * ReLook::BG_COUNT + background;
        ReLook* rc = m_looks[index];
        if (rc == NULL) {
@@ -526,8 +543,8 @@ ReLook* ReEdit::lookOf(ReLook::ForeGround foreground,
  */
 void ReEdit::mouseMoveEvent(QMouseEvent* event) {
        if (m_lastMousePosition.x() >= 0
-               && (handleHScrollBar(event, true, this)
-                       || handleVScrollBar(event, true, this))) {
+           && (handleHScrollBar(event, true, this)
+               || handleVScrollBar(event, true, this))) {
                emit repaint();
        }
 }
@@ -545,12 +562,13 @@ void ReEdit::mousePressEvent(QMouseEvent* event) {
        } else {
                QPoint position = event->pos();
                m_cursorLineNo = position.y()
-                       / heightToFullHeight(m_standardMetrics->height()) + m_firstLine;
+                   / heightToFullHeight(m_standardMetrics->height()) + m_firstLine;
                int x = position.x();
                int charWidth = m_standardMetrics->width('x');
                x -= m_widthLineNumbers;
-               if (x >= 0 && x < m_widthEdit - m_widthLineNumbers - m_widthVScrollBar) {
-                       if (x <=  + charWidth / 2)
+               if (x >= 0
+                   && x < m_widthEdit - m_widthLineNumbers - m_widthVScrollBar) {
+                       if (x <= +charWidth / 2)
                                m_cursorCol = m_firstCol - 1;
                        else
                                m_cursorCol = m_firstCol + columnToIndex(x / charWidth);
@@ -588,14 +606,14 @@ void ReEdit::paintEvent(QPaintEvent* event) {
        int pageSize = (rect.height() - m_heightHScrollBar) / lineHeight;
        int charWidth = m_standardMetrics->averageCharWidth();
        int pageWidth = (rect.width() - m_widthVScrollBar - m_widthLineNumbers)
-               / charWidth;
+           / charWidth;
        int firstLine = m_firstLine;
        load(firstLine, pageSize, pageWidth, this);
        QPainter painter(this);
        ReLook* look = lookOf(ReLook::FG_STANDARD, ReLook::BG_STANDARD);
        painter.setBrush(*look->m_brush);
        QRect editArea(rect.left() + m_widthLineNumbers, rect.top(),
-               rect.right() - m_widthVScrollBar, rect.bottom() - m_heightHScrollBar);
+           rect.right() - m_widthVScrollBar, rect.bottom() - m_heightHScrollBar);
        painter.drawRect(editArea);
        draw(painter, rect.top(), rect.left() + m_widthLineNumbers);
        int left = rect.left() + m_widthLineNumbers - 3;
@@ -606,13 +624,13 @@ void ReEdit::paintEvent(QPaintEvent* event) {
        for (int ix = 0; ix < m_list.length(); ix++, lineNo++) {
                QString number = QString::number(lineNo) + ":";
                ReLook* look =
-                       lineNo == m_cursorLineNo + 1 ?
-                               lookOf(ReLook::FG_CURRENT_LINE, ReLook::BG_CURRENT_LINE) :
-                               lookStd;
+                   lineNo == m_cursorLineNo + 1 ?
+                       lookOf(ReLook::FG_CURRENT_LINE, ReLook::BG_CURRENT_LINE) :
+                       lookStd;
                int width = look->m_metrics->width(number);
                if (ix == 0)
                        y = rect.top() + look->m_metrics->height()
-                               - look->m_metrics->descent();
+                           - look->m_metrics->descent();
                painter.setFont(*look->m_font);
                painter.setPen(*look->m_pen);
                painter.drawText(left + m_widthLineNumbers - width - 5, y, number);
@@ -620,25 +638,25 @@ void ReEdit::paintEvent(QPaintEvent* event) {
        }
        // We paint the cursor:
        if (m_cursorVisible && m_cursorLineNo >= firstLine
-               && m_cursorLineNo < firstLine + pageSize) {
+           && 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, m_tabWidth,
+                           m_lines->lineAt(m_cursorLineNo)) - m_firstCol;
                int x = rect.left() + m_widthLineNumbers + 1
-                       + (col + 1) * lookStd->m_metrics->width('x');
+                   + (col + 1) * 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);
        }
        int maxLines = max(1, m_lines->lineCount() - pageSize);
        drawScrollbars(painter, rect, double(pageSize) / maxLines,
-               double(m_firstLine) / maxLines,
-               m_maxCols == 0 ? 1.0 : (double) m_screenWidth / m_maxCols,
-               m_maxCols == 0 ? 0.0 : (double) m_firstCol / m_maxCols);
+           double(m_firstLine) / maxLines,
+           m_maxCols == 0 ? 1.0 : (double) m_screenWidth / m_maxCols,
+           m_maxCols == 0 ? 0.0 : (double) m_firstCol / m_maxCols);
        ReLogger::globalLogger()->logv(LOG_INFO, 3, "draw: %.4f",
-               double(clock() - start) / CLOCKS_PER_SEC);
+           double(clock() - start) / CLOCKS_PER_SEC);
 }
 
 /**
@@ -698,16 +716,16 @@ void ReEdit::setTabStrings(int tabWidth) {
  * Constructor.
  */
 ReParagraphs::ReParagraphs() :
-               m_builders(),
-               m_firstLine(0),
-               m_firstCol(0),
-               m_cursorLineNo(0),
-               m_cursorCol(-1),
-               m_lines(NULL),
-               m_list(),
-               m_maxCols(0),
-               m_screenWidth(0),
-               m_cursorVisible(true) {
+           m_builders(),
+           m_firstLine(0),
+           m_firstCol(0),
+           m_cursorLineNo(0),
+           m_cursorCol(-1),
+           m_lines(NULL),
+           m_list(),
+           m_maxCols(0),
+           m_screenWidth(0),
+           m_cursorVisible(true) {
 }
 
 /**
@@ -749,7 +767,7 @@ void ReParagraphs::clear() {
  *                                     expanded tabs
  */
 int ReParagraphs::columnToIndex(int column, int tabWidth,
-       const QString& string) {
+    const QString& string) {
        int rc = 0;
        if (column < 0)
                rc = -1;
@@ -779,7 +797,7 @@ int ReParagraphs::columnToIndex(int column, int tabWidth,
 ReParagraph* ReParagraphs::cursorParagraph() {
        ReParagraph* rc = NULL;
        if (m_cursorLineNo >= m_firstLine
-               && m_cursorLineNo < m_firstLine + m_list.length()) {
+           && m_cursorLineNo < m_firstLine + m_list.length()) {
                rc = m_list.at(m_cursorLineNo - m_firstLine);
        }
        return rc;
@@ -793,7 +811,7 @@ ReParagraph* ReParagraphs::cursorParagraph() {
  */
 int ReParagraphs::columnToIndex(int cursorCol) {
        int rc = columnToIndex(cursorCol, m_tabWidth,
-               m_lines->lineAt(m_cursorLineNo));
+           m_lines->lineAt(m_cursorLineNo));
        return rc;
 }
 
@@ -831,7 +849,7 @@ void ReParagraphs::draw(QPainter& painter, int top, int left) {
  * @return
  */
 int ReParagraphs::indexToColumn(int index, int tabWidth,
-       const QString& string) {
+    const QString& string) {
        int rc = 0;
        if (index >= 0) {
                int length = string.length();
@@ -898,13 +916,13 @@ void ReParagraphs::setLines(ReLines* lines) {
  * @param edit      the parent, the edit field
  */
 void ReParagraphBuilder::buildParagraph(ReParagraph& paragraph, int lineNo,
-       ReEdit* edit) {
+    ReEdit* edit) {
        if (paragraph.length() == 0) {
                int firstCol = edit->m_firstCol;
                const QString& text = edit->lines().lineAt(lineNo);
                ReLook* look = edit->lookOf(ReLook::FG_STANDARD, ReLook::BG_STANDARD);
                ReLook* lookTab = edit->lookOf(ReLook::FG_GREY_LIGHT,
-                       ReLook::BG_STANDARD);
+                   ReLook::BG_STANDARD);
                paragraph.m_columns = 0;
                int ixTab;
                ReEditText* part;
@@ -991,14 +1009,14 @@ void ReParagraph::draw(QPainter& painter, int& top, int left) {
  * Constructor.
  */
 ReMouseCatcher::ReMouseCatcher() :
-               m_clickObjects(),
-               m_vScrollBar(new ClickPosition(CO_VSCROLLBAR)),
-               m_hScrollBar(new ClickPosition(CO_HSCROLLBAR)),
-               m_hSlider(new ClickPosition(CO_HSLIDER)),
-               m_vSlider(new ClickPosition(CO_VSLIDER)),
-               m_lastMousePosition(),
-               m_lastTopVSlider(0),
-               m_lastLeftHSlider(0) {
+           m_clickObjects(),
+           m_vScrollBar(new ClickPosition(CO_VSCROLLBAR)),
+           m_hScrollBar(new ClickPosition(CO_HSCROLLBAR)),
+           m_hSlider(new ClickPosition(CO_HSLIDER)),
+           m_vSlider(new ClickPosition(CO_VSLIDER)),
+           m_lastMousePosition(),
+           m_lastTopVSlider(0),
+           m_lastLeftHSlider(0) {
 
 }
 /**
@@ -1031,7 +1049,7 @@ void ReMouseCatcher::insertClickObject(ReMouseCatcher::ClickPosition* object) {
  * @return      <code>true</code>: the mouse click is inside the horizontal sb
  */
 bool ReMouseCatcher::handleHScrollBar(QMouseEvent* event, bool isDragged,
-       ReEdit* edit) {
+    ReEdit* edit) {
        QPoint pos = event->pos();
        bool rc = rectContains(*m_hScrollBar, pos, "hScrollBar");
        if (rc) {
@@ -1041,8 +1059,8 @@ bool ReMouseCatcher::handleHScrollBar(QMouseEvent* event, bool isDragged,
                        int moveGap = m_hScrollBar->width() - m_hSlider->width();
                        double position = moveGap == 0 ? 0.0 : double(sliderPos) / moveGap;
                        int col = roundInt(
-                               (edit->m_maxCols - edit->m_screenWidth)
-                                       * max(0.0, min(position, 1.0)));
+                           (edit->m_maxCols - edit->m_screenWidth)
+                               * max(0.0, min(position, 1.0)));
                        edit->reposition(edit->m_cursorLineNo, col);
                } else {
                        if (pos.y() < m_hSlider->left())
@@ -1063,10 +1081,10 @@ bool ReMouseCatcher::handleHScrollBar(QMouseEvent* event, bool isDragged,
  * @return          <code>true</code>: the mouse click is inside the vertical sb
  */
 bool ReMouseCatcher::handleVScrollBar(QMouseEvent* event, bool isDragged,
-       ReEdit* edit) {
+    ReEdit* edit) {
        QPoint pos = event->pos();
        bool rc = rectContains(*m_vScrollBar, pos, "vScrollBar")
-               || (isDragged && m_vScrollBar->contains(m_lastMousePosition));
+           || (isDragged && m_vScrollBar->contains(m_lastMousePosition));
        if (rc) {
                if (isDragged) {
                        int distance = pos.y() - m_lastMousePosition.y();
@@ -1074,8 +1092,8 @@ bool ReMouseCatcher::handleVScrollBar(QMouseEvent* event, bool isDragged,
                        int moveGap = m_vScrollBar->height() - m_vSlider->height();
                        double position = moveGap == 0 ? 0.0 : double(sliderPos) / moveGap;
                        int line = roundInt(
-                               (edit->lines().lineCount() - edit->pageSize())
-                                       * max(0.0, min(position, 1.0)));
+                           (edit->lines().lineCount() - edit->pageSize())
+                               * max(0.0, min(position, 1.0)));
                        edit->reposition(line, edit->m_cursorCol);
                } else {
                        if (pos.y() < m_vSlider->top())