History

more work on clicking focus

ZappoMan committed 11 years ago

Commit b7d9dc41 parent 8cf450c5 files · +33 −10Browse files

Showing the changes to interface/src/Application.cpp (1 of 5 files). Show all

Unified · Split

interface/src/Application.cpp+20−10
@@ -673,12 +673,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 672 unmodified lines
673673 auto& packetReceiver = nodeList->getPacketReceiver();
674674 packetReceiver.registerListener(PacketType::DomainConnectionDenied, this, "handleDomainConnectionDeniedPacket");
675675
676+ // 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
676677 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
677678 connect(entityScriptingInterface.data(), &EntityScriptingInterface::clickDownOnEntity,
678679 [this, entityScriptingInterface](const EntityItemID& entityItemID, const MouseEvent& event) {
679680 if (_keyboardFocusedItem != entityItemID) {
680681 _keyboardFocusedItem = UNKNOWN_ENTITY_ID;
681− qDebug() << "_keyboardFocusedItem:" << UNKNOWN_ENTITY_ID;
682+ qDebug() << "clickDownOnEntity.... _keyboardFocusedItem:" << UNKNOWN_ENTITY_ID;
682683 auto properties = entityScriptingInterface->getEntityProperties(entityItemID);
683684 if (EntityTypes::Web == properties.getType() && !properties.getLocked()) {
684685 auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(entityItemID);
@@ -686,21 +687,19 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 1 unmodified line
686687 if (webEntity) {
687688 webEntity->setProxyWindow(_window->windowHandle());
688689 _keyboardFocusedItem = entityItemID;
689− qDebug() << "_keyboardFocusedItem:" << entityItemID;
690+ _lastAcceptedKeyPress = usecTimestampNow();
691+ qDebug() << "clickDownOnEntity.... _keyboardFocusedItem:" << entityItemID;
690692 }
691693 }
692694 }
693695 });
694696
695− /*
696− // FIXME - need a solution for unfocusing on delayed time
697− connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverLeaveEntity, [=](const EntityItemID& entityItemID, const MouseEvent& event) {
698− if (_keyboardFocusedItem == entityItemID) {
699− _keyboardFocusedItem = UNKNOWN_ENTITY_ID;
700− qDebug() << "_keyboardFocusedItem:" << UNKNOWN_ENTITY_ID;
701− }
697+ // If the user clicks somewhere where there is NO entity at all, we will release focus
698+ connect(getEntities(), &EntityTreeRenderer::mousePressOffEntity,
699+ [=](const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId) {
700+ _keyboardFocusedItem = UNKNOWN_ENTITY_ID;
701+ qDebug() << "mousePressOffEntity... _keyboardFocusedItem:" << UNKNOWN_ENTITY_ID;
702702 });
703− */
704703 }
705704
706705 void Application::aboutToQuit() {
@@ -1277,6 +1276,7 @@ bool Application::event(QEvent* event) { · 570 unmodified lines
12771276 event->setAccepted(false);
12781277 QCoreApplication::sendEvent(webEntity->getEventHandler(), event);
12791278 if (event->isAccepted()) {
1279+ _lastAcceptedKeyPress = usecTimestampNow();
12801280 return true;
12811281 }
12821282 }
@@ -1286,6 +1286,16 @@ bool Application::event(QEvent* event) { · 3 unmodified lines
12861286 default:
12871287 break;
12881288 }
1289+
1290+ const quint64 LOSE_FOCUS_AFTER_ELAPSED_TIME = 30 * USECS_PER_SECOND; // if idle for 30 seconds, drop focus
1291+ quint64 elapsedSinceAcceptedKeyPress = usecTimestampNow() - _lastAcceptedKeyPress;
1292+ if (elapsedSinceAcceptedKeyPress > LOSE_FOCUS_AFTER_ELAPSED_TIME) {
1293+ _keyboardFocusedItem = UNKNOWN_ENTITY_ID;
1294+ qDebug() << "idle for 30 seconds.... _keyboardFocusedItem:" << UNKNOWN_ENTITY_ID;
1295+ } else {
1296+ qDebug() << "elapsedSinceAcceptedKeyPress:" << elapsedSinceAcceptedKeyPress;
1297+ }
1298+
12891299 }
12901300
12911301 switch (event->type()) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t