more work on clicking focus

This commit is contained in:
ZappoMan 2015-08-17 13:06:32 -07:00
parent 8cf450cb67
commit b7d9dc444b
5 changed files with 33 additions and 10 deletions

View file

@ -673,12 +673,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
auto& packetReceiver = nodeList->getPacketReceiver(); auto& packetReceiver = nodeList->getPacketReceiver();
packetReceiver.registerListener(PacketType::DomainConnectionDenied, this, "handleDomainConnectionDeniedPacket"); packetReceiver.registerListener(PacketType::DomainConnectionDenied, this, "handleDomainConnectionDeniedPacket");
// If the user clicks an an entity, we will check that it's an unlocked web entity, and if so, set the focus to it
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
connect(entityScriptingInterface.data(), &EntityScriptingInterface::clickDownOnEntity, connect(entityScriptingInterface.data(), &EntityScriptingInterface::clickDownOnEntity,
[this, entityScriptingInterface](const EntityItemID& entityItemID, const MouseEvent& event) { [this, entityScriptingInterface](const EntityItemID& entityItemID, const MouseEvent& event) {
if (_keyboardFocusedItem != entityItemID) { if (_keyboardFocusedItem != entityItemID) {
_keyboardFocusedItem = UNKNOWN_ENTITY_ID; _keyboardFocusedItem = UNKNOWN_ENTITY_ID;
qDebug() << "_keyboardFocusedItem:" << UNKNOWN_ENTITY_ID; qDebug() << "clickDownOnEntity.... _keyboardFocusedItem:" << UNKNOWN_ENTITY_ID;
auto properties = entityScriptingInterface->getEntityProperties(entityItemID); auto properties = entityScriptingInterface->getEntityProperties(entityItemID);
if (EntityTypes::Web == properties.getType() && !properties.getLocked()) { if (EntityTypes::Web == properties.getType() && !properties.getLocked()) {
auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(entityItemID); auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(entityItemID);
@ -686,21 +687,19 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
if (webEntity) { if (webEntity) {
webEntity->setProxyWindow(_window->windowHandle()); webEntity->setProxyWindow(_window->windowHandle());
_keyboardFocusedItem = entityItemID; _keyboardFocusedItem = entityItemID;
qDebug() << "_keyboardFocusedItem:" << entityItemID; _lastAcceptedKeyPress = usecTimestampNow();
qDebug() << "clickDownOnEntity.... _keyboardFocusedItem:" << entityItemID;
} }
} }
} }
}); });
/* // If the user clicks somewhere where there is NO entity at all, we will release focus
// FIXME - need a solution for unfocusing on delayed time connect(getEntities(), &EntityTreeRenderer::mousePressOffEntity,
connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverLeaveEntity, [=](const EntityItemID& entityItemID, const MouseEvent& event) { [=](const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId) {
if (_keyboardFocusedItem == entityItemID) {
_keyboardFocusedItem = UNKNOWN_ENTITY_ID; _keyboardFocusedItem = UNKNOWN_ENTITY_ID;
qDebug() << "_keyboardFocusedItem:" << UNKNOWN_ENTITY_ID; qDebug() << "mousePressOffEntity... _keyboardFocusedItem:" << UNKNOWN_ENTITY_ID;
}
}); });
*/
} }
void Application::aboutToQuit() { void Application::aboutToQuit() {
@ -1277,6 +1276,7 @@ bool Application::event(QEvent* event) {
event->setAccepted(false); event->setAccepted(false);
QCoreApplication::sendEvent(webEntity->getEventHandler(), event); QCoreApplication::sendEvent(webEntity->getEventHandler(), event);
if (event->isAccepted()) { if (event->isAccepted()) {
_lastAcceptedKeyPress = usecTimestampNow();
return true; return true;
} }
} }
@ -1286,6 +1286,16 @@ bool Application::event(QEvent* event) {
default: default:
break; break;
} }
const quint64 LOSE_FOCUS_AFTER_ELAPSED_TIME = 30 * USECS_PER_SECOND; // if idle for 30 seconds, drop focus
quint64 elapsedSinceAcceptedKeyPress = usecTimestampNow() - _lastAcceptedKeyPress;
if (elapsedSinceAcceptedKeyPress > LOSE_FOCUS_AFTER_ELAPSED_TIME) {
_keyboardFocusedItem = UNKNOWN_ENTITY_ID;
qDebug() << "idle for 30 seconds.... _keyboardFocusedItem:" << UNKNOWN_ENTITY_ID;
} else {
qDebug() << "elapsedSinceAcceptedKeyPress:" << elapsedSinceAcceptedKeyPress;
}
} }
switch (event->type()) { switch (event->type()) {

View file

@ -680,6 +680,7 @@ private:
DialogsManagerScriptingInterface* _dialogsManagerScriptingInterface = new DialogsManagerScriptingInterface(); DialogsManagerScriptingInterface* _dialogsManagerScriptingInterface = new DialogsManagerScriptingInterface();
EntityItemID _keyboardFocusedItem; EntityItemID _keyboardFocusedItem;
quint64 _lastAcceptedKeyPress = 0;
}; };
#endif // hifi_Application_h #endif // hifi_Application_h

View file

@ -861,6 +861,8 @@ void EntityTreeRenderer::mousePressEvent(QMouseEvent* event, unsigned int device
if (entityScript.property("clickDownOnEntity").isValid()) { if (entityScript.property("clickDownOnEntity").isValid()) {
entityScript.property("clickDownOnEntity").call(entityScript, entityScriptArgs); entityScript.property("clickDownOnEntity").call(entityScript, entityScriptArgs);
} }
} else {
emit mousePressOffEntity(rayPickResult, event, deviceID);
} }
_lastMouseEvent = MouseEvent(*event, deviceID); _lastMouseEvent = MouseEvent(*event, deviceID);
_lastMouseEventValid = true; _lastMouseEventValid = true;

View file

@ -95,6 +95,7 @@ public:
signals: signals:
void mousePressOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId); void mousePressOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId);
void mousePressOffEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId);
void mouseMoveOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId); void mouseMoveOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId);
void mouseReleaseOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId); void mouseReleaseOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId);

View file

@ -56,6 +56,15 @@ RenderableWebEntityItem::~RenderableWebEntityItem() {
} }
void RenderableWebEntityItem::render(RenderArgs* args) { void RenderableWebEntityItem::render(RenderArgs* args) {
// debug bounds on mac.
{
gpu::Batch& batch = *args->_batch;
batch.setModelTransform(getTransformToCenter()); // we want to include the scale as well
glm::vec4 cubeColor{ 1.0f, 0.0f, 0.0f, 1.0f};
DependencyManager::get<DeferredLightingEffect>()->renderWireCube(batch, 1.0f, cubeColor);
}
QOpenGLContext * currentContext = QOpenGLContext::currentContext(); QOpenGLContext * currentContext = QOpenGLContext::currentContext();
QSurface * currentSurface = currentContext->surface(); QSurface * currentSurface = currentContext->surface();
if (!_webSurface) { if (!_webSurface) {