summaryrefslogtreecommitdiffstats
path: root/editorlib/qml/CameraEntityDelegate.qml
blob: d08e758b594559570b2070b23c9d23fbaa077494 (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt3D Editor of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.5
import com.theqtcompany.SceneEditor3D 1.0
import QtQuick.Controls 2.0 as QQC2
import Qt3D.Core 2.0
import Qt3D.Render 2.0

ComponentDelegate {
    id: thisDelegate
    componentType: EditorSceneItemComponentsModel.CameraEntity
    title: qsTr("Camera") + editorScene.emptyString

    viewTitleVisible: editorContent.cameraViewVisible

    onChangeViewVisibity: {
        editorContent.cameraViewVisible = viewVisibility
    }

    Component.onCompleted: {
        if (!editorContent.cameraViewVisible)
            height = minimumComponentHeight
    }

    // Need this separate connection as any checked property binding will not persist
    // over user clicking on the radio buttons.
    Connections {
        target: componentData
        onProjectionTypeChanged: {
            if (componentData.projectionType === CameraLens.OrthographicProjection)
                orthoButton.checked = true
            else
                perspectiveButton.checked = true
        }
    }

    function changeProjectionType(newValue) {
        var oldValue = componentData.projectionType;
        if (oldValue !== newValue) {
            editorScene.undoHandler.createChangePropertyCommand(
                        editorContent.selectedEntityName, componentType,
                        "projectionType", newValue, oldValue, true);
        }
    }

    Column {
        spacing: 4
        width: parent.width

        QQC2.GroupBox {
            id: groupBoxControl
            title: qsTr("Projection Type") + editorScene.emptyString

            label: Text {
                width: groupBoxControl.availableWidth
                text: groupBoxControl.title
                color: enabled ? editorContent.textColor : editorContent.disabledTextColor
                font.family: editorContent.labelFontFamily
                font.weight: editorContent.labelFontWeight
                font.pixelSize: editorContent.labelFontPixelSize
                elide: Text.ElideRight
                horizontalAlignment: Text.AlignLeft
                verticalAlignment: Text.AlignVCenter
            }

            Row {
                StyledRadioButton {
                    id: orthoButton
                    checked: componentData.projectionType === CameraLens.OrthographicProjection
                    onCheckedChanged: {
                        if (checked)
                            changeProjectionType(CameraLens.OrthographicProjection)
                    }
                }
                Rectangle {
                    color: "transparent"
                    width: orthoLabel.width
                    height: orthoButton.height
                    StyledLabel {
                        id: orthoLabel
                        anchors.verticalCenter: parent.verticalCenter
                        text: qsTr("Orthographic") + editorScene.emptyString
                        tooltip: qsTr("Use orthographic projection, i.e. camera\nwith no perspective correction.")
                                 + editorScene.emptyString
                    }
                }
                StyledRadioButton {
                    id: perspectiveButton
                    checked: componentData.projectionType === CameraLens.PerspectiveProjection
                    onCheckedChanged: {
                        if (checked)
                            changeProjectionType(CameraLens.PerspectiveProjection)
                    }
                }
                Rectangle {
                    color: "transparent"
                    width: perspectiveLabel.width
                    height: perspectiveButton.height
                    StyledLabel {
                        id: perspectiveLabel
                        anchors.verticalCenter: parent.verticalCenter
                        text: qsTr("Perspective") + editorScene.emptyString
                        tooltip: qsTr("Use perspective projection, i.e. camera with\nperspective correction based on field-of-view.")
                                 + editorScene.emptyString
                    }
                }
            }
        }

        FloatPropertyInputField {
            id: nearPlaneField
            label: qsTr("Near Plane") + editorScene.emptyString
            propertyName: "nearPlane"
            minimum: 0.01
            roundDigits: 2
            step: 1 // = 0.01 (because roundDigits is 2)
            component: componentData
            componentType: thisDelegate.componentType
            tooltip: qsTr("Near plane of the camera, i.e. objects closer\nto the camera than this will be cropped.")
                     + editorScene.emptyString
        }

        FloatPropertyInputField {
            id: farPlaneField
            label: qsTr("Far Plane") + editorScene.emptyString
            propertyName: "farPlane"
            minimum: nearPlaneField.fieldValue
            roundDigits: 2
            component: componentData
            componentType: thisDelegate.componentType
            tooltip: qsTr("Far plane of the camera, i.e. objects further\naway from the camera than this will be cropped.")
                     + editorScene.emptyString
        }

        FloatSliderPropertyInputField {
            id: fieldOfViewField
            visible: componentData.projectionType === CameraLens.PerspectiveProjection
            label: qsTr("Field of View") + editorScene.emptyString
            propertyName: "fieldOfView"
            component: componentData
            componentType: thisDelegate.componentType
            minimum: 0
            maximum: 180
            stepSize: 1
            tooltip: qsTr("Field of view (FOV) of the camera.") + editorScene.emptyString
        }

        FloatPropertyInputField {
            id: aspectRatioField
            visible: componentData.projectionType === CameraLens.PerspectiveProjection
            label: qsTr("Aspect Ratio") + editorScene.emptyString
            propertyName: "aspectRatio"
            minimum: 0.1
            roundDigits: 3
            step: 10 // = 0.01 (because roundDigits is 3)
            component: componentData
            componentType: thisDelegate.componentType
            tooltip: qsTr("Aspect ratio, i.e. width to height\nratio of the intended view.")
                     + editorScene.emptyString
        }

        FloatPropertyInputField {
            id: leftField
            label: qsTr("Left") + editorScene.emptyString
            visible: componentData.projectionType === CameraLens.OrthographicProjection
            propertyName: "left"
            component: componentData
            componentType: thisDelegate.componentType
            tooltip: qsTr("Left limit of the view.") + editorScene.emptyString
        }

        FloatPropertyInputField {
            id: rightField
            label: qsTr("Right") + editorScene.emptyString
            visible: componentData.projectionType === CameraLens.OrthographicProjection
            propertyName: "right"
            component: componentData
            componentType: thisDelegate.componentType
            tooltip: qsTr("Right limit of the view.") + editorScene.emptyString
        }

        FloatPropertyInputField {
            id: bottomField
            label: qsTr("Bottom") + editorScene.emptyString
            visible: componentData.projectionType === CameraLens.OrthographicProjection
            propertyName: "bottom"
            component: componentData
            componentType: thisDelegate.componentType
            tooltip: qsTr("Bottom limit of the view.") + editorScene.emptyString
        }

        FloatPropertyInputField {
            id: topField
            label: qsTr("Top") + editorScene.emptyString
            visible: componentData.projectionType === CameraLens.OrthographicProjection
            propertyName: "top"
            component: componentData
            componentType: thisDelegate.componentType
            tooltip: qsTr("Top limit of the view.") + editorScene.emptyString
        }

        Vector3DPropertyInputField {
            id: positionVectorField
            label: qsTr("Position") + editorScene.emptyString
            propertyName: "position"
            component: componentData
            componentType: thisDelegate.componentType
            tooltip: qsTr("Position of the camera\non the %1 axis.") // Needs arg, as it will be replaced in the vector3dinpufield
            tooltipArgs: ["X", "Y", "Z"]
        }

        Vector3DPropertyInputField {
            id: upVectorField
            label: qsTr("Up") + editorScene.emptyString
            propertyName: "upVector"
            component: componentData
            componentType: thisDelegate.componentType
            // TODO: Need to block (0,0,0) value for upvector somehow, it crashes the camera
            tooltip: qsTr("Which way is up for the camera.%1") // Needs arg, as it will be replaced in the vector3dinpufield
        }

        Vector3DPropertyInputField {
            id: viewCenterVectorField
            label: qsTr("View Center") + editorScene.emptyString
            propertyName: "viewCenter"
            component: componentData
            componentType: thisDelegate.componentType
            tooltip: qsTr("The point the camera is\nfacing on the %1 axis.") // Needs arg, as it will be replaced in the vector3dinpufield
            tooltipArgs: ["X", "Y", "Z"]
        }
    }
}