Results 1 to 2 of 2

Thread: Freeze_drawing

  1. #1
    Join Date
    Sep 2012
    Posts
    11
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Freeze_drawing

    in my application i am drawing sine-wave using qpainter widget.now i have to implement such functionality that on button pressed wave drawing should be stopped at that instant. and when i pressed same button again it should resume wave drawing from last instant.how to implement freeze functionalit
    drawthread.cpp
    Qt Code:
    1. #include "drawthread.h"
    2. #include <QtCore>
    3. #include <QtGui>
    4.  
    5. DrawThread::DrawThread(QObject *parent):QThread(parent)
    6. {
    7. X1=XStartpoint=50;
    8. Y1=YStartpoint=150;
    9. amplitude = 10;
    10. Ttime = 5;
    11. }
    12.  
    13. void DrawThread::run()
    14. {
    15. while(1)
    16. {
    17. qreal tempAmp;
    18.  
    19.  
    20. tempAmp=amplitude;
    21.  
    22. for(int a=1;a<amplitude;a++)
    23. {
    24. XStartpoint = X1;
    25. YStartpoint = Y1;
    26.  
    27. X1+=Ttime/tempAmp;
    28. tempAmp--;
    29. Y1-=1;
    30.  
    31. emit DrawLine(XStartpoint,YStartpoint,X1,Y1);
    32. }
    33.  
    34. tempAmp=1;
    35. for(int g=amplitude;g>0;g--)
    36. {
    37. XStartpoint = X1;
    38. YStartpoint = Y1;
    39.  
    40. X1+=Ttime/tempAmp;
    41. tempAmp++;
    42. Y1+=1;
    43.  
    44. emit DrawLine(XStartpoint,YStartpoint,X1,Y1);
    45. }
    46.  
    47. // second
    48.  
    49. tempAmp=amplitude;
    50.  
    51. for(int a=1;a<amplitude;a++)
    52. {
    53. XStartpoint = X1;
    54. YStartpoint = Y1;
    55.  
    56. X1+=Ttime/tempAmp;
    57. tempAmp--;
    58. Y1+=1;
    59.  
    60. emit DrawLine(XStartpoint,YStartpoint,X1,Y1);
    61. }
    62.  
    63. tempAmp=1;
    64. for(int g=amplitude;g>0;g--)
    65. {
    66. XStartpoint = X1;
    67. YStartpoint = Y1;
    68.  
    69. X1+=Ttime/tempAmp;
    70. tempAmp++;
    71. Y1-=1;
    72.  
    73. emit DrawLine(XStartpoint,YStartpoint,X1,Y1);
    74. }
    75. if(X1 > 300)
    76. {
    77. X1=XStartpoint=50;
    78. Y1=YStartpoint=150;
    79.  
    80. emit DrawLine(XStartpoint,YStartpoint,X1,Y1);
    81. }
    82. msleep(250);
    83. }
    84. }
    To copy to clipboard, switch view to plain text mode 
    -------------------------------------------------------------------------------------------------------------------------------------------
    pixmap.cpp
    Qt Code:
    1. #include "pixmap.h"
    2. #include "ui_pixmap.h"
    3. #include "drawthread.h"
    4.  
    5. DrawThread thread1;
    6.  
    7. pixmap::pixmap(QWidget *parent) :
    8. QDialog(parent),
    9. ui(new Ui::pixmap)
    10. {
    11. ui->setupUi(this);
    12. X1=XStartpoint=50;
    13. Y1=YStartpoint=150;
    14.  
    15. amplitude = 10;
    16. Ttime = 5;
    17.  
    18. drawpath=new QPainterPath(QPointF(50,150));
    19.  
    20. drawpixmap = new QPixmap(size());
    21. drawpixmap->fill(Qt::transparent);
    22.  
    23. connect(&thread1,SIGNAL(DrawLine(int ,int ,qreal ,qreal )),this,SLOT(display(int ,int ,qreal ,qreal)));
    24. thread1.start();
    25. }
    26.  
    27. pixmap::~pixmap()
    28. {
    29. delete ui;
    30. }
    31.  
    32. void pixmap::paintEvent(QPaintEvent *pEvent)
    33. {
    34.  
    35. QWidget::paintEvent(pEvent);
    36. QPainter painter(this) ;
    37.  
    38. painter.begin(drawpixmap);
    39. QPen pen1(Qt::red, 2);
    40. QPen pen2(Qt::magenta, 2);
    41. QPen pen3(Qt::green, 1);
    42.  
    43.  
    44. painter.setRenderHint(QPainter::SmoothPixmapTransform,true);
    45. painter.setPen(pen1);
    46.  
    47. painter.drawLine(50,100,50,250); //Y-AXIS
    48. painter.drawLine(50,150,350,150); //X-AXIS
    49.  
    50.  
    51. painter.drawText(360,150,"Time ");
    52. painter.drawText(50,80,"Amplitude");
    53.  
    54. //y-arrow
    55. painter.drawLine(50,100,40,110);
    56. painter.drawLine(50,100,60,110);
    57.  
    58. // //x-arrows
    59.  
    60. painter.setPen(pen2);
    61.  
    62. painter.drawLine(XStartpoint,YStartpoint,XStartpoint-5,YStartpoint-5);
    63. painter.drawLine(XStartpoint,YStartpoint,XStartpoint-5,YStartpoint+5);
    64.  
    65. painter.setPen(pen3);
    66.  
    67. if(!drawpath->isEmpty())
    68. {
    69. painter.drawPath(*drawpath);
    70. painter.drawPixmap(0,0,*drawpixmap);
    71. }
    72. }
    73.  
    74. void pixmap::display(int lastx,int lasty,qreal currx,qreal curry)
    75. {
    76. X1=currx;
    77. Y1=curry;
    78. XStartpoint=lastx;
    79. YStartpoint=lasty;
    80.  
    81. if(X1==XStartpoint)
    82. {
    83. *drawpath=drawpath->subtracted(*drawpath);
    84. }
    85.  
    86. drawpath->moveTo(XStartpoint,YStartpoint);
    87. drawpath->lineTo(X1,Y1);
    88. repaint();
    89. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 24th June 2015 at 09:13. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Freeze_drawing

    Not sure what you are asking for.

    How to temporarily make a thread wait for something?
    QWaitCondition could be your friend for that.

    Cheers,
    _

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.