Skip to content

Commit

Permalink
Merge branch '997-textmapper-for-log' into '0.13.x-rc'
Browse files Browse the repository at this point in the history
Resolve "TextMapper for Log"

See merge request devel/studio!276
  • Loading branch information
Jazzco committed Oct 2, 2019
2 parents 426858e + 798d631 commit 39e4473
Show file tree
Hide file tree
Showing 45 changed files with 4,329 additions and 1,880 deletions.
119 changes: 86 additions & 33 deletions src/editors/abstractedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ AbstractEdit::AbstractEdit(QWidget *parent)
}

AbstractEdit::~AbstractEdit()
{}
{
mSelUpdater.stop();
}

void AbstractEdit::setOverwriteMode(bool overwrite)
{
Expand All @@ -58,23 +60,23 @@ void AbstractEdit::sendToggleBookmark()
{
FileId fi = fileId();
if (fi.isValid()) {
emit toggleBookmark(fi, effectiveBlockNr(textCursor().blockNumber()), textCursor().positionInBlock());
emit toggleBookmark(fi, absoluteBlockNr(textCursor().blockNumber()), textCursor().positionInBlock());
}
}

void AbstractEdit::sendJumpToNextBookmark()
{
FileId fi = fileId();
if (fi.isValid()) {
emit jumpToNextBookmark(false, fi, effectiveBlockNr(textCursor().blockNumber()));
emit jumpToNextBookmark(false, fi, absoluteBlockNr(textCursor().blockNumber()));
}
}

void AbstractEdit::sendJumpToPrevBookmark()
{
FileId fi = fileId();
if (fi.isValid()) {
emit jumpToNextBookmark(true, fi, effectiveBlockNr(textCursor().blockNumber()));
emit jumpToNextBookmark(true, fi, absoluteBlockNr(textCursor().blockNumber()));
}
}

Expand All @@ -93,13 +95,17 @@ void AbstractEdit::updateGroupId()
marksChanged();
}

void AbstractEdit::disconnectTimers()
{
disconnect(&mSelUpdater, &QTimer::timeout, this, &AbstractEdit::internalExtraSelUpdate);
}

void AbstractEdit::updateExtraSelections()
{
// TRACE();
mSelUpdater.start();
// QList<QTextEdit::ExtraSelection> selections;
// extraSelMarks(selections);
// setExtraSelections(selections);
// setExtraSelections(selections);
}

void AbstractEdit::setMarks(const LineMarks *marks)
Expand All @@ -113,11 +119,16 @@ const LineMarks* AbstractEdit::marks() const
return mMarks;
}

int AbstractEdit::effectiveBlockNr(const int &localBlockNr) const
int AbstractEdit::absoluteBlockNr(const int &localBlockNr) const
{
return localBlockNr;
}

int AbstractEdit::localBlockNr(const int &absoluteBlockNr) const
{
return absoluteBlockNr;
}

int AbstractEdit::topVisibleLine()
{
QTextBlock block = firstVisibleBlock();
Expand Down Expand Up @@ -176,6 +187,41 @@ void AbstractEdit::extraSelMarks(QList<QTextEdit::ExtraSelection> &selections)
}
}

void AbstractEdit::updateCursorShape(const Qt::CursorShape &defaultShape)
{
Qt::CursorShape shape = defaultShape;
viewport()->setCursor(shape);
}

QPoint AbstractEdit::toolTipPos(const QPoint &mousePos)
{
QPoint pos = mousePos;
if (!mMarksAtMouse.isEmpty()) {
QTextCursor cursor(document()->findBlockByNumber(localBlockNr(mMarksAtMouse.first()->line())));
cursor.setPosition(cursor.position() + mMarksAtMouse.first()->column(), QTextCursor::MoveAnchor);
pos.setY(cursorRect(cursor).bottom());
} else {
QTextCursor cursor = cursorForPosition(mousePos);
cursor.setPosition(cursor.block().position());
pos.setY(cursorRect(cursor).bottom());
}
if (pos.x() < 10) pos.setX(10);
if (pos.x() > width()-100) pos.setX(width()-100);
return pos;
}

QVector<int> AbstractEdit::toolTipLstNumbers(const QPoint &pos)
{
Q_UNUSED(pos)
QVector<int> lstLines;
for (TextMark *mark: mMarksAtMouse) {
int lstLine = mark->value();
if (lstLine < 0 && mark->refMark()) lstLine = mark->refMark()->value();
if (lstLine >= 0) lstLines << lstLine;
}
return lstLines;
}

void AbstractEdit::internalExtraSelUpdate()
{
QList<QTextEdit::ExtraSelection> selections;
Expand All @@ -184,17 +230,20 @@ void AbstractEdit::internalExtraSelUpdate()
setExtraSelections(selections);
}

void AbstractEdit::showToolTip(const QList<TextMark*> marks)
//void AbstractEdit::showToolTip(const QList<TextMark*> &marks, const QPoint &pos)
//{
// if (marks.size() > 0) {
// QStringList tips;
// emit requestMarkTexts(groupId(), marks, tips);
// QToolTip::showText(mapToGlobal(pos), tips.join("\n"), this);
// }
//}

void AbstractEdit::showToolTip(const QVector<int> &lstNumbers, const QPoint &pos)
{
if (marks.size() > 0) {
QTextCursor cursor(document()->findBlockByNumber(marks.first()->line()));
cursor.setPosition(cursor.position() + marks.first()->column(), QTextCursor::MoveAnchor);
QPoint pos = cursorRect(cursor).bottomLeft();
if (pos.x() < 10) pos.setX(10);
QStringList tips;
emit requestLstTexts(groupId(), marks, tips);
QToolTip::showText(mapToGlobal(pos), tips.join("\n"), this);
}
QStringList tips;
emit requestLstTexts(groupId(), lstNumbers, tips);
QToolTip::showText(mapToGlobal(pos), tips.join("\n"), this);
}

bool AbstractEdit::event(QEvent *e)
Expand All @@ -212,13 +261,15 @@ bool AbstractEdit::event(QEvent *e)

bool AbstractEdit::eventFilter(QObject *o, QEvent *e)
{
Q_UNUSED(o);
Q_UNUSED(o)
if (e->type() == QEvent::ToolTip) {
QHelpEvent* helpEvent = static_cast<QHelpEvent*>(e);
if (!mMarksAtMouse.isEmpty())
showToolTip(mMarksAtMouse);
mTipPos = helpEvent->pos();
return !mMarksAtMouse.isEmpty();
QVector<int> lstLines = toolTipLstNumbers(mTipPos);
QPoint pos = toolTipPos(mTipPos);
if (!lstLines.isEmpty())
showToolTip(lstLines, pos);
return !lstLines.isEmpty();
}
return QPlainTextEdit::eventFilter(o, e);
}
Expand All @@ -227,12 +278,16 @@ void AbstractEdit::keyPressEvent(QKeyEvent *e)
{
if (e == Hotkey::MoveViewLineUp) {
verticalScrollBar()->setValue(verticalScrollBar()->value()-1);
e->accept();
} else if (e == Hotkey::MoveViewLineDown) {
verticalScrollBar()->setValue(verticalScrollBar()->value()+1);
e->accept();
} else if (e == Hotkey::MoveViewPageUp) {
verticalScrollBar()->setValue(verticalScrollBar()->value()-verticalScrollBar()->pageStep());
e->accept();
} else if (e == Hotkey::MoveViewPageDown) {
verticalScrollBar()->setValue(verticalScrollBar()->value()+verticalScrollBar()->pageStep());
e->accept();
} else {
QPlainTextEdit::keyPressEvent(e);
if ((e->key() & 0x11111110) == 0x01000010)
Expand All @@ -242,9 +297,9 @@ void AbstractEdit::keyPressEvent(QKeyEvent *e)
if (e->modifiers() & Qt::ControlModifier) {
if (!mMarksAtMouse.isEmpty()) mMarksAtMouse.first()->cursorShape(&shape, true);
}
viewport()->setCursor(shape);

QWidget::keyPressEvent(e);
updateCursorShape(shape);
// TODO(JM) REVIEW! This is already done above - check with Rogo
// QWidget::keyPressEvent(e);
}

void AbstractEdit::keyReleaseEvent(QKeyEvent *e)
Expand All @@ -254,7 +309,7 @@ void AbstractEdit::keyReleaseEvent(QKeyEvent *e)
if (e->modifiers() & Qt::ControlModifier) {
if (!mMarksAtMouse.isEmpty()) mMarksAtMouse.first()->cursorShape(&shape, true);
}
viewport()->setCursor(shape);
updateCursorShape(shape);
}

void AbstractEdit::mousePressEvent(QMouseEvent *e)
Expand All @@ -281,28 +336,26 @@ const QList<TextMark *> &AbstractEdit::marksAtMouse() const
void AbstractEdit::mouseMoveEvent(QMouseEvent *e)
{
QPlainTextEdit::mouseMoveEvent(e);
if (QToolTip::isVisible() && (mTipPos-e->pos()).manhattanLength() > 3) {
if (QToolTip::isVisible() && (mTipPos-e->pos()).manhattanLength() > 5) {
mTipPos = QPoint();
QToolTip::hideText();
}
Qt::CursorShape shape = Qt::IBeamCursor;
if (!mMarks || mMarks->isEmpty()) {
// No marks or the text is editable
viewport()->setCursor(shape);
updateCursorShape(shape);
return;
}
QTextCursor cursor = cursorForPosition(e->pos());
QList<TextMark*> marks = mMarks->values(effectiveBlockNr(cursor.blockNumber()));
QList<TextMark*> marks = mMarks->values(absoluteBlockNr(cursor.blockNumber()));
mMarksAtMouse.clear();
int col = cursor.positionInBlock();
for (TextMark* mark: marks) {
if ((!mark->groupId().isValid() || mark->groupId() == groupId())
&& (mark->inColumn(col) || e->x() < 0))
if ((!mark->groupId().isValid() || mark->groupId() == groupId()))
mMarksAtMouse << mark;
}
if (!mMarksAtMouse.isEmpty() && (isReadOnly() || e->x() < 0))
shape = mMarksAtMouse.first()->cursorShape(&shape, true);
viewport()->setCursor(shape);
updateCursorShape(shape);
}

void AbstractEdit::mouseReleaseEvent(QMouseEvent *e)
Expand All @@ -317,7 +370,7 @@ void AbstractEdit::mouseReleaseEvent(QMouseEvent *e)

void AbstractEdit::marksChanged(const QSet<int> dirtyLines)
{
Q_UNUSED(dirtyLines);
Q_UNUSED(dirtyLines)
}


Expand Down
13 changes: 10 additions & 3 deletions src/editors/abstractedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ class AbstractEdit : public QPlainTextEdit
void jumpTo(int line, int column = 0);

void updateGroupId();
virtual void disconnectTimers();

signals:
void requestLstTexts(NodeId groupId, const QList<TextMark*> &marks, QStringList &result);
// void requestMarkTexts(NodeId groupId, const QList<TextMark*> &marks, QStringList &result);
void requestLstTexts(NodeId groupId, const QVector<int> &lstLines, QStringList &result);
void toggleBookmark(FileId fileId, int lineNr, int posInLine);
void jumpToNextBookmark(bool back, FileId refFileId, int refLineNr);
void cloneBookmarkMenu(QMenu *menu);
Expand All @@ -65,7 +67,8 @@ protected slots:
friend class FileMeta;

AbstractEdit(QWidget *parent);
void showToolTip(const QList<TextMark *> marks);
// void showToolTip(const QList<TextMark *> &marks, const QPoint &pos);
void showToolTip(const QVector<int> &lstNumbers, const QPoint &pos);
QMimeData* createMimeDataFromSelection() const override;
bool event(QEvent *event) override;
bool eventFilter(QObject *o, QEvent *e) override;
Expand All @@ -87,10 +90,14 @@ protected slots:
}
virtual void setMarks(const LineMarks *marks);
virtual const LineMarks* marks() const;
virtual int effectiveBlockNr(const int &localBlockNr) const;
virtual int absoluteBlockNr(const int &localBlockNr) const;
virtual int localBlockNr(const int &absoluteBlockNr) const;
virtual int topVisibleLine();
virtual void extraSelCurrentLine(QList<QTextEdit::ExtraSelection>& selections);
virtual void extraSelMarks(QList<QTextEdit::ExtraSelection> &selections);
virtual void updateCursorShape(const Qt::CursorShape &defaultShape);
virtual QPoint toolTipPos(const QPoint &mousePos);
virtual QVector<int> toolTipLstNumbers(const QPoint &pos);

private:
const LineMarks* mMarks = nullptr;
Expand Down
Loading

0 comments on commit 39e4473

Please sign in to comment.