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 "listViewFocusController.h"
|
||||
|
||||
#include <QQuickWindow>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
#include <QQuickWindow>
|
||||
|
||||
bool isListView(QObject *item)
|
||||
{
|
||||
|
|
@ -39,7 +36,8 @@ bool isOnTheScene(QObject* object)
|
|||
}
|
||||
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;
|
||||
// qDebug() << (res ? "===>> item is inside the Scene" : "===>> ITEM IS OUTSIDE THE SCENE") << " itemRect: " <<
|
||||
// itemRect << "; windowRect: " << windowRect;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -54,11 +52,7 @@ QList<QObject*> getSubChain(QObject* object)
|
|||
const auto children = object->children();
|
||||
|
||||
for (const auto child : children) {
|
||||
if (child
|
||||
&& isFocusable(child)
|
||||
&& isOnTheScene(child)
|
||||
&& isEnabled(child)
|
||||
) {
|
||||
if (child && focusControlTools::isFocusable(child) && isOnTheScene(child) && focusControlTools::isEnabled(child)) {
|
||||
res.append(child);
|
||||
} else {
|
||||
res.append(getSubChain(child));
|
||||
|
|
@ -68,15 +62,16 @@ QList<QObject*> getSubChain(QObject* object)
|
|||
}
|
||||
|
||||
FocusController::FocusController(QQmlApplicationEngine *engine, QObject *parent)
|
||||
: QObject{parent}
|
||||
, m_engine{engine}
|
||||
, m_focusChain{}
|
||||
, m_focusedItem{nullptr}
|
||||
, m_rootObjects{}
|
||||
, m_defaultFocusItem{QSharedPointer<QQuickItem>()}
|
||||
, m_lvfc{nullptr}
|
||||
: QObject { parent },
|
||||
m_engine { engine },
|
||||
m_focusChain {},
|
||||
m_focusedItem { nullptr },
|
||||
m_rootObjects {},
|
||||
m_defaultFocusItem { QSharedPointer<QQuickItem>() },
|
||||
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");
|
||||
if (newDefaultFocusItem && m_defaultFocusItem != newDefaultFocusItem) {
|
||||
m_defaultFocusItem.reset(newDefaultFocusItem);
|
||||
|
|
@ -84,12 +79,10 @@ FocusController::FocusController(QQmlApplicationEngine* engine, QObject *parent)
|
|||
}
|
||||
});
|
||||
|
||||
QObject::connect(this, &FocusController::focusedItemChanged, this, [this]() {
|
||||
m_focusedItem->forceActiveFocus(Qt::TabFocusReason);
|
||||
});
|
||||
QObject::connect(this, &FocusController::focusedItemChanged, this,
|
||||
[this]() { m_focusedItem->forceActiveFocus(Qt::TabFocusReason); });
|
||||
}
|
||||
|
||||
|
||||
void FocusController::nextKeyTabItem()
|
||||
{
|
||||
nextItem(Direction::Forward);
|
||||
|
|
@ -182,9 +175,7 @@ void FocusController::reload(Direction direction)
|
|||
qDebug() << "===>> Calling < reload >...";
|
||||
m_focusChain.clear();
|
||||
|
||||
QObject* rootObject = (m_rootObjects.empty()
|
||||
? m_engine->rootObjects().value(0)
|
||||
: m_rootObjects.top());
|
||||
QObject *rootObject = (m_rootObjects.empty() ? m_engine->rootObjects().value(0) : m_rootObjects.top());
|
||||
|
||||
if (!rootObject) {
|
||||
qCritical() << "No ROOT OBJECT found!";
|
||||
|
|
@ -197,7 +188,8 @@ void FocusController::reload(Direction direction)
|
|||
|
||||
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()) {
|
||||
qWarning() << "Focus chain is empty!";
|
||||
|
|
@ -263,7 +255,7 @@ void FocusController::nextItem(Direction direction)
|
|||
|
||||
setFocusItem(focusedItem);
|
||||
|
||||
printItems(m_focusChain, focusedItem);
|
||||
focusControlTools::printItems(m_focusChain, focusedItem);
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,9 @@
|
|||
#ifndef FOCUSCONTROLLER_H
|
||||
#define FOCUSCONTROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QStack>
|
||||
#include <QSharedPointer>
|
||||
#include "ui/controllers/listViewFocusController.h"
|
||||
|
||||
|
||||
class QQuickItem;
|
||||
class QQmlApplicationEngine;
|
||||
class ListViewFocusController;
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
/*!
|
||||
* \brief The FocusController class makes focus control more straightforward
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue