]> gitweb.hamatoma.de Git - reqt/commitdiff
grip items in sliders, DEL actions
authorhama <hama@siduction.net>
Tue, 28 Jul 2015 22:42:10 +0000 (00:42 +0200)
committerhama <hama@siduction.net>
Tue, 28 Jul 2015 22:42:10 +0000 (00:42 +0200)
* 3 lines to mark the horizonal and vertical slider
* implemntation of EA_DEL_END_OF_LINE, EA_DEL_BEGIN_OF_LINE,
  EA_DEL_LINE

gui/ReEdit.cpp
gui/ReEdit.hpp

index 0d2351983f1a8ffbd748df184f2606ed42b8f765..c2ec7ea2e80e90a7060a8a08d77be725900a23b3 100644 (file)
@@ -145,6 +145,9 @@ ReEdit::ReEdit(QWidget* parent) :
        appendBuilder(new ReCursortLineBuilder());
        assignKeysStandard();
 }
+/**
+ * Assigns a standard version of colors to symbolic colors.
+ */
 void ReEdit::assignColorsStandard() {
        m_fontColors[ReLook::FG_STANDARD] = new QColor(Qt::black);
        m_fontColors[ReLook::FG_CURRENT_LINE] = new QColor(Qt::blue);
@@ -180,6 +183,9 @@ void ReEdit::assignColorsStandard() {
        m_brushColors[ReLook::BG_BLUE] = new QColor(Qt::blue);
 }
 
+/**
+ * Assigns a the standard version of keys to editor actions.
+ */
 void ReEdit::assignKeysStandard() {
        m_keyRaw.clear();
        m_keyControl.clear();
@@ -202,8 +208,8 @@ void ReEdit::assignKeysStandard() {
        m_keyRaw[Qt::Key_Delete] = EA_DEL_CHAR;
        m_keyRaw[Qt::Key_Backspace] = EA_BACKSPACE;
        m_keyControl[Qt::Key_Delete] = EA_DEL_END_OF_LINE;
-       m_keyShift[Qt::Key_Delete] = EA_DEL_BEGIN_OF_LINE;
-       m_keyAlt[Qt::Key_Delete] = EA_DEL_LINE;
+       m_keyControl[Qt::Key_Backspace] = EA_DEL_BEGIN_OF_LINE;
+       m_keyShift[Qt::Key_Delete] = EA_DEL_LINE;
        m_keyControl[Qt::Key_Z] = EA_UNDO;
        m_keyControlShift[Qt::Key_Z] = EA_REDO;
        m_keyAltControl[Qt::Key_Left] = EA_VIEW_LEFT;
@@ -298,6 +304,15 @@ void ReEdit::drawScrollbars(QPainter& painter, const QRect& rect,
        m_vSlider->setRect(x + width2, rect.top() + sliderPos + width,
            m_widthVScrollBar - width2, sliderSize - width2);
        painter.drawRect(*m_vSlider);
+       int middle = m_vSlider->top() + m_vSlider->height() / 2;
+       painter.drawLine(m_vSlider->left() + 2, middle, m_vSlider->right() - 2,
+           middle);
+       middle -= m_heightHScrollBar / 2 - 2;
+       painter.drawLine(m_vSlider->left() + 2, middle, m_vSlider->right() - 2,
+           middle);
+       middle += m_heightHScrollBar - 4;
+       painter.drawLine(m_vSlider->left() + 2, middle, m_vSlider->right() - 2,
+           middle);
        // Slider (horizontal)
        calcSliderSize(rect.width() - m_widthLineNumbers - m_widthVScrollBar,
            m_heightHScrollBar, sizeHorizontal, posHorizontal, sliderPos,
@@ -306,6 +321,15 @@ void ReEdit::drawScrollbars(QPainter& painter, const QRect& rect,
            rect.bottom() - m_heightHScrollBar + width, sliderSize - width,
            m_heightHScrollBar - width2);
        painter.drawRect(*m_hSlider);
+       middle = m_hSlider->left() + m_hSlider->width() / 2;
+       painter.drawLine(middle, m_hSlider->top() + 2, middle,
+           m_hSlider->bottom() - 2);
+       middle -= m_heightHScrollBar / 2 - 2;
+       painter.drawLine(middle, m_hSlider->top() + 2, middle,
+           m_hSlider->bottom() - 2);
+       middle += m_heightHScrollBar - 4;
+       painter.drawLine(middle, m_hSlider->top() + 2, middle,
+           m_hSlider->bottom() - 2);
 }
 
 /**
@@ -329,19 +353,19 @@ void ReEdit::editorAction(ReEdit::EditorAction action) {
                                m_cursorCol = -1;
                        else {
                                m_cursorLineNo--;
-                               m_cursorCol = m_lines->lineAt(m_cursorLineNo).length() - 1;
+                               m_cursorCol = lastColOfCurrent();
                        }
-               } else if (m_cursorCol >= m_lines->lineAt(m_cursorLineNo).length() - 1)
-                       m_cursorCol = m_lines->lineAt(m_cursorLineNo).length() - 2;
+               } else if (m_cursorCol >= lastColOfCurrent())
+                       m_cursorCol = lastColOfCurrent() - 1;
                ensureCursorVisible();
                break;
        case EA_CHAR_RIGHT:
-               if (++m_cursorCol >= m_lines->lineAt(m_cursorLineNo).length()) {
+               if (++m_cursorCol > lastColOfCurrent()) {
                        int oldLine = m_cursorLineNo;
                        m_cursorCol = -1;
                        editorAction(EA_LINE_DOWN);
                        if (m_cursorLineNo == oldLine)
-                               m_cursorCol = m_lines->lineAt(m_cursorLineNo).length() - 1;
+                               m_cursorCol = lastColOfCurrent();
                }
                ensureCursorVisible();
                break;
@@ -360,7 +384,7 @@ void ReEdit::editorAction(ReEdit::EditorAction action) {
                ensureCursorVisible();
                break;
        case EA_END_OF_LINE:
-               m_cursorCol = m_lines->lineAt(m_cursorLineNo).length() - 1;
+               m_cursorCol = lastColOfCurrent();
                ensureCursorVisible();
                break;
        case EA_BEGIN_OF_FILE:
@@ -370,7 +394,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;
+               m_cursorCol = lastColOfCurrent();
                ensureCursorVisible();
                break;
        case EA_PAGE_UP:
@@ -398,11 +422,26 @@ void ReEdit::editorAction(ReEdit::EditorAction action) {
 
                break;
        }
-       case EA_DEL_END_OF_LINE:
+       case EA_DEL_END_OF_LINE: {
+               int lastIx = lastColOfCurrent();
+               if (m_cursorCol < lastIx) {
+                       m_lines->removePart(m_cursorLineNo, m_cursorCol + 1,
+                           lastIx - m_cursorCol, true);
+                       ensureCursorVisible();
+               }
                break;
+       }
        case EA_DEL_BEGIN_OF_LINE:
+               if (m_cursorCol > 0) {
+                       m_lines->removePart(m_cursorLineNo, 0, m_cursorCol + 1, true);
+                       m_cursorCol = -1;
+                       ensureCursorVisible();
+               }
                break;
        case EA_DEL_LINE:
+               m_lines->removeLines(m_cursorLineNo, 1, true);
+               m_cursorCol = m_firstCol == 0 ? -1 : m_firstCol;
+               ensureCursorVisible();
                break;
        case EA_UNDO:
                m_lines->undo(m_cursorLineNo, m_cursorCol);
@@ -440,7 +479,7 @@ void ReEdit::ensureCursorVisible() {
        else if (m_cursorCol < m_firstCol) {
                m_firstCol = m_cursorCol;
        } else if (m_cursorCol >= m_firstCol + m_screenWidth) {
-               int length = m_lines->lineAt(m_cursorLineNo).length();
+               int length = lastColOfCurrent() + 1;
                m_firstCol = max(0, min(m_cursorCol, length - m_screenWidth));
        }
 }
index a6b04fac7423650c79d79a8231845d58318b3b98..a1d14da503918372a9edf8dd8e650916fac009ea 100644 (file)
@@ -85,8 +85,8 @@ public:
         * @param source    source to copy
         */
        inline ReEditText(const ReEditText& source) :
-                       m_text(source.m_text),
-                       m_look(source.m_look) {
+                   m_text(source.m_text),
+                   m_look(source.m_look) {
        }
        /** Assignment operator.
         * @param source    source to copy
@@ -146,14 +146,14 @@ public:
 class ReParagraphBuilder {
 public:
        virtual void buildParagraph(ReParagraph& paragraph, int lineNo,
-               ReEdit* edit);
+           ReEdit* edit);
 };
 
 class ReCursortLineBuilder: public ReParagraphBuilder {
        // ReParagraphBuilder interface
 public:
        virtual void buildParagraph(ReParagraph& paragraph, int lineNo,
-               ReEdit* edit);
+           ReEdit* edit);
 };
 
 /**
@@ -234,10 +234,10 @@ public:
        class ClickPosition: public QRect {
        public:
                ClickPosition(ClickObjType type) :
-                               QRect(0, 0, 0, 0),
-                               m_type(type),
-                               m_title(),
-                               m_object(NULL) {
+                           QRect(0, 0, 0, 0),
+                           m_type(type),
+                           m_title(),
+                           m_object(NULL) {
                }
        public:
                bool operator <(const ClickPosition& op) {
@@ -307,9 +307,17 @@ public:
        void assignKeysStandard();
        int cursorLineNo() const;
        void editorAction(EditorAction action);
+       /** Returns the last column of the cursor line
+        * @return -1:  the length of the cursor line is 0<br>
+        *                              otherwise: the last index of the cursor line
+        */
+       inline
+       int lastColOfCurrent() const {
+               return m_lines->lineAt(m_cursorLineNo).length() - 1;
+       }
        ReLines& lines();
        ReLook* lookOf(ReLook::ForeGround foreground,
-               ReLook::BackGround background);
+           ReLook::BackGround background);
        /** Returns the current page size.
         * return    number of visible lines in the edit field
         */
@@ -334,8 +342,8 @@ public:
 protected:
        QBrush* createBrush(ReLook::BackGround background);
        void drawScrollbars(QPainter& painter, const QRect& rect,
-               double sizeVertical, double posVertical, double sizeHorizontal,
-               double posHorizontal);
+           double sizeVertical, double posVertical, double sizeHorizontal,
+           double posHorizontal);
        void ensureCursorVisible();
 protected slots:
        void keyPressEvent(QKeyEvent* event);