📄 zbench.cpp
字号:
pt.drawText( xx, yy, wk, 15 ); } pt.end();}// **********************************************************************// Draw Graphic// **********************************************************************// 2003.06.06 append pt.drawArc( ...// **********************************************************************void AppZBench::paintLineRect(){ int i; int k; int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 }; int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 }; int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 }; int xx1; int xx2; int yy1; int yy2; QPainter pt; QBrush br; srand( time( NULL ) ); pt.begin( this ); for ( i= 0 ; i < DRAW_TEST_COUNT ; i++ ) { k = rand() % 9; pt.setPen( QColor( rr[k], gg[k], bb[k] )); xx1 = rand() % x_size; xx2 = rand() % x_size; yy1 = rand() % ( y_size - CAPTION_Y_SIZE - 1 ) + CAPTION_Y_SIZE; yy2 = rand() % ( y_size - CAPTION_Y_SIZE - 1 ) + CAPTION_Y_SIZE; pt.drawLine( xx1, yy1, xx2, yy2 ); } br.setStyle( SolidPattern ); for ( i= 0 ; i < DRAW_TEST_COUNT ; i++ ) { k = rand() % 9; pt.setPen( QColor( rr[k], gg[k], bb[k] )); xx1 = rand() % ( x_size - 90 ) + 10; xx2 = rand() % 20 + 50; // width yy1 = rand() % ( y_size - 70 ) + 24; yy2 = rand() % 10 + 40; // hight pt.drawArc( xx1, yy1, xx2, yy2, 360*16, 360*16 ); } for ( i= 0 ; i < DRAW_TEST_COUNT ; i++ ) { k = rand() % 9; br.setColor( QColor( rr[k], gg[k], bb[k] )); xx1 = rand() % ( x_size - 90 ) + 10; xx2 = rand() % 20 + 50; // width yy1 = rand() % ( y_size - 70 ) + 24; yy2 = rand() % 10 + 40; // hight pt.fillRect( xx1, yy1, xx2, yy2, br ); } pt.end();}// **********************************************************************// Read & Write// v2.0.0// **********************************************************************#define BUFF_SIZE 8192#define FILE_SIZE 1024 * 1024 // 1Mbchar FileBuf[BUFF_SIZE+1];bool AppZBench::writeFile( QString w_path ){ int i; int k; int n; int pos; int len; char *data = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 62// /*------------------------------------ int w_len; QFile writeFile( w_path ); srand( time( NULL ) ); for( n= 0 ; n < 20 ; n++ ) { if ( ! writeFile.open( IO_WriteOnly )) { writeFile.close(); writeFile.remove(); return( false ); } // ------------------------------------------ sequential write for( k= 0 ; k < 256 ; k++ ) { n = rand() % 30; memcpy( &FileBuf[k*32], &data[n], 32 ); } for( i= 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ ) { w_len = writeFile.writeBlock( FileBuf, BUFF_SIZE ); if ( w_len != BUFF_SIZE ) { writeFile.close(); writeFile.remove(); return( false ); } writeFile.flush(); } // ------------------------------------------ random write for( i= 0 ; i < 400 ; i++ ) { len = rand() % 90 + 4000; for( k= 0 ; k < 128 ; k++ ) { n = rand() % 30; memcpy( &FileBuf[k*8], &data[n], 32 ); } pos = rand() % ( FILE_SIZE - BUFF_SIZE ); writeFile.at( pos ); w_len = writeFile.writeBlock( FileBuf, len ); if ( w_len != len ) { writeFile.close(); writeFile.remove(); return( false ); } writeFile.flush(); } writeFile.close(); } return( true );// ------------------------------------*//* ---------------------------------- srand( time( NULL ) ); FILE *fp; for( n= 0 ; n < 40 ; n++ ) { if (( fp = fopen( w_path, "wt" )) == NULL ) return( false ); memset( FileBuf, '\0', BUFF_SIZE+1 ); // ------------------------------------------ sequential write for( i= 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ ) { for( k= 0 ; k < 128 ; k++ ) { n = rand() % 30; memcpy( &FileBuf[k*8], &data[n], 32 ); } fputs( FileBuf, fp ); } // ------------------------------------------ random write for( i= 0 ; i < 300 ; i++ ) { memset( FileBuf, '\0', 130 ); len = rand() % 120 + 8; for( k= 0 ; k < 16 ; k++ ) { n = rand() % 54; memcpy( &FileBuf[k*8], &data[n], 8 ); } pos = rand() % ( FILE_SIZE / BUFF_SIZE - BUFF_SIZE ); fseek( fp, pos, SEEK_SET ); fputs( FileBuf, fp ); } fclose( fp ); } return( true );-------------------------------------*/}bool AppZBench::readFile( QString r_path ){ int i; int k; int len; int pos; int r_len; QFile readFile( r_path ); srand( time( NULL ) ); for( k= 0 ; k < 200 ; k++ ) { if ( ! readFile.open( IO_ReadOnly )) { readFile.remove(); return( false ); } // ------------------------------------------ sequential read readFile.at( 0 ); for( i= 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ ) { readFile.at( i * BUFF_SIZE ); r_len = readFile.readBlock( FileBuf, BUFF_SIZE ); if ( r_len != BUFF_SIZE ) { readFile.close(); readFile.remove(); return( false ); } } // ------------------------------------------ random read for( i= 0 ; i < 1000 ; i++ ) { len = rand() % 120 + 8; pos = rand() % ( FILE_SIZE / BUFF_SIZE - BUFF_SIZE ); readFile.at( pos ); r_len = readFile.readBlock( FileBuf, len ); if ( r_len != len ) { readFile.close(); readFile.remove(); return( false ); } } readFile.close(); } return( true );}// **********************************************************************// // v2.0.0// **********************************************************************StartDialog::StartDialog( QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl ){ bool c700 = false; int xx; // ---------------------------------- frame size x_size = parent->width(); y_size = parent->height(); if ( x_size > 400 ) // check A300, B500 : 240 x 320 size is 2/3 { // 480x640, 640x480 xx = 300; c700 = true; } else // 240 x 320 { xx = 200; } setCaption( tr( "ZBench start dialog" ) ); QLabel* label1 = new QLabel( tr( "- [ ZBench ] user choice -" ), this ); if ( c700 ) label1->setGeometry( QRect( 5, 10, 300, 25 ) ); else label1->setGeometry( QRect( 5, 10, 200, 17 ) ); IntCheckBox = new QCheckBox( tr( " Integer" ), this ); if ( c700 ) IntCheckBox->setGeometry( QRect( 8, 37, xx - 11, 25 ) ); else IntCheckBox->setGeometry( QRect( 8, 29, xx - 11, 17 ) ); FloatCheckBox = new QCheckBox( tr( " Floating Point" ), this ); if ( c700 ) FloatCheckBox->setGeometry( QRect( 8, 64, xx - 11, 25 ) ); else FloatCheckBox->setGeometry( QRect( 8, 48, xx - 11, 17 ) ); TextCheckBox = new QCheckBox( tr( " Draw Text" ), this ); if ( c700 ) TextCheckBox->setGeometry( QRect( 8, 91, xx - 11, 25 ) ); else TextCheckBox->setGeometry( QRect( 8, 67, xx - 11, 17 ) ); GraphicCheckBox = new QCheckBox( tr( " Draw Graphic" ), this ); if ( c700 ) GraphicCheckBox->setGeometry( QRect( 8, 118, xx - 11, 25 ) ); else GraphicCheckBox->setGeometry( QRect( 8, 86, xx - 11, 17 ) ); mainCheckBox = new QCheckBox( tr( " main unit" ), this ); if ( c700 ) mainCheckBox->setGeometry( QRect( 8, 145, xx - 11, 25 ) ); else mainCheckBox->setGeometry( QRect( 8, 105, xx - 11, 17 ) ); SdCheckBox = new QCheckBox( tr( " SD card" ), this ); if ( c700 ) SdCheckBox->setGeometry( QRect( 8, 172, xx - 11, 25 ) ); else SdCheckBox->setGeometry( QRect( 8, 124, xx - 11, 17 ) ); CfCheckBox = new QCheckBox( tr( " CF card" ), this ); if ( c700 ) CfCheckBox->setGeometry( QRect( 8, 199, xx - 11, 25 ) ); else CfCheckBox->setGeometry( QRect( 8, 143, xx - 11, 17 ) ); QLabel* label2 = new QLabel( tr( "*** output result ***" ), this ); if ( c700 ) label2->setGeometry( QRect( 5, 226, xx - 11, 25 ) ); else label2->setGeometry( QRect( 5, 162, xx - 11, 17 ) ); ClipbCheckBox = new QCheckBox( tr( " clipboard" ), this ); if ( c700 ) ClipbCheckBox->setGeometry( QRect( 8, 253, xx - 11, 25 ) ); else ClipbCheckBox->setGeometry( QRect( 8, 181, xx - 11, 17 ) ); PushButton1 = new QPushButton( tr( "OK" ), this ); if ( c700 ) PushButton1->setGeometry( QRect( 8, 280, 72, 26 ) ); else PushButton1->setGeometry( QRect( 8, 200, 72, 26 ) ); PushButton2 = new QPushButton( tr( "Cancel" ), this ); if ( c700 ) PushButton2->setGeometry( QRect( xx - 115, 280, 110, 26 ) ); else PushButton2->setGeometry( QRect( xx - 115, 200, 110, 26 ) ); connect( PushButton1 ,SIGNAL( clicked()), this, SLOT( accept()) ); connect( PushButton2 ,SIGNAL( clicked()), this, SLOT( hide()) ); // ------------------------------ default check IntCheckBox->setChecked( ((AppZBench*)parent)->which_int ); FloatCheckBox->setChecked( ((AppZBench*)parent)->which_float ); TextCheckBox->setChecked( ((AppZBench*)parent)->which_text ); GraphicCheckBox->setChecked( ((AppZBench*)parent)->which_graphic ); mainCheckBox->setChecked( ((AppZBench*)parent)->which_main ); SdCheckBox->setChecked( ((AppZBench*)parent)->which_sd ); CfCheckBox->setChecked( ((AppZBench*)parent)->which_cf ); ClipbCheckBox->setChecked( ((AppZBench*)parent)->which_clipb );}void StartDialog::accept(){ which_int = IntCheckBox->isChecked(); which_float = FloatCheckBox->isChecked(); which_text = TextCheckBox->isChecked(); which_graphic = GraphicCheckBox->isChecked(); which_main = mainCheckBox->isChecked(); which_sd = SdCheckBox->isChecked(); which_cf = CfCheckBox->isChecked(); which_clipb = ClipbCheckBox->isChecked(); hide(); QDialog::accept();}/* * Destroys the object and frees any allocated resources */StartDialog::~StartDialog(){}// eof
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -