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

View file

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

View file

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

View file

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

View file

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

View file

@ -11,6 +11,7 @@ Flickable {
} 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.returnToBounds()
}
clip: true

View file

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

View file

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

View file

@ -50,28 +50,44 @@ Item {
Keys.onBacktabPressed: {
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
implicitHeight: content.implicitHeight + content.anchors.leftMargin + content.anchors.rightMargin
// onFocusChanged: {
// if (root.activeFocus) {
// if (root.parentFlickable) {
// root.parentFlickable.ensureVisible(root)
// }
// }
// }
onFocusChanged: {
if (root.activeFocus) {
if (root.parentFlickable) {
root.parentFlickable.ensureVisible(root)
}
}
}
// Connections {
// target: rightImage
// function onFocusChanged() {
// if (rightImage.activeFocus) {
// if (root.parentFlickable) {
// root.parentFlickable.ensureVisible(root)
// }
// }
// }
// }
Connections {
target: rightImage
function onFocusChanged() {
if (rightImage.activeFocus) {
if (root.parentFlickable) {
root.parentFlickable.ensureVisible(root)
}
}
}
}
MouseArea {
anchors.fill: parent

View file

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

View file

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

View file

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

View file

@ -16,13 +16,29 @@ TabButton {
property bool isFocusable: true
Keys.onTabPressed: {
FocusController.nextKeyTabItem()
}
Keys.onTabPressed: {
FocusController.nextKeyTabItem()
}
Keys.onBacktabPressed: {
FocusController.previousKeyTabItem()
}
Keys.onBacktabPressed: {
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 int borderFocusedWidth: 1
@ -30,7 +46,6 @@ TabButton {
property var clickedFunc
hoverEnabled: true
// focusPolicy: Qt.TabFocus
icon.source: image
icon.color: isSelected ? selectedColor : defaultColor
@ -53,7 +68,6 @@ TabButton {
}
Keys.onEnterPressed: {
console.log("$$$$$$$$$ ENTER PRESSED INSIDE TABIMAGEBUTTONTYPE")
if (root.clickedFunc && typeof root.clickedFunc === "function") {
root.clickedFunc()
}

View file

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

View file

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