Support a 'nav focus' state to allow joystick / hydra navigation of UI

This commit is contained in:
Brad Davis 2015-12-30 17:13:20 -08:00
parent e863d4edee
commit af132e267f
2 changed files with 42 additions and 0 deletions

View file

@ -142,4 +142,44 @@ void OffscreenUi::error(const QString& text) {
OffscreenUi::ButtonCallback OffscreenUi::NO_OP_CALLBACK = [](QMessageBox::StandardButton) {};
static const char * const NAVIGATION_FOCUSED_PROPERTY = "NavigationFocused";
class OffscreenFlags : public QObject{
Q_OBJECT
Q_PROPERTY(bool navigationFocused READ isNavigationFocused WRITE setNavigationFocused NOTIFY navigationFocusedChanged)
public:
OffscreenFlags(QObject* parent = nullptr) : QObject(parent) {}
bool isNavigationFocused() const { return _navigationFocused; }
void setNavigationFocused(bool focused) {
if (_navigationFocused != focused) {
_navigationFocused = focused;
emit navigationFocusedChanged();
}
}
signals:
void navigationFocusedChanged();
private:
bool _navigationFocused { false };
};
OffscreenFlags* getFlags(QQmlContext* context) {
static OffscreenFlags* offscreenFlags { nullptr };
if (!offscreenFlags) {
offscreenFlags = new OffscreenFlags(context);
context->setContextProperty("OffscreenFlags", offscreenFlags);
}
return offscreenFlags;
}
bool OffscreenUi::navigationFocused() {
return getFlags(getRootContext())->isNavigationFocused();
}
void OffscreenUi::setNavigationFocused(bool focused) {
getFlags(getRootContext())->setNavigationFocused(focused);
}
#include "OffscreenUi.moc"

View file

@ -29,6 +29,8 @@ public:
void show(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {});
void toggle(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {});
bool shouldSwallowShortcut(QEvent* event);
bool navigationFocused();
void setNavigationFocused(bool focused);
// Messagebox replacement functions
using ButtonCallback = std::function<void(QMessageBox::StandardButton)>;