diff --git a/HTYPaint b/HTYPaint index 6f13b95..d294fbe 100644 Binary files a/HTYPaint and b/HTYPaint differ diff --git a/README.md b/README.md index 2276dc6..cc095ea 100644 --- a/README.md +++ b/README.md @@ -13,4 +13,5 @@ ![alt](gray.jpg) ![alt](invert.jpg) # 参考 -Color与Int类型相互转换:https://blog.csdn.net/snowdream86/article/details/5273757 \ No newline at end of file +Color与Int类型相互转换:https://blog.csdn.net/snowdream86/article/details/5273757 +获取父窗口里的对象: \ No newline at end of file diff --git a/imagewidget.cpp b/imagewidget.cpp index 40b02ad..05a03da 100644 --- a/imagewidget.cpp +++ b/imagewidget.cpp @@ -1,7 +1,6 @@ #include "math.h" -#include "mainwindow.h" -#include "ui_mainwindow.h" #include "imagewidget.h" +#include "mainwindow.h" ImageWidget::ImageWidget(QWidget *parent) : QWidget(parent) @@ -22,7 +21,7 @@ ImageWidget::ImageWidget(QWidget *parent) connect(new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Left), this), SIGNAL(activated()), this, SLOT(moveRightLeft())); connect(new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Right), this), SIGNAL(activated()), this, SLOT(moveRightRight())); connect(new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Up), this), SIGNAL(activated()), this, SLOT(moveBottomUp())); - connect(new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Down), this), SIGNAL(activated()), this, SLOT(moveBottomDown())); + connect(new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Down), this), SIGNAL(activated()), this, SLOT(moveBottomDown())); } ImageWidget::~ImageWidget() @@ -167,7 +166,7 @@ void ImageWidget::draw(QImage &img) break;} case FILL_DRAW: qDebug() << painterPath; - if(!painterPath.isEmpty() && painterPath.contains(startPnt)){ + if (!painterPath.isEmpty() && painterPath.contains(startPnt)) { painter.setBrush(brush); painter.drawPath(painterPath); } @@ -180,8 +179,8 @@ void ImageWidget::draw(QImage &img) break; case DEL_DRAW:{ QRect rect(startPnt, endPnt); - for(int x = rect.x(); xparentWidget()->parentWidget(); + qDebug() << mainWindow->checkBox_color_border->isChecked() << mainWindow->checkBox_color_fill->isChecked(); QRgb RGB = imgtemp.pixel(startPnt.x(),startPnt.y()); - pen.setColor(RGB); - brush.setColor(RGB); - painter.setBrush(brush); - emit pick(pen.color()); + if (mainWindow->checkBox_color_border->isChecked()) { + pen.setColor(RGB); + painter.setPen(pen); + QPalette plt = mainWindow->toolButton_color_border->palette(); + plt.setColor(QPalette::ButtonText, pen.color()); + mainWindow->toolButton_color_border->setPalette(plt); + } + if (mainWindow->checkBox_color_fill->isChecked()) { + brush.setColor(RGB); + painter.setBrush(brush); + QPalette plt = mainWindow->toolButton_color_fill->palette(); + plt.setColor(QPalette::ButtonText, brush.color()); + mainWindow->toolButton_color_fill->setPalette(plt); + } + //emit pick(pen.color()); break;} default: break; @@ -227,7 +239,7 @@ void ImageWidget::mousePressEvent(QMouseEvent *e) default: break; } - if(e->buttons() & Qt::RightButton){ + if (e->buttons() & Qt::RightButton) { imgtemp = image; draw(imgtemp); } @@ -754,12 +766,16 @@ void ImageWidget::blur(int p) bool ImageWidget::eventFilter(QObject *obj, QEvent *event) { - Q_UNUSED(obj); + Q_UNUSED(obj); if (event->type() == QEvent::MouseMove) { QMouseEvent *mouseEvent = static_cast(event); - emit statusBar2Message(QString::number(mouseEvent->pos().x())+","+QString::number(mouseEvent->pos().y())); + //emit statusBar2Message(QString::number(mouseEvent->pos().x()) + "," + QString::number(mouseEvent->pos().y())); + MainWindow *mainWindow = (MainWindow*)parentWidget()->parentWidget()->parentWidget(); + mainWindow->LSB2->setText(QString::number(mouseEvent->pos().x()) + "," + QString::number(mouseEvent->pos().y())); } else if(event->type() == QEvent::Leave) { - emit statusBar2Message(""); + //emit statusBar2Message(""); + MainWindow *mainWindow = (MainWindow*)parentWidget()->parentWidget()->parentWidget(); + mainWindow->LSB2->setText(""); } return false; } diff --git a/imagewidget.h b/imagewidget.h index 8ac05de..c3de461 100644 --- a/imagewidget.h +++ b/imagewidget.h @@ -14,6 +14,7 @@ #include #include + //线段 //typedef struct myLine{ // QPoint startPnt; @@ -53,7 +54,7 @@ public: Q_ENUM(BorderType) ImageWidget(QWidget *parent = nullptr); - ~ImageWidget(); + ~ImageWidget(); DrawType drawType; QImage image, imgtemp, imgbuf[10], imgmove; QPoint startPnt; //起点 @@ -88,7 +89,7 @@ public: void clipPath(int x, int y, int width, int height, bool isConfirm); void deleteBlackBorder(BorderType border_type, int d); -private: +private: QImage imgload,imgpaste; void mousePressEvent(QMouseEvent *e); void mouseMoveEvent(QMouseEvent *e); diff --git a/main.cpp b/main.cpp index fd3025a..2719662 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,5 @@ #include "mainwindow.h" #include -#include int main(int argc, char *argv[]) { diff --git a/mainwindow.cpp b/mainwindow.cpp index fab140e..d61f2b8 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -42,7 +42,7 @@ MainWindow::MainWindow(QWidget *parent) : imageWidget = new ImageWidget; connect(imageWidget, SIGNAL(statusBar1Message(QString)), LSB1, SLOT(setText(QString))); connect(imageWidget, SIGNAL(statusBar2Message(QString)), LSB2, SLOT(setText(QString))); - connect(imageWidget, SIGNAL(pick(QColor)), this, SLOT(setPicker(QColor))); + //connect(imageWidget, SIGNAL(pick(QColor)), this, SLOT(setPicker(QColor))); scrollArea = new QScrollArea; scrollArea->setWidget(imageWidget); scrollArea->widget()->setMinimumSize(600,500); @@ -53,7 +53,6 @@ MainWindow::MainWindow(QWidget *parent) : toolButton_color_border->setToolTip("边框"); ui->mainToolBar->addWidget(toolButton_color_border); checkBox_color_border = new QCheckBox(this); - //checkBox_color_border->setCheckState(Qt::Checked); ui->mainToolBar->addWidget(checkBox_color_border); toolButton_color_fill = new QToolButton(this); toolButton_color_fill->setText("■"); @@ -223,7 +222,7 @@ QColor MainWindow::intToColor(int intColor) void MainWindow::on_action_changelog_triggered() { - QString s = "1.21\n(2022-10)\n增加对比度调整。\n\n1.20\n(2022-05)\n关闭时保存设置,打开时读取设置。\n\n1.19\n(2021-04)\n修复缩放锯齿问题。\n\n1.18\n(2020-12)\n如果粘贴的图片比当前图片大,询问是否扩张,然后处理。\n\n1.17\n(2020-04)\n修复:上个选区残留问题。\n增加:第一次全选可以填充颜色(因路径不能清空只能填充一次,再次填充需要关闭再打开)。\n\n1.16\n(2020-03)\n增加:圆形路径裁剪。\n背景文字改成了描边文字。\n\n1.15\n(2019-11)\n增加:文字工具可以绘制矩形背景。\n\n1.14\n(2019-08)\n增加:颜色调节。\n修复:选择颜色取消时颜色变黑色。\n\n1.13\n(2019-06)\n修复:选区裁剪大小微差。删除选区操作后没有设置回到框选工具。\n优化:信息内容、选区裁剪。群组工具栏Action,实现互斥Checked。\n增加:画线长度信息,画框长、宽信息,微调显示信息,裁剪后滚动条回到0。\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实现画点、线、框、圆、字。"; + QString s = "1.22\n(2022-11)\n边框和填充可以分开取色。\n\n1.21\n(2022-10)\n增加对比度调整。\n\n1.20\n(2022-05)\n关闭时保存设置,打开时读取设置。\n\n1.19\n(2021-04)\n修复缩放锯齿问题。\n\n1.18\n(2020-12)\n如果粘贴的图片比当前图片大,询问是否扩张,然后处理。\n\n1.17\n(2020-04)\n修复:上个选区残留问题。\n增加:第一次全选可以填充颜色(因路径不能清空只能填充一次,再次填充需要关闭再打开)。\n\n1.16\n(2020-03)\n增加:圆形路径裁剪。\n背景文字改成了描边文字。\n\n1.15\n(2019-11)\n增加:文字工具可以绘制矩形背景。\n\n1.14\n(2019-08)\n增加:颜色调节。\n修复:选择颜色取消时颜色变黑色。\n\n1.13\n(2019-06)\n修复:选区裁剪大小微差。删除选区操作后没有设置回到框选工具。\n优化:信息内容、选区裁剪。群组工具栏Action,实现互斥Checked。\n增加:画线长度信息,画框长、宽信息,微调显示信息,裁剪后滚动条回到0。\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); @@ -253,7 +252,7 @@ void MainWindow::on_action_aboutQt_triggered() void MainWindow::on_action_about_triggered() { - QMessageBox aboutMB(QMessageBox::NoIcon, "关于", "海天鹰画图 1.21\n一款基于 Qt 的画图程序。\n作者:海天鹰\nE-mail: sonichy@163.com\n主页:https://gitlink.org.cn/sonichy/HTYPaint\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\nColor与Int类型相互转换:https://blog.csdn.net/snowdream86/article/details/5273757"); + QMessageBox aboutMB(QMessageBox::NoIcon, "关于", "海天鹰画图 1.22\n一款基于 Qt 的画图程序。\n作者:海天鹰\nE-mail: sonichy@163.com\n主页:https://gitlink.org.cn/sonichy/HTYPaint\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\nColor与Int类型相互转换:https://blog.csdn.net/snowdream86/article/details/5273757"); aboutMB.setIconPixmap(QPixmap(":/icon/HTYPaint.png")); aboutMB.exec(); } diff --git a/mainwindow.h b/mainwindow.h index 129b6a6..ad993bc 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -37,6 +37,7 @@ #include #include #include +//#include "imagewidget.h" namespace Ui { class MainWindow; @@ -55,6 +56,7 @@ public: QSpinBox *spinbox_penWidth, *spinw, *spinwr, *spinh, *spinhr; QString text, path; QCheckBox *checkBox_color_fill, *checkBox_color_border; + QLabel *LSB1,*LSB2; QFont font; QString filename; @@ -68,7 +70,6 @@ protected: private: QScrollArea *scrollArea; ImageWidget *imageWidget; - QLabel *LSB1,*LSB2; void readSettings(); QSettings settings; QColor intToColor(int intColor);