#include "curchatwidget.h"

CurChatWidget::CurChatWidget(QWidget * parent  ):QWidget(parent)
{

}
 CurChatWidget::~CurChatWidget()
 {

 }

void   CurChatWidget::painteXY(QPainter & painter)
{
    // 获取Widget的尺寸
    int width = this->width();
    int height = this->height();

    // 绘制X轴
    int marDec = 20;//边距
    painter.drawLine(0+marDec, height-marDec, width-marDec, height-marDec);

    // 绘制Y轴
    painter.drawLine(0+marDec, height-marDec, 0+marDec, 0+marDec);
    //横向分为五分
    for(int i =0;i< 5;i++)
    {
        //获取图形宽度
        int paWidth = width - marDec*2;
        int paheight = height -  marDec*2;
        int perWidth = paWidth/5;
        int xstart = marDec +perWidth* i;
        int ystart = marDec ;

        int xend = marDec +perWidth* i;
        int yend  = paheight+marDec;
         painter.setPen(Qt::lightGray);
         painter.drawLine(xstart, ystart, xend, yend);

         //每份里面又分为五分，虚线
         for(int j= 1 ;j<5;j++)
         {
             int  xstartSmall  =    xstart +perWidth/5* j;
             int ystartSmall   =    marDec ;

             int xendSmall= xstart +perWidth/5* j;
             int yendSmall  = paheight + marDec;
                 QPen pen;
                // QColor color(0xff,0,0);
                 QColor color( Qt::lightGray);
                 pen.setColor(color);
                 pen.setWidth(2);
                 pen.setCapStyle(Qt::RoundCap);
                 pen.setJoinStyle(Qt::BevelJoin);
                 pen.setStyle(Qt::DotLine);

             painter.setPen(pen);
             painter.drawLine(xstartSmall, ystartSmall, xendSmall, yendSmall);
         }
    }
}

void CurChatWidget::paintEvent(QPaintEvent *)
{
         QPainter painter(this);
          painter.setRenderHint(QPainter::Antialiasing, true);

          // 设置画笔的颜色和样式
          painter.setPen(Qt::black);
     painteXY(painter);




  }
