Skip to content

Commit e3ffc6d

Browse files
committed
Add Question component
1 parent 39d12ef commit e3ffc6d

File tree

3 files changed

+183
-0
lines changed

3 files changed

+183
-0
lines changed

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ qt_add_qml_module(scratchcpp-render
1313
internal/MonitorSlider.qml
1414
internal/ListMonitor.qml
1515
internal/TextBubble.qml
16+
internal/Question.qml
1617
shaders/sprite.vert
1718
shaders/sprite.frag
19+
icons/enter.svg
1820
SOURCES
1921
global.h
2022
projectloader.cpp

src/icons/enter.svg

Lines changed: 81 additions & 0 deletions
Loading

src/internal/Question.qml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// SPDX-License-Identifier: LGPL-3.0-or-later
2+
3+
import QtQuick
4+
import QtQuick.Controls
5+
6+
Rectangle {
7+
id: root
8+
property string question: ""
9+
readonly property alias answer: textField.text
10+
signal closed()
11+
12+
QtObject {
13+
id: priv
14+
readonly property int margin: 18
15+
readonly property int spacing: 6
16+
}
17+
18+
color: "white"
19+
border.color: Qt.rgba(0.85, 0.85, 0.85, 1)
20+
border.width: 2
21+
radius: 9
22+
implicitHeight: labelLoader.height + textField.height + 2 * priv.margin + priv.spacing
23+
onActiveFocusChanged: {
24+
if(activeFocus)
25+
textField.forceActiveFocus();
26+
}
27+
28+
function clear() {
29+
textField.clear();
30+
question = "";
31+
}
32+
33+
Loader {
34+
id: labelLoader
35+
anchors.left: parent.left
36+
anchors.right: parent.right
37+
anchors.top: parent.top
38+
anchors.leftMargin: priv.margin
39+
anchors.topMargin: priv.margin
40+
anchors.rightMargin: priv.margin
41+
active: root.question !== ""
42+
43+
sourceComponent: Text {
44+
text: root.question
45+
color: "#575E75"
46+
font.family: "Helvetica"
47+
font.pointSize: 9
48+
font.bold: true
49+
}
50+
}
51+
52+
TextField {
53+
id: textField
54+
anchors.left: parent.left
55+
anchors.right: parent.right
56+
anchors.top: labelLoader.bottom
57+
anchors.leftMargin: priv.margin - leftInset
58+
anchors.topMargin: priv.spacing - topInset
59+
anchors.rightMargin: priv.margin - rightInset
60+
anchors.bottomMargin: priv.margin - bottomInset
61+
color: "#575E75"
62+
font.family: "Helvetica"
63+
font.pointSize: 8
64+
leftInset: 5
65+
topInset: 0
66+
rightInset: 0
67+
bottomInset: 0
68+
padding: 0
69+
Keys.onReturnPressed: closed()
70+
Keys.onEnterPressed: closed()
71+
72+
background: Rectangle {
73+
color: root.color
74+
border.color: root.border.color
75+
radius: height / 2
76+
implicitHeight: 30
77+
}
78+
79+
Rectangle {
80+
anchors.right: parent.right
81+
anchors.top: parent.top
82+
anchors.rightMargin: 4
83+
anchors.topMargin: 3.5
84+
color: "#4D97FF"
85+
width: 25
86+
height: 25
87+
radius: width / 2
88+
89+
Image {
90+
anchors.fill: parent
91+
source: "qrc:/qt/qml/ScratchCPP/Render/icons/enter.svg"
92+
93+
MouseArea {
94+
anchors.fill: parent
95+
onClicked: closed()
96+
}
97+
}
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)