Qt 触摸屏校准程序_第1页
Qt 触摸屏校准程序_第2页
Qt 触摸屏校准程序_第3页
Qt 触摸屏校准程序_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Qt/Embedded中与用户输入事件相关的信号,是建立在对底层输入设备的接口调用之上 的,一般通过对设备文件的I/O读写来实现。大部分这样的驱动程序已经被封装进Qt库 当中,形成了相应的设备驱动接口,如显示卡驱动、鼠标、键盘、串口和并口等。其中鼠 标设备的抽象基类为QWSMouse Handler,从该类又重新派生出一些具体的鼠标类设备 的实现类。在3.3.4版本系列的Qt/Embedded中,鼠标类设备的派生结构如图3所示。图3鼠标类设备的派生结构图(灰色线框表示可省略类结构)鼠标类设备的加载方式与KeyBoard设备加载方式是类似的,在系统构造QWSServer对象时,调用成 员函数 Q

2、WSServer: openMouse,程序在 QWSServer: openMouse 函 数中再调用 QmouseDriverFactory:create ()或 QmouseDriverPlugin: create ()。该函数根 据Linux系统的环境变量QWS_MOUSE_PROTO获得鼠标类设备的设备类型和设备节 点。打开并返回相应设备的基类指针QWSMouseHandler给系统,系统通过操作该基类派 生出的具体子类设备指针QWSCustomMouseHandler,获得对具体鼠标类设备的调用操作 触摸屏和鼠标类设备在功能上基本是一致的,因此,在Qt库中一般把触摸屏模拟成鼠标 设

3、备来实现对触摸屏设备的操作。基于Qt的触摸屏校准程序头文件#include #include class CalibrationDialog : public QDialogpublic:CalibrationDialog(QWidget *parent = 0);CalibrationDialog();int exec();void close();protected:void paintEvent(QPaintEvent*);void mouseReleaseEvent(QMouseEvent*);void accept();private:QWSPointerCalibrationDat

4、a data;int pressCount;源文件#include calibrationdialog.h#include #include #include #include #include #include #include #include #include #include maindialog.h#include application.h该文件为触摸屏校准窗口主程序extern MainDialog *g_pMainDlg;根据屏幕上的 TopLeft,TopRight,BottomRight,BottomLeft,Center 五个点进行触摸屏校准static int loca

5、tion5 = QWSPointerCalibrationData:TopLeft,QWSPointerCalibrationData:TopRight,QWSPointerCalibrationData:BottomRight,QWSPointerCalibrationData:BottomLeft,QWSPointerCalibrationData:Center;描述:触摸屏校准窗口构造函数参数:parent -父窗口指针返回:无CalibrationDialog:CalibrationDialog(QWidget *parent) :QDialog(parent) setObjectNa

6、me(CalibrationDialog);QRect desktop = QApplication:desktop()-geometry(); desktop.moveTo(QPoint(0, 0); setGeometry(desktop);setFocusPolicy(Qt:StrongFocus);setFocus();setModal(true);int width = qt_screen-deviceWidth();int height = qt_screen-deviceHeight();int dx = width / 10;int dy = height / 10;QPoin

7、t *points = data.screenPoints; pointsQWSPointerCalibrationData:TopLeft = QPoint(dx, dy); pointsQWSPointerCalibrationData:BottomLeft = QPoint(dx, height - dy); pointsQWSPointerCalibrationData:BottomRight = QPoint(width - dx, height - dy); pointsQWSPointerCalibrationData:TopRight = QPoint(width - dx,

8、dy); pointsQWSPointerCalibrationData:Center = QPoint(width / 2, height / 2);pressCount = 0; 描述:触摸屏校准窗口析构函数参数:无返回:无CalibrationDialog:CalibrationDialog() 描述:运行触摸屏校准窗口参数:无返回:无int CalibrationDialog:exec()(Application *)qApp)-setLCDOn();pressCount = 0;QWSServer:mouseHandler()-clearCalibration(); grabMous

9、e();/g_pMainDlg-m_pAbnormalMsgBox-hide();activateWindow();int ret = QDialog:exec(); /show();/raise(); releaseMouse();return ret;描述:触摸屏校准窗口自绘函数参数:无返回:无void CalibrationDialog:paintEvent(QPaintEvent*) QPainter p(this);p.fillRect(rect(), Qt:white);QPoint point = data.screenPointslocationpressCount;/ Map

10、 to logical coordinates in case the screen is transformedQSize screenSize(qt_screen-deviceWidth(), qt_screen-deviceHeight(); point = qt_screen-mapFromDevice(point, screenSize);p.fillRect(point.x() - 6, point.y() - 1, 13, 3, Qt:black);p.fillRect(point.x() - 1, point.y() - 6, 3, 13, Qt:black);描述:触摸屏校准窗口触摸屏/鼠标放开回调函数,记录下5 个点的触摸数据,然 后进行触摸屏校准计算参数:event -鼠标事件返回:无void CalibrationDialog:mouseReleaseEvent(QMouseEvent *event)/ Map from device coordinates in case the screen is transformed QSize screenSize(qt_screen-width(), qt_screen-height(); QPoint p = qt_s

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论