format FocusController
This commit is contained in:
parent
a57e94e4f2
commit
11d20974f0
2 changed files with 56 additions and 69 deletions
|
|
@ -1,10 +1,7 @@
|
||||||
#include "focusController.h"
|
#include "focusController.h"
|
||||||
|
|
||||||
#include "listViewFocusController.h"
|
|
||||||
|
|
||||||
#include <QQuickWindow>
|
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
|
#include <QQuickWindow>
|
||||||
|
|
||||||
bool isListView(QObject *item)
|
bool isListView(QObject *item)
|
||||||
{
|
{
|
||||||
|
|
@ -39,7 +36,8 @@ bool isOnTheScene(QObject* object)
|
||||||
}
|
}
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,11 +52,7 @@ QList<QObject*> getSubChain(QObject* object)
|
||||||
const auto children = object->children();
|
const auto children = object->children();
|
||||||
|
|
||||||
for (const auto child : children) {
|
for (const auto child : children) {
|
||||||
if (child
|
if (child && focusControlTools::isFocusable(child) && isOnTheScene(child) && focusControlTools::isEnabled(child)) {
|
||||||
&& isFocusable(child)
|
|
||||||
&& isOnTheScene(child)
|
|
||||||
&& isEnabled(child)
|
|
||||||
) {
|
|
||||||
res.append(child);
|
res.append(child);
|
||||||
} else {
|
} else {
|
||||||
res.append(getSubChain(child));
|
res.append(getSubChain(child));
|
||||||
|
|
@ -68,15 +62,16 @@ QList<QObject*> getSubChain(QObject* object)
|
||||||
}
|
}
|
||||||
|
|
||||||
FocusController::FocusController(QQmlApplicationEngine *engine, QObject *parent)
|
FocusController::FocusController(QQmlApplicationEngine *engine, QObject *parent)
|
||||||
: QObject{parent}
|
: QObject { parent },
|
||||||
, m_engine{engine}
|
m_engine { engine },
|
||||||
, m_focusChain{}
|
m_focusChain {},
|
||||||
, m_focusedItem{nullptr}
|
m_focusedItem { nullptr },
|
||||||
, m_rootObjects{}
|
m_rootObjects {},
|
||||||
, m_defaultFocusItem{QSharedPointer<QQuickItem>()}
|
m_defaultFocusItem { QSharedPointer<QQuickItem>() },
|
||||||
, m_lvfc{nullptr}
|
m_lvfc { nullptr }
|
||||||
{
|
{
|
||||||
QObject::connect(m_engine.get(), &QQmlApplicationEngine::objectCreated, this, [this](QObject *object, const QUrl &url){
|
QObject::connect(m_engine.get(), &QQmlApplicationEngine::objectCreated, this,
|
||||||
|
[this](QObject *object, const QUrl &url) {
|
||||||
QQuickItem *newDefaultFocusItem = object->findChild<QQuickItem *>("defaultFocusItem");
|
QQuickItem *newDefaultFocusItem = object->findChild<QQuickItem *>("defaultFocusItem");
|
||||||
if (newDefaultFocusItem && m_defaultFocusItem != newDefaultFocusItem) {
|
if (newDefaultFocusItem && m_defaultFocusItem != newDefaultFocusItem) {
|
||||||
m_defaultFocusItem.reset(newDefaultFocusItem);
|
m_defaultFocusItem.reset(newDefaultFocusItem);
|
||||||
|
|
@ -84,12 +79,10 @@ FocusController::FocusController(QQmlApplicationEngine* engine, QObject *parent)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(this, &FocusController::focusedItemChanged, this, [this]() {
|
QObject::connect(this, &FocusController::focusedItemChanged, this,
|
||||||
m_focusedItem->forceActiveFocus(Qt::TabFocusReason);
|
[this]() { m_focusedItem->forceActiveFocus(Qt::TabFocusReason); });
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FocusController::nextKeyTabItem()
|
void FocusController::nextKeyTabItem()
|
||||||
{
|
{
|
||||||
nextItem(Direction::Forward);
|
nextItem(Direction::Forward);
|
||||||
|
|
@ -182,9 +175,7 @@ void FocusController::reload(Direction direction)
|
||||||
qDebug() << "===>> Calling < reload >...";
|
qDebug() << "===>> Calling < reload >...";
|
||||||
m_focusChain.clear();
|
m_focusChain.clear();
|
||||||
|
|
||||||
QObject* rootObject = (m_rootObjects.empty()
|
QObject *rootObject = (m_rootObjects.empty() ? m_engine->rootObjects().value(0) : m_rootObjects.top());
|
||||||
? m_engine->rootObjects().value(0)
|
|
||||||
: m_rootObjects.top());
|
|
||||||
|
|
||||||
if (!rootObject) {
|
if (!rootObject) {
|
||||||
qCritical() << "No ROOT OBJECT found!";
|
qCritical() << "No ROOT OBJECT found!";
|
||||||
|
|
@ -197,7 +188,8 @@ void FocusController::reload(Direction direction)
|
||||||
|
|
||||||
m_focusChain.append(getSubChain(rootObject));
|
m_focusChain.append(getSubChain(rootObject));
|
||||||
|
|
||||||
std::sort(m_focusChain.begin(), m_focusChain.end(), direction == Direction::Forward ? isLess : isMore);
|
std::sort(m_focusChain.begin(), m_focusChain.end(),
|
||||||
|
direction == Direction::Forward ? focusControlTools::isLess : focusControlTools::isMore);
|
||||||
|
|
||||||
if (m_focusChain.empty()) {
|
if (m_focusChain.empty()) {
|
||||||
qWarning() << "Focus chain is empty!";
|
qWarning() << "Focus chain is empty!";
|
||||||
|
|
@ -263,7 +255,7 @@ void FocusController::nextItem(Direction direction)
|
||||||
|
|
||||||
setFocusItem(focusedItem);
|
setFocusItem(focusedItem);
|
||||||
|
|
||||||
printItems(m_focusChain, focusedItem);
|
focusControlTools::printItems(m_focusChain, focusedItem);
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,9 @@
|
||||||
#ifndef FOCUSCONTROLLER_H
|
#ifndef FOCUSCONTROLLER_H
|
||||||
#define FOCUSCONTROLLER_H
|
#define FOCUSCONTROLLER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include "ui/controllers/listViewFocusController.h"
|
||||||
#include <QStack>
|
|
||||||
#include <QSharedPointer>
|
|
||||||
|
|
||||||
|
#include <QQmlApplicationEngine>
|
||||||
class QQuickItem;
|
|
||||||
class QQmlApplicationEngine;
|
|
||||||
class ListViewFocusController;
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief The FocusController class makes focus control more straightforward
|
* \brief The FocusController class makes focus control more straightforward
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue