MauiKit Terminal

TerminalScrollBar.qml
1import QtQuick 2.14
2import org.mauikit.controls 1.3 as Maui
3import org.mauikit.terminal 1.0 as Term
4import QtQuick.Controls 2.14
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 if (!terminal) return;
35 if (updating) return;
36 updating = true;
37 terminal.scrollbarCurrentValue = contentY * terminal.scrollbarMaximum / (contentHeight - height);
38 updating = false;
39 }
40
41 function updateFromTerminal() {
42 if (!terminal) return;
43 if (updating) return;
44
45 updating = true;
46 contentHeight = height * terminal.totalLines / terminal.lines;
47 contentY = (contentHeight - height) * terminal.scrollbarCurrentValue / terminal.scrollbarMaximum;
48
49 // pretend to flick so that the scrollbar appears
50 flick(0.0, 0.0);
51 cancelFlick();
52 updating = false;
53 }
54
55 onContentYChanged: terminalProxyFlickable.updateTerminal()
56
57 Connections {
58 target: terminal
59 function onScrollbarMaximumChanged ()
60 {
61 terminalProxyFlickable.updateFromTerminal()
62 }
63
64 function onScrollbarCurrentValueChanged()
65 {
66 terminalProxyFlickable.updateFromTerminal()
67 }
68
69 function onTotalLinesChanged()
70 {
71 terminalProxyFlickable.updateFromTerminal()
72 }
73
74 function onLinesChanged()
75 {
76 terminalProxyFlickable.updateFromTerminal()
77 }
78 }
79
80 ScrollBar.vertical: ScrollBar
81 {
82 Maui.Theme.colorSet: Maui.Theme.Complementary // text color of terminal is also complementary
83 Maui.Theme.inherit: false
84
85 // parent: terminalProxyFlickable
86 width: visible ? implicitWidth : 0
87 x: control.width - width - Maui.Style.space.small
88 y: 0
89 policy: ScrollBar.AsNeeded
90 }
91 }
92
93
94}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Aug 30 2024 11:51:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.