summaryrefslogtreecommitdiffstats
path: root/tools/qqem/qml/FindBar.qml
blob: 4b7d32b2ac341555856912c4185c78b10bf67dea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

Rectangle {
    id: rootItem

    property bool show: false
    property bool stringNotFound: currentEditorComponent ? currentEditorComponent.stringNotFound : false

    function setFindString(findString) {
        findTextField.text = findString;
        findTextField.selectAll();
        findTextField.focus = true;
    }
    function findNext() {
        if (currentEditorComponent)
            currentEditorComponent.findNext(findTextField.text);
    }
    function findPrev() {
        if (currentEditorComponent)
            currentEditorComponent.findPrev(findTextField.text);
    }

    Layout.fillWidth: true
    height: 44
    visible: rootItem.show
    enabled: visible
    color: mainView.backgroundColor1

    RowLayout {
        id: findTextRow
        width: parent.width
        anchors.verticalCenter: parent.verticalCenter
        spacing: 5
        Item {
            width: 5
            height: 1
        }
        Text {
            font.pixelSize: 14
            color: mainView.foregroundColor2
            text: "Find:"
        }
        CustomTextField {
            id: findTextField
            Layout.fillWidth: true
            onAccepted: {
                findNext();
            }
            Item {
                id: stringNotFoundItem

                readonly property alias show: rootItem.stringNotFound
                property real showAnimated: show

                anchors.fill: parent
                anchors.margins: -1
                z: -1
                opacity: showAnimated
                visible: opacity > 0
                Rectangle {
                    anchors.fill: parent
                    color: "#dd4040"
                }
                Behavior on showAnimated {
                    NumberAnimation {
                        duration: 400
                        easing.type: Easing.InOutQuad
                    }
                }
            }
        }
        Button {
            id: findPrevButton
            Layout.preferredHeight: 40
            text: "Previous"
            onClicked: {
                findPrev();
            }
            Action {
                shortcut: StandardKey.FindPrevious
                enabled: rootItem.show
                onTriggered: {
                    findPrev();
                }
            }
        }
        Button {
            id: findNextButton
            Layout.preferredHeight: 40
            text: "Next"
            onClicked: {
                findNext();
            }
            Action {
                shortcut: StandardKey.FindNext
                enabled: rootItem.show
                onTriggered: {
                    findNext();
                }
            }
        }
        CustomIconButton {
            height: 22
            width: height
            icon: "images/icon_remove_shadow.png"
            onClicked: {
                mainView.showFindBar = false;
            }
        }
        Item {
            width: 1
            height: 1
        }
    }
}