mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 14:18:24 +02:00
Added smart pointer for qml buttons. removed extra modifiers. page changed using left and right buttons
This commit is contained in:
parent
99a6b12828
commit
cdb9d72387
3 changed files with 61 additions and 86 deletions
|
@ -16,11 +16,13 @@ Item {
|
||||||
readonly property int buttonsRowsOnPage: 4
|
readonly property int buttonsRowsOnPage: 4
|
||||||
readonly property int buttonsColumnsOnPage: 3
|
readonly property int buttonsColumnsOnPage: 3
|
||||||
|
|
||||||
|
property var currentGridItems: null
|
||||||
|
|
||||||
focus: true
|
focus: true
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: gridsRecreateTimer
|
id: gridsRecreateTimer
|
||||||
interval: 200
|
interval: 50
|
||||||
repeat: false
|
repeat: false
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
doRecreateGrids()
|
doRecreateGrids()
|
||||||
|
@ -57,6 +59,7 @@ Item {
|
||||||
grid.children[0].children.push(button);
|
grid.children[0].children.push(button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
swipeView.currentIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// used to look up a button by its uuid
|
// used to look up a button by its uuid
|
||||||
|
@ -241,10 +244,29 @@ Item {
|
||||||
SwipeView {
|
SwipeView {
|
||||||
id: swipeView
|
id: swipeView
|
||||||
clip: false
|
clip: false
|
||||||
currentIndex: pageIndicator.currentIndex
|
property int previousIndex: -1
|
||||||
onCurrentIndexChanged: {
|
|
||||||
rowIndex = 0;
|
onCurrentItemChanged: {
|
||||||
columnIndex = 0;
|
if (swipeView.currentIndex < 0
|
||||||
|
|| swipeView.itemAt(swipeView.currentIndex) === null
|
||||||
|
|| swipeView.itemAt(swipeView.currentIndex).children[0] === null
|
||||||
|
|| swipeView.itemAt(swipeView.currentIndex).children[0].children === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentGridItems = swipeView.itemAt(swipeView.currentIndex).children[0].children;
|
||||||
|
|
||||||
|
var row = rowIndex < 0 ? 0 : rowIndex;
|
||||||
|
var column = previousIndex > swipeView.currentIndex ? buttonsColumnsOnPage - 1 : 0;
|
||||||
|
var index = row * buttonsColumnsOnPage + column;
|
||||||
|
if (index < 0 || index >= currentGridItems.length) {
|
||||||
|
column = 0;
|
||||||
|
row = 0;
|
||||||
|
}
|
||||||
|
rowIndex = row;
|
||||||
|
columnIndex = column;
|
||||||
|
setCurrentItemState("hover state");
|
||||||
|
previousIndex = currentIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
|
@ -266,7 +288,7 @@ Item {
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
opacity: index === pageIndicator.currentIndex ? 0.95 : pressed ? 0.7 : 0.45
|
opacity: index === pageIndicator.currentIndex ? 0.95 : 0.45
|
||||||
implicitWidth: index === pageIndicator.currentIndex ? 15 : 10
|
implicitWidth: index === pageIndicator.currentIndex ? 15 : 10
|
||||||
implicitHeight: implicitWidth
|
implicitHeight: implicitWidth
|
||||||
radius: width/2
|
radius: width/2
|
||||||
|
@ -287,44 +309,27 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setCurrentItemState(state) {
|
function setCurrentItemState(state) {
|
||||||
var index = rowIndex*buttonsColumnsOnPage + columnIndex;
|
var buttonIndex = rowIndex * buttonsColumnsOnPage + columnIndex;
|
||||||
var currentGridItems = swipeView.currentItem.children[0].children;
|
if (currentGridItems !== null && buttonIndex >= 0 && buttonIndex < currentGridItems.length) {
|
||||||
if (currentGridItems !== null && index >= 0 && index < currentGridItems.length) {
|
if (currentGridItems[buttonIndex].isActive) {
|
||||||
if (currentGridItems[index].isActive) {
|
currentGridItems[buttonIndex].state = "active state";
|
||||||
currentGridItems[index].state = "active state";
|
|
||||||
} else {
|
} else {
|
||||||
currentGridItems[index].state = state;
|
currentGridItems[buttonIndex].state = state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function previousPage() {
|
|
||||||
setCurrentItemState("base state");
|
|
||||||
var currentPage = swipeView.currentIndex;
|
|
||||||
currentPage = currentPage - 1;
|
|
||||||
if (currentPage < 0) {
|
|
||||||
currentPage = swipeView.count - 1;
|
|
||||||
}
|
|
||||||
swipeView.currentIndex = currentPage;
|
|
||||||
}
|
|
||||||
|
|
||||||
function nextPage() {
|
|
||||||
setCurrentItemState("base state");
|
|
||||||
var currentPage = swipeView.currentIndex;
|
|
||||||
currentPage = currentPage + 1;
|
|
||||||
if (currentPage >= swipeView.count) {
|
|
||||||
currentPage = 0;
|
|
||||||
}
|
|
||||||
swipeView.currentIndex = currentPage;
|
|
||||||
}
|
|
||||||
|
|
||||||
function nextItem() {
|
function nextItem() {
|
||||||
setCurrentItemState("base state");
|
setCurrentItemState("base state");
|
||||||
var currentGridItems = swipeView.currentItem.children[0].children;
|
|
||||||
var nextColumnIndex = columnIndex + 1;
|
var nextColumnIndex = columnIndex + 1;
|
||||||
var index = rowIndex*buttonsColumnsOnPage + nextColumnIndex;
|
var index = rowIndex * buttonsColumnsOnPage + nextColumnIndex;
|
||||||
if(index >= currentGridItems.length || nextColumnIndex >= buttonsColumnsOnPage) {
|
if (index >= currentGridItems.length || nextColumnIndex >= buttonsColumnsOnPage) {
|
||||||
nextColumnIndex = 0;
|
if (swipeView.currentIndex < swipeView.count - 1) {
|
||||||
|
swipeView.incrementCurrentIndex();
|
||||||
|
} else {
|
||||||
|
setCurrentItemState("hover state");
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
columnIndex = nextColumnIndex;
|
columnIndex = nextColumnIndex;
|
||||||
setCurrentItemState("hover state");
|
setCurrentItemState("hover state");
|
||||||
|
@ -332,17 +337,15 @@ Item {
|
||||||
|
|
||||||
function previousItem() {
|
function previousItem() {
|
||||||
setCurrentItemState("base state");
|
setCurrentItemState("base state");
|
||||||
var column = columnIndex;
|
var column = columnIndex - 1;
|
||||||
column = column - 1;
|
|
||||||
|
|
||||||
if (column < 0 ) {
|
if (column < 0) {
|
||||||
column = buttonsColumnsOnPage - 1;
|
if (swipeView.currentIndex > 0) {
|
||||||
var index = rowIndex*buttonsColumnsOnPage + column;
|
swipeView.decrementCurrentIndex();
|
||||||
var currentGridItems = swipeView.currentItem.children[0].children;
|
} else {
|
||||||
while(index >= currentGridItems.length) {
|
setCurrentItemState("hover state");
|
||||||
column = column - 1;
|
|
||||||
index = rowIndex*buttonsColumnsOnPage + column;
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
columnIndex = column;
|
columnIndex = column;
|
||||||
setCurrentItemState("hover state");
|
setCurrentItemState("hover state");
|
||||||
|
@ -350,16 +353,14 @@ Item {
|
||||||
|
|
||||||
function upItem() {
|
function upItem() {
|
||||||
setCurrentItemState("base state");
|
setCurrentItemState("base state");
|
||||||
var row = rowIndex;
|
var row = rowIndex - 1;
|
||||||
row = row - 1;
|
|
||||||
|
|
||||||
if (row < 0 ) {
|
if (row < 0 ) {
|
||||||
row = buttonsRowsOnPage - 1;
|
row = buttonsRowsOnPage - 1;
|
||||||
var index = row*buttonsColumnsOnPage + columnIndex;
|
var index = row * buttonsColumnsOnPage + columnIndex;
|
||||||
var currentGridItems = swipeView.currentItem.children[0].children;
|
while (index >= currentGridItems.length) {
|
||||||
while(index >= currentGridItems.length) {
|
|
||||||
row = row - 1;
|
row = row - 1;
|
||||||
index = row*buttonsColumnsOnPage + columnIndex;
|
index = row * buttonsColumnsOnPage + columnIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rowIndex = row;
|
rowIndex = row;
|
||||||
|
@ -369,8 +370,7 @@ Item {
|
||||||
function downItem() {
|
function downItem() {
|
||||||
setCurrentItemState("base state");
|
setCurrentItemState("base state");
|
||||||
rowIndex = rowIndex + 1;
|
rowIndex = rowIndex + 1;
|
||||||
var currentGridItems = swipeView.currentItem.children[0].children;
|
var index = rowIndex * buttonsColumnsOnPage + columnIndex;
|
||||||
var index = rowIndex*buttonsColumnsOnPage + columnIndex;
|
|
||||||
if (index >= currentGridItems.length) {
|
if (index >= currentGridItems.length) {
|
||||||
rowIndex = 0;
|
rowIndex = 0;
|
||||||
}
|
}
|
||||||
|
@ -379,7 +379,6 @@ Item {
|
||||||
|
|
||||||
function selectItem() {
|
function selectItem() {
|
||||||
var index = rowIndex*buttonsColumnsOnPage + columnIndex;
|
var index = rowIndex*buttonsColumnsOnPage + columnIndex;
|
||||||
var currentGridItems = swipeView.currentItem.children[0].children;
|
|
||||||
if (currentGridItems !== null && index >= 0 && index < currentGridItems.length) {
|
if (currentGridItems !== null && index >= 0 && index < currentGridItems.length) {
|
||||||
currentGridItems[index].clicked();
|
currentGridItems[index].clicked();
|
||||||
if (tabletRoot) {
|
if (tabletRoot) {
|
||||||
|
@ -388,33 +387,9 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Keys.onRightPressed: {
|
Keys.onRightPressed: nextItem();
|
||||||
if (event.modifiers & Qt.ShiftModifier) {
|
Keys.onLeftPressed: previousItem();
|
||||||
nextPage();
|
Keys.onDownPressed: downItem();
|
||||||
} else {
|
Keys.onUpPressed: upItem();
|
||||||
nextItem();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Keys.onLeftPressed: {
|
|
||||||
if (event.modifiers & Qt.ShiftModifier) {
|
|
||||||
previousPage();
|
|
||||||
} else {
|
|
||||||
previousItem();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Keys.onDownPressed: {
|
|
||||||
if (event.modifiers & Qt.ShiftModifier) {
|
|
||||||
nextPage();
|
|
||||||
} else {
|
|
||||||
downItem();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Keys.onUpPressed: {
|
|
||||||
if (event.modifiers & Qt.ShiftModifier) {
|
|
||||||
previousPage();
|
|
||||||
} else {
|
|
||||||
upItem();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Keys.onReturnPressed: selectItem();
|
Keys.onReturnPressed: selectItem();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1008,6 +1008,6 @@ void TabletButtonProxy::editProperties(const QVariantMap& properties) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QQuickItem *TabletButtonProxy::getQmlButton() const {
|
QPointer<QQuickItem> TabletButtonProxy::getQmlButton() const {
|
||||||
return _qmlButton;
|
return _qmlButton;
|
||||||
}
|
}
|
||||||
|
|
|
@ -305,7 +305,7 @@ public:
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE void editProperties(const QVariantMap& properties);
|
Q_INVOKABLE void editProperties(const QVariantMap& properties);
|
||||||
|
|
||||||
QQuickItem *getQmlButton() const;
|
QPointer<QQuickItem> getQmlButton() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void clickedSlot() { emit clicked(); }
|
void clickedSlot() { emit clicked(); }
|
||||||
|
@ -321,7 +321,7 @@ signals:
|
||||||
protected:
|
protected:
|
||||||
QUuid _uuid;
|
QUuid _uuid;
|
||||||
int _stableOrder;
|
int _stableOrder;
|
||||||
QQuickItem* _qmlButton { nullptr };
|
QPointer<QQuickItem> _qmlButton;
|
||||||
QObject* _toolbarButtonProxy { nullptr };
|
QObject* _toolbarButtonProxy { nullptr };
|
||||||
QVariantMap _properties;
|
QVariantMap _properties;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue