0

试图在相机和图像之间切换视图,但结果很奇怪

工具栏测试.qml

import QtQuick 2.0

Item{
    id:root
    height: 800; width: 144

    signal fullScreen()
    signal camera()
    signal photo()

    Column{
        id: toolBarColumn

        anchors.fill: root
        spacing: 10

        Rectangle{

            width: 144
            height: 70
            color: "blue"

            Text{
                text: "fullScreen"
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    fullScreen()
                }
            }
        }

        Rectangle{

            width: 144
            height: 70
            color: "blue"

            Text{
                text: "camera"
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    camera()
                }
            }
        }

        Rectangle{

            width: 144
            height: 70
            color: "blue"

            Text{
                text: "photo"
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    photo()
                }
            }
        }
    }
}

PhotoTest.qml

import QtQuick 2.0
import QtMultimedia 5.0


Rectangle{
    id: root

    width: 480
    height: 320
    color: "black"
    state: "PHOTO"

    property alias source: largeImage.source

    property var theID: largeImage

    QtObject{
        id: param

        property var theID: largeImage
    }

    Image{
        id : largeImage
        anchors.fill: parent
        cache: false
        fillMode: Image.PreserveAspectFit
        smooth: true
    }

    Camera{
        id: camera
    }

    VideoOutput {
        id: videoOutput

        anchors.fill: parent
        source: camera
    }

    states:[
        State {
            name: "PHOTO"
            StateChangeScript{
                script:{
                    camera.stop()
                    param.theID = largeImage
                }
            }

            PropertyChanges { target: largeImage; opacity: 1}
            PropertyChanges { target: videoOutput; opacity: 0}
        },
        State {
            name: "CAMERA"
            StateChangeScript{
                script:{
                    camera.captureMode = Camera.CaptureStillImage
                    camera.start()
                    param.theID = videoOutput
                }
            }

            PropertyChanges {target: largeImage; opacity: 0}
            PropertyChanges { target: videoOutput; opacity: 1}
        }
    ]
}

main.qml

import QtQuick 2.0

Rectangle {
    id: root

    width: 800
    height: 480

    QtObject{
        id: param

        property string previousFullScreenState
    }

    ToolBarTest{
        id: toolBarTest

        onFullScreen: {
            param.previousFullScreenState = root.state
            root.state = "FULLSCREEN"
        }

        onPhoto: {
            root.state = "PHOTO"
        }

        onCamera: {
            root.state = "CAMERA"
        }
    }

    PhotoTest{
        id: photoTest

        anchors.left: toolBarTest.right
        width: parent.width - toolBarTest.width

        source: "/Users/yyyy/Downloads/1359170070532.jpg"

        MouseArea{
            anchors.fill: parent

            onClicked: {
                if(root.state == "FULLSCREEN"){
                    root.state = param.previousFullScreenState
                }
            }
        }
    }

    states: [
        State {
            name: "PHOTO"

            PropertyChanges { target: photoTest; state: "PHOTO"}
            PropertyChanges { target: toolBarTest; width: 144}
        },
        State {
            name: "CAMERA"

            PropertyChanges { target: photoTest; state: "CAMERA"}
            PropertyChanges { target: toolBarTest; width: 144}
        },
        State {
            name: "FULLSCREEN"

            PropertyChanges { target: toolBarTest; width: 0}
        }
    ]
}

一旦状态为“CAMERA”,我单击“fullScreen”按钮 photoTest.qml 不显示相机的全尺寸,而是显示照片的全尺寸,发生了什么?我会犯什么样的错误?

Qt 版本:5.1Beta 操作系统:mac osx 10.8.3 编译器:clang 3.2

4

1 回答 1

0

我在 main.qml 中明确指定“FULLSCREEN”的状态为

State {
            name: "FULLSCREEN"

            PropertyChanges { target: photoTest; state: param.fullScreenPreviousState == "PHOTO" ? "PHOTO" : "CAMERA"} //new conditon
            PropertyChanges { target: toolBarTest; width: 0}
        }

我们必须在改变状态时明确指定不同组件的所有条件?

于 2013-06-09T22:17:24.303 回答