void MainWindow
::keyPressEvent(QKeyEvent *ke
) {
int dx = 0;
int dy = 0;
int offset = 1;
printf("%s: Got key %d\n", __FUNCTION__, ke->key());
if ( ke->isAutoRepeat() )
offset = 5;
if ( ke->key() == Qt::Key_Left )
dx = -offset;
else if ( ke->key() == Qt::Key_Right)
dx = offset;
else if ( ke->key() == Qt::Key_Up)
dy = -offset;
else if ( ke->key() == Qt::Key_Down)
dy = offset;
else if ( ke->key() == Qt::Key_Q)
{
printf("%s: Got Quit key \n", __FUNCTION__);
exit(1);
}
if ( dx != 0 || dy != 0 )
{
const QRect rect
= scribbleArea
->contentsRect
();
printf("%s: Got Rect as (%d,%d), top=%d, bottom=%d, width=%d, height=%d \n", __FUNCTION__,
rect.x(), rect.y(), rect.top(), rect.bottom(), rect.width(), rect.height());
printf("%s: Got position as global(%d,%d), QCursor(%d,%d) \n", __FUNCTION__,
int x = pos.x() + dx;
int y = pos.y() + dy;
#if 1
update();
#else
#endif
}
}
void MainWindow
::leaveEvent(QEvent *event
) {
const QRect rect
= scribbleArea
->contentsRect
();
/*
printf("%s: Got Rect as (%d,%d), top=%d, bottom=%d, width=%d, height=%d \n", __FUNCTION__,
rect.x(), rect.y(), rect.top(), rect.bottom(), rect.width(), rect.height());
printf("%s: Got position as global(%d,%d), QCursor(%d,%d) \n", __FUNCTION__,
pos.x(), pos.y(), QCursor::pos().x(), QCursor::pos().y());
*/
int x = pos.x();
int y = pos.y();
if(pos.y() < rect.top())
{
printf("%s: Moving Up \n", __FUNCTION__);
y = rect.top() + 1;
}
else if(pos.y() > rect.bottom())
{
printf("%s: Moving Down \n", __FUNCTION__);
y = rect.bottom() -1;
}
else if(pos.x() < rect.left())
{
printf("%s: Moving Left \n", __FUNCTION__);
x = rect.left() + 1;
}
else if(pos.x() > rect.right())
{
printf("%s: Moving Right \n", __FUNCTION__);
x = rect.right() - 1;
}
else
{
printf("%s: Invalid Leave \n", __FUNCTION__);
}
#if 0
#else
#endif
}
srinirao@srinirao:~> wc -l mainwindow.cpp
83 mainwindow.cpp
srinirao@srinirao:~> cat mainwindow.cpp
void MainWindow
::keyPressEvent(QKeyEvent *ke
) {
int dx = 0;
int dy = 0;
int offset = 1;
printf("%s: Got key %d\n", __FUNCTION__, ke->key());
if ( ke->isAutoRepeat() )
offset = 5;
if ( ke->key() == Qt::Key_Left )
dx = -offset;
else if ( ke->key() == Qt::Key_Right)
dx = offset;
else if ( ke->key() == Qt::Key_Up)
dy = -offset;
else if ( ke->key() == Qt::Key_Down)
dy = offset;
else if ( ke->key() == Qt::Key_Q)
{
printf("%s: Got Quit key \n", __FUNCTION__);
exit(1);
}
if ( dx != 0 || dy != 0 )
{
const QRect rect
= scribbleArea
->contentsRect
();
printf("%s: Got Rect as (%d,%d), top=%d, bottom=%d, width=%d, height=%d \n", __FUNCTION__,
rect.x(), rect.y(), rect.top(), rect.bottom(), rect.width(), rect.height());
printf("%s: Got position as global(%d,%d), QCursor(%d,%d) \n", __FUNCTION__,
int x = pos.x() + dx;
int y = pos.y() + dy;
#if 1
update();
#else
#endif
}
}
void MainWindow
::leaveEvent(QEvent *event
) {
const QRect rect
= scribbleArea
->contentsRect
();
/*
printf("%s: Got Rect as (%d,%d), top=%d, bottom=%d, width=%d, height=%d \n", __FUNCTION__,
rect.x(), rect.y(), rect.top(), rect.bottom(), rect.width(), rect.height());
printf("%s: Got position as global(%d,%d), QCursor(%d,%d) \n", __FUNCTION__,
pos.x(), pos.y(), QCursor::pos().x(), QCursor::pos().y());
*/
int x = pos.x();
int y = pos.y();
if(pos.y() < rect.top())
{
printf("%s: Moving Up \n", __FUNCTION__);
y = rect.top() + 1;
}
else if(pos.y() > rect.bottom())
{
printf("%s: Moving Down \n", __FUNCTION__);
y = rect.bottom() -1;
}
else if(pos.x() < rect.left())
{
printf("%s: Moving Left \n", __FUNCTION__);
x = rect.left() + 1;
}
else if(pos.x() > rect.right())
{
printf("%s: Moving Right \n", __FUNCTION__);
x = rect.right() - 1;
}
else
{
printf("%s: Invalid Leave \n", __FUNCTION__);
}
#if 0
#else
#endif
}
void MainWindow::keyPressEvent(QKeyEvent *ke)
{
int dx = 0;
int dy = 0;
int offset = 1;
printf("%s: Got key %d\n", __FUNCTION__, ke->key());
if ( ke->isAutoRepeat() )
offset = 5;
if ( ke->key() == Qt::Key_Left )
dx = -offset;
else if ( ke->key() == Qt::Key_Right)
dx = offset;
else if ( ke->key() == Qt::Key_Up)
dy = -offset;
else if ( ke->key() == Qt::Key_Down)
dy = offset;
else if ( ke->key() == Qt::Key_Q)
{
printf("%s: Got Quit key \n", __FUNCTION__);
exit(1);
}
if ( dx != 0 || dy != 0 )
{
const QRect rect = scribbleArea->contentsRect();
const QPoint pos = scribbleArea->mapFromGlobal(QCursor::pos());
printf("%s: Got Rect as (%d,%d), top=%d, bottom=%d, width=%d, height=%d \n", __FUNCTION__,
rect.x(), rect.y(), rect.top(), rect.bottom(), rect.width(), rect.height());
printf("%s: Got position as global(%d,%d), QCursor(%d,%d) \n", __FUNCTION__,
pos.x(), pos.y(), QCursor::pos().x(), QCursor::pos().y());
int x = pos.x() + dx;
int y = pos.y() + dy;
#if 1
QCursor::setPos(scribbleArea->mapToGlobal(QPoint(x, y)));
update();
#else
QMouseEvent event1(QEvent::MouseMove, QPoint(x,y), (Qt::MouseButton)0, (Qt::MouseButtons)0, 0);
QApplication::sendEvent(this, &event1);
#endif
}
}
void MainWindow::leaveEvent(QEvent *event)
{
const QRect rect = scribbleArea->contentsRect();
const QPoint pos = scribbleArea->mapFromGlobal(QCursor::pos());
/*
printf("%s: Got Rect as (%d,%d), top=%d, bottom=%d, width=%d, height=%d \n", __FUNCTION__,
rect.x(), rect.y(), rect.top(), rect.bottom(), rect.width(), rect.height());
printf("%s: Got position as global(%d,%d), QCursor(%d,%d) \n", __FUNCTION__,
pos.x(), pos.y(), QCursor::pos().x(), QCursor::pos().y());
*/
int x = pos.x();
int y = pos.y();
if(pos.y() < rect.top())
{
printf("%s: Moving Up \n", __FUNCTION__);
y = rect.top() + 1;
}
else if(pos.y() > rect.bottom())
{
printf("%s: Moving Down \n", __FUNCTION__);
y = rect.bottom() -1;
}
else if(pos.x() < rect.left())
{
printf("%s: Moving Left \n", __FUNCTION__);
x = rect.left() + 1;
}
else if(pos.x() > rect.right())
{
printf("%s: Moving Right \n", __FUNCTION__);
x = rect.right() - 1;
}
else
{
printf("%s: Invalid Leave \n", __FUNCTION__);
}
#if 0
QCursor::setPos(scribbleArea->mapToGlobal(QPoint(100, 100)));
#else
QCursor::setPos(scribbleArea->mapToGlobal(QPoint(x, y)));
#endif
QApplication::processEvents();
}
srinirao@srinirao:~> wc -l mainwindow.cpp
83 mainwindow.cpp
srinirao@srinirao:~> cat mainwindow.cpp
void MainWindow::keyPressEvent(QKeyEvent *ke)
{
int dx = 0;
int dy = 0;
int offset = 1;
printf("%s: Got key %d\n", __FUNCTION__, ke->key());
if ( ke->isAutoRepeat() )
offset = 5;
if ( ke->key() == Qt::Key_Left )
dx = -offset;
else if ( ke->key() == Qt::Key_Right)
dx = offset;
else if ( ke->key() == Qt::Key_Up)
dy = -offset;
else if ( ke->key() == Qt::Key_Down)
dy = offset;
else if ( ke->key() == Qt::Key_Q)
{
printf("%s: Got Quit key \n", __FUNCTION__);
exit(1);
}
if ( dx != 0 || dy != 0 )
{
const QRect rect = scribbleArea->contentsRect();
const QPoint pos = scribbleArea->mapFromGlobal(QCursor::pos());
printf("%s: Got Rect as (%d,%d), top=%d, bottom=%d, width=%d, height=%d \n", __FUNCTION__,
rect.x(), rect.y(), rect.top(), rect.bottom(), rect.width(), rect.height());
printf("%s: Got position as global(%d,%d), QCursor(%d,%d) \n", __FUNCTION__,
pos.x(), pos.y(), QCursor::pos().x(), QCursor::pos().y());
int x = pos.x() + dx;
int y = pos.y() + dy;
#if 1
QCursor::setPos(scribbleArea->mapToGlobal(QPoint(x, y)));
update();
#else
QMouseEvent event1(QEvent::MouseMove, QPoint(x,y), (Qt::MouseButton)0, (Qt::MouseButtons)0, 0);
QApplication::sendEvent(this, &event1);
#endif
}
}
void MainWindow::leaveEvent(QEvent *event)
{
const QRect rect = scribbleArea->contentsRect();
const QPoint pos = scribbleArea->mapFromGlobal(QCursor::pos());
/*
printf("%s: Got Rect as (%d,%d), top=%d, bottom=%d, width=%d, height=%d \n", __FUNCTION__,
rect.x(), rect.y(), rect.top(), rect.bottom(), rect.width(), rect.height());
printf("%s: Got position as global(%d,%d), QCursor(%d,%d) \n", __FUNCTION__,
pos.x(), pos.y(), QCursor::pos().x(), QCursor::pos().y());
*/
int x = pos.x();
int y = pos.y();
if(pos.y() < rect.top())
{
printf("%s: Moving Up \n", __FUNCTION__);
y = rect.top() + 1;
}
else if(pos.y() > rect.bottom())
{
printf("%s: Moving Down \n", __FUNCTION__);
y = rect.bottom() -1;
}
else if(pos.x() < rect.left())
{
printf("%s: Moving Left \n", __FUNCTION__);
x = rect.left() + 1;
}
else if(pos.x() > rect.right())
{
printf("%s: Moving Right \n", __FUNCTION__);
x = rect.right() - 1;
}
else
{
printf("%s: Invalid Leave \n", __FUNCTION__);
}
#if 0
QCursor::setPos(scribbleArea->mapToGlobal(QPoint(100, 100)));
#else
QCursor::setPos(scribbleArea->mapToGlobal(QPoint(x, y)));
#endif
QApplication::processEvents();
}
To copy to clipboard, switch view to plain text mode
Bookmarks