void circleForm
::keyPressEvent( QKeyEvent *event
) {
// qDebug( "Key Press Event" );
switch ( event->key() )
{
case Qt::Key_F11:
nextBoltHoleCircle = TRUE;
break;
case Qt::Key_F10:
prevBoltHoleCircle = TRUE;
break;
case Qt::Key_Enter:
needToDrawCircle = TRUE;
break;
default:
}
}
if(needToDrawCircle){
painter.
setPen(QPen(Qt
::blue,
1, Qt
::DashDotDotLine));
painter.drawLine(0,180,380,180);//horizontal line
painter.drawLine(190,0,190,360);//vertical line
painter.
setPen(QPen(Qt
::black,
2, Qt
::SolidLine));
int framecentre_x = 190;
int framecentre_y = 180;
painter.drawPoint(framecentre_x,framecentre_y);//centrepoint
painter.drawEllipse(framecentre_x-100,framecentre_y-100,200,200);//big circle(90,80)
int i;
double x;
angle = 360.00/Hol;
for(i = 0;i < Hol;i++ ){
x = (angle * i);
qDebug(" x = %lf\n",x);
xangle = (x * PI)/180;
qDebug("xangle = %lf",xangle);
xcordinate = cosine(xangle);
qDebug("xcordinate = %lf",xcordinate);
yangle = (x * PI)/180;
qDebug("yangle = %lf",yangle);
ycordinate = sine(yangle);
qDebug("ycordinate = %lf",ycordinate);
painter.
setPen(QPen(Qt
::black,
2, Qt
::SolidLine));
painter.drawEllipse((190 + 100 * xcordinate)- 10,(180 + 100 * ycordinate)- 10,20,20);//working
}
painter.
setBrush(QBrush(Qt
::red, Qt
::SolidPattern));
painter.drawEllipse((190 + 100 * 1)- 10,(180 + 100 * 0)- 10,20,20);
}
needToDrawCircle = FALSE;
if(prevBoltHoleCircle){
qDebug("painting bolt hole circle\n");
qDebug("xcordinate = %lf",xcordinate);
qDebug("ycordinate = %lf",ycordinate);
painter.
setBrush(QBrush(Qt
::blue, Qt
::SolidPattern));
painter.drawEllipse((190 + 100 * xcordinate)- 10,(180 + 100 * ycordinate)- 10,20,20);
qDebug("PREVIOUS\n");
}
prevBoltHoleCircle = FALSE;
if(nextBoltHoleCircle){
qDebug("painting bolt hole circle\n");
qDebug("xcordinate = %lf",xcordinate);
qDebug("ycordinate = %lf",ycordinate);
painter.
setBrush(QBrush(Qt
::blue, Qt
::SolidPattern));
painter.drawEllipse((190 + 100 * xcordinate)- 10,(180 + 100 * ycordinate)- 10,20,20);
qDebug("NEXT\n");
}
nextBoltHoleCircle = FALSE;
}
void circleForm::keyPressEvent( QKeyEvent *event )
{
// qDebug( "Key Press Event" );
switch ( event->key() )
{
case Qt::Key_F11:
nextBoltHoleCircle = TRUE;
break;
case Qt::Key_F10:
prevBoltHoleCircle = TRUE;
break;
case Qt::Key_Enter:
needToDrawCircle = TRUE;
break;
default:
QWidget::keyPressEvent(event);
}
}
void circleForm::PaintEvent(QPaintEvent *event){
QDialog::PaintEvent(event);
if(needToDrawCircle){
QPainter painter(this);
painter.setPen(QPen(Qt::blue, 1, Qt::DashDotDotLine));
painter.drawLine(0,180,380,180);//horizontal line
painter.drawLine(190,0,190,360);//vertical line
painter.setPen(QPen(Qt::black, 2, Qt::SolidLine));
int framecentre_x = 190;
int framecentre_y = 180;
painter.drawPoint(framecentre_x,framecentre_y);//centrepoint
painter.drawEllipse(framecentre_x-100,framecentre_y-100,200,200);//big circle(90,80)
int i;
double x;
angle = 360.00/Hol;
for(i = 0;i < Hol;i++ ){
x = (angle * i);
qDebug(" x = %lf\n",x);
xangle = (x * PI)/180;
qDebug("xangle = %lf",xangle);
xcordinate = cosine(xangle);
qDebug("xcordinate = %lf",xcordinate);
yangle = (x * PI)/180;
qDebug("yangle = %lf",yangle);
ycordinate = sine(yangle);
qDebug("ycordinate = %lf",ycordinate);
painter.setPen(QPen(Qt::black, 2, Qt::SolidLine));
painter.drawEllipse((190 + 100 * xcordinate)- 10,(180 + 100 * ycordinate)- 10,20,20);//working
}
painter.setBrush(QBrush(Qt::red, Qt::SolidPattern));
painter.drawEllipse((190 + 100 * 1)- 10,(180 + 100 * 0)- 10,20,20);
}
needToDrawCircle = FALSE;
if(prevBoltHoleCircle){
QPainter painter(this);
qDebug("painting bolt hole circle\n");
qDebug("xcordinate = %lf",xcordinate);
qDebug("ycordinate = %lf",ycordinate);
painter.setBrush(QBrush(Qt::blue, Qt::SolidPattern));
painter.drawEllipse((190 + 100 * xcordinate)- 10,(180 + 100 * ycordinate)- 10,20,20);
qDebug("PREVIOUS\n");
}
prevBoltHoleCircle = FALSE;
if(nextBoltHoleCircle){
QPainter painter(this);
qDebug("painting bolt hole circle\n");
qDebug("xcordinate = %lf",xcordinate);
qDebug("ycordinate = %lf",ycordinate);
painter.setBrush(QBrush(Qt::blue, Qt::SolidPattern));
painter.drawEllipse((190 + 100 * xcordinate)- 10,(180 + 100 * ycordinate)- 10,20,20);
qDebug("NEXT\n");
}
nextBoltHoleCircle = FALSE;
}
To copy to clipboard, switch view to plain text mode
Bookmarks