| 1 |
/* |
| 2 |
* Copyright (C) 2013 Canonical Ltd |
| 3 |
* |
| 4 |
* This program is free software: you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License version 3 as |
| 6 |
* published by the Free Software Foundation. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
* |
| 16 |
* Authored by: Michael Spencer <[email protected]> |
| 17 |
*/ |
| 18 |
import QtQuick 2.4 |
| 19 |
import Lomiri.Components 1.3 |
| 20 |
import QtGraphicalEffects 1.0 |
| 21 |
|
| 22 |
MouseArea { |
| 23 |
id: delegate |
| 24 |
|
| 25 |
property bool isSelected |
| 26 |
|
| 27 |
property string iconName |
| 28 |
property string title |
| 29 |
property string path |
| 30 |
|
| 31 |
// Ensure that file name can overlap the items below. |
| 32 |
z: delegate.containsMouse ? 10 : 0 |
| 33 |
|
| 34 |
function getTextSize () { |
| 35 |
switch (globalSettings.gridSize) { |
| 36 |
case 0: return Label.XSmall |
| 37 |
case 1: return Label.Small |
| 38 |
case 2: return Label.Medium |
| 39 |
case 3: return Label.Large |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
Rectangle { |
| 44 |
anchors { fill: parent; margins: units.dp(2) } |
| 45 |
radius: units.dp(4) |
| 46 |
opacity: delegate.isSelected ? 0.5 : 0 |
| 47 |
color: theme.palette.selected.focus |
| 48 |
|
| 49 |
Behavior on opacity { |
| 50 |
LomiriNumberAnimation {} |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
Item { |
| 55 |
id: imgContainer |
| 56 |
anchors { top: parent.top; topMargin: units.gu(1) } |
| 57 |
anchors.horizontalCenter: parent.horizontalCenter |
| 58 |
height: delegate.width / 1.7 |
| 59 |
width: height |
| 60 |
opacity: delegate.isSelectedForCut ? 0.5 : 1 |
| 61 |
|
| 62 |
Icon { |
| 63 |
anchors.fill: parent |
| 64 |
visible: !image.visible |
| 65 |
name: delegate.iconName |
| 66 |
} |
| 67 |
|
| 68 |
Image { |
| 69 |
id: image |
| 70 |
anchors.fill: parent |
| 71 |
sourceSize: Qt.size(image.width, image.height) |
| 72 |
visible: status == Image.Ready |
| 73 |
|
| 74 |
source: model.mimeType.indexOf("image/") > -1 ? "image://thumbnailer/file://" + delegate.path : "" |
| 75 |
fillMode: Image.PreserveAspectFit |
| 76 |
asynchronous: true |
| 77 |
} |
| 78 |
|
| 79 |
/*BrightnessContrast { |
| 80 |
anchors.fill: imgContainer |
| 81 |
brightness: 0.3 |
| 82 |
source: imgContainer |
| 83 |
opacity: visible ? 1.0 : 0.0 |
| 84 |
visible: delegate.containsMouse |
| 85 |
|
| 86 |
Behavior on opacity { |
| 87 |
LomiriNumberAnimation {} |
| 88 |
} |
| 89 |
}*/ |
| 90 |
} |
| 91 |
|
| 92 |
Label { |
| 93 |
anchors { |
| 94 |
left: parent.left; leftMargin: units.gu(0.5) |
| 95 |
right: parent.right; rightMargin: units.gu(0.5) |
| 96 |
top: imgContainer.bottom; topMargin: units.gu(1) |
| 97 |
} |
| 98 |
|
| 99 |
horizontalAlignment: Text.AlignHCenter |
| 100 |
color: theme.palette.normal.backgroundSecondaryText |
| 101 |
|
| 102 |
text: delegate.title |
| 103 |
|
| 104 |
// TODO: This is probably too small, but this way we are sure that text has always |
| 105 |
// a good contrast with bg, since it doesn't overlay other icons or strings. |
| 106 |
textSize: getTextSize() |
| 107 |
|
| 108 |
wrapMode: Text.WrapAtWordBoundaryOrAnywhere |
| 109 |
elide: Text.ElideMiddle |
| 110 |
maximumLineCount: delegate.containsMouse ? Number.MAX_VALUE : 3 |
| 111 |
|
| 112 |
style: delegate.containsMouse && !delegate.isSelected ? Text.Outline : Text.Normal |
| 113 |
styleColor: theme.palette.normal.background |
| 114 |
} |
| 115 |
|
| 116 |
acceptedButtons: (Qt.LeftButton | Qt.RightButton) |
| 117 |
hoverEnabled: true |
| 118 |
|
| 119 |
// WORKAROUND: This postpone removal of delegates until all UITK Popups are closed. |
| 120 |
// TODO: Provide a less "hackish" fix |
| 121 |
GridView.onRemove: SequentialAnimation { |
| 122 |
PropertyAction { target: delegate; property: "GridView.delayRemove"; value: true } |
| 123 |
NumberAnimation { target: delegate; property: "scale"; to: 0; duration: 250; easing.type: Easing.InOutQuad } |
| 124 |
PropertyAction { target: delegate; property: "GridView.delayRemove"; value: false } |
| 125 |
} |
| 126 |
} |