MainBlock.qml 5.34 KB
Newer Older
Marco Martin's avatar
Marco Martin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/********************************************************************
 This file is part of the KDE project.

Copyright (C) 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/

Marco Martin's avatar
Marco Martin committed
20
import QtQuick 2.5
Marco Martin's avatar
Marco Martin committed
21 22 23 24 25 26 27 28 29 30 31 32
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.1
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.workspace.keyboardlayout 1.0
import "../components"

PlasmaCore.ColorScope {
    id: block
    colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
    anchors.fill: parent

Marco Martin's avatar
Marco Martin committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    Component.onCompleted: appearAnimation.running = true;

    SequentialAnimation {
        id: appearAnimation
        ParallelAnimation {
            YAnimator {
                target: topPanel
                from: -topPanel.height
                to: 0
                duration: units.longDuration
            }
            YAnimator {
                target: bottomPanel
                from: block.height
                to: block.height - bottomPanel.height
                duration: units.longDuration
            }
        }
        ScriptAction {
            script: {
                topPanel.anchors.top = block.top;
                bottomPanel.anchors.bottom = block.bottom;
            }
        }
    }
Marco Martin's avatar
Marco Martin committed
58
    Item {
Marco Martin's avatar
Marco Martin committed
59 60
        id: topPanel
        y: -height
Marco Martin's avatar
Marco Martin committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
        anchors {
            left: parent.left
            right: parent.right
        }

        height: infoPane.height + units.largeSpacing * 2

        Rectangle {
            anchors.fill: parent
            color: PlasmaCore.ColorScope.backgroundColor
            opacity: 0.8
        }
        InfoPane {
            id: infoPane
            anchors.centerIn: parent
        }
    }

    Item {
Marco Martin's avatar
Marco Martin committed
80
        id: bottomPanel
Marco Martin's avatar
Marco Martin committed
81 82 83 84 85
        height: mainLayout.height + units.largeSpacing * 2
        anchors {
            left: parent.left
            right: parent.right
        }
Marco Martin's avatar
Marco Martin committed
86
        y: parent.height
Marco Martin's avatar
Marco Martin committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
        Rectangle {
            anchors.fill: parent
            color: PlasmaCore.ColorScope.backgroundColor
            opacity: 0.8
        }
        function unlockFunction() {
            authenticator.tryUnlock(passwordInput.text);
        }

        ColumnLayout {
            id: mainLayout
            anchors {
                left: parent.left
                right: parent.right
                verticalCenter: parent.verticalCenter
            }
            spacing: units.largeSpacing
            RowLayout {
                anchors.horizontalCenter: parent.horizontalCenter


                PlasmaComponents.TextField {
                    id: passwordInput
                    placeholderText: i18nd("plasma_lookandfeel_org.kde.lookandfeel","Password")
                    echoMode: TextInput.Password
                    enabled: !authenticator.graceLocked
                    onAccepted: actionButton.clicked(null)
                    focus: false

                    onVisibleChanged: {
                        if (visible) {
                            forceActiveFocus();
                        }
                        text = "";
                    }
                    onTextChanged: {
                        if (text == "") {
                            clearTimer.stop();
                        } else {
                            clearTimer.restart();
                        }
                    }

                    Timer {
                        id: clearTimer
                        interval: 30000
                        repeat: false
                        onTriggered: {
                            passwordInput.text = "";
                        }
                    }
                }

                DialerIconButton { 
                    source: "edit-clear"
                    callback: function() {
                        if (passwordInput.text.length > 0) {
                            passwordInput.text = passwordInput.text.substr(0, passwordInput.text.length - 1);
                        }
                    }
                }

                Connections {
                    target: root
                    onClearPassword: {
                        passwordInput.selectAll();
                        passwordInput.forceActiveFocus();
                    }
                }
            }
            Dialer {
                id: dialer
                Layout.fillWidth: true
            }
            PlasmaComponents.Button {
                id: actionButton
                Layout.alignment: Qt.AlignHCenter
                Layout.minimumWidth: passwordInput.width
                text: i18n("Unlock")
                enabled: !authenticator.graceLocked
                onClicked: {
Marco Martin's avatar
Marco Martin committed
168
                    bottomPanel.unlockFunction();
Marco Martin's avatar
Marco Martin committed
169 170 171 172 173
                }
            }
        }
    }
}