qt 3.3.3 calibrate 소스를 qt4로 변경했습니다. 근데 동작을 안하네요..ㅠㅠ
qte-3.3.3 에서 실행되던 calibrate 소스를 qt로 컴파일 하면서 변경했습니다.
초기 calibrate 실행을 시키니 240 320 화면을 인식하더라구요...
십자가 모양의 커서가 떠서 눌렀는데,
디바이스 드라이버 커널쪽에서는 반응을 하는데 calibrate 응용 프로그램에서는 반응이 없네요...휴~~~~~
제가 변경한 소스가 맞는지 고수님들 확인 부탁드리겠습니다..
#include
//#ifdef WS_QWS
#include
#include
#include
class QTimer;
class Calibrate : public QWidget
{
Q_OBJECT
public:
Calibrate(QWidget* parent=0, /*const char * name=0,*/ Qt::WindowFlags=0);
~Calibrate();
private:
QPoint fromDevice( const QPoint &p );
bool sanityCheck();
void moveCrosshair( QPoint pt );
void paintEvent( QPaintEvent * );
void mousePressEvent( QMouseEvent * );
void mouseReleaseEvent( QMouseEvent * );
private slots:
void timeout();
private:
QWSPointerCalibrationData cd;
QWSPointerCalibrationData::Location location;
QPoint crossPos;
QPoint penPos;
QPixmap saveUnder;
QTimer *timer;
int dx;
int dy;
};
//#endif // WS_QWS
#include //#ifdef WS_QWS #include #include #include #include #include //#include //#include #include #include "calibrate.h"
//const Qt::WFlags m_flag = (Qt::Tool | Qt::WindowStaysOnTopHint | Qt::WA_DeleteOnClose);
Calibrate::Calibrate(QWidget* parent, /*const char * name,*/ Qt::WindowFlags wf) :
QWidget( parent, 0/*name,*/ /*Qt::Tool | Qt::FramelessWindowHint | Qt::WA_DeleteOnClose*/)
{
const int offset = 30;
QRect desk = qApp->desktop()->screenGeometry();
setGeometry( 0, 0, desk.width(), desk.height() );
qDebug("%d %d", desk.width(), desk.height() );
// setBackgroundColor(Qt::white);
cd.screenPoints[QWSPointerCalibrationData::TopLeft] = QPoint( offset, offset );
cd.screenPoints[QWSPointerCalibrationData::BottomLeft] = QPoint( offset, qt_screen->deviceHeight() - offset );
cd.screenPoints[QWSPointerCalibrationData::BottomRight] = QPoint( qt_screen->deviceWidth() - offset, qt_screen->deviceHeight() - offset );
cd.screenPoints[QWSPointerCalibrationData::TopRight] = QPoint( qt_screen->deviceWidth() - offset, offset );
cd.screenPoints[QWSPointerCalibrationData::Center] = QPoint( qt_screen->deviceWidth()/2, qt_screen->deviceHeight()/2 );
crossPos = fromDevice( cd.screenPoints[QWSPointerCalibrationData::TopLeft] );
location = QWSPointerCalibrationData::TopLeft;
timer = new QTimer( this );
connect( timer, SIGNAL(timeout()), this, SLOT(timeout()) );
QWSServer::mouseHandler()->clearCalibration();
grabMouse();
}
Calibrate::~Calibrate()
{
}
QPoint Calibrate::fromDevice( const QPoint &p )
{
return qt_screen->mapFromDevice( p,
QSize(qt_screen->deviceWidth(), qt_screen->deviceHeight()) );
}
bool Calibrate::sanityCheck()
{
QPoint tl = cd.devPoints[QWSPointerCalibrationData::TopLeft];
QPoint tr = cd.devPoints[QWSPointerCalibrationData::TopRight];
QPoint bl = cd.devPoints[QWSPointerCalibrationData::BottomLeft];
QPoint br = cd.devPoints[QWSPointerCalibrationData::BottomRight];
qDebug("tl-x : %d, tl-y : %d, tr-x : %d, tr-y : %d", tl.x(), tl.y(),
tr.x(), tr.y());
qDebug("bl-x : %d, bl-y : %d, br-x : %d, br-y : %d", bl.x(), bl.y(),
br.x(), br.y());
int vl = qAbs( tl.y() - bl.y() );
int vr = qAbs( tr.y() - br.y() );
qDebug("vl(tl.y - bl.y): %d, vr(tr.y - br.y) : %d", vl, vr);
int diff = qAbs( vl - vr );
int avg = ( vl + vr ) / 2;
qDebug("diff(vl - vr) : %d, avg((vl+vr)/2) : %d", diff, avg);
if ( diff > avg / 20 ) { // 5% leeway
qDebug(" diff > avg / 20 : False");
return FALSE;
}
qDebug(" diff <= avg / 20 : OK");
int ht = qAbs( tl.x() - tr.x() );
int hb = qAbs( br.x() - bl.x() );
qDebug("ht(tl.x - tr.x): %d, hb(br.y - bl.y) : %d", ht, hb);
diff = qAbs( ht - hb );
avg = ( ht + hb ) / 2;
qDebug("diff(ht - hb) : %d, avg((ht+hb)/2) : %d", diff, avg);
if ( diff > avg / 20 ) { // 5% leeway
qDebug(" diff > avg / 20 : False");
return FALSE;
}
qDebug(" diff <= avg / 20 : OK");
return TRUE;
}
void Calibrate::moveCrosshair( QPoint pt )
{
QPainter p( this );
p.fillRect(rect(), QBrush(Qt::white));
p.drawRect( pt.x()-1, pt.y()-8, 2, 7 );
p.drawRect( pt.x()-1, pt.y()+1, 2, 7 );
p.drawRect( pt.x()-8, pt.y()-1, 7, 2 );
p.drawRect( pt.x()+1, pt.y()-1, 7, 2 );
crossPos = pt;
}
void Calibrate::paintEvent( QPaintEvent * )
{
QPainter p( this );
p.fillRect(rect(), QBrush(Qt::white));
moveCrosshair( crossPos );
}
void Calibrate::mousePressEvent( QMouseEvent *e )
{
// map to device coordinates
QPoint devPos = qt_screen->mapToDevice( e->pos(), QSize(qt_screen->width(), qt_screen->height()) );
if ( penPos.isNull() )
penPos = devPos;
else
penPos = QPoint( (penPos.x() + devPos.x())/2, (penPos.y() + devPos.y())/2 );
qDebug("mousePressEvent(%d, %d)", penPos.x(), penPos.y());
}
void Calibrate::mouseReleaseEvent( QMouseEvent * )
{
if ( timer->isActive() )
return;
bool doMove = TRUE;
cd.devPoints[location] = penPos;
if ( location < QWSPointerCalibrationData::LastLocation )
{
location = (QWSPointerCalibrationData::Location)((int)location + 1);
}
else
{
if ( sanityCheck() )
{
for(int i=0; i<5; i++)
{
qDebug("dev %4x:%4x, scr %4x:%4x \n", cd.devPoints[i].x(), cd.devPoints[i].y(), cd.screenPoints[i].x(), cd.screenPoints[i].y() );
}
QWSServer::mouseHandler()->calibrate( &cd );
releaseMouse();
hide();
close();
doMove = FALSE;
}
else
{
location = QWSPointerCalibrationData::TopLeft;
}
}
if ( doMove )
{
QPoint target = fromDevice( cd.screenPoints[location] );
dx = (target.x() - crossPos.x())/10;
dy = (target.y() - crossPos.y())/10;
timer->start( 30 );
}
}
void Calibrate::timeout()
{
QPoint target = fromDevice( cd.screenPoints[location] );
bool doneX = FALSE;
bool doneY = FALSE;
QPoint newPos( crossPos.x() + dx, crossPos.y() + dy );
if ( qAbs(crossPos.x() - target.x()) <= qAbs(dx) ) {
newPos.setX( target.x() );
doneX = TRUE;
}
if ( qAbs(crossPos.y() - target.y()) <= qAbs(dy) ) {
newPos.setY(target.y());
doneY = TRUE;
}
if ( doneX && doneY ) {
penPos = QPoint();
timer->stop();
}
moveCrosshair( newPos );
}
//#endif // WS_QWS
#include //#include //#include #include "calibrate.h"
int main( int argc, char ** argv )
{
QApplication a( argc, argv );
Calibrate c;
// a.setMainWidget(&c);
// a.setMainWidget( c );
c.show();
return a.exec();
}
댓글 달기