\r
CV_IMPL int cvWaitKey(int delay)\r
{\r
- int result = -1;\r
+ int result = -1;\r
\r
- if (!guiMainThread)\r
- return result;\r
+ if (!guiMainThread)\r
+ return result;\r
\r
unsigned long delayms = delay <= 0 ? ULONG_MAX : delay; //in milliseconds\r
\r
- if (multiThreads)\r
- {\r
- mutexKey.lock();\r
- if (key_pressed.wait(&mutexKey, delayms)) //false if timeout\r
- {\r
- result = last_key;\r
- }\r
- last_key = -1;\r
- mutexKey.unlock();\r
- }\r
+ if (multiThreads)\r
+ {\r
+ mutexKey.lock();\r
+ if (key_pressed.wait(&mutexKey, delayms)) //false if timeout\r
+ {\r
+ result = last_key;\r
+ }\r
+ last_key = -1;\r
+ mutexKey.unlock();\r
+ }\r
else\r
{\r
- //cannot use wait here because events will not be distributed before processEvents (the main eventLoop is broken)\r
- //so I create a Thread for the QTimer\r
+ //cannot use wait here because events will not be distributed before processEvents (the main eventLoop is broken)\r
+ //so I create a Thread for the QTimer\r
\r
- if (delay > 0)\r
- guiMainThread->timer->start(delay);\r
+ if (delay > 0)\r
+ guiMainThread->timer->start(delay);\r
\r
- //QMutex dummy;\r
+ //QMutex dummy;\r
\r
- while (!guiMainThread->bTimeOut)\r
- {\r
- qApp->processEvents(QEventLoop::AllEvents);\r
-\r
- if (!guiMainThread)//when all the windows are deleted\r
- return result;\r
-\r
- mutexKey.lock();\r
- if (last_key != -1)\r
- {\r
- result = last_key;\r
- last_key = -1;\r
- guiMainThread->timer->stop();\r
- //printf("keypressed\n");\r
- }\r
- mutexKey.unlock();\r
-\r
- if (result!=-1)\r
- {\r
- break;\r
- }\r
- else\r
- {\r
- /*\r
- * //will not work, I broke the event loop !!!!\r
- dummy.lock();\r
- QWaitCondition waitCondition;\r
- waitCondition.wait(&dummy, 2);\r
- */\r
-\r
- //to decrease CPU usage\r
- //sleep 1 millisecond\r
+ while (!guiMainThread->bTimeOut)\r
+ {\r
+ qApp->processEvents(QEventLoop::AllEvents);\r
+\r
+ if (!guiMainThread)//when all the windows are deleted\r
+ return result;\r
+\r
+ mutexKey.lock();\r
+ if (last_key != -1)\r
+ {\r
+ result = last_key;\r
+ last_key = -1;\r
+ guiMainThread->timer->stop();\r
+ //printf("keypressed\n");\r
+ }\r
+ mutexKey.unlock();\r
+\r
+ if (result!=-1)\r
+ {\r
+ break;\r
+ }\r
+ else\r
+ {\r
+ /*\r
+ * //will not work, I broke the event loop !!!!\r
+ dummy.lock();\r
+ QWaitCondition waitCondition;\r
+ waitCondition.wait(&dummy, 2);\r
+ */\r
+\r
+ //to decrease CPU usage\r
+ //sleep 1 millisecond\r
#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64\r
- Sleep(1);\r
+ Sleep(1);\r
#else\r
- usleep(1000);\r
+ usleep(1000);\r
#endif\r
- }\r
- }\r
+ }\r
+ }\r
\r
- guiMainThread->bTimeOut = false;\r
- }\r
+ guiMainThread->bTimeOut = false;\r
+ }\r
\r
- return result;\r
+ return result;\r
}\r
\r
\r
//setAttribute(Qt::WA_DeleteOnClose); //in other case, does not release memory\r
setContentsMargins(0, 0, 0, 0);\r
setWindowTitle(name);\r
- setObjectName(name);\r
+ setObjectName(name);\r
+\r
+ setFocus( Qt::PopupFocusReason ); //#1695 arrow keys are not recieved without the explicit focus\r
\r
resize(400, 300);\r
setMinimumSize(1, 1);\r
//see http://doc.trolltech.com/4.6/qt.html#Key-enum\r
int key = event->key();\r
\r
- //bool goodKey = false;\r
- bool goodKey = true;\r
-\r
- Qt::Key qtkey = static_cast<Qt::Key>(key);\r
- char asciiCode = QTest::keyToAscii(qtkey);\r
- if (asciiCode != 0)\r
- {\r
- key = static_cast<int>(asciiCode);\r
- }\r
+ Qt::Key qtkey = static_cast<Qt::Key>(key);\r
+ char asciiCode = QTest::keyToAscii(qtkey);\r
+ if (asciiCode != 0)\r
+ key = static_cast<int>(asciiCode);\r
+ else\r
+ key = event->nativeVirtualKey(); //same codes as returned by GTK-based backend\r
\r
//control plus (Z, +, -, up, down, left, right) are used for zoom/panning functions\r
- if (event->modifiers() != Qt::ControlModifier && goodKey)\r
- {\r
+ if (event->modifiers() != Qt::ControlModifier)\r
+ {\r
mutexKey.lock();\r
last_key = key;\r
- //last_key = event->nativeVirtualKey ();\r
mutexKey.unlock();\r
key_pressed.wakeAll();\r
//event->accept();\r
//up, down, dclick, move\r
void DefaultViewPort::icvmouseHandler(QMouseEvent *event, type_mouse_event category, int &cv_event, int &flags)\r
{\r
- Qt::KeyboardModifiers modifiers = event->modifiers();\r
+ Qt::KeyboardModifiers modifiers = event->modifiers();\r
Qt::MouseButtons buttons = event->buttons();\r
\r
flags = 0;\r
if(modifiers & Qt::ShiftModifier)\r
- flags |= CV_EVENT_FLAG_SHIFTKEY;\r
- if(modifiers & Qt::ControlModifier)\r
- flags |= CV_EVENT_FLAG_CTRLKEY;\r
- if(modifiers & Qt::AltModifier)\r
- flags |= CV_EVENT_FLAG_ALTKEY;\r
+ flags |= CV_EVENT_FLAG_SHIFTKEY;\r
+ if(modifiers & Qt::ControlModifier)\r
+ flags |= CV_EVENT_FLAG_CTRLKEY;\r
+ if(modifiers & Qt::AltModifier)\r
+ flags |= CV_EVENT_FLAG_ALTKEY;\r
\r
if(buttons & Qt::LeftButton)\r
- flags |= CV_EVENT_FLAG_LBUTTON;\r
- if(buttons & Qt::RightButton)\r
- flags |= CV_EVENT_FLAG_RBUTTON;\r
+ flags |= CV_EVENT_FLAG_LBUTTON;\r
+ if(buttons & Qt::RightButton)\r
+ flags |= CV_EVENT_FLAG_RBUTTON;\r
if(buttons & Qt::MidButton)\r
- flags |= CV_EVENT_FLAG_MBUTTON;\r
+ flags |= CV_EVENT_FLAG_MBUTTON;\r
\r
cv_event = CV_EVENT_MOUSEMOVE;\r
- switch(event->button())\r
- {\r
- case Qt::LeftButton:\r
- cv_event = tableMouseButtons[category][0];\r
- flags |= CV_EVENT_FLAG_LBUTTON;\r
- break;\r
- case Qt::RightButton:\r
- cv_event = tableMouseButtons[category][1];\r
- flags |= CV_EVENT_FLAG_RBUTTON;\r
- break;\r
- case Qt::MidButton:\r
- cv_event = tableMouseButtons[category][2];\r
- flags |= CV_EVENT_FLAG_MBUTTON;\r
- break;\r
- default:;\r
- }\r
+ switch(event->button())\r
+ {\r
+ case Qt::LeftButton:\r
+ cv_event = tableMouseButtons[category][0];\r
+ flags |= CV_EVENT_FLAG_LBUTTON;\r
+ break;\r
+ case Qt::RightButton:\r
+ cv_event = tableMouseButtons[category][1];\r
+ flags |= CV_EVENT_FLAG_RBUTTON;\r
+ break;\r
+ case Qt::MidButton:\r
+ cv_event = tableMouseButtons[category][2];\r
+ flags |= CV_EVENT_FLAG_MBUTTON;\r
+ break;\r
+ default:;\r
+ }\r
}\r
\r
\r