跪求跑马灯所有代码解释!!!!急求~~~真心看不懂呀~

abcd 2014-01-14 12:50:02
/****************************************************************************
** Form implementation generated from reading ui file 'formLED.ui'
**
** Created: ? 8?9 15:33:06 2010
** by: The User Interface Compiler ($Id: qt/main.cpp 3.3.3 edited Nov 24 2003 $)
**
** WARNING! All changes made in this file will be lost!
** Author: Enphear in GEC
** GuangZhou 2010 summer
****************************************************************************/

#include "formLED.h"

#include <qvariant.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qimage.h>
#include <qpixmap.h>
#include <qtimer.h>


/*
* Constructs a FormLED as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* TRUE to construct a modal dialog.
*/
FormLED::FormLED( QWidget* parent, const char* name, bool modal, WFlags fl )
: QDialog( parent, name, modal, fl )
{
if ( !name )
setName( "FormLED" );
setMinimumSize( QSize( 320, 240 ) );
setMaximumSize( QSize( 320, 240 ) );
setPaletteBackgroundColor( QColor( 170, 255, 255 ) );

textLabel = new QLabel( this, "textLabel" );
textLabel->setGeometry( QRect( 10, 30, 301, 80 ) );
textLabel->setPaletteForegroundColor( QColor( 255, 255, 127 ) );
textLabel->setPaletteBackgroundColor( QColor( 170, 85, 255 ) );
QFont textLabel_font( textLabel->font() );
textLabel_font.setFamily( "Nimbus Sans L" );
textLabel_font.setPointSize( 24 );
textLabel_font.setBold( TRUE );
textLabel->setFont( textLabel_font );
textLabel->setAlignment( Qt::AlignCenter );

pushButtonRun = new QPushButton( this, "pushButtonRun" );


pushButtonRun->setGeometry( QRect( 80, 170, 161, 51 ) );
QFont pushButtonRun_font( pushButtonRun->font() );
pushButtonRun_font.setFamily( "Nimbus Sans L" );
pushButtonRun_font.setPointSize( 20 );
pushButtonRun_font.setBold( TRUE );
pushButtonRun->setFont( pushButtonRun_font );

pushButtonExit = new QPushButton( this, "pushButtonExit" );



pushButtonExit->setGeometry( QRect( 290, 0, 30, 21 ) );
pushButtonExit->setPaletteForegroundColor( QColor( 255, 255, 255 ) );
pushButtonExit->setPaletteBackgroundColor( QColor( 255, 0, 0 ) );
QFont pushButtonExit_font( pushButtonExit->font() );
pushButtonExit_font.setFamily( "Nimbus Sans L" );
pushButtonExit_font.setPointSize( 12 );
pushButtonExit_font.setBold( TRUE );
pushButtonExit->setFont( pushButtonExit_font );

for(int i=0,x=40;i<=COUNTS_OF_LEDS-1;i++,x+=70)
{
led[i] = new QLabel( this, "led" );


led[i]->setGeometry( QRect( x, 120, 40, 40 ) );
led[i]->setPaletteBackgroundColor( QColor( 170, 170, 170 ) );
QFont led_font( led[i]->font() );
led_font.setFamily( "Nimbus Sans L" );
led_font.setPointSize( 12 );
led_font.setBold( TRUE );
led[i]->setFont( led_font );
led[i]->setAlignment( Qt::AlignCenter );
}

timer=new QTimer;

isRunning=false;
fd=open(DEV_NAME,O_RDWR);



if(fd<0)
{
qDebug("Device open errors!");
//exit(0);
}

languageChange();
resize( QSize(320, 240).expandedTo(minimumSizeHint()) );
clearWState( WState_Polished );

// signals and slots connections
connect( pushButtonExit, SIGNAL( clicked() ), this, SLOT( close() ) );
//

connect( pushButtonRun, SIGNAL( clicked() ), this, SLOT( onRun() ) );
//

connect( timer, SIGNAL( timeout () ), this, SLOT( onTimeout() ) );
//


}

/*
* Destroys the object and frees any allocated resources
*/
FormLED::~FormLED()
{
// no need to delete child widgets, Qt does it all for us
}

/*
* Sets the strings of the subwidgets using the current
* language.
*/
void FormLED::languageChange()
{
setCaption( tr( "Horse Race LED" ) );
textLabel->setText( tr( "Horse Race LED!" ) );
led[0]->setText( tr( "1" ) );
led[1]->setText( tr( "2" ) );
led[2]->setText( tr( "3" ) );
led[3]->setText( tr( "4" ) );
pushButtonExit->setText( tr( "X" ) );
pushButtonRunTextChange();
}

void FormLED::pushButtonRunTextChange()
{
if(isRunning==false)
{
pushButtonRun->setText( tr( "Start" ) );
pushButtonRun->setPaletteForegroundColor( QColor( 255, 85, 255 ) );
pushButtonRun->setPaletteBackgroundColor( QColor( 170, 255, 0 ) );
}
else
{
pushButtonRun->setText( tr( "Pause" ) );
pushButtonRun->setPaletteForegroundColor( QColor( 255, 255, 255 ) );
pushButtonRun->setPaletteBackgroundColor( QColor( 255, 170, 0 ) );
}
}

void FormLED::onRun()
{
if(isRunning==true)
{
isRunning=false;
timer->stop();
}
else
{
isRunning=true;
onTimeout();
timer->start(INTERVAL);
}
pushButtonRunTextChange();
}

void FormLED::onTimeout()
{
static int lightUp=0;

switch(lightUp)
{
case 0: ioctl(fd,2,0);
break;
case 1: ioctl(fd,1,0);
break;
case 2: ioctl(fd,3,0);
break;
case 3: ioctl(fd,4,0);
break;
}

if(lightUp==0)
led[COUNTS_OF_LEDS-1]->setPaletteBackgroundColor(QColor(170,170,170));
else
led[lightUp-1]->setPaletteBackgroundColor(QColor(170,170,170));
led[lightUp]->setPaletteBackgroundColor(QColor(255,0,0));

lightUp++;
if(lightUp>=COUNTS_OF_LEDS) lightUp=0;
}

...全文
451 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
aoxuehan0424 2014-01-28
  • 打赏
  • 举报
回复
你贴的代码其实不多,主要是没格式,没格式的代码就算只有10行,看起来也费劲儿。
「已注销」 2014-01-28
  • 打赏
  • 举报
回复
慢慢消化吧楼主
zqxwce007 2014-01-24
  • 打赏
  • 举报
回复
代码太长,真心不想看
王洁 2014-01-24
  • 打赏
  • 举报
回复
这么多的代码就得自己看着雪,别人解释了你也是知道了个大概,凡是还得靠自己
一去丶二三里 2014-01-23
  • 打赏
  • 举报
回复
基础这东西很重要啊!这么多代码,估计都没人愿意看了。。。
请叫我砖家 2014-01-23
  • 打赏
  • 举报
回复
一下贴这么多,谁跟你慢慢解释啊,建议你还是一句一句查吧,这样自己也能快速掌握以下,老是让别人告诉你学的不扎实

16,235

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧