Console.qml 2.31 KB
Newer Older
1 2
import QtQuick 2.2
import QtQuick.Dialogs 1.0
3
import org.kde.analitza 1.0
4
import org.kde.kalgebra.mobile 1.0
5
import widgets 1.0
6

7
KAlgebraPage
8
{
9
    id: page
10
    ListModel { id: itemModel }
11

12 13 14 15 16
    ConsoleModel {
        id: consoleModel
//         variables: app.variables
        mode: ConsoleModel.Evaluate
        onErrorMessage: {
17
            itemModel.insert(0, { result: error })
18 19 20 21 22 23 24 25
            input.selectAll()
            view.currentIndex = 0
        }
        onOperationSuccessfulString: {
            itemModel.insert(0, { result: expression + "=" + result })
            input.selectAll()
            view.currentIndex = 0
        }
26 27 28 29 30 31 32 33 34 35
    }

    FileDialog {
        id: fileDialog
        folder: shortcuts.home
        onAccepted: proceed()

        property var proceed
    }

36
    function proceedLoadScript() {
37
        consoleModel.loadScript(fileDialog.fileUrl)
38
    }
39 40 41 42 43 44

    contextualActions: [
        Action {
            text: i18n("Load Script...")
            onTriggered: {
                fileDialog.title = text
45
                fileDialog.proceed = page.proceedLoadScript
46 47 48 49 50 51 52 53 54 55 56 57 58
                var v = fileDialog.open()
                console.log("opened...", v)
            }
        },
        Action {
            text: i18n("Save Script...")
        },
        //TODO: Recent scripts
        Action {
            text: i18n("Export Log...")
        },
        // --
        Action {
59 60
            text: consoleModel.mode == ConsoleModel.Calculate ? i18n("Evaluate...") : i18n("Calculate...")
            onTriggered: consoleModel.mode = !consoleModel.mode
61 62 63 64 65 66 67 68
        },
        // --
        Action {
            iconName: "edit-clear-history"
            text: i18n("Clear Log")
            onTriggered: itemModel.clear()
        }
    ]
69 70 71 72 73 74
    
    ExpressionInput {
        id: input
        focus: true
        
        Keys.onReturnPressed: {
75
            consoleModel.addOperation(text)
76 77
        }
        
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
78 79 80 81
        anchors {
            top: parent.top
            left: parent.left
            right: parent.right
82
            margins: page.dp*6
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
83
        }
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
    }
    
    SimpleListView {
        id: view
        model: itemModel
        role: "result"
        title: "Results"
        
        anchors {
            top: input.bottom
            bottom: parent.bottom
            left: parent.left
            right: parent.right
        }
    }
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
99
}