#ifndef PaintPane_H

#define PaintPane_H



#include <qwidget.h>

#include <qpainter.h>

#include <qvaluevector.h>





//

// zobrazovaci panel

//

class PaintPane : public QWidget

{

    Q_OBJECT

public:

    //

    // konstruktor

    //

    PaintPane( QWidget *parent = 0, const char *name = 0): QWidget( parent, name, WResizeNoErase ) 

    {

 

     space1 = 20;  //vzdalenost mezi osou a okrajem kreslici plochy

     pointSize = 3;  //velikost jednoho jedince zobrazeneho jako ctverecek o dane velikosti

     fontSize = 5;   //velikost pisma pro popis os

     

     color[0]=Qt::green;

     color[1]=Qt::blue;

     color[2]=Qt::red;    

     

     brush[0]=QBrush(Qt::green, Qt::SolidPattern);

     brush[1]=QBrush(Qt::blue, Qt::SolidPattern);

     brush[2]=QBrush(Qt::red, Qt::SolidPattern);

    }

    

    //

    // destruktor

    //

    ~PaintPane(){}

    

    QColor color[3];

    QBrush brush[3];

    int space1;

    int fontSize;

    int pointSize;



    QRect v;

    int h;

    int w;

  

    

    //

    // zobrazeni vektoru

    //

 void showIt()

 { 

     QPainter  paint(this);

     v = paint.viewport();

     h = v.height();

     w = v.width(); 



     paint.drawLine(space1, space1/2 ,space1, h-space1/2);  // nakresli vertikalni osu

     paint.drawLine(space1/2, h-space1, w,h-space1 );  // nakresli horizontalni osu

     QFont font( "Helvetica", fontSize );

     paint.setFont( font );

 

     for(int ii=0; ii<11; ii++)   //vertikalni osa

     {

  paint.drawText( space1/4, (h-9*space1/8)-h/11*ii, QString("").setNum(10*ii) ); //popis vertikalni osy

              paint.drawLine( space1/2, (h-space1)-h/11*ii,space1,(h-space1)-h/11*ii ); // draw line

     }

     

     for(int ii=0; ii<11; ii++)   //horizontalni osa

     {

  paint.drawText((w-3*space1/4)-w/11*ii, h-space1/2, QString("").setNum(10*(10-ii)) );

              paint.drawLine((w-space1)-w/11*ii, h-space1,(w-space1)-w/11*ii,h-space1/2 ); // draw line

     }



 //////////////////

     paint.setBrush(QBrush(Qt::black, Qt::SolidPattern));

  

     int xpos=10, ypos=20;

for(int kk=0; kk<100;kk++)

{

  paint.setBrush(brush[kk%3]);

  xpos=20; ypos=kk;

  paint.setPen( color[kk%3] );

  paint.drawRoundRect(space1+xpos*w/110-1,h-space1-ypos*h/110-1, pointSize, pointSize); // ted je to ok

}

///////////////////////

 

     if (inputVector.empty()==false)

     {

  int val;

  for(QValueVector<int>::iterator ii = inputVector.begin();ii!=inputVector.end();)

             {

 xpos=*ii++;

             ypos=*ii++;

 val=*ii++;

             paint.setPen( color[val] );

             paint.setBrush(brush[val]);

             paint.drawRoundRect(space1+xpos*w/110-1,h-space1-ypos*h/110-1, pointSize, pointSize); // vyktesli bod v miste danym souradnicemi xpos a ypos

 }

     }

 

};



 

 //

 // nakresli jeden bod na danem miste a danou barvou

 //

 void paintPoint(int xpos, int ypos, int val)

 {

     QPainter paint(this);

     paint.setPen( color[val] );

     paint.setBrush(brush[val]);

     paint.drawRoundRect(space1+xpos*w/110-1,h-space1-ypos*h/110-1, pointSize, pointSize);

     inputVector.append(xpos);

     inputVector.append(ypos);

     inputVector.append(val);     

 }

 

 

 QValueVector<int> inputVector;

 

 

 //

 // vyprazdni seznam vlozenych bodu

 //

 void resetVector(){inputVector.clear();}

 

public slots:

protected:

    void   paintEvent( QPaintEvent * ){ showIt();}

private:



};



#endif

