修复:删除选区操作后没有设置回到框选工具。增加:群组工具栏Action,实现互斥Checked。

This commit is contained in:
sonichy 2019-06-13 11:47:55 +08:00
parent 5e0e775e90
commit 9102549c62
11 changed files with 130 additions and 35 deletions

BIN
HTYPaint

Binary file not shown.

BIN
HTYPaint.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -5,7 +5,6 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = HTYPaint
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
imagewidget.cpp
@ -18,4 +17,4 @@ FORMS += mainwindow.ui
RESOURCES += \
res.qrc
RC_FILE = res.rc
RC_FILE = res.rc

View File

@ -175,9 +175,10 @@ void ImageWidget::draw(QImage &img)
QRect rect(startPnt, endPnt);
for(int x = rect.x(); x<rect.x() + rect.width(); x++){
for(int y = rect.y(); y < rect.y() + rect.height(); y++){
image.setPixelColor(x, y, QColor(0,0,0,0));
image.setPixelColor(x, y, brush.color());
}
}
draw_type = SELECT_DRAW;
break;}
case MOVE_DRAW:{
QRect target(endPnt,imgmove.size());
@ -672,8 +673,9 @@ void ImageWidget::transparent()
for(int x=0; x<w; x++){
for(int y=0; y<h; y++){
QRgb RGB = image.pixel(x,y);
if (RGB == pen.color().rgb()){
QRgb RGBT = qRgba(qRed(RGB),qGreen(RGB),qBlue(RGB),0);
//if (RGB == pen.color().rgb()) {//颜色相等
if(qAbs(qRed(RGB) - pen.color().red()) <= pen.width() && qAbs(qGreen(RGB) - pen.color().green()) <= pen.width() && qAbs(qBlue(RGB) - pen.color().blue()) < pen.width()){//颜色近似
QRgb RGBT = qRgba(qRed(RGB), qGreen(RGB), qBlue(RGB), 0);
imgTansparent.setPixel(x,y,RGBT);
}else{
imgTansparent.setPixel(x,y,RGB);
@ -753,4 +755,29 @@ void ImageWidget::mosaic(int p)
QPainter painter(&imgtemp);
painter.drawImage(xs,ys,imgMosaic);
update();
}
void ImageWidget::matting()
{
//抠图,不可能完成的任务
int w,h;
w = imgtemp.width();
h = imgtemp.height();
QImage imgTansparent(w,h,QImage::Format_ARGB32);
int gray = qGray(pen.color().rgb());
for(int x=0; x<w; x++){
for(int y=0; y<h; y++){
QRgb RGB = image.pixel(x,y);
if (qAbs(qGray(RGB) - gray) < 5){//颜色近似
QRgb RGBT = qRgba(qRed(RGB), qGreen(RGB), qBlue(RGB), 0);
imgTansparent.setPixel(x,y,RGBT);
}else{
imgTansparent.setPixel(x,y,RGB);
}
}
}
imgtemp = imgTansparent;
image = imgTansparent;
update();
moveImgbuf();
}

View File

@ -81,6 +81,7 @@ public slots:
void selectAll();
void undo();
void redo();
void matting();
private slots:
void moveUp();

View File

@ -1,3 +1,3 @@
s="[Desktop Entry]\nName=海天鹰画图\nComment=极简单的画图程序\nExec=`pwd`/HTYPaint %u\nIcon=`pwd`/icon.png\nPath=`pwd`\nTerminal=false\nType=Application\nMimeType=image/bmp;image/bmp24;image/ico;image/jpg;image/jpe;image/jpeg;image/jpeg24;image/jng;image/pcd;image/pcx;image/png;image/tga;image/tif;image/tiff;image/tiff24;image/psd;image/xpm;image/dds;image/gif;image/sgi;image/j2k;image/jp2;image/pct;image/webp;image/wdp;image/cr2;image/pef;image/arw;image/nef;image/icb;image/dng;image/vda;image/vst;image/raf;image/orf;image/svg;image/ptif;image/mef;image/mrw;image/xbm;\nCategories=Graphics;"
s="[Desktop Entry]\nName=海天鹰画图\nComment=极简单的画图程序\nExec=`pwd`/HTYPaint %u\nIcon=`pwd`/HTYPaint.png\nPath=`pwd`\nTerminal=false\nType=Application\nMimeType=image/bmp;image/bmp24;image/ico;image/jpg;image/jpe;image/jpeg;image/jpeg24;image/jng;image/pcd;image/pcx;image/png;image/tga;image/tif;image/tiff;image/tiff24;image/psd;image/xpm;image/dds;image/gif;image/sgi;image/j2k;image/jp2;image/pct;image/webp;image/wdp;image/cr2;image/pef;image/arw;image/nef;image/icb;image/dng;image/vda;image/vst;image/raf;image/orf;image/svg;image/ptif;image/mef;image/mrw;image/xbm;\nCategories=Graphics;"
echo -e $s > HTYPaint.desktop
cp `pwd`/HTYPaint.desktop ~/.local/share/applications/HTYPaint.desktop

View File

@ -33,6 +33,19 @@ MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QActionGroup *AG = new QActionGroup(this);
AG->addAction(ui->actionPencil);
AG->addAction(ui->actionLine);
AG->addAction(ui->actionArrow);
AG->addAction(ui->actionRect);
AG->addAction(ui->actionEllipse);
AG->addAction(ui->actionText);
AG->addAction(ui->actionColorPicker);
AG->addAction(ui->actionFill);
AG->addAction(ui->actionErase);
AG->addAction(ui->actionMove);
AG->addAction(ui->actionRectselect);
setStyleSheet("QScrollArea{ background-color:#cccccc; }");
//状态栏
LSB1 = new QLabel("欢迎使用海天鹰画图!");
@ -105,6 +118,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(ui->actionZoomin, SIGNAL(triggered(bool)), imageWidget, SLOT(zoomin()));
connect(ui->actionZoomout, SIGNAL(triggered(bool)), imageWidget, SLOT(zoomout()));
connect(ui->actionZoom1, SIGNAL(triggered(bool)), imageWidget, SLOT(zoom1()));
connect(ui->action_matting, SIGNAL(triggered(bool)), imageWidget, SLOT(matting()));
connect(btnColorFill, SIGNAL(clicked()), this, SLOT(setColorFill()));
connect(btnColorBorder, SIGNAL(clicked()), this, SLOT(setColorBorder()));
@ -138,7 +152,7 @@ void MainWindow::resizeEvent(QResizeEvent *event)
void MainWindow::on_action_changelog_triggered()
{
QString s = "1.12\n(2019-05)\n修复PNG转灰度图透明度丢失。\n\n1.11\n(2019-04)\n修改:删除选取填充,白色改成透明色。\n增加:棋盘背景。\n增加:鼠标移动定位文字。\n增加Ctrl+鼠标滚轮 改变线粗或字体大小。\n\n1.10\n(2018-12)\n增加:选区马赛克。\n\n1.9\n(2018-11)\n增加:画笔粗细快捷键,画图更加方便。\n\n1.8\n(2018-05)\n修复:删除选区有虚线框,从右键打开方式无法打开文件。\n\n1.7\n(2017-11)\n颜色透明工具,取色后在边框色、填充色显示,超出边界清空鼠标位置信息。\n增加灰色背景,凸显绘图区域。\n优化代码。\n(2017-10)\n简化工具信号简化setCursor()。\n(2017-09)\n增加箭头工具。\n增加抗锯齿。\n\n1.6\n(2017-07)\n更新日志消息窗口写不下了,改成带滚动条的文本框。\n自定义信号结合事件过滤器,把鼠标移动位置发送到主窗体信息栏。\n增加拖放打开文件。\n(2017-06)\n使用自定义信号解决子类发信息给主窗体状态栏问题致谢rekols。\n(2017-05)\n右键打开文件记忆文件路径。\n\n1.5 (2017-04)\n透明色反色不改变。\n增加取色工具,橡皮擦颜色不再固定为白色,而是填充色。\n\n1.4 (2017-03)\n支持命令行打开文件和打开方式打开文件。\n修复鼠标指针引用本地文件没引用资源文件引起启动path参数改变不能加载图标的问题。\n菜单的SIGNAL-SLOT改为on_action_triggered()\n修复PNG图片裁剪丢失透明度问题。\n新建图像为透明图像。\n\n1.3 (2017-03)\n实现选区模糊。\n加入模糊滤镜。\n\n1.2 (2017-02)\n文件名显示在窗口标题栏。\n区别保存和另存为。\n增加导入图片。\n\n1.1 (2017-01)\n新增灰度、反色。\n\n1.0 (2017-01)\n解决删除选区后画不出选框的问题。\n恢复撤销。\n增加全选。\n实现选区或剪贴板移动!\n保存时自动获取打开文件的路径。\n增加按像素、比例缩放。\n实现在属性窗口设置画布大小。\n2016-12\n增加快捷键控制选框及其边框移动。\n绘图代码从MainWindow向imageWidget迁移。\n实现水平镜像、垂直镜像。\n实现放大、缩小、原始大小。\n为了增加滚动条增加自定义imageWidget。\n状态栏显示绘图详情。\n复制选区到系统剪贴板,从系统剪贴板获取图像粘贴。\n优化颜色选择交互。\n增加撤销、重做功能有BUG。\n设为壁纸。\n画选区,剪裁选区。\n新建图片,打开图片,保存图片。\n实现画点、线、框、圆、字。";
QString s = "1.13\n(2019-06)\n修复:删除选区操作后没有设置回到框选工具。\n群组工具栏Action实现互斥Checked。\n\n1.12\n(2019-05)\n修复PNG转灰度图透明度丢失。\n\n1.11\n(2019-04)\n修改:删除选取填充,白色改成透明色。\n增加:棋盘背景。\n增加:鼠标移动定位文字。\n增加Ctrl+鼠标滚轮 改变线粗或字体大小。\n\n1.10\n(2018-12)\n增加:选区马赛克。\n\n1.9\n(2018-11)\n增加:画笔粗细快捷键,画图更加方便。\n\n1.8\n(2018-05)\n修复:删除选区有虚线框,从右键打开方式无法打开文件。\n\n1.7\n(2017-11)\n颜色透明工具,取色后在边框色、填充色显示,超出边界清空鼠标位置信息。\n增加灰色背景,凸显绘图区域。\n优化代码。\n(2017-10)\n简化工具信号简化setCursor()。\n(2017-09)\n增加箭头工具。\n增加抗锯齿。\n\n1.6\n(2017-07)\n更新日志消息窗口写不下了,改成带滚动条的文本框。\n自定义信号结合事件过滤器,把鼠标移动位置发送到主窗体信息栏。\n增加拖放打开文件。\n(2017-06)\n使用自定义信号解决子类发信息给主窗体状态栏问题致谢rekols。\n(2017-05)\n右键打开文件记忆文件路径。\n\n1.5 (2017-04)\n透明色反色不改变。\n增加取色工具,橡皮擦颜色不再固定为白色,而是填充色。\n\n1.4 (2017-03)\n支持命令行打开文件和打开方式打开文件。\n修复鼠标指针引用本地文件没引用资源文件引起启动path参数改变不能加载图标的问题。\n菜单的SIGNAL-SLOT改为on_action_triggered()\n修复PNG图片裁剪丢失透明度问题。\n新建图像为透明图像。\n\n1.3 (2017-03)\n实现选区模糊。\n加入模糊滤镜。\n\n1.2 (2017-02)\n文件名显示在窗口标题栏。\n区别保存和另存为。\n增加导入图片。\n\n1.1 (2017-01)\n新增灰度、反色。\n\n1.0 (2017-01)\n解决删除选区后画不出选框的问题。\n恢复撤销。\n增加全选。\n实现选区或剪贴板移动!\n保存时自动获取打开文件的路径。\n增加按像素、比例缩放。\n实现在属性窗口设置画布大小。\n2016-12\n增加快捷键控制选框及其边框移动。\n绘图代码从MainWindow向imageWidget迁移。\n实现水平镜像、垂直镜像。\n实现放大、缩小、原始大小。\n为了增加滚动条增加自定义imageWidget。\n状态栏显示绘图详情。\n复制选区到系统剪贴板,从系统剪贴板获取图像粘贴。\n优化颜色选择交互。\n增加撤销、重做功能有BUG。\n设为壁纸。\n画选区,剪裁选区。\n新建图片,打开图片,保存图片。\n实现画点、线、框、圆、字。";
QDialog *dialog = new QDialog;
dialog->setWindowTitle("更新历史");
dialog->setFixedSize(400,300);
@ -168,8 +182,8 @@ void MainWindow::on_action_aboutQt_triggered()
void MainWindow::on_action_about_triggered()
{
QMessageBox aboutMB(QMessageBox::NoIcon, "关于", "海天鹰画图 1.12\n一款基于 Qt 的画图程序。\n作者:黄颖\nE-mail: sonichy@163.com\n主页https://github.com/sonichy\n参考文献:\n绘图:\nhttp://tzc.is-programmer.com/posts/534.html\nhttp://lizhigg.love.blog.163.com/blog/static/62611781201222105550184/\n滚动条http://down.51cto.com/data/233634\n灰度图http://www.cnblogs.com/xianglan/archive/2010/12/24/1915905.html\n拖放打开文件http://blog.csdn.net/rl529014/article/details/53057577");
aboutMB.setIconPixmap(QPixmap(":/icon.png"));
QMessageBox aboutMB(QMessageBox::NoIcon, "关于", "海天鹰画图 1.13\n一款基于 Qt 的画图程序。\n作者:黄颖\nE-mail: sonichy@163.com\n主页https://github.com/sonichy\n参考文献:\n绘图:\nhttp://tzc.is-programmer.com/posts/534.html\nhttp://lizhigg.love.blog.163.com/blog/static/62611781201222105550184/\n滚动条http://down.51cto.com/data/233634\n灰度图http://www.cnblogs.com/xianglan/archive/2010/12/24/1915905.html\n拖放打开文件http://blog.csdn.net/rl529014/article/details/53057577");
aboutMB.setIconPixmap(QPixmap(":/HTYPaint.png"));
aboutMB.exec();
}
@ -205,11 +219,9 @@ void MainWindow::textChange(QString s)
void MainWindow::on_action_open_triggered()
{
if(path==""){
path = QFileDialog::getOpenFileName(this,"打开图片", ".", "图片文件(*.jpg *.jpeg *.png *.bmp)");
}else{
path = QFileDialog::getOpenFileName(this,"打开图片", path, "图片文件(*.jpg *.jpeg *.png *.bmp)");
}
if (path=="")
path = ".";
path = QFileDialog::getOpenFileName(this,"打开图片", path, "图片文件(*.jpg *.jpeg *.png *.bmp)");
if(path.length() != 0){
open(path);
}

View File

@ -18,7 +18,7 @@
</property>
<property name="windowIcon">
<iconset resource="res.qrc">
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
<normaloff>:/HTYPaint.png</normaloff>:/HTYPaint.png</iconset>
</property>
<widget class="QWidget" name="centralWidget"/>
<widget class="QMenuBar" name="menuBar">
@ -27,7 +27,7 @@
<x>0</x>
<y>0</y>
<width>1050</width>
<height>23</height>
<height>26</height>
</rect>
</property>
<widget class="QMenu" name="menu_file">
@ -66,6 +66,7 @@
<addaction name="action_blur"/>
<addaction name="action_transparent"/>
<addaction name="action_mosaic"/>
<addaction name="action_matting"/>
</widget>
<widget class="QMenu" name="menu_about">
<property name="title">
@ -115,7 +116,8 @@
<widget class="QStatusBar" name="statusBar"/>
<action name="action_open">
<property name="icon">
<iconset theme="document-open"/>
<iconset theme="document-open">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>打开</string>
@ -126,7 +128,8 @@
</action>
<action name="action_save">
<property name="icon">
<iconset theme="document-save"/>
<iconset theme="document-save">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>保存</string>
@ -137,7 +140,8 @@
</action>
<action name="action_saveas">
<property name="icon">
<iconset theme="document-save-as"/>
<iconset theme="document-save-as">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>另存为</string>
@ -148,7 +152,8 @@
</action>
<action name="action_quit">
<property name="icon">
<iconset theme="application-exit"/>
<iconset theme="application-exit">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>退出</string>
@ -159,7 +164,8 @@
</action>
<action name="action_undo">
<property name="icon">
<iconset theme="edit-undo"/>
<iconset theme="edit-undo">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>撤销</string>
@ -170,7 +176,8 @@
</action>
<action name="action_redo">
<property name="icon">
<iconset theme="edit-redo"/>
<iconset theme="edit-redo">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>重做</string>
@ -181,7 +188,8 @@
</action>
<action name="action_copy">
<property name="icon">
<iconset theme="edit-copy"/>
<iconset theme="edit-copy">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>复制</string>
@ -192,7 +200,8 @@
</action>
<action name="action_cut">
<property name="icon">
<iconset theme="edit-cut"/>
<iconset theme="edit-cut">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>剪切</string>
@ -203,7 +212,8 @@
</action>
<action name="action_paste">
<property name="icon">
<iconset theme="edit-paste"/>
<iconset theme="edit-paste">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>粘贴</string>
@ -214,7 +224,8 @@
</action>
<action name="action_selectAll">
<property name="icon">
<iconset theme="edit-select-all"/>
<iconset theme="edit-select-all">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>全选</string>
@ -225,7 +236,8 @@
</action>
<action name="action_delete">
<property name="icon">
<iconset theme="edit-delete"/>
<iconset theme="edit-delete">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>删除</string>
@ -258,7 +270,8 @@
</action>
<action name="action_property">
<property name="icon">
<iconset theme="document-properties"/>
<iconset theme="document-properties">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>属性</string>
@ -269,7 +282,8 @@
</action>
<action name="action_setWallpaper">
<property name="icon">
<iconset theme="computer"/>
<iconset theme="computer">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>设为壁纸</string>
@ -277,7 +291,8 @@
</action>
<action name="action_help">
<property name="icon">
<iconset theme="help-contents"/>
<iconset theme="help-contents">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>帮助</string>
@ -288,7 +303,8 @@
</action>
<action name="action_changelog">
<property name="icon">
<iconset theme="help-faq"/>
<iconset theme="help-faq">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>更新日志</string>
@ -296,7 +312,8 @@
</action>
<action name="action_about">
<property name="icon">
<iconset theme="help-about"/>
<iconset theme="help-about">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>关于</string>
@ -304,7 +321,8 @@
</action>
<action name="action_new">
<property name="icon">
<iconset theme="document-new"/>
<iconset theme="document-new">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>新建</string>
@ -315,7 +333,7 @@
</action>
<action name="actionPencil">
<property name="checkable">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
@ -335,6 +353,9 @@
</property>
</action>
<action name="actionLine">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="res.qrc">
<normaloff>:/line.png</normaloff>:/line.png</iconset>
@ -347,6 +368,9 @@
</property>
</action>
<action name="actionEllipse">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="res.qrc">
<normaloff>:/ellipse.png</normaloff>:/ellipse.png</iconset>
@ -359,6 +383,9 @@
</property>
</action>
<action name="actionRect">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="res.qrc">
<normaloff>:/rect.png</normaloff>:/rect.png</iconset>
@ -371,6 +398,9 @@
</property>
</action>
<action name="actionText">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="res.qrc">
<normaloff>:/text.png</normaloff>:/text.png</iconset>
@ -383,6 +413,9 @@
</property>
</action>
<action name="actionErase">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="res.qrc">
<normaloff>:/eraser.png</normaloff>:/eraser.png</iconset>
@ -395,6 +428,9 @@
</property>
</action>
<action name="actionMove">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="res.qrc">
<normaloff>:/move.png</normaloff>:/move.png</iconset>
@ -407,6 +443,9 @@
</property>
</action>
<action name="actionRectselect">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="res.qrc">
<normaloff>:/rectselect.png</normaloff>:/rectselect.png</iconset>
@ -459,6 +498,9 @@
</property>
</action>
<action name="actionCutSelect">
<property name="checkable">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="res.qrc">
<normaloff>:/clip.png</normaloff>:/clip.png</iconset>
@ -471,6 +513,9 @@
</property>
</action>
<action name="actionFill">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="res.qrc">
<normaloff>:/fill.png</normaloff>:/fill.png</iconset>
@ -595,6 +640,9 @@
</property>
</action>
<action name="actionColorPicker">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="res.qrc">
<normaloff>:/color_picker.png</normaloff>:/color_picker.png</iconset>
@ -607,6 +655,9 @@
</property>
</action>
<action name="actionArrow">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="res.qrc">
<normaloff>:/arrow.png</normaloff>:/arrow.png</iconset>
@ -634,6 +685,11 @@
<string>Ctrl+M</string>
</property>
</action>
<action name="action_matting">
<property name="text">
<string>抠图</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 177 B

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1,6 +1,5 @@
<RCC>
<qresource prefix="/">
<file>icon.png</file>
<file>clip.png</file>
<file>ellipse.png</file>
<file>eraser.png</file>
@ -20,5 +19,6 @@
<file>MirrorVertical.png</file>
<file>color_picker.png</file>
<file>arrow.png</file>
<file>HTYPaint.png</file>
</qresource>
</RCC>