C++ 入門指南 4.01

encryptor_demo/main.qml

import QtQuick
import QtQuick.Controls

import io.qt.examples.encryptcontroller 1.0

ApplicationWindow {
    id: root
    width: 350
    height: 120
    visible: true

    title: qsTr("編密碼小工具")

    EncryptController {
        id: controller
    }

    Column {
        Row {
            width: 350
            height: 25

            Text {
                width: 50
                horizontalAlignment: Text.AlignRight
                text: qsTr("輸入:")
            }

            TextField {
                id: input
                width: 300
                color: "blue"
                placeholderText: qsTr("輸入英文句子")
                text: controller.userInput

                onEditingFinished: controller.userInput = text
            }
        }

        Row {
            width: 350
            height: 25

            Text {
                width: 50
                horizontalAlignment: Text.AlignRight
                text: qsTr("輸出:")
            }

            TextField {
                id: output
                width: 300
                color: "red"
                placeholderText: qsTr("這裡顯示編碼結果")
                readOnly: true
                text: ""
            }
        }

        Row {
            width: 350
            height: 35

            Button {
                id: newButton
                width: 50
                text: "新建"
                onClicked: {
                    controller.setEncryptObject()
                    display.text = controller.getEncryptObject()
                }
            }

            Button {
                width: 50
                text: "存檔"
                onClicked: {
                    controller.save();
                    display.text = "已存檔"
                }
            }

            Button {
                width: 50
                text: "載入"
                onClicked: {
                    if (controller.load()) {
                        display.text = "已載入"
                    }
                    else {
                        display.text = "無法載入"
                    }
                }
            }

            Button {
                width: 50
                text: "編碼"
                onClicked: {
                    controller.encodeFunction()
                    output.text = controller.getEncodeResult()
                    display.text = "編碼結果如上"
                }
            }

            Button {
                width: 50
                text: "解碼"
                onClicked: {
                    controller.decodeFunction()
                    output.text = controller.getDecodeResult()
                    display.text = "解碼結果如上"
                }
            }

            Button {
                width: 50
                text: "清除"
                onClicked: {
                    input.text = ""
                    output.text = ""
                    controller.clear()
                    display.text = "已清除"
                }
            }

            Button {
                width: 50
                text: "拷貝"
                onClicked: {
                    controller.copy()
                    display.text = "已拷貝到系統剪貼簿"
                }
            }
        }

        Row {
            width: 350
            height: 50
            Text {
                id: display
                width: 350
                text: "提示訊息"
            }
        }
    }
}

/* 《程式語言教學誌》的範例程式
   http://kaiching.org/
   檔名:main.qml
   功能:示範完整功能的 Encrypt GUI 應用程式
   作者:張凱慶 */

相關教學影片

上一頁 範例程式篇 encryptor_gui_demo/main.qml
回 C++ 入門指南 4.01 目錄
下一頁 範例程式篇 encryptcontroller.h
回 C++ 教材
回程式語言教材首頁