on xenial help sign in
New tabbar from sdk
commit8189f0a7ecaaf9f3fcf07592cca718266ca65492 authorAlbert Astals <albert.astals@canonical.com> dateMon 25 Nov 2013, 11:13 (13 years ago) parentad55782
5 files changed+21−44
Dash/DashContent.qml+12−39 plugins/Unity/scopes.cpp+3 plugins/Unity/scopes.h+2−1 tests/qmltests/Dash/tst_Dash.qml+2−2 tests/qmltests/Dash/tst_DashContent.qml+2−2
Dash/DashContent.qml+12−39
@@ -163,51 +163,24 @@ Item {
163163 objectName: "tabbar"
164164 height: units.gu(7)
165165 width: parent.width
166− implicitWidth: currentButtonWidth
166+ implicitWidth: 400
167167
168− property alias selectedTabIndex: tabs.selectedTabIndex
168+ model: dashContentList.model
169169
170− Component.onCompleted: {
171− __styleInstance.headerTextStyle = Text.Raised
172− __styleInstance.headerTextStyleColor = "black"
170+ onSelectedIndexChanged: {
171+ dashContentList.currentIndex = selectedIndex;
173172 }
174173
175− tabsItem: TabsBase {
176− id: tabs
177−
178− Repeater {
179− model: dashContentList.model
180− Tab {
181− id: tab
182− title: scope.name
183− Component.onCompleted: {
184− var aux = tabs.tabList;
185− aux.push(tab)
186− tabs.tabList = aux;
187− tabs.modelChanged();
188− if (tabs.selectedTabIndex == -1) {
189− tabs.selectedTabIndex = 0;
190− }
191− }
192− Component.onDestruction: {
193− var aux = tabs.tabList;
194− aux.splice(aux.indexOf(tab), 1)
195− tabs.tabList = aux;
196− tabs.modelChanged();
197− }
198− }
199− }
200−
201− onSelectedTabIndexChanged: {
202− dashContentList.currentIndex = selectedTabIndex;
174+ Connections {
175+ target: dashContentList
176+ onCurrentIndexChanged: {
177+ tabbar.selectedIndex = dashContentList.currentIndex
203178 }
179+ }
204180
205− Connections {
206− target: dashContentList
207− onCurrentIndexChanged: {
208− tabs.selectedTabIndex = dashContentList.currentIndex
209− }
210− }
181+ Component.onCompleted: {
182+ __styleInstance.headerTextStyle = Text.Raised
183+ __styleInstance.headerTextStyleColor = "black"
211184 }
212185 }
213186 }
plugins/Unity/scopes.cpp+3
@@ -36,6 +36,7 @@ Scopes::Scopes(QObject *parent)
3636 m_roles[Scopes::RoleScope] = "scope";
3737 m_roles[Scopes::RoleId] = "id";
3838 m_roles[Scopes::RoleVisible] = "visible";
39+ m_roles[Scopes::RoleTitle] = "title";
3940
4041 m_unityScopes->scope_added.connect(sigc::mem_fun(this, &Scopes::onScopeAdded));
4142 m_unityScopes->scope_removed.connect(sigc::mem_fun(this, &Scopes::onScopeRemoved));
@@ -71,6 +72,8 @@ QVariant Scopes::data(const QModelIndex& index, int role) const
7172 return QVariant::fromValue(scope->id());
7273 } else if (role == Scopes::RoleVisible) {
7374 return QVariant::fromValue(scope->visible());
75+ } else if (role == Scopes::RoleTitle) {
76+ return scope->name();
7477 } else {
7578 return QVariant();
7679 }
plugins/Unity/scopes.h+2−1
@@ -54,7 +54,8 @@ public:
5454 enum Roles {
5555 RoleScope,
5656 RoleId,
57− RoleVisible
57+ RoleVisible,
58+ RoleTitle
5859 };
5960
6061 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
tests/qmltests/Dash/tst_Dash.qml+2−2
@@ -88,7 +88,7 @@ Item {
8888
8989 dash.setCurrentScope(data.tag, true /* animate */, false /* reset */);
9090 compare(dashContent.currentIndex, data.shouldBeVisible ? data.visualIndex : current_index);
91− compare(tabbar.selectedTabIndex, data.shouldBeVisible ? data.visualIndex : current_index);
91+ compare(tabbar.selectedIndex, data.shouldBeVisible ? data.visualIndex : current_index);
9292 }
9393
9494 function test_show_scope_on_load_data() {
@@ -124,7 +124,7 @@ Item {
124124 var dashContent = findChild(dash, "dashContent");
125125 var current_index = dashContent.currentIndex;
126126
127− tabbar.selectedTabIndex = data.visualIndex;
127+ tabbar.selectedIndex = data.visualIndex;
128128 compare(dashContent.currentIndex, data.shouldBeVisible ? data.visualIndex : current_index);
129129 }
130130 }
tests/qmltests/Dash/tst_DashContent.qml+2−2
@@ -240,9 +240,9 @@ Item {
240240 function test_tabBar_listens_to_index_change() {
241241 var tabbar = findChild(dashContent, "tabbar");
242242 tryCompare(dashContent, "currentIndex", 0);
243− compare(tabbar.selectedTabIndex, 0);
243+ compare(tabbar.selectedIndex, 0);
244244 dashContent.currentIndex = 1;
245− compare(tabbar.selectedTabIndex, 1);
245+ compare(tabbar.selectedIndex, 1);
246246 }
247247 }
248248}