@ -1264,8 +1264,11 @@ void TerminalDisplay::updateImage()
dirtyRegion | = QRect ( 0 , _contentRect . top ( ) + ( _screenWindow - > currentResultLine ( ) - _screenWindow - > currentLine ( ) ) * _fontHeight ,
_columns * _fontWidth , _fontHeight ) ;
}
_screenWindow - > resetScrollCount ( ) ;
if ( _highlightScrolledLinesControl . enabled ) {
dirtyRegion | = highlightScrolledLinesRegion ( ) ;
}
_screenWindow - > resetScrollCount ( ) ;
// update the parts of the display which have changed
update ( dirtyRegion ) ;
@ -1333,6 +1336,7 @@ void TerminalDisplay::paintEvent(QPaintEvent* pe)
drawContents ( paint , rect ) ;
}
drawCurrentResultRect ( paint ) ;
highlightScrolledLines ( paint ) ;
drawInputMethodPreeditString ( paint , preeditRect ( ) ) ;
paintFilters ( paint ) ;
@ -1767,6 +1771,75 @@ void TerminalDisplay::drawCurrentResultRect(QPainter& painter)
painter . fillRect ( _searchResultRect , QColor ( 0 , 0 , 255 , 80 ) ) ;
}
void TerminalDisplay : : highlightScrolledLines ( QPainter & painter )
{
if ( ! _highlightScrolledLinesControl . enabled ) {
return ;
}
QColor color = QColor ( _colorTable [ Color4Index ] ) ;
color . setAlpha ( _highlightScrolledLinesControl . timer - > isActive ( ) ? 255 : 150 ) ;
painter . fillRect ( _highlightScrolledLinesControl . rect , color ) ;
}
QRect TerminalDisplay : : highlightScrolledLinesRegion ( )
{
QRect result ;
if ( _scrollBar - > maximum ( ) = = 0 ) {
// De-highlight when entering something like 'vim'
if ( ! _highlightScrolledLinesControl . rect . isEmpty ( ) ) {
result = _highlightScrolledLinesControl . rect ;
_highlightScrolledLinesControl . rect . setRect ( 0 , 0 , 0 , 0 ) ;
}
} else {
const int highlightLeftPosition = _scrollbarLocation = = Enum : : ScrollBarLeft ? _scrollBar - > width ( ) : 0 ;
if ( _highlightScrolledLinesControl . previousScrollCount ! = 0 ) {
// De-highlight previously scrolled lines
if ( _screenWindow - > scrollCount ( ) = = 0 & & _scrollBar - > value ( ) = = _scrollBar - > maximum ( ) ) {
// Nothing has moved, we can reuse _highlightScrolledLinesControl.rect to clear
result = _highlightScrolledLinesControl . rect ;
_highlightScrolledLinesControl . rect . setRect ( 0 , 0 , 0 , 0 ) ;
} else {
int start = 0 ;
const int nb_lines = abs ( _highlightScrolledLinesControl . previousScrollCount ) ;
if ( _screenWindow - > scrollCount ( ) * _highlightScrolledLinesControl . previousScrollCount > 0 ) {
start = _screenWindow - > scrollCount ( ) < 0 ? abs ( _screenWindow - > scrollCount ( ) ) :
_screenWindow - > windowLines ( ) - _screenWindow - > scrollCount ( ) - _highlightScrolledLinesControl . previousScrollCount ;
} else {
start = _highlightScrolledLinesControl . previousScrollCount > 0 ? _screenWindow - > windowLines ( ) - _highlightScrolledLinesControl . previousScrollCount : 0 ;
}
result = QRect ( highlightLeftPosition , _contentRect . top ( ) + start * _fontHeight , HIGHLIGHT_SCROLLED_LINES_WIDTH , nb_lines * _fontHeight ) ;
}
}
// Highlight the new lines coming into view
int nb_lines = abs ( _screenWindow - > scrollCount ( ) ) ;
if ( nb_lines > 0 ) {
if ( _highlightScrolledLinesControl . timer - > isActive ( ) & & ( _screenWindow - > scrollCount ( ) * _highlightScrolledLinesControl . previousScrollCount > 0 ) ) {
nb_lines + = abs ( _highlightScrolledLinesControl . previousScrollCount ) ;
nb_lines = std : : min ( nb_lines , _screenWindow - > windowLines ( ) ) ;
_highlightScrolledLinesControl . previousScrollCount + = _screenWindow - > scrollCount ( ) ;
} else {
_highlightScrolledLinesControl . previousScrollCount = _screenWindow - > scrollCount ( ) ;
}
const int start = _screenWindow - > scrollCount ( ) > 0 ? std : : max ( _screenWindow - > windowLines ( ) - nb_lines , 0 ) : 0 ;
_highlightScrolledLinesControl . rect . setRect ( highlightLeftPosition , _contentRect . top ( ) + start * _fontHeight ,
HIGHLIGHT_SCROLLED_LINES_WIDTH , nb_lines * _fontHeight ) ;
result | = _highlightScrolledLinesControl . rect ;
_highlightScrolledLinesControl . timer - > start ( ) ;
}
}
return result ;
}
void TerminalDisplay : : highlightScrolledLinesEvent ( )
{
update ( _highlightScrolledLinesControl . rect ) ;
}
QRect TerminalDisplay : : imageToWidget ( const QRect & imageArea ) const
{
QRect result ;
@ -2002,7 +2075,8 @@ void TerminalDisplay::calcGeometry()
contentsRect ( ) . height ( ) - headerHeight // height
) ;
_contentRect = contentsRect ( ) . adjusted ( _margin , _margin , - _margin , - _margin ) ;
_contentRect = contentsRect ( ) . adjusted ( _margin + ( _highlightScrolledLinesControl . enabled ? HIGHLIGHT_SCROLLED_LINES_WIDTH : 0 ) , _margin ,
- _margin - ( _highlightScrolledLinesControl . enabled ? HIGHLIGHT_SCROLLED_LINES_WIDTH : 0 ) , - _margin ) ;
switch ( _scrollbarLocation ) {
case Enum : : ScrollBarHidden :
@ -2161,6 +2235,19 @@ bool TerminalDisplay::scrollFullPage() const
return _scrollFullPage ;
}
void TerminalDisplay : : setHighlightScrolledLines ( bool highlight )
{
_highlightScrolledLinesControl . enabled = highlight ;
if ( _highlightScrolledLinesControl . enabled & & _highlightScrolledLinesControl . timer = = nullptr ) {
// setup timer for diming the highlight on scrolled lines
_highlightScrolledLinesControl . timer = new QTimer ( this ) ;
_highlightScrolledLinesControl . timer - > setSingleShot ( true ) ;
_highlightScrolledLinesControl . timer - > setInterval ( 250 ) ;
connect ( _highlightScrolledLinesControl . timer , & QTimer : : timeout , this , & Konsole : : TerminalDisplay : : highlightScrolledLinesEvent ) ;
}
}
/* ------------------------------------------------------------------------- */
/* */
/* Mouse */
@ -4064,6 +4151,9 @@ void TerminalDisplay::applyProfile(const Profile::Ptr &profile)
setMiddleClickPasteMode ( Enum : : MiddleClickPasteModeEnum ( profile - > property < int > ( Profile : : MiddleClickPasteMode ) ) ) ;
setCopyTextAsHTML ( profile - > property < bool > ( Profile : : CopyTextAsHTML ) ) ;
// highlight lines scrolled into view (must be applied before margin/center)
setHighlightScrolledLines ( profile - > property < bool > ( Profile : : HighlightScrolledLines ) ) ;
// margin/center
setMargin ( profile - > property < int > ( Profile : : TerminalMargin ) ) ;
setCenterContents ( profile - > property < bool > ( Profile : : TerminalCenter ) ) ;