~ubuntu-branches/ubuntu/saucy/share-like-connect/saucy

« back to all changes in this revision

Viewing changes to applet/contents/ui/IconLoader.qml

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-09-17 11:30:06 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130917113006-5ohj8qt9kuf3izma
Tags: 1:0.4-0ubuntu1
* New upstream release LP: #1227602
* Use epoch to reset version number in line with upstream
* Add build-dep on nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
*   Copyright (C) 2011 by Marco MArtin <mart@kde.org>
3
 
*
4
 
*   This program is free software; you can redistribute it and/or modify
5
 
*   it under the terms of the GNU Library General Public License as
6
 
*   published by the Free Software Foundation; either version 2, or
7
 
*   (at your option) any later version.
8
 
*
9
 
*   This program is distributed in the hope that it will be useful,
10
 
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
*   GNU Library General Public License for more details
13
 
*
14
 
*   You should have received a copy of the GNU Library General Public
15
 
*   License along with this program; if not, write to the
16
 
*   Free Software Foundation, Inc.,
17
 
*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
 
*/
19
 
 
20
 
/**Documented API
21
 
Inherits:
22
 
        Item
23
 
 
24
 
Imports:
25
 
        QtQuick 1.1
26
 
        org.kde.plasma.core
27
 
        org.kde.qtextracomponents
28
 
 
29
 
Description:
30
 
 TODO i need more info here
31
 
 
32
 
Properties:
33
 
        bool valid:
34
 
        Returns if the icon is valid or not.
35
 
 
36
 
        string source:
37
 
        Returns the dir,in which the icon exists.
38
 
**/
39
 
 
40
 
import QtQuick 1.1
41
 
import org.kde.plasma.core 0.1 as PlasmaCore
42
 
import org.kde.qtextracomponents 0.1
43
 
 
44
 
Item {
45
 
    id: root
46
 
 
47
 
    property bool valid: false
48
 
 
49
 
    property variant source
50
 
 
51
 
    onSourceChanged: {
52
 
        //is it a qicon?
53
 
        if (typeof source != "string") {
54
 
            imageLoader.sourceComponent = iconComponent
55
 
            valid = true
56
 
            return
57
 
        } else if (source == "") {
58
 
            imageLoader.sourceComponent = null
59
 
            valid = false
60
 
            return
61
 
        }
62
 
 
63
 
        svgIcon.imagePath = "toolbar-icons/"+root.source.split("-")[0]
64
 
        if (!svgIcon.isValid() || !svgIcon.hasElement(root.source)) {
65
 
            svgIcon.imagePath = "icons/"+root.source.split("-")[0]
66
 
        }
67
 
 
68
 
        if (svgIcon.isValid() && svgIcon.hasElement(root.source)) {
69
 
            imageLoader.sourceComponent = svgComponent
70
 
        } else if ((root.source.indexOf(".") == -1 && root.source.indexOf(":") == -1)) {
71
 
            imageLoader.sourceComponent = iconComponent
72
 
        } else {
73
 
            imageLoader.sourceComponent = imageComponent
74
 
        }
75
 
        valid = true
76
 
    }
77
 
 
78
 
    implicitWidth: theme.smallIconSize
79
 
    implicitHeight: theme.smallIconSize
80
 
 
81
 
    PlasmaCore.Svg {
82
 
        id: svgIcon
83
 
    }
84
 
 
85
 
    function roundToStandardSize(size)
86
 
    {
87
 
        if (size >= theme.enormousIconSize) {
88
 
            return theme.enormousIconSize
89
 
        } else if (size >= theme.hugeIconSize) {
90
 
            return theme.hugeIconSize
91
 
        } else if (size >= theme.largeIconSize) {
92
 
            return theme.largeIconSize
93
 
        } else if (size >= theme.mediumIconSize) {
94
 
            return theme.mediumIconSize
95
 
        } else if (size >= theme.smallMediumIconSize) {
96
 
            return theme.smallMediumIconSize
97
 
        } else {
98
 
            return theme.smallIconSize
99
 
        }
100
 
    }
101
 
 
102
 
    Loader {
103
 
        id: imageLoader
104
 
        anchors.fill: parent
105
 
 
106
 
        Component {
107
 
            id: svgComponent
108
 
 
109
 
            PlasmaCore.SvgItem {
110
 
                svg: svgIcon
111
 
                elementId: root.source
112
 
                anchors.fill: parent
113
 
                smooth: true
114
 
            }
115
 
        }
116
 
 
117
 
        Component {
118
 
            id: iconComponent
119
 
 
120
 
            QIconItem {
121
 
                icon: (typeof source == "string") ? QIcon(root.source) : root.source
122
 
                smooth: true
123
 
                anchors.fill: parent
124
 
            }
125
 
        }
126
 
 
127
 
        Component {
128
 
            id: imageComponent
129
 
 
130
 
            Image {
131
 
                source: root.source
132
 
                sourceSize.width: width
133
 
                sourceSize.height: height
134
 
                fillMode: Image.PreserveAspectFit
135
 
                smooth: true
136
 
                anchors.fill: parent
137
 
            }
138
 
        }
139
 
    }
140
 
}