Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Preliminary support for notch in indicator bar #448

Draft
wants to merge 1 commit into
base: xenial
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion qml/Panel/Indicators/IndicatorItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ IndicatorDelegate {
property bool expanded: false
property bool selected: false
property real iconHeight: units.gu(2)
property bool notch: identifier === "notch"
property real notchW: units.gu(3)
readonly property color color: {
if (!expanded) return theme.palette.normal.backgroundText;
if (!selected) return theme.palette.disabled.backgroundText;
Expand Down Expand Up @@ -65,7 +67,7 @@ IndicatorDelegate {
id: mainItems
anchors.centerIn: parent

width: leftLabelItem.width + iconsItem.width + rightLabelItem.width
width: notch ? notchW : leftLabelItem.width + iconsItem.width + rightLabelItem.width
implicitHeight: units.gu(2)

Label {
Expand Down Expand Up @@ -106,6 +108,7 @@ IndicatorDelegate {
id: iconRepeater
objectName: "iconRepeater"

// model: notch ? [] : d.useFallbackIcon ? [ "image://theme/settings" ] : root.icons
model: d.useFallbackIcon ? [ "image://theme/settings" ] : root.icons

Icon {
Expand All @@ -117,6 +120,7 @@ IndicatorDelegate {
source: modelData
color: root.color
Behavior on color { ColorAnimation { duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing } }
visible: !notch

// Workaround indicators getting stretched/squished when (un)plugging external/virtual monitor
onHeightChanged: {
Expand Down
20 changes: 15 additions & 5 deletions qml/Panel/Panel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ Item {
// Whether our expanded menus should take up the full width of the panel
property bool partialWidth: width >= units.gu(60)

property alias expanded: __indicators.expanded
property alias listView: __indicators.listView
property real notchW: units.gu(3)
// onNotchWChanged: console.log(notchW)

property string mode: "staged"

MouseArea {
Expand Down Expand Up @@ -422,6 +427,8 @@ Item {
height: parent.height
expanded: indicators.expanded
selected: ListView.isCurrentItem
notchW: root.notchW
// onNotchWChanged: console.log(notchW)

identifier: model.identifier
busName: indicatorProperties.busName
Expand All @@ -437,27 +444,30 @@ Item {
}

pageDelegate: PanelMenuPage {
objectName: modelData.identifier + "-page"
objectName: modelData ? modelData.identifier + "-page" : ""
submenuIndex: 0

menuModel: delegate.menuModel

factory: IndicatorMenuItemFactory {
indicator: {
var context = modelData.identifier;
var context = modelData ? modelData.identifier : "";
if (context && context.indexOf("fake-") === 0) {
context = context.substring("fake-".length)
}
// if (context && context === "notch") {
// return undefined
// }
return context;
}
rootModel: delegate.menuModel
}

IndicatorDelegate {
id: delegate
busName: modelData.indicatorProperties.busName
actionsObjectPath: modelData.indicatorProperties.actionsObjectPath
menuObjectPath: modelData.indicatorProperties.menuObjectPath
busName: modelData ? modelData.indicatorProperties.busName : ""
actionsObjectPath: modelData ? modelData.indicatorProperties.actionsObjectPath : ""
menuObjectPath: modelData ? modelData.indicatorProperties.menuObjectPath : ""
}
}

Expand Down
7 changes: 7 additions & 0 deletions qml/Panel/PanelBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ Item {

property alias hideRow: row.hideRow
property alias rowItemDelegate: row.delegate
property alias listView: row.listView

implicitWidth: flickable.contentWidth

function indicatorAt(x, y) {
return row.indicatorAt(x, y)
}
function getCurrentItemX() {
return row.getCurrentItemX()
}
function selectItemAt(lateralPosition) {
if (!expanded) {
row.resetCurrentItem();
Expand Down
5 changes: 5 additions & 0 deletions qml/Panel/PanelItemRow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Item {
property bool expanded: false
readonly property alias currentItem: row.currentItem
readonly property alias currentItemIndex: row.currentIndex
property alias listView: row

property real unitProgress: 0.0
property real selectionChangeBuffer: units.gu(2)
Expand Down Expand Up @@ -128,6 +129,10 @@ Item {
return false;
}

function getCurrentItemX() {
return row.currentItem.x
}

function selectItemAt(lateralPosition) {
var item = indicatorAt(lateralPosition, 0);
if (item && item.opacity > 0 && item.enabled) {
Expand Down
17 changes: 17 additions & 0 deletions qml/Panel/PanelMenu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ Showable {

onUnitProgressChanged: d.updateState()

property alias listView: bar.listView
function indicatorAt(x, y) {
return bar.indicatorAt(x, y)
}
function selectNextItem() {
return bar.selectNextItem()
}
function selectPreviousItem() {
return bar.selectPreviousItem()
}
function setCurrentItemIndex(i) {
return bar.setCurrentItemIndex(i)
}
function getCurrentItemX() {
return bar.getCurrentItemX()
}

Item {
anchors {
left: parent.left
Expand Down
1 change: 1 addition & 0 deletions qml/Panel/PanelMenuPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ PageStack {
if (clearModel) {
clear();
var model = root.submenuIndex == undefined ? menuModel : menuModel.submenu(root.submenuIndex)
// console.log(JSON.stringify(model))
if (model) {
push(pageComponent, { "menuModel": model });
}
Expand Down
9 changes: 9 additions & 0 deletions tests/mocks/Unity/Indicators/IndicatorsModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ Indicators.FakeIndicatorsModel {
"actionsObjectPath": "/com/canonical/indicators/fake5"
}
},
{
"identifier": "notch",
"indicatorProperties": {
"enabled": true,
"busName": "com.canonical.indicators.fake-notch",
"menuObjectPath": "/com/canonical/indicators/fake-notch",
"actionsObjectPath": "/com/canonical/indicators/fake-notch"
}
},
{
"identifier": "fake-indicator-power",
"indicatorProperties": {
Expand Down
14 changes: 14 additions & 0 deletions tests/mocks/Unity/Indicators/fakeindicatorsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "fakeindicatorsmodel.h"
#include "indicators.h"
#include <QDebug>

FakeIndicatorsModel::FakeIndicatorsModel(QObject *parent)
: QAbstractListModel(parent),
Expand Down Expand Up @@ -104,6 +105,19 @@ void FakeIndicatorsModel::remove(int row)

endRemoveRows();
}
void FakeIndicatorsModel::moveNotchToIndex(const int notchIndex, const int index)
{
QList<QVariant> allData = m_modelData.toList();
// qDebug() << allData;
beginResetModel();
allData.move(notchIndex, index);
// qDebug() << allData;
m_modelData = allData;
Q_EMIT modelDataChanged();

endResetModel();
// qDebug() << m_modelData;
}

void FakeIndicatorsModel::setModelData(const QVariant& modelData)
{
Expand Down
3 changes: 3 additions & 0 deletions tests/mocks/Unity/Indicators/fakeindicatorsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class FakeIndicatorsModel : public QAbstractListModel
QModelIndex parent (const QModelIndex &index) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;

// Notch
Q_INVOKABLE void moveNotchToIndex(const int notchIndex, const int index);

Q_SIGNALS:
void countChanged();
void profileChanged();
Expand Down
25 changes: 25 additions & 0 deletions tests/qmltests/Panel/PanelTest.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import QtQuick 2.4
import Unity.Indicators 0.1 as Indicators

// this file
Rectangle {
id: root
color: theme.palette.normal.background
Expand Down Expand Up @@ -59,6 +60,30 @@ Rectangle {
}
}

// get actual indicator index from original model index
function getIndicatorIndex(index) {
var i;
for (i = 0; i < __indicatorsModel.modelData.length; i++) {
if (__indicatorsModel.modelData[i]["identifier"] === __indicatorsModel.originalModelData[index]["identifier"]) {
console.log(__indicatorsModel.modelData[i]["identifier"])
return i;
}
}
}

function getIndicatorIndexFromIdentifier(identifier) {
var i;
for (i = 0; i < __indicatorsModel.modelData.length; i++) {
if (__indicatorsModel.modelData[i]["identifier"] === identifier) {
return i;
}
}
}

function moveNotch(index) {
__indicatorsModel.moveNotchToIndex(getIndicatorIndex(6), index)
}

function setIndicatorVisible(index, visible) {
var identifier = __indicatorsModel.originalModelData[index]["identifier"];
__indicatorsModel.setIndicatorVisible(identifier, visible);
Expand Down
Loading