~dpm/ubuntu-filemanager-app/run-ap-from-out-of-source-build

« back to all changes in this revision

Viewing changes to components/FolderIconDelegate.qml

  • Committer: Michael Spencer
  • Date: 2014-02-19 00:00:15 UTC
  • mto: This revision was merged to the branch mainline in revision 132.
  • Revision ID: sonrisesoftware@gmail.com-20140219000015-3ogzcc7roicfqbyi
Refactored files into sub-directories

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <sonrisesoftware@gmail.com>
 
17
 */
 
18
import QtQuick 2.0
 
19
import QtGraphicalEffects 1.0
 
20
import Ubuntu.Components 0.1
 
21
 
 
22
Item {
 
23
    id: delegate
 
24
    height: units.gu(11)
 
25
    width: units.gu(11)
 
26
 
 
27
    property bool selected
 
28
    property alias mouseOver: mouseArea.containsMouse
 
29
 
 
30
    Rectangle {
 
31
        anchors.centerIn: parent
 
32
       // anchors.verticalCenterOffset: units.gu(0.5)
 
33
        height: parent.height// + units.gu(1)
 
34
        width: height
 
35
 
 
36
        radius: units.gu(2)
 
37
        smooth: true
 
38
        antialiasing: true
 
39
        opacity: selected ? 0.5 : 0
 
40
        color: UbuntuColors.orange
 
41
 
 
42
        Behavior on opacity {
 
43
            UbuntuNumberAnimation {}
 
44
        }
 
45
    }
 
46
 
 
47
    objectName: "folder" + index
 
48
 
 
49
    property string fileName: model.fileName
 
50
    property string filePath: fileView.path + '/' + fileName
 
51
 
 
52
    property string text: fileName
 
53
    property string subText: Qt.formatDateTime(model.modifiedDate, Qt.DefaultLocaleShortDate) + (!model.isDir ? ", " + fileSize : "")
 
54
 
 
55
    property var icon: fileIcon(filePath, model.isDir)
 
56
 
 
57
    Item {
 
58
        anchors {
 
59
            left: parent.left
 
60
            right: parent.right
 
61
            top: parent.top
 
62
            bottom: label.top
 
63
            topMargin: units.gu(0.5)
 
64
            bottomMargin: units.gu(1)
 
65
            leftMargin: units.gu(1)
 
66
            rightMargin: units.gu(1)
 
67
        }
 
68
 
 
69
        Image {
 
70
            id: image
 
71
            anchors.centerIn: parent
 
72
            width: units.gu(6)
 
73
            height: width
 
74
 
 
75
            source: delegate.icon
 
76
        }
 
77
 
 
78
        BrightnessContrast {
 
79
            anchors.fill: image
 
80
            brightness: 0.3
 
81
            source: image
 
82
            opacity: mouseOver ? 1 : 0
 
83
 
 
84
            Behavior on opacity {
 
85
                UbuntuNumberAnimation {}
 
86
            }
 
87
        }
 
88
    }
 
89
 
 
90
    property bool expand: mouseOver && label.implicitWidth >= label.width
 
91
    z: expand ? 1 : 0
 
92
 
 
93
    Rectangle {
 
94
        anchors {
 
95
            fill: label
 
96
            margins: units.gu(-0.5)
 
97
            leftMargin: units.gu(-1)
 
98
            rightMargin: units.gu(-1)
 
99
        }
 
100
        color: "white"
 
101
        radius: height/2
 
102
        border.color: UbuntuColors.warmGrey
 
103
        antialiasing: true
 
104
        opacity: expand ? 1 : 0
 
105
 
 
106
        Behavior on opacity {
 
107
            UbuntuNumberAnimation {}
 
108
        }
 
109
    }
 
110
 
 
111
    Label {
 
112
        id: label
 
113
        anchors {
 
114
            horizontalCenter: parent.horizontalCenter
 
115
            bottom: parent.bottom
 
116
            bottomMargin: units.gu(0.75)
 
117
        }
 
118
 
 
119
        width: expand ? implicitWidth : (parent.width - units.gu(0.5))
 
120
 
 
121
        Behavior on width {
 
122
            UbuntuNumberAnimation {}
 
123
        }
 
124
 
 
125
        horizontalAlignment: Text.AlignHCenter
 
126
        elide: Text.ElideMiddle
 
127
 
 
128
        text: delegate.text
 
129
        color: expand ? UbuntuColors.coolGrey : Theme.palette.selected.backgroundText
 
130
        Behavior on color {
 
131
            ColorAnimation { duration: 200 }
 
132
        }
 
133
    }
 
134
 
 
135
    MouseArea {
 
136
        id: mouseArea
 
137
        anchors.fill: parent
 
138
        hoverEnabled: true
 
139
        acceptedButtons: (Qt.LeftButton | Qt.RightButton)
 
140
 
 
141
        onClicked: {
 
142
            if (mouse.button === Qt.RightButton)
 
143
                pressAndHold(mouse)
 
144
            else
 
145
                itemClicked(model)
 
146
        }
 
147
 
 
148
        propagateComposedEvents: true
 
149
 
 
150
        onPressAndHold: itemLongPress(delegate, model)
 
151
    }
 
152
}