add more key handlers

This commit is contained in:
Cyril Anisimov 2024-09-19 15:00:01 +02:00
parent 02bbcd3a31
commit cecee3769e
15 changed files with 228 additions and 76 deletions

View file

@ -18,7 +18,6 @@ bool isVisible(QObject* item)
bool isFocusable(QObject* item) bool isFocusable(QObject* item)
{ {
const auto res = item->property("isFocusable").toBool(); const auto res = item->property("isFocusable").toBool();
// qDebug() << "==>> " << (res ? "FOCUSABLE" : "NOT focusable") << item;
return res; return res;
} }
@ -60,28 +59,23 @@ bool isOnTheScene(QObject* object)
return false; return false;
} }
QRectF itemRect{}; // TODO: ListView couln't get into list because it's children's rect is too large QRectF itemRect = item->mapRectToScene(item->childrenRect());
// if (isListView(item)) {
// itemRect = QRectF(item->x(), item->y(), item->width(), item->height());
// } else {
itemRect = item->mapRectToScene(item->childrenRect());
// }
QQuickWindow* window = item->window(); QQuickWindow* window = item->window();
if (!window) { if (!window) {
qWarning() << "Couldn't get the window on the Scene check"; qWarning() << "Couldn't get the window on the Scene check";
return false; return false;
} }
// const auto contentItem = window->contentItem(); const auto contentItem = window->contentItem();
// if (!contentItem) { if (!contentItem) {
// qWarning() << "Couldn't get the content item on the Scene check"; qWarning() << "Couldn't get the content item on the Scene check";
// return false; return false;
// } }
// QRectF windowRect = contentItem->childrenRect(); QRectF windowRect = contentItem->childrenRect();
// const auto res = (windowRect.contains(itemRect) || isListView(item)); const auto res = (windowRect.contains(itemRect) || isListView(item));
// // qDebug() << (res ? "===>> item is inside the Scene" : "===>> ITEM IS OUTSIDE THE SCENE") << " itemRect: " << itemRect << "; windowRect: " << windowRect; // qDebug() << (res ? "===>> item is inside the Scene" : "===>> ITEM IS OUTSIDE THE SCENE") << " itemRect: " << itemRect << "; windowRect: " << windowRect;
// return res; return res;
return true;
} }
bool isEnabled(QObject* obj) bool isEnabled(QObject* obj)
@ -98,7 +92,6 @@ QQuickItem* getPageOfItem(QQuickItem* item) // TODO: remove?
} }
const auto pagePattern = QString::fromLatin1("Page"); const auto pagePattern = QString::fromLatin1("Page");
QString className{item->metaObject()->className()}; QString className{item->metaObject()->className()};
qDebug() << "=====================>> Item: " << item << " with name: " << item->metaObject()->className();
const auto isPage = className.contains(pagePattern, Qt::CaseSensitive); const auto isPage = className.contains(pagePattern, Qt::CaseSensitive);
if(isPage) { if(isPage) {
return item; return item;
@ -122,9 +115,7 @@ QList<QObject*> getSubChain(QObject* item)
&& isEnabled(child) && isEnabled(child)
) { ) {
res.append(child); res.append(child);
// qDebug() << "==>> [*** added ***] " << qobject_cast<QQuickItem*>(child);
} else { } else {
// qDebug() << "==>> [** skipped **] " << qobject_cast<QQuickItem*>(child);
res.append(getSubChain(child)); res.append(getSubChain(child));
} }
} }
@ -134,14 +125,12 @@ QList<QObject*> getSubChain(QObject* item)
template<typename T> template<typename T>
void printItems(const T& items, QObject* current_item) void printItems(const T& items, QObject* current_item)
{ {
qDebug() << "**********************************************";
for(const auto& item : items) { for(const auto& item : items) {
QQuickItem* i = qobject_cast<QQuickItem*>(item); QQuickItem* i = qobject_cast<QQuickItem*>(item);
QPointF coords {getItemCenterPointOnScene(i)}; QPointF coords {getItemCenterPointOnScene(i)};
QString prefix = current_item == i ? "==>" : " "; QString prefix = current_item == i ? "==>" : " ";
qDebug() << prefix << " Item: " << i << " with coords: " << coords; // qDebug() << prefix << " Item: " << i << " with coords: " << coords; // Uncomment to visualize tab transitions
} }
qDebug() << "**********************************************";
} }
/*! /*!
@ -308,7 +297,7 @@ void FocusController::resetFocus()
void FocusController::nextKeyTabItem() void FocusController::nextKeyTabItem()
{ {
if (m_lvfc) { if (m_lvfc) {
focusNextListViewItem(); // Need to go on first element by default? focusNextListViewItem();
return; return;
} }
@ -335,7 +324,6 @@ void FocusController::nextKeyTabItem()
} }
if(isListView(m_focusedItem)) { if(isListView(m_focusedItem)) {
qDebug() << "===>> Found ListView Item: " << m_focusedItem; // TODO: remove?
m_lvfc = new ListViewFocusController(m_focusedItem, this); m_lvfc = new ListViewFocusController(m_focusedItem, this);
focusNextListViewItem(); focusNextListViewItem();
return; return;
@ -387,22 +375,22 @@ void FocusController::previousKeyTabItem()
void FocusController::nextKeyUpItem() void FocusController::nextKeyUpItem()
{ {
qDebug() << "nextKeyUpItem" << "triggered"; previousKeyTabItem();
} }
void FocusController::nextKeyDownItem() void FocusController::nextKeyDownItem()
{ {
qDebug() << "nextKeyDownItem" << "triggered"; nextKeyTabItem();
} }
void FocusController::nextKeyLeftItem() void FocusController::nextKeyLeftItem()
{ {
qDebug() << "nextKeyLeftItem" << "triggered"; previousKeyTabItem();
} }
void FocusController::nextKeyRightItem() void FocusController::nextKeyRightItem()
{ {
qDebug() << "nextKeyRightItem" << "triggered"; nextKeyTabItem();
} }
void FocusController::reload() void FocusController::reload()
@ -414,10 +402,8 @@ void FocusController::reload()
const auto rootItem = m_rootItem; const auto rootItem = m_rootItem;
if (rootItem != nullptr) { if (rootItem != nullptr) {
qDebug() << "*** root item: " << rootItem;
rootObjects << qobject_cast<QObject*>(rootItem); rootObjects << qobject_cast<QObject*>(rootItem);
} else { } else {
qDebug() << "*** root item is null";
rootObjects = m_engine->rootObjects(); rootObjects = m_engine->rootObjects();
} }
@ -453,14 +439,10 @@ void FocusController::reload()
return; return;
} }
// qDebug() << "==> Active Focused Item: " << window->activeFocusItem();
// qDebug() << "--> Active Focused Object: " << window->focusObject();
// qDebug() << ">>> Current Focused Item: " << m_focused_item;
m_focusedItemIndex = m_focusChain.indexOf(window->activeFocusItem()); m_focusedItemIndex = m_focusChain.indexOf(window->activeFocusItem());
if(m_focusedItemIndex == -1) { if(m_focusedItemIndex == -1) {
qDebug() << "===>> No focus item in chain. Moving focus to begin..."; qInfo() << "No focus item in chain. Moving focus to begin...";
// m_focused_item_index = 0; // if not in focus chain current // m_focused_item_index = 0; // if not in focus chain current
return; return;
} }

View file

@ -25,7 +25,23 @@ Button {
Keys.onBacktabPressed: { Keys.onBacktabPressed: {
FocusController.previousKeyTabItem() FocusController.previousKeyTabItem()
} }
Keys.onUpPressed: {
FocusController.nextKeyUpItem()
}
Keys.onDownPressed: {
FocusController.nextKeyDownItem()
}
Keys.onLeftPressed: {
FocusController.nextKeyLeftItem()
}
Keys.onRightPressed: {
FocusController.nextKeyRightItem()
}
implicitWidth: 190 implicitWidth: 190
implicitHeight: 190 implicitHeight: 190

View file

@ -46,6 +46,14 @@ ListView {
FocusController.previousKeyTabItem() FocusController.previousKeyTabItem()
} }
Keys.onRightPressed: {
FocusController.nextKeyTabItem()
}
Keys.onLeftPressed: {
FocusController.previousKeyTabItem()
}
// activeFocusOnTab: true // activeFocusOnTab: true
// onActiveFocusChanged: { // onActiveFocusChanged: {
// console.log("===========================") // console.log("===========================")

View file

@ -46,11 +46,9 @@ DrawerType2 {
descriptionText: qsTr("Enabled \nCan't be disabled for current server") descriptionText: qsTr("Enabled \nCan't be disabled for current server")
rightImageSource: "qrc:/images/controls/chevron-right.svg" rightImageSource: "qrc:/images/controls/chevron-right.svg"
// KeyNavigation.tab: siteBasedSplitTunnelingSwitch.visible ? siteBasedSplitTunnelingSwitch.rightButton : focusItem
clickedFunction: function() { clickedFunction: function() {
// PageController.goToPage(PageEnum.PageSettingsSplitTunneling) PageController.goToPage(PageEnum.PageSettingsSplitTunneling)
// root.close() root.close()
} }
} }
@ -67,10 +65,6 @@ DrawerType2 {
descriptionText: enabled && SitesModel.isTunnelingEnabled ? qsTr("Enabled") : qsTr("Disabled") descriptionText: enabled && SitesModel.isTunnelingEnabled ? qsTr("Enabled") : qsTr("Disabled")
rightImageSource: "qrc:/images/controls/chevron-right.svg" rightImageSource: "qrc:/images/controls/chevron-right.svg"
// KeyNavigation.tab: appSplitTunnelingSwitch.visible ?
// appSplitTunnelingSwitch.rightButton :
// focusItem
clickedFunction: function() { clickedFunction: function() {
PageController.goToPage(PageEnum.PageSettingsSplitTunneling) PageController.goToPage(PageEnum.PageSettingsSplitTunneling)
root.closeTriggered() root.closeTriggered()
@ -90,8 +84,6 @@ DrawerType2 {
descriptionText: AppSplitTunnelingModel.isTunnelingEnabled ? qsTr("Enabled") : qsTr("Disabled") descriptionText: AppSplitTunnelingModel.isTunnelingEnabled ? qsTr("Enabled") : qsTr("Disabled")
rightImageSource: "qrc:/images/controls/chevron-right.svg" rightImageSource: "qrc:/images/controls/chevron-right.svg"
// KeyNavigation.tab: focusItem
clickedFunction: function() { clickedFunction: function() {
PageController.goToPage(PageEnum.PageSettingsAppSplitTunneling) PageController.goToPage(PageEnum.PageSettingsAppSplitTunneling)
root.closeTriggered() root.closeTriggered()

View file

@ -38,14 +38,28 @@ Button {
property bool isFocusable: true property bool isFocusable: true
Keys.onTabPressed: { Keys.onTabPressed: {
console.debug("--> Tab is pressed on BasicButtonType: ", objectName)
FocusController.nextKeyTabItem() FocusController.nextKeyTabItem()
} }
Keys.onBacktabPressed: { Keys.onBacktabPressed: {
console.debug("--> Shift+Tab is pressed on ", objectName)
FocusController.previousKeyTabItem() FocusController.previousKeyTabItem()
} }
Keys.onUpPressed: {
FocusController.nextKeyUpItem()
}
Keys.onDownPressed: {
FocusController.nextKeyDownItem()
}
Keys.onLeftPressed: {
FocusController.nextKeyLeftItem()
}
Keys.onRightPressed: {
FocusController.nextKeyRightItem()
}
implicitHeight: 56 implicitHeight: 56

View file

@ -11,6 +11,7 @@ Flickable {
} else if (item.y + item.height > fl.contentY + fl.height) { } else if (item.y + item.height > fl.contentY + fl.height) {
fl.contentY = item.y + item.height - fl.height + 40 // 40 is a bottom margin fl.contentY = item.y + item.height - fl.height + 40 // 40 is a bottom margin
} }
fl.returnToBounds()
} }
clip: true clip: true

View file

@ -30,15 +30,29 @@ RadioButton {
property bool isFocusable: true property bool isFocusable: true
Keys.onTabPressed: { Keys.onTabPressed: {
console.debug("--> Tab is pressed on BasicButtonType: ", objectName)
FocusController.nextKeyTabItem() FocusController.nextKeyTabItem()
} }
Keys.onBacktabPressed: { Keys.onBacktabPressed: {
console.debug("--> Shift+Tab is pressed on ", objectName)
FocusController.previousKeyTabItem() FocusController.previousKeyTabItem()
} }
Keys.onUpPressed: {
FocusController.nextKeyUpItem()
}
Keys.onDownPressed: {
FocusController.nextKeyDownItem()
}
Keys.onLeftPressed: {
FocusController.nextKeyLeftItem()
}
Keys.onRightPressed: {
FocusController.nextKeyRightItem()
}
indicator: Rectangle { indicator: Rectangle {
anchors.fill: parent anchors.fill: parent
radius: 16 radius: 16

View file

@ -38,6 +38,22 @@ Button {
FocusController.previousKeyTabItem() FocusController.previousKeyTabItem()
} }
Keys.onUpPressed: {
FocusController.nextKeyUpItem()
}
Keys.onDownPressed: {
FocusController.nextKeyDownItem()
}
Keys.onLeftPressed: {
FocusController.nextKeyLeftItem()
}
Keys.onRightPressed: {
FocusController.nextKeyRightItem()
}
Keys.onEnterPressed: root.clicked() Keys.onEnterPressed: root.clicked()
Keys.onReturnPressed: root.clicked() Keys.onReturnPressed: root.clicked()

View file

@ -50,28 +50,44 @@ Item {
Keys.onBacktabPressed: { Keys.onBacktabPressed: {
FocusController.previousKeyTabItem() FocusController.previousKeyTabItem()
} }
Keys.onUpPressed: {
FocusController.nextKeyUpItem()
}
Keys.onDownPressed: {
FocusController.nextKeyDownItem()
}
Keys.onLeftPressed: {
FocusController.nextKeyLeftItem()
}
Keys.onRightPressed: {
FocusController.nextKeyRightItem()
}
implicitWidth: content.implicitWidth + content.anchors.topMargin + content.anchors.bottomMargin implicitWidth: content.implicitWidth + content.anchors.topMargin + content.anchors.bottomMargin
implicitHeight: content.implicitHeight + content.anchors.leftMargin + content.anchors.rightMargin implicitHeight: content.implicitHeight + content.anchors.leftMargin + content.anchors.rightMargin
// onFocusChanged: { onFocusChanged: {
// if (root.activeFocus) { if (root.activeFocus) {
// if (root.parentFlickable) { if (root.parentFlickable) {
// root.parentFlickable.ensureVisible(root) root.parentFlickable.ensureVisible(root)
// } }
// } }
// } }
// Connections { Connections {
// target: rightImage target: rightImage
// function onFocusChanged() { function onFocusChanged() {
// if (rightImage.activeFocus) { if (rightImage.activeFocus) {
// if (root.parentFlickable) { if (root.parentFlickable) {
// root.parentFlickable.ensureVisible(root) root.parentFlickable.ensureVisible(root)
// } }
// } }
// } }
// } }
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent

View file

@ -43,6 +43,22 @@ ListView {
FocusController.previousKeyTabItem() FocusController.previousKeyTabItem()
} }
Keys.onUpPressed: {
FocusController.nextKeyUpItem()
}
Keys.onDownPressed: {
FocusController.nextKeyDownItem()
}
Keys.onLeftPressed: {
FocusController.nextKeyLeftItem()
}
Keys.onRightPressed: {
FocusController.nextKeyRightItem()
}
ButtonGroup { ButtonGroup {
id: buttonGroup id: buttonGroup
} }

View file

@ -45,10 +45,27 @@ Switch {
FocusController.previousKeyTabItem() FocusController.previousKeyTabItem()
} }
Keys.onUpPressed: {
FocusController.nextKeyUpItem()
}
Keys.onDownPressed: {
FocusController.nextKeyDownItem()
}
Keys.onLeftPressed: {
FocusController.nextKeyLeftItem()
}
Keys.onRightPressed: {
FocusController.nextKeyRightItem()
}
hoverEnabled: enabled ? true : false hoverEnabled: enabled ? true : false
focusPolicy: Qt.TabFocus focusPolicy: Qt.TabFocus
property FlickableType parentFlickable: null property FlickableType parentFlickable: null
onFocusChanged: { onFocusChanged: {
if (root.activeFocus) { if (root.activeFocus) {
if (root.parentFlickable) { if (root.parentFlickable) {

View file

@ -26,6 +26,22 @@ TabButton {
Keys.onBacktabPressed: { Keys.onBacktabPressed: {
FocusController.previousKeyTabItem() FocusController.previousKeyTabItem()
} }
Keys.onUpPressed: {
FocusController.nextKeyUpItem()
}
Keys.onDownPressed: {
FocusController.nextKeyDownItem()
}
Keys.onLeftPressed: {
FocusController.nextKeyLeftItem()
}
Keys.onRightPressed: {
FocusController.nextKeyRightItem()
}
implicitHeight: 48 implicitHeight: 48

View file

@ -16,13 +16,29 @@ TabButton {
property bool isFocusable: true property bool isFocusable: true
Keys.onTabPressed: { Keys.onTabPressed: {
FocusController.nextKeyTabItem() FocusController.nextKeyTabItem()
} }
Keys.onBacktabPressed: { Keys.onBacktabPressed: {
FocusController.previousKeyTabItem() FocusController.previousKeyTabItem()
} }
Keys.onUpPressed: {
FocusController.nextKeyUpItem()
}
Keys.onDownPressed: {
FocusController.nextKeyDownItem()
}
Keys.onLeftPressed: {
FocusController.nextKeyLeftItem()
}
Keys.onRightPressed: {
FocusController.nextKeyRightItem()
}
property string borderFocusedColor: AmneziaStyle.color.paleGray property string borderFocusedColor: AmneziaStyle.color.paleGray
property int borderFocusedWidth: 1 property int borderFocusedWidth: 1
@ -30,7 +46,6 @@ TabButton {
property var clickedFunc property var clickedFunc
hoverEnabled: true hoverEnabled: true
// focusPolicy: Qt.TabFocus
icon.source: image icon.source: image
icon.color: isSelected ? selectedColor : defaultColor icon.color: isSelected ? selectedColor : defaultColor
@ -53,7 +68,6 @@ TabButton {
} }
Keys.onEnterPressed: { Keys.onEnterPressed: {
console.log("$$$$$$$$$ ENTER PRESSED INSIDE TABIMAGEBUTTONTYPE")
if (root.clickedFunc && typeof root.clickedFunc === "function") { if (root.clickedFunc && typeof root.clickedFunc === "function") {
root.clickedFunc() root.clickedFunc()
} }

View file

@ -34,6 +34,26 @@ RadioButton {
FocusController.nextKeyTabItem() FocusController.nextKeyTabItem()
} }
Keys.onBacktabPressed: {
FocusController.previousKeyTabItem()
}
Keys.onUpPressed: {
FocusController.nextKeyUpItem()
}
Keys.onDownPressed: {
FocusController.nextKeyDownItem()
}
Keys.onLeftPressed: {
FocusController.nextKeyLeftItem()
}
Keys.onRightPressed: {
FocusController.nextKeyRightItem()
}
hoverEnabled: true hoverEnabled: true
// focusPolicy: Qt.TabFocus // focusPolicy: Qt.TabFocus

View file

@ -410,6 +410,16 @@ PageType {
ServersListView { ServersListView {
id: serversMenuContent id: serversMenuContent
objectName: "serversMenuContent" objectName: "serversMenuContent"
isFocusable: false
Connections {
target: drawer
function onIsOpenedChanged() {
serversMenuContent.isFocusable = drawer.isOpened
}
}
} }
} }
} }