mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 18:41:10 +02:00
Use buttons index
This commit is contained in:
parent
ffcccacfa5
commit
35fee739c5
4 changed files with 27 additions and 41 deletions
|
@ -24,9 +24,9 @@ Item {
|
||||||
property int stableOrder: 0
|
property int stableOrder: 0
|
||||||
property var tabletRoot;
|
property var tabletRoot;
|
||||||
property var flickable: null
|
property var flickable: null
|
||||||
|
property var gridView: null
|
||||||
|
|
||||||
property int row: -1
|
property int buttonIndex: -1
|
||||||
property int column: -1
|
|
||||||
|
|
||||||
width: 129
|
width: 129
|
||||||
height: 129
|
height: 129
|
||||||
|
@ -138,7 +138,8 @@ Item {
|
||||||
enabled: true
|
enabled: true
|
||||||
preventStealing: false
|
preventStealing: false
|
||||||
onClicked: {
|
onClicked: {
|
||||||
tablet.setCurrentItemState("base state");
|
gridView.currentIndex = buttonIndex
|
||||||
|
|
||||||
if (tabletButton.inDebugMode) {
|
if (tabletButton.inDebugMode) {
|
||||||
if (tabletButton.isActive) {
|
if (tabletButton.isActive) {
|
||||||
tabletButton.isActive = false;
|
tabletButton.isActive = false;
|
||||||
|
@ -146,8 +147,6 @@ Item {
|
||||||
tabletButton.isActive = true;
|
tabletButton.isActive = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tablet.rowIndex = tabletButton.row
|
|
||||||
tablet.columnIndex = tabletButton.column
|
|
||||||
|
|
||||||
tabletButton.clicked();
|
tabletButton.clicked();
|
||||||
if (tabletRoot) {
|
if (tabletRoot) {
|
||||||
|
@ -156,7 +155,7 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
onEntered: {
|
onEntered: {
|
||||||
tablet.setCurrentItemState("base state");
|
gridView.currentIndex = buttonIndex
|
||||||
tabletButton.isEntered = true;
|
tabletButton.isEntered = true;
|
||||||
Tablet.playSound(TabletEnums.ButtonHover);
|
Tablet.playSound(TabletEnums.ButtonHover);
|
||||||
|
|
||||||
|
@ -165,8 +164,6 @@ Item {
|
||||||
} else {
|
} else {
|
||||||
tabletButton.state = "hover state";
|
tabletButton.state = "hover state";
|
||||||
}
|
}
|
||||||
tablet.rowIndex = tabletButton.row
|
|
||||||
tablet.columnIndex = tabletButton.column
|
|
||||||
}
|
}
|
||||||
onExited: {
|
onExited: {
|
||||||
tabletButton.isEntered = false;
|
tabletButton.isEntered = false;
|
||||||
|
|
|
@ -14,9 +14,6 @@ Item {
|
||||||
objectName: "tablet"
|
objectName: "tablet"
|
||||||
property var tabletProxy: Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
property var tabletProxy: Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
|
|
||||||
property int rowIndex: 6 // by default
|
|
||||||
property int columnIndex: 1 // point to 'go to location'
|
|
||||||
|
|
||||||
property var currentGridItems: null
|
property var currentGridItems: null
|
||||||
|
|
||||||
focus: true
|
focus: true
|
||||||
|
@ -145,10 +142,9 @@ Item {
|
||||||
if (buttonIndex < 0) {
|
if (buttonIndex < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.warn("changing item at", buttonIndex, buttonstate)
|
||||||
|
|
||||||
var itemat = gridView.contentItem.children[buttonIndex].children[0];
|
var itemat = gridView.contentItem.children[buttonIndex].children[0];
|
||||||
console.warn("changing item at", buttonIndex, state, itemat.objectName,
|
|
||||||
gridView.contentItem.children[buttonIndex].objectName)
|
|
||||||
if (itemat.isActive) {
|
if (itemat.isActive) {
|
||||||
itemat.state = "active state";
|
itemat.state = "active state";
|
||||||
} else {
|
} else {
|
||||||
|
@ -158,9 +154,7 @@ Item {
|
||||||
|
|
||||||
onCurrentIndexChanged: {
|
onCurrentIndexChanged: {
|
||||||
setButtonState(previousGridIndex, "base state");
|
setButtonState(previousGridIndex, "base state");
|
||||||
rowIndex = Math.floor(currentIndex / TabletEnums.ButtonsColumnsOnPage);
|
console.warn("current index", currentIndex)
|
||||||
columnIndex = currentIndex % TabletEnums.ButtonsColumnsOnPage
|
|
||||||
console.warn("current index", currentIndex, rowIndex, columnIndex)
|
|
||||||
setButtonState(currentIndex, "hover state");
|
setButtonState(currentIndex, "hover state");
|
||||||
previousGridIndex = currentIndex
|
previousGridIndex = currentIndex
|
||||||
}
|
}
|
||||||
|
@ -181,12 +175,10 @@ Item {
|
||||||
TabletButton {
|
TabletButton {
|
||||||
id: tabletButton
|
id: tabletButton
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
|
gridView: wrapper.GridView.view
|
||||||
|
buttonIndex: page.proxyModel.buttonIndex(uuid);
|
||||||
flickable: swipeView.contentItem;
|
flickable: swipeView.contentItem;
|
||||||
onClicked: modelData.clicked()
|
onClicked: modelData.clicked()
|
||||||
onStateChanged: console.warn("state", state, uuid)
|
|
||||||
// Component.onCompleted: {
|
|
||||||
// state = Qt.binding(function() { return wrapper.GridView.isCurrentItem ? "hover state" : "base state"; });
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
|
@ -221,7 +213,6 @@ Item {
|
||||||
|
|
||||||
currentGridItems.currentIndex = (previousIndex > swipeView.currentIndex ? currentGridItems.count - 1 : 0);
|
currentGridItems.currentIndex = (previousIndex > swipeView.currentIndex ? currentGridItems.count - 1 : 0);
|
||||||
previousIndex = currentIndex;
|
previousIndex = currentIndex;
|
||||||
setButtonState(currentIndex, "hover state");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
|
@ -263,17 +254,6 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setCurrentItemState(state) {
|
|
||||||
var buttonIndex = rowIndex * TabletEnums.ButtonsColumnsOnPage + columnIndex;
|
|
||||||
if (currentGridItems !== null && buttonIndex >= 0 && buttonIndex < currentGridItems.length) {
|
|
||||||
if (currentGridItems[buttonIndex].isActive) {
|
|
||||||
currentGridItems[buttonIndex].state = "active state";
|
|
||||||
} else {
|
|
||||||
currentGridItems[buttonIndex].state = state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
focus = true;
|
focus = true;
|
||||||
forceActiveFocus();
|
forceActiveFocus();
|
||||||
|
|
|
@ -93,13 +93,27 @@ void TabletButtonListModel::removeButton(TabletButtonProxy* button) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TabletButtonsProxyModel::TabletButtonsProxyModel(QObject *parent)
|
TabletButtonsProxyModel::TabletButtonsProxyModel(QObject *parent)
|
||||||
: QSortFilterProxyModel(parent), _pageIndex(-1) {
|
: QSortFilterProxyModel(parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int TabletButtonsProxyModel::pageIndex() const {
|
int TabletButtonsProxyModel::pageIndex() const {
|
||||||
return _pageIndex;
|
return _pageIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TabletButtonsProxyModel::buttonIndex(const QString &uuid) {
|
||||||
|
if (!sourceModel() || _pageIndex < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
TabletButtonListModel* model = static_cast<TabletButtonListModel*>(sourceModel());
|
||||||
|
for (int i = 0; i < model->rowCount(); i++) {
|
||||||
|
TabletButtonProxy* bproxy = model->data(model->index(i), ButtonProxyRole).value<TabletButtonProxy*>();
|
||||||
|
if (bproxy && bproxy->getUuid().toString().contains(uuid)) {
|
||||||
|
return i - (_pageIndex*TabletScriptingInterface::ButtonsOnPage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void TabletButtonsProxyModel::setPageIndex(int pageIndex)
|
void TabletButtonsProxyModel::setPageIndex(int pageIndex)
|
||||||
{
|
{
|
||||||
if (_pageIndex == pageIndex)
|
if (_pageIndex == pageIndex)
|
||||||
|
@ -117,11 +131,6 @@ bool TabletButtonsProxyModel::filterAcceptsRow(int sourceRow,
|
||||||
&& sourceRow < (_pageIndex + 1)*TabletScriptingInterface::ButtonsOnPage);
|
&& sourceRow < (_pageIndex + 1)*TabletScriptingInterface::ButtonsOnPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TabletButtonsProxyModel::lessThan(const QModelIndex &left,
|
|
||||||
const QModelIndex &right) const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
TabletScriptingInterface::TabletScriptingInterface() {
|
TabletScriptingInterface::TabletScriptingInterface() {
|
||||||
qmlRegisterType<TabletScriptingInterface>("TabletScriptingInterface", 1, 0, "TabletEnums");
|
qmlRegisterType<TabletScriptingInterface>("TabletScriptingInterface", 1, 0, "TabletEnums");
|
||||||
qmlRegisterType<TabletButtonsProxyModel>("TabletScriptingInterface", 1, 0, "TabletButtonsProxyModel");
|
qmlRegisterType<TabletButtonsProxyModel>("TabletScriptingInterface", 1, 0, "TabletButtonsProxyModel");
|
||||||
|
|
|
@ -129,8 +129,9 @@ class TabletButtonsProxyModel : public QSortFilterProxyModel
|
||||||
|
|
||||||
Q_PROPERTY(int pageIndex READ pageIndex WRITE setPageIndex NOTIFY pageIndexChanged)
|
Q_PROPERTY(int pageIndex READ pageIndex WRITE setPageIndex NOTIFY pageIndexChanged)
|
||||||
public:
|
public:
|
||||||
TabletButtonsProxyModel(QObject *parent = 0);
|
TabletButtonsProxyModel(QObject* parent = 0);
|
||||||
int pageIndex() const;
|
int pageIndex() const;
|
||||||
|
Q_INVOKABLE int buttonIndex(const QString& uuid);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setPageIndex(int pageIndex);
|
void setPageIndex(int pageIndex);
|
||||||
|
@ -140,10 +141,9 @@ signals:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
||||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _pageIndex;
|
int _pageIndex { -1 };
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(TabletButtonsProxyModel*);
|
Q_DECLARE_METATYPE(TabletButtonsProxyModel*);
|
||||||
|
|
Loading…
Reference in a new issue