m_keyControlShift(),
m_keyRaw(),
m_keyShift(){
+ setFocusPolicy(Qt::WheelFocus);
m_standardFont = new QFont("Courier");
m_standardFont->setStyleHint(QFont::TypeWriter);
m_standardFont->setPixelSize(16);
else
map = &m_keyAltControlShift;
if (map->contains(event->key())){
- EditorAction action = (*map)[event->key()];
+ EditorAction action = (*map)[key];
editorAction(action);
}
}
return m_cursorLine;
}
+/**
+ * Ensures that the cursor line is visible.
+ *
+ * @param cursorLine -1 or number of the new cursor line
+ */
+void ReEdit::ensureVisible(int cursorLine){
+ if (cursorLine >= 0)
+ m_cursorLine = cursorLine;
+ int firstLine = m_paragraphs.firstLine();
+ int count = m_paragraphs.list().length();
+ if (m_cursorLine < firstLine){
+ m_paragraphs.load(m_cursorLine, count, this);
+ } else if (m_firstLine > firstLine + count - 1){
+ int maxNo = m_lines->lineCount();
+ if (m_firstLine < maxNo - count - 1)
+ m_paragraphs.load(m_cursorLine, count, this);
+ else
+ m_paragraphs.load(maxNo - count - 1, count, this);
+ }
+}
+
/**
* Does an editor action.
*
* @param action action to do
*/
void ReEdit::editorAction(ReEdit::EditorAction action){
+ int pageSize = m_paragraphs.list().length() - 1;
switch (action) {
case EA_UNDEF:
break;
m_cursorCol++;
break;
case EA_LINE_UP:
- break;
if (--m_cursorLine < 0)
m_cursorLine = 0;
+ ensureVisible();
break;
case EA_LINE_DOWN:
- m_cursorLine++;
+ if (++m_cursorLine >= m_lines->lineCount())
+ m_cursorLine = m_lines->lineCount() - 1;
+ ensureVisible();
break;
case EA_BEGIN_OF_LINE:
m_cursorCol = -1;
+ ensureVisible();
break;
case EA_END_OF_LINE:
m_cursorCol = 99;
+ ensureVisible();
break;
case EA_BEGIN_OF_FILE:
- m_cursorLine = 0;
+ ensureVisible(0);
break;
case EA_END_OF_FILE:
- m_cursorLine = m_lines->lineCount() - 1;
+ ensureVisible(m_lines->lineCount() - 1);
break;
case EA_PAGE_UP:
- break;
+ // Do not change cursor line!
+ if (m_paragraphs.firstLine() > 0)
+ {
+ int line = m_paragraphs.firstLine() - pageSize;
+ if (line < 0)
+ line = 0;
+ m_paragraphs.load(0, pageSize + 1, this);
+ }
+ break;
case EA_PAGE_DOWN:
- break;
+ // Do not change cursor line!
+ if (m_paragraphs.firstLine() < m_lines->lineCount() - pageSize)
+ {
+ int line = m_paragraphs.firstLine() + pageSize;
+ if (line > m_lines->lineCount() - pageSize)
+ line = m_lines->lineCount() - pageSize;
+ m_paragraphs.load(line, pageSize + 1, this);
+ }
+ break;
case EA_DEL_CHAR:
break;
case EA_BACKSPACE:
default:
break;
}
+ emit repaint();
}
/**
int count = height();
count = count / heightToFullHeight(m_standardMetrics->height()) + 1;
m_paragraphs.load(m_cursorLine, count, this);
+ emit repaint();
}
/**