|
1 import Qt 4.7 |
|
2 |
|
3 Rectangle { |
|
4 property string text: "" |
|
5 property string defaultText: "" |
|
6 property bool cancelable: true |
|
7 property int size: 0 |
|
8 signal confirmed(string input); |
|
9 |
|
10 id: page |
|
11 opacity: 0 |
|
12 |
|
13 width: dialogText.width + 30 + size; height: dialogText.height + okButton.height + inputText.height + 44 |
|
14 anchors.verticalCenter: mainWindow.verticalCenter |
|
15 anchors.horizontalCenter: mainWindow.horizontalCenter |
|
16 |
|
17 border.width: 1; color: "lightgray"; radius: 5 |
|
18 |
|
19 Text { |
|
20 id: dialogText |
|
21 text: page.text |
|
22 x: 15; y: 15 |
|
23 color: activePalette.buttonText |
|
24 } |
|
25 |
|
26 Rectangle { |
|
27 id: inputArea |
|
28 width: page.width - 30 |
|
29 height: inputText.height + 4 |
|
30 border.width: 1; color: "white"; radius: 1 |
|
31 anchors.left: dialogText.left |
|
32 anchors.top: dialogText.bottom; anchors.topMargin: 7 |
|
33 } |
|
34 |
|
35 TextEdit { |
|
36 id: inputText |
|
37 text: page.defaultText |
|
38 width: inputArea.width - 10 |
|
39 anchors.verticalCenter: inputArea.verticalCenter |
|
40 anchors.horizontalCenter: inputArea.horizontalCenter |
|
41 } |
|
42 |
|
43 Button { |
|
44 id: okButton |
|
45 text: "Ok" |
|
46 width: 75; height: 25 |
|
47 anchors.top: inputArea.bottom; anchors.topMargin: 10 |
|
48 |
|
49 onClicked: { |
|
50 page.confirmed(inputText.text); |
|
51 forceClose(); |
|
52 } |
|
53 } |
|
54 |
|
55 Button { |
|
56 id: noButton |
|
57 text: "Cancel" |
|
58 width: 75; height: 25 |
|
59 anchors.left: page.horizontalCenter; anchors.leftMargin: 5 |
|
60 anchors.top: inputArea.bottom; anchors.topMargin: 10 |
|
61 |
|
62 onClicked: { |
|
63 forceClose(); |
|
64 } |
|
65 } |
|
66 |
|
67 function forceClose() |
|
68 { |
|
69 page.opacity = 0; |
|
70 inputText.text = ""; |
|
71 } |
|
72 |
|
73 Component.onCompleted: { |
|
74 if (cancelable == false) { |
|
75 noButton.opacity = 0; |
|
76 okButton.anchors.horizontalCenter = page.horizontalCenter; |
|
77 } else { |
|
78 okButton.anchors.right = page.horizontalCenter; |
|
79 okButton.anchors.rightMargin = 5; |
|
80 } |
|
81 |
|
82 } |
|
83 } |