~feng-kylin/youker-assistant/youker-assistant

« back to all changes in this revision

Viewing changes to qml/func/common/ToolButton.qml

  • Committer: kobe
  • Date: 2015-02-13 07:37:10 UTC
  • Revision ID: xiangli@ubuntukylin.com-20150213073710-0jyp02ilyi5njj10
Qt Version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import QtQuick 1.1
2
 
import StyleItemType 0.1
3
 
import TooltipAreaType 0.1
4
 
import "private" as Private
5
 
Private.Button {
6
 
    id:button
7
 
 
8
 
    property alias containsMouse: tooltip.containsMouse
9
 
    property string iconName
10
 
    property string styleHint
11
 
    property int iconSize: (backgroundItem && backgroundItem.style === "mac" && button.styleHint.indexOf("segmented") !== -1) ? 16 : 24
12
 
 
13
 
    implicitWidth: backgroundItem.implicitWidth
14
 
    implicitHeight: backgroundItem.implicitHeight
15
 
 
16
 
    TooltipArea {
17
 
        // Note this will eat hover events
18
 
        id: tooltip
19
 
        anchors.fill: parent
20
 
        text: button.tooltip
21
 
    }
22
 
 
23
 
    background: StyleItem {
24
 
        id: styleitem
25
 
        anchors.fill: parent
26
 
        elementType: "toolbutton"
27
 
        on: pressed | checked
28
 
        sunken: pressed
29
 
        raised: containsMouse
30
 
        hover: containsMouse
31
 
        info: __position
32
 
        hint: button.styleHint
33
 
        contentWidth: Math.max(textitem.paintedWidth, 32)
34
 
        contentHeight: 32
35
 
        Text {
36
 
            id: textitem
37
 
            text: button.text
38
 
            anchors.centerIn: parent
39
 
            visible: button.iconSource == ""
40
 
        }
41
 
    }
42
 
    Image {
43
 
        id: themeIcon
44
 
        anchors.centerIn: parent
45
 
        opacity: enabled ? 1 : 0.5
46
 
        smooth: true
47
 
        sourceSize.width: iconSize
48
 
        property string iconPath: "image://desktoptheme/" + button.iconName
49
 
        source: backgroundItem && backgroundItem.hasThemeIcon(iconName) ? iconPath : ""
50
 
        fillMode: Image.PreserveAspectFit
51
 
        Image {
52
 
            // Use fallback icon
53
 
            anchors.centerIn: parent
54
 
            sourceSize: parent.sourceSize
55
 
            visible: (themeIcon.status != Image.Ready)
56
 
            source: visible ? button.iconSource : ""
57
 
        }
58
 
    }
59
 
}