• 大小: 25KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-11
  • 语言: 其他
  • 标签: 绘图板  

资源简介

可以实现基本涂鸦功能并且可以绘制矩形,椭圆,直线等基本图形并进行缩放,移动和填充

资源截图

代码片段和文件信息

#include “canvas.h“
#include 
#include
canvas::canvas()
{
    Pixmap =QPixmap(500400); //画布的初始化大小设为500*400

    backColor=Qt::white;

    Pixmap.fill(backColor);//画布初始化背景色使用白色

    /*各标志量初始化*/

    //px1=py1=px2=py2=0;

    shape_flage=0;

    ismoving=0;

    ischoose=0;

    iszooming=0;

    isfilling=0;

    modified=0;

    pen_Color=“黑色“;

    brush_Color=“白色“;

}



/*设置填充颜色*/

void canvas::setBrushColor(QString color)
{

    brush_Color=color;

}



/*设置画笔颜色*/

void canvas::setpenColor(QString color)
{

   pen_Color=color;

}



/*保存画布*/

bool canvas::savePixmap(const QString &fileName const char *fileFormat)
{
    QPixmap visiblePixmap=Pixmap;

    if (visiblePixmap.save(fileName fileFormat))   //实现文件存储

    {
        modified=0;//画布改变标识变量置0

        return 1;

    }

    else

    {

        return 0;

    }

}



/*判断画布是否改变*/

 bool canvas::get_modified()
 {

     return modified;

 }



 /*重绘函数*/

void canvas::paintEvent(QPaintEvent *event)
{

    QPainter pp(this);

    pp.drawPixmap(00Pixmap);//以为(00)原点画出Pixmap上的内容

}



/*鼠标按下事件*/

void canvas::mousePressEvent(QMouseEvent *event)
{
    /*如果按下左键则将该店位置坐标传给起始坐标*/

    if(event->button()==Qt::LeftButton)//鼠标按下左键

    {
        begin=event->pos();//该点坐标赋给begin

        if(ismoving==0&&iszooming==0)//如果进行绘画功能

          {
           set_shape_point(SPbegin.x()begin.y()begin.x()begin.y()shape_flage);//将该点信息存入SP

           ShapePoint.push_back(SP);//将SP存入容器尾部

          }

        if(ismoving==1||iszooming==1)//移动或缩放操作

          {
            shape_num=choose_shape(begin);//选择要移动的图形并将位置信息赋值给shape_num

            if(ischoose==1)//如果选中图形

            {
               /*将起点坐标赋给px1*/

               px1=ShapePoint[shape_num].p1x;
               py1=ShapePoint[shape_num].p1y;

               /*将终点坐标赋给px2*/
               px2=ShapePoint[shape_num].p2x;
               py2=ShapePoint[shape_num].p2y;

            }



        }



        /*对图形进行填充*/
        if(isfilling==1)

         {
            shape_num=choose_shape(begin);//选择填充的图形

            if(ischoose==1)
            {

                ShapePoint[shape_num].Bcolor=brush_Color;//将填充颜色赋给Bcolor

                draw();//绘画
            }

         }

     }
}



/*鼠标移动事件*/

void canvas::mouseMoveEvent(QMouseEvent *event)
{
   if(event->buttons()&Qt::LeftButton)

     {
       if(ismoving==0&&iszooming==0&&shape_flage==0)//绘制普通图形

        {
           /*将该点坐标存到容器中,其中终点与起点相同*/

            end=event->pos();

            set_shape_point(SPend.x()end.y()end.x()end.y()shape_flage);

            ShapePoint.push_back(SP);
        }

        if(ismoving==0&&iszooming==0&&shape_flage!=0)//绘制特殊图形

          {
            /*将该点坐标存到容器中,其中终点与起点相同*/

              end=event->pos();

              set_shape_point(SPbegin.x

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-06-21 02:55  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\
     文件       11073  2014-06-21 02:17  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\canvas.cpp
     文件        2964  2014-06-21 02:03  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\canvas.h
     文件         389  2014-06-20 11:24  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\d.pro
     文件       18900  2014-06-21 02:55  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\d.pro.user
     文件         566  2014-06-16 23:25  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\ellipse.cpp
     文件         522  2014-06-16 17:39  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\ellipse.h
     文件         486  2014-06-16 12:32  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\icon.qrc
     目录           0  2014-06-21 02:25  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\images\
     文件        1028  2009-10-16 18:37  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\images\clear.png
     文件         928  2009-10-16 18:37  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\images\exit.png
     文件         822  2005-12-30 20:46  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\images\left.bmp
     文件        1038  2009-10-16 18:37  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\images\new.png
     文件         854  2009-10-16 18:37  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\images\open.png
     文件         822  2005-12-30 20:46  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\images\right.bmp
     文件         246  2002-01-13 09:42  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\images\save.bmp
     文件         246  2002-01-13 09:42  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\images\saveas.bmp
     文件         246  1999-11-20 10:49  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\images\select.bmp
     文件        1332  2009-09-22 13:43  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\images\zoom-in.png
     文件        1266  2009-09-22 13:43  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\images\zoom-out.png
     文件         592  2014-06-16 17:39  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\line.cpp
     文件         456  2014-06-16 17:39  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\line.h
     文件         295  2014-06-19 23:32  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\main.cpp
     文件        5323  2014-06-21 00:21  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\mainwindow.cpp
     文件        1577  2014-06-21 00:21  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\mainwindow.h
     文件        8584  2014-06-20 17:32  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\mainwindow.ui
     文件         753  2014-06-16 17:43  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\rectangle.cpp
     文件         710  2014-06-16 17:39  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\rectangle.h
     文件         492  2014-06-16 17:41  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\shape.cpp
     文件         461  2014-06-17 23:04  06_12弘深_20125079李杰_20125074段广晗_20124499肖垚 2\shape.h

评论

共有 条评论

相关资源