diff --git a/src/EditProfileDialog.h b/src/EditProfileDialog.h --- a/src/EditProfileDialog.h +++ b/src/EditProfileDialog.h @@ -175,6 +175,7 @@ void scrollFullPage(); void scrollHalfPage(); + void toggleHighlightScrolledLines(bool enable); // keyboard page void editKeyBinding(); diff --git a/src/EditProfileDialog.cpp b/src/EditProfileDialog.cpp --- a/src/EditProfileDialog.cpp +++ b/src/EditProfileDialog.cpp @@ -1578,6 +1578,12 @@ setupRadio(pageamounts, scrollFullPage); + + const auto options = QVector{ + {_scrollingUi->highlightScrolledLinesButton, Profile::HighlightScrolledLines, SLOT(toggleHighlightScrolledLines(bool))} + }; + setupCheckBoxes(options, profile); + // signals and slots connect(_scrollingUi->historySizeWidget, &Konsole::HistorySizeWidget::historySizeChanged, this, &Konsole::EditProfileDialog::historySizeChanged); @@ -1603,6 +1609,11 @@ updateTempProfileProperty(Profile::ScrollFullPage, Enum::ScrollPageHalf); } +void EditProfileDialog::toggleHighlightScrolledLines(bool enable) +{ + updateTempProfileProperty(Profile::HighlightScrolledLines, enable); +} + void EditProfileDialog::setupMousePage(const Profile::Ptr &profile) { const auto options = QVector{ diff --git a/src/EditProfileScrollingPage.ui b/src/EditProfileScrollingPage.ui --- a/src/EditProfileScrollingPage.ui +++ b/src/EditProfileScrollingPage.ui @@ -189,6 +189,45 @@ + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 16 + + + + + + + + + 0 + 0 + + + + Highlighting: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Highlight the lines coming into view + + + diff --git a/src/Profile.h b/src/Profile.h --- a/src/Profile.h +++ b/src/Profile.h @@ -150,6 +150,10 @@ * height or half height. */ ScrollFullPage, + /** (bool) Specifies whether the the lines that are scrolled into view + * should be highlighted. + */ + HighlightScrolledLines, /** (bool) Specifies whether the terminal will enable Bidirectional * text display */ diff --git a/src/Profile.cpp b/src/Profile.cpp --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -92,6 +92,7 @@ , { HistorySize , "HistorySize" , SCROLLING_GROUP , QVariant::Int } , { ScrollBarPosition , "ScrollBarPosition" , SCROLLING_GROUP , QVariant::Int } , { ScrollFullPage , "ScrollFullPage" , SCROLLING_GROUP , QVariant::Bool } + , { HighlightScrolledLines , "HighlightScrolledLines" , SCROLLING_GROUP , QVariant::Bool } // Terminal Features , { UrlHintsModifiers , "UrlHintsModifiers" , TERMINAL_GROUP , QVariant::Int } @@ -186,6 +187,7 @@ setProperty(HistorySize, 1000); setProperty(ScrollBarPosition, Enum::ScrollBarRight); setProperty(ScrollFullPage, false); + setProperty(HighlightScrolledLines, false); setProperty(FlowControlEnabled, true); setProperty(UrlHintsModifiers, 0); diff --git a/src/TerminalDisplay.h b/src/TerminalDisplay.h --- a/src/TerminalDisplay.h +++ b/src/TerminalDisplay.h @@ -112,6 +112,7 @@ void setScrollFullPage(bool fullPage); bool scrollFullPage() const; + void setHighlightScrolledLines(bool highlight); /** * Returns the display's filter chain. When the image for the display is updated, @@ -605,6 +606,8 @@ void drawContents(QPainter &painter, const QRect &rect); // draw a transparent rectangle over the line of the current match void drawCurrentResultRect(QPainter &painter); + // draw a tranparent rectangle over the lines that have been scrolled in + void highlightScrolledLinesRect(QPainter& painter); // draws a section of text, all the text in this section // has a common color and style void drawTextFragment(QPainter &painter, const QRect &rect, const QString &text, @@ -847,6 +850,12 @@ IncrementalSearchBar *_searchBar; QRect _searchResultRect; + + bool _highlightScrolledLines; + bool _needToHighlightLines; + QRect _highlightScrolledLinesRect; + int _previousScrollCount; + friend class TerminalDisplayAccessible; }; diff --git a/src/TerminalDisplay.cpp b/src/TerminalDisplay.cpp --- a/src/TerminalDisplay.cpp +++ b/src/TerminalDisplay.cpp @@ -130,6 +130,7 @@ }); connect(_screenWindow.data(), &Konsole::ScreenWindow::scrolled, this, [this]() { _filterUpdateRequired = true; + _needToHighlightLines = true; }); _screenWindow->setWindowLines(_lines); } @@ -483,6 +484,10 @@ , _scrollWheelState(ScrollState()) , _searchBar(new IncrementalSearchBar(this)) , _searchResultRect(QRect()) + , _highlightScrolledLines(false) + , _needToHighlightLines(false) + , _highlightScrolledLinesRect(QRect()) + , _previousScrollCount(0) { // terminal applications are not designed with Right-To-Left in mind, // so the layout is forced to Left-To-Right @@ -1200,8 +1205,30 @@ dirtyRegion |= QRect(0, _contentRect.top() + (_screenWindow->currentResultLine() - _screenWindow->currentLine()) * _fontHeight, _columns * _fontWidth, _fontHeight); } - _screenWindow->resetScrollCount(); + if (_highlightScrolledLines && _needToHighlightLines) { + if (_previousScrollCount != 0) { + const int nb_lines = abs(_previousScrollCount); + int start = 0; + if (_screenWindow->scrollCount() * _previousScrollCount < 0) { + start = _previousScrollCount > 0 ? _screenWindow->windowLines() - _previousScrollCount : 0; + } else { + start = _screenWindow->scrollCount() < 0 ? abs(_screenWindow->scrollCount()) : + _screenWindow->windowLines() - _screenWindow->scrollCount() - _previousScrollCount; + } + dirtyRegion |= QRect(0, _contentRect.top() + start * _fontHeight, _columns * _fontWidth, nb_lines * _fontHeight); + } + if (_screenWindow->scrollCount() != 0) { + const int nb_lines = abs(_screenWindow->scrollCount()); + const int start = _screenWindow->scrollCount() > 0 ? _screenWindow->windowLines() - _screenWindow->scrollCount() : 0; + _highlightScrolledLinesRect.setRect(0, _contentRect.top() + start * _fontHeight, _columns * _fontWidth, nb_lines * _fontHeight); + dirtyRegion |= _highlightScrolledLinesRect; + } else { + _highlightScrolledLinesRect.setRect(0, 0, 0, 0); + } + _previousScrollCount = _screenWindow->scrollCount(); + } + _screenWindow->resetScrollCount(); // update the parts of the display which have changed update(dirtyRegion); @@ -1265,6 +1292,7 @@ drawContents(paint, rect); } drawCurrentResultRect(paint); + highlightScrolledLinesRect(paint); drawInputMethodPreeditString(paint, preeditRect()); paintFilters(paint); @@ -1682,6 +1710,19 @@ painter.fillRect(_searchResultRect, QColor(0, 0, 255, 80)); } +void TerminalDisplay::highlightScrolledLinesRect(QPainter& painter) +{ + if (!_highlightScrolledLines || !_needToHighlightLines) { + return; + } + + _needToHighlightLines = false; + + QColor color = QColor(_colorTable[DEFAULT_FORE_COLOR]); + color.setAlpha(20); + painter.fillRect(_highlightScrolledLinesRect, color); +} + QRect TerminalDisplay::imageToWidget(const QRect& imageArea) const { QRect result; @@ -2050,6 +2091,12 @@ return _scrollFullPage; } + +void TerminalDisplay::setHighlightScrolledLines(bool highlight) +{ + _highlightScrolledLines = highlight; +} + /* ------------------------------------------------------------------------- */ /* */ /* Mouse */ @@ -2690,6 +2737,7 @@ { Q_ASSERT(_sessionController != nullptr); _sessionController->setSearchStartToWindowCurrentLine(); + _needToHighlightLines = true; } /* Moving left/up from the line containing pnt, return the starting @@ -3904,4 +3952,7 @@ // mouse wheel zoom _mouseWheelZoom = profile->mouseWheelZoomEnabled(); setAlternateScrolling(profile->property(Profile::AlternateScrolling)); + + // hightlight lines scrolled in view + setHighlightScrolledLines(profile->property(Profile::HighlightScrolledLines)); }