Output.qml 8.62 KB
Newer Older
Daniel Vrátil's avatar
Daniel Vrátil committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
    Copyright (C) 2012  Dan Vratil <dvratil@redhat.com>

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

    This library 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

19
import QtQuick 2.1
20
import QtGraphicalEffects 1.0
21
import org.kde.kscreen 1.0
Daniel Vrátil's avatar
Daniel Vrátil committed
22 23 24

QMLOutput {

Daniel Vrátil's avatar
Daniel Vrátil committed
25 26
    id: root;

27
    signal clicked();
Daniel Vrátil's avatar
Daniel Vrátil committed
28
    signal primaryTriggered(string self);
29
    signal enabledToggled(string self);
30 31
    signal mousePressed();
    signal mouseReleased();
Daniel Vrátil's avatar
Daniel Vrátil committed
32

33
    property bool isDragged: monitorMouseArea.drag.active;
34
    property bool isDragEnabled: true;
Daniel Vrátil's avatar
Daniel Vrátil committed
35
    property bool isToggleButtonVisible: false;
36
    property bool hasMoved: false;
Daniel Vrátil's avatar
Daniel Vrátil committed
37 38 39 40 41 42 43

    width: monitorMouseArea.width;
    height: monitorMouseArea.height;

    visible: (opacity > 0);
    opacity: output.connected ? 1.0 : 0.0;

44

45 46 47 48
    Component.onCompleted: {
        root.updateRootProperties();
    }

Daniel Vrátil's avatar
Daniel Vrátil committed
49 50 51 52 53 54 55 56 57
    SystemPalette {

        id: palette;
    }

    MouseArea {

        id: monitorMouseArea;

58 59
        width: root.currentOutputWidth * screen.outputScale;
        height: root.currentOutputHeight * screen.outputScale
60 61 62 63

        anchors.centerIn: parent;

        opacity: root.output.enabled ? 1.0 : 0.5;
Daniel Vrátil's avatar
Daniel Vrátil committed
64 65
        transformOrigin: Item.Center;
        rotation: {
Laurent Montel's avatar
Laurent Montel committed
66
            if (output.rotation === KScreenOutput.None) {
67
                return 0;
Laurent Montel's avatar
Laurent Montel committed
68
            } else if (output.rotation === KScreenOutput.Left) {
69
                return 270;
Laurent Montel's avatar
Laurent Montel committed
70
            } else if (output.rotation === KScreenOutput.Inverted) {
Daniel Vrátil's avatar
Daniel Vrátil committed
71 72
                return 180;
            } else {
73
                return 90;
Daniel Vrátil's avatar
Daniel Vrátil committed
74 75 76
            }
        }

77
        hoverEnabled: true;
78
        preventStealing: true;
79

Daniel Vrátil's avatar
Daniel Vrátil committed
80
        drag {
Daniel Vrátil's avatar
Daniel Vrátil committed
81
            target: root.isDragEnabled && !root.isCloneMode ? root : null;
Daniel Vrátil's avatar
Daniel Vrátil committed
82 83
            axis: Drag.XandYAxis;
            minimumX: 0;
84
            maximumX: screen.maxScreenSize.width - root.width;
Daniel Vrátil's avatar
Daniel Vrátil committed
85
            minimumY: 0;
86
            maximumY: screen.maxScreenSize.height - root.height;
Daniel Vrátil's avatar
Daniel Vrátil committed
87 88 89 90 91 92 93 94 95 96 97 98 99
            filterChildren: false;
        }

        drag.onActiveChanged: {
            /* If the drag is shorter then the animation then make sure
             * we won't end up in an inconsistent state */
            if (dragActiveChangedAnimation.running) {
                dragActiveChangedAnimation.complete();
            }

            dragActiveChangedAnimation.running = true;
        }

100
        onPressed: root.clicked();
Daniel Vrátil's avatar
Daniel Vrátil committed
101

Daniel Vrátil's avatar
Daniel Vrátil committed
102 103 104 105
        /* FIXME: This could be in 'Behavior', but MouseArea had
         * some complaints...to tired to investigate */
        PropertyAnimation {
            id: dragActiveChangedAnimation;
106

Daniel Vrátil's avatar
Daniel Vrátil committed
107 108 109 110 111 112 113 114
            target: monitor;
            property: "opacity";
            from: monitorMouseArea.drag.active ? 0.7 : 1.0
            to: monitorMouseArea.drag.active ? 1.0 : 0.7
            duration: 100;
            easing.type: "OutCubic";
        }

115
        Behavior on opacity {
Daniel Vrátil's avatar
Daniel Vrátil committed
116
            PropertyAnimation {
117 118 119
                property: "opacity";
                easing.type: "OutCubic";
                duration: 250;
Daniel Vrátil's avatar
Daniel Vrátil committed
120 121 122 123 124 125 126
            }
        }

        Behavior on rotation {
            RotationAnimation {
                easing.type: "OutCubic"
                duration: 250;
Daniel Vrátil's avatar
Daniel Vrátil committed
127
                direction: RotationAnimation.Shortest;
Daniel Vrátil's avatar
Daniel Vrátil committed
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
            }
        }

        Behavior on width {
            PropertyAnimation {
                property: "width";
                easing.type: "OutCubic";
                duration: 150;
            }
        }

        Behavior on height {
            PropertyAnimation {
                property: "height";
                easing.type: "OutCubic";
                duration: 150;
            }
        }

        Rectangle {

            id: monitor;
150

151
            anchors.fill: parent;
Daniel Vrátil's avatar
Daniel Vrátil committed
152 153

            radius: 4;
154
            color: palette.window;
155
            smooth: true;
156
            clip: true;
157

Daniel Vrátil's avatar
Daniel Vrátil committed
158
            border {
159
                color: root.focus ? palette.highlight : palette.shadow;
Daniel Vrátil's avatar
Daniel Vrátil committed
160
                width: 1;
161 162 163 164 165 166

                Behavior on color {
                    PropertyAnimation {
                        duration: 150;
                    }
                }
Daniel Vrátil's avatar
Daniel Vrátil committed
167 168
            }

169 170 171 172
            Rectangle {

                id: posLabel;

173 174
                y: 4;
                x: 4;
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197

                width: childrenRect.width + 5;
                height: childrenRect.height + 2;

                radius: 4;

                opacity: root.output.enabled && monitorMouseArea.drag.active ? 1.0 : 0.0;
                visible: opacity != 0.0;

                color: "#101010";

                Text {
                    id: posLabelText;

                    text: root.outputX + "," + root.outputY;

                    color: "white";

                    y: 2;
                    x: 2;
                }
            }

198
            Item {
199 200
                y: ((parent.height - orientationPanel.height) / 2) - (implicitHeight / 2)

201
                anchors {
202 203 204 205
                    left: parent.left;
                    right: parent.right;
                    leftMargin: 5;
                    rightMargin: 5;
206 207
                }

208 209 210 211
                Text {
                    id: nameLabel
                    text: if (root.isCloneMode === true) {
                            return "";
Laurent Montel's avatar
Laurent Montel committed
212
                          } else if (root.output.type !== KScreenOutput.Panel && root.output.edid && root.output.edid.name) {
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
                            return root.output.edid.name;
                          } else {
                            return "";
                          }

                    color: palette.text;
                    font.pixelSize: 10;

                    anchors {
                        horizontalCenter: parent.horizontalCenter;
                        bottom: labelVendor.top;
                        topMargin: 5;
                    }
                }

228 229
                Text {
                    id: labelVendor;
230
                    text: if (root.isCloneMode) {
Lukáš Tinkl's avatar
Lukáš Tinkl committed
231
                            return i18n("Unified Outputs");
Laurent Montel's avatar
Laurent Montel committed
232
                          } else if (root.output.type === KScreenOutput.Panel) {
Lukáš Tinkl's avatar
Lukáš Tinkl committed
233
                            return i18n("Laptop Screen");
234 235 236 237 238 239 240 241
                          } else if (root.output.edid && root.output.edid.vendor) {
                            return root.output.edid.vendor;
                          } else {
                            return root.output.name;
                          }

                    anchors {
                        verticalCenter: parent.verticalCenter;
242 243
                        left: parent.left;
                        right: parent.right;
244
                    }
245
                    horizontalAlignment: Text.AlignHCenter;
246 247 248

                    color: palette.text;
                    font.pixelSize: 14;
249
                    elide: Text.ElideRight;
250 251 252 253
                }

                Text {
                    id: label
254
                    text: (labelVendor.text === root.output.name) ? "" : root.output.name
255 256 257 258 259 260 261 262 263 264

                    color: palette.text;
                    font.pixelSize: 10;

                    anchors {
                        horizontalCenter: parent.horizontalCenter;
                        top: labelVendor.bottom;
                        topMargin: 5;
                    }
                }
Daniel Vrátil's avatar
Daniel Vrátil committed
265
            }
266 267 268
        }
        Item {
            id: orientationPanelContainer;
Daniel Vrátil's avatar
Daniel Vrátil committed
269

270
            anchors.fill: monitor;
Daniel Vrátil's avatar
Daniel Vrátil committed
271

272
            visible: false
Daniel Vrátil's avatar
Daniel Vrátil committed
273

274 275
            Rectangle {
                id: orientationPanel;
276

277 278 279 280 281
                anchors {
                    left: parent.left;
                    right: parent.right;
                    bottom: parent.bottom;
                }
282

283 284 285
                height: 10;
                color: root.focus ? palette.highlight : palette.shadow;
                smooth: true;
286

287 288 289
                Behavior on color {
                    PropertyAnimation {
                        duration: 150;
290 291
                    }
                }
Daniel Vrátil's avatar
Daniel Vrátil committed
292
            }
293
        }
294

295 296 297 298
        OpacityMask {
            anchors.fill: orientationPanelContainer;
            source: orientationPanelContainer;
            maskSource: monitor;
299
        }
Daniel Vrátil's avatar
Daniel Vrátil committed
300
    }
301

Daniel Vrátil's avatar
Daniel Vrátil committed
302 303 304 305 306 307
    Behavior on opacity {
        PropertyAnimation {
            duration: 200;
            easing.type: "OutCubic";
        }
    }
Daniel Vrátil's avatar
Daniel Vrátil committed
308
}