實(shí)訓(xùn)四的資料_第1頁
實(shí)訓(xùn)四的資料_第2頁
實(shí)訓(xùn)四的資料_第3頁
實(shí)訓(xùn)四的資料_第4頁
實(shí)訓(xùn)四的資料_第5頁
已閱讀5頁,還剩18頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

《嵌入式操作系統(tǒng)課程設(shè)計(jì)》實(shí)訓(xùn)報(bào)告PAGE第1頁共23頁《嵌入式操作系統(tǒng)B》實(shí)訓(xùn)報(bào)告上海第二工業(yè)大學(xué)計(jì)算機(jī)科學(xué)與技術(shù)系學(xué)生實(shí)訓(xùn)報(bào)告課程名稱嵌入式操作系統(tǒng)課程設(shè)計(jì)實(shí)訓(xùn)類別驗(yàn)證型實(shí)訓(xùn)項(xiàng)目名稱布局管理、事件處理和圖像班級10計(jì)科A1姓名學(xué)號實(shí)訓(xùn)時(shí)間2013年11月1日實(shí)訓(xùn)地點(diǎn)15號樓507指導(dǎo)教師組號同組學(xué)生信息(請?zhí)顚懺谙路剑┌嗉壭彰麑W(xué)號一、實(shí)訓(xùn)目的1、了解并掌握QT提供的多種布局管理部件,包括QT布局管理器、分裂器、棧部件、工作空間部件和多文檔區(qū)部件等;2、分析Qt的常用事件,包括鼠標(biāo)事件、鍵盤事件以及事件過濾器的使用方法;3、掌握QPainter、QCanvas與OpenGL進(jìn)行繪圖的基本方法,并注意這三類方式使用的異同點(diǎn)。二、設(shè)備和儀器裝有Linux和Windows操作系統(tǒng)的PC機(jī)一臺實(shí)訓(xùn)內(nèi)容完成書本第六部分“布局管理”中的兩個(gè)例題QScrollView的IconEditor和多文檔界面的Editor;QScrollView的IconEditor運(yùn)行結(jié)果:主要代碼注釋如下:ImageEditor.cppImageEditor::ImageEditor(QWidget*parent,constchar*name):QScrollView(parent,name,WStaticContents|WNoAutoErase){curColor=black;zoom=8;curImage.create(16,16,32);//若沒有加載圖片,則將畫布的大小設(shè)置為16*16大小的curImage.fill(qRgba(0,0,0,0));//顏色為白色curImage.setAlphaBuffer(true);resizeContents();//此函數(shù)用于管理初始窗口部件獲取自己的大小}voidImageEditor::resizeContents(){QSizesize=zoom*curImage.size();if(zoom>=3)size+=QSize(1,1);//若zoom大于等于3,size則放大一格QScrollView::resizeContents(size.width(),size.height());//QScrollView是否顯示滾動(dòng)條由窗口的大小決定}About菜單為:AboutQt菜單為實(shí)驗(yàn)過程:運(yùn)行結(jié)果:完成書本第七部分“事件處理”中的例題Ticker;#include<qpainter.h>#include"ticker.h"Ticker::Ticker(QWidget*parent,constchar*name):QWidget(parent,name){offset=0;//設(shè)置被繪制文本X坐標(biāo)myTimerId=0;//定時(shí)器標(biāo)示器}voidTicker::setText(constQString&newText){myText=newText;update();//強(qiáng)制重新繪制updateGeometry();//提示ticker窗口布局的變化}QSizeTicker::sizeHint()const{returnfontMetrics().size(0,text());}voidTicker::paintEvent(QPaintEvent*){QPainterpainter(this);inttextWidth=fontMetrics().width(text());//確定文版需要多少水平空間if(textWidth<1)return;intx=-offset;while(x<width()){painter.drawText(x,0,textWidth,height(),AlignLeft|AlignVCenter,text());x+=textWidth;}}voidTicker::showEvent(QShowEvent*){myTimerId=startTimer(30);//設(shè)置一個(gè)30秒的定時(shí)器}voidTicker::timerEvent(QTimerEvent*event)//時(shí)間間隔調(diào)用{if(event->timerId()==myTimerId){++offset;if(offset>=fontMetrics().width(text()))offset=0;scroll(-1,0); //左移一個(gè)像素}else{QWidget::timerEvent(event);}}voidTicker::hideEvent(QHideEvent*){killTimer(myTimerId);//當(dāng)文本消失時(shí),釋放對應(yīng)的定時(shí)器}請按下列程序源代碼,編寫ch_601,并在程序后進(jìn)行注釋:ch_601.cpp的源程序?yàn)椋?include<qtimer.h>#include<qpainter.h>#include<qapplication.h>#include<qtextcodec.h>#include<stdlib.h>#include"ch_601.h"ch_601::ch_601(QWidget*parent,constchar*name):QWidget(parent,name){for(inta=0;a<numColors;a++)//聲明變量a產(chǎn)生隨機(jī)顏色{colors[a]=QColor(rand()&255,rand()&255);//設(shè)置隨機(jī)顏色}rectangles=0;//矩形計(jì)數(shù)為0startTimer(0);//開始計(jì)數(shù)為0QTimer*counter=newQTimer(this);connect(counter,SIGNAL(timeout()),this,SLOT(updateCaption()));//計(jì)數(shù)器的信號為timeout時(shí),更新captioncounter->start(1000);}voidch_601::updateCaption(){QStrings;s.sprintf(QObject::tr("QTimer實(shí)例"),rectangles);//設(shè)置caption為“QTimer實(shí)例”和舉行數(shù)rectangles=0;setCaption(s);}voidch_601::paintEvent(QPaintEvent*){QPainterpaint(this);intw=width();//寬winth=height();//高h(yuǎn)if(w<=0||h<=0)//若w<=0或h<=0return;//返回paint.setPen(NoPen);//若沒有畫筆則設(shè)置畫筆paint.setBrush(colors[rand()%numColors]);//畫刷顏色隨機(jī)QPointp1(rand()%w,rand()%h);//設(shè)置矩形的位置QPointp2(rand()%w,rand()%h);QRectr(p1,p2);paint.drawRect(r);//畫矩形}voidch_601::timerEvent(QTimerEvent*){for(inti=0;i<100;i++){repaint(false);//在一個(gè)繪畫窗口發(fā)送之前,之前的窗口不會(huì)被擦除rectangles++;//矩形累加}}Main.cpp的源程序?yàn)椋?include<qapplication.h>#include<qtextcodec.h>#include"ch_601.h"intmain(intargc,char**argv){QApplicationa(argc,argv);ch_601always(0,0);QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030"));//設(shè)置標(biāo)題字體always.resize(400,250); //初始化窗體a.setMainWidget(&always);always.setCaption(QObject::tr("時(shí)鐘的測試?yán)}"));always.show();returna.exec();}ch_601.h的源程序?yàn)椋?ifndefCH_601_H#defineCH_601_H#include<qwidget.h>constintnumColors=120;classCh_601:publicQWidget{Q_OBJECTpublic:Ch_601(QWidget*parent=0,constchar*name=0);protected:void paintEvent(QPaintEvent*);void timerEvent(QTimerEvent*);privateslots:void updateCaption();private:int rectangles;QColor colors[numColors];};#endifCh_601運(yùn)行結(jié)果:請按下列程序源代碼(其中主程序自編),編寫ch_602,并在程序后進(jìn)行注釋:#include"progressbar.h"#include<qradiobutton.h>#include<qpushbutton.h>#include<qprogressbar.h>#include<qlayout.h>#include<qmotifstyle.h>ProgressBar::ProgressBar(QWidget*parent,constchar*name):QButtonGroup(0,Horizontal,QObject::tr("進(jìn)度條測試"),parent,name),timer(){setMargin(10);//設(shè)置邊距QGridLayout*toplayout=newQGridLayout(layout(),2,2,5);//設(shè)置空間組setRadioButtonExclusive(TRUE);//按鍵單一選擇slow=newQRadioButton(QObject::tr("低速"),this);//設(shè)置低速,中速,高速三個(gè)選項(xiàng)normal=newQRadioButton(QObject::tr("中速"),this);fast=newQRadioButton(QObject::tr("高速"),this);QVBoxLayout*vb1=newQVBoxLayout;//新建一個(gè)boxtoplayout->addLayout(vb1,0,0); //嵌套布局vb1->addWidget(slow); //添加slow,normal,fast到布局vb1->addWidget(normal);vb1->addWidget(fast);start=newQPushButton(QObject::tr("開始"),this);//新建開始按鈕reset=newQPushButton(QObject::tr("重啟"),this);//新建重啟按鈕QVBoxLayout*vb2=newQVBoxLayout;toplayout->addLayout(vb2,0,1);vb2->addWidget(start);vb2->addWidget(reset);progress=newQProgressBar(100,this);//添加進(jìn)度條toplayout->addMultiCellWidget(progress,1,1,0,1);//1列插入progressbar占2行2列connect(start,SIGNAL(clicked()),this,SLOT(slotStart()));//點(diǎn)擊開始觸發(fā)開始槽connect(reset,SIGNAL(timeout()),this,SLOT(slotTimeout()));//點(diǎn)擊重置觸發(fā)timeout槽normal->setChecked(TRUE);//默認(rèn)選中設(shè)置為中速start->setFixedWidth(80);//設(shè)置最大最小寬度為80setMinimumWidth(300);//設(shè)置最小寬度300}voidProgressBar::slotStart(){if(progress->progress()==-1){if(slow->isChecked())progress->setTotalSteps(10000);//slow進(jìn)度條滿需10000小時(shí)elseif(normal->isChecked())progress->setTotalSteps(1000);//normal進(jìn)度條滿需1000小時(shí)elseprogress->setTotalSteps(50);//fast進(jìn)度條滿需50小時(shí)slow->setEnabled(FALSE);//slow不能選中normal->setEnabled(FALSE);//normal不能選中fast->setEnabled(FALSE); /fast不能選中}if(!timer.isActive())//若時(shí)鐘未被激活{timer.start(1);//時(shí)鐘設(shè)置為1start->setText(QObject::tr("暫停"));}else{timer.stop();//時(shí)間停止start->setText(QObject::tr("繼續(xù)"));}}voidProgressBar::slotReset()//進(jìn)度條重置{timer.stop();start->setText(QObject::tr("開始"));start->setEnabled(TRUE);//start可以被選擇slow->setEnabled(TRUE);//slow可以被選擇normal->setEnabled(TRUE);//normal可以被選擇fast->setEnabled(TRUE);//fast可以被選擇progress->reset();//進(jìn)度條重置}voidProgressBar::slotTimeout(){intp=progress->progress();//聲明p,用于保存進(jìn)度條#if1if(p==progress->totalSteps())//若進(jìn)度條滿{start->setText(QObject::tr("開始"));start->setEnabled(FALSE);return;}#endifprogress->setProgress(++p);}processbar.h的源程序?yàn)?#ifndefPROGRESSBAR_H#definePROGRESSBAR_H#include<qbuttongroup.h>#include<qtimer.h>classQRadioButton;classQPushButton;classQProgressBar;classProgressBar:publicQButtonGroup{Q_OBJECTpublic:ProgressBar(QWidget*parent=0,constchar*name=0);protected:QRadioButton*slow,*normal,*fast;QPushButton*start,*pause,*reset;QProgressBar*progress;QTimertimer;protectedslots:voidslotStart();voidslotReset();voidslotTimeout();};#endifMain.cpp源程序?yàn)椋?include<qapplication.h>#include"progressbar.h"intmain(intargc,char**argv){QApplicationa(argc,argv);ProgressBar*progrssbar=newProgressBar;a.setMainWidget(progrssbar);progrssbar->show();//顯示窗體returna.exec();}運(yùn)行界面如下:請按下列程序源代碼,編寫ch_801,并在程序后進(jìn)行注釋。ch_801.cpp的源程序?yàn)椋?include<qapplication.h>#include<qpainter.h>#include<qpicture.h>#include<qpixmap.h>#include<qwidget.h>#include<qmessagebox.h>#include<qfile.h>#include<ctype.h>#include<qtextcodec.h>voidpaintCar(QPainter*p) {QPointArraya;QBrushbrush(Qt::green,Qt::SolidPattern);//設(shè)置刷子為綠色,并且是滿填充p->setBrush(brush); //選中刷子a.setPoints(4,50,150,650,150,650,350,50,350);//設(shè)置點(diǎn)p->drawPolygon(a); //點(diǎn)內(nèi)畫一個(gè)多邊形QFontf("courier",20,QFont::Bold);p->setFont(f);//設(shè)置字體QColorwindowColor(120,120,255); //設(shè)置窗體顏色brush.setColor(windowColor); //刷子設(shè)置為窗體顏色p->setBrush(brush); p->drawRect(100,180,100,70); //畫4個(gè)窗體 p->drawRect(220,180,100,70); p->drawRect(340,180,100,70); p->drawRect(460,180,100,70);p->drawText(50,250,650,70,Qt::AlignCenter,QObject::tr("公共汽車"));//車體上顯示的字 p->setBrush(Qt::red); //刷子為紅色 p->drawRect(600,110,20,40);// p->setBrush(Qt::yellow); p->drawEllipse(610,70,20,20); p->drawEllipse(640,35,30,30); p->drawEllipse(670,0,40,40);p->setBackgroundMode(Qt::OpaqueMode); //輪胎背景不透明p->setBrush(Qt::DiagCrossPattern); p->drawEllipse(90,310,80,80); p->setBrush(Qt::DiagCrossPattern); p->drawEllipse(310,310,80,80); p->setBrush(Qt::DiagCrossPattern); p->drawEllipse(530,310,80,80);}classPictureDisplay:publicQWidget {public:PictureDisplay(constchar*fileName); //圖片顯示~PictureDisplay();protected:void paintEvent(QPaintEvent*);void keyPressEvent(QKeyEvent*);private:QPicture*pict;QString name;};PictureDisplay::PictureDisplay(constchar*fileName){pict=newQPicture;name=fileName;if(!pict->load(fileName)){ //若沒有符合名字的圖片 deletepict; pict=0; name.sprintf("Notabletoloadpicture:%s",fileName);}}PictureDisplay::~PictureDisplay(){deletepict;}voidPictureDisplay::paintEvent(QPaintEvent*){QPainterpaint(this); if(pict) paint.drawPicture(*pict); //畫圖else paint.drawText(rect(),AlignCenter,name);//寫字}voidPictureDisplay::keyPressEvent(QKeyEvent*k){switch(tolower(k->ascii())){//判斷主程序顯示圖片按鍵按下去的情況 case'r': //按下r pict->load(name);//顯示name update(); //更新 break; case'q': //按下q QApplication::exit();//退出應(yīng)用程序 break;}}intmain(intargc,char**argv){QApplicationa(argc,argv); QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030"));constchar*fileName="car.pic"; //設(shè)置fileName if(argc==2) fileName=argv[1];if(!QFile::exists(fileName)){//如果fileName圖片不存在 QPicturepict; QPainterpaint; paint.begin(&pict); paintCar(&paint); paint.end(); pict.save(fileName); //保存fileName QMessageBox::information(0,"BUSEXAMPLE",QObject::tr("關(guān)閉對話框后請重新運(yùn)行我,圖片就出來了!")); return0;}else{ PictureDisplaytest(fileName); a.setMainWidget(&test); test.setCaption("BUSEXAMPLE"); test.show(); //顯示 returna.exec(); }}完成書本P:211“使用OpenGL進(jìn)行繪圖”中的例題Cube;#include<qcolordialog.h>#include"cube.h"Cube::Cube(QWidget*parent,constchar*name):QGLWidget(parent,name){setFormat(QGLFormat(DoubleBuffer|DepthBuffer));//定義各式雙緩存|深度緩存rotationX=0; //初始化3條軸rotationY=0;rotationZ=0;faceColors[0]=red; //定義六個(gè)面的顏色分別為紅色,綠色,藍(lán)色,粉色,黃色,草綠色faceColors[1]=green;faceColors[2]=blue;faceColors[3]=cyan;faceColors[4]=yellow;faceColors[5]=magenta;}voidCube::initializeGL(){qglClearColor(black);//用黑色初始化glShadeModel(GL_FLAT);//陰影模式glEnable(GL_DEPTH_TEST);glEnable(GL_CULL_FACE);}voidCube::resizeGL(intwidth,intheight){glViewport(0,0,width,height);glMatrixMode(GL_PROJECTION);glLoadIdentity();GLfloatx=(GLfloat)width/height;glFrustum(-x,x,-1.0,1.0,4.0,15.0);glMatrixMode(GL_MODELVIEW);}voidCube::paintGL(){glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);draw(); //圖的實(shí)際繪制的調(diào)用}voidCube::draw(){staticconstGLfloatcoords[6][4][3]={//6個(gè)面的坐標(biāo){{+1.0,-1.0,+1.0},{+1.0,-1.0,-1.0},{+1.0,+1.0,-1.0},{+1.0,+1.0,+1.0}},{{-1.0,-1.0,-1.0},{-1.0,-1.0,+1.0},{-1.0,+1.0,+1.0},{-1.0,+1.0,-1.0}},{{+1.0,-1.0,-1.0},{-1.0,-1.0,-1.0},{-1.0,+1.0,-1.0},{+1.0,+1.0,-1.0}},{{-1.0,-1.0,+1.0},{+1.0,-1.0,+1.0},{+1.0,+1.0,+1.0},{-1.0,+1.0,+1.0}},{{-1.0,-1.0,-1.0},{+1.0,-1.0,-1.0},{+1.0,-1.0,+1.0},{-1.0,-1.0,+1.0}},{{-1.0,+1.0,+1.0},{+1.0,+1.0,+1.0},{+1.0,+1.0,-1.0},{-1.0,+1.0,-1.0}}};glMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef(0.0,0.0,-10.0);glRotatef(rotationX,1.0,0.0,0.0);glRotatef(rotationY,0.0,1.0,0.0);glRotatef(rotationZ,0.0,0.0,1.0);for(inti=0;i<6;++i){glLoadName(i);glBegin(GL_QUADS);qglColor(faceColors[i]);//保存顏色來繪制正方體for(intj=0;j<4;++j){glVertex3f(coords[i][j][0],coords[i][j][1],coords[i][j][2]);}glEnd();}}voidCube::mousePressEvent(QMouseEvent*event){lastPos=event->pos();//鼠標(biāo)點(diǎn)下的那個(gè)點(diǎn)作為軸點(diǎn)}voidCube::mouseMoveEvent(QMouseEvent*event) //鼠標(biāo)移動(dòng)時(shí),正方體改變樣式{

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論