Skip to content

Commit

Permalink
[重构图形库以引入圆角矩形绘制功能]: 引入了新的GraphicsRoundedRectItem类以支持圆角矩形的绘制,并重构了相关类…
Browse files Browse the repository at this point in the history
…以适应这一新功能。

- 将文档目录从`doc`更名为`docs`,并更新了所有相关的文件引用路径。
- 删除了旧的圆角编辑窗口图片,并新增了`RoundEdit.jpg`图片。
- 更新了`README.md`中的图片引用路径,并修正了图片显示问题。
- 在`Qt-Graphics.pro`中增加了对新文件`docs/**`的包含。
- 重命名和移动了图片文件,从`doc/`到`docs/`,并新增了`RoundEdit.jpg`。
- 在`drawwidget.cpp`中增加了对圆角矩形和旋转矩形的支持。
- 在`maskdialog.cpp`中进行了一些代码改进,使用`auto`关键字简化类型声明。
- 重构了`rounddialog.cc`和`rounddialog.hpp`,使用新的`GraphicsRoundedRectItem`代替了旧的`GraphicsRectItem`,并增加了预览和遮罩功能。
- 更新了`subtitlsplicingwidget.cc`,将图片格式从`ARGB32`改为`RGBA8888_Premultiplied`以保持一致性。
- 在`CMakeLists.txt`中添加了对新组件`graphicsroundedrectitem`的编译指令。
- 在`basicgraphicsitem.cpp`和`basicgraphicsitem.h`中增加了显示边框的选项,并在各类图形项中实现了边框绘制。
- 更新了`graphics.pro`,增加了对新头文件和源文件的包含。
- 在`graphicsarcitem.cpp`、`graphicscircleitem.cpp`、`graphicslineitem.cpp`、`graphicspixmapitem.cpp`、`graphicspolygonitem.cpp`、`graphicsringitem.cpp`和`graphicsrotatedrectitem.cpp`中增加了边框绘制功能。
- 重构了`graphicsrectitem.cpp`和`graphicsrectitem.h`,现在`GraphicsRectItem`继承自`GraphicsRoundedRectItem`,并使用新的圆角矩形实现。
- 新增了`graphicsroundedrectitem.cc`和`graphicsroundedrectitem.hpp`,提供了圆角矩形的实现。
  • Loading branch information
RealChuan committed Aug 29, 2024
1 parent 0d97583 commit 1686f5d
Show file tree
Hide file tree
Showing 41 changed files with 586 additions and 450 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ name: CMake Build
on:
push:
paths-ignore:
- 'doc/**'
- 'docs/**'
- '.clang-format'
- '.gitignore'
- 'LICENSE'
- 'README*'
pull_request:
paths-ignore:
- 'doc/**'
- 'docs/**'
- '.clang-format'
- '.gitignore'
- 'LICENSE'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/qmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ name: QMake Build
on:
push:
paths-ignore:
- 'doc/**'
- 'docs/**'
- '.clang-format'
- '.gitignore'
- 'LICENSE'
- 'README*'
pull_request:
paths-ignore:
- 'doc/**'
- 'docs/**'
- '.clang-format'
- '.gitignore'
- 'LICENSE'
Expand Down
2 changes: 1 addition & 1 deletion Qt-Graphics.pro
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SUBDIRS += \
examples

DISTFILES += \
doc/** \
docs/** \
.clang* \
LICENSE \
README*
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
## 看图界面

<div align=center>
<img src="doc/ImageView.png" width="90%" height="90%">
<img src="docs/ImageView.png" width="90%" height="90%">
</div>

## Opengl看图界面
Expand All @@ -45,23 +45,21 @@
## 马赛克绘制界面(橡皮擦效果)

<div align=center>
<img src="doc/MaskEdit.png" width="90%" height="90%">
<img src="docs/MaskEdit.png" width="90%" height="90%">
</div>

## 圆角编辑窗口(也可编辑成圆形图标)

1. 一定要保存为PNG,不然圆角处会变成黑色;

<div align=center>
<img src="doc/RoundEdit_1.png" width="90%" height="90%">
<img src="doc/RoundEdit_2.png" width="90%" height="90%">
<img src="doc/RoundEdit_3.png" width="90%" height="90%">
<img src="docs/RoundEdit.jpg" width="90%" height="90%">
</div>

## 简单图形绘制界面

<div align=center>
<img src="doc/DrawScene.png" width="90%" height="90%">
<img src="docs/DrawScene.png" width="90%" height="90%">
</div>

## 电影字幕拼接界面
Expand All @@ -71,7 +69,7 @@
3. 虽然第一眼看起来模糊,但是实际生成的时候都是重新载入左侧原图剪切生成,保存后可用其他图片查看工具验证,或者按照上一点(2)查看;

<div align=center>
<img src="doc/FilmSubTiltleSplicing.png" width="90%" height="90%">
<img src="docs/FilmSubTiltleSplicing.png" width="90%" height="90%">
</div>

## GIF录制(egif和gif-h库)和截图功能
Expand All @@ -80,5 +78,5 @@
2. 截屏之后可以使用(4)绘制图形;

<div align=center>
<img src="doc/Record_Screenshot.gif" width="90%" height="90%">
<img src="docs/Record_Screenshot.gif" width="90%" height="90%">
</div>
Binary file removed doc/RoundEdit_1.png
Binary file not shown.
Binary file removed doc/RoundEdit_2.png
Binary file not shown.
Binary file removed doc/RoundEdit_3.png
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added docs/RoundEdit.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions examples/common/viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ void ImageLoadRunnable::run()
if (image.width() > WIDTH || image.height() > WIDTH) {
image = image.scaled(WIDTH, WIDTH, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
if (d_ptr->viewPtr.isNull() || !d_ptr->running.load()) {
return;
}
if (!d_ptr->viewPtr->setImage(info, image, d_ptr->taskCount)) {
if (d_ptr->viewPtr.isNull() || !d_ptr->running.load()
|| !d_ptr->viewPtr->setImage(info, image, d_ptr->taskCount)) {
return;
}
}
Expand Down
8 changes: 5 additions & 3 deletions examples/graphics/drawwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <graphics/graphicsrectitem.h>
#include <graphics/graphicsringitem.h>
#include <graphics/graphicsrotatedrectitem.h>
#include <graphics/graphicsroundedrectitem.hpp>
#include <graphics/graphicstextitem.hpp>
#include <graphics/imageview.h>
#include <utils/validator.hpp>
Expand Down Expand Up @@ -100,11 +101,12 @@ void DrawWidget::onAddShape(QListWidgetItem *item)
switch (type) {
case BasicGraphicsItem::LINE: shape = new GraphicsLineItem; break;
case BasicGraphicsItem::RECT: shape = new GraphicsRectItem; break;
case BasicGraphicsItem::ROUNDEDRECT: shape = new GraphicsRoundedRectItem; break;
case BasicGraphicsItem::ROTATEDRECT: shape = new GraphicsRotatedRectItem; break;
case BasicGraphicsItem::CIRCLE: shape = new GraphicsCircleItem; break;
case BasicGraphicsItem::POLYGON: shape = new GraphicsPolygonItem; break;
case BasicGraphicsItem::RING: shape = new GraphicsRingItem; break;
case BasicGraphicsItem::ARC: shape = new GraphicsArcItem; break;
case BasicGraphicsItem::ROTATEDRECT: shape = new GraphicsRotatedRectItem; break;
default: break;
}
if (shape) {
Expand Down Expand Up @@ -218,13 +220,13 @@ void DrawWidget::setupUI()
d_ptr->shapeWidget->addItem(item);

auto bodyLayout = new QHBoxLayout;
bodyLayout->setContentsMargins(QMargins());
bodyLayout->setContentsMargins({});
bodyLayout->setSpacing(0);
bodyLayout->addWidget(d_ptr->shapeWidget);
bodyLayout->addWidget(d_ptr->imageView);

auto layout = new QVBoxLayout(this);
layout->setContentsMargins(QMargins());
layout->setContentsMargins({});
layout->setSpacing(0);
layout->addWidget(cerateToolBar());
layout->addLayout(bodyLayout);
Expand Down
6 changes: 3 additions & 3 deletions examples/graphics/imagecaptureview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
class ImageCaptureView::ImageCaptureViewPrivate
{
public:
ImageCaptureViewPrivate(QWidget *parent)
: q_ptr(parent)
explicit ImageCaptureViewPrivate(ImageCaptureView *q)
: q_ptr(q)
, rectPtr(new Graphics::GraphicsRectItem)
{}
~ImageCaptureViewPrivate() {}

QWidget *q_ptr;
ImageCaptureView *q_ptr;
QScopedPointer<Graphics::GraphicsRectItem> rectPtr;
};

Expand Down
14 changes: 8 additions & 6 deletions examples/graphics/imageviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ using namespace Graphics;
class ImageViewer::ImageViewerPrivate
{
public:
ImageViewerPrivate(QWidget *parent)
: q_ptr(parent)
explicit ImageViewerPrivate(ImageViewer *q)
: q_ptr(q)
{
imageView = new ImageView(q_ptr);
imageViewFormat = new ImageView(q_ptr);
Expand All @@ -38,7 +38,9 @@ class ImageViewer::ImageViewerPrivate
colorBox->addItem(Conversionflags.key(i), Conversionflags.value(i));
}
}
QWidget *q_ptr;

ImageViewer *q_ptr;

ImageView *imageView;
ImageView *imageViewFormat;
QLabel *urlLabel;
Expand Down Expand Up @@ -200,7 +202,7 @@ void ImageViewer::clearThumbnail()

void ImageViewer::setupUI()
{
QSplitter *splitter = new QSplitter(Qt::Horizontal, this);
auto *splitter = new QSplitter(Qt::Horizontal, this);
splitter->addWidget(d_ptr->imageView);
splitter->addWidget(d_ptr->imageViewFormat);
splitter->addWidget(toolWidget());
Expand All @@ -209,8 +211,8 @@ void ImageViewer::setupUI()
splitter->setStretchFactor(2, 1);
splitter->setSizes({INT_MAX, INT_MAX, 1});

QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(QMargins());
auto *layout = new QVBoxLayout(this);
layout->setContentsMargins({});
layout->addWidget(splitter);
layout->addWidget(d_ptr->imageListView);

Expand Down
27 changes: 12 additions & 15 deletions examples/graphics/listiitemview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class LoadImageTask : public QRunnable
{
public:
LoadImageTask(const QString &path, ListItemView *parent)
explicit LoadImageTask(const QString &path, ListItemView *parent)
: m_imagePath(path)
, m_viewPtr(parent)
{
Expand All @@ -16,18 +16,14 @@ class LoadImageTask : public QRunnable
void run() override
{
QImage image(m_imagePath);
QSize widgetSize;
if (m_viewPtr.isNull() || image.isNull()) {
return;
} else {
widgetSize = m_viewPtr->size();
}
auto widgetSize = m_viewPtr->size();
auto imageSize = image.size();
image = image.scaled(widgetSize, Qt::KeepAspectRatio /*, Qt::SmoothTransformation*/);
if (m_viewPtr.isNull()) {
return;
}
m_viewPtr->setImage(image, imageSize);
QMetaObject::invokeMethod(
m_viewPtr.data(), [=] { m_viewPtr->setImage(image, imageSize); }, Qt::QueuedConnection);
}

private:
Expand All @@ -38,16 +34,17 @@ class LoadImageTask : public QRunnable
class ListItemView::ListItemViewPrivate
{
public:
ListItemViewPrivate(QWidget *parent)
: q_ptr(parent)
explicit ListItemViewPrivate(ListItemView *q)
: q_ptr(q)
{
upButton = new QPushButton(QObject::tr("UP", "ListItemView"), q_ptr);
upButton->setCursor(Qt::PointingHandCursor);
downButton = new QPushButton(QObject::tr("DOWN", "ListItemView"), q_ptr);
downButton->setCursor(Qt::PointingHandCursor);
}

QWidget *q_ptr;
ListItemView *q_ptr;

QString path;
QSize imageSize;

Expand Down Expand Up @@ -123,14 +120,14 @@ void ListItemView::resizeEvent(QResizeEvent *event)

void ListItemView::setupUI()
{
auto buttonLayout = new QHBoxLayout;
buttonLayout->setContentsMargins(QMargins());
auto *buttonLayout = new QHBoxLayout;
buttonLayout->setContentsMargins({});
buttonLayout->addStretch();
buttonLayout->addWidget(d_ptr->upButton);
buttonLayout->addWidget(d_ptr->downButton);

auto layout = new QVBoxLayout(this);
layout->setContentsMargins(QMargins());
auto *layout = new QVBoxLayout(this);
layout->setContentsMargins({});
layout->addLayout(buttonLayout);
layout->addStretch();
}
Expand Down
14 changes: 7 additions & 7 deletions examples/graphics/maskdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,24 @@ void MaskDialog::onSave()

auto newFlatBlueButton(const QString &text, QWidget *parent) -> QPushButton *
{
QPushButton *button = new QPushButton(text, parent);
auto *button = new QPushButton(text, parent);
return button;
}

void MaskDialog::setupUI()
{
QPushButton *button1 = newFlatBlueButton(tr("Mask"), this);
QPushButton *button2 = newFlatBlueButton(tr("Erase"), this);
QPushButton *button3 = new QPushButton(tr("Clear"), this);
auto *button1 = newFlatBlueButton(tr("Mask"), this);
auto *button2 = newFlatBlueButton(tr("Erase"), this);
auto *button3 = new QPushButton(tr("Clear"), this);
d_ptr->buttonGroup->addButton(button1, 1);
d_ptr->buttonGroup->addButton(button2, 2);
d_ptr->buttonGroup->addButton(button3, 3);
d_ptr->buttonGroup->button(1)->setChecked(true);

QPushButton *saveButton = newFlatBlueButton(tr("Save"), this);
auto *saveButton = newFlatBlueButton(tr("Save"), this);
connect(saveButton, &QPushButton::clicked, this, &MaskDialog::onSave);

QHBoxLayout *editLayout = new QHBoxLayout;
auto *editLayout = new QHBoxLayout;
editLayout->addStretch();
editLayout->addWidget(new QLabel(tr("Pen Size: "), this));
editLayout->addWidget(d_ptr->penSizeSpinBox);
Expand All @@ -195,7 +195,7 @@ void MaskDialog::setupUI()
editLayout->addWidget(saveButton);
editLayout->addStretch();

QVBoxLayout *layout = new QVBoxLayout(this);
auto *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 10);
layout->addWidget(d_ptr->imageView);
layout->addLayout(editLayout);
Expand Down
2 changes: 1 addition & 1 deletion examples/graphics/openglviewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void OpenglViewer::setupUI()
splitter->setSizes({INT_MAX, 1});

auto *layout = new QVBoxLayout(this);
layout->setContentsMargins(QMargins());
layout->setContentsMargins({});
layout->addWidget(splitter);
layout->addWidget(d_ptr->imageListView);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/graphics/recordwidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void RecordWidget::setupUI()
titleLayout->addWidget(d_ptr->closeButton);

auto layout = new QGridLayout(this);
layout->setContentsMargins(QMargins());
layout->setContentsMargins({});
layout->setSpacing(0);
layout->addWidget(d_ptr->titleWidget, 0, 0);
layout->addWidget(d_ptr->screenshotsWidget, 1, 0);
Expand Down
Loading

0 comments on commit 1686f5d

Please sign in to comment.