6 Publisher::Publisher( QWidget *parent, const char *name )
7 : QWidget( parent, name )
14 while(m_incx==0) m_incx=(rand()%3-1)*m_stepx;
15 while(m_incy==0) m_incy=(rand()%3-1)*m_stepy;
17 m_shapeRect.setRect(0,0,25,45);
20 void Publisher::Create(QString name, char shape, char color, long strength)
22 NtpTime timePersistence;
24 m_mainFrm = new MainForm;
25 Text = new QLabel( m_mainFrm, "Text" );
26 Text->setGeometry( QRect(10 , 0, 60, 15 ) );
27 Text->setText( trUtf8( "Strength : " ) );
28 str = new QSlider(m_mainFrm, "str" );
29 str->setGeometry( QRect( 70, 0, 130, 15 ) );
30 str->setMaxValue( 10 );
31 str->setOrientation( QSlider::Horizontal );
32 connect( str, SIGNAL( valueChanged(int) ), this, SLOT(changeStrenght() ) );
34 m_mainFrm->SetProperties(shape,color);
35 m_shapeRect.moveBy(rand()%m_mainFrm->MaxX(),rand()%m_mainFrm->MaxY());
44 strTitle="Publisher : "+name+" (Topic=";
49 strTitle+="RECTANGLE, Type=";
53 strTitle+="ELLIPSE, Type=";
57 strTitle+="TRIANGLE, Type=";
83 NtpTimeAssembFromMs(timePersistence, 5, 0);
84 h_pub=ORTEAppPublAdd(app1,topic,type,
85 &timePersistence,strength);
87 strTitle+=", Strength="+QString::number(strength)+" )";
88 m_mainFrm->setCaption(strTitle);
91 QTimer *timer = new QTimer(this);
92 connect( timer, SIGNAL(timeout()), SLOT(Timer()));
93 timer->start( 50, FALSE );
96 void Publisher::Timer()
99 memset(msg,0,sizeof(msg));
101 sprintf(msg,"%i %i %i %i",m_shapeRect.left(),m_shapeRect.top(),m_shapeRect.right(),m_shapeRect.bottom());
102 //Don't forget add to length last zero char !!!
103 ORTEAppPublSend(app1,h_pub,msg,strlen(msg)+1);
106 void Publisher::MoveShape()
108 if(m_shapeRect.left()<=0) m_incx=m_stepx;
109 if(m_shapeRect.top()<=0) m_incy=m_stepy;
110 if((m_shapeRect.right())>=m_mainFrm->MaxX()) m_incx=-m_stepx;
111 if((m_shapeRect.bottom())>=m_mainFrm->MaxY()) m_incy=-m_stepy;
113 if(m_mainFrm->View->m_mousePressed==1)
115 int tmpW=m_shapeRect.width();
116 int tmpH=m_shapeRect.height();
118 m_shapeRect.setRect(m_mainFrm->View->m_mouseX-tmpW/2,m_mainFrm->View->m_mouseY-tmpH/2,tmpW,tmpH);
122 m_shapeRect.moveBy(m_incx,m_incy);
125 m_mainFrm->SetShapeRect(m_shapeRect);
128 void Publisher::Destroy()
130 m_mainFrm->WantClose();
132 ORTEAppDestroy(app1);
134 void Publisher::changeStrenght()
136 ORTEPublProp publ_prop;
137 ORTEAppPublPropGet(this->app1,this->h_pub,&publ_prop);
138 publ_prop.strength=str->value();
139 ORTEAppPublPropSet(this->app1,this->h_pub,&publ_prop);
140 QString name=QString::number(str->value());
141 if((str->value())<10) name+=" ";
142 (this->strTitle).replace((this->strTitle).length()-3,2,name);
143 (this->m_mainFrm)->setCaption(this->strTitle);