Qt 觸摸屏校準程序_第1頁
Qt 觸摸屏校準程序_第2頁
Qt 觸摸屏校準程序_第3頁
Qt 觸摸屏校準程序_第4頁
全文預覽已結束

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、Qt/Embedded中與用戶輸入事件相關的信號,是建立在對底層輸入設備的接口調(diào)用之上 的,一般通過對設備文件的I/O讀寫來實現(xiàn)。大部分這樣的驅(qū)動程序已經(jīng)被封裝進Qt庫 當中,形成了相應的設備驅(qū)動接口,如顯示卡驅(qū)動、鼠標、鍵盤、串口和并口等。其中鼠 標設備的抽象基類為QWSMouse Handler,從該類又重新派生出一些具體的鼠標類設備 的實現(xiàn)類。在3.3.4版本系列的Qt/Embedded中,鼠標類設備的派生結構如圖3所示。圖3鼠標類設備的派生結構圖(灰色線框表示可省略類結構)鼠標類設備的加載方式與KeyBoard設備加載方式是類似的,在系統(tǒng)構造QWSServer對象時,調(diào)用成 員函數(shù) Q

2、WSServer: openMouse,程序在 QWSServer: openMouse 函 數(shù)中再調(diào)用 QmouseDriverFactory:create ()或 QmouseDriverPlugin: create ()。該函數(shù)根 據(jù)Linux系統(tǒng)的環(huán)境變量QWS_MOUSE_PROTO獲得鼠標類設備的設備類型和設備節(jié) 點。打開并返回相應設備的基類指針QWSMouseHandler給系統(tǒng),系統(tǒng)通過操作該基類派 生出的具體子類設備指針QWSCustomMouseHandler,獲得對具體鼠標類設備的調(diào)用操作 觸摸屏和鼠標類設備在功能上基本是一致的,因此,在Qt庫中一般把觸摸屏模擬成鼠標 設

3、備來實現(xiàn)對觸摸屏設備的操作?;赒t的觸摸屏校準程序頭文件#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;根據(jù)屏幕上的 TopLeft,TopRight,BottomRight,BottomLeft,Center 五個點進行觸摸屏校準static int loca

5、tion5 = QWSPointerCalibrationData:TopLeft,QWSPointerCalibrationData:TopRight,QWSPointerCalibrationData:BottomRight,QWSPointerCalibrationData:BottomLeft,QWSPointerCalibrationData:Center;描述:觸摸屏校準窗口構造函數(shù)參數(shù):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; 描述:觸摸屏校準窗口析構函數(shù)參數(shù):無返回:無CalibrationDialog:CalibrationDialog() 描述:運行觸摸屏校準窗口參數(shù):無返回:無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;描述:觸摸屏校準窗口自繪函數(shù)參數(shù):無返回:無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);描述:觸摸屏校準窗口觸摸屏/鼠標放開回調(diào)函數(shù),記錄下5 個點的觸摸數(shù)據(jù),然 后進行觸摸屏校準計算參數(shù):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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論