我补充一下,程序源代码如下:
#include <qtopia/qpeapplication.h>
#include <qlabel.h>
#include<qpushbutton.h>
#include<qstring.h>
#include<qfont.h>
#include<qpopupmenu.h>
#include<qmenubar.h>
#include<qpainter.h>
#include<qtableview.h>
#include<qwidget.h>
#include<qheader.h>
#include<qlineedit.h>
#include<qmultilineedit.h>
#include<qpainter.h>
#include<qfont.h>
#include<qpicture.h>
#include<qpixmap.h>
#include<qtimer.h>
#include<qcolor.h>
#include<qframe.h>
#include<qlcdnumber.h>
#include<stdio.h>
#include<qscrollview.h>
#include<qdialog.h>
#include<math.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/soundcard.h>
#include <qthread.h>
#include <qapplication.h>
#include <qcolor.h>
#include "pthread.h"
#define PI 3.1415926
#define w_flush 786
#define h_flush 252/4
/*
//class Record:public QWidget,public QThread
class Record:public QThread
{
Q_OBJECT
public:
Record(QWidget *parent = 0,const char *name = 0);
void run();
void stop();
};
//Record::Record(QWidget *parent,const char *name):QWidget(parent,name)
Record::Record(QWidget *parent,const char *name):QThread()
{
}
*/
class Question:public QWidget
{
Q_OBJECT
public:
//Question();
Question(QWidget *parent =0, const char *name =0);
protected:
virtual void paintEvent(QPaintEvent *);
//QPainter *painter;
private slots:
void flushBuff();
private:
int buffer[1000];
int buffer1[1000];
QLabel *label;
QTimer *timer;
QFrame *frame;
QFrame *frame1;
};
//Question::Question():QDialog(0,0,TRUE)
Question::Question(QWidget *parent, const char *name):QWidget(parent,name)
{
setCaption("OUR_EXAMPLE");
frame = new QFrame(this,"frame");
frame->setBackgroundColor(black);
frame->setGeometry(QRect(0,0,w_flush,h_flush));
frame1 = new QFrame(this,"frame1");
frame1->setBackgroundColor(black);
frame1->setGeometry(QRect(0,h_flush + 2,w_flush,h_flush));
//frame->setGeometry(QRect(40,40,402,252));
// for(int i =0; i <200; i++)
for(int i =0; i <w_flush; i++)
{
//buffer = (int)(sin((i*PI)/50)*50);
buffer = (int)(sin((i*PI)/25)*25);
buffer1 = (int)(sin((i*PI)/25)*25);
}
QTimer *timer = new QTimer(this,"timer");
connect(timer, SIGNAL(timeout()),this,SLOT(flushBuff()));
//timer->start(30);
timer->start(1);
/*
label = new QLabel(this);
label->setText("Do you ");
label->setGeometry(10,10,300,100);
label->setAlignment(AlignCenter);
*/
}
void Question::flushBuff()
{
int tmp = buffer[0];
int i;
//for(i =0; i <200; i++)
for(i =0; i <w_flush; i++)
{
buffer = buffer[i+1];
}
//buffer[199] = tmp;
buffer[w_flush - 1] = tmp;
tmp = buffer1[0];
for(i =0; i <w_flush; i++)
{
buffer1 = buffer1[i+1];
}
buffer1[w_flush - 1] = tmp;
repaint(0,0,w_flush,2*h_flush,TRUE);
}
void Question::paintEvent(QPaintEvent *)
{
frame->erase(0,0,w_flush,h_flush);
QPainter painter(frame);
QPoint beginPoint;
QPoint endPoint;
painter.setPen(blue);
for(int i =0; i <w_flush; i++)
{
beginPoint.setX(2*i);
beginPoint.setY(buffer + h_flush/2);
endPoint.setX(2*i+1);
endPoint.setY(buffer[i+1] + h_flush/2);
painter.drawLine(beginPoint,endPoint);
}
frame1->erase(0,0,w_flush,h_flush);
QPainter painter1(frame1);
QPoint beginPoint1;
QPoint endPoint1;
painter1.setPen(red);
for(int i =0; i <w_flush; i++)
{
beginPoint1.setX(2*i);
beginPoint1.setY(buffer1 + h_flush/2);
endPoint1.setX(2*i+1);
endPoint1.setY(buffer1[i+1] + h_flush/2);
painter1.drawLine(beginPoint1,endPoint1);
}
}
class MyTable:public QTableView
{
public:
MyTable(QWidget *parent = 0);
private:
void paintCell(QPainter *, int, int);
};
MyTable::MyTable(QWidget *parent):QTableView(parent)
{
setNumCols(3);
setNumRows(100);
setCellWidth(106);
setCellHeight(30);
setBackgroundMode(PaletteBase);
};
void MyTable::paintCell(QPainter* p, int row, int col)
{
int x = (cellWidth(col) - 1);
int y = (cellHeight(row) - 1);
p->drawLine(x, 0, x, y);
p->drawLine(0, y, x, y);
if(col == 0)
{
p->drawText(0,0, (x+1), (y+1), AlignCenter, "1.2");
}
if(col == 1)
{
p->drawText(0,0, (x+1), (y+1), AlignCenter, "5");
}
if(col == 2)
{
p->drawText(0,0, (x+1), (y+1), AlignCenter, "360");
}
};
class Counter:public QWidget
{
Q_OBJECT
public:
Counter(QWidget *parent = 0,const char *name = 0);
public slots:
void IncCounter();
void DecCounter();
private:
//int counter;
unsigned char counter;
QLabel *label;
};
Counter::Counter(QWidget *parent, const char *name):
QWidget(parent,name)
{
counter = 0;
label = new QLabel("0",this);
label->setAlignment(AlignVCenter | AlignHCenter);
}
void Counter::IncCounter()
{
char str[30];
sprintf(str, "%d", ++counter);
label->setText(str);
}
void Counter::DecCounter()
{
char str[30];
sprintf(str, "%d", --counter);
label->setText(str);
}
class MyMainWindow:public QWidget
//class MyMainWindow:public QScrollView
{
Q_OBJECT
public:
//MyMainWindow();
MyMainWindow(QWidget *parent =0, const char *name =0);
public slots:
void addline();
void open();
void Collect();
private:
//QWidget *main;
//绯荤粺鑿滃崟
QPopupMenu *file;
QPopupMenu *config;
QPopupMenu *watch;
QMenuBar *menubar;
//鏁版嵁鏄捐〃鏍? MyTable *table;
QHeader *header;
QHeader *header1;
QMultiLineEdit *edit;
virtual void paintEvent(QPaintEvent*);
QPainter *paint;
QLabel *label;
QTimer *timer;
QScrollView *scrollview;
QScrollView *scrollview1;
QPushButton *AddButton;
QPushButton *SubButton;
Counter *counter;
Question *q;
int count;
int x1;
int y1;
int w;
int h;
int start;
int end;
void trans_c(int x, int y, int r, int arc);
// void RecordFunction();
};
//void MyMainWindow::RecordFunction()
//{
//}
void MyMainWindow::trans_c(int x, int y, int r, int arc)
{
x1 = x -r;
y1 = y -r;
w = h = r;
start = 90*16;
end = arc*16;
}
void MyMainWindow::open()
{
//Question *q = new Question();
}
void MyMainWindow::Collect()
{
//Question *q = new Question();
//q->setGeometry(QRect(10,180,w_flush,2*h_flush));
//q->exec();
//q = new Question(this);
//q->setGeometry(QRect(10,200,w_flush,2*h_flush));
//q->show();
}
void MyMainWindow::addline()
{
char str[30];
if(count > 16)
{
edit->removeLine(0);
}
sprintf(str,"%d",++count);
edit->insertLine(str);
//edit->insertLine("ABCD");
//scrollview->scrollBy(0,2);
}
//void MyMainWindow::paintEvent(QPaintEvent *)
void MyMainWindow::paintEvent(QPaintEvent *)
{
QPixmap image("1.bmp");
paint = new QPainter;
paint->begin(this);
paint->drawPixmap(0,20,image);
paint->setPen(QPen(red, 1, QPen::SolidLine));
trans_c(100,100,50,90);
paint->drawArc(x1,y1,w,h,start,end);
//paint->drawArc(100,100,100,100,1440,2880);
paint->setPen(QPen(green, 1, QPen::SolidLine));
paint->drawText(200,100,"xyzzzzz");
paint->drawText(200,160,"1234567");
paint->end();
};
//MyMainWindow::MyMainWindow()
MyMainWindow::MyMainWindow(QWidget *parent, const char *name):
QWidget(parent,name)
//MyMainWindow::MyMainWindow()
{
unsigned char i;
count = 0;
//qscroll = new QScrollView(this);
//main = new QWidget(this);
//main->setGeometry(0,0,800,480);
//main->setFixedSize(800,480);
//setGeometry(0,0,800,480);
//setFixedSize(800,480);
q = new Question(this);
q->setGeometry(QRect(2,330,w_flush,2*h_flush));
//counter = new Counter(this);
//counter->setGeometry(50,125,90,40);
header = new QHeader(this);
header->setGeometry(312,25,243,30);
header->setOrientation(Horizontal);
header->addLabel("jinxie",81);
header->addLabel("fangwei",81);
header->addLabel("gongjumian",81);
header1 = new QHeader(this);
header1->setGeometry(555,25,244,30);
header1->setOrientation(Horizontal);
header1->addLabel("shujuchuangkou",244);
file = new QPopupMenu();
file->insertItem("&Open",this,SLOT(open()));
file->insertItem("Print");
file->insertItem("Quit",qApp,SLOT(quit()));
//AddButton =new QPushButton("Add",this);
//AddButton->setGeometry(50,40,90,40);
//QObject::connect(AddButton,SIGNAL(clicked()),this,SLOT(addline()));
config = new QPopupMenu();
config->insertItem("Start");
config->insertItem("Adjust");
config->insertItem("Test");
watch = new QPopupMenu();
watch->insertItem("Voltage");
watch->insertItem("Modify");
watch->insertItem("Collect",this,SLOT(Collect()));
menubar = new QMenuBar(this);
menubar->insertItem("File",file);
menubar->insertItem("config",config);
menubar->insertItem("watch",watch);
//scrollview = new QScrollView(this);
//scrollview->setGeometry(555,50,245,280);
scrollview1 = new QScrollView(this);
scrollview1->setGeometry(312,50,243,280);
table = new MyTable();
edit = new QMultiLineEdit(this);
edit->setGeometry(555,50,245,280);
//edit->setMinimumWidth(320);
//edit->setMinimumHeight(280);
//edit->setAutoUpdate(TRUE);
edit->setReadOnly(TRUE);
//scrollview->addChild(edit);
//scrollview->show();
scrollview1->addChild(table);
scrollview1->show();
// edit->insertLine("2009.12.15");
// edit->insertLine("123456");
// edit->insertLine("789642");
//edit->deleteLine();
for(i =0; i <20; i++)
{
// edit->insertLine("ABCD");
}
//addChild(main);
//qscroll->addChild(edit);
//QTimer *ti = new QTimer(this,"timer");
//QObject::connect(ti,SIGNAL(timeout()),counter,SLOT(IncCounter()));
//ti->start(1);
};
void RecordFunction()
{
unsigned i;
i++;
while(1)
{
i++;
}
}
pthread_t id1;
//int main(int argc, char **argv)
int main(int argc, char **argv)
{
//pthread_t id1;
pthread_create(&id1,NULL,(void *)&RecordFunction,NULL);
// pthread_create(&id1,NULL,(void*)&RecordFunction(*arg),NULL);
QApplication app(argc, argv);
//MyMainWindow *mainwindow = new MyMainWindow(0);
//app.setMainWidget(mainwindow);
MyMainWindow w;
//w.lower();
//w.setMouseTracking(TRUE);
//w.showFullScreen();
app.setMainWidget(&w);
//mainwindow->show();
w.setGeometry(QRect(0,0,800,480));
w.setMinimumHeight(480);
w.show();
//w.showFullScreen();
int result = app.exec();
return result;
//int result = app.exec();
//return result;
}
#include "main.moc"
pro文件如下:
CONFIG += qtopiaapp
CONFIG -= buildQuicklaunch
CONFIG += qt thread release
LIBS = $(SUBLIBS) -L$(QTDIR)/lib -L/usr/X11R6/lib -lqt -lXext -lX11 -lm -lpthread
#DESTDIR = $(QPEDIR)/bin
DESTDIR = $(pwd)
#HEADERS = hello.h
#SOURCES = hello.cpp
SOURCES+=main.cpp
INTERFACES = hello_base.ui
TARGET = hello
我的脚本文件如下:
#!/bin/bash
source /opt/FriendlyARM/mini2440/arm-qtopia/qtopia-2.2.0-FriendlyARM/setQpeEnv
qmake -spec /opt/FriendlyARM/mini2440/arm-qtopia/qtopia-2.2.0-FriendlyARM/qtopia/mkspecs/qws/linux-arm-g++ -o Makefile *.pro
make clean
make
mv hello /mnt/hgfs/linux/