Warning, /graphics/krita/libs/libqml/qml/panels/PresetsPanel.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 import org.krita.sketch.components 1.0
0010 
0011 Panel {
0012     id: base;
0013     name: "Presets";
0014     colorSet: "presets";
0015 
0016     /*actions: [
0017         Button {
0018             id: addButton;
0019 
0020             width: Constants.GridWidth / 2
0021             height: Constants.GridHeight;
0022 
0023             color: "transparent";
0024             image: "../images/svg/icon-add.svg"
0025             textColor: "white";
0026             shadow: false;
0027             highlight: false;
0028             onClicked: base.toggleEdit();
0029 
0030             states: State {
0031                 name: "edit"
0032                 when: base.state == "edit";
0033 
0034                 PropertyChanges { target: addButton; text: "Cancel"; color: Constants.Theme.NegativeColor; width: Constants.GridWidth * 2; }
0035             }
0036 
0037             transitions: Transition {
0038                 to: "edit";
0039                 reversible: true;
0040 
0041                 ParallelAnimation {
0042                     NumberAnimation { target: addButton; properties: "width"; duration: Constants.AnimationDuration; }
0043                     ColorAnimation { target: addButton; properties: "color"; duration: Constants.AnimationDuration; }
0044                 }
0045             }
0046         },
0047         Button {
0048             id: editButton;
0049 
0050             width: Constants.GridWidth / 2
0051             height: Constants.GridHeight;
0052 
0053             text: ""
0054             image: "../images/svg/icon-edit.svg"
0055             color: "transparent";
0056             textColor: "white";
0057             shadow: false;
0058             highlight: false;
0059             onClicked: base.toggleEdit();
0060 
0061             states: State {
0062                 name: "edit"
0063                 when: base.state == "edit";
0064 
0065                 PropertyChanges { target: editButton; text: "Save"; color: Constants.Theme.PositiveColor; width: Constants.GridWidth * 2; }
0066             }
0067 
0068             transitions: Transition {
0069                 to: "edit";
0070                 reversible: true;
0071 
0072                 ParallelAnimation {
0073                     NumberAnimation { target: editButton; properties: "width"; duration: Constants.AnimationDuration; }
0074                     ColorAnimation { target: editButton; properties: "color"; duration: Constants.AnimationDuration; }
0075                 }
0076             }
0077         }
0078     ]*/
0079 
0080     PresetModel {
0081         id: presetsModel;
0082         view: sketchView.view;
0083         onCurrentPresetChanged: {
0084             peekViewGrid.currentIndex = nameToIndex(currentPreset);
0085             fullViewGrid.currentIndex = nameToIndex(currentPreset);
0086         }
0087     }
0088     Connections {
0089         target: sketchView;
0090         onLoadingFinished: {
0091 //            if (window.applicationName === undefined) {
0092                 if(toolManager.currentTool === null)
0093                     toolManager.requestToolChange("KritaShape/KisToolBrush");
0094                 presetsModel.currentPreset = Settings.lastPreset;
0095 //            }
0096         }
0097     }
0098 
0099     peekContents: GridView {
0100         id: peekViewGrid;
0101         anchors.fill: parent;
0102         keyNavigationWraps: false
0103 
0104         model: presetsModel;
0105         delegate: Button {
0106             width: Constants.GridWidth;
0107             height: Constants.GridHeight;
0108 
0109             checked: GridView.isCurrentItem;
0110             checkedColor: Settings.theme.color("panels/presets/preset/active");
0111 
0112             color: Settings.theme.color("panels/presets/preset/inactive")
0113 
0114             highlightColor: Settings.theme.color("panels/presets/preset/active")
0115 
0116             Image {
0117                 anchors {
0118                     bottom: peekLabel.top
0119                     top: parent.top;
0120                     horizontalCenter: parent.horizontalCenter;
0121                     margins: 2
0122                 }
0123                 source: model.image
0124                 fillMode: Image.PreserveAspectFit;
0125                 asynchronous: true;
0126             }
0127             Label {
0128                     id: peekLabel
0129                     anchors {
0130                         left: parent.left
0131                         right: parent.right
0132                         bottom: parent.bottom
0133                         margins: 2
0134                     }
0135                     elide: Text.ElideMiddle;
0136                     text: model.text;
0137                     font.pixelSize: Constants.SmallFontSize
0138                     horizontalAlignment: Text.AlignHCenter
0139             }
0140 
0141             onClicked: {
0142                 presetsModel.activatePreset(index);
0143                 toolManager.requestToolChange("KritaShape/KisToolBrush");
0144                 peekViewGrid.currentIndex = index;
0145                 fullViewGrid.currentIndex = index;
0146             }
0147         }
0148 
0149         cellWidth: Constants.GridWidth;
0150         cellHeight: Constants.GridHeight;
0151         ScrollDecorator {
0152             flickableItem: parent;
0153         }
0154     }
0155 
0156     fullContents: PageStack {
0157         id: contentArea;
0158         anchors.fill: parent;
0159         initialPage: GridView {
0160             id: fullViewGrid;
0161             anchors.fill: parent;
0162             model: presetsModel;
0163             delegate: Item {
0164                 height: Constants.GridHeight;
0165                 width: contentArea.width;
0166                 Rectangle {
0167                     anchors.fill: parent;
0168                     color: (model.name === presetsModel.currentPreset) ?
0169                         Settings.theme.color("panels/presets/preset/active") :
0170                         Settings.theme.color("panels/presets/preset/inactive");
0171                 }
0172                 Rectangle {
0173                     id: presetThumbContainer;
0174                     anchors {
0175                         verticalCenter: parent.verticalCenter;
0176                         left: parent.left;
0177                     }
0178                     height: Constants.GridHeight;
0179                     width: height;
0180                     color: "transparent";
0181                     Image {
0182                         anchors.centerIn: parent;
0183                         cache: false;
0184                         source: model.image;
0185                         smooth: true;
0186                         width: parent.width * 0.8;
0187                         height: parent.height * 0.8;
0188                         fillMode: Image.PreserveAspectFit;
0189                         asynchronous: true;
0190                     }
0191                 }
0192                 Label {
0193                     anchors {
0194                         top: parent.top;
0195                         left: presetThumbContainer.right;
0196                         right: parent.right;
0197                         bottom: parent.bottom;
0198                     }
0199                     wrapMode: Text.Wrap;
0200                     elide: Text.ElideRight;
0201                     text: model.text;
0202                     maximumLineCount: 3;
0203                 }
0204                 MouseArea {
0205                     anchors.fill: parent;
0206                     onClicked: {
0207                         presetsModel.activatePreset(index);
0208                         toolManager.requestToolChange("KritaShape/KisToolBrush");
0209                         peekViewGrid.currentIndex = index;
0210                         fullViewGrid.currentIndex = index;
0211                     }
0212                 }
0213             }
0214 
0215             cellWidth: contentArea.width;
0216             cellHeight: Constants.GridHeight;
0217             ScrollDecorator {
0218                 flickableItem: parent;
0219             }
0220         }
0221     }
0222 
0223     onStateChanged: if ( state != "edit" && contentArea.depth > 1 ) {
0224         contentArea.pop();
0225     }
0226 
0227     function toggleEdit() {
0228         if ( base.state == "edit" ) {
0229             base.state = "full";
0230             contentArea.pop();
0231         } else if ( base.state == "full" ) {
0232             base.state = "edit";
0233             contentArea.push( editPresetPage );
0234         }
0235     }
0236 
0237     Component { id: editPresetPage; EditPresetPage { } }
0238 }