Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
d46f44b4
Commit
d46f44b4
authored
Mar 28, 2012
by
Andrey Kamaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#1695 fixed arrow key events with the Qt backend
parent
dd01861d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
96 deletions
+94
-96
window_QT.cpp
modules/highgui/src/window_QT.cpp
+94
-96
No files found.
modules/highgui/src/window_QT.cpp
View file @
d46f44b4
...
...
@@ -256,77 +256,77 @@ CV_IMPL void cvDisplayStatusBar(const char* name, const char* text, int delayms)
CV_IMPL
int
cvWaitKey
(
int
delay
)
{
int
result
=
-
1
;
int
result
=
-
1
;
if
(
!
guiMainThread
)
return
result
;
if
(
!
guiMainThread
)
return
result
;
unsigned
long
delayms
=
delay
<=
0
?
ULONG_MAX
:
delay
;
//in milliseconds
if
(
multiThreads
)
{
mutexKey
.
lock
();
if
(
key_pressed
.
wait
(
&
mutexKey
,
delayms
))
//false if timeout
{
result
=
last_key
;
}
last_key
=
-
1
;
mutexKey
.
unlock
();
}
if
(
multiThreads
)
{
mutexKey
.
lock
();
if
(
key_pressed
.
wait
(
&
mutexKey
,
delayms
))
//false if timeout
{
result
=
last_key
;
}
last_key
=
-
1
;
mutexKey
.
unlock
();
}
else
{
//cannot use wait here because events will not be distributed before processEvents (the main eventLoop is broken)
//so I create a Thread for the QTimer
//cannot use wait here because events will not be distributed before processEvents (the main eventLoop is broken)
//so I create a Thread for the QTimer
if
(
delay
>
0
)
guiMainThread
->
timer
->
start
(
delay
);
if
(
delay
>
0
)
guiMainThread
->
timer
->
start
(
delay
);
//QMutex dummy;
//QMutex dummy;
while
(
!
guiMainThread
->
bTimeOut
)
{
qApp
->
processEvents
(
QEventLoop
::
AllEvents
);
if
(
!
guiMainThread
)
//when all the windows are deleted
return
result
;
mutexKey
.
lock
();
if
(
last_key
!=
-
1
)
{
result
=
last_key
;
last_key
=
-
1
;
guiMainThread
->
timer
->
stop
();
//printf("keypressed\n");
}
mutexKey
.
unlock
();
if
(
result
!=-
1
)
{
break
;
}
else
{
/*
* //will not work, I broke the event loop !!!!
dummy.lock();
QWaitCondition waitCondition;
waitCondition.wait(&dummy, 2);
*/
//to decrease CPU usage
//sleep 1 millisecond
while
(
!
guiMainThread
->
bTimeOut
)
{
qApp
->
processEvents
(
QEventLoop
::
AllEvents
);
if
(
!
guiMainThread
)
//when all the windows are deleted
return
result
;
mutexKey
.
lock
();
if
(
last_key
!=
-
1
)
{
result
=
last_key
;
last_key
=
-
1
;
guiMainThread
->
timer
->
stop
();
//printf("keypressed\n");
}
mutexKey
.
unlock
();
if
(
result
!=-
1
)
{
break
;
}
else
{
/*
* //will not work, I broke the event loop !!!!
dummy.lock();
QWaitCondition waitCondition;
waitCondition.wait(&dummy, 2);
*/
//to decrease CPU usage
//sleep 1 millisecond
#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
Sleep
(
1
);
Sleep
(
1
);
#else
usleep
(
1000
);
usleep
(
1000
);
#endif
}
}
}
}
guiMainThread
->
bTimeOut
=
false
;
}
guiMainThread
->
bTimeOut
=
false
;
}
return
result
;
return
result
;
}
...
...
@@ -1553,7 +1553,9 @@ CvWindow::CvWindow(QString name, int arg2)
//setAttribute(Qt::WA_DeleteOnClose); //in other case, does not release memory
setContentsMargins
(
0
,
0
,
0
,
0
);
setWindowTitle
(
name
);
setObjectName
(
name
);
setObjectName
(
name
);
setFocus
(
Qt
::
PopupFocusReason
);
//#1695 arrow keys are not recieved without the explicit focus
resize
(
400
,
300
);
setMinimumSize
(
1
,
1
);
...
...
@@ -2060,22 +2062,18 @@ void CvWindow::keyPressEvent(QKeyEvent *event)
//see http://doc.trolltech.com/4.6/qt.html#Key-enum
int
key
=
event
->
key
();
//bool goodKey = false;
bool
goodKey
=
true
;
Qt
::
Key
qtkey
=
static_cast
<
Qt
::
Key
>
(
key
);
char
asciiCode
=
QTest
::
keyToAscii
(
qtkey
);
if
(
asciiCode
!=
0
)
{
key
=
static_cast
<
int
>
(
asciiCode
);
}
Qt
::
Key
qtkey
=
static_cast
<
Qt
::
Key
>
(
key
);
char
asciiCode
=
QTest
::
keyToAscii
(
qtkey
);
if
(
asciiCode
!=
0
)
key
=
static_cast
<
int
>
(
asciiCode
);
else
key
=
event
->
nativeVirtualKey
();
//same codes as returned by GTK-based backend
//control plus (Z, +, -, up, down, left, right) are used for zoom/panning functions
if
(
event
->
modifiers
()
!=
Qt
::
ControlModifier
&&
goodKey
)
{
if
(
event
->
modifiers
()
!=
Qt
::
ControlModifier
)
{
mutexKey
.
lock
();
last_key
=
key
;
//last_key = event->nativeVirtualKey ();
mutexKey
.
unlock
();
key_pressed
.
wakeAll
();
//event->accept();
...
...
@@ -2813,41 +2811,41 @@ void DefaultViewPort::scaleView(qreal factor,QPointF center)
//up, down, dclick, move
void
DefaultViewPort
::
icvmouseHandler
(
QMouseEvent
*
event
,
type_mouse_event
category
,
int
&
cv_event
,
int
&
flags
)
{
Qt
::
KeyboardModifiers
modifiers
=
event
->
modifiers
();
Qt
::
KeyboardModifiers
modifiers
=
event
->
modifiers
();
Qt
::
MouseButtons
buttons
=
event
->
buttons
();
flags
=
0
;
if
(
modifiers
&
Qt
::
ShiftModifier
)
flags
|=
CV_EVENT_FLAG_SHIFTKEY
;
if
(
modifiers
&
Qt
::
ControlModifier
)
flags
|=
CV_EVENT_FLAG_CTRLKEY
;
if
(
modifiers
&
Qt
::
AltModifier
)
flags
|=
CV_EVENT_FLAG_ALTKEY
;
flags
|=
CV_EVENT_FLAG_SHIFTKEY
;
if
(
modifiers
&
Qt
::
ControlModifier
)
flags
|=
CV_EVENT_FLAG_CTRLKEY
;
if
(
modifiers
&
Qt
::
AltModifier
)
flags
|=
CV_EVENT_FLAG_ALTKEY
;
if
(
buttons
&
Qt
::
LeftButton
)
flags
|=
CV_EVENT_FLAG_LBUTTON
;
if
(
buttons
&
Qt
::
RightButton
)
flags
|=
CV_EVENT_FLAG_RBUTTON
;
flags
|=
CV_EVENT_FLAG_LBUTTON
;
if
(
buttons
&
Qt
::
RightButton
)
flags
|=
CV_EVENT_FLAG_RBUTTON
;
if
(
buttons
&
Qt
::
MidButton
)
flags
|=
CV_EVENT_FLAG_MBUTTON
;
flags
|=
CV_EVENT_FLAG_MBUTTON
;
cv_event
=
CV_EVENT_MOUSEMOVE
;
switch
(
event
->
button
())
{
case
Qt
:
:
LeftButton
:
cv_event
=
tableMouseButtons
[
category
][
0
];
flags
|=
CV_EVENT_FLAG_LBUTTON
;
break
;
case
Qt
:
:
RightButton
:
cv_event
=
tableMouseButtons
[
category
][
1
];
flags
|=
CV_EVENT_FLAG_RBUTTON
;
break
;
case
Qt
:
:
MidButton
:
cv_event
=
tableMouseButtons
[
category
][
2
];
flags
|=
CV_EVENT_FLAG_MBUTTON
;
break
;
default
:
;
}
switch
(
event
->
button
())
{
case
Qt
:
:
LeftButton
:
cv_event
=
tableMouseButtons
[
category
][
0
];
flags
|=
CV_EVENT_FLAG_LBUTTON
;
break
;
case
Qt
:
:
RightButton
:
cv_event
=
tableMouseButtons
[
category
][
1
];
flags
|=
CV_EVENT_FLAG_RBUTTON
;
break
;
case
Qt
:
:
MidButton
:
cv_event
=
tableMouseButtons
[
category
][
2
];
flags
|=
CV_EVENT_FLAG_MBUTTON
;
break
;
default
:
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment