* There is no warranty.
* You also can use the licence from http://www.wtfpl.net/.
* The original sources can be found on https://github.com/republib.
-*/
+ */
#include "base/rebase.hpp"
#include "gui/regui.hpp"
+#include "QKeyEvent"
/** @file
* @brief Unit test of the basic exceptions.
*/
class TestReEdit: public ReTest, protected ReEdit {
public:
TestReEdit() :
- ReTest("ReEdit") {
+ ReTest("ReEdit"),
+ ReEdit(NULL) {
doIt();
}
public:
ReLines m_lines;
- void init(const QString& lines){
+ void init(const QString& lines) {
m_lines.clear();
- m_lines.append(lines);
+ m_lines.insertLines(0, lines, false);
setLines(&m_lines);
}
+ void pushKey(int key, const QString& text = "",
+ Qt::KeyboardModifiers modifiers = Qt::NoModifier) {
+ QKeyEvent event(QEvent::KeyPress, key, modifiers, text);
+ keyPressEvent(&event);
+ }
+
+ void checkFirstPos(int col, int expectedFirstLine, int expectedFirstCol) {
+ m_cursorCol = col;
+ ensureCursorVisible();
+ checkEqu(expectedFirstLine, m_firstLine);
+ checkEqu(expectedFirstCol, m_firstCol);
+ }
void testEnsureCursorVisible() {
init("abc\n123456789_12\nxyz");
m_screenWidth = 5;
m_firstLine = 0;
m_firstCol = 0;
- m_cursorLineNo = -1;
- ensureCursorVisible();
- checkEqu(0, m_firstLineNo);
- checkEqu(-1, m_firstCol);
+ checkFirstPos(0, 0, 0);
- m_cursorLine = 1;
- for (col = 0; col < m_screenWidth; col++){
- m_cursorCol = col;
- ensureCursorVisible();
- checkEqu(1, m_firstLineNo);
- checkEqu(0, m_firstCol);
- }
- for (col = m_screenWidth; col < 2* m_screenWidth; col++){
- m_cursorCol = col;
- ensureCursorVisible();
- checkEqu(1, m_firstLineNo);
- checkEqu(m_screenWidth, m_firstCol);
+ m_cursorLineNo = 1;
+ int col;
+ for (col = 0; col < m_screenWidth; col++) {
+ checkFirstPos(col, 1, 0);
}
- for (col = 2*m_screenWidth; col < 13; col++){
- m_cursorCol = col;
- ensureCursorVisible();
- checkEqu(1, m_firstLineNo);
- checkEqu(2*m_screenWidth, m_firstCol);
+ int lineLength = 12;
+ int colMax = lineLength - m_screenWidth;
+ checkFirstPos(m_screenWidth, 1, m_screenWidth);
+ checkFirstPos(m_screenWidth + 1, 1, m_screenWidth + 1);
+ for (col = colMax; col < lineLength + 2; col++) {
+ checkFirstPos(col, 1, colMax);
}
+ }
+ void checkCursorPos(int key, int expectedLineNo, int expectedCol) {
+ pushKey(key);
+ checkEqu(expectedLineNo, m_cursorLineNo);
+ checkEqu(expectedCol, m_cursorCol);
+ }
+ void checkCursorPos(EditorAction action, int expectedLineNo,
+ int expectedCol) {
+ editorAction(action);
+ checkEqu(expectedLineNo, m_cursorLineNo);
+ checkEqu(expectedCol, m_cursorCol);
+ }
+
+ void testCursorMove() {
+ init("abc\n123456789_12\nxy");
+ m_screenWidth = 5;
+ m_firstLine = 0;
+ m_firstCol = 0;
+ m_cursorCol = -1;
+ m_cursorLineNo = 0;
+ // Left, right, pos1 and end:
+ checkCursorPos(Qt::Key_Right, 0, 0);
+ checkCursorPos(Qt::Key_Right, 0, 1);
+ checkCursorPos(Qt::Key_Right, 0, 2);
+ // next line:
+ checkCursorPos(Qt::Key_Right, 1, -1);
+ checkCursorPos(Qt::Key_Right, 1, 0);
+ checkCursorPos(Qt::Key_Right, 1, 1);
+ checkCursorPos(Qt::Key_Home, 1, -1);
+ checkCursorPos(Qt::Key_End, 1, 11);
+ // next line:
+ checkCursorPos(Qt::Key_Right, 2, -1);
+ checkCursorPos(Qt::Key_Right, 2, 0);
+ checkCursorPos(Qt::Key_Right, 2, 1);
+ // EoF reached: position remains
+ checkCursorPos(Qt::Key_Right, 2, 1);
+ checkCursorPos(Qt::Key_Left, 2, 0);
+ checkCursorPos(Qt::Key_Left, 2, -1);
+ // prev. line:
+ checkCursorPos(Qt::Key_Left, 1, 11);
+ checkCursorPos(Qt::Key_Left, 1, 10);
+ checkCursorPos(Qt::Key_Home, 1, -1);
+ // prev. line:
+ checkCursorPos(Qt::Key_Left, 0, 2);
+ checkCursorPos(Qt::Key_Left, 0, 1);
+ checkCursorPos(Qt::Key_Left, 0, 0);
+ checkCursorPos(Qt::Key_Left, 0, -1);
+ // BoF: position remains:
+ checkCursorPos(Qt::Key_Left, 0, -1);
+
+ // Right when column to left:
+ checkCursorPos(Qt::Key_Down, 1, -1);
+ checkCursorPos(Qt::Key_End, 1, 11);
+ // the column remains at 11!
+ checkCursorPos(Qt::Key_Up, 0, 11);
+ // the last index is 2
+ checkCursorPos(Qt::Key_Left, 0, 1);
+ checkCursorPos(Qt::Key_Left, 0, 0);
+ checkCursorPos(Qt::Key_Left, 0, -1);
+
+ // Up and down, first column:
+ // first line: position remains:
+ checkCursorPos(Qt::Key_Up, 0, -1);
+ checkCursorPos(Qt::Key_Down, 1, -1);
+ checkCursorPos(Qt::Key_Down, 2, -1);
+ // last line: position remains:
+ checkCursorPos(Qt::Key_Down, 2, -1);
+ checkCursorPos(Qt::Key_Up, 1, -1);
+ checkCursorPos(Qt::Key_Up, 0, -1);
+ checkCursorPos(Qt::Key_Down, 1, -1);
+ // Up and down, last column:
+ checkCursorPos(Qt::Key_End, 1, 11);
+ checkCursorPos(Qt::Key_Up, 0, 11);
+ checkCursorPos(Qt::Key_Up, 0, 11);
+ checkCursorPos(Qt::Key_Down, 1, 11);
+ checkCursorPos(Qt::Key_Down, 2, 11);
+ checkCursorPos(Qt::Key_Down, 2, 11);
+
+ // BoF and EoF:
+ checkCursorPos(EA_BEGIN_OF_FILE, 0, -1);
+ checkCursorPos(EA_BEGIN_OF_FILE, 0, -1);
+ checkCursorPos(EA_END_OF_FILE, 2, 1);
+ checkCursorPos(EA_END_OF_FILE, 2, 1);
+ checkCursorPos(EA_BEGIN_OF_FILE, 0, -1);
+ }
+
+ void testEnterText() {
+ init("abc\n1234\nxy");
+ m_screenWidth = 5;
+ m_firstLine = 0;
+ m_firstCol = 0;
+
+ // Split line at the end:
+ m_cursorLineNo = 0;
+ m_cursorCol = 2;
+ pushKey(Qt::Key_Enter, "\n");
+ checkEqu("abc", m_lines.lineAt(0));
+ checkEqu("", m_lines.lineAt(1));
+ checkEqu("1234", m_lines.lineAt(2));
+
+ // Split line in the middle of the line:
+ m_cursorLineNo = 0;
+ m_cursorCol = 1;
+ init("abc\n1234\nxy");
+ pushKey(Qt::Key_Enter, "\n");
+ checkEqu("ab", m_lines.lineAt(0));
+ checkEqu("c", m_lines.lineAt(1));
+ checkEqu("1234", m_lines.lineAt(1));
log("ok");
}
+
virtual void run() {
- testBasic();
+ testEnterText();
+ testCursorMove();
+ testEnsureCursorVisible();
}
};
-void TestReEdit() {
+void testReEdit() {
TestReEdit test;
+ ReUseParameter(&test);
}
-
-
-
* @param edit the parent
*/
ReLook::ReLook() :
- m_font(NULL),
- m_metrics(NULL),
- m_foreground(FG_STANDARD),
- m_background(BG_STANDARD),
- m_edit(NULL) {
+ m_font(NULL),
+ m_metrics(NULL),
+ m_foreground(FG_STANDARD),
+ m_background(BG_STANDARD),
+ m_edit(NULL) {
}
/**
* @param look the presentation of the text
*/
ReEditText::ReEditText(const QString& text, ReLook* look) :
- m_text(text),
- m_look(look) {
+ m_text(text),
+ m_look(look) {
}
* @param edit the edit field (parent)
*/
void ReCursortLineBuilder::buildParagraph(ReParagraph& paragraph, int lineNo,
- ReEdit* edit) {
+ ReEdit* edit) {
if (lineNo == edit->cursorLineNo()) {
for (int ix = 0; ix < paragraph.length(); ix++) {
ReEditText* text = paragraph.at(ix);
* @param parent NULL or a widget which destroy the instance
*/
ReEdit::ReEdit(QWidget* parent) :
- QWidget(parent),
- ReMouseCatcher(),
- m_widthEdit(0),
- m_heightEdit(0),
- m_insertMode(true),
- m_breakLines(false),
- m_widthLineNumbers(50),
- m_widthVScrollBar(16),
- m_heightHScrollBar(16),
- m_looks(),
- m_standardBrush(new QBrush(Qt::SolidPattern)),
- m_scrollbarBrush(new QBrush(Qt::SolidPattern)),
- m_sliderBrush(new QBrush(Qt::ConicalGradientPattern)),
- m_brushColors(),
- m_standardPen(new QPen(Qt::SolidLine)),
- m_standardFont(NULL),
- m_standardMetrics(NULL),
- m_fontColors(),
- m_keyAlt(),
- m_keyAltControl(),
- m_keyAltControlShift(),
- m_keyAltShift(),
- m_keyControl(),
- m_keyControlShift(),
- m_keyRaw(),
- m_keyShift() {
+ QWidget(parent),
+ ReMouseCatcher(),
+ m_widthEdit(0),
+ m_heightEdit(0),
+ m_insertMode(true),
+ m_breakLines(false),
+ m_widthLineNumbers(50),
+ m_widthVScrollBar(16),
+ m_heightHScrollBar(16),
+ m_looks(),
+ m_standardBrush(new QBrush(Qt::SolidPattern)),
+ m_scrollbarBrush(new QBrush(Qt::SolidPattern)),
+ m_sliderBrush(new QBrush(Qt::ConicalGradientPattern)),
+ m_brushColors(),
+ m_standardPen(new QPen(Qt::SolidLine)),
+ m_standardFont(NULL),
+ m_standardMetrics(NULL),
+ m_fontColors(),
+ m_keyAlt(),
+ m_keyAltControl(),
+ m_keyAltControlShift(),
+ m_keyAltShift(),
+ m_keyControl(),
+ m_keyControlShift(),
+ m_keyRaw(),
+ m_keyShift() {
setFocusPolicy(Qt::WheelFocus);
m_standardFont = new QFont("Courier");
m_standardFont->setStyleHint(QFont::TypeWriter);
* @param length OUT: the slider length in pixel
*/
void calcSliderSize(int size, int minSize, double sizeFactor, double posFactor,
- int& position, int& length) {
+ int& position, int& length) {
if (sizeFactor > 1.0)
sizeFactor = 1.0;
if (posFactor > 100)
* @param posHorizontal the position of the scrollbar as factor [0..1]
*/
void ReEdit::drawScrollbars(QPainter& painter, const QRect& rect,
- double sizeVertical, double posVertical, double sizeHorizontal,
- double posHorizontal) {
+ double sizeVertical, double posVertical, double sizeHorizontal,
+ double posHorizontal) {
// We paint the vertical scrollbar:
QBrush brush(*m_brushColors[ReLook::BG_SCROLLBAR], Qt::SolidPattern);
painter.setBrush(brush);
static int width = 1;
static int width2 = 2 * width;
m_vScrollBar->setRect(x + width2, rect.top(), m_widthVScrollBar - width2,
- rect.height() - m_heightHScrollBar - width);
+ rect.height() - m_heightHScrollBar - width);
painter.drawRect(*m_vScrollBar);
// We paint the horizontal scrollbar:
m_hScrollBar->setRect(rect.left() + m_widthLineNumbers,
- rect.bottom() - m_heightHScrollBar + width,
- rect.width() - m_widthVScrollBar - m_widthLineNumbers,
- m_heightHScrollBar - width2);
+ rect.bottom() - m_heightHScrollBar + width,
+ rect.width() - m_widthVScrollBar - m_widthLineNumbers,
+ m_heightHScrollBar - width2);
painter.drawRect(*m_hScrollBar);
// Slider (vertical)
int sliderSize = 0;
int sliderPos = 0;
calcSliderSize(rect.height() - m_heightHScrollBar, m_heightHScrollBar,
- sizeVertical, posVertical, sliderPos, sliderSize);
+ sizeVertical, posVertical, sliderPos, sliderSize);
m_vSlider->setRect(x + width2, rect.top() + sliderPos + width,
- m_widthVScrollBar - width2, sliderSize - width2);
+ m_widthVScrollBar - width2, sliderSize - width2);
painter.drawRect(*m_vSlider);
// Slider (horizontal)
calcSliderSize(rect.width() - m_widthLineNumbers - m_widthVScrollBar,
- m_heightHScrollBar, sizeHorizontal, posHorizontal, sliderPos,
- sliderSize);
+ m_heightHScrollBar, sizeHorizontal, posHorizontal, sliderPos,
+ sliderSize);
m_hSlider->setRect(rect.left() + m_widthLineNumbers + sliderPos,
- rect.bottom() - m_heightHScrollBar + width, sliderSize - width,
- m_heightHScrollBar - width2);
+ rect.bottom() - m_heightHScrollBar + width, sliderSize - width,
+ m_heightHScrollBar - width2);
painter.drawRect(*m_hSlider);
}
case EA_UNDEF:
break;
case EA_CHAR_LEFT:
- if (--m_cursorCol < -1)
- m_cursorCol = -1;
+ if (--m_cursorCol < -1) {
+ if (m_cursorLineNo == 0)
+ m_cursorCol = -1;
+ else {
+ m_cursorLineNo--;
+ m_cursorCol = m_lines->lineAt(m_cursorLineNo).length() - 1;
+ }
+ } else if (m_cursorCol >= m_lines->lineAt(m_cursorLineNo).length() - 1)
+ m_cursorCol = m_lines->lineAt(m_cursorLineNo).length() - 2;
ensureCursorVisible();
break;
case EA_CHAR_RIGHT:
- if (++m_cursorCol >= m_lines->lineAt(m_cursorLineNo).length())
- m_cursorCol = m_lines->lineAt(m_cursorLineNo).length() - 1;
+ if (++m_cursorCol >= m_lines->lineAt(m_cursorLineNo).length()) {
+ int oldLine = m_cursorLineNo;
+ m_cursorCol = -1;
+ editorAction(EA_LINE_DOWN);
+ if (m_cursorLineNo == oldLine)
+ m_cursorCol = m_lines->lineAt(m_cursorLineNo).length() - 1;
+ }
ensureCursorVisible();
break;
case EA_LINE_UP:
break;
case EA_END_OF_FILE:
m_cursorLineNo = m_lines->lineCount() - 1;
+ m_cursorCol = m_lines->lineAt(m_cursorLineNo).length() - 1;
ensureCursorVisible();
break;
case EA_PAGE_UP:
reposition(m_firstLine + pageSize, m_firstCol);
break;
case EA_DEL_CHAR:
+ m_lines->removePart(m_cursorLineNo, m_cursorCol + 1, 1, true);
break;
- case EA_BACKSPACE:
+ case EA_BACKSPACE: {
+ int currentCol = m_cursorCol;
+ m_cursorCol = max(-1, currentCol - 1);
+ if (currentCol == -1 && m_cursorLineNo > 0) {
+ // join the previous and the current line:
+ // the cursor position will be the end of the previous line:
+ m_cursorCol = m_lines->lineAt(m_cursorLineNo - 1).length() - 1;
+ }
+ if (m_lines->removePart(m_cursorLineNo, columnToIndex(currentCol), 1,
+ true))
+ m_cursorLineNo = max(0, m_cursorLineNo - 1);
+
break;
+ }
case EA_DEL_END_OF_LINE:
break;
case EA_DEL_BEGIN_OF_LINE:
*/
void ReEdit::ensureCursorVisible() {
if (m_cursorLineNo < m_firstLine
- || m_cursorLineNo >= m_firstLine + pageSize()) {
+ || m_cursorLineNo >= m_firstLine + pageSize()) {
reposition(m_cursorLineNo, m_cursorCol);
}
if (m_cursorCol < 0)
m_firstCol = 0;
- else if ( m_cursorCol < m_firstCol) {
+ else if (m_cursorCol < m_firstCol) {
m_firstCol = m_cursorCol;
- } else if (m_cursorCol >= m_firstCol + m_screenWidth){
+ } else if (m_cursorCol >= m_firstCol + m_screenWidth) {
int length = m_lines->lineAt(m_cursorLineNo).length();
m_firstCol = max(0, min(m_cursorCol, length - m_screenWidth));
}
m_cursorLineNo++;
break;
case Qt::Key_Backspace: {
- int currentCol = m_cursorCol;
- m_cursorCol = max(-1, currentCol - 1);
- if (currentCol == -1 && m_cursorLineNo > 0) {
- // join the previous and the current line:
- // the cursor position will be the end of the previous line:
- m_cursorCol = m_lines->lineAt(m_cursorLineNo - 1).length() - 1;
- }
- if (m_lines->removePart(m_cursorLineNo, columnToIndex(currentCol),
- 1, true))
- m_cursorLineNo = max(0, m_cursorLineNo - 1);
+ editorAction(EA_BACKSPACE);
break;
}
case Qt::Key_Delete:
- m_lines->removePart(m_cursorLineNo, m_cursorCol + 1, 1, true);
+ editorAction(EA_DEL_CHAR);
break;
default:
m_lines->insertText(m_cursorLineNo, m_cursorCol + 1, keyText);
break;
}
} else if (shift && !keyText.isEmpty() && key != Qt::Key_Delete
- && key != Qt::Key_Backspace) {
+ && key != Qt::Key_Backspace) {
m_lines->insertText(m_cursorLineNo, m_cursorCol + 1, keyText);
m_cursorCol++;
} else {
* @return
*/
ReLook* ReEdit::lookOf(ReLook::ForeGround foreground,
- ReLook::BackGround background) {
+ ReLook::BackGround background) {
int index = foreground * ReLook::BG_COUNT + background;
ReLook* rc = m_looks[index];
if (rc == NULL) {
*/
void ReEdit::mouseMoveEvent(QMouseEvent* event) {
if (m_lastMousePosition.x() >= 0
- && (handleHScrollBar(event, true, this)
- || handleVScrollBar(event, true, this))) {
+ && (handleHScrollBar(event, true, this)
+ || handleVScrollBar(event, true, this))) {
emit repaint();
}
}
} else {
QPoint position = event->pos();
m_cursorLineNo = position.y()
- / heightToFullHeight(m_standardMetrics->height()) + m_firstLine;
+ / heightToFullHeight(m_standardMetrics->height()) + m_firstLine;
int x = position.x();
int charWidth = m_standardMetrics->width('x');
x -= m_widthLineNumbers;
- if (x >= 0 && x < m_widthEdit - m_widthLineNumbers - m_widthVScrollBar) {
- if (x <= + charWidth / 2)
+ if (x >= 0
+ && x < m_widthEdit - m_widthLineNumbers - m_widthVScrollBar) {
+ if (x <= +charWidth / 2)
m_cursorCol = m_firstCol - 1;
else
m_cursorCol = m_firstCol + columnToIndex(x / charWidth);
int pageSize = (rect.height() - m_heightHScrollBar) / lineHeight;
int charWidth = m_standardMetrics->averageCharWidth();
int pageWidth = (rect.width() - m_widthVScrollBar - m_widthLineNumbers)
- / charWidth;
+ / charWidth;
int firstLine = m_firstLine;
load(firstLine, pageSize, pageWidth, this);
QPainter painter(this);
ReLook* look = lookOf(ReLook::FG_STANDARD, ReLook::BG_STANDARD);
painter.setBrush(*look->m_brush);
QRect editArea(rect.left() + m_widthLineNumbers, rect.top(),
- rect.right() - m_widthVScrollBar, rect.bottom() - m_heightHScrollBar);
+ rect.right() - m_widthVScrollBar, rect.bottom() - m_heightHScrollBar);
painter.drawRect(editArea);
draw(painter, rect.top(), rect.left() + m_widthLineNumbers);
int left = rect.left() + m_widthLineNumbers - 3;
for (int ix = 0; ix < m_list.length(); ix++, lineNo++) {
QString number = QString::number(lineNo) + ":";
ReLook* look =
- lineNo == m_cursorLineNo + 1 ?
- lookOf(ReLook::FG_CURRENT_LINE, ReLook::BG_CURRENT_LINE) :
- lookStd;
+ lineNo == m_cursorLineNo + 1 ?
+ lookOf(ReLook::FG_CURRENT_LINE, ReLook::BG_CURRENT_LINE) :
+ lookStd;
int width = look->m_metrics->width(number);
if (ix == 0)
y = rect.top() + look->m_metrics->height()
- - look->m_metrics->descent();
+ - look->m_metrics->descent();
painter.setFont(*look->m_font);
painter.setPen(*look->m_pen);
painter.drawText(left + m_widthLineNumbers - width - 5, y, number);
}
// We paint the cursor:
if (m_cursorVisible && m_cursorLineNo >= firstLine
- && m_cursorLineNo < firstLine + pageSize) {
+ && m_cursorLineNo < firstLine + pageSize) {
ReParagraph* cursorPara = cursorParagraph();
int col = min(m_cursorCol, cursorPara->m_columns - 1);
if (col != -1)
- col = indexToColumn(col, m_tabWidth, m_lines->lineAt(m_cursorLineNo))
- - m_firstCol;
+ col = indexToColumn(col, m_tabWidth,
+ m_lines->lineAt(m_cursorLineNo)) - m_firstCol;
int x = rect.left() + m_widthLineNumbers + 1
- + (col + 1) * lookStd->m_metrics->width('x');
+ + (col + 1) * lookStd->m_metrics->width('x');
int y = rect.top() + (m_cursorLineNo - firstLine) * lineHeight;
painter.setPen(*look->m_pen);
painter.drawLine(x, y, x, y + lineHeight);
}
int maxLines = max(1, m_lines->lineCount() - pageSize);
drawScrollbars(painter, rect, double(pageSize) / maxLines,
- double(m_firstLine) / maxLines,
- m_maxCols == 0 ? 1.0 : (double) m_screenWidth / m_maxCols,
- m_maxCols == 0 ? 0.0 : (double) m_firstCol / m_maxCols);
+ double(m_firstLine) / maxLines,
+ m_maxCols == 0 ? 1.0 : (double) m_screenWidth / m_maxCols,
+ m_maxCols == 0 ? 0.0 : (double) m_firstCol / m_maxCols);
ReLogger::globalLogger()->logv(LOG_INFO, 3, "draw: %.4f",
- double(clock() - start) / CLOCKS_PER_SEC);
+ double(clock() - start) / CLOCKS_PER_SEC);
}
/**
* Constructor.
*/
ReParagraphs::ReParagraphs() :
- m_builders(),
- m_firstLine(0),
- m_firstCol(0),
- m_cursorLineNo(0),
- m_cursorCol(-1),
- m_lines(NULL),
- m_list(),
- m_maxCols(0),
- m_screenWidth(0),
- m_cursorVisible(true) {
+ m_builders(),
+ m_firstLine(0),
+ m_firstCol(0),
+ m_cursorLineNo(0),
+ m_cursorCol(-1),
+ m_lines(NULL),
+ m_list(),
+ m_maxCols(0),
+ m_screenWidth(0),
+ m_cursorVisible(true) {
}
/**
* expanded tabs
*/
int ReParagraphs::columnToIndex(int column, int tabWidth,
- const QString& string) {
+ const QString& string) {
int rc = 0;
if (column < 0)
rc = -1;
ReParagraph* ReParagraphs::cursorParagraph() {
ReParagraph* rc = NULL;
if (m_cursorLineNo >= m_firstLine
- && m_cursorLineNo < m_firstLine + m_list.length()) {
+ && m_cursorLineNo < m_firstLine + m_list.length()) {
rc = m_list.at(m_cursorLineNo - m_firstLine);
}
return rc;
*/
int ReParagraphs::columnToIndex(int cursorCol) {
int rc = columnToIndex(cursorCol, m_tabWidth,
- m_lines->lineAt(m_cursorLineNo));
+ m_lines->lineAt(m_cursorLineNo));
return rc;
}
* @return
*/
int ReParagraphs::indexToColumn(int index, int tabWidth,
- const QString& string) {
+ const QString& string) {
int rc = 0;
if (index >= 0) {
int length = string.length();
* @param edit the parent, the edit field
*/
void ReParagraphBuilder::buildParagraph(ReParagraph& paragraph, int lineNo,
- ReEdit* edit) {
+ ReEdit* edit) {
if (paragraph.length() == 0) {
int firstCol = edit->m_firstCol;
const QString& text = edit->lines().lineAt(lineNo);
ReLook* look = edit->lookOf(ReLook::FG_STANDARD, ReLook::BG_STANDARD);
ReLook* lookTab = edit->lookOf(ReLook::FG_GREY_LIGHT,
- ReLook::BG_STANDARD);
+ ReLook::BG_STANDARD);
paragraph.m_columns = 0;
int ixTab;
ReEditText* part;
* Constructor.
*/
ReMouseCatcher::ReMouseCatcher() :
- m_clickObjects(),
- m_vScrollBar(new ClickPosition(CO_VSCROLLBAR)),
- m_hScrollBar(new ClickPosition(CO_HSCROLLBAR)),
- m_hSlider(new ClickPosition(CO_HSLIDER)),
- m_vSlider(new ClickPosition(CO_VSLIDER)),
- m_lastMousePosition(),
- m_lastTopVSlider(0),
- m_lastLeftHSlider(0) {
+ m_clickObjects(),
+ m_vScrollBar(new ClickPosition(CO_VSCROLLBAR)),
+ m_hScrollBar(new ClickPosition(CO_HSCROLLBAR)),
+ m_hSlider(new ClickPosition(CO_HSLIDER)),
+ m_vSlider(new ClickPosition(CO_VSLIDER)),
+ m_lastMousePosition(),
+ m_lastTopVSlider(0),
+ m_lastLeftHSlider(0) {
}
/**
* @return <code>true</code>: the mouse click is inside the horizontal sb
*/
bool ReMouseCatcher::handleHScrollBar(QMouseEvent* event, bool isDragged,
- ReEdit* edit) {
+ ReEdit* edit) {
QPoint pos = event->pos();
bool rc = rectContains(*m_hScrollBar, pos, "hScrollBar");
if (rc) {
int moveGap = m_hScrollBar->width() - m_hSlider->width();
double position = moveGap == 0 ? 0.0 : double(sliderPos) / moveGap;
int col = roundInt(
- (edit->m_maxCols - edit->m_screenWidth)
- * max(0.0, min(position, 1.0)));
+ (edit->m_maxCols - edit->m_screenWidth)
+ * max(0.0, min(position, 1.0)));
edit->reposition(edit->m_cursorLineNo, col);
} else {
if (pos.y() < m_hSlider->left())
* @return <code>true</code>: the mouse click is inside the vertical sb
*/
bool ReMouseCatcher::handleVScrollBar(QMouseEvent* event, bool isDragged,
- ReEdit* edit) {
+ ReEdit* edit) {
QPoint pos = event->pos();
bool rc = rectContains(*m_vScrollBar, pos, "vScrollBar")
- || (isDragged && m_vScrollBar->contains(m_lastMousePosition));
+ || (isDragged && m_vScrollBar->contains(m_lastMousePosition));
if (rc) {
if (isDragged) {
int distance = pos.y() - m_lastMousePosition.y();
int moveGap = m_vScrollBar->height() - m_vSlider->height();
double position = moveGap == 0 ? 0.0 : double(sliderPos) / moveGap;
int line = roundInt(
- (edit->lines().lineCount() - edit->pageSize())
- * max(0.0, min(position, 1.0)));
+ (edit->lines().lineCount() - edit->pageSize())
+ * max(0.0, min(position, 1.0)));
edit->reposition(line, edit->m_cursorCol);
} else {
if (pos.y() < m_vSlider->top())