Warning, /graphics/krita/libs/libqml/plugins/components/Dialog.qml is written in an unsupported language. File is not indexed.

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2012 Arjen Hiemstra <ahiemstra@heimr.nl>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 import QtQuick 2.3
0008 import org.krita.sketch 1.0
0009 
0010 Item {
0011     id: base;
0012     enabled: (visible && opacity > 0.0);
0013 
0014     property alias title: dialogTitle.text;
0015     property alias message: dialogText.text;
0016     property variant buttons: null;
0017     property alias modalBackgroundColor: modalFill.color;
0018     property alias textAlign: dialogText.horizontalAlignment;
0019     property int progress: -1;
0020 
0021     property int defaultButton: 0;
0022     property int currentButton: defaultButton;
0023 
0024     signal buttonClicked(int button);
0025     signal canceled();
0026 
0027     function show(message) {
0028         if (message) {
0029             base.message = message;
0030         }
0031         base.opacity = 1;
0032     }
0033 
0034     function hide(message) {
0035         if (message) {
0036             base.message = message;
0037         }
0038         base.opacity = 0;
0039         base.currentButton = base.defaultButton;
0040     }
0041 
0042     anchors.fill: parent;
0043     z: 99; //Just to make sure we're always on top.
0044     opacity: 0;
0045     Behavior on opacity { NumberAnimation { duration: Constants.AnimationDuration; } }
0046 
0047     MouseArea {
0048         anchors.fill: parent;
0049         onClicked: {
0050             // Don't allow people to click away a progress bar...
0051             // horrible things could happen if they do so (inconsistent states and what not)
0052             if (progress !== -1)
0053                 return;
0054             base.canceled();
0055             base.hide();
0056         }
0057     }
0058     SimpleTouchArea {
0059         anchors.fill: parent;
0060         onTouched: {
0061             // Don't allow people to click away a progress bar...
0062             // horrible things could happen if they do so (inconsistent states and what not)
0063             if (progress !== -1)
0064                 return;
0065             base.canceled();
0066             base.hide();
0067         }
0068     }
0069 
0070     Rectangle {
0071         id: modalFill;
0072 
0073         anchors.fill: parent;
0074         color: Settings.theme.color("components/dialog/modalOverlay");
0075 
0076         Keys.enabled: base.visible && base.opacity === 1;
0077         Keys.onEscapePressed: {
0078                 // Don't allow people to escape from a progress bar...
0079                 // horrible things could happen if they do so (inconsistent states and what not)
0080                 if (progress !== -1)
0081                     return;
0082                 base.canceled();
0083                 base.hide();
0084             }
0085         Keys.onEnterPressed: { base.buttonClicked(base.currentButton); base.hide(); }
0086         Keys.onReturnPressed: { base.buttonClicked(base.currentButton); base.hide(); }
0087         focus: Keys.enabled;
0088         Keys.onTabPressed: {
0089             base.currentButton += 1;
0090             if (base.currentButton >= base.buttons.length) {
0091                 base.currentButton = 0;
0092             }
0093         }
0094     }
0095 
0096     Rectangle {
0097         id: dialogBackground;
0098 
0099         anchors.centerIn: parent;
0100 
0101         width: parent.width / 2;
0102         height: Constants.GridHeight * 2 + dialogText.height + 32;
0103 
0104         radius: 8;
0105 
0106         gradient: Gradient {
0107             GradientStop { position: 0; color: Settings.theme.color("components/dialog/background/start"); }
0108             GradientStop { position: 0.4; color: Settings.theme.color("components/dialog/background/stop"); }
0109         }
0110 
0111         Rectangle {
0112             id: dialogHeader;
0113 
0114             anchors {
0115                 top: parent.top;
0116                 left: parent.left;
0117                 right: parent.right;
0118             }
0119 
0120             height: Constants.GridHeight;
0121             color: Settings.theme.color("components/dialog/header");
0122             radius: 8;
0123 
0124             Rectangle {
0125                 anchors {
0126                     left: parent.left;
0127                     right: parent.right;
0128                     bottom: parent.bottom;
0129                 }
0130                 height: 8;
0131                 color: Settings.theme.color("components/dialog/header");
0132             }
0133 
0134             Label {
0135                 id: dialogTitle;
0136                 anchors.centerIn: parent;
0137                 color: Settings.theme.color("components/dialog/headerText");
0138                 font: Settings.theme.font("title");
0139             }
0140 
0141             Shadow { anchors { left: parent.left; right: parent.right; top: parent.bottom; } }
0142         }
0143 
0144         Label {
0145             id: dialogText;
0146 
0147             anchors {
0148                 left: parent.left;
0149                 leftMargin: 8;
0150                 right: parent.right;
0151                 rightMargin: 8;
0152             }
0153 
0154             y: dialogHeader.height + 16;
0155             elide: Text.ElideNone;
0156             wrapMode: Text.Wrap;
0157         }
0158 
0159         Rectangle {
0160             id: progressBase;
0161             opacity: (progress > 0 && progressBar.width > 0) ? 1 : 0;
0162             Behavior on opacity { NumberAnimation { duration: Constants.AnimationDuration; } }
0163             anchors {
0164                 top: dialogText.bottom;
0165                 horizontalCenter: parent.horizontalCenter;
0166                 margins: 8;
0167             }
0168             height: Constants.LargeFontSize + 4;
0169             width: 208;
0170             radius: height / 2;
0171             border {
0172                 width: 1;
0173                 color: Settings.theme.color("components/dialog/progress/border");
0174             }
0175             color: Settings.theme.color("components/dialog/progress/background");
0176             Rectangle {
0177                 id: progressBar;
0178                 anchors {
0179                     top: parent.top;
0180                     left: parent.left;
0181                     margins: 4;
0182                 }
0183                 radius: height / 2;
0184                 width: progress >= 0 ? (progress * 2) + 1: 100;
0185                 height: parent.height - 7;
0186                 Behavior on width { PropertyAnimation { duration: 100; } }
0187                 color: Settings.theme.color("components/dialog/progress/bar");
0188             }
0189         }
0190         BusyIndicator {
0191             id: busy;
0192             anchors.fill: progressBase;
0193             opacity: (progress > -1 && progressBase.opacity === 0) ? 1 : 0;
0194             running: opacity === 1;
0195             Behavior on opacity { PropertyAnimation { duration: 100; } }
0196         }
0197 
0198         Row {
0199             id: buttonRow;
0200 
0201             anchors {
0202                 left: parent.left;
0203                 leftMargin: 8;
0204                 right: parent.right;
0205                 bottom: parent.bottom;
0206                 bottomMargin: 8;
0207             }
0208 
0209             height: Constants.GridHeight;
0210             spacing: 8;
0211 
0212             Repeater {
0213                 model: base.buttons;
0214 
0215                 delegate: Button {
0216                     width: (parent.width / base.buttons.length) - 8;
0217                     height: parent.height;
0218                     radius: 8;
0219 
0220                     text: modelData;
0221                     color: Settings.theme.color("components/dialog/button");
0222                     textColor: Settings.theme.color("components/dialog/buttonText");
0223 
0224                     onClicked: { base.buttonClicked(index); base.hide(); }
0225                     hasFocus: index === base.currentButton;
0226                 }
0227             }
0228         }
0229     }
0230 
0231     Shadow {
0232         anchors {
0233             left: dialogBackground.left;
0234             leftMargin: dialogBackground.radius;
0235             right: dialogBackground.right;
0236             rightMargin: dialogBackground.radius;
0237             top: dialogBackground.bottom;
0238         }
0239     }
0240 }