]> rtime.felk.cvut.cz Git - orte.git/blob - orte/contrib/shape/FPublisher.ui.h
The uLUt files included in ORTE updated to actual version from uLan repository.
[orte.git] / orte / contrib / shape / FPublisher.ui.h
1 /****************************************************************************
2 ** ui.h extension file, included from the uic-generated form implementation.
3 **
4 ** If you wish to add, delete or rename functions or slots use
5 ** Qt Designer which will update this file, preserving your code. Create an
6 ** init() function in place of a constructor, and a destroy() function in
7 ** place of a destructor.
8 *****************************************************************************/
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <qtimer.h> 
12 #include <qapplication.h>
13 #if (QT_VERSION-0 >= 0x040000)
14 #include <QCloseEvent>
15 #endif
16
17 extern QApplication *a;
18
19 void FPublisher::init()
20 {
21     stepx=rand()%2+1;stepy=rand()%2+1;
22     incx=incy=0;
23     while(incx==0) incx=(rand()%3-1)*stepx;
24     while(incy==0) incy=(rand()%3-1)*stepy;
25     rect.setRect(0,0,25,45);
26     ORTEInit(); 
27     domain=ORTEDomainAppCreate(ORTE_DEFAULT_DOMAIN,NULL,NULL,ORTE_FALSE);
28     BoxType_type_register(domain);
29     publisher=NULL;
30 }
31
32 void FPublisher::initPublisher(int icolor,int istrength)
33 {
34     NtpTime     persistence;
35     QString     topic;
36
37     color=icolor;
38     strength=istrength;
39     boxType.color=color;
40     boxType.shape=strength;
41     timer = new QTimer(this);
42     connect( timer, SIGNAL(timeout()), SLOT(Timer()));
43     timer->start( 50, FALSE );
44     view->activateObject(0,color,strength);//color,shape
45     NtpTimeAssembFromMs(persistence, 5, 0);
46     switch(color) {
47         case CL_BLUE:topic="Blue";break;
48         case CL_GREEN:topic="Green";break;
49         case CL_RED:topic="Red";break;
50         case CL_BLACK:topic="Black";break;
51         case CL_YELLOW:topic="Yellow";break;
52     }
53     publisher=ORTEPublicationCreate(
54         domain,
55         topic,
56         "BoxType",
57         &boxType,
58         &persistence,
59         strength,
60         NULL,
61         NULL,
62         NULL);
63 }
64
65 void FPublisher::closeEvent( QCloseEvent *e )
66 {
67     destroy();
68     e->accept();
69 }
70
71 void FPublisher::destroy()
72 {
73     if (domain) {
74       delete timer;
75       ORTEDomainAppDestroy(domain);
76       domain=NULL;
77     }
78 }
79
80 void FPublisher::Timer()
81 {
82     a->lock();
83     if(rect.left()<=0) incx=stepx;
84     if(rect.top()<=0) incy=stepy;
85     if((rect.right())>=view->width()) incx=-stepx;
86     if((rect.bottom())>=view->height()) incy=-stepy;
87     if(view->mousePressed==1) {
88         int tmpW=rect.width();
89         int tmpH=rect.height();
90         rect.setRect(view->mouseX-tmpW/2,view->mouseY-tmpH/2,tmpW,tmpH);
91     } else {
92         rect.moveBy(incx,incy);
93     }
94     view->setPosition(0,rect);
95     //prepare published data
96     boxType.rectangle.top_left_x=rect.left();
97     boxType.rectangle.top_left_y=rect.top();
98     boxType.rectangle.bottom_right_x=rect.right();
99     boxType.rectangle.bottom_right_y=rect.bottom();
100     ORTEPublicationSend(publisher);    
101     a->unlock();
102 }
103
104
105 void FPublisher::strengthChanged()
106 {
107     ORTEPublProp  pp;
108     
109     if (!publisher) return;
110     a->lock();
111     ORTEPublicationPropertiesGet(publisher,&pp);
112     pp.strength=slider->value();
113     ORTEPublicationPropertiesSet(publisher,&pp);
114     a->unlock();
115 }