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(); QDeclarativeContext *creationContext = component->creationContext();
m_rootObject = component->create(creationContext); m_rootObject = component->create(creationContext);
if (component->status() == QDeclarativeComponent::Error) {
kWarning()<<component->errors();
}
if (m_rootObject) { if (m_rootObject) {
setMainItem(qobject_cast<QGraphicsObject *>(m_rootObject.data())); setMainItem(qobject_cast<QGraphicsObject *>(m_rootObject.data()));

View File

@ -64,58 +64,69 @@ Item {
function open() function open()
{ {
var pos = dialog.popupPosition(null, Qt.alignCenter) dialog.state = ""
dialog.x = pos.x
dialog.y = pos.y
dialog.visible = true
dialog.activateWindow()
} }
function accept() function accept()
{ {
if (status == DialogStatus.Open) { if (status == DialogStatus.Open) {
dialog.visible = false status = DialogStatus.Closing
accepted() accepted()
dialog.state = "closed"
} }
} }
function reject() { function reject()
{
if (status == DialogStatus.Open) { if (status == DialogStatus.Open) {
dialog.visible = false status = DialogStatus.Closing
dialog.state = "closed"
rejected() rejected()
} }
} }
function close() { function close()
dialog.visible = false {
dialog.state = "closed"
} }
visible: false Rectangle {
id: fader
PlasmaCore.Dialog { property double alpha: 0
id: dialog color: Qt.rgba(0.0, 0.0, 0.0, alpha)
windowFlags: Qt.Dialog anchors.fill: parent
}
//onFaderClicked: root.clickedOutside() MouseArea {
property Item rootItem anchors.fill: parent
onClicked: {
//state: "Hidden" clickedOutside()
visible: false close()
onVisibleChanged: {
if (visible) {
status = DialogStatus.Open
} else {
status = DialogStatus.Closed
}
} }
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 id: mainItem
x: dialog.margins.left
y: dialog.margins.top
width: theme.defaultFont.mSize.width * 40 width: theme.defaultFont.mSize.width * 40
height: titleBar.childrenRect.height + contentItem.childrenRect.height + buttonItem.childrenRect.height + 8 height: titleBar.childrenRect.height + contentItem.childrenRect.height + buttonItem.childrenRect.height + 8
// Consume all key events that are not processed by children // Consume all key events that are not processed by children
Keys.onPressed: event.accepted = true Keys.onPressed: event.accepted = true
Keys.onReleased: event.accepted = true Keys.onReleased: event.accepted = true
@ -160,5 +171,70 @@ Item {
Component.onCompleted: { Component.onCompleted: {
rootItem = Utils.rootObject() 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
}
}
}
]
} }
} }