Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ViewsSelector.qml « qml « resources - github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 18d1f667595afde0ec3206ebf1a0492d4ab58ea8 (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
// Copyright (c) 2018 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.

import QtQuick 2.7
import QtQuick.Controls 2.3

import UM 1.2 as UM
import Cura 1.0 as Cura

Cura.ExpandablePopup
{
    id: viewSelector

    contentPadding: UM.Theme.getSize("default_lining").width
    contentAlignment: Cura.ExpandablePopup.ContentAlignment.AlignLeft

    property var viewModel: UM.ViewModel { }

    property var activeView:
    {
        for (var i = 0; i < viewModel.rowCount(); i++)
        {
            if (viewModel.items[i].active)
            {
                return viewModel.items[i]
            }
        }
        return null
    }

    Component.onCompleted:
    {
        // Nothing was active, so just return the first one (the list is sorted by priority, so the most
        // important one should be returned)
        if (activeView == null)
        {
            UM.Controller.setActiveView(viewModel.getItem(0).id)
        }
    }

    headerItem: Item
    {
        Label
        {
            id: title
            text: catalog.i18nc("@button", "View types")
            verticalAlignment: Text.AlignVCenter
            height: parent.height
            elide: Text.ElideRight
            font: UM.Theme.getFont("default")
            color: UM.Theme.getColor("text_medium")
            renderType: Text.NativeRendering
        }

        Label
        {
            text: viewSelector.activeView ? viewSelector.activeView.name : ""
            verticalAlignment: Text.AlignVCenter
            anchors
            {
                left: title.right
                leftMargin: UM.Theme.getSize("default_margin").width
            }
            height: parent.height
            elide: Text.ElideRight
            font: UM.Theme.getFont("default")
            color: UM.Theme.getColor("text")
            renderType: Text.NativeRendering
        }
    }

    contentItem: Column
    {
        id: viewSelectorPopup
        width: viewSelector.width - 2 * viewSelector.contentPadding

        // For some reason the height/width of the column gets set to 0 if this is not set...
        Component.onCompleted:
        {
            height = implicitHeight
            width = viewSelector.width - 2 * viewSelector.contentPadding
        }

        Repeater
        {
            id: viewsList
            model: viewSelector.viewModel

            delegate: Button
            {
                id: viewsSelectorButton
                text: model.name
                width: parent.width
                height: UM.Theme.getSize("action_button").height
                leftPadding: UM.Theme.getSize("default_margin").width
                rightPadding: UM.Theme.getSize("default_margin").width
                checkable: true
                checked: viewSelector.activeView != null ? viewSelector.activeView.id == id : false

                contentItem: Label
                {
                    id: buttonText
                    text: viewsSelectorButton.text
                    color: UM.Theme.getColor("text")
                    font: UM.Theme.getFont("action_button")
                    renderType: Text.NativeRendering
                    verticalAlignment: Text.AlignVCenter
                    elide: Text.ElideRight
                }

                background: Rectangle
                {
                    id: backgroundRect
                    color: viewsSelectorButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
                    radius: UM.Theme.getSize("action_button_radius").width
                    border.width: UM.Theme.getSize("default_lining").width
                    border.color: viewsSelectorButton.checked ? UM.Theme.getColor("primary") : "transparent"
                }

                onClicked:
                {
                    toggleContent()
                    UM.Controller.setActiveView(id)
                }
            }
        }
    }
}