Qt 觸摸屏校準(zhǔn)程序_第1頁(yè)
Qt 觸摸屏校準(zhǔn)程序_第2頁(yè)
Qt 觸摸屏校準(zhǔn)程序_第3頁(yè)
Qt 觸摸屏校準(zhǔn)程序_第4頁(yè)
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、Qt/Embedded中與用戶輸入事件相關(guān)的信號(hào),是建立在對(duì)底層輸入設(shè)備的接口調(diào)用之上 的,一般通過(guò)對(duì)設(shè)備文件的I/O讀寫來(lái)實(shí)現(xiàn)。大部分這樣的驅(qū)動(dòng)程序已經(jīng)被封裝進(jìn)Qt庫(kù) 當(dāng)中,形成了相應(yīng)的設(shè)備驅(qū)動(dòng)接口,如顯示卡驅(qū)動(dòng)、鼠標(biāo)、鍵盤、串口和并口等。其中鼠 標(biāo)設(shè)備的抽象基類為QWSMouse Handler,從該類又重新派生出一些具體的鼠標(biāo)類設(shè)備 的實(shí)現(xiàn)類。在3.3.4版本系列的Qt/Embedded中,鼠標(biāo)類設(shè)備的派生結(jié)構(gòu)如圖3所示。圖3鼠標(biāo)類設(shè)備的派生結(jié)構(gòu)圖(灰色線框表示可省略類結(jié)構(gòu))鼠標(biāo)類設(shè)備的加載方式與KeyBoard設(shè)備加載方式是類似的,在系統(tǒng)構(gòu)造QWSServer對(duì)象時(shí),調(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獲得鼠標(biāo)類設(shè)備的設(shè)備類型和設(shè)備節(jié) 點(diǎn)。打開并返回相應(yīng)設(shè)備的基類指針QWSMouseHandler給系統(tǒng),系統(tǒng)通過(guò)操作該基類派 生出的具體子類設(shè)備指針QWSCustomMouseHandler,獲得對(duì)具體鼠標(biāo)類設(shè)備的調(diào)用操作 觸摸屏和鼠標(biāo)類設(shè)備在功能上基本是一致的,因此,在Qt庫(kù)中一般把觸摸屏模擬成鼠標(biāo) 設(shè)

3、備來(lái)實(shí)現(xiàn)對(duì)觸摸屏設(shè)備的操作?;赒t的觸摸屏校準(zhǔn)程序頭文件#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該文件為觸摸屏校準(zhǔn)窗口主程序extern MainDialog *g_pMainDlg;根據(jù)屏幕上的 TopLeft,TopRight,BottomRight,BottomLeft,Center 五個(gè)點(diǎn)進(jìn)行觸摸屏校準(zhǔn)static int loca

5、tion5 = QWSPointerCalibrationData:TopLeft,QWSPointerCalibrationData:TopRight,QWSPointerCalibrationData:BottomRight,QWSPointerCalibrationData:BottomLeft,QWSPointerCalibrationData:Center;描述:觸摸屏校準(zhǔn)窗口構(gòu)造函數(shù)參數(shù):parent -父窗口指針?lè)祷兀簾o(wú)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; 描述:觸摸屏校準(zhǔn)窗口析構(gòu)函數(shù)參數(shù):無(wú)返回:無(wú)CalibrationDialog:CalibrationDialog() 描述:運(yùn)行觸摸屏校準(zhǔn)窗口參數(shù):無(wú)返回:無(wú)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;描述:觸摸屏校準(zhǔn)窗口自繪函數(shù)參數(shù):無(wú)返回:無(wú)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);描述:觸摸屏校準(zhǔn)窗口觸摸屏/鼠標(biāo)放開回調(diào)函數(shù),記錄下5 個(gè)點(diǎn)的觸摸數(shù)據(jù),然 后進(jìn)行觸摸屏校準(zhǔn)計(jì)算參數(shù):event -鼠標(biāo)事件返回:無(wú)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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論