MauiKit Terminal

TerminalScrollBar.qml
1import QtQuick
2import org.mauikit.controls as Maui
3import org.mauikit.terminal as Term
4import QtQuick.Controls
5
6Item
7{
8 id: control
9 property Term.QMLTermWidget terminal
10 onTerminalChanged: terminalProxyFlickable.updateFromTerminal()
11
12 property int highlightLine : -1
13
14 Flickable
15 {
16 id: terminalProxyFlickable
17 anchors.fill: parent
18 // enabled: false
19 interactive: false
20
21 Rectangle
22 {
23 width: parent.width
24 height: kterminal.fontHeight()
25 color: Maui.Theme.highlightColor
26 opacity: 0.2
27 y: Math.floor(height * control.highlightLine)
28 visible: control.highlightLine > -1
29 }
30
31 property bool updating: false
32
33 function updateTerminal()
34 {
35 if (!terminal) return;
36 if (updating) return;
37 updating = true;
38 terminal.scrollbarCurrentValue = contentY * terminal.scrollbarMaximum / (contentHeight - height);
39 updating = false;
40 }
41
42 function updateFromTerminal()
43 {
44 if (!terminal) return;
45 if (updating) return;
46
47 updating = true;
48 contentHeight = height * terminal.totalLines / terminal.lines;
49 contentY = (contentHeight - height) * terminal.scrollbarCurrentValue / terminal.scrollbarMaximum;
50
51 // pretend to flick so that the scrollbar appears
52 flick(0.0, 0.0);
53 cancelFlick();
54 updating = false;
55 }
56
57 onContentYChanged: terminalProxyFlickable.updateTerminal()
58
59 Connections
60 {
61 target: terminal
62 function onScrollbarMaximumChanged ()
63 {
64 terminalProxyFlickable.updateFromTerminal()
65 }
66
67 function onScrollbarCurrentValueChanged()
68 {
69 terminalProxyFlickable.updateFromTerminal()
70 }
71
72 function onTotalLinesChanged()
73 {
74 terminalProxyFlickable.updateFromTerminal()
75 }
76
77 function onLinesChanged()
78 {
79 terminalProxyFlickable.updateFromTerminal()
80 }
81 }
82
83 ScrollBar.vertical: ScrollBar
84 {
85 Maui.Theme.colorSet: Maui.Theme.Complementary // text color of terminal is also complementary
86 Maui.Theme.inherit: false
87
88 // parent: terminalProxyFlickable
89 width: visible ? implicitWidth : 0
90 x: control.width - width - Maui.Style.space.small
91 y: 0
92 policy: ScrollBar.AsNeeded
93 }
94 }
95}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:00:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.