#include "mypaint.h"
#include<QPushButton>
#include<QWidget>
#include<math.h>
MyPaint::MyPaint(QWidget *parent) :
QMainWindow(parent)
, m_curvePen(Qt::black)
, m_dragging(false)
{
m_curvePen.setWidth(2);
m_colors[0] = Qt::green;
m_colors[1] = Qt::red;
m_colors[2] = Qt::blue;
m_colors[3] = Qt::green;
for (int i = 0; i < NUM_POINTS; i++) {
m_pens[i] = QPen(m_colors[i]);
m_brushes[i] = QBrush(m_colors[i]);
}
m_points[StartPoint] = QPointF(200, height() - 20);
m_points[ControlPoint1] = QPointF(width() - 20, height() - 20);
m_points[ControlPoint2] = QPointF(200, 60);
m_points[EndPoint] = QPointF(width() - 20, 60);
_lpress = false;//初始鼠标左键未按下
_drawType = 0;//初始为什么都不画
_drag = 0;//默认非拖拽模式
_begin = pos();//拖拽的参考坐标,方便计算位移
_openflag = 0;//初始不打开图片
this->setGeometry(250,200,960,720);//设置窗体大小、位置
setMouseTracking(true);//开启鼠标实时追踪,监听鼠标移动事件,默认只有按下时才监听
//设置背景颜色
this->setStyleSheet("background-color:white;");
//创建工具栏
QToolBar *tbar = addToolBar(tr("工具栏"));
tbar->setMovable(false);//工具栏不可移动
tbar->setIconSize(QSize(20, 20));//设置动作图标的尺寸
tbar->setStyleSheet("background-color:rgb(155,155,155)");//背景色
_Rmenu = new QMenu(this);//创建右键菜单
_Rmenu->addAction(tr("保存 \tCtrl+S"), this, SLOT(SavePic()));//添加菜单动作
_Rmenu->addAction(tr("退出 \tALT+F4"), this, SLOT(close()));//添加菜单动作
_Rmenu->setStyleSheet("background-color:rgb(199,237,204)");//设置背景色
QAction *openAction = new QAction(tr("&打开"), this);//打开动作
openAction->setIcon(QIcon(":/png/images/open.png"));//图标
openAction->setShortcut(QKeySequence(tr("Ctrl+O")));//热键
tbar->addAction(openAction);//添加到工具栏
QAction *saveAction = new QAction(tr("&保存"), this);//保存动作
saveAction->setIcon(QIcon(":/png/images/save.png"));//图标
saveAction->setShortcut(QKeySequence(tr("Ctrl+S")));//热键
tbar->addAction(saveAction);//添加到工具栏
QAction *lineAction = new QAction(tr("&DDA"), this);//直线动作
lineAction->setIcon(QIcon(":/png/images/dda.png"));//图标
lineAction->setShortcut(QKeySequence(tr("Ctrl+L")));//热键
tbar->addAction(lineAction);//添加到工具栏
QAction *lineAction1 = new QAction(tr("&中点"), this);//直线动作
lineAction1->setIcon(QIcon(":/png/images/中点.png"));//图标
lineAction1->setShortcut(QKeySequence(tr("Ctrl+L")));//热键
tbar->addAction(lineAction1);//添加到工具栏
QAction *lineAction2 = new QAction(tr("&Bresenham"), this);//直线动作
lineAction2->setIcon(QIcon(":/png/images/bresenham.png"));//图标
lineAction2->setShortcut(QKeySequence(tr("Ctrl+L")));//热键
tbar->addAction(lineAction2);//添加到工具栏
QAction *rectAction = new QAction(tr("&矩形"), this);//矩形动作
rectAction->setIcon(QIcon(":/png/images/rect.png"));//图标
rectAction->setShortcut(QKeySequence(tr("Ctrl+R")));//热键
tbar->addAction(rectAction);
QAction *ellipseAction = new QAction(tr("&椭圆"), this);//椭圆动作
ellipseAction->setIcon(QIcon(":/png/images/ellipse.png"));//图标
ellipseAction->setShortcut(QKeySequence(tr("Ctrl+E")));//热键
tbar->addAction(ellipseAction);
QAction *typeAction = new QAction(tr("&线宽"), this);//文字动作
typeAction->setIcon(QIcon(":/png/images/线宽3.png"));//图标
typeAction->setShortcut(QKeySequence(tr("Ctrl+T")));//热键
tbar->addAction(typeAction);
QAction *type5Action = new QAction(tr("&线宽"), this);//文字动作
type5Action->setIcon(QIcon(":/png/images/线宽5.png"));//图标
type5Action->setShortcut(QKeySequence(tr("Ctrl+T")));//热键
tbar->addAction(type5Action);
QAction *type7Action = new QAction(tr("&线宽"), this);//文字动作
type7Action->setIcon(QIcon(":/png/images/线宽7.png"));//图标
type7Action->setShortcut(QKeySequence(tr("Ctrl+T")));//热键
tbar->addAction(type7Action);
QAction *colorAction = new QAction(tr("&颜色"), this);//文字动作
colorAction->setIcon(QIcon(":/png/images/红色.png"));//图标
colorAction->setShortcut(QKeySequence(tr("Ctrl+T")));//热键
tbar->addAction(colorAction);
QAction *color1Action = new QAction(tr("&颜色"), this);//文字动作
color1Action->setIcon(QIcon(":/png/images/绿色.png"));//图标
color1Action->setShortcut(QKeySequence(tr("Ctrl+T")));//热键
tbar->addAction(color1Action);
QAction *color2Action = new QAction(tr("&颜色"), this);//文字动作
color2Action->setIcon(QIcon(":/png/images/蓝色.png"));//图标
color2Action->setShortcut(QKeySequence(tr("Ctrl+T")));//热键
tbar->addAction(color2Action);
QAction *polygonAction = new QAction(tr("&扫描转换"), this);//扫描转换
polygonAction->setIcon(QIcon(":/png/images/蓝色.png"));//图标
polygonAction->setShortcut(QKeySequence(tr("Ctrl+T")));//热键
tbar->addAction(polygonAction);
QAction *seedAction = new QAction(tr("&种子填充"), this);//种子填充
seedAction->setIcon(QIcon(":/png/images/蓝色.png"));//图标
seedAction->setShortcut(QKeySequence(tr("Ctrl+T")));//热键
tbar->addAction(seedAction);
QAction *cutAction = new QAction(tr("裁剪"), this);//种子填充
cutAction->setIcon(QIcon(":/png/images/蓝色.png"));//图标
cutAction->setShortcut(QKeySequence(tr("Ctrl+T")));//热键
tbar->addAction(cutAction);
QAction *moveAction = new QAction(tr("平移"), this);//种子填充
moveAction->setIcon(QIcon(":/png/images/蓝色.png"));//图标
moveAction->setShortcut(QKeySequence(tr("Ctrl+T")));//热键
tbar->addAction(moveAction);
QAction *setcenterAction = new QAction(tr("设置中心点"), this);//种子填充
setcenterAction->setIcon(QIcon(":/png/images/蓝色.png"));//图标
setcenterAction->setShortcut(QKeySequence(tr("Ctrl+T")));//热键
tbar->addAction(setcenterAction);
QAction *scaleAction = new QAction(tr("缩放"), this);//种子填充
scaleAction->setIcon(QIcon(":/png/images/蓝色.png"));//图标
scaleAction->setShortcut(QKeySequence(tr("Ctrl+T")));//热键
tbar->addAction(scaleAction);
QAction *rotateAction = new QAction(tr("旋转"), this);//种子填充
rotateAction->setIcon(QIcon(":/png/images/蓝色.png"));//图标
rotateAction->setShortcut(QKeySequence(tr("Ctrl+T")));//热键
tbar->addAction(rotateAction);
QAction *bezierAction = new QAction(tr("贝塞尔"), this);//种子填充
bezierAction->setIcon(QIcon(":/png/images/rect.png"));//图标
bezierAction->setShortcut(QKeySequence(tr("Ctrl+T")));//热键
tbar->addAction(bezierAction);
//连接信号与槽函数
connect(ellipseAction, SIGNAL(triggered()), this, SLOT(Ellipses()));
connect(lineAction, SIGNAL(triggered()), this, SLOT(Line()));
connect(lineAction1, SIGNAL(triggered()), this, SLOT(Line1()));
connect(lineAction2, SIGNAL(triggered()), this, SLOT(Line2()));
connect(rectAction, SIGNAL(triggered()), this, SLOT(Rects()));
connect(saveAction, SIGNAL(triggered()), this, SLOT(SavePic()));
connect(openAction, SIGNAL(triggered()), this, SLOT(OpenPic()));
connect(typeAction, SIGNAL(triggered()), this, SLOT(LineType()));
connect(type5Action, SIGNAL(triggered()), this, SLOT(LineType5()));
connect(type7Action, SIGNAL(triggered()), this, SLOT(LineType7()));
connect(colorAction, SIGNAL(triggered()), this, SLOT(ColorType()));
connect(color1Action, SIGNAL(triggered()), this, SLOT(ColorType1()));
connect(color2Action, SIGNAL(triggered()), this, SLOT(ColorType2()));
connect(polygonAction, SIGN
- 1
- 2
- 3
- 4
- 5
- 6
前往页