| 1 |
/* |
| 2 |
* Copyright (C) 2012-2015 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 |
* Authors: |
| 17 |
* Charles Lindsay <[email protected]> |
| 18 |
*/ |
| 19 |
|
| 20 |
import QtQuick 2.9 |
| 21 |
import Lomiri.Components 1.3 |
| 22 |
import "../Utility" |
| 23 |
|
| 24 |
// The user interaction and selection handling for items in the |
| 25 |
// OrganicMediaList. |
| 26 |
Item { |
| 27 |
id: organicItemInteraction |
| 28 |
|
| 29 |
/*! |
| 30 |
*/ |
| 31 |
signal pressed() |
| 32 |
signal selected() |
| 33 |
|
| 34 |
/*! |
| 35 |
*/ |
| 36 |
property var selectionItem |
| 37 |
/*! |
| 38 |
*/ |
| 39 |
property SelectionState selection |
| 40 |
|
| 41 |
// readonly |
| 42 |
property bool isSelected: selection.isSelected(selectionItem) |
| 43 |
|
| 44 |
property bool isEventHeader: false |
| 45 |
|
| 46 |
anchors.fill: parent |
| 47 |
|
| 48 |
function toggleSelection() { |
| 49 |
selection.toggleSelection(selectionItem); |
| 50 |
if (isSelected) |
| 51 |
organicItemInteraction.selected(); |
| 52 |
} |
| 53 |
|
| 54 |
Rectangle { |
| 55 |
id: selectionRectangle |
| 56 |
objectName: "selectionCheckbox" |
| 57 |
anchors { |
| 58 |
top: parent.top |
| 59 |
right: parent.right |
| 60 |
topMargin: units.gu(0.5) |
| 61 |
rightMargin: units.gu(0.5) |
| 62 |
} |
| 63 |
width: units.gu(4) |
| 64 |
height: width |
| 65 |
color: isSelected ? theme.palette.normal.positive : LomiriColors.inkstone |
| 66 |
radius: 10 |
| 67 |
opacity: isSelected ? 0.8 : 0.6 |
| 68 |
visible: selection.inSelectionMode && !isEventHeader |
| 69 |
|
| 70 |
Icon { |
| 71 |
anchors.centerIn: parent |
| 72 |
width: parent.width * 0.8 |
| 73 |
height: width |
| 74 |
name: "ok" |
| 75 |
color: "white" |
| 76 |
visible: isSelected |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
MouseArea { |
| 81 |
anchors.fill: parent |
| 82 |
|
| 83 |
acceptedButtons: Qt.LeftButton | Qt.RightButton |
| 84 |
|
| 85 |
onPressAndHold: toggleSelection() |
| 86 |
onClicked: { |
| 87 |
if (mouse.button == Qt.RightButton || isEventHeader) |
| 88 |
toggleSelection(); |
| 89 |
else |
| 90 |
organicItemInteraction.pressed(); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
MouseArea { |
| 95 |
anchors { |
| 96 |
top: parent.top |
| 97 |
right: parent.right |
| 98 |
} |
| 99 |
width: parent.width * 0.5 |
| 100 |
height: parent.height * 0.5 |
| 101 |
enabled: selectionRectangle.visible |
| 102 |
|
| 103 |
onClicked: { |
| 104 |
mouse.accepted = true; |
| 105 |
toggleSelection(); |
| 106 |
} |
| 107 |
} |
| 108 |
} |