tabletFocus update

This commit is contained in:
Dante Ruiz 2017-01-17 17:27:37 +00:00
parent d3fa7651c9
commit 9a61b6030b
7 changed files with 81 additions and 61 deletions

View file

@ -3,17 +3,15 @@ import QtGraphicalEffects 1.0
FocusScope {
id: tablet
objectName: "tablet"
focus: true
enabled: true
objectName: "tablet"
property double micLevel: 0.8
property int index: 0
property int count: flowMain.children.length
property int rowIndex: 0
property int columnIndex: 0
property int count: (flowMain.children.length - 1)
width: parent.width
height: parent.height
//property alias currentItem: flowMain.currentItem
// called by C++ code to keep audio bar updated
function setMicLevel(newMicLevel) {
tablet.micLevel = newMicLevel;
@ -182,7 +180,6 @@ FocusScope {
clip: true
Flow {
id: flowMain
focus: true
spacing: 16
anchors.right: parent.right
anchors.rightMargin: 30
@ -192,50 +189,6 @@ FocusScope {
anchors.bottomMargin: 30
anchors.top: parent.top
anchors.topMargin: 30
function setCurrentItemState(state) {
flowMain.children[index].state = state;
}
function nextItem() {
setCurrentItemState("base state");
index = (index + count + 1) % count;
setCurrentItemState("hover state");
console.log("next item at index: " + index);
}
function previousItem() {
setCurrentItemState("base state");
index = (index + count - 1 ) % count;
setCurrentItemState("hover state");
console.log("previous item at index: " + index);
}
function upItem() {
setCurrentItemState("base state");
index = (index + count - 3) % count;
setCurrentItemState("hover state");
console.log("up item at index: " + index);
}
function downItem() {
setCurrentItemState("base state");
index = (index + count + 3) % count;
setCurrentItemState("hover state");
console.log("down item at index :" + index);
}
function selectItem() {
flowMain.children[index].clicked();
if(tabletRoot) {
tabletRoot.playButtonClickSound();
}
}
Keys.onRightPressed: nextItem();
Keys.onLeftPressed: previousItem();
Keys.onDownPressed: downItem();
Keys.onUpPressed: upItem();
Keys.onReturnPressed: selectItem();
}
}
}
@ -260,5 +213,68 @@ FocusScope {
}
}
]
function setCurrentItemState(state) {
var index = rowIndex + columnIndex;
if (index >= 0 && index <= count ) {
flowMain.children[index].state = state;
}
}
function nextItem() {
setCurrentItemState("base state");
if((rowIndex + columnIndex) != count) {
columnIndex = (columnIndex + 3 + 1) % 3
};
setCurrentItemState("hover state");
}
function previousItem() {
setCurrentItemState("base state");
var prevIndex = (columnIndex + 3 - 1) % 3;
if((rowIndex + prevIndex) <= count){
columnIndex = prevIndex;
}
setCurrentItemState("hover state");
}
function upItem() {
setCurrentItemState("base state");
rowIndex = rowIndex - 3;
if (rowIndex < 0 ) {
rowIndex = (count - (count % 3));
var index = rowIndex + columnIndex;
if(index > count) {
rowIndex = rowIndex - 3;
console.log("index: " + (rowIndex +columnIndex));
}
}
console.log("row index: " + rowIndex);
setCurrentItemState("hover state");
}
function downItem() {
setCurrentItemState("base state");
rowIndex = rowIndex + 3;
var index = rowIndex + columnIndex;
if (index > count ) {
rowIndex = 0;
}
setCurrentItemState("hover state");
}
function selectItem() {
flowMain.children[rowIndex + columnIndex].clicked();
if (tabletRoot) {
tabletRoot.playButtonClickSound();
}
}
Keys.onRightPressed: nextItem();
Keys.onLeftPressed: previousItem();
Keys.onDownPressed: downItem();
Keys.onUpPressed: upItem();
Keys.onReturnPressed: selectItem();
}

View file

@ -87,6 +87,10 @@ FocusScope {
}
}
function pop() {
menuPopperUpper.closeLastMenu();
}
function setRootMenu(menu) {
tabletMenu.rootMenu = menu
buildMenu()

View file

@ -13,12 +13,12 @@ import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import "../../styles-uit"
import "."
FocusScope {
id: root
implicitHeight: background.height
implicitWidth: background.width
property alias currentItem: listView.currentItem
property alias model: listView.model
property bool isSubMenu: false
@ -111,7 +111,7 @@ FocusScope {
function previousItem() { currentIndex = (currentIndex + count - 1) % count; }
function nextItem() { currentIndex = (currentIndex + count + 1) % count; }
function selectCurrentItem() { if (currentIndex != -1) root.selected(currentItem.source); }
function previousPage() {console.log("going to previous page"); }
function previousPage() { root.parent.pop(); }
Keys.onUpPressed: previousItem();
Keys.onDownPressed: nextItem();

View file

@ -91,7 +91,6 @@ Item {
breadcrumbText.text = "Menu";
topMenu = null;
offscreenFlags.navigationFocused = false;
//menuRoot.enabled = false;
}
}
@ -100,7 +99,6 @@ Item {
topMenu = newMenu;
topMenu.focus = true;
offscreenFlags.navigationFocused = true;
console.log(offscreenWindow.activeFocusItem);
}
function clearMenus() {
@ -160,7 +158,6 @@ Item {
function popup(parent, items) {
d.clearMenus();
//menuRoot.enabled = true;
d.buildMenu(items, point);
}

View file

@ -1,7 +1,7 @@
import QtQuick 2.0
import Hifi 1.0
Item {
FocusScope {
id: tabletRoot
objectName: "tabletRoot"
property var eventBridge;
@ -26,7 +26,11 @@ Item {
}
function forceFocus() {
console.log(loader.item.objectName);
offscreenWindow.requestActivate();
loader.item.forceActiveFocus();
console.log("----------> adding focus");
console.log("------>Current foucs itrm: " + offscreenWindow.activeFocusItem);
}
Loader {

View file

@ -979,7 +979,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
auto offscreenUi = DependencyManager::get<OffscreenUi>();
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
if (offscreenUi->navigationFocused()) {
qDebug() << "NavigationFocused";
auto actionEnum = static_cast<Action>(action);
int key = Qt::Key_unknown;
static int lastKey = Qt::Key_unknown;
@ -1025,7 +1024,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
auto window = tabletScriptingInterface->getTabletWindow();
if (navAxis && window) {
qDebug() << "Sending input to qml";
if (lastKey != Qt::Key_unknown) {
QKeyEvent event(QEvent::KeyRelease, lastKey, Qt::NoModifier);
sendEvent(window, &event);

View file

@ -215,8 +215,9 @@ void TabletProxy::addButtonsToHomeScreen() {
addButtonProxyToQmlTablet(tablet, buttonProxy.data());
}
auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader");
QObject::disconnect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen()));
QMetaObject::invokeMethod(_qmlTabletRoot, "forceFocus");
qDebug() << "----> INVOKEMETHOD";
QObject::disconnect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen()));
}
QObject* TabletProxy::getTabletSurface() {