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

« back to all changes in this revision

Viewing changes to qml/func/common/TabFrame.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
 
Item {
4
 
    id: tabWidget
5
 
    width: 100
6
 
    height: 100
7
 
    property int current: 0
8
 
    property int count: stack.children.length
9
 
    property bool frame: true
10
 
    property bool tabsVisible: true
11
 
    property string position: "North"
12
 
    default property alias tabs : stack.children
13
 
    property Item tabBar: tabbarItem
14
 
 
15
 
    onCurrentChanged: __setOpacities()
16
 
    Component.onCompleted: __setOpacities()
17
 
 
18
 
    property int __baseOverlap : frameitem.pixelMetric("tabbaseoverlap")// add paintmargins;
19
 
    function __setOpacities() {
20
 
        for (var i = 0; i < stack.children.length; ++i) {
21
 
            stack.children[i].visible = (i == current ? true : false)
22
 
        }
23
 
    }   
24
 
 
25
 
    Component {
26
 
        id: tabcomp
27
 
        Tab {}
28
 
    }
29
 
 
30
 
    function addTab(component, title) {
31
 
        var tab = tabcomp.createObject(this);
32
 
        component.createObject(tab)
33
 
        tab.parent = stack
34
 
        tab.title = title
35
 
        __setOpacities()
36
 
        return tab
37
 
    }
38
 
 
39
 
    function removeTab(id) {
40
 
        var tab = tabs[id]
41
 
        tab.destroy()
42
 
        if (current > 0)
43
 
            current-=1
44
 
    }
45
 
 
46
 
    StyleItem {
47
 
        id: frameitem
48
 
        z: style == "oxygen" ? 1 : 0
49
 
        elementType: "tabframe"
50
 
        info: position
51
 
        value: tabbarItem && tabsVisible && tabbarItem.tab(current) ? tabbarItem.tab(current).x : 0
52
 
        minimum: tabbarItem && tabsVisible && tabbarItem.tab(current) ? tabbarItem.tab(current).width : 0
53
 
        maximum: tabbarItem && tabsVisible ? tabbarItem.tabWidth : width
54
 
        anchors.fill: parent
55
 
 
56
 
        property int frameWidth: pixelMetric("defaultframewidth")
57
 
 
58
 
        Item {
59
 
            id: stack
60
 
            anchors.fill: parent
61
 
            anchors.margins: (frame ? frameitem.frameWidth : 0)
62
 
            anchors.topMargin: anchors.margins + (frameitem.style =="mac" ? 6 : 0)
63
 
            anchors.bottomMargin: anchors.margins + (frameitem.style =="mac" ? 6 : 0)
64
 
        }
65
 
 
66
 
        anchors.topMargin: tabbarItem && tabsVisible && position == "North" ? Math.max(0, tabbarItem.height - __baseOverlap) : 0
67
 
 
68
 
        states: [
69
 
            State {
70
 
                name: "South"
71
 
                when: position == "South" && tabbarItem!= undefined
72
 
                PropertyChanges {
73
 
                    target: frameitem
74
 
                    anchors.topMargin: 0
75
 
                    anchors.bottomMargin: tabbarItem ? tabbarItem.height - __baseOverlap: 0
76
 
                }
77
 
                PropertyChanges {
78
 
                    target: tabbarItem
79
 
                    anchors.topMargin: -__baseOverlap
80
 
                }
81
 
                AnchorChanges {
82
 
                    target: tabbarItem
83
 
                    anchors.top: frameitem.bottom
84
 
                    anchors.bottom: undefined
85
 
                }
86
 
            }
87
 
        ]
88
 
    }
89
 
    TabBar {
90
 
        id: tabbarItem
91
 
        tabFrame: tabWidget
92
 
        anchors.top: tabWidget.top
93
 
        anchors.left: tabWidget.left
94
 
        anchors.right: tabWidget.right
95
 
    }
96
 
}