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);
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();
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;
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,
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);
}
/**
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;
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:
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:
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);
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));
}
}
* @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
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);
};
/**
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) {
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
*/
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);