边框和填充可以分开取色

This commit is contained in:
sonichy 2022-11-14 12:52:59 +08:00
parent 702ebf9372
commit 304ae634e0
7 changed files with 40 additions and 23 deletions

BIN
HTYPaint

Binary file not shown.

View File

@ -14,3 +14,4 @@
![alt](invert.jpg)
# 参考
Color与Int类型相互转换https://blog.csdn.net/snowdream86/article/details/5273757
获取父窗口里的对象:

View File

@ -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)
@ -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(); x<rect.x() + rect.width(); x++){
for(int y = rect.y(); y < rect.y() + rect.height(); y++){
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, brush.color());
}
}
@ -194,11 +193,24 @@ void ImageWidget::draw(QImage &img)
painter.drawImage(target, imgmove, source);
break;}
case COLORPICKER_DRAW:{
MainWindow *mainWindow = (MainWindow*)parentWidget()->parentWidget()->parentWidget();
qDebug() << mainWindow->checkBox_color_border->isChecked() << mainWindow->checkBox_color_fill->isChecked();
QRgb RGB = imgtemp.pixel(startPnt.x(),startPnt.y());
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);
emit pick(pen.color());
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);
}
@ -757,9 +769,13 @@ bool ImageWidget::eventFilter(QObject *obj, QEvent *event)
Q_UNUSED(obj);
if (event->type() == QEvent::MouseMove) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(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;
}

View File

@ -14,6 +14,7 @@
#include <QRect>
#include <QMessageBox>
//线段
//typedef struct myLine{
// QPoint startPnt;

View File

@ -1,6 +1,5 @@
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
int main(int argc, char *argv[])
{

View File

@ -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();
}

View File

@ -37,6 +37,7 @@
#include <QShortcut>
#include <QSettings>
#include <QMetaEnum>
//#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);