~ubuntu-branches/ubuntu/saucy/plasma-nm/saucy-proposed

« back to all changes in this revision

Viewing changes to applet/declarative/contents/ui/Toolbar.qml

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-08-16 19:07:09 UTC
  • Revision ID: package-import@ubuntu.com-20130816190709-ef9ydm9skigmg15l
Tags: upstream-0.0~git20130816
ImportĀ upstreamĀ versionĀ 0.0~git20130816

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright 2013 Jan Grulich <jgrulich@redhat.com>
 
3
 
 
4
    This library is free software; you can redistribute it and/or
 
5
    modify it under the terms of the GNU Lesser General Public
 
6
    License as published by the Free Software Foundation; either
 
7
    version 2.1 of the License, or (at your option) version 3, or any
 
8
    later version accepted by the membership of KDE e.V. (or its
 
9
    successor approved by the membership of KDE e.V.), which shall
 
10
    act as a proxy defined in Section 6 of version 3 of the license.
 
11
 
 
12
    This library is distributed in the hope that it will be useful,
 
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
    Lesser General Public License for more details.
 
16
 
 
17
    You should have received a copy of the GNU Lesser General Public
 
18
    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
19
*/
 
20
 
 
21
import QtQuick 1.1
 
22
import org.kde.qtextracomponents 0.1
 
23
import org.kde.plasma.graphicswidgets 0.1 as PlasmaWidgets
 
24
import org.kde.plasma.components 0.1 as PlasmaComponents
 
25
import org.kde.plasma.extras 0.1 as PlasmaExtras
 
26
import org.kde.plasma.core 0.1 as PlasmaCore
 
27
import org.kde.plasmanm 0.1 as PlasmaNM
 
28
 
 
29
Item {
 
30
    id: toolBar;
 
31
 
 
32
    property bool expanded: false;
 
33
 
 
34
    height: theme.defaultFont.mSize.height * 2;
 
35
 
 
36
    PlasmaNM.NetworkStatus {
 
37
        id: networkStatus;
 
38
 
 
39
        onSetGlobalStatus: {
 
40
            statusLabel.text = status;
 
41
            progressIndicator.running = inProgress;
 
42
            if (connected) {
 
43
                statusIcon.source = "user-online";
 
44
                statusIcon.enabled = true;
 
45
            } else {
 
46
                statusIcon.source = "user-offline";
 
47
                statusIcon.enabled = false;
 
48
            }
 
49
        }
 
50
    }
 
51
 
 
52
    Item {
 
53
        id: toolbarLine;
 
54
 
 
55
        height: theme.defaultFont.mSize.height * 2;
 
56
        anchors {
 
57
            left: parent.left;
 
58
            right: parent.right;
 
59
            bottom: parent.bottom;
 
60
        }
 
61
 
 
62
        PlasmaCore.IconItem {
 
63
            id: statusIcon
 
64
 
 
65
            height: theme.smallMediumIconSize;
 
66
            width: height;
 
67
            anchors {
 
68
                left: parent.left;
 
69
                verticalCenter: parent.verticalCenter;
 
70
                leftMargin: padding.margins.left;
 
71
            }
 
72
 
 
73
            PlasmaComponents.BusyIndicator {
 
74
                id: progressIndicator;
 
75
 
 
76
                anchors.fill: parent;
 
77
                running: false;
 
78
                visible: running;
 
79
            }
 
80
        }
 
81
 
 
82
        PlasmaComponents.Label {
 
83
            id: statusLabel;
 
84
 
 
85
            height: theme.defaultFont.mSize.height * 2;
 
86
            anchors {
 
87
                left: statusIcon.right;
 
88
                right: toolButton.left;
 
89
                verticalCenter: parent.verticalCenter;
 
90
                leftMargin: padding.margins.left;
 
91
            }
 
92
            elide: Text.ElideRight;
 
93
        }
 
94
 
 
95
        PlasmaCore.IconItem {
 
96
            id: toolButton;
 
97
 
 
98
            height: theme.smallMediumIconSize;
 
99
            width: height;
 
100
            anchors {
 
101
                right: parent.right;
 
102
                verticalCenter: parent.verticalCenter;
 
103
                rightMargin: padding.margins.right;
 
104
            }
 
105
            source: "configure";
 
106
        }
 
107
 
 
108
        MouseArea {
 
109
            id: toolbarMouseArea;
 
110
 
 
111
            anchors { fill: parent }
 
112
 
 
113
            onClicked: {
 
114
                hideOrShowOptions();
 
115
            }
 
116
        }
 
117
    }
 
118
 
 
119
    OptionsWidget {
 
120
        id: options;
 
121
 
 
122
        anchors {
 
123
            left: parent.left;
 
124
            right: parent.right;
 
125
            top: parent.top;
 
126
            bottomMargin: padding.margins.bottom;
 
127
        }
 
128
        visible: false;
 
129
 
 
130
        onOpenEditor: {
 
131
            if (mainWindow.autoHideOptions) {
 
132
                expanded = false;
 
133
            }
 
134
        }
 
135
    }
 
136
 
 
137
    states: [
 
138
        State {
 
139
            name: "Hidden";
 
140
            when: !expanded;
 
141
        },
 
142
 
 
143
        State {
 
144
            name: "Expanded";
 
145
            when: expanded;
 
146
            PropertyChanges { target: toolBar; height: options.childrenRect.height + theme.defaultFont.mSize.height * 2 + padding.margins.top }
 
147
            PropertyChanges { target: options; visible: true }
 
148
        }
 
149
    ]
 
150
 
 
151
    transitions: Transition {
 
152
        NumberAnimation { duration: 300; properties: "height, visible" }
 
153
    }
 
154
 
 
155
    function hideOrShowOptions() {
 
156
        if (!expanded) {
 
157
            expanded = true;
 
158
            plasmoid.writeConfig("optionsExpanded", "expanded");
 
159
        } else {
 
160
            expanded = false;
 
161
            plasmoid.writeConfig("optionsExpanded", "hidden");
 
162
        }
 
163
    }
 
164
 
 
165
    Component.onCompleted: {
 
166
        networkStatus.init();
 
167
 
 
168
        if (plasmoid.readConfig("optionsExpanded") == "expanded") {
 
169
            expanded = true;
 
170
        }
 
171
    }
 
172
}