mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 14:08:51 +02:00
Fix sortOrder param on tablet buttons
This commit is contained in:
parent
2e4fc5e58c
commit
27ea74f5bf
13 changed files with 40 additions and 25 deletions
|
@ -31,6 +31,8 @@
|
||||||
const QString SYSTEM_TOOLBAR = "com.highfidelity.interface.toolbar.system";
|
const QString SYSTEM_TOOLBAR = "com.highfidelity.interface.toolbar.system";
|
||||||
const QString SYSTEM_TABLET = "com.highfidelity.interface.tablet.system";
|
const QString SYSTEM_TABLET = "com.highfidelity.interface.tablet.system";
|
||||||
const QString TabletScriptingInterface::QML = "hifi/tablet/TabletRoot.qml";
|
const QString TabletScriptingInterface::QML = "hifi/tablet/TabletRoot.qml";
|
||||||
|
const QString BUTTON_SORT_ORDER_KEY = "sortOrder";
|
||||||
|
const int DEFAULT_BUTTON_SORT_ORDER = 100;
|
||||||
|
|
||||||
static QString getUsername() {
|
static QString getUsername() {
|
||||||
QString username = "Unknown user";
|
QString username = "Unknown user";
|
||||||
|
@ -74,11 +76,20 @@ QVariant TabletButtonListModel::data(const QModelIndex& index, int role) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
TabletButtonProxy* TabletButtonListModel::addButton(const QVariant& properties) {
|
TabletButtonProxy* TabletButtonListModel::addButton(const QVariant& properties) {
|
||||||
auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap()));
|
QVariantMap newTabletButtonProperties = properties.toMap();
|
||||||
|
if (newTabletButtonProperties.find(BUTTON_SORT_ORDER_KEY) == newTabletButtonProperties.end()) {
|
||||||
|
newTabletButtonProperties[BUTTON_SORT_ORDER_KEY] = DEFAULT_BUTTON_SORT_ORDER;
|
||||||
|
}
|
||||||
|
int insertButtonUsingIndex = computeNewButtonIndex(newTabletButtonProperties);
|
||||||
|
auto newTabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(newTabletButtonProperties));
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
_buttons.push_back(tabletButtonProxy);
|
if (insertButtonUsingIndex < _buttons.size()) {
|
||||||
|
_buttons.insert(_buttons.begin() + insertButtonUsingIndex, newTabletButtonProxy);
|
||||||
|
} else {
|
||||||
|
_buttons.push_back(newTabletButtonProxy);
|
||||||
|
}
|
||||||
endResetModel();
|
endResetModel();
|
||||||
return tabletButtonProxy.data();
|
return newTabletButtonProxy.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabletButtonListModel::removeButton(TabletButtonProxy* button) {
|
void TabletButtonListModel::removeButton(TabletButtonProxy* button) {
|
||||||
|
@ -92,6 +103,20 @@ void TabletButtonListModel::removeButton(TabletButtonProxy* button) {
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TabletButtonListModel::computeNewButtonIndex(const QVariantMap& newButtonProperties) {
|
||||||
|
int buttonCount = (int)_buttons.size();
|
||||||
|
int newButtonSortOrder = newButtonProperties[BUTTON_SORT_ORDER_KEY].toInt();
|
||||||
|
if (newButtonSortOrder == DEFAULT_BUTTON_SORT_ORDER) return buttonCount;
|
||||||
|
for (int i = 0; i < buttonCount; i++) {
|
||||||
|
QVariantMap tabletButtonProperties = _buttons[i]->getProperties();
|
||||||
|
int tabletButtonSortOrder = tabletButtonProperties[BUTTON_SORT_ORDER_KEY].toInt();
|
||||||
|
if (newButtonSortOrder <= tabletButtonSortOrder) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buttonCount;
|
||||||
|
}
|
||||||
|
|
||||||
TabletButtonsProxyModel::TabletButtonsProxyModel(QObject *parent)
|
TabletButtonsProxyModel::TabletButtonsProxyModel(QObject *parent)
|
||||||
: QSortFilterProxyModel(parent) {
|
: QSortFilterProxyModel(parent) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,7 @@ protected:
|
||||||
friend class TabletProxy;
|
friend class TabletProxy;
|
||||||
TabletButtonProxy* addButton(const QVariant& properties);
|
TabletButtonProxy* addButton(const QVariant& properties);
|
||||||
void removeButton(TabletButtonProxy* button);
|
void removeButton(TabletButtonProxy* button);
|
||||||
|
int computeNewButtonIndex(const QVariantMap& newButtonProperties);
|
||||||
using List = std::list<QSharedPointer<TabletButtonProxy>>;
|
using List = std::list<QSharedPointer<TabletButtonProxy>>;
|
||||||
static QHash<int, QByteArray> _roles;
|
static QHash<int, QByteArray> _roles;
|
||||||
static Qt::ItemFlags _flags;
|
static Qt::ItemFlags _flags;
|
||||||
|
|
|
@ -22,8 +22,7 @@
|
||||||
|
|
||||||
var button = tablet.addButton({
|
var button = tablet.addButton({
|
||||||
icon: Script.resolvePath("dynamicsTests.svg"),
|
icon: Script.resolvePath("dynamicsTests.svg"),
|
||||||
text: "Dynamics",
|
text: "Dynamics"
|
||||||
sortOrder: 15
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,7 @@
|
||||||
var button = tablet.addButton({
|
var button = tablet.addButton({
|
||||||
text: TABLET_BUTTON_NAME,
|
text: TABLET_BUTTON_NAME,
|
||||||
icon: ICON_URL,
|
icon: ICON_URL,
|
||||||
activeIcon: ACTIVE_ICON_URL,
|
activeIcon: ACTIVE_ICON_URL
|
||||||
sortOrder: 1
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var hasEventBridge = false;
|
var hasEventBridge = false;
|
||||||
|
|
|
@ -30,8 +30,7 @@
|
||||||
var button = tablet.addButton({
|
var button = tablet.addButton({
|
||||||
text: TABLET_BUTTON_NAME,
|
text: TABLET_BUTTON_NAME,
|
||||||
icon: ICON_URL,
|
icon: ICON_URL,
|
||||||
activeIcon: ACTIVE_ICON_URL,
|
activeIcon: ACTIVE_ICON_URL
|
||||||
sortOrder: 1
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var hasEventBridge = false;
|
var hasEventBridge = false;
|
||||||
|
|
|
@ -31,8 +31,7 @@
|
||||||
var button = tablet.addButton({
|
var button = tablet.addButton({
|
||||||
text: TABLET_BUTTON_NAME,
|
text: TABLET_BUTTON_NAME,
|
||||||
icon: ICON_URL,
|
icon: ICON_URL,
|
||||||
activeIcon: ACTIVE_ICON_URL,
|
activeIcon: ACTIVE_ICON_URL
|
||||||
sortOrder: 1
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var hasEventBridge = false;
|
var hasEventBridge = false;
|
||||||
|
|
|
@ -945,8 +945,7 @@
|
||||||
tabletButton = tablet.addButton({
|
tabletButton = tablet.addButton({
|
||||||
icon: tabletButtonIcon,
|
icon: tabletButtonIcon,
|
||||||
activeIcon: tabletButtonActiveIcon,
|
activeIcon: tabletButtonActiveIcon,
|
||||||
text: tabletButtonName,
|
text: tabletButtonName
|
||||||
sortOrder: 0
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Messages.subscribe(channelName);
|
Messages.subscribe(channelName);
|
||||||
|
|
|
@ -37,8 +37,7 @@
|
||||||
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
button = tablet.addButton({
|
button = tablet.addButton({
|
||||||
icon: "icons/tablet-icons/goto-i.svg",
|
icon: "icons/tablet-icons/goto-i.svg",
|
||||||
text: buttonName,
|
text: buttonName
|
||||||
sortOrder: 8
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,7 @@ if (Settings.getValue("HUDUIEnabled")) {
|
||||||
button = tablet.addButton({
|
button = tablet.addButton({
|
||||||
icon: "icons/tablet-icons/goto-i.svg",
|
icon: "icons/tablet-icons/goto-i.svg",
|
||||||
activeIcon: "icons/tablet-icons/goto-a.svg",
|
activeIcon: "icons/tablet-icons/goto-a.svg",
|
||||||
text: buttonName,
|
text: buttonName
|
||||||
sortOrder: 8
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,7 @@
|
||||||
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
var button = tablet.addButton({
|
var button = tablet.addButton({
|
||||||
icon: Script.resolvePath("assets/images/run.svg"),
|
icon: Script.resolvePath("assets/images/run.svg"),
|
||||||
text: "RUN",
|
text: "RUN"
|
||||||
sortOrder: 15
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function onClicked() {
|
function onClicked() {
|
||||||
|
|
|
@ -37,8 +37,7 @@
|
||||||
var button = tablet.addButton({
|
var button = tablet.addButton({
|
||||||
icon: "icons/tablet-icons/users-i.svg",
|
icon: "icons/tablet-icons/users-i.svg",
|
||||||
activeIcon: "icons/tablet-icons/users-a.svg",
|
activeIcon: "icons/tablet-icons/users-a.svg",
|
||||||
text: "USERS",
|
text: "USERS"
|
||||||
sortOrder: 11
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var onUsersScreen = false;
|
var onUsersScreen = false;
|
||||||
|
|
|
@ -31,8 +31,7 @@ var activeButton = tablet.addButton({
|
||||||
icon: whiteIcon,
|
icon: whiteIcon,
|
||||||
activeIcon: blackIcon,
|
activeIcon: blackIcon,
|
||||||
text: APP_NAME,
|
text: APP_NAME,
|
||||||
isActive: isActive,
|
isActive: isActive
|
||||||
sortOrder: 11
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
|
|
|
@ -32,8 +32,7 @@
|
||||||
var button = tablet.addButton({
|
var button = tablet.addButton({
|
||||||
icon: ICONS.icon,
|
icon: ICONS.icon,
|
||||||
activeIcon: ICONS.activeIcon,
|
activeIcon: ICONS.activeIcon,
|
||||||
text: TABLET_BUTTON_NAME,
|
text: TABLET_BUTTON_NAME
|
||||||
sortOrder: 1
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var hasEventBridge = false;
|
var hasEventBridge = false;
|
||||||
|
|
Loading…
Reference in a new issue