basic functionality for the Dialog

This commit is contained in:
Marco Martin 2012-01-09 16:51:01 +01:00
parent 2d19601715
commit 646f66b90c
2 changed files with 109 additions and 30 deletions

View File

@ -91,6 +91,9 @@ FullScreenDialog::FullScreenDialog(QDeclarativeItem *parent)
QDeclarativeContext *creationContext = component->creationContext();
m_rootObject = component->create(creationContext);
if (component->status() == QDeclarativeComponent::Error) {
kWarning()<<component->errors();
}
if (m_rootObject) {
setMainItem(qobject_cast<QGraphicsObject *>(m_rootObject.data()));

View File

@ -64,58 +64,69 @@ Item {
function open()
{
var pos = dialog.popupPosition(null, Qt.alignCenter)
dialog.x = pos.x
dialog.y = pos.y
dialog.visible = true
dialog.activateWindow()
dialog.state = ""
}
function accept()
{
if (status == DialogStatus.Open) {
dialog.visible = false
status = DialogStatus.Closing
accepted()
dialog.state = "closed"
}
}
function reject() {
function reject()
{
if (status == DialogStatus.Open) {
dialog.visible = false
status = DialogStatus.Closing
dialog.state = "closed"
rejected()
}
}
function close() {
dialog.visible = false
function close()
{
dialog.state = "closed"
}
visible: false
PlasmaCore.Dialog {
id: dialog
windowFlags: Qt.Dialog
//onFaderClicked: root.clickedOutside()
property Item rootItem
//state: "Hidden"
visible: false
onVisibleChanged: {
if (visible) {
status = DialogStatus.Open
} else {
status = DialogStatus.Closed
}
Rectangle {
id: fader
property double alpha: 0
color: Qt.rgba(0.0, 0.0, 0.0, alpha)
anchors.fill: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
clickedOutside()
close()
}
onActiveWindowChanged: if (!activeWindow) dialog.visible = false
}
mainItem: Item {
PlasmaCore.FrameSvgItem {
id: dialog
width: mainItem.width + margins.left + margins.right
height: mainItem.height + margins.top + margins.bottom
anchors.centerIn: parent
imagePath: "dialogs/background"
state: "closed"
transform: Translate {
id: dialogTransform
y: root.height - dialog.y
}
//state: "Hidden"
Item {
id: mainItem
x: dialog.margins.left
y: dialog.margins.top
width: theme.defaultFont.mSize.width * 40
height: titleBar.childrenRect.height + contentItem.childrenRect.height + buttonItem.childrenRect.height + 8
// Consume all key events that are not processed by children
Keys.onPressed: event.accepted = true
Keys.onReleased: event.accepted = true
@ -160,5 +171,70 @@ Item {
Component.onCompleted: {
rootItem = Utils.rootObject()
}
states: [
State {
name: "closed"
PropertyChanges {
target: dialogTransform
y: root.height - dialog.y
}
PropertyChanges {
target: fader
alpha: 0
}
},
State {
name: ""
PropertyChanges {
target: dialogTransform
y: 0
}
PropertyChanges {
target: fader
alpha: 0.6
}
}
]
transitions: [
// Transition between open and closed states.
Transition {
from: ""
to: "closed"
reversible: false
SequentialAnimation {
ScriptAction {
script: root.status = DialogStatus.Closing
}
PropertyAnimation {
properties: "y, alpha"
easing.type: Easing.InOutQuad
duration: 2250
}
ScriptAction {
script: root.status = DialogStatus.Closed
}
}
},
Transition {
from: "closed"
to: ""
reversible: false
SequentialAnimation {
ScriptAction {
script: root.status = DialogStatus.Opening
}
PropertyAnimation {
properties: "y, alpha"
easing.type: Easing.InOutQuad
duration: 2250
}
ScriptAction {
script: root.status = DialogStatus.Open
}
}
}
]
}
}