From: hama Date: Sun, 21 Jun 2015 10:16:14 +0000 (+0200) Subject: baseic editor actions (navigation) X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=c0c6dc4719fbb1e124d426f4a437d051576877a4;p=reqt baseic editor actions (navigation) --- diff --git a/appl/reditor/reditor.pro b/appl/reditor/reditor.pro index b22b7ab..24ec39a 100644 --- a/appl/reditor/reditor.pro +++ b/appl/reditor/reditor.pro @@ -20,8 +20,6 @@ SOURCES += main.cpp\ HEADERS += mainwindow.hpp \ - ../../gui/ReEdit \ - ../../gui/ReEdit.hpp \ ../../base/rebase.hpp \ ../../gui/regui.hpp diff --git a/gui/ReEdit.cpp b/gui/ReEdit.cpp index dc6e5db..2bd3288 100644 --- a/gui/ReEdit.cpp +++ b/gui/ReEdit.cpp @@ -114,6 +114,7 @@ ReEdit::ReEdit(QWidget* parent) : m_keyControlShift(), m_keyRaw(), m_keyShift(){ + setFocusPolicy(Qt::WheelFocus); m_standardFont = new QFont("Courier"); m_standardFont->setStyleHint(QFont::TypeWriter); m_standardFont->setPixelSize(16); @@ -288,7 +289,7 @@ void ReEdit::keyPressEvent(QKeyEvent* event){ else map = &m_keyAltControlShift; if (map->contains(event->key())){ - EditorAction action = (*map)[event->key()]; + EditorAction action = (*map)[key]; editorAction(action); } } @@ -304,12 +305,34 @@ int ReEdit::cursorLine() const{ 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; @@ -321,29 +344,49 @@ void ReEdit::editorAction(ReEdit::EditorAction action){ 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: @@ -357,6 +400,7 @@ void ReEdit::editorAction(ReEdit::EditorAction action){ default: break; } + emit repaint(); } /** @@ -389,6 +433,7 @@ void ReEdit::setLines(ReLines* lines){ int count = height(); count = count / heightToFullHeight(m_standardMetrics->height()) + 1; m_paragraphs.load(m_cursorLine, count, this); + emit repaint(); } /** diff --git a/gui/ReEdit.hpp b/gui/ReEdit.hpp index fda026d..e4e2a0a 100644 --- a/gui/ReEdit.hpp +++ b/gui/ReEdit.hpp @@ -254,7 +254,9 @@ public: } protected: - QBrush*createBrush(ReLook::BackGround background);signals: + QBrush*createBrush(ReLook::BackGround background); + void ensureVisible(int cursorLine = -1); +//signals: public slots: virtual void paintEvent(QPaintEvent *);