summaryrefslogtreecommitdiff
path: root/kodereviewer/qml/ProjectListPage.qml
blob: b4e37de57697e7df0f6cc2596e9d8ff8bbab6fc1 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
pragma ComponentBehavior: Bound
import QtQuick 2.15 // Removing version break onCurrentItemChanged
import QtQuick.Layouts
import QtQuick.Controls as QQC2

import org.kde.kirigamiaddons.delegates as Delegates
import org.kde.kitemmodels 1 as KItemModels
import org.kde.kirigami as Kirigami

import org.deprecated.kodereviewer

Kirigami.ScrollablePage {
    id: root

    required property NetworkManager connection
    required property Project project
    signal pullRequestSelected(int pullRequest)

    readonly property int currentWidth: _private.currentWidth + 1

    onCurrentWidthChanged: pageStack.defaultColumnWidth = root.currentWidth
    Component.onCompleted: {
        pageStack.defaultColumnWidth = root.currentWidth
        connection.getPullRequests()
    }

    Kirigami.Theme.colorSet: Kirigami.Theme.View
    Kirigami.Theme.inherit: false

    PullRequestModel {
        id: pullRequestModel
        project: root.project
    }

    KItemModels.KSortFilterProxyModel {
        id: pullRequestFilterModel
        sourceModel: pullRequestModel
        filterRoleName: "title"
    }

    title: "Pull Requests"

    actions: [
        Kirigami.Action {
            id: refreshAction
            icon.name: "view-refresh"
            shortcut: Shortcut {
                sequence: "F5"
                onActivated: {
                    refreshAction.trigger()
                }
            }
            onTriggered: connection.getPullRequests()
        },
        Kirigami.Action {
            id: searchAction
            icon.name: "search"
            shortcut: Shortcut {
                sequence: "Ctrl+F"
                onActivated: {
                    print("Shortcut triggered")
                    searchAction.trigger()
                }
            }

            onTriggered: print("search triggered")
        }
    ]

    ListView {
        id: view
        model: pullRequestModel
        clip: true
        delegate: Delegates.RoundedItemDelegate {
            required property int number
            required property string title
            required property bool draft
            required property int index

            highlighted: ListView.isCurrentItem

            text: `${number} - ${title}`
            icon {
                name: "vcs-merge-request"
                color: draft ? Kirigami.Theme.disabledTextColor : Kirigami.Theme.positiveTextColor
            }

            onClicked: {
                view.currentIndex = index
                root.pullRequestSelected(number)
            }
        }
    }


    MouseArea {
        anchors.top: parent.top
        anchors.bottom: parent.bottom
        parent: applicationWindow().overlay.parent

        x: root.currentWidth - width / 2
        width: Kirigami.Units.smallSpacing * 2
        z: root.z + 1
        enabled: true
        visible: enabled
        cursorShape: Qt.SplitHCursor

        property int _lastX

        onPressed: mouse => {
            _lastX = mouse.x;
        }
        onPositionChanged: mouse => {
            if (_lastX == -1) {
                return;
            }
            if (mouse.x > _lastX) {
                // _private.currentWidth = _private.currentWidth + (_lastX + mouse.x);
                _private.currentWidth = Math.min(_private.maxWidth, _private.currentWidth + (mouse.x - _lastX))
            } else if (mouse.x < _lastX) {
                const tmpWidth = _private.currentWidth - (_lastX - mouse.x);
                if (tmpWidth > _private.minWidth)
                    _private.currentWidth = tmpWidth;

            }
        }
    }

    /*
     * Hold the modifiable currentWidth in a private object so that only internal
     * members can modify it.
     */
    QtObject {
        id: _private
        property int currentWidth: defaultWidth
        readonly property int defaultWidth: Kirigami.Units.gridUnit * 17
        readonly property int minWidth: Kirigami.Units.gridUnit * 2
        readonly property int maxWidth: Kirigami.Units.gridUnit * 25
    }

}