Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Konsole
Commits
9433d17a
Commit
9433d17a
authored
Dec 12, 2020
by
Carlos Alves
Committed by
Kurt Hindenburg
Dec 23, 2020
Browse files
Initial refactoring TerminalScrollBar class
parent
8ed8e0df
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/CMakeLists.txt
View file @
9433d17a
...
...
@@ -177,6 +177,7 @@ set(konsoleprivate_SRCS ${windowadaptors_SRCS}
terminalDisplay/extras/CompositeWidgetFocusWatcher.cpp
terminalDisplay/extras/AutoScrollHandler.cpp
terminalDisplay/extras/HighlightScrolledLines.cpp
terminalDisplay/TerminalDisplay.cpp
terminalDisplay/TerminalPainter.cpp
...
...
src/terminalDisplay/TerminalDisplay.cpp
View file @
9433d17a
...
...
@@ -673,8 +673,22 @@ void TerminalDisplay::updateImage()
// can simply be moved up or down
// disable this shortcut for transparent konsole with scaled pixels, otherwise we get rendering artifacts, see BUG 350651
if
(
!
(
WindowSystemInfo
::
HAVE_TRANSPARENCY
&&
(
qApp
->
devicePixelRatio
()
>
1.0
))
&&
_wallpaper
->
isNull
()
&&
!
_searchBar
->
isVisible
())
{
_scrollBar
->
scrollImage
(
_screenWindow
->
scrollCount
()
,
_screenWindow
->
scrollRegion
());
// if the flow control warning is enabled this will interfere with the
// scrolling optimizations and cause artifacts. the simple solution here
// is to just disable the optimization whilst it is visible
if
(
!
((
_outputSuspendedMessageWidget
!=
nullptr
)
&&
_outputSuspendedMessageWidget
->
isVisible
())
&&
!
((
_readOnlyMessageWidget
!=
nullptr
)
&&
_readOnlyMessageWidget
->
isVisible
()))
{
// hide terminal size label to prevent it being scrolled and show again after scroll
const
bool
viewResizeWidget
=
(
_resizeWidget
!=
nullptr
)
&&
_resizeWidget
->
isVisible
();
if
(
viewResizeWidget
)
{
_resizeWidget
->
hide
();
}
_scrollBar
->
scrollImage
(
_screenWindow
->
scrollCount
(),
_screenWindow
->
scrollRegion
(),
_image
,
_imageSize
);
if
(
viewResizeWidget
)
{
_resizeWidget
->
show
();
}
}
}
if
(
_image
==
nullptr
)
{
...
...
@@ -831,13 +845,8 @@ void TerminalDisplay::updateImage()
_columns
*
_fontWidth
,
_fontHeight
);
}
if
(
_highlightScrolledLinesControl
.
enabled
)
{
dirtyRegion
|=
emit
highlightScrolledLinesRegion
(
dirtyRegion
.
isEmpty
(),
_highlightScrolledLinesControl
.
timer
,
_highlightScrolledLinesControl
.
previousScrollCount
,
_highlightScrolledLinesControl
.
rect
,
_highlightScrolledLinesControl
.
needToClear
,
HIGHLIGHT_SCROLLED_LINES_WIDTH
);
if
(
_scrollBar
->
highlightScrolledLines
().
isEnabled
())
{
dirtyRegion
|=
emit
highlightScrolledLinesRegion
(
dirtyRegion
.
isEmpty
(),
_scrollBar
);
}
_screenWindow
->
resetScrollCount
();
...
...
@@ -915,8 +924,8 @@ void TerminalDisplay::paintEvent(QPaintEvent* pe)
emit
drawContents
(
_image
,
paint
,
rect
,
false
,
_imageSize
,
_bidiEnabled
,
_fixedFont
,
_lineProperties
);
}
emit
drawCurrentResultRect
(
paint
,
_searchResultRect
);
if
(
_highlightScrolledLines
Control
.
e
nabled
)
{
emit
highlightScrolledLines
(
paint
,
_highlightScrolledLines
Control
.
timer
,
_
highlightScrolledLines
Control
.
rect
);
if
(
_
scrollBar
->
highlightScrolledLines
().
isE
nabled
()
)
{
emit
highlightScrolledLines
(
paint
,
_
scrollBar
->
highlightScrolledLines
().
isTimerActive
(),
_scrollBar
->
highlightScrolledLines
()
.
rect
()
);
}
emit
drawInputMethodPreeditString
(
paint
,
preeditRect
(),
_inputMethodData
,
_image
);
paintFilters
(
paint
);
...
...
@@ -1205,8 +1214,10 @@ void TerminalDisplay::calcGeometry()
contentsRect
().
height
()
-
headerHeight
// height
);
_contentRect
=
contentsRect
().
adjusted
(
_margin
+
(
_highlightScrolledLinesControl
.
enabled
?
HIGHLIGHT_SCROLLED_LINES_WIDTH
:
0
),
_margin
,
-
_margin
-
(
_highlightScrolledLinesControl
.
enabled
?
HIGHLIGHT_SCROLLED_LINES_WIDTH
:
0
),
-
_margin
);
_contentRect
=
contentsRect
().
adjusted
(
_margin
+
(
_scrollBar
->
highlightScrolledLines
().
isEnabled
()
?
_scrollBar
->
highlightScrolledLines
().
HIGHLIGHT_SCROLLED_LINES_WIDTH
:
0
),
_margin
,
-
_margin
-
(
_scrollBar
->
highlightScrolledLines
().
isEnabled
()
?
_scrollBar
->
highlightScrolledLines
().
HIGHLIGHT_SCROLLED_LINES_WIDTH
:
0
),
-
_margin
);
switch
(
_scrollBar
->
scrollBarPosition
())
{
case
Enum
::
ScrollBarHidden
:
...
...
@@ -3021,7 +3032,6 @@ void TerminalDisplay::applyProfile(const Profile::Ptr &profile)
// highlight lines scrolled into view (must be applied before margin/center)
_scrollBar
->
setHighlightScrolledLines
(
profile
->
property
<
bool
>
(
Profile
::
HighlightScrolledLines
));
_highlightScrolledLinesControl
.
needToClear
=
true
;
// margin/center
setMargin
(
profile
->
property
<
int
>
(
Profile
::
TerminalMargin
));
...
...
src/terminalDisplay/TerminalDisplay.h
View file @
9433d17a
...
...
@@ -206,6 +206,7 @@ public:
}
void
setSize
(
int
columns
,
int
lines
);
void
propagateSize
();
// reimplemented
QSize
sizeHint
()
const
override
;
...
...
@@ -323,8 +324,6 @@ public:
// toggle the header bar Minimize/Maximize button.
void
setExpandedMode
(
bool
expand
);
friend
class
TerminalScrollBar
;
TerminalScrollBar
*
scrollBar
()
const
{
return
_scrollBar
;
...
...
@@ -555,8 +554,8 @@ Q_SIGNALS:
QVector
<
LineProperty
>
lineProperties
);
void
drawCurrentResultRect
(
QPainter
&
painter
,
QRect
searchResultRect
);
void
highlightScrolledLines
(
QPainter
&
painter
,
QTimer
*
timer
,
QRect
rect
);
QRegion
highlightScrolledLinesRegion
(
bool
nothingChanged
,
QTimer
*
timer
,
int
&
previousScrollCount
,
QRect
&
rect
,
bool
&
needToClear
,
int
HighlightScrolledLinesWidth
);
void
highlightScrolledLines
(
QPainter
&
painter
,
bool
isTimerActive
,
QRect
rect
);
QRegion
highlightScrolledLinesRegion
(
bool
nothingChanged
,
TerminalScrollBar
*
scrollBar
);
void
drawBackground
(
QPainter
&
painter
,
const
QRect
&
rect
,
const
QColor
&
backgroundColor
,
bool
useOpacitySetting
);
void
drawCharacters
(
QPainter
&
painter
,
const
QRect
&
rect
,
const
QString
&
text
,
...
...
@@ -639,7 +638,6 @@ private:
void
showResizeNotification
();
void
calcGeometry
();
void
propagateSize
();
void
updateImageSize
();
void
makeImage
();
...
...
@@ -807,15 +805,6 @@ private:
bool
_drawOverlay
;
Qt
::
Edge
_overlayEdge
;
struct
{
bool
enabled
=
false
;
QRect
rect
;
int
previousScrollCount
=
0
;
QTimer
*
timer
=
nullptr
;
bool
needToClear
=
false
;
}
_highlightScrolledLinesControl
;
static
const
int
HIGHLIGHT_SCROLLED_LINES_WIDTH
=
3
;
bool
_hasCompositeFocus
;
bool
_displayVerticalLine
;
int
_displayVerticalLineAtChar
;
...
...
src/terminalDisplay/TerminalPainter.cpp
View file @
9433d17a
...
...
@@ -272,17 +272,17 @@ namespace Konsole
display
->
columns
()
*
display
->
fontWidth
(),
display
->
fontHeight
());
painter
.
fillRect
(
searchResultRect
,
QColor
(
0
,
0
,
255
,
80
));
}
void
TerminalPainter
::
highlightScrolledLines
(
QPainter
&
painter
,
QTimer
*
timer
,
QRect
rect
)
void
TerminalPainter
::
highlightScrolledLines
(
QPainter
&
painter
,
bool
isTimerActive
,
QRect
rect
)
{
const
auto
display
=
qobject_cast
<
TerminalDisplay
*>
(
sender
());
const
auto
display
=
qobject_cast
<
TerminalDisplay
*>
(
sender
());
QColor
color
=
QColor
(
display
->
terminalColor
()
->
colorTable
()[
Color4Index
]);
color
.
setAlpha
(
t
imer
->
is
Active
()
?
255
:
150
);
color
.
setAlpha
(
isT
imerActive
?
255
:
150
);
painter
.
fillRect
(
rect
,
color
);
}
QRegion
TerminalPainter
::
highlightScrolledLinesRegion
(
bool
nothingChanged
,
QTimer
*
timer
,
int
&
previousScrollCount
,
QRect
&
rect
,
bool
&
needToClear
,
int
HighlightScrolledLinesWidth
)
QRegion
TerminalPainter
::
highlightScrolledLinesRegion
(
bool
nothingChanged
,
TerminalScrollBar
*
scrollBar
)
{
const
auto
display
=
qobject_cast
<
TerminalDisplay
*>
(
sender
());
...
...
@@ -293,21 +293,23 @@ namespace Konsole
int
nb_lines
=
abs
(
display
->
screenWindow
()
->
scrollCount
());
if
(
nb_lines
>
0
&&
display
->
scrollBar
()
->
maximum
()
>
0
)
{
QRect
new_highlight
;
bool
addToCurrentHighlight
=
timer
->
is
Active
()
&&
(
display
->
screenWindow
()
->
scrollCount
()
*
p
reviousScrollCount
>
0
);
bool
addToCurrentHighlight
=
scrollBar
->
highlightScrolledLines
().
isTimer
Active
()
&&
(
display
->
screenWindow
()
->
scrollCount
()
*
scrollBar
->
highlightScrolledLines
().
getP
reviousScrollCount
()
>
0
);
if
(
addToCurrentHighlight
)
{
const
int
oldScrollCount
=
scrollBar
->
highlightScrolledLines
().
getPreviousScrollCount
();
if
(
display
->
screenWindow
()
->
scrollCount
()
>
0
)
{
start
=
-
1
*
(
previous
ScrollCount
+
display
->
screenWindow
()
->
scrollCount
())
+
display
->
screenWindow
()
->
windowLines
();
start
=
-
1
*
(
old
ScrollCount
+
display
->
screenWindow
()
->
scrollCount
())
+
display
->
screenWindow
()
->
windowLines
();
}
else
{
start
=
-
1
*
previous
ScrollCount
;
start
=
-
1
*
old
ScrollCount
;
}
p
reviousScrollCount
+
=
display
->
screenWindow
()
->
scrollCount
();
scrollBar
->
highlightScrolledLines
().
setP
reviousScrollCount
(
oldScrollCount
+
display
->
screenWindow
()
->
scrollCount
()
)
;
}
else
{
start
=
display
->
screenWindow
()
->
scrollCount
()
>
0
?
display
->
screenWindow
()
->
windowLines
()
-
nb_lines
:
0
;
p
reviousScrollCount
=
display
->
screenWindow
()
->
scrollCount
();
scrollBar
->
highlightScrolledLines
().
setP
reviousScrollCount
(
display
->
screenWindow
()
->
scrollCount
()
)
;
}
new_highlight
.
setRect
(
highlightLeftPosition
,
display
->
contentRect
().
top
()
+
start
*
display
->
fontHeight
(),
HighlightScrolledLinesWidth
,
nb_lines
*
display
->
fontHeight
());
new_highlight
.
setRect
(
highlightLeftPosition
,
display
->
contentRect
().
top
()
+
start
*
display
->
fontHeight
(),
scrollBar
->
highlightScrolledLines
().
HIGHLIGHT_SCROLLED_LINES_WIDTH
,
nb_lines
*
display
->
fontHeight
());
new_highlight
.
setTop
(
std
::
max
(
new_highlight
.
top
(),
display
->
contentRect
().
top
()));
new_highlight
.
setBottom
(
std
::
min
(
new_highlight
.
bottom
(),
display
->
contentRect
().
bottom
()));
if
(
!
new_highlight
.
isValid
())
{
...
...
@@ -315,22 +317,22 @@ namespace Konsole
}
if
(
addToCurrentHighlight
)
{
rect
|=
new_highlight
;
scrollBar
->
highlightScrolledLines
().
rect
()
|=
new_highlight
;
}
else
{
dirtyRegion
|=
rect
;
rect
=
new_highlight
;
dirtyRegion
|=
scrollBar
->
highlightScrolledLines
().
rect
()
;
scrollBar
->
highlightScrolledLines
().
rect
()
=
new_highlight
;
}
timer
->
start
();
}
else
if
(
!
nothingChanged
||
n
eedToClear
)
{
dirtyRegion
=
rect
;
rect
.
setRect
(
0
,
0
,
0
,
0
);
n
eedToClear
=
false
;
scrollBar
->
highlightScrolledLines
().
startTimer
();
}
else
if
(
!
nothingChanged
||
scrollBar
->
highlightScrolledLines
().
isN
eedToClear
()
)
{
dirtyRegion
=
scrollBar
->
highlightScrolledLines
().
rect
()
;
scrollBar
->
highlightScrolledLines
().
rect
()
.
setRect
(
0
,
0
,
0
,
0
);
scrollBar
->
highlightScrolledLines
().
setN
eedToClear
(
false
)
;
}
return
dirtyRegion
;
}
void
TerminalPainter
::
drawTextFragment
(
QPainter
&
painter
,
const
QRect
&
rect
,
const
QString
&
text
,
const
Character
*
style
,
const
QColor
*
colorTable
)
{
...
...
src/terminalDisplay/TerminalPainter.h
View file @
9433d17a
...
...
@@ -42,6 +42,7 @@ namespace Konsole
explicit
TerminalPainter
(
QObject
*
parent
=
nullptr
);
~
TerminalPainter
()
=
default
;
public
Q_SLOTS
:
// -- Drawing helpers --
// divides the part of the display specified by 'rect' into
...
...
@@ -55,10 +56,10 @@ namespace Konsole
void
drawCurrentResultRect
(
QPainter
&
painter
,
QRect
searchResultRect
);
// draw a thin highlight on the left of the screen for lines that have been scrolled into view
void
highlightScrolledLines
(
QPainter
&
painter
,
QTimer
*
timer
,
QRect
rect
);
void
highlightScrolledLines
(
QPainter
&
painter
,
bool
isTimerActive
,
QRect
rect
);
// compute which region need to be repainted for scrolled lines highlight
QRegion
highlightScrolledLinesRegion
(
bool
nothingChanged
,
QTimer
*
timer
,
int
&
previousScrollCount
,
QRect
&
rect
,
bool
&
needToClear
,
int
HighlightScrolledLinesWidth
);
QRegion
highlightScrolledLinesRegion
(
bool
nothingChanged
,
TerminalScrollBar
*
scrollBar
);
// draws the background for a text fragment
// if useOpacitySetting is true then the color's alpha value will be set to
...
...
src/terminalDisplay/TerminalScrollBar.cpp
View file @
9433d17a
...
...
@@ -11,8 +11,8 @@
// Konsole
#include "TerminalDisplay.h"
#include "session/SessionController.h"
#include "../characters/Character.h"
#include "extras/HighlightScrolledLines.h"
// KDE
#include <KMessageWidget>
...
...
@@ -24,9 +24,8 @@
namespace
Konsole
{
TerminalScrollBar
::
TerminalScrollBar
(
TerminalDisplay
*
display
)
:
QScrollBar
(
display
)
,
_display
(
display
)
TerminalScrollBar
::
TerminalScrollBar
(
QWidget
*
parent
)
:
QScrollBar
(
parent
)
,
_scrollFullPage
(
false
)
,
_alternateScrolling
(
false
)
,
_scrollbarLocation
(
Enum
::
ScrollBarRight
)
...
...
@@ -43,94 +42,93 @@ namespace Konsole
_scrollbarLocation
=
position
;
applyScrollBarPosition
(
true
);
}
void
TerminalScrollBar
::
setScroll
(
int
cursor
,
int
slines
)
void
TerminalScrollBar
::
setScroll
(
int
cursor
,
int
slines
)
{
const
auto
display
=
qobject_cast
<
TerminalDisplay
*>
(
this
->
parent
());
// update _scrollBar if the range or value has changed,
// otherwise return
//
// setting the range or value of a _scrollBar will always trigger
// a repaint, so it should be avoided if it is not necessary
if
(
this
->
minimum
()
==
0
&&
this
->
maximum
()
==
(
slines
-
_
display
->
_
lines
)
&&
this
->
value
()
==
cursor
)
{
if
(
this
->
minimum
()
==
0
&&
this
->
maximum
()
==
(
slines
-
display
->
lines
()
)
&&
this
->
value
()
==
cursor
)
{
return
;
}
disconnect
(
this
,
&
QScrollBar
::
valueChanged
,
this
,
&
TerminalScrollBar
::
scrollBarPositionChanged
);
setRange
(
0
,
slines
-
_
display
->
_
lines
);
setRange
(
0
,
slines
-
display
->
lines
()
);
setSingleStep
(
1
);
setPageStep
(
_
display
->
_
lines
);
setPageStep
(
display
->
lines
()
);
setValue
(
cursor
);
connect
(
this
,
&
QScrollBar
::
valueChanged
,
this
,
&
TerminalScrollBar
::
scrollBarPositionChanged
);
}
void
TerminalScrollBar
::
setScrollFullPage
(
bool
fullPage
)
void
TerminalScrollBar
::
setScrollFullPage
(
bool
fullPage
)
{
_scrollFullPage
=
fullPage
;
}
bool
TerminalScrollBar
::
scrollFullPage
()
const
{
return
_scrollFullPage
;
}
void
TerminalScrollBar
::
setHighlightScrolledLines
(
bool
highlight
)
void
TerminalScrollBar
::
setHighlightScrolledLines
(
bool
highlight
)
{
_display
->
_highlightScrolledLinesControl
.
enabled
=
highlight
;
if
(
_display
->
_highlightScrolledLinesControl
.
enabled
&&
_display
->
_highlightScrolledLinesControl
.
timer
==
nullptr
)
{
// setup timer for diming the highlight on scrolled lines
_display
->
_highlightScrolledLinesControl
.
timer
=
new
QTimer
(
this
);
_display
->
_highlightScrolledLinesControl
.
timer
->
setSingleShot
(
true
);
_display
->
_highlightScrolledLinesControl
.
timer
->
setInterval
(
250
);
connect
(
_display
->
_highlightScrolledLinesControl
.
timer
,
&
QTimer
::
timeout
,
this
,
&
TerminalScrollBar
::
highlightScrolledLinesEvent
);
}
_highlightScrolledLines
.
setEnabled
(
highlight
);
_highlightScrolledLines
.
setTimer
(
this
);
_highlightScrolledLines
.
setNeedToClear
(
true
);
}
bool
TerminalScrollBar
::
alternateScrolling
()
const
{
return
_alternateScrolling
;
}
void
TerminalScrollBar
::
setAlternateScrolling
(
bool
enable
)
void
TerminalScrollBar
::
setAlternateScrolling
(
bool
enable
)
{
_alternateScrolling
=
enable
;
}
void
TerminalScrollBar
::
scrollBarPositionChanged
(
int
)
void
TerminalScrollBar
::
scrollBarPositionChanged
(
int
)
{
if
(
_display
->
screenWindow
().
isNull
())
{
const
auto
display
=
qobject_cast
<
TerminalDisplay
*>
(
this
->
parent
());
if
(
display
->
screenWindow
().
isNull
())
{
return
;
}
_
display
->
screenWindow
()
->
scrollTo
(
this
->
value
());
display
->
screenWindow
()
->
scrollTo
(
this
->
value
());
// if the thumb has been moved to the bottom of the _scrollBar then set
// the display to automatically track new output,
// that is, scroll down automatically
// to how new _lines as they are added
const
bool
atEndOfOutput
=
(
this
->
value
()
==
this
->
maximum
());
_
display
->
screenWindow
()
->
setTrackOutput
(
atEndOfOutput
);
display
->
screenWindow
()
->
setTrackOutput
(
atEndOfOutput
);
_
display
->
updateImage
();
display
->
updateImage
();
}
void
TerminalScrollBar
::
highlightScrolledLinesEvent
()
void
TerminalScrollBar
::
highlightScrolledLinesEvent
()
{
_display
->
update
(
_display
->
_highlightScrolledLinesControl
.
rect
);
const
auto
display
=
qobject_cast
<
TerminalDisplay
*>
(
this
->
parent
());
display
->
update
(
_highlightScrolledLines
.
rect
());
}
void
TerminalScrollBar
::
applyScrollBarPosition
(
bool
propagate
)
void
TerminalScrollBar
::
applyScrollBarPosition
(
bool
propagate
)
{
setHidden
(
_scrollbarLocation
==
Enum
::
ScrollBarHidden
);
if
(
propagate
)
{
_display
->
propagateSize
();
_display
->
update
();
const
auto
display
=
qobject_cast
<
TerminalDisplay
*>
(
this
->
parent
());
display
->
propagateSize
();
display
->
update
();
}
}
// scrolls the image by 'lines', down if lines > 0 or up otherwise.
//
// the terminal emulation keeps track of the scrolling of the character
...
...
@@ -139,43 +137,26 @@ namespace Konsole
// display is much cheaper than re-rendering all the text for the
// part of the image which has moved up or down.
// Instead only new lines have to be drawn
void
TerminalScrollBar
::
scrollImage
(
int
lines
,
const
QRect
&
screenWindowRegion
)
void
TerminalScrollBar
::
scrollImage
(
int
lines
,
const
QRect
&
screenWindowRegion
,
Character
*
image
,
int
imageSize
)
{
// return if there is nothing to do
if
((
lines
==
0
)
||
(
_display
->
_image
==
nullptr
))
{
return
;
}
// if the flow control warning is enabled this will interfere with the
// scrolling optimizations and cause artifacts. the simple solution here
// is to just disable the optimization whilst it is visible
if
((
_display
->
_outputSuspendedMessageWidget
!=
nullptr
)
&&
_display
->
_outputSuspendedMessageWidget
->
isVisible
())
{
return
;
}
if
((
_display
->
_readOnlyMessageWidget
!=
nullptr
)
&&
_display
->
_readOnlyMessageWidget
->
isVisible
())
{
if
((
lines
==
0
)
||
(
image
==
nullptr
))
{
return
;
}
const
auto
display
=
qobject_cast
<
TerminalDisplay
*>
(
this
->
parent
());
// constrain the region to the display
// the bottom of the region is capped to the number of lines in the display's
// internal image - 2, so that the height of 'region' is strictly less
// than the height of the internal image.
QRect
region
=
screenWindowRegion
;
region
.
setBottom
(
qMin
(
region
.
bottom
(),
_
display
->
_
lines
-
2
));
region
.
setBottom
(
qMin
(
region
.
bottom
(),
display
->
lines
()
-
2
));
// return if there is nothing to do
if
(
!
region
.
isValid
()
||
(
region
.
top
()
+
abs
(
lines
))
>=
region
.
bottom
()
||
_display
->
_lines
<=
region
.
bottom
())
{
if
(
!
region
.
isValid
()
||
(
region
.
top
()
+
abs
(
lines
))
>=
region
.
bottom
()
||
display
->
lines
()
<=
region
.
bottom
())
{
return
;
}
// hide terminal size label to prevent it being scrolled
if
((
_display
->
_resizeWidget
!=
nullptr
)
&&
_display
->
_resizeWidget
->
isVisible
())
{
_display
->
_resizeWidget
->
hide
();
}
// Note: With Qt 4.4 the left edge of the scrolled area must be at 0
// to get the correct (newly exposed) part of the widget repainted.
//
...
...
@@ -190,27 +171,27 @@ namespace Konsole
const
int
SCROLLBAR_CONTENT_GAP
=
1
;
QRect
scrollRect
;
if
(
_scrollbarLocation
==
Enum
::
ScrollBarLeft
)
{
scrollRect
.
setLeft
(
scrollBarWidth
+
SCROLLBAR_CONTENT_GAP
+
(
_
display
->
_
highlightScrolledLines
Control
.
e
nabled
?
_display
->
HIGHLIGHT_SCROLLED_LINES_WIDTH
:
0
));
scrollRect
.
setRight
(
_
display
->
width
());
scrollRect
.
setLeft
(
scrollBarWidth
+
SCROLLBAR_CONTENT_GAP
+
(
_highlightScrolledLines
.
isE
nabled
()
?
_highlightScrolledLines
.
HIGHLIGHT_SCROLLED_LINES_WIDTH
:
0
));
scrollRect
.
setRight
(
display
->
width
());
}
else
{
scrollRect
.
setLeft
(
_
display
->
_
highlightScrolledLines
Control
.
e
nabled
?
_display
->
HIGHLIGHT_SCROLLED_LINES_WIDTH
:
0
);
scrollRect
.
setRight
(
_
display
->
width
()
-
scrollBarWidth
-
SCROLLBAR_CONTENT_GAP
);
scrollRect
.
setLeft
(
_highlightScrolledLines
.
isE
nabled
()
?
_highlightScrolledLines
.
HIGHLIGHT_SCROLLED_LINES_WIDTH
:
0
);
scrollRect
.
setRight
(
display
->
width
()
-
scrollBarWidth
-
SCROLLBAR_CONTENT_GAP
);
}
void
*
firstCharPos
=
&
_display
->
_
image
[
region
.
top
()
*
_
display
->
_
columns
];
void
*
lastCharPos
=
&
_display
->
_
image
[(
region
.
top
()
+
abs
(
lines
))
*
_
display
->
_
columns
];
void
*
firstCharPos
=
&
image
[
region
.
top
()
*
display
->
columns
()
];
void
*
lastCharPos
=
&
image
[(
region
.
top
()
+
abs
(
lines
))
*
display
->
columns
()
];
const
int
top
=
_
display
->
_
contentRect
.
top
()
+
(
region
.
top
()
*
_
display
->
_
fontHeight
);
const
int
top
=
display
->
contentRect
()
.
top
()
+
(
region
.
top
()
*
display
->
fontHeight
()
);
const
int
linesToMove
=
region
.
height
()
-
abs
(
lines
);
const
int
bytesToMove
=
linesToMove
*
_
display
->
_
columns
*
sizeof
(
Character
);
const
int
bytesToMove
=
linesToMove
*
display
->
columns
()
*
sizeof
(
Character
);
Q_ASSERT
(
linesToMove
>
0
);
Q_ASSERT
(
bytesToMove
>
0
);
scrollRect
.
setTop
(
lines
>
0
?
top
:
top
+
abs
(
lines
)
*
_
display
->
_
fontHeight
);
scrollRect
.
setHeight
(
linesToMove
*
_
display
->
_
fontHeight
);
scrollRect
.
setTop
(
lines
>
0
?
top
:
top
+
abs
(
lines
)
*
display
->
fontHeight
()
);
scrollRect
.
setHeight
(
linesToMove
*
display
->
fontHeight
()
);
if
(
!
scrollRect
.
isValid
()
||
scrollRect
.
isEmpty
())
{
return
;
...
...
@@ -219,22 +200,22 @@ namespace Konsole
// scroll internal image
if
(
lines
>
0
)
{
// check that the memory areas that we are going to move are valid
Q_ASSERT
((
char
*
)
lastCharPos
+
bytesToMove
<
(
char
*
)(
_display
->
_
image
+
(
_
display
->
_
lines
*
_
display
->
_
columns
)));
Q_ASSERT
((
lines
*
_
display
->
_
columns
)
<
_display
->
_
imageSize
);
Q_ASSERT
((
char
*
)
lastCharPos
+
bytesToMove
<
(
char
*
)(
image
+
(
display
->
lines
()
*
display
->
columns
()
)));
Q_ASSERT
((
lines
*
display
->
columns
()
)
<
imageSize
);
// scroll internal image down
memmove
(
firstCharPos
,
lastCharPos
,
bytesToMove
);
}
else
{
// check that the memory areas that we are going to move are valid
Q_ASSERT
((
char
*
)
firstCharPos
+
bytesToMove
<
(
char
*
)(
_display
->
_
image
+
(
_
display
->
_
lines
*
_
display
->
_
columns
)));
Q_ASSERT
((
char
*
)
firstCharPos
+
bytesToMove
<
(
char
*
)(
image
+
(
display
->
lines
()
*
display
->
columns
()
)));
//scroll internal image up
memmove
(
lastCharPos
,
firstCharPos
,
bytesToMove
);
memmove
(
lastCharPos
,
firstCharPos
,
bytesToMove
);
}
// scroll the display vertically to match internal _image
_
display
->
scroll
(
0
,
_
display
->
_
fontHeight
*
(
-
lines
),
scrollRect
);
display
->
scroll
(
0
,
display
->
fontHeight
()
*
(
-
lines
),
scrollRect
);
}
}
}
// namespace Konsole
src/terminalDisplay/TerminalScrollBar.h
View file @
9433d17a
...
...
@@ -17,6 +17,7 @@
#include "Enumeration.h"
#include "ScreenWindow.h"
#include "konsoleprivate_export.h"
#include "extras/HighlightScrolledLines.h"
namespace
Konsole
{
...
...
@@ -26,7 +27,7 @@ namespace Konsole
{
Q_OBJECT
public:
explicit
TerminalScrollBar
(
TerminalDisplay
*
display
);
explicit
TerminalScrollBar
(
QWidget
*
parent
);
/**
* Specifies whether the terminal display has a vertical scroll bar, and if so whether it
...
...
@@ -68,24 +69,32 @@ namespace Konsole
// 'region' is the part of the image to scroll - currently only
// the top, bottom and height of 'region' are taken into account,
// the left and right are ignored.
void
scrollImage
(
int
lines
,
const
QRect
&
screenWindowRegion
);
void
scrollImage
(
int
lines
,
const
QRect
&
screenWindowRegion
,
Character
*
image
,
int
imageSize
);
Enum
::
ScrollBarPositionEnum
scrollBarPosition
()
const
{
return
_scrollbarLocation
;
}
/**
* Return the higlight line control
*/
HighlightScrolledLines
&
highlightScrolledLines
()
{
return
_highlightScrolledLines
;
}
public
Q_SLOTS
:
void
scrollBarPositionChanged
(
int
value
);
void
highlightScrolledLinesEvent
();
private:
TerminalDisplay
*
_display
;
bool
_scrollFullPage
;
bool
_alternateScrolling
;
Enum
::
ScrollBarPositionEnum
_scrollbarLocation
;
HighlightScrolledLines
_highlightScrolledLines
;
};
}
}
// namespace Konsole
#endif
src/terminalDisplay/extras/HighlightScrolledLines.cpp
0 → 100644
View file @
9433d17a
/*
SPDX-FileCopyrightText: 2020-2020 Carlos Alves <cbcalves@gmail.com>
SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com>
SPDX-FileCopyrightText: 1997, 1998 Lars Doelle <lars.doelle@on-line.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
// Own
#include "HighlightScrolledLines.h"
// Konsole
#include "../TerminalScrollBar.h"
namespace
Konsole
{
HighlightScrolledLines
::
HighlightScrolledLines
()