#include "gui/regui.hpp"
#include <QPaintEvent>
+/**
+ * Calculates the full line height (with gap between lines)
+ *
+ * @param height the line height
+ * @return the full line height (with gap)
+ */
inline int heightToFullHeight(int height){
return height * 7 / 6;
}
void ReEdit::paintEvent(QPaintEvent* event){
QRect rect = event->rect();
int lineHeight = heightToFullHeight(m_standardMetrics->height());
- int count = (rect.height() + lineHeight - 1) / lineHeight;
+ int count = rect.height() / lineHeight;
m_paragraphs.load(m_paragraphs.firstLine(), count, this);
QPainter painter(this);
map = &m_keyShift;
else if (alt && !shift && !control)
map = &m_keyAlt;
- else if (alt && shift && !control)
- map = &m_keyAltShift;
+ else if (control && ! alt && ! shift)
+ map = &m_keyControl;
else if (alt && control && !shift)
map = &m_keyAltControl;
else if (control && shift && !alt)
*
* @param cursorLine -1 or number of the new cursor line
*/
-void ReEdit::ensureVisible(int cursorLine){
+void ReEdit::ensureCursorVisible(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);
- }
+ int pageSize = m_paragraphs.list().length();
+ if (m_cursorLine < firstLine
+ || m_cursorLine >= firstLine + pageSize){
+ reposition(m_cursorLine);
+ }
}
/**
case EA_CHAR_LEFT:
if (m_cursorCol-- < -1)
m_cursorCol = -1;
+ ensureCursorVisible();
break;
case EA_CHAR_RIGHT:
m_cursorCol++;
+ ensureCursorVisible();
break;
case EA_LINE_UP:
if (--m_cursorLine < 0)
m_cursorLine = 0;
- ensureVisible();
+ ensureCursorVisible();
break;
case EA_LINE_DOWN:
if (++m_cursorLine >= m_lines->lineCount())
m_cursorLine = m_lines->lineCount() - 1;
- ensureVisible();
+ ensureCursorVisible();
break;
case EA_BEGIN_OF_LINE:
m_cursorCol = -1;
- ensureVisible();
+ ensureCursorVisible();
break;
case EA_END_OF_LINE:
m_cursorCol = 99;
- ensureVisible();
+ ensureCursorVisible();
break;
case EA_BEGIN_OF_FILE:
- ensureVisible(0);
+ ensureCursorVisible(0);
break;
case EA_END_OF_FILE:
- ensureVisible(m_lines->lineCount() - 1);
+ ensureCursorVisible(m_lines->lineCount() - 1);
break;
case EA_PAGE_UP:
// 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);
- }
+ reposition(m_paragraphs.firstLine() - pageSize);
break;
case EA_PAGE_DOWN:
// 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);
- }
+ reposition(m_paragraphs.firstLine() + pageSize);
break;
case EA_DEL_CHAR:
break;
emit repaint();
}
+/**
+ * Ensures that a given line is visible.
+ *
+ * @param firstLine number of the line which should be visible
+ */
+void ReEdit::reposition(int firstLine){
+ int pageSize = m_paragraphs.list().length();
+ if (firstLine <= 0)
+ firstLine = 0;
+ else if (firstLine >= m_lines->lineCount() - pageSize)
+ firstLine = m_lines->lineCount() - pageSize + 1;
+ m_paragraphs.load(firstLine, pageSize, this);
+}
+
/**
* Sets the line number of the cursor line.
* @param cursorLine the line number [0..N-1]
m_lines = lines;
m_paragraphs.setLines(lines);
int count = height();
- count = count / heightToFullHeight(m_standardMetrics->height()) + 1;
+ count = count / heightToFullHeight(m_standardMetrics->height());
m_paragraphs.load(m_cursorLine, count, this);
emit repaint();
}