From ea990f089a422111b048e3ade757269213446152 Mon Sep 17 00:00:00 2001 From: xinhecuican <2686462757@qq.com> Date: Mon, 4 Dec 2023 11:03:34 +0800 Subject: [PATCH 01/11] =?UTF-8?q?grahpics=20scene=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ISSUE_TEMPLATE/bug_report.md | 31 +-- .github/ISSUE_TEMPLATE/custom.md | 10 - .github/ISSUE_TEMPLATE/feature_request.md | 12 +- Base/WindowBase.h | 8 +- GraphicsScene/Container/geolayercontainer.cpp | 113 ++++++++ GraphicsScene/Container/geolayercontainer.h | 25 ++ GraphicsScene/Container/layercontainer.cpp | 9 + GraphicsScene/Container/layercontainer.h | 26 ++ .../Container/textlayercontainer.cpp | 213 +++++++++++++++ GraphicsScene/Container/textlayercontainer.h | 30 ++ GraphicsScene/Layer/arrowlayer.cpp | 154 +++++++++++ GraphicsScene/Layer/arrowlayer.h | 49 ++++ GraphicsScene/Layer/layerbase.cpp | 44 +++ GraphicsScene/Layer/layerbase.h | 37 +++ GraphicsScene/Layer/piclayer.cpp | 64 +++++ GraphicsScene/Layer/piclayer.h | 24 ++ GraphicsScene/Layer/rectlayer.cpp | 256 ++++++++++++++++++ GraphicsScene/Layer/rectlayer.h | 61 +++++ GraphicsScene/Layer/rootlayer.cpp | 27 ++ GraphicsScene/Layer/rootlayer.h | 20 ++ GraphicsScene/Layer/textlayer.cpp | 77 ++++++ GraphicsScene/Layer/textlayer.h | 32 +++ GraphicsScene/Widgets/FontData.h | 17 ++ GraphicsScene/Widgets/PaintData.h | 33 +++ GraphicsScene/Widgets/attributetoolbar.cpp | 69 +++++ GraphicsScene/Widgets/attributetoolbar.h | 24 ++ GraphicsScene/Widgets/expandbutton.cpp | 170 ++++++++++++ GraphicsScene/Widgets/expandbutton.h | 54 ++++ GraphicsScene/Widgets/layertoolbar.cpp | 105 +++++++ GraphicsScene/Widgets/layertoolbar.h | 34 +++ GraphicsScene/Widgets/scrollitem.cpp | 59 ++++ GraphicsScene/Widgets/scrollitem.h | 21 ++ GraphicsScene/Widgets/textitem.cpp | 175 ++++++++++++ GraphicsScene/Widgets/textitem.h | 52 ++++ GraphicsScene/ilayercontrol.cpp | 30 ++ GraphicsScene/ilayercontrol.h | 32 +++ GraphicsScene/layermanager.cpp | 59 ++++ GraphicsScene/layermanager.h | 24 ++ GraphicsScene/paintarea.cpp | 167 ++++++++++++ GraphicsScene/paintarea.h | 37 +++ Helper/Serialize.h | 2 +- Helper/common.h | 4 +- Helper/debug.cpp | 23 ++ Helper/debug.h | 5 + Helper/log.cpp | 4 + Helper/math.h | 2 +- Helper/mstring.cpp | 7 +- Helper/mstring.h | 4 +- Manager/Data/UpdateData.h | 2 +- Manager/Data/uiglobalparser.cpp | 12 +- Manager/Data/uiglobalparser.h | 6 +- Manager/Data/uiparser.h | 2 +- Manager/Data/update_dialog.cpp | 4 +- Manager/Data/updatedownloader.cpp | 4 +- Manager/KeyManager.cpp | 4 +- Manager/KeyManager.h | 6 +- Manager/WindowManager.cpp | 4 +- Manager/WindowManager.h | 2 +- Manager/config.cpp | 6 +- Manager/config.h | 4 +- Manager/uimanager.cpp | 8 +- Manager/uimanager.h | 4 +- Manager/update.cpp | 6 +- Manager/update.h | 4 +- Paint/Widgets/Layers/LayerItems/picitem.cpp | 3 +- Paint/Widgets/Layers/arrowlayer.h | 2 +- Paint/Widgets/history.cpp | 4 +- Paint/Widgets/history.h | 2 +- Paint/Widgets/style_manager.cpp | 16 +- Paint/Widgets/style_manager.h | 4 +- Resource/Languages/chinese.xml | 1 + Style_widget/bubbletipswidget.cpp | 2 +- Style_widget/colorwidget.cpp | 5 +- Style_widget/colorwidget.h | 2 + Style_widget/spacer.cpp | 4 +- Style_widget/spacer.h | 2 +- Style_widget/titlebar.cpp | 2 +- Style_widget/tray.cpp | 4 +- capture.pro | 36 +++ new_capture/Widgets/attributetoolbar.h | 1 + 80 files changed, 2583 insertions(+), 120 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/custom.md create mode 100644 GraphicsScene/Container/geolayercontainer.cpp create mode 100644 GraphicsScene/Container/geolayercontainer.h create mode 100644 GraphicsScene/Container/layercontainer.cpp create mode 100644 GraphicsScene/Container/layercontainer.h create mode 100644 GraphicsScene/Container/textlayercontainer.cpp create mode 100644 GraphicsScene/Container/textlayercontainer.h create mode 100644 GraphicsScene/Layer/arrowlayer.cpp create mode 100644 GraphicsScene/Layer/arrowlayer.h create mode 100644 GraphicsScene/Layer/layerbase.cpp create mode 100644 GraphicsScene/Layer/layerbase.h create mode 100644 GraphicsScene/Layer/piclayer.cpp create mode 100644 GraphicsScene/Layer/piclayer.h create mode 100644 GraphicsScene/Layer/rectlayer.cpp create mode 100644 GraphicsScene/Layer/rectlayer.h create mode 100644 GraphicsScene/Layer/rootlayer.cpp create mode 100644 GraphicsScene/Layer/rootlayer.h create mode 100644 GraphicsScene/Layer/textlayer.cpp create mode 100644 GraphicsScene/Layer/textlayer.h create mode 100644 GraphicsScene/Widgets/FontData.h create mode 100644 GraphicsScene/Widgets/PaintData.h create mode 100644 GraphicsScene/Widgets/attributetoolbar.cpp create mode 100644 GraphicsScene/Widgets/attributetoolbar.h create mode 100644 GraphicsScene/Widgets/expandbutton.cpp create mode 100644 GraphicsScene/Widgets/expandbutton.h create mode 100644 GraphicsScene/Widgets/layertoolbar.cpp create mode 100644 GraphicsScene/Widgets/layertoolbar.h create mode 100644 GraphicsScene/Widgets/scrollitem.cpp create mode 100644 GraphicsScene/Widgets/scrollitem.h create mode 100644 GraphicsScene/Widgets/textitem.cpp create mode 100644 GraphicsScene/Widgets/textitem.h create mode 100644 GraphicsScene/ilayercontrol.cpp create mode 100644 GraphicsScene/ilayercontrol.h create mode 100644 GraphicsScene/layermanager.cpp create mode 100644 GraphicsScene/layermanager.h create mode 100644 GraphicsScene/paintarea.cpp create mode 100644 GraphicsScene/paintarea.h diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index dd84ea7..033221b 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -7,32 +7,11 @@ assignees: '' --- -**Describe the bug** -A clear and concise description of what the bug is. +**版本** -**To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error +- 操作系统版本: +- 程序版本: -**Expected behavior** -A clear and concise description of what you expected to happen. +**问题** -**Screenshots** -If applicable, add screenshots to help explain your problem. - -**Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] - -**Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] - -**Additional context** -Add any other context about the problem here. +简要描述你的操作过程,最好可以提供日志文件。日志文件在Data/Temp/log.txt \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md deleted file mode 100644 index 48d5f81..0000000 --- a/.github/ISSUE_TEMPLATE/custom.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -name: Custom issue template -about: Describe this issue template's purpose here. -title: '' -labels: '' -assignees: '' - ---- - - diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index bbcbbe7..94d49ee 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -7,14 +7,10 @@ assignees: '' --- -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] +**描述你想增加或实现的功能** -**Describe the solution you'd like** -A clear and concise description of what you want to happen. +... -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. +**描述目前可能的思路** -**Additional context** -Add any other context or screenshots about the feature request here. +... diff --git a/Base/WindowBase.h b/Base/WindowBase.h index d5590a1..13642d4 100644 --- a/Base/WindowBase.h +++ b/Base/WindowBase.h @@ -2,10 +2,10 @@ #define WINDOW_BASE_H #include #include -#include "Helper/Reflect.h" -#include "Helper/mstring.h" -#include "Manager/uimanager.h" -#include "Manager/KeyManager.h" +#include "../Helper/Reflect.h" +#include "../Helper/mstring.h" +#include "../Manager/uimanager.h" +#include "../Manager/KeyManager.h" class WindowBase : public QMainWindow { public: diff --git a/GraphicsScene/Container/geolayercontainer.cpp b/GraphicsScene/Container/geolayercontainer.cpp new file mode 100644 index 0000000..4b2a60e --- /dev/null +++ b/GraphicsScene/Container/geolayercontainer.cpp @@ -0,0 +1,113 @@ +#include "geolayercontainer.h" +#include +#include "../../Helper/imagehelper.h" +#include "../../Style_widget/colorwidget.h" +#include +#include "../../Manager/uimanager.h" +#include "../../Helper/math.h" +#include "../Layer/rectlayer.h" +#include "../Layer/arrowlayer.h" +#include "../paintarea.h" +#include + +GeoLayerContainer::GeoLayerContainer(PaintArea* area) : + LayerContainer(area), + geoType(RECT), + rectId(0), + arrowId(0) +{ + rectPaintData = UIManager::instance()->getRectData(); + arrowPaintData = UIManager::instance()->getArrowData(); +} + +QWidget* GeoLayerContainer::onValid(QWidget* widgetParent){ + if(widget == NULL){ + widget = new QWidget(widgetParent); + QHBoxLayout* layout = new QHBoxLayout(); + QButtonGroup* shapeGroup = new QButtonGroup(widgetParent); + shapeGroup->setExclusive(true); + connect(shapeGroup, static_cast(&QButtonGroup::buttonClicked), + this, [=](int id) { + switch(id) { + case 0: geoType = RECT; break; + case 1: geoType = ARROW; break; + default: + geoType = id; + qWarning() << "未知形状"; + break; + } + }); + QToolButton* rectButton = new QToolButton(widgetParent); + rectButton->setObjectName("rectButton"); + rectButton->setToolTip("矩形"); + rectButton->setIcon(ImageHelper::getIcon("rect")); + rectButton->setCheckable(true); + rectButton->setChecked(true); + shapeGroup->addButton(rectButton, 0); + QToolButton* arrowButton = new QToolButton(widgetParent); + arrowButton->setObjectName("arrowButton"); + arrowButton->setIcon(ImageHelper::getIcon("paint_arrow")); + arrowButton->setToolTip("{D7HSBXWTLj}箭头"); + arrowButton->setCheckable(true); + shapeGroup->addButton(arrowButton, 1); + ColorWidget* colorWidget = new ColorWidget(widgetParent); + connect(colorWidget, &ColorWidget::colorChange, this, [=](const QColor& color){ + switch(geoType){ + case RECT: rectPaintData.color = color; break; + case ARROW: arrowPaintData.color = color; break; + } + }); + QSpinBox* widthButton = new QSpinBox(widgetParent); + widthButton->setRange(1, 50); + widthButton->setValue(3); + widthButton->setAccelerated(true); + widthButton->setWrapping(true); + widthButton->setKeyboardTracking(true); + connect(widthButton, static_cast(&QSpinBox::valueChanged), this, [=](int value) { + switch(geoType){ + case RECT: rectPaintData.width = value; break; + case ARROW: arrowPaintData.width = value; break; + } + }); + + layout->addWidget(rectButton); + layout->addWidget(arrowButton); + layout->addWidget(colorWidget); + layout->addWidget(widthButton); + widget->setLayout(layout); + } + return widget; +} + +void GeoLayerContainer::layerMousePressEvent(QGraphicsSceneMouseEvent *event){ + beginPoint = event->scenePos(); +} + +void GeoLayerContainer::layerMouseMoveEvent(QGraphicsSceneMouseEvent *event){ + +} + +void GeoLayerContainer::layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event){ + QPointF endPoint = event->scenePos(); + switch (geoType) { + case RECT: { + QRectF rect = Math::buildRect(beginPoint, endPoint); + if(rect.height() < 10 || rect.width() < 10) return; + RectLayer* layer = new RectLayer(rect, "rect" + QString::number(rectId), area, NULL); + rectId++; + layer->setEnable(true); + layer->setEnableScroll(true); + area->addLayer(layer); + break; + } + case ARROW: { + QLineF line(beginPoint, endPoint); + if(line.length() < 10) return; + ArrowLayer* layer = new ArrowLayer(beginPoint, endPoint, "arrow" + QString::number(arrowId), area, NULL); + arrowId++; + layer->setEnable(true); + area->addLayer(layer); + break; + } + } +} diff --git a/GraphicsScene/Container/geolayercontainer.h b/GraphicsScene/Container/geolayercontainer.h new file mode 100644 index 0000000..9084c56 --- /dev/null +++ b/GraphicsScene/Container/geolayercontainer.h @@ -0,0 +1,25 @@ +#ifndef GEOLAYERCONTAINER_H +#define GEOLAYERCONTAINER_H +#include "layercontainer.h" +#include "../Widgets/PaintData.h" + +class GeoLayerContainer : public LayerContainer +{ +public: + const static int RECT = 0; + const static int ARROW = 1; + GeoLayerContainer(PaintArea* area); + QWidget* onValid(QWidget* widgetParent) override; + void layerMouseMoveEvent(QGraphicsSceneMouseEvent *event) override; + void layerMousePressEvent(QGraphicsSceneMouseEvent* event) override; + void layerMouseReleaseEvent(QGraphicsSceneMouseEvent* event) override; +private: + QPointF beginPoint; + int geoType; + PaintData rectPaintData; + PaintData arrowPaintData; + int rectId; + int arrowId; +}; + +#endif // GEOLAYERCONTAINER_H diff --git a/GraphicsScene/Container/layercontainer.cpp b/GraphicsScene/Container/layercontainer.cpp new file mode 100644 index 0000000..fbce170 --- /dev/null +++ b/GraphicsScene/Container/layercontainer.cpp @@ -0,0 +1,9 @@ +#include "layercontainer.h" +#include "../paintarea.h" + +LayerContainer::LayerContainer(PaintArea* area): + QObject(area), + area(area), + widget(NULL){ + +} diff --git a/GraphicsScene/Container/layercontainer.h b/GraphicsScene/Container/layercontainer.h new file mode 100644 index 0000000..82329d4 --- /dev/null +++ b/GraphicsScene/Container/layercontainer.h @@ -0,0 +1,26 @@ +#ifndef LAYERCONTAINER_H +#define LAYERCONTAINER_H +#include +#include +#include +#include +#include "../ilayercontrol.h" + +class PaintArea; + +class LayerContainer : public QObject +{ +public: + LayerContainer(PaintArea* area); + virtual ~LayerContainer(){ + } + virtual void layerMouseMoveEvent(QGraphicsSceneMouseEvent *event) {} + virtual void layerMousePressEvent(QGraphicsSceneMouseEvent* event) {} + virtual void layerMouseReleaseEvent(QGraphicsSceneMouseEvent* event) {} + virtual QWidget* onValid(QWidget* widgetParent)=0; +protected: + PaintArea* area; + QWidget* widget; +}; + +#endif // LAYERCONTAINER_H diff --git a/GraphicsScene/Container/textlayercontainer.cpp b/GraphicsScene/Container/textlayercontainer.cpp new file mode 100644 index 0000000..d4d1113 --- /dev/null +++ b/GraphicsScene/Container/textlayercontainer.cpp @@ -0,0 +1,213 @@ +#include "textlayercontainer.h" +#include "../Layer/textlayer.h" +#include "../paintarea.h" +#include "../../Manager/uimanager.h" +#include +#include "../../Helper/imagehelper.h" +#include "../../Helper/mstring.h" + +TextLayerContainer::TextLayerContainer(PaintArea* area) : + LayerContainer(area), + textId(0), + data(UIManager::instance()->getFontData()) +{ +} + +void TextLayerContainer::layerMousePressEvent(QGraphicsSceneMouseEvent *event){ + TextLayer* textLayer = new TextLayer(event->scenePos(), "text" + QString::number(textId), area, NULL); + textId++; + textLayer->setEnable(true); + connect(textLayer, &TextLayer::formatChange, this, [=](const QFont& font, const QBrush& brush){ + int r = 0, g = 0, b = 0; + brush.color().getRgb(&r,&g,&b); + colorSelectButton->setStyleSheet(QString("background-color: rgb(%1,%2,%3)").arg(r).arg(g).arg(b)); + + fontBox->setCurrentText(font.family()); + widthBox->setCurrentText(QString::number(font.pointSize())); + boldButton->setChecked(font.bold()); + italicButton->setChecked(font.italic()); + underlineButton->setChecked(font.underline()); + data.font = font; + data.color = brush.color(); + }); + area->addLayer(textLayer); +} + +QWidget* TextLayerContainer::onValid(QWidget *widgetParent){ + if(widget == NULL){ + widget = new QWidget(widgetParent); + QHBoxLayout* layout = new QHBoxLayout(); + + QToolButton* brushButton = new QToolButton(widgetParent); + brushButton->setIcon(ImageHelper::getIcon("brush")); + brushButton->setToolTip(MString::search("{hULcO1ELot}格式刷")); + connect(brushButton, &QToolButton::clicked, this, [=](){ + LayerBase* focusLayer = area->getFocusLayer(); + if(focusLayer!= NULL && focusLayer->getName().startsWith("text")){ + focusLayer->setParameter("brush", 1); + } + }); + + colorSelectButton = new QToolButton(widgetParent); + int r = 0, g = 0, b = 0; + data.color.getRgb(&r,&g,&b); + colorSelectButton->setStyleSheet(QString("background-color: rgb(%1,%2,%3)").arg(r).arg(g).arg(b)); + connect(colorSelectButton, &QToolButton::clicked, this, [=](){ + QColorDialog dialog; + QColor color = dialog.getColor(color, widgetParent, MString::search("{6Of41PN3eL}选择字体颜色"), + QColorDialog::ShowAlphaChannel); + int r = 0, g = 0, b = 0; + color.getRgb(&r,&g,&b); + data.color.setRgb(r, g, b); + colorSelectButton->setStyleSheet(QString("background-color: rgb(%1,%2,%3)").arg(r).arg(g).arg(b)); + LayerBase* focusLayer = area->getFocusLayer(); + if(focusLayer!= NULL && focusLayer->getName().startsWith("text")){ + focusLayer->setParameter("color", data.color); + } + }); + + fontBox = new QComboBox(widgetParent); + QStandardItemModel *model=new QStandardItemModel(this); //源数据 + QList row; + QStandardItem *blankitem=new QStandardItem(""); + model->appendRow(blankitem); //增加一行空白 + QList list = get_font_text(); + foreach (QString name, list) { + if(!name.isEmpty()) { + row.clear(); + QStandardItem *item=new QStandardItem(name); + model->appendRow(item); //添加一行,2列数据 + } + } + fontBox->setModel(model); //QComboBox设置数据源 + fontBox->setEditable(true); + QCompleter *completer=new QCompleter(fontBox); + completer->setCaseSensitivity(Qt::CaseInsensitive); + completer->setModel(model); + completer->setCompletionColumn(fontBox->modelColumn()); + completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion); + completer->setMaxVisibleItems(10); //下拉最大高度 + fontBox->setCompleter(completer); //设置自动补全 + // m_ComboBox->setStyleSheet("QComboBox{combobox-popup: 0;}"); //linux系统上,防止下拉框过长,消耗时间较多 + fontBox->setMaxVisibleItems(10); //下拉最大高度 + fontBox->setCurrentText("宋体"); + connect(fontBox, static_cast(&QComboBox::currentIndexChanged) + , this, [=](const QString& text) { + data.font.setFamily(text); + fontBox->clearFocus(); + LayerBase* focusLayer = area->getFocusLayer(); + if(focusLayer!= NULL && focusLayer->getName().startsWith("text")){ + focusLayer->setParameter("font", data.font); + } + }); + + widthBox = new QComboBox(widgetParent); + QList width_text = {"4", "8", "15", "20", "22", "26", "30", "40", "50"}; + widthBox->addItems(width_text); + widthBox->setEditable(true); + widthBox->setCurrentText(QString::number(data.font.pointSize())); + connect(widthBox, static_cast(&QComboBox::currentIndexChanged) + , this, [=](const QString& text) { + bool success = false; + int num = text.toInt(&success); + if(success && num > 0) { + widthBox->clearFocus(); + data.font.setPointSize(num); + LayerBase* focusLayer = area->getFocusLayer(); + if(focusLayer!= NULL && focusLayer->getName().startsWith("text")){ + focusLayer->setParameter("font", data.font); + } + } + }); + boldButton = new QToolButton(widgetParent); + boldButton->setIcon(ImageHelper::getIcon("bold", 48, 48)); + boldButton->setCheckable(true); + connect(boldButton, &QToolButton::clicked, this, [=]() { + if(data.font.bold()) { + data.font.setBold(false); + boldButton->setChecked(false); + } else { + data.font.setBold(true); + boldButton->setChecked(true); + } + LayerBase* focusLayer = area->getFocusLayer(); + if(focusLayer!= NULL && focusLayer->getName().startsWith("text")){ + focusLayer->setParameter("font", data.font); + } + }); + italicButton = new QToolButton(widgetParent); + italicButton->setIcon(ImageHelper::getIcon("italic", 48, 48)); + italicButton->setCheckable(true); + connect(italicButton, &QToolButton::clicked, this, [=]() { + if(data.font.italic()) { + data.font.setItalic(false); + italicButton->setChecked(false); + } else { + data.font.setItalic(true); + italicButton->setChecked(true); + } + LayerBase* focusLayer = area->getFocusLayer(); + if(focusLayer!= NULL && focusLayer->getName().startsWith("text")){ + focusLayer->setParameter("font", data.font); + } + }); + underlineButton = new QToolButton(widgetParent); + underlineButton->setIcon(ImageHelper::getIcon("underline", 48, 48)); + underlineButton->setCheckable(true); + connect(underlineButton, &QToolButton::clicked, this, [=]() { + if(data.font.underline()) { + data.font.setUnderline(false); + underlineButton->setChecked(false); + } else { + data.font.setUnderline(true); + underlineButton->setChecked(true); + } + LayerBase* focusLayer = area->getFocusLayer(); + if(focusLayer!= NULL && focusLayer->getName().startsWith("text")){ + focusLayer->setParameter("font", data.font); + } + }); + colorSelectButton->setFixedSize(fontBox->height(), fontBox->height()); + boldButton->setFixedSize(fontBox->height(), fontBox->height()); + italicButton->setFixedSize(fontBox->height(), fontBox->height()); + underlineButton->setFixedSize(fontBox->height(), fontBox->height()); + + layout->addWidget(brushButton); + layout->addWidget(colorSelectButton); + layout->addWidget(fontBox); + layout->addWidget(widthBox); + layout->addWidget(boldButton); + layout->addWidget(italicButton); + layout->addWidget(underlineButton); + widget->setLayout(layout); + } + return widget; +} + +QList TextLayerContainer::get_font_text() { + QList font_text = QList({"Agency FB", "Algerian", "Arial", "Arial Black", "Arial Narrow", + "Bauhaus 93", "Bell MT", + "Bodoni MT", "Bodoni MT Black", "Bodoni MT Condensed", "Book Antiqua", "Broadway", + "Calibri", "Calibri Light", "Californian FB", "Calisto MT", + "Candara", "Candara Light", "Castellar", "Centaur", "Century", "Century Gothic", + "Chiller", "Colonna MT", "Comic Sans MS", "Consolas", "Constantia", "Cooper Black", + "Corbel", "Corbel Light", "Courier", "Courier New", "Curlz MT", + "Dubai", "Dubai Light", "Dubai Medium", "Ebrima", "Elephant", "Engravers MT", + "Ink Free", + "Microsoft Himalaya", "Microsoft JhengHei", + "Microsoft New Tai Lue", "Microsoft PhagsPa", "Microsoft Sans Serif", + "Microsoft Tai Le", "Microsoft YaHei UI", "MingLiU-ExtB", + "Mistral", "Modern", "Modern No. 20", "Mongolian Baiti", "Monotype Corsiva", + "MS Gothic", "MS Outlook", "MS PGothic", + "MS Sans Serif", "MS Serif", "MS UI Gothic", "MT Extra", "MV Boli", "Myanmar Text", "Niagara Engraved", + "Niagara Solid", "Nirmala UI", "Nirmala UI Semilight", "NumberOnly", + "Onyx", "Open Sans", "Papyrus", "Parchment", + "Perpetua", + "Ravie", "Rockwell", + "Small Fonts", "Snap ITC", "Stencil", "Sylfaen", "Symbol", "System", + "Tahoma", "Terminal", "Times New Roman", "Verdana", + "仿宋", "华文中宋", "华文仿宋", "华文宋体", "华文彩云", "华文新魏", "华文楷体", + "华文琥珀", "华文细黑", "华文行楷", "华文隶书", "宋体", "幼圆", "微软雅黑", "微软雅黑 Light", "思源黑体", + "新宋体", "方正姚体", "方正粗黑宋简体", "方正舒体", "楷体", "等线", "等线 Light", "隶书", "黑体"}); + return font_text; +} diff --git a/GraphicsScene/Container/textlayercontainer.h b/GraphicsScene/Container/textlayercontainer.h new file mode 100644 index 0000000..4bcdffb --- /dev/null +++ b/GraphicsScene/Container/textlayercontainer.h @@ -0,0 +1,30 @@ +#ifndef TEXTLAYERCONTAINER_H +#define TEXTLAYERCONTAINER_H +#include "layercontainer.h" +#include "../Widgets/FontData.h" +#include +#include +#include +#include + + +class TextLayerContainer : public LayerContainer +{ +public: + TextLayerContainer(PaintArea* area); + void layerMousePressEvent(QGraphicsSceneMouseEvent *event) override; + QWidget * onValid(QWidget *widgetParent) override; + +private: + QList get_font_text(); + int textId; + FontData data; + QToolButton* colorSelectButton; + QComboBox* fontBox; + QComboBox* widthBox; + QToolButton* boldButton; + QToolButton* italicButton; + QToolButton* underlineButton; +}; + +#endif // TEXTLAYERCONTAINER_H diff --git a/GraphicsScene/Layer/arrowlayer.cpp b/GraphicsScene/Layer/arrowlayer.cpp new file mode 100644 index 0000000..d1038b6 --- /dev/null +++ b/GraphicsScene/Layer/arrowlayer.cpp @@ -0,0 +1,154 @@ +#include "arrowlayer.h" +#include "../../Manager/uimanager.h" + +ArrowLayer::ArrowLayer(const QPointF& beginPt, const QPointF& endPt, const QString& name, ILayerControl* manager, QGraphicsItem* parent) : + LayerBase(name, manager, parent){ + setLine(beginPt, endPt); + beginButton = new ExpandButton(ExpandButton::W, beginPt, this); + endButton = new ExpandButton(ExpandButton::E, endPt, this); + connect(beginButton, static_cast(&ExpandButton::posChange), this, &ArrowLayer::posChangeFunc); + connect(endButton, static_cast(&ExpandButton::posChange), this, &ArrowLayer::posChangeFunc); + setAcceptHoverEvents(true); + data = UIManager::instance()->getArrowData(); +} + +void ArrowLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + painter->setRenderHint(QPainter::Antialiasing, true); //设置反走样,防锯齿 + QPen pen(data.color, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + QBrush brush(data.color, Qt::SolidPattern); + painter->setPen(pen); + painter->setBrush(brush); + QLineF line(beginPt, endPt); + painter->drawLine(line); + painter->drawPolygon(arrow_points, 3); +} + +QRectF ArrowLayer::boundingRect() const { + QRectF ans(beginPt, endPt); + ans.setTopLeft(ans.topLeft() - QPointF(3, 3)); + ans.setBottomRight(ans.bottomRight() + QPointF(3, 3)); + return ans; +} + +QPainterPath ArrowLayer::shape() const { + QLineF line(beginPt, endPt); + line = line.unitVector(); + QLineF vertical_line = line; + vertical_line.setAngle(line.angle() + 90); + qreal half_width = ExtRefArrowLenght * sin(ExtRefArrowDegrees) + 5; + QPainterPath path; + QLineF new_line = vertical_line; + new_line.setLength(half_width); + path.moveTo(new_line.p2()); + QPointF delta = new_line.p2() - new_line.p1(); + path.lineTo(endPt + delta); + path.lineTo(endPt - delta); + path.lineTo(beginPt - delta); + for(QGraphicsItem* item : childItems()) { + path.addPath(item->shape()); + } + path = path.simplified(); + return path; +} + + +void ArrowLayer::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { + outCursor = cursor(); + if(enable) { + setCursor(Qt::SizeAllCursor); + showButtons(); + } + QGraphicsObject::hoverEnterEvent(event); +} + +void ArrowLayer::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { + setCursor(outCursor); + hideButtons(); + QGraphicsItem::hoverLeaveEvent(event); +} + +void ArrowLayer::mousePressEvent(QGraphicsSceneMouseEvent *event) { + point = event->scenePos(); + manager->requestFocus(this); +} + +void ArrowLayer::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { + if(enable) { + QPointF delta_point = event->scenePos() - point; + point = event->scenePos(); + moveBy(delta_point.x(), delta_point.y()); + } +} + +void ArrowLayer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { + if(enable) { + QPointF delta_point = event->scenePos() - point; + point = event->scenePos(); + moveBy(delta_point.x(), delta_point.y()); + } +} + +void ArrowLayer::setLine(const QPointF& beginPt, const QPointF& endPt) { + this->beginPt = beginPt; + this->endPt = endPt; + createArrow(); +} + + +void ArrowLayer::createArrow() { + //箭头直线与水平方向的夹角再加pi + float angle = atan2(endPt.y()-beginPt.y(), endPt.x()-beginPt.x()) + 3.1415926; + //这两个值需要根据实际场景的坐标大小进行调整, + + + arrow_points[0] = endPt; + //求得箭头点1坐标 + arrow_points[1].setX(endPt.x() + ExtRefArrowLenght * cos(angle - ExtRefArrowDegrees)); + arrow_points[1].setY(endPt.y() + ExtRefArrowLenght * sin(angle - ExtRefArrowDegrees)); + //求得箭头点2坐标 + arrow_points[2].setX(endPt.x() + ExtRefArrowLenght * cos(angle + ExtRefArrowDegrees)); + arrow_points[2].setY(endPt.y() + ExtRefArrowLenght * sin(angle + ExtRefArrowDegrees)); +} + +void ArrowLayer::posChangeFunc(ExpandButton::ButtonDirection dir, qreal x, qreal y) { + if(dir == ExpandButton::W) { + beginPt = beginPt + QPointF(x, y); + createArrow(); + } else { + endPt = endPt + QPointF(x, y); + createArrow(); + } + QRectF rect = boundingRect(); + rect.setTopLeft(rect.topLeft()-QPointF(5, 5)); + rect.setBottomRight(rect.bottomRight()+QPointF(5, 5)); + update(rect); +} + +void ArrowLayer::showButtons() { + beginButton->show(); + endButton->show(); +} + +void ArrowLayer::hideButtons() { + if(manager->hasFocus(this)) { + return; + } + beginButton->hide(); + endButton->hide(); +} + +void ArrowLayer::getFocus(){ + showButtons(); +} + +void ArrowLayer::loseFocus(){ + hideButtons(); +} + +void ArrowLayer::setParameter(const QString &name, const QVariant &var){ + +} + +void ArrowLayer::reset(){ + manager->removeThis(this); +} diff --git a/GraphicsScene/Layer/arrowlayer.h b/GraphicsScene/Layer/arrowlayer.h new file mode 100644 index 0000000..3eda753 --- /dev/null +++ b/GraphicsScene/Layer/arrowlayer.h @@ -0,0 +1,49 @@ +#ifndef ARROWLAYER_H +#define ARROWLAYER_H +#include "layerbase.h" +#include "../Widgets/expandbutton.h" +#include + +class ArrowLayer : public LayerBase +{ +public: + ArrowLayer(const QPointF& beginPt, + const QPointF& endPt, + const QString& name, + ILayerControl* manager, + QGraphicsItem* parent=nullptr); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; + QRectF boundingRect()const override; + QPainterPath shape()const override; + void setParameter(const QString &name, const QVariant &var) override; + void reset() override; + void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; + void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; + void mousePressEvent(QGraphicsSceneMouseEvent *event) override; + void setLine(const QPointF& beginPt, const QPointF& endPt); + void getFocus() override; + void loseFocus() override; + +private slots: + void posChangeFunc(ExpandButton::ButtonDirection dir, qreal x, qreal y); +private: + void createArrow(); + void showButtons(); + void hideButtons(); + +private: + QPointF arrow_points[3]; + QPointF beginPt; + QPointF endPt; + QPointF point; + ExpandButton* beginButton; + ExpandButton* endButton; + QCursor outCursor; + PaintData data; + const float ExtRefArrowLenght = 10;//箭头末端大小的长度, + const float ExtRefArrowDegrees = M_PI / 6;//箭头末端顶角的一半 +}; + +#endif // ARROWLAYER_H diff --git a/GraphicsScene/Layer/layerbase.cpp b/GraphicsScene/Layer/layerbase.cpp new file mode 100644 index 0000000..d04ef08 --- /dev/null +++ b/GraphicsScene/Layer/layerbase.cpp @@ -0,0 +1,44 @@ +#include "layerbase.h" + +LayerBase::LayerBase(const QString& name, ILayerControl* manager, QGraphicsItem* parent) : + QGraphicsObject(parent), + name(name), + manager(manager), + erase(false), + enable(false), + isSaving(false) +{ + +} + +bool LayerBase::isEnable(){ + return enable; +} + +bool LayerBase::isErase(){ + return erase; +} + +void LayerBase::prepareSave(){ + isSaving = true; +} + +void LayerBase::endSave(){ + isSaving = false; +} + +QString LayerBase::getName() const{ + return name; +} + +void LayerBase::setErase(bool enable){ + erase = enable; +} + +void LayerBase::setEnable(bool enable){ + this->enable = enable; +} + +int LayerBase::getZValue() const { + return 0; +} diff --git a/GraphicsScene/Layer/layerbase.h b/GraphicsScene/Layer/layerbase.h new file mode 100644 index 0000000..33d5c0d --- /dev/null +++ b/GraphicsScene/Layer/layerbase.h @@ -0,0 +1,37 @@ +#ifndef LAYERBASE_H +#define LAYERBASE_H +#include +#include "../ilayercontrol.h" +#include +#include + +class LayerBase : public QGraphicsObject +{ + Q_OBJECT +public: + explicit LayerBase(const QString& name, ILayerControl* manager, QGraphicsItem* parent=nullptr); + virtual ~LayerBase(){} + bool isEnable(); + bool isErase(); + QString getName()const; + virtual const QString getHelp(){return "";}; + virtual void setErase(bool enable); + virtual void setEnable(bool enable); + virtual void setParameter(const QString& name, const QVariant& var){}; + virtual void prepareSave(); + virtual void endSave(); + virtual void reset()=0; + virtual int getZValue() const; + virtual void getFocus(){} + virtual void loseFocus(){} + virtual void onImageSet(){} + +protected: + QString name; + ILayerControl* manager; + bool erase; + bool enable; + bool isSaving; +}; + +#endif // LAYERBASE_H diff --git a/GraphicsScene/Layer/piclayer.cpp b/GraphicsScene/Layer/piclayer.cpp new file mode 100644 index 0000000..25cbaf3 --- /dev/null +++ b/GraphicsScene/Layer/piclayer.cpp @@ -0,0 +1,64 @@ +#include "piclayer.h" +#include + +PicLayer::PicLayer(const QString& name, ILayerControl* manager, bool enableBound, QGraphicsItem* parent) : + LayerBase(name, manager, parent), + enableBound(enableBound) +{ + if(enableBound){ + rectLayer = new RectLayer(boundingRect(), "", manager, this); + rectLayer->setBoundEffect(); + connect(rectLayer, &RectLayer::sizeChange, this, [=]() { + prepareGeometryChange(); + mask = rectLayer->boundingRect(); + this->update(); + }); + } + setAcceptHoverEvents(true); +} + +void PicLayer::setParameter(const QString &name, const QVariant &var){ + +} + +QRectF PicLayer::boundingRect() const{ + if(!manager->isImageValid()) return QRectF(); + return mask; +} + +QPainterPath PicLayer::shape() const{ + QPainterPath path; + path.addRect(mask); + return path; +} + +void PicLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ + if(manager->isImageValid()){ + painter->drawImage(mask.topLeft(), manager->getImage(), mask); + } +} + +void PicLayer::onImageSet(){ + prepareGeometryChange(); + mask = QRectF(QPointF(0, 0), manager->getImage().size()); + if(enableBound){ + rectLayer->setBounding(mask); + rectLayer->setLimit(mask); + } +} + +void PicLayer::prepareSave(){ + if(enableBound){ + rectLayer->hide(); + } +} + +void PicLayer::endSave(){ + if(enableBound){ + rectLayer->show(); + } +} + +void PicLayer::reset(){ + mask = QRectF(); +} diff --git a/GraphicsScene/Layer/piclayer.h b/GraphicsScene/Layer/piclayer.h new file mode 100644 index 0000000..53fde0b --- /dev/null +++ b/GraphicsScene/Layer/piclayer.h @@ -0,0 +1,24 @@ +#ifndef PICLAYER_H +#define PICLAYER_H +#include "layerbase.h" +#include "rectlayer.h" + +class PicLayer : public LayerBase +{ +public: + PicLayer(const QString& name, ILayerControl* manager, bool enableBound=true, QGraphicsItem* parent=nullptr); + void setParameter(const QString &name, const QVariant &var) override; + void prepareSave() override; + void endSave() override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr)override; + QRectF boundingRect() const override; + QPainterPath shape() const override; + void onImageSet() override; + void reset() override; +private: + bool enableBound; + RectLayer* rectLayer; + QRectF mask; +}; + +#endif // PICLAYER_H diff --git a/GraphicsScene/Layer/rectlayer.cpp b/GraphicsScene/Layer/rectlayer.cpp new file mode 100644 index 0000000..cc29e6a --- /dev/null +++ b/GraphicsScene/Layer/rectlayer.cpp @@ -0,0 +1,256 @@ +#include "rectlayer.h" +#include + +RectLayer::RectLayer( + const QRectF& rect, + const QString& name, + ILayerControl* manager, + QGraphicsItem* parent, + bool enableResize) : + LayerBase(name, manager, parent), + scrollItem(NULL), + enableScroll(false), + buttonFocus(false) +{ + this->enableResize = enableResize; + paintData.color = QColor(161, 47, 47); + paintData.width = 3; + paintData.joinStyle = Qt::RoundJoin; + setAcceptHoverEvents(true); + prepareGeometryChange(); + setPos(rect.topLeft()); + this->rect = QRectF(QPointF(0, 0), QSize(rect.width(), rect.height())); + setBounding(this->rect); +} + +void RectLayer::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { + if(!enable) return; + if(enableResize) { + outCursor = cursor(); + setCursor(Qt::SizeAllCursor); + showButtons(); + } +} + +void RectLayer::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { + if(!enable) return; + setCursor(outCursor); + hideButtons(); +} + +void RectLayer::mousePressEvent(QGraphicsSceneMouseEvent *event) { + beginPoint = event->scenePos(); + if(manager != NULL) manager->requestFocus(this); +} + +void RectLayer::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { + if(enable) { + QPointF delta = event->scenePos() - beginPoint; + beginPoint = event->scenePos(); + moveBy(delta.x(), delta.y()); + emit move(delta.x(), delta.y()); + } +} + +void RectLayer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { + if(enable) { + QPointF delta = event->scenePos() - beginPoint; + moveBy(delta.x(), delta.y()); + emit move(delta.x(), delta.y()); + } +} + +void RectLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + painter->setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing, true); + paintStyle(painter); + painter->drawRect(this->boundingRect()); +} + +void RectLayer::setEnableResize(bool enable){ + enableResize = enable; + if(enableResize && buttons.size() == 0){ + initButtons(); + } +} + +void RectLayer::setBounding(const QRectF& rect) { + this->rect = rect; + if(buttons.size() == 0 && enableResize) { + initButtons(); + } else { + for(int i=0; isetPos(x, y); + } + } + hideButtons(); +} + +void RectLayer::posChangeFunc(ExpandButton::ButtonDirection dir, qreal x, qreal y) { + QRectF before_rect = rect; + qreal width = buttons[ExpandButton::NW]->boundingRect().width(); + before_rect.setTopLeft(before_rect.topLeft() - QPointF(width, width)); + before_rect.setBottomRight(before_rect.bottomRight() + QPointF(width, width)); + QPointF point(x, y); + prepareGeometryChange(); + switch (dir) { + case ExpandButton::NW: + rect.setTopLeft(rect.topLeft() + point); + buttons[ExpandButton::NE]->moveBy(0, y); + buttons[ExpandButton::SW]->moveBy(x, 0); + break; + case ExpandButton::NE: + rect.setTopRight(rect.topRight() + point); + buttons[ExpandButton::NW]->moveBy(0, y); + buttons[ExpandButton::SE]->moveBy(x, 0); + break; + case ExpandButton::SW: + rect.setBottomLeft(rect.bottomLeft() + point); + buttons[ExpandButton::SE]->moveBy(0, y); + buttons[ExpandButton::NW]->moveBy(x, 0); + break; + case ExpandButton::SE: + rect.setBottomRight(rect.bottomRight() + point); + buttons[ExpandButton::SW]->moveBy(0, y); + buttons[ExpandButton::NE]->moveBy(x, 0); + break; + default: + qWarning() << "no implement this direction"; + break; + } + if(scrollItem != NULL) + scrollItem->setPos(rect.left()+rect.width()/2, rect.top()-scrollItem->boundingRect().height()); + update(before_rect); +} + +void RectLayer::posToFunc(ExpandButton::ButtonDirection dir, qreal x, qreal y) { + emit sizeChange(); +} + +void RectLayer::showButtons() { + if (enableResize) { + for(ExpandButton* button: buttons) { + button->show(); + } + } + if (enableScroll) { + scrollItem->show(); + } +} + +void RectLayer::hideButtons() { + if (buttonFocus || (manager!= NULL && manager->hasFocus(this))) return; + for (ExpandButton* button: buttons) { + button->hide(); + } + if(scrollItem != NULL) scrollItem->hide(); +} + +void RectLayer::setEnableScroll(bool enable){ + enableScroll = enable; + if(enableScroll){ + scrollItem = new ScrollItem(this); + scrollItem->setPos(QPointF(rect.width()/2, -scrollItem->boundingRect().height())); + connect(scrollItem, &ScrollItem::angleChange, this, [=](qreal angle) { + setTransform(transform().rotate(angle)); + }); + } +} + +void RectLayer::paintStyle(QPainter *painter){ + QPen pen; + pen.setColor(paintData.color); + pen.setWidth(paintData.width); + pen.setJoinStyle(paintData.joinStyle); + pen.setCapStyle(paintData.capStyle); + painter->setPen(pen); +} + +void RectLayer::setLimit(const QRectF& limit) { + for(ExpandButton* button: buttons) { + button->setLimit(limit); + } +} + +void RectLayer::setStyle(const PaintData& data){ + paintData = data; +} +bool RectLayer::contains(const QPointF &point) const { + if(QGraphicsObject::contains(point)) return true; + for(QGraphicsItem* item: childItems()) { + if(item->isVisible() && item->contains(item->mapFromParent(point)))return true; + } + return false; +} + +void RectLayer::prepareSave(){ + LayerBase::prepareSave(); + showButtons(); +} + +void RectLayer::endSave(){ + LayerBase::endSave(); + hideButtons(); +} + +void RectLayer::initButtons(){ + for(int i=0; i<4; i++) { + ExpandButton::ButtonDirection dir = (ExpandButton::ButtonDirection)i; + QPointF p = rect.topLeft(); + float x = dir == ExpandButton::NW || dir == ExpandButton::SW ? p.x() : p.x() + rect.width(); + float y = dir == ExpandButton::NW || dir == ExpandButton::NE ? p.y() : p.y() + rect.height(); + ExpandButton* button = new ExpandButton(dir, QPointF(x, y), this); + connect(button, static_cast(&ExpandButton::posChange), this, &RectLayer::posChangeFunc); + connect(button, &ExpandButton::posTo, this, &RectLayer::posToFunc); + buttons.insert(dir, button); + } +} + +void RectLayer::setBoundEffect(){ + setEnableScroll(false); + setEnableResize(true); +} + +void RectLayer::reset(){ + if(manager != NULL) manager->removeThis(this); +} + +void RectLayer::setParameter(const QString &name, const QVariant &var){ + if(name == "style"){ + paintData = var.value(); + } +} + +QRectF RectLayer::boundingRect() const{ + return rect; +} + +QPainterPath RectLayer::shape() const { + QPainterPath ans; + QRectF tmp1 = rect; + tmp1.setTopLeft(tmp1.topLeft() - QPoint(5, 5)); + tmp1.setBottomRight(tmp1.bottomRight() + QPoint(5, 5)); + ans.addRect(tmp1); + if(rect.width() > 10 && rect.height() > 10) { + QRectF tmp = rect; + tmp.setTopLeft(tmp.topLeft() + QPoint(5, 5)); + tmp.setBottomRight(tmp.bottomRight() - QPoint(5, 5)); + ans.addRect(tmp); + } + return ans; +} + +int RectLayer::getZValue() const{ + return 2; +} + +void RectLayer::getFocus(){ + showButtons(); +} + +void RectLayer::loseFocus(){ + hideButtons(); +} diff --git a/GraphicsScene/Layer/rectlayer.h b/GraphicsScene/Layer/rectlayer.h new file mode 100644 index 0000000..82388cc --- /dev/null +++ b/GraphicsScene/Layer/rectlayer.h @@ -0,0 +1,61 @@ +#ifndef RECTLAYER_H +#define RECTLAYER_H +#include "layerbase.h" +#include "../Widgets/expandbutton.h" +#include "../Widgets/scrollitem.h" + +class RectLayer : public LayerBase +{ + Q_OBJECT +public: + RectLayer(const QRectF& rect, const QString& name, ILayerControl* manager, QGraphicsItem* parent=nullptr, bool enableResize=true); + void setParameter(const QString &name, const QVariant &var) override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; + void prepareSave() override; + void endSave() override; + void reset() override; + int getZValue() const override; + QRectF boundingRect() const override; + QPainterPath shape() const override; + void getFocus() override; + void loseFocus() override; + void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; + void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; + void mousePressEvent(QGraphicsSceneMouseEvent *event) override; + + void setEnableResize(bool enable); + void setEnableScroll(bool enable); + void setBounding(const QRectF& rect); + void setLimit(const QRectF& limit); + void setStyle(const PaintData& data); + void showButtons(); + void hideButtons(); + bool contains(const QPointF& point)const override; + void setBoundEffect(); + void setButtonFocus(bool enable); + +signals: + void sizeChange(); + void move(qreal dx, qreal dy); + +private slots: + void posChangeFunc(ExpandButton::ButtonDirection dir, qreal x, qreal y); + void posToFunc(ExpandButton::ButtonDirection dir, qreal x, qreal y); + +private: + void paintStyle(QPainter* painter); + void initButtons(); + QRectF rect; + QMap buttons; + ScrollItem* scrollItem; + bool enableScroll; + bool enableResize; + bool buttonFocus; + PaintData paintData; + QPointF beginPoint; + QCursor outCursor; +}; + +#endif // RECTLAYER_H diff --git a/GraphicsScene/Layer/rootlayer.cpp b/GraphicsScene/Layer/rootlayer.cpp new file mode 100644 index 0000000..bc3761d --- /dev/null +++ b/GraphicsScene/Layer/rootlayer.cpp @@ -0,0 +1,27 @@ +#include "rootlayer.h" +#include "../paintarea.h" + +RootLayer::RootLayer(PaintArea* area, QGraphicsItem* parent) : QGraphicsItem(parent) +{ + area->addItem(this); +} + +QRectF RootLayer::boundingRect() const{ + return QRectF(); +} + +void RootLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ + +} + +void RootLayer::mousePressEvent(QGraphicsSceneMouseEvent *event){ + +} + +void RootLayer::mouseMoveEvent(QGraphicsSceneMouseEvent *event){ + +} + +void RootLayer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ + +} diff --git a/GraphicsScene/Layer/rootlayer.h b/GraphicsScene/Layer/rootlayer.h new file mode 100644 index 0000000..b0a2a79 --- /dev/null +++ b/GraphicsScene/Layer/rootlayer.h @@ -0,0 +1,20 @@ +#ifndef ROOTLAYER_H +#define ROOTLAYER_H +#include + +class PaintArea; + +class RootLayer : public QGraphicsItem +{ +public: + RootLayer(PaintArea* area, QGraphicsItem* parent=nullptr); + QRectF boundingRect() const override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; + void mousePressEvent(QGraphicsSceneMouseEvent *event) override; + void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; +private: + PaintArea* area; +}; + +#endif // ROOTLAYER_H diff --git a/GraphicsScene/Layer/textlayer.cpp b/GraphicsScene/Layer/textlayer.cpp new file mode 100644 index 0000000..3ea046a --- /dev/null +++ b/GraphicsScene/Layer/textlayer.cpp @@ -0,0 +1,77 @@ +#include "textlayer.h" + +TextLayer::TextLayer(const QPointF& pos, + const QString& name, + ILayerControl* manager, + QGraphicsItem* parent) : + LayerBase(name, manager, parent), + textItem(new TextItem(pos, this)) +{ + connect(textItem, &TextItem::requestFocus, this, [=](){ + manager->requestFocus(this); + }); + connect(textItem, &TextItem::formatChange, this, [=](const QFont& font, const QBrush& brush){ + emit formatChange(font, brush); + }); +} + +void TextLayer::reset(){ + manager->removeThis(this); +} + +void TextLayer::getFocus(){ + textItem->getFocus(); +} + +void TextLayer::loseFocus(){ + if(textItem->toPlainText() == ""){ + manager->removeThis(this); + return; + } + textItem->loseFocus(); +} + +QRectF TextLayer::boundingRect() const{ + return QRectF(); +} + +void TextLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ + +} + +void TextLayer::prepareSave(){ + textItem->loseFocus(); +} + +void TextLayer::setParameter(const QString &name, const QVariant &var){ + if(name == "font"){ + QFont font = var.value(); + textItem->setFont(font); + } + if(name == "color"){ + QColor color = var.value(); + textItem->setColor(color); + } + if(name == "brush"){ + textItem->setBrush(true); + } +} + +void TextLayer::setEnable(bool enable){ + LayerBase::setEnable(enable); + textItem->setEnable(enable); +} + +const QString TextLayer::getHelp(){ + return "font: 设置字体\n" + "color: 设置字体颜色\n" + "brush: 设置字体刷"; +} + +bool TextLayer::contains(const QPointF &point) const{ + if(QGraphicsObject::contains(point)) return true; + for(QGraphicsItem* item: childItems()) { + if(item->isVisible() && item->contains(item->mapFromParent(point)))return true; + } + return false; +} diff --git a/GraphicsScene/Layer/textlayer.h b/GraphicsScene/Layer/textlayer.h new file mode 100644 index 0000000..19a6a45 --- /dev/null +++ b/GraphicsScene/Layer/textlayer.h @@ -0,0 +1,32 @@ +#ifndef TEXTLAYER_H +#define TEXTLAYER_H +#include "layerbase.h" +#include "../Widgets/textitem.h" + +class TextLayer : public LayerBase +{ + Q_OBJECT +public: + TextLayer(const QPointF& pos, + const QString& name, + ILayerControl* manager, + QGraphicsItem* parent=nullptr); + void reset() override; + void getFocus() override; + void loseFocus() override; + QRectF boundingRect() const override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; + void prepareSave() override; + void setParameter(const QString &name, const QVariant &var) override; + void setEnable(bool enable) override; + const QString getHelp() override; + bool contains(const QPointF& point)const override; + +signals: + void formatChange(const QFont& font, const QBrush& brush); + +private: + TextItem* textItem; +}; + +#endif // TEXTLAYER_H diff --git a/GraphicsScene/Widgets/FontData.h b/GraphicsScene/Widgets/FontData.h new file mode 100644 index 0000000..e9207bb --- /dev/null +++ b/GraphicsScene/Widgets/FontData.h @@ -0,0 +1,17 @@ +#ifndef FONTDATA_H +#define FONTDATA_H +#include +#include + +class FontData { +public: + FontData(){} + FontData(QFont font, QColor color){ + this->font = font; + this->color = color; + } + QFont font; + QColor color; +}; + +#endif // FONTDATA_H diff --git a/GraphicsScene/Widgets/PaintData.h b/GraphicsScene/Widgets/PaintData.h new file mode 100644 index 0000000..673ced1 --- /dev/null +++ b/GraphicsScene/Widgets/PaintData.h @@ -0,0 +1,33 @@ +#ifndef PAINT_DATA_H +#define PAINT_DATA_H +#include +#include + +struct PaintData { +public: + PaintData() {}; + PaintData(QColor color, double width, QColor back_color=QColor(255, 255, 255), + Qt::PenCapStyle cap_style=Qt::SquareCap, + Qt::PenJoinStyle join_style=Qt::RoundJoin) { + this->color = color; + this->width = width; + this->capStyle = cap_style; + this->joinStyle = join_style; + this->backColor = back_color; + } + void copy_to(PaintData* data) { + data->color = color; + data->width = width; + data->capStyle = capStyle; + data->joinStyle = joinStyle; + data->backColor = backColor; + } + QColor color; + int width;//笔的粗细 + Qt::PenCapStyle capStyle; + Qt::PenJoinStyle joinStyle; + QColor backColor; +}; +Q_DECLARE_METATYPE(PaintData) + +#endif // PAINT_DATA_H diff --git a/GraphicsScene/Widgets/attributetoolbar.cpp b/GraphicsScene/Widgets/attributetoolbar.cpp new file mode 100644 index 0000000..f577baf --- /dev/null +++ b/GraphicsScene/Widgets/attributetoolbar.cpp @@ -0,0 +1,69 @@ +#include "attributetoolbar.h" +#include +#include + +AttributeToolbar::AttributeToolbar(QWidget* parent) : QWidget(parent) { + setAttribute(Qt::WA_StyledBackground); + layout = new QHBoxLayout(); + layout->setSpacing(3); + layout->setContentsMargins(3, 2, 3, 2); + setLayout(layout); +} + +void AttributeToolbar::addWidget(QWidget *widget) { + if(!containWidget(widget)){ + widgets.append(widget); + widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + } + widget->show(); + layout->addWidget(widget); + adjustSize(); + // actions.append(QToolBar::addWidget(widget)); +} + +void AttributeToolbar::removeAll() { + QLayoutItem *child; + while ((child = layout->takeAt(0)) != nullptr) { + if(child->widget()) { + layout->removeWidget(child->widget()); + child->widget()->hide(); + } + if(child->layout()){ + auto childLayout = child->layout(); + layout->removeItem(childLayout); + } + } + update(); +} + +void AttributeToolbar::hideAll(){ + QLayoutItem *child; + while ((child = layout->takeAt(0)) != nullptr) { + if(child->widget()) { + child->widget()->hide(); + } + } + update(); +} + +void AttributeToolbar::paintEvent(QPaintEvent *event) { + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); +} + +void AttributeToolbar::setAttriLayout(QLayout *layout){ + removeAll(); + this->layout->addLayout(layout, 1); + adjustSize(); +} + +void AttributeToolbar::showWidget(QWidget *widget){ + removeAll(); + addWidget(widget); +} + +bool AttributeToolbar::containWidget(QWidget* widget){ + return widgets.contains(widget); +} diff --git a/GraphicsScene/Widgets/attributetoolbar.h b/GraphicsScene/Widgets/attributetoolbar.h new file mode 100644 index 0000000..d7e8398 --- /dev/null +++ b/GraphicsScene/Widgets/attributetoolbar.h @@ -0,0 +1,24 @@ +#ifndef ATTRIBUTETOOLBAR_H +#define ATTRIBUTETOOLBAR_H +#include +#include +#include + +class AttributeToolbar : public QWidget +{ + Q_OBJECT +public: + AttributeToolbar(QWidget* parent=nullptr); + void addWidget(QWidget* widget); + void showWidget(QWidget* widget); + void paintEvent(QPaintEvent *event) override; + void removeAll(); + void setAttriLayout(QLayout* layout); + void hideAll(); +private: + bool containWidget(QWidget* widget); + QHBoxLayout* layout; + QList widgets; +}; + +#endif // ATTRIBUTETOOLBAR_H diff --git a/GraphicsScene/Widgets/expandbutton.cpp b/GraphicsScene/Widgets/expandbutton.cpp new file mode 100644 index 0000000..64b59f5 --- /dev/null +++ b/GraphicsScene/Widgets/expandbutton.cpp @@ -0,0 +1,170 @@ +#include "expandbutton.h" +#include +#include +#include + +ExpandButton::ExpandButton() +{ + is_limit = false; + is_capture = false; + setAcceptHoverEvents(true); +} + +ExpandButton::ExpandButton(QGraphicsItem* parent) : QGraphicsObject(parent) +{ + is_limit = false; + is_capture = false; + setAcceptHoverEvents(true); +} + +ExpandButton::ExpandButton(ButtonDirection dir, QPointF pos, QGraphicsItem* parent): QGraphicsObject(parent) +{ + this->dir = dir; + setPos(pos); + setAcceptHoverEvents(true); + is_limit = false; + is_capture = false; +} + +void ExpandButton::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + begin_point = event->scenePos(); + record_point = event->scenePos(); + emit posChangeBegin(begin_point.x(), begin_point.y()); +} + +void ExpandButton::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + QPointF delta_point = event->scenePos() - begin_point; + begin_point = event->scenePos(); + QPointF after_point = pos() + delta_point; + if(is_limit && (after_point.x() > limit.right() || after_point.x() < limit.left() + || after_point.y() > limit.bottom() || after_point.y() < limit.top())) + { + return; + } + moveBy(delta_point.x(), delta_point.y()); + emit posChange(dir, delta_point.x(), delta_point.y()); + emit posChange(index, delta_point.x(), delta_point.y(), x_neighbor_index, y_neighbor_index); +} + +void ExpandButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + QPointF delta_point = event->scenePos() - begin_point; + begin_point = event->scenePos(); + QPointF after_point = pos() + delta_point; + if(is_limit && (after_point.x() > limit.right() || after_point.x() < limit.left() + || after_point.y() > limit.bottom() || after_point.y() < limit.top())) + { + return; + } + moveBy(delta_point.x(), delta_point.y()); + delta_point = event->scenePos() - record_point; + emit posTo(dir, delta_point.x(), delta_point.y()); +} + +void ExpandButton::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + out_cursor = cursor(); + if(is_capture) + { + setCursor(Qt::PointingHandCursor); + } + if(dir == N || dir == S) + { + setCursor(Qt::SizeVerCursor); + } + else if(dir == W || dir == E) + { + setCursor(Qt::SizeHorCursor); + } + else if(dir == NE || dir == SW) + { + setCursor(Qt::SizeBDiagCursor); + } + else + { + setCursor(Qt::SizeFDiagCursor); + } +} + +void ExpandButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + setCursor(out_cursor); +} + +void ExpandButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + QBrush brush(QColor(255, 255, 255, 128)); + painter->setBrush(brush); + painter->drawEllipse(QPointF(0, 0), radius, radius); +} + +QRectF ExpandButton::boundingRect() const +{ + return QRectF(-QPointF(radius, radius), QPointF(radius, radius)); +} + +QPainterPath ExpandButton::shape() const +{ + QPainterPath path; + path.addEllipse(QRectF(-QPointF(radius, radius), QPointF(radius, radius))); + return path; +} + +void ExpandButton::setLimit(QRectF rect) +{ + is_limit = true; + limit = rect; +} + +void ExpandButton::setIndex(int index) +{ + this->index.append(index); + is_capture = true; +} + +void ExpandButton::setPosition(QPointF pos) +{ + setPos(pos); +} + +bool ExpandButton::setNeighbor(QPoint pos, int index) +{ + if(this->pos().x() == pos.x()) + { + x_neighbor_index = index; + return true; + } + else if(this->pos().y() == pos.y()) + { + y_neighbor_index = index; + return true; + } + return false; +} + +void ExpandButton::setIntPos(QPoint pos) +{ + this->int_point = pos; +} + +QPoint ExpandButton::getPos() +{ + return int_point; +} + +void ExpandButton::clearIndex() +{ + index.clear(); +} + +QList ExpandButton::getIndex() +{ + return index; +} + +void ExpandButton::setButtonIndex(int index) +{ + buttonIndex = index; +} diff --git a/GraphicsScene/Widgets/expandbutton.h b/GraphicsScene/Widgets/expandbutton.h new file mode 100644 index 0000000..ec83f0c --- /dev/null +++ b/GraphicsScene/Widgets/expandbutton.h @@ -0,0 +1,54 @@ +#ifndef EXPANDBUTTON_H +#define EXPANDBUTTON_H +#include +#include +#include +#include "PaintData.h" + +class ExpandButton : public QGraphicsObject +{ + Q_OBJECT +public: + enum ButtonDirection {NW, NE, SW, SE, N, W, S, E}; + ExpandButton(); + ExpandButton(QGraphicsItem* parent=nullptr); + ExpandButton(ButtonDirection dir, QPointF pos, QGraphicsItem* parent=nullptr); + void mousePressEvent(QGraphicsSceneMouseEvent *event) override; + void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; + void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; + void setLimit(QRectF rect); + void setIndex(int index); + void setButtonIndex(int index); + void setPosition(QPointF pos); + void setIntPos(QPoint pos); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; + QRectF boundingRect() const override; + QPainterPath shape() const override; + bool setNeighbor(QPoint pos, int index); + QPoint getPos(); + void clearIndex(); + QList getIndex(); +signals: + void posChangeBegin(qreal x, qreal y); + void posChange(ButtonDirection dir, qreal x, qreal y); + void posChange(QList index, qreal x, qreal y, int x_neighbor_index, int y_neighbor_index); + void posTo(ButtonDirection dir, qreal x, qreal y); +private: + ButtonDirection dir; + QList index; + int buttonIndex; + int x_neighbor_index; + int y_neighbor_index; + QCursor out_cursor; + QPointF begin_point; + QPointF record_point; + QPoint int_point; + QRectF limit; + bool is_limit; + bool is_capture; + const qreal radius = 5; +}; + +#endif // EXPANDBUTTON_H diff --git a/GraphicsScene/Widgets/layertoolbar.cpp b/GraphicsScene/Widgets/layertoolbar.cpp new file mode 100644 index 0000000..eb3e945 --- /dev/null +++ b/GraphicsScene/Widgets/layertoolbar.cpp @@ -0,0 +1,105 @@ +#include "layertoolbar.h" +#include +#include "../../Helper/mstring.h" +#include "../../Helper/imagehelper.h" +#include + +LayerToolBar::LayerToolBar(PaintArea* area, QWidget* parent) : + QToolBar(parent), + area(area), + group(new QButtonGroup(this)), + groupId(0), + attributeBar(new AttributeToolbar(parent)), + bound(ImageHelper::getCurrentGeometry()) +{ + group->setExclusive(true); + connect(group, static_cast(&QButtonGroup::buttonClicked), this, &LayerToolBar::onGroupClick); +} + +void LayerToolBar::addContainer(QToolButton* button, LayerContainer* container, bool exclude){ + if(!exclude){ + connect(button, &QToolButton::clicked, this, [=](){ + area->setContainer(container); + QWidget* widget = container->onValid(attributeBar); + attributeBar->addWidget(widget); + moveTo(mask); + }); + } + else{ + button->setCheckable(true); + button->setChecked(false); + group->addButton(button, groupId); + groupId++; + containers.append(container); + } + addWidget(button); + adjustSize(); +} + +void LayerToolBar::addContainer(const QString &icon, + const QString &tip, + LayerContainer *container, + bool exclude){ + QToolButton* toolButton = new QToolButton(this); + toolButton->setToolTip(MString::search(tip)); + toolButton->setIcon(ImageHelper::getIcon(icon)); + addContainer(toolButton, container, exclude); +} + +void LayerToolBar::moveTo(const QRectF& mask){ + this->mask = mask; + if(!isVisible()) + show(); + if(!attributeBar->isVisible()) + attributeBar->show(); + + if(group->checkedButton() == NULL) { + qInfo() << "checked button NULL"; + return; + } + int bar_height = height(); + int bar_width = width(); + QRectF mask_bound = mask; + int left = mask_bound.right() - bar_width; + int top = mask_bound.bottom(); + + int attributeBarWidth = attributeBar->width(); + int attributeBarHeight = attributeBar->height(); + int maxWidth = group->checkedButton()->pos().x() + attributeBarWidth > bar_width ? group->checkedButton()->pos().x() + attributeBarWidth : bar_width; + if(left + maxWidth > bound.right()) { + left = bound.right() - maxWidth; + } + if(left < 0) { + left = 0; + } + if(top + bar_height + attributeBarHeight > bound.bottom()) { + top = bound.bottom() - bar_height - attributeBarHeight; + } + if(top < 0) { + top = 0; + } + if(left == 0 && top == 0){ + QPoint toolbarPos = mapToGlobal(QPoint(left, top)); + left = toolbarPos.x(); + top = toolbarPos.y(); + } + move(left, top); + attributeBar->move(left + group->checkedButton()->pos().x(), top + bar_height); +} + +void LayerToolBar::setContainer(LayerContainer *container){ + for(int i=0; ibutton(i)->setChecked(true); + onGroupClick(i); + break; + } + } +} + +void LayerToolBar::onGroupClick(int id){ + area->setContainer(containers[id]); + QWidget* widget = containers[id]->onValid(attributeBar); + attributeBar->showWidget(widget); + moveTo(mask); +} diff --git a/GraphicsScene/Widgets/layertoolbar.h b/GraphicsScene/Widgets/layertoolbar.h new file mode 100644 index 0000000..73ce2c2 --- /dev/null +++ b/GraphicsScene/Widgets/layertoolbar.h @@ -0,0 +1,34 @@ +#ifndef LAYERTOOLBAR_H +#define LAYERTOOLBAR_H +#include +#include "../Container/layercontainer.h" +#include "attributetoolbar.h" +#include "../paintarea.h" + +class LayerToolBar : public QToolBar +{ +public: + LayerToolBar(PaintArea* area, QWidget* parent=nullptr); + void addContainer(QToolButton* button, LayerContainer* container, bool exclude=false); + void addContainer(const QString& icon, + const QString& tip, + LayerContainer* container, + bool exclude = false); + void moveTo(const QRectF& mask); + void setBound(const QRectF& bound); + void setContainer(LayerContainer* container); + +private slots: + void onGroupClick(int id); + +private: + PaintArea* area; + QButtonGroup* group; + int groupId; + AttributeToolbar* attributeBar; + QList containers; + QRectF mask; + QRectF bound; +}; + +#endif // LAYERTOOLBAR_H diff --git a/GraphicsScene/Widgets/scrollitem.cpp b/GraphicsScene/Widgets/scrollitem.cpp new file mode 100644 index 0000000..a9ab6b0 --- /dev/null +++ b/GraphicsScene/Widgets/scrollitem.cpp @@ -0,0 +1,59 @@ +#include "scrollitem.h" +#include +#include +#include +#include +#include +#include +#include + +ScrollItem::ScrollItem(QGraphicsItem* parent) : QGraphicsObject(parent) +{ + pix = QPixmap(":/image/rotate.png"); + pix.scaled(16, 16); + setCursor(QCursor(pix)); +} + +void ScrollItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + painter->drawPixmap(QPointF(-pix.width()/2.0, -pix.height()/2.0), pix); +} + +QRectF ScrollItem::boundingRect() const +{ + return QRectF(QPointF(-pix.width()/2.0, -pix.height()/2.0), QSizeF(pix.width(), pix.height())); +} + +void ScrollItem::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + begin_point = event->scenePos(); +} + +void ScrollItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + begin_point = mapToParent(mapFromScene(begin_point)); + QVector2D start_vec(begin_point.x(), begin_point.y()); + start_vec.normalize(); + QPointF point = mapToParent(mapFromScene(event->scenePos())); + QVector2D end_vec(point.x(), point.y()); + end_vec.normalize(); + + qreal dotValue = QVector2D::dotProduct(start_vec, end_vec); + if (dotValue > 1.0) + dotValue = 1.0; + else if (dotValue < -1.0) + dotValue = -1.0; + + dotValue = qAcos(dotValue); + + qreal angle = dotValue * 1.0 / (M_PI / 180); + + QVector3D crossValue = QVector3D::crossProduct( \ + QVector3D(start_vec, 1.0), \ + QVector3D(end_vec, 1.0)); + + if (crossValue.z() < 0) + angle = -angle; + emit angleChange(angle); + begin_point = event->scenePos(); +} diff --git a/GraphicsScene/Widgets/scrollitem.h b/GraphicsScene/Widgets/scrollitem.h new file mode 100644 index 0000000..cda4f59 --- /dev/null +++ b/GraphicsScene/Widgets/scrollitem.h @@ -0,0 +1,21 @@ +#ifndef SCROLLITEM_H +#define SCROLLITEM_H +#include + +class ScrollItem : public QGraphicsObject +{ + Q_OBJECT +public: + ScrollItem(QGraphicsItem* parent); + QRectF boundingRect()const override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr)override; + void mousePressEvent(QGraphicsSceneMouseEvent *event) override; + void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; +signals: + void angleChange(qreal angle); +private: + QPixmap pix; + QPointF begin_point; +}; + +#endif // SCROLLITEM_H diff --git a/GraphicsScene/Widgets/textitem.cpp b/GraphicsScene/Widgets/textitem.cpp new file mode 100644 index 0000000..9820ebf --- /dev/null +++ b/GraphicsScene/Widgets/textitem.cpp @@ -0,0 +1,175 @@ +#include "textitem.h" +#include "../../Manager/uimanager.h" +#include +#include +#include + +TextItem::TextItem(const QPointF& pos, QGraphicsItem* parent) : QGraphicsTextItem(parent), + forceFocus(false), + mEnable(true), + commitString(false), + isBrush(false), + nowPos(0) +{ + setTextInteractionFlags(Qt::TextEditorInteraction); + setPos(pos); + rectLayer = new RectLayer(QRectF(QPointF(0, 0), boundingRect().size()), "", NULL, this, false); + rectLayer->setEnable(true); + PaintData rectData; + rectData.color = QColor(0, 0, 0); + rectData.width = 1; + rectData.joinStyle = Qt::RoundJoin; + rectLayer->setStyle(rectData); + connect(rectLayer, &RectLayer::move, this, [=](qreal dx, qreal dy) { + moveBy(dx, dy); + rectLayer->setPos(0, 0); + }); + connect(document(), &QTextDocument::contentsChanged, this, [=]() { + rectLayer->setBounding(boundingRect()); + }); + connect(document(), &QTextDocument::cursorPositionChanged, this, [=](const QTextCursor& cursor) { + onCursorPositionChange(cursor.position()); + }); + connect(document(), static_cast(&QTextDocument::contentsChange), + this, [=](int position, int charsRemoved, int charsAdded) { + if(isBrush) { + isBrush = false; + return; + } + QTextCursor textCursor(document()); + if(!commitString) { + textCursor.setPosition(position); + textCursor.setPosition(position+charsAdded, QTextCursor::KeepAnchor); + } else { + if(charsAdded - charsRemoved == commitLen && position == 0) { + textCursor.setPosition(commitPos); + textCursor.setPosition(commitPos+commitLen, QTextCursor::KeepAnchor); + } else { + textCursor.setPosition(position); + textCursor.setPosition(position+commitLen, QTextCursor::KeepAnchor); + } + } + commitString = false; + textCursor.setCharFormat(currentFormat); + }); + setFocus(); + FontData data = UIManager::instance()->getFontData(); + currentFormat.setFont(data.font); + currentFormat.setForeground(data.color); +} + + +void TextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { + setFocus(); + if(mEnable) { + boundShow(); + } +} + +void TextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { + if(!forceFocus) + clearFocus(); + boundHide(); +} + +void TextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { + emit requestFocus(); + QGraphicsTextItem::mousePressEvent(event); + if(nowPos != textCursor().position()) { + onCursorPositionChange(textCursor().position()); + } +} + +void TextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { + if(textCursor().selectedText().size() != 0 && isBrush) { + QTextCursor text_cursor(document()); + text_cursor.setPosition(textCursor().selectionStart()); + text_cursor.setPosition(textCursor().selectionEnd(), QTextCursor::KeepAnchor); + text_cursor.setCharFormat(brushFormat); + onCursorPositionChange(textCursor().position()); + } +} + +void TextItem::focusInEvent(QFocusEvent *event) { + QGraphicsTextItem::focusInEvent(event); +} + +void TextItem::focusOutEvent(QFocusEvent* event) { + QGraphicsTextItem::focusOutEvent(event); +} + +void TextItem::keyPressEvent(QKeyEvent *event) { + emit requestFocus(); + QGraphicsTextItem::keyPressEvent(event); + if(event->key() == Qt::Key_Right || event->key() == Qt::Key_Left) { + onCursorPositionChange(textCursor().position()); + } +} + +void TextItem::inputMethodEvent(QInputMethodEvent *event) { + commitPos = textCursor().position(); + commitString = true; + commitLen = event->commitString().length(); + QGraphicsTextItem::inputMethodEvent(event); +} + + +void TextItem::boundShow() { + rectLayer->show(); +} + +void TextItem::boundHide() { + if(forceFocus) { + return; + } + rectLayer->hide(); + update(); +} + + +void TextItem::onCursorPositionChange(int current) { + nowPos = current; + formatChange(textCursor().charFormat().font(), textCursor().charFormat().foreground()); + currentFormat = textCursor().charFormat(); +} + +void TextItem::getFocus(){ + forceFocus = true; + update(); +} + +void TextItem::loseFocus(){ + forceFocus = false; + boundHide(); + update(); +} + +void TextItem::setEnable(bool enable){ + this->mEnable = enable; + if(enable){ + setTextInteractionFlags(Qt::TextEditorInteraction); + } + else{ + QTextCursor cursor = textCursor(); + cursor.clearSelection(); + setTextCursor(cursor); + rectLayer->hide(); + forceFocus = false; + setTextInteractionFlags(Qt::NoTextInteraction); + } + update(); +} + +void TextItem::setFont(const QFont &font){ + currentFormat.setFont(font); +} + +void TextItem::setColor(QColor color){ + currentFormat.setForeground(color); +} + +void TextItem::setBrush(bool enable){ + isBrush = enable; + if(enable) brushFormat = currentFormat; +} + diff --git a/GraphicsScene/Widgets/textitem.h b/GraphicsScene/Widgets/textitem.h new file mode 100644 index 0000000..01f0638 --- /dev/null +++ b/GraphicsScene/Widgets/textitem.h @@ -0,0 +1,52 @@ +#ifndef TEXTITEM_H +#define TEXTITEM_H +#include +#include "../Layer/rectlayer.h" +#include + +class TextItem : public QGraphicsTextItem +{ + Q_OBJECT +public: + TextItem(const QPointF& rect, + QGraphicsItem* parent=nullptr); + void getFocus(); + void loseFocus(); + void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; + void mousePressEvent(QGraphicsSceneMouseEvent *event) override; + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; + void focusInEvent(QFocusEvent *event) override; + void focusOutEvent(QFocusEvent *event) override; + void keyPressEvent(QKeyEvent *event) override; + void inputMethodEvent(QInputMethodEvent* event) override; + void setEnable(bool enable); + void setFont(const QFont& font); + void setColor(QColor color); + void setBrush(bool enable); + +signals: + void requestFocus(); + void formatChange(const QFont& font, const QBrush& brush); + +private: + void boundShow(); + void boundHide(); + void initFlowEditPanel(); + void onCursorPositionChange(int current); +private: + + QRectF rect; + RectLayer* rectLayer; + bool forceFocus; + bool mEnable; + bool commitString; + bool isBrush; + int commitLen; + int commitPos; + int nowPos; + QTextCharFormat brushFormat; + QTextCharFormat currentFormat; +}; + +#endif // TEXTITEM_H diff --git a/GraphicsScene/ilayercontrol.cpp b/GraphicsScene/ilayercontrol.cpp new file mode 100644 index 0000000..03e829b --- /dev/null +++ b/GraphicsScene/ilayercontrol.cpp @@ -0,0 +1,30 @@ +#include "ilayercontrol.h" + +ILayerControl::ILayerControl() +{ + modified = false; + imageValid = false; +} + +QImage ILayerControl::getOriginImage() const{ + return image; +} + +QImage ILayerControl::getImage() const{ + if(modified){ + return modifiedImage; + } + return image; +} + +void ILayerControl::modifyImage(const QPoint &pos, const QColor& color){ + if(!modified){ + modifiedImage = image; + } + modified = true; + modifiedImage.setPixel(pos, color.rgba()); +} + +bool ILayerControl::isImageValid(){ + return imageValid; +} diff --git a/GraphicsScene/ilayercontrol.h b/GraphicsScene/ilayercontrol.h new file mode 100644 index 0000000..cb01bdf --- /dev/null +++ b/GraphicsScene/ilayercontrol.h @@ -0,0 +1,32 @@ +#ifndef ILAYERCONTROL_H +#define ILAYERCONTROL_H +#include + +class LayerBase; +/** + * @brief 供@ref LayerBase 访问和操作图像及提供一些全局操作 + */ +class ILayerControl +{ +public: + enum SaveType{ClipBoard, Persist, Temp}; + ILayerControl(); + virtual ~ILayerControl(){} + virtual bool save(SaveType type, const QString& path="")=0; + virtual QImage getOriginImage() const; + virtual QImage getImage() const; + bool isImageValid(); + virtual bool hasFocus(LayerBase* layer)=0; + virtual void requestFocus(LayerBase* layer)=0; + virtual void removeThis(LayerBase* layer)=0; + virtual void modifyImage(const QPoint& pos, const QColor& color); + virtual void setEraseEnable(bool enable)=0; + virtual void setEnable(bool enable)=0; +protected: + bool imageValid; + QImage image; + QImage modifiedImage; + bool modified; +}; + +#endif // ILAYERCONTROL_H diff --git a/GraphicsScene/layermanager.cpp b/GraphicsScene/layermanager.cpp new file mode 100644 index 0000000..46d8836 --- /dev/null +++ b/GraphicsScene/layermanager.cpp @@ -0,0 +1,59 @@ +#include "layermanager.h" +#include + +LayerManager::LayerManager() +{ + focusLayer = NULL; +} + +void LayerManager::addLayer(LayerBase *layer){ + if(layers.contains(layer->getName())){ + qWarning() << "layer name: " << layer->getName() << " already in manager"; + } + layers.insert(layer->getName(), layer); + changeFocusLayer(layer); +} + +void LayerManager::changeFocusLayer(const QString &name){ + auto layer = layers.find(name); + if(layer != layers.end()){ + changeFocusLayer(layer.value()); + } +} + +void LayerManager::changeFocusLayer(LayerBase* layer){ + if(focusLayer == layer){ + return; + } + LayerBase* beforeFocusLayer = focusLayer; + focusLayer = layer; + focusLayer->getFocus(); + if(beforeFocusLayer != NULL){ + beforeFocusLayer->loseFocus(); + } +} + +bool LayerManager::hasFocus(LayerBase *layer){ + return focusLayer == layer; +} + +LayerBase* LayerManager::removeLayer(const QString &name){ + auto layer = layers.find(name); + if(layer != layers.end()){ + if(focusLayer == layer.value()){ + focusLayer = NULL; + } + LayerBase* value = layer.value(); + layers.remove(name); + return value; + } + return NULL; +} + +QList LayerManager::getLayers() const{ + return layers.values(); +} + +LayerBase* LayerManager::getFocusLayer(){ + return focusLayer; +} diff --git a/GraphicsScene/layermanager.h b/GraphicsScene/layermanager.h new file mode 100644 index 0000000..3146b2e --- /dev/null +++ b/GraphicsScene/layermanager.h @@ -0,0 +1,24 @@ +#ifndef LAYERMANAGER_H +#define LAYERMANAGER_H +#include +#include +#include "Layer/layerbase.h" + +class LayerManager +{ +public: + LayerManager(); + virtual ~LayerManager(){} + virtual void addLayer(LayerBase* layer); + virtual LayerBase* removeLayer(const QString& name); + virtual void changeFocusLayer(const QString& name); + virtual void changeFocusLayer(LayerBase* layer); + bool hasFocus(LayerBase* layer); + LayerBase* getFocusLayer(); + QList getLayers() const; +protected: + QHash layers; + LayerBase* focusLayer; +}; + +#endif // LAYERMANAGER_H diff --git a/GraphicsScene/paintarea.cpp b/GraphicsScene/paintarea.cpp new file mode 100644 index 0000000..a13be4b --- /dev/null +++ b/GraphicsScene/paintarea.cpp @@ -0,0 +1,167 @@ +#include "paintarea.h" +#include +#include "opencv2/core.hpp" +#include "opencv2/opencv.hpp" +#include +#include "../Helper/imagehelper.h" +#include "../Paint/Widgets/history.h" +#include +#include + +PaintArea::PaintArea(QWidget* parent) : + QGraphicsScene(parent), + container(NULL), + inLayer(false), + press(false), + mouseGrabber(NULL), + rootLayer(new RootLayer(this)) +{ +} + +void PaintArea::mousePressEvent(QGraphicsSceneMouseEvent *event){ + for(auto& layer: layers){ + if((layer->isEnable() || layer->isErase()) && layer->contains(layer->mapFromScene(event->scenePos()))){ +// sendEvent(layer, event); + inLayer = true; + press = true; + mouseGrabber = layer; + } + } + if(!inLayer){ + if(container != NULL) container->layerMousePressEvent(event); + } + QGraphicsScene::mousePressEvent(event); +} + +void PaintArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event){ + QGraphicsScene::mouseMoveEvent(event); + if(!inLayer){ + if(container != NULL) container->layerMouseMoveEvent(event); + return; + } +// if(press) sendEvent(mouseGrabber, event); +} + +void PaintArea::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ + if(!inLayer){ + if(container != NULL) container->layerMouseReleaseEvent(event); + return; + } +// if(press) sendEvent(mouseGrabber, event); + press = false; + inLayer = false; + QGraphicsScene::mouseReleaseEvent(event); +} + +bool PaintArea::save(SaveType type, const QString &path){ + if(path == "") { + return false; + } + for(auto& layer: layers){ + layer->prepareSave(); + } + QRectF bound; + for(auto& layer: layers){ + bound = bound.united(layer->boundingRect()); + } + + if(bound == QRectF(0, 0, 0, 0)) + return false; + + cv::Mat ans(bound.height(), bound.width(), CV_8UC4); + for(int i=0; i 32700 ? 32700 : bound.height() - i; + QRect temp_rect(bound.left(), bound.top()+i, bound.width(), height); + QImage image(bound.width(), height, QImage::Format_ARGB32); + // image.fill(Qt::transparent); + QPainter painter(&image); + render(&painter, QRectF(QPointF(0, 0), image.size()), temp_rect); + cv::Mat temp_mat = ImageHelper::QImage2Mat(image); + temp_mat.copyTo(ans(cv::Rect(0, i, bound.width(), height))); + } + if(type == ClipBoard){ + QClipboard *clip=QApplication::clipboard(); + clip->setImage(ImageHelper::Mat2QImage(ans)); + } + else{ + cv::imwrite(path.toLocal8Bit().toStdString(), ans); + History_data::save_type saveType = History_data::Editable; + if(type == Persist) saveType = History_data::Persist; + History::instance()->log(saveType, path); + } + for(auto& layer: layers){ + layer->endSave(); + } + return true; +} + +void PaintArea::setEraseEnable(bool enable){ + for(auto iter=layers.begin(); iter!=layers.end(); iter++){ + iter.value()->setErase(enable); + } +} + +void PaintArea::setEnable(bool enable){ + for(auto iter=layers.begin(); iter!=layers.end(); iter++){ + iter.value()->setEnable(enable); + } +} + +void PaintArea::addLayer(LayerBase *layer){ + layer->setParentItem(rootLayer); + layer->setZValue(layer->getZValue()); +// addItem(layer); + LayerManager::addLayer(layer); +} + +LayerBase* PaintArea::removeLayer(const QString &name){ + LayerBase* layer = LayerManager::removeLayer(name); + if(layer != NULL){ + removeItem(layer); + layer->deleteLater(); + } + return layer; +} + +bool PaintArea::hasFocus(LayerBase *layer){ + return LayerManager::hasFocus(layer); +} + +void PaintArea::requestFocus(LayerBase *layer){ + LayerManager::changeFocusLayer(layer); +} + +void PaintArea::setContainer(LayerContainer *container){ + this->container = container; +} + +void PaintArea::setImage(const QImage& image){ + setSceneRect(0, 0, image.width(), image.height()); + this->image = image; + imageValid = true; + for(LayerBase* layer : layers){ + layer->onImageSet(); + } + update(); +} + +void PaintArea::reset(){ + this->image = QImage(); + this->modifiedImage = QImage(); + this->modified = false; + imageValid = false; + this->container = NULL; + inLayer = false; + focusLayer = NULL; + for(LayerBase* layer : layers){ + layer->reset(); + } +} + +QGraphicsItem* PaintArea::getRootLayer(){ + return rootLayer; +} + +void PaintArea::removeThis(LayerBase *layer){ + removeLayer(layer->getName()); +} diff --git a/GraphicsScene/paintarea.h b/GraphicsScene/paintarea.h new file mode 100644 index 0000000..047f8cd --- /dev/null +++ b/GraphicsScene/paintarea.h @@ -0,0 +1,37 @@ +#ifndef PAINTAREA_H +#define PAINTAREA_H +#include +#include "ilayercontrol.h" +#include "layermanager.h" +#include +#include "Container/layercontainer.h" +#include "Layer/rootlayer.h" + +class PaintArea : public QGraphicsScene, public ILayerControl, public LayerManager +{ +public: + PaintArea(QWidget* parent=nullptr); + bool save(SaveType type, const QString &path = "") override; + void setEraseEnable(bool enable) override; + void setEnable(bool enable) override; + bool hasFocus(LayerBase *layer) override; + void requestFocus(LayerBase *layer) override; + void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; + void mousePressEvent(QGraphicsSceneMouseEvent *event) override; + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; + void addLayer(LayerBase *layer) override; + LayerBase* removeLayer(const QString &name) override; + void removeThis(LayerBase *layer) override; + void setContainer(LayerContainer* container); + void setImage(const QImage& image); + void reset(); + QGraphicsItem* getRootLayer(); +private: + LayerContainer* container; + bool inLayer; + bool press; + QGraphicsItem* mouseGrabber; + RootLayer* rootLayer; +}; + +#endif // PAINTAREA_H diff --git a/Helper/Serialize.h b/Helper/Serialize.h index fbf8b84..d14f8ba 100644 --- a/Helper/Serialize.h +++ b/Helper/Serialize.h @@ -1,7 +1,7 @@ #ifndef SERIALIZE_H #define SERIALIZE_H #include -#include +#include "../Base/Serializable.h" #include #include #include diff --git a/Helper/common.h b/Helper/common.h index adbafa4..ce6d621 100644 --- a/Helper/common.h +++ b/Helper/common.h @@ -5,8 +5,8 @@ #include #include #include -#include "Manager/WindowManager.h" -#include "Manager/config.h" +#include "../Manager/WindowManager.h" +#include "../Manager/config.h" #include #include diff --git a/Helper/debug.cpp b/Helper/debug.cpp index 35d4412..7085fbe 100644 --- a/Helper/debug.cpp +++ b/Helper/debug.cpp @@ -58,3 +58,26 @@ void Debug::endTimer() { qint64 Debug::getTime() { return QDateTime::currentMSecsSinceEpoch(); } + +QString Debug::backtrace() +{ + HANDLE process = GetCurrentProcess(); + SymInitialize(process, NULL, TRUE); + + void *stack[100]; + WORD frames = CaptureStackBackTrace(0, 100, stack, NULL); + + SYMBOL_INFO *symbol = (SYMBOL_INFO *)calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1); + symbol->MaxNameLen = 255; + symbol->SizeOfStruct = sizeof(SYMBOL_INFO); + + QString result; + for (int i = 0; i < frames; i++) { + SymFromAddr(process, (DWORD64)(stack[i]), 0, symbol); + result += symbol->Name; + result += '\n'; + } + + free(symbol); + return result; +} diff --git a/Helper/debug.h b/Helper/debug.h index 60f0487..879ae4d 100644 --- a/Helper/debug.h +++ b/Helper/debug.h @@ -4,6 +4,10 @@ #include #include #include +#include +#include + +#pragma comment(lib, "Dbghelp.lib") class Debug { public: @@ -13,6 +17,7 @@ class Debug { static void beginTimer(QString name); static void endTimer(); static qint64 getTime(); + static QString backtrace(); private: struct TimerElement { QString name; diff --git a/Helper/log.cpp b/Helper/log.cpp index ebe8f02..0a29dea 100644 --- a/Helper/log.cpp +++ b/Helper/log.cpp @@ -1,6 +1,7 @@ #include "log.h" #include +#include "debug.h" QFile *gFileLog = NULL; @@ -21,6 +22,9 @@ void log(QtMsgType type, const QMessageLogContext &context, const QString &msg) msgText = msgText.arg(msgHead[type]).arg(context.file).arg(context.line).arg(context.function).arg(msg.toStdString().c_str()).arg(current_date_time); // gFileLog->write(msgText.toLocal8Bit(), msgText.length()); tWrite << msgText; + if(type == 1 || type == 2 || type == 3){ + tWrite << Debug::backtrace(); + } }else{ // fprintf(stderr, "%s | %s | %s:%u, %s | %s\n", msgHead[type], current_date_time.toLocal8Bit().constData(), context.file, context.line, context.function, localMsg.constData()); } diff --git a/Helper/math.h b/Helper/math.h index 4bff561..775eec0 100644 --- a/Helper/math.h +++ b/Helper/math.h @@ -3,7 +3,7 @@ #include #include #include -#include "Helper/common.h" +#include "common.h" using namespace std; class Math { diff --git a/Helper/mstring.cpp b/Helper/mstring.cpp index 183bd85..5455dde 100644 --- a/Helper/mstring.cpp +++ b/Helper/mstring.cpp @@ -1,6 +1,6 @@ #include "mstring.h" #include -#include "Manager/config.h" +#include "../Manager/config.h" #include #include "debug.h" @@ -14,7 +14,7 @@ QList MString::loading_list = QList(); /* * xml格式可以直接看:/Languages/Config/chinese.xml */ -void MString::load_from_file(QString path) { +void MString::load_from_file(const QString& path) { strings.clear(); QString language; int index = Config::getConfig(Config::language); @@ -66,7 +66,8 @@ void MString::load_from_file(QString path) { * 可以不加括号,但是不能只写一半括号 * string的id不能重复,建议通过https://www.random.org/strings/等随机字符串生成网站获得 */ -QString MString::search(QString id) { +QString MString::search(const QString& id) { + if(id == "") return id; QString id_name = ""; int end_index = 0; if(id[0] == "{") { diff --git a/Helper/mstring.h b/Helper/mstring.h index 8810760..4bfe51b 100644 --- a/Helper/mstring.h +++ b/Helper/mstring.h @@ -7,8 +7,8 @@ class MString { public: MString(); - static void load_from_file(QString path); - static QString search(QString id); + static void load_from_file(const QString& path); + static QString search(const QString& id); private: static QHash strings; static QList loading_list; diff --git a/Manager/Data/UpdateData.h b/Manager/Data/UpdateData.h index fe17e0a..115c96e 100644 --- a/Manager/Data/UpdateData.h +++ b/Manager/Data/UpdateData.h @@ -1,6 +1,6 @@ #ifndef UPDATE_DATA_H #define UPDATE_DATA_H -#include "Base/Serializable.h" +#include "../../Base/Serializable.h" #include #include diff --git a/Manager/Data/uiglobalparser.cpp b/Manager/Data/uiglobalparser.cpp index c2f6304..a36198a 100644 --- a/Manager/Data/uiglobalparser.cpp +++ b/Manager/Data/uiglobalparser.cpp @@ -27,15 +27,15 @@ void UIGlobalParser::deserialized(QJsonObject *json) { } var = parse(COLOR, "background_color", &pencilObject, success); if(success) { - pencilData.back_color = var.value(); + pencilData.backColor = var.value(); } var = parse(CAP_STYLE, "cap_style", &pencilObject, success); if(success) { - pencilData.cap_style = var.value(); + pencilData.capStyle = var.value(); } var = parse(JOIN_STYLE, "join_style", &pencilObject, success); if(success) { - pencilData.join_style = var.value(); + pencilData.joinStyle = var.value(); } } @@ -52,15 +52,15 @@ void UIGlobalParser::deserialized(QJsonObject *json) { } var = parse(COLOR, "background_color", &highlighterObject, success); if(success) { - highlighterData.back_color = var.value(); + highlighterData.backColor = var.value(); } var = parse(CAP_STYLE, "cap_style", &highlighterObject, success); if(success) { - highlighterData.cap_style = var.value(); + highlighterData.capStyle = var.value(); } var = parse(JOIN_STYLE, "join_style", &highlighterObject, success); if(success) { - highlighterData.join_style = var.value(); + highlighterData.joinStyle = var.value(); } } diff --git a/Manager/Data/uiglobalparser.h b/Manager/Data/uiglobalparser.h index 6028e84..80404ef 100644 --- a/Manager/Data/uiglobalparser.h +++ b/Manager/Data/uiglobalparser.h @@ -1,9 +1,9 @@ #ifndef UIGLOBALPARSER_H #define UIGLOBALPARSER_H -#include "Base/Serializable.h" -#include "Paint/Data/paint_data.h" +#include "../../Base/Serializable.h" +#include "../../GraphicsScene/Widgets/PaintData.h" #include -#include "Paint/Data/fontdata.h" +#include "../../GraphicsScene/Widgets/FontData.h" /** * @brief 主题global.json的解析类 diff --git a/Manager/Data/uiparser.h b/Manager/Data/uiparser.h index 287df94..72b3dd4 100644 --- a/Manager/Data/uiparser.h +++ b/Manager/Data/uiparser.h @@ -1,6 +1,6 @@ #ifndef UIPARSER_H #define UIPARSER_H -#include "Base/Serializable.h" +#include "../../Base/Serializable.h" #include class UIParser : public Serializable { diff --git a/Manager/Data/update_dialog.cpp b/Manager/Data/update_dialog.cpp index 9c7fc82..824031f 100644 --- a/Manager/Data/update_dialog.cpp +++ b/Manager/Data/update_dialog.cpp @@ -3,8 +3,8 @@ #include #include #include -#include "Helper/debug.h" -#include "Manager/config.h" +#include "../../Helper/debug.h" +#include "../config.h" #include #include #include "Reply_timeout.h" diff --git a/Manager/Data/updatedownloader.cpp b/Manager/Data/updatedownloader.cpp index d2d4f2c..33101d8 100644 --- a/Manager/Data/updatedownloader.cpp +++ b/Manager/Data/updatedownloader.cpp @@ -1,8 +1,8 @@ #include "updatedownloader.h" #include -#include "Helper/debug.h" +#include "../../Helper/debug.h" #include -#include "Manager/config.h" +#include "../../Manager/config.h" #include "JlCompress.h" diff --git a/Manager/KeyManager.cpp b/Manager/KeyManager.cpp index 4f67063..71a9856 100644 --- a/Manager/KeyManager.cpp +++ b/Manager/KeyManager.cpp @@ -1,14 +1,14 @@ #include "KeyManager.h" #include #include "WindowManager.h" -#include "Helper/debug.h" +#include "../Helper/debug.h" #include #include #include #include "update.h" #define WIN32_LEAN_AND_MEAN #include -#include "MainFilter.h" +#include "../MainFilter.h" #include "hook.h" #include diff --git a/Manager/KeyManager.h b/Manager/KeyManager.h index 9d6aaa7..9e50612 100644 --- a/Manager/KeyManager.h +++ b/Manager/KeyManager.h @@ -4,12 +4,12 @@ #include #include #include -#include "Helper/debug.h" -#include "Helper/EnumReflect.h" +#include "../Helper/debug.h" +#include "../Helper/EnumReflect.h" #include "IKeyListener.h" #include "QAbstractNativeEventFilter" #include -#include "Helper/Template.h" +#include "../Helper/Template.h" #include class KeyManager { diff --git a/Manager/WindowManager.cpp b/Manager/WindowManager.cpp index b3824b3..e32cc15 100644 --- a/Manager/WindowManager.cpp +++ b/Manager/WindowManager.cpp @@ -1,11 +1,11 @@ #include "WindowManager.h" #include -#include "Helper/debug.h" +#include "../Helper/debug.h" #include "config.h" #include #include #include "KeyManager.h" -#include "MainFilter.h" +#include "../MainFilter.h" QMap WindowManager::windowList = QMap(); diff --git a/Manager/WindowManager.h b/Manager/WindowManager.h index f54f1e9..2678b28 100644 --- a/Manager/WindowManager.h +++ b/Manager/WindowManager.h @@ -3,7 +3,7 @@ #include #include #include -#include "Base/WindowBase.h" +#include "../Base/WindowBase.h" #include #include diff --git a/Manager/config.cpp b/Manager/config.cpp index d4f37aa..4cef8bd 100644 --- a/Manager/config.cpp +++ b/Manager/config.cpp @@ -5,10 +5,10 @@ #include #include #include -#include "Helper/Serialize.h" -#include "Helper/mstring.h" +#include "../Helper/Serialize.h" +#include "../Helper/mstring.h" #include -#include "Helper/debug.h" +#include "../Helper/debug.h" #include "update.h" DEFINE_STRING(Config); diff --git a/Manager/config.h b/Manager/config.h index 14e8a43..d196dd4 100644 --- a/Manager/config.h +++ b/Manager/config.h @@ -2,8 +2,8 @@ #define CONFIG_H #include #include -#include "Base/Serializable.h" -#include "Helper/EnumReflect.h" +#include "../Base/Serializable.h" +#include "../Helper/EnumReflect.h" #include #include #include diff --git a/Manager/uimanager.cpp b/Manager/uimanager.cpp index c8ad11a..8072bcf 100644 --- a/Manager/uimanager.cpp +++ b/Manager/uimanager.cpp @@ -1,12 +1,12 @@ #include "uimanager.h" #include #include -#include "Helper/common.h" +#include "../Helper/common.h" #include "config.h" -#include "Helper/mstring.h" +#include "../Helper/mstring.h" #include -#include "Manager/Data/uiparser.h" -#include "Manager/Data/uiglobalparser.h" +#include "Data/uiparser.h" +#include "Data/uiglobalparser.h" UIManager* UIManager::_instance = nullptr; diff --git a/Manager/uimanager.h b/Manager/uimanager.h index 9d2f2cd..b0cda3d 100644 --- a/Manager/uimanager.h +++ b/Manager/uimanager.h @@ -1,8 +1,8 @@ #ifndef UIMANAGER_H #define UIMANAGER_H #include -#include "Helper/Serialize.h" -#include "Manager/Data/uiglobalparser.h" +#include "../Helper/Serialize.h" +#include "Data/uiglobalparser.h" class UIManager : Serializable { public: diff --git a/Manager/update.cpp b/Manager/update.cpp index 0c407f9..92c266f 100644 --- a/Manager/update.cpp +++ b/Manager/update.cpp @@ -2,15 +2,15 @@ #include #include #include -#include "Helper/Serialize.h" -#include "Helper/debug.h" +#include "../Helper/Serialize.h" +#include "../Helper/debug.h" #include "config.h" #include "Data/Reply_timeout.h" #include #include #include "KeyManager.h" #include "WindowManager.h" -#include "Paint/Widgets/history.h" +#include "../Paint/Widgets/history.h" Update::Update() { newest_data = UpdateData(); diff --git a/Manager/update.h b/Manager/update.h index 24e912f..68bdbca 100644 --- a/Manager/update.h +++ b/Manager/update.h @@ -1,11 +1,11 @@ #ifndef UPDATE_H #define UPDATE_H -#include "Base/Serializable.h" +#include "../Base/Serializable.h" #include "Data/UpdateData.h" #include "Data/update_dialog.h" #include #include -#include "Helper/common.h" +#include "../Helper/common.h" class Update : public QWidget, public Serializable { diff --git a/Paint/Widgets/Layers/LayerItems/picitem.cpp b/Paint/Widgets/Layers/LayerItems/picitem.cpp index d081f5b..6ea0768 100644 --- a/Paint/Widgets/Layers/LayerItems/picitem.cpp +++ b/Paint/Widgets/Layers/LayerItems/picitem.cpp @@ -16,7 +16,7 @@ void PicItem::setPix(const QPixmap &pix){ } void PicItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ - painter->drawPixmap(mask.topLeft(), mask_pix, mask); + painter->drawPixmap(bound.topLeft(), mask_pix, bound); } void PicItem::reset(){ @@ -25,6 +25,7 @@ void PicItem::reset(){ } void PicItem::setMask(QRectF mask){ + prepareGeometryChange(); this->mask = mask; } diff --git a/Paint/Widgets/Layers/arrowlayer.h b/Paint/Widgets/Layers/arrowlayer.h index 18721af..3aa0656 100644 --- a/Paint/Widgets/Layers/arrowlayer.h +++ b/Paint/Widgets/Layers/arrowlayer.h @@ -2,7 +2,7 @@ #define ARROWLAYER_H #include #include "baselayer.h" -#include "Paint/Widgets/Layers/LayerItems/expandbutton.h" +#include "LayerItems/expandbutton.h" #include class ArrowLayer : public QGraphicsObject, public BaseLayer { diff --git a/Paint/Widgets/history.cpp b/Paint/Widgets/history.cpp index 9c18a2c..29e5295 100644 --- a/Paint/Widgets/history.cpp +++ b/Paint/Widgets/history.cpp @@ -2,9 +2,9 @@ #include #include #include -#include "Helper/debug.h" +#include "../../Helper/debug.h" #include -#include "Manager/config.h" +#include "../../Manager/config.h" #include History::History() diff --git a/Paint/Widgets/history.h b/Paint/Widgets/history.h index ff9d448..f102bc7 100644 --- a/Paint/Widgets/history.h +++ b/Paint/Widgets/history.h @@ -1,6 +1,6 @@ #ifndef HISTORY_H #define HISTORY_H -#include "Paint/Data/History_data.h" +#include "../Data/History_data.h" #include #include diff --git a/Paint/Widgets/style_manager.cpp b/Paint/Widgets/style_manager.cpp index 7900239..b13dc69 100644 --- a/Paint/Widgets/style_manager.cpp +++ b/Paint/Widgets/style_manager.cpp @@ -1,5 +1,5 @@ #include "style_manager.h" -#include "Manager/uimanager.h" +#include "../../Manager/uimanager.h" Style_manager* Style_manager::_instance = NULL; @@ -39,7 +39,7 @@ void Style_manager::change_color(QColor color) { } void Style_manager::change_back_color(QColor color) { - now_data.back_color = color; + now_data.backColor = color; is_change = true; } @@ -49,12 +49,12 @@ void Style_manager::change_width(double width) { } void Style_manager::change_cap_style(Qt::PenCapStyle style) { - now_data.cap_style = style; + now_data.capStyle = style; is_change = true; } void Style_manager::change_join_style(Qt::PenJoinStyle style) { - now_data.join_style = style; + now_data.joinStyle = style; is_change = true; } @@ -63,10 +63,10 @@ void Style_manager::change_pen(PaintData data) { change_color(data.color); if(now_data.width != data.width) change_width(data.width); - if(now_data.cap_style != data.cap_style) - change_cap_style(data.cap_style); - if(now_data.join_style != data.join_style) - change_join_style(data.join_style); + if(now_data.capStyle != data.capStyle) + change_cap_style(data.capStyle); + if(now_data.joinStyle != data.joinStyle) + change_join_style(data.joinStyle); } PaintData* Style_manager::get() { diff --git a/Paint/Widgets/style_manager.h b/Paint/Widgets/style_manager.h index 4e7fb92..8d55d91 100644 --- a/Paint/Widgets/style_manager.h +++ b/Paint/Widgets/style_manager.h @@ -1,7 +1,7 @@ #ifndef STYLE_MANAGER_H #define STYLE_MANAGER_H -#include "Helper/plist.h" -#include "Paint/Data/paint_data.h" +#include "../../Helper/plist.h" +#include "../../GraphicsScene/Widgets/PaintData.h" #include class Style_manager { diff --git a/Resource/Languages/chinese.xml b/Resource/Languages/chinese.xml index 05325a8..11cee67 100644 --- a/Resource/Languages/chinese.xml +++ b/Resource/Languages/chinese.xml @@ -129,4 +129,5 @@ + diff --git a/Style_widget/bubbletipswidget.cpp b/Style_widget/bubbletipswidget.cpp index 7648708..adab88e 100644 --- a/Style_widget/bubbletipswidget.cpp +++ b/Style_widget/bubbletipswidget.cpp @@ -2,7 +2,7 @@ #include "ui_bubbletipswidget.h" #include #include -#include "Helper/mstring.h" +#include "../Helper/mstring.h" BubbleTipsWidget::BubbleTipsWidget(QWidget *parent) : QWidget(parent) diff --git a/Style_widget/colorwidget.cpp b/Style_widget/colorwidget.cpp index 881ce7a..21680c7 100644 --- a/Style_widget/colorwidget.cpp +++ b/Style_widget/colorwidget.cpp @@ -2,9 +2,9 @@ #include "ui_ColorWidget.h" #include #include -#include "Paint/Widgets/style_manager.h" +#include "../Paint/Widgets/style_manager.h" #include -#include "Helper/mstring.h" +#include "../Helper/mstring.h" #include #include @@ -32,6 +32,7 @@ ColorWidget::ColorWidget(QWidget* parent) : QWidget(parent), ui(new Ui::ColorWid this->default_color.setRgb(r, g, b); ui->current->setStyleSheet(QString("background-color: rgba(%1,%2,%3, 1)").arg(r).arg(g).arg(b)); Style_manager::instance()->change_color(default_color); + emit colorChange(default_color); } }); } diff --git a/Style_widget/colorwidget.h b/Style_widget/colorwidget.h index 6301532..7d67893 100644 --- a/Style_widget/colorwidget.h +++ b/Style_widget/colorwidget.h @@ -18,6 +18,8 @@ class ColorWidget : public QWidget { ~ColorWidget(); void setCurrentStyle(QColor color); void paintEvent(QPaintEvent *event) override; +signals: + void colorChange(const QColor& color); private slots: void onDefaultClick(); diff --git a/Style_widget/spacer.cpp b/Style_widget/spacer.cpp index 1bef918..6db9bf2 100644 --- a/Style_widget/spacer.cpp +++ b/Style_widget/spacer.cpp @@ -1,10 +1,10 @@ #include "spacer.h" #include #include -#include "Helper/mstring.h" +#include "../Helper/mstring.h" #include #include -#include "Helper/imagehelper.h" +#include "../Helper/imagehelper.h" Spacer::Spacer() { diff --git a/Style_widget/spacer.h b/Style_widget/spacer.h index 7d0bdc8..6275a3e 100644 --- a/Style_widget/spacer.h +++ b/Style_widget/spacer.h @@ -4,7 +4,7 @@ #include #include #include -#include "Helper/plist.h" +#include "../Helper/plist.h" class Spacer : public QWidget { Q_OBJECT diff --git a/Style_widget/titlebar.cpp b/Style_widget/titlebar.cpp index 31755ed..81b40a8 100644 --- a/Style_widget/titlebar.cpp +++ b/Style_widget/titlebar.cpp @@ -4,7 +4,7 @@ #include #include #include -#include "Helper/imagehelper.h" +#include "../Helper/imagehelper.h" Titlebar::Titlebar(QWidget* parent) : QWidget(parent) { diff --git a/Style_widget/tray.cpp b/Style_widget/tray.cpp index 4ae1db2..bfc5473 100644 --- a/Style_widget/tray.cpp +++ b/Style_widget/tray.cpp @@ -1,7 +1,7 @@ #include "tray.h" -#include "Manager/WindowManager.h" +#include "../Manager/WindowManager.h" #include -#include "Helper/common.h" +#include "../Helper/common.h" Tray::Tray() { diff --git a/capture.pro b/capture.pro index 37888dd..9c1ba28 100644 --- a/capture.pro +++ b/capture.pro @@ -18,6 +18,23 @@ QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO QMAKE_LFLAGS_RELEASE = $$QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO SOURCES += \ + GraphicsScene/Container/geolayercontainer.cpp \ + GraphicsScene/Container/layercontainer.cpp \ + GraphicsScene/Container/textlayercontainer.cpp \ + GraphicsScene/Layer/arrowlayer.cpp \ + GraphicsScene/Layer/layerbase.cpp \ + GraphicsScene/Layer/piclayer.cpp \ + GraphicsScene/Layer/rectlayer.cpp \ + GraphicsScene/Layer/rootlayer.cpp \ + GraphicsScene/Layer/textlayer.cpp \ + GraphicsScene/Widgets/attributetoolbar.cpp \ + GraphicsScene/Widgets/expandbutton.cpp \ + GraphicsScene/Widgets/layertoolbar.cpp \ + GraphicsScene/Widgets/scrollitem.cpp \ + GraphicsScene/Widgets/textitem.cpp \ + GraphicsScene/ilayercontrol.cpp \ + GraphicsScene/layermanager.cpp \ + GraphicsScene/paintarea.cpp \ Helper/debug.cpp \ Helper/imagehelper.cpp \ Helper/log.cpp \ @@ -109,6 +126,25 @@ HEADERS += \ Base/Serializable.h \ Base/TabBase.h \ Base/WindowBase.h \ + GraphicsScene/Container/geolayercontainer.h \ + GraphicsScene/Container/layercontainer.h \ + GraphicsScene/Container/textlayercontainer.h \ + GraphicsScene/Layer/arrowlayer.h \ + GraphicsScene/Layer/layerbase.h \ + GraphicsScene/Layer/piclayer.h \ + GraphicsScene/Layer/rectlayer.h \ + GraphicsScene/Layer/rootlayer.h \ + GraphicsScene/Layer/textlayer.h \ + GraphicsScene/Widgets/FontData.h \ + GraphicsScene/Widgets/PaintData.h \ + GraphicsScene/Widgets/attributetoolbar.h \ + GraphicsScene/Widgets/expandbutton.h \ + GraphicsScene/Widgets/layertoolbar.h \ + GraphicsScene/Widgets/scrollitem.h \ + GraphicsScene/Widgets/textitem.h \ + GraphicsScene/ilayercontrol.h \ + GraphicsScene/layermanager.h \ + GraphicsScene/paintarea.h \ Helper/EnumReflect.h \ Helper/GraphicsViewPatch.h \ Helper/PaintHelper.h \ diff --git a/new_capture/Widgets/attributetoolbar.h b/new_capture/Widgets/attributetoolbar.h index e4c10af..d6fa38d 100644 --- a/new_capture/Widgets/attributetoolbar.h +++ b/new_capture/Widgets/attributetoolbar.h @@ -2,6 +2,7 @@ #define ATTRIBUTETOOLBAR_H #include #include +#include class AttributeToolbar : public QWidget { From fdae97f10f4d8014b6db47f3480db6d802d4f79a Mon Sep 17 00:00:00 2001 From: xinhecuican <2686462757@qq.com> Date: Mon, 4 Dec 2023 19:23:41 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E9=87=8D=E5=86=99=E7=BB=98=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GraphicsScene/Container/geolayercontainer.cpp | 53 ++++-- GraphicsScene/Container/geolayercontainer.h | 4 + .../Container/paintlayercontainer.cpp | 109 ++++++++++++ GraphicsScene/Container/paintlayercontainer.h | 26 +++ GraphicsScene/Layer/arrowlayer.cpp | 5 + GraphicsScene/Layer/arrowlayer.h | 1 + GraphicsScene/Layer/paintlayer.cpp | 155 ++++++++++++++++++ GraphicsScene/Layer/paintlayer.h | 51 ++++++ GraphicsScene/Layer/piclayer.cpp | 4 + GraphicsScene/Layer/piclayer.h | 1 + GraphicsScene/Layer/rectlayer.cpp | 8 + GraphicsScene/Layer/rectlayer.h | 1 + GraphicsScene/paintarea.cpp | 11 +- capture.pro | 4 + 14 files changed, 416 insertions(+), 17 deletions(-) create mode 100644 GraphicsScene/Container/paintlayercontainer.cpp create mode 100644 GraphicsScene/Container/paintlayercontainer.h create mode 100644 GraphicsScene/Layer/paintlayer.cpp create mode 100644 GraphicsScene/Layer/paintlayer.h diff --git a/GraphicsScene/Container/geolayercontainer.cpp b/GraphicsScene/Container/geolayercontainer.cpp index 4b2a60e..a8dc6ca 100644 --- a/GraphicsScene/Container/geolayercontainer.cpp +++ b/GraphicsScene/Container/geolayercontainer.cpp @@ -5,8 +5,6 @@ #include #include "../../Manager/uimanager.h" #include "../../Helper/math.h" -#include "../Layer/rectlayer.h" -#include "../Layer/arrowlayer.h" #include "../paintarea.h" #include @@ -21,6 +19,7 @@ GeoLayerContainer::GeoLayerContainer(PaintArea* area) : } QWidget* GeoLayerContainer::onValid(QWidget* widgetParent){ + area->setEnable(true); if(widget == NULL){ widget = new QWidget(widgetParent); QHBoxLayout* layout = new QHBoxLayout(); @@ -47,7 +46,7 @@ QWidget* GeoLayerContainer::onValid(QWidget* widgetParent){ QToolButton* arrowButton = new QToolButton(widgetParent); arrowButton->setObjectName("arrowButton"); arrowButton->setIcon(ImageHelper::getIcon("paint_arrow")); - arrowButton->setToolTip("{D7HSBXWTLj}箭头"); + arrowButton->setToolTip(MString::search("{D7HSBXWTLj}箭头")); arrowButton->setCheckable(true); shapeGroup->addButton(arrowButton, 1); ColorWidget* colorWidget = new ColorWidget(widgetParent); @@ -81,10 +80,33 @@ QWidget* GeoLayerContainer::onValid(QWidget* widgetParent){ void GeoLayerContainer::layerMousePressEvent(QGraphicsSceneMouseEvent *event){ beginPoint = event->scenePos(); + switch (geoType) { + case RECT: { + QRectF rect = Math::buildRect(beginPoint, beginPoint + QPointF(1, 1)); + rectLayer = new RectLayer(rect, "rect" + QString::number(rectId), area, area->getRootLayer(), false); + rectLayer->setEnable(false); + break; + } + case ARROW: { + arrowLayer = new ArrowLayer(beginPoint, beginPoint + QPointF(1, 1), "arrow" + QString::number(arrowId), area, area->getRootLayer()); + arrowLayer->setEnable(false); + break; + } + } } void GeoLayerContainer::layerMouseMoveEvent(QGraphicsSceneMouseEvent *event){ - + switch (geoType) { + case RECT: { + QRectF rect = Math::buildRect(beginPoint, event->scenePos()); + rectLayer->setRect(rect); + break; + } + case ARROW: { + arrowLayer->setEndPoint(event->scenePos()); + break; + } + } } void GeoLayerContainer::layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event){ @@ -92,21 +114,26 @@ void GeoLayerContainer::layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event){ switch (geoType) { case RECT: { QRectF rect = Math::buildRect(beginPoint, endPoint); - if(rect.height() < 10 || rect.width() < 10) return; - RectLayer* layer = new RectLayer(rect, "rect" + QString::number(rectId), area, NULL); + if(rect.height() < 10 || rect.width() < 10) { + rectLayer->deleteLater(); + return; + } rectId++; - layer->setEnable(true); - layer->setEnableScroll(true); - area->addLayer(layer); + rectLayer->setEnable(true); + rectLayer->setEnableResize(true); + rectLayer->setEnableScroll(true); + area->addLayer(rectLayer); break; } case ARROW: { QLineF line(beginPoint, endPoint); - if(line.length() < 10) return; - ArrowLayer* layer = new ArrowLayer(beginPoint, endPoint, "arrow" + QString::number(arrowId), area, NULL); + if(line.length() < 10) { + arrowLayer->deleteLater(); + return; + } arrowId++; - layer->setEnable(true); - area->addLayer(layer); + arrowLayer->setEnable(true); + area->addLayer(arrowLayer); break; } } diff --git a/GraphicsScene/Container/geolayercontainer.h b/GraphicsScene/Container/geolayercontainer.h index 9084c56..a54d2d6 100644 --- a/GraphicsScene/Container/geolayercontainer.h +++ b/GraphicsScene/Container/geolayercontainer.h @@ -2,6 +2,8 @@ #define GEOLAYERCONTAINER_H #include "layercontainer.h" #include "../Widgets/PaintData.h" +#include "../Layer/rectlayer.h" +#include "../Layer/arrowlayer.h" class GeoLayerContainer : public LayerContainer { @@ -20,6 +22,8 @@ class GeoLayerContainer : public LayerContainer PaintData arrowPaintData; int rectId; int arrowId; + RectLayer* rectLayer; + ArrowLayer* arrowLayer; }; #endif // GEOLAYERCONTAINER_H diff --git a/GraphicsScene/Container/paintlayercontainer.cpp b/GraphicsScene/Container/paintlayercontainer.cpp new file mode 100644 index 0000000..4830613 --- /dev/null +++ b/GraphicsScene/Container/paintlayercontainer.cpp @@ -0,0 +1,109 @@ +#include "paintlayercontainer.h" +#include +#include "../../Helper/imagehelper.h" +#include "../../Style_widget/colorwidget.h" +#include +#include "../../Manager/uimanager.h" +#include "../../Helper/math.h" +#include "../paintarea.h" +#include + +PaintLayerContainer::PaintLayerContainer(PaintArea* area) : + LayerContainer(area), + type(0), + paintId(0) +{ + pencilData = UIManager::instance()->getPencilData(); + highlighterData = UIManager::instance()->getHighlighterData(); +} + +QWidget* PaintLayerContainer::onValid(QWidget *widgetParent) { + area->setEnable(false); + if(widget == NULL){ + widget = new QWidget(widgetParent); + QHBoxLayout* layout = new QHBoxLayout(); + QButtonGroup* shapeGroup = new QButtonGroup(widgetParent); + shapeGroup->setExclusive(true); + connect(shapeGroup, static_cast(&QButtonGroup::buttonClicked), + this, [=](int id) { + switch(id) { + case 0: type = Pencil; break; + case 1: type = Highlighter; break; + default: + type = id; + qWarning() << "未知形状"; + break; + } + }); + QToolButton* pencilButton = new QToolButton(widgetParent); + pencilButton->setObjectName("pencilButton"); + pencilButton->setToolTip("笔"); + pencilButton->setIcon(ImageHelper::getIcon("pencil")); + pencilButton->setCheckable(true); + pencilButton->setChecked(true); + shapeGroup->addButton(pencilButton, 0); + QToolButton* highlighterButton = new QToolButton(widgetParent); + highlighterButton->setObjectName("highlighterButton"); + highlighterButton->setIcon(ImageHelper::getIcon("highlighter")); + highlighterButton->setToolTip(MString::search("{j54u1kWtCx}荧光笔")); + highlighterButton->setCheckable(true); + shapeGroup->addButton(highlighterButton, 1); + ColorWidget* colorWidget = new ColorWidget(widgetParent); + connect(colorWidget, &ColorWidget::colorChange, this, [=](const QColor& color){ + switch(type){ + case Pencil: pencilData.color = color; break; + case Highlighter: highlighterData.color = color; break; + } + }); + QSpinBox* widthButton = new QSpinBox(widgetParent); + widthButton->setRange(1, 50); + widthButton->setValue(3); + widthButton->setAccelerated(true); + widthButton->setWrapping(true); + widthButton->setKeyboardTracking(true); + connect(widthButton, static_cast(&QSpinBox::valueChanged), this, [=](int value) { + switch(type){ + case Pencil: pencilData.width = value; break; + case Highlighter: highlighterData.width = value; break; + } + }); + + layout->addWidget(pencilButton); + layout->addWidget(highlighterButton); + layout->addWidget(colorWidget); + layout->addWidget(widthButton); + widget->setLayout(layout); + } + return widget; +} + +void PaintLayerContainer::layerMousePressEvent(QGraphicsSceneMouseEvent *event) { + paintLayer = new PaintLayer("line" + QString::number(paintId), area, area->getRootLayer()); + switch(type) { + case Pencil: + paintLayer->setParameter("color", pencilData.color); + paintLayer->setParameter("width", pencilData.width); + break; + case Highlighter: + paintLayer->setParameter("color", highlighterData.color); + paintLayer->setParameter("width", highlighterData.width); + break; + } + paintLayer->setEnable(false); + paintLayer->addPoint(event->scenePos()); + beforeTime = QDateTime::currentMSecsSinceEpoch(); +} + +void PaintLayerContainer::layerMouseMoveEvent(QGraphicsSceneMouseEvent *event) { + qint64 currentTime = QDateTime::currentMSecsSinceEpoch(); + if(currentTime - beforeTime > 30) { + beforeTime = currentTime; + paintLayer->addPoint(event->scenePos()); + } +} + +void PaintLayerContainer::layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event) { + paintLayer->addPoint(event->scenePos()); + paintId++; + area->addLayer(paintLayer); +} diff --git a/GraphicsScene/Container/paintlayercontainer.h b/GraphicsScene/Container/paintlayercontainer.h new file mode 100644 index 0000000..4cee46a --- /dev/null +++ b/GraphicsScene/Container/paintlayercontainer.h @@ -0,0 +1,26 @@ +#ifndef PAINTLAYERCONTAINER_H +#define PAINTLAYERCONTAINER_H +#include "layercontainer.h" +#include "../Widgets/PaintData.h" +#include "../Layer/paintlayer.h" + +class PaintLayerContainer : public LayerContainer +{ +public: + static const int Pencil = 0; + static const int Highlighter = 1; + PaintLayerContainer(PaintArea* area); + void layerMousePressEvent(QGraphicsSceneMouseEvent *event) override; + void layerMouseMoveEvent(QGraphicsSceneMouseEvent *event) override; + void layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; + QWidget * onValid(QWidget *widgetParent) override; +private: + int type; + PaintData pencilData; + PaintData highlighterData; + PaintLayer* paintLayer; + int paintId; + qint64 beforeTime; +}; + +#endif // PAINTLAYERCONTAINER_H diff --git a/GraphicsScene/Layer/arrowlayer.cpp b/GraphicsScene/Layer/arrowlayer.cpp index d1038b6..25a979f 100644 --- a/GraphicsScene/Layer/arrowlayer.cpp +++ b/GraphicsScene/Layer/arrowlayer.cpp @@ -152,3 +152,8 @@ void ArrowLayer::setParameter(const QString &name, const QVariant &var){ void ArrowLayer::reset(){ manager->removeThis(this); } + +void ArrowLayer::setEndPoint(const QPointF &point) { + this->endPt = point; + setLine(beginPt, endPt); +} diff --git a/GraphicsScene/Layer/arrowlayer.h b/GraphicsScene/Layer/arrowlayer.h index 3eda753..895f3f4 100644 --- a/GraphicsScene/Layer/arrowlayer.h +++ b/GraphicsScene/Layer/arrowlayer.h @@ -25,6 +25,7 @@ class ArrowLayer : public LayerBase void setLine(const QPointF& beginPt, const QPointF& endPt); void getFocus() override; void loseFocus() override; + void setEndPoint(const QPointF& point); private slots: void posChangeFunc(ExpandButton::ButtonDirection dir, qreal x, qreal y); diff --git a/GraphicsScene/Layer/paintlayer.cpp b/GraphicsScene/Layer/paintlayer.cpp new file mode 100644 index 0000000..bea0b94 --- /dev/null +++ b/GraphicsScene/Layer/paintlayer.cpp @@ -0,0 +1,155 @@ +#include "paintlayer.h" +#include + +PaintLayer::PaintLayer(const QString& name, + ILayerControl* manager, + QGraphicsItem* parent) : + LayerBase(name, manager, parent) +{ + method = Smooth; +} + +QRectF PaintLayer::boundingRect() const { + return path.boundingRect(); +} + +QPainterPath PaintLayer::shape() const { + return path; +} + +void PaintLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + painter->save(); + painter->setRenderHint(QPainter::Antialiasing, true); + painter->drawPath(path); + painter->restore(); +} + +void PaintLayer::reset(){ + manager->removeThis(this); +} + +void PaintLayer::mousePressEvent(QGraphicsSceneMouseEvent *event){ + +} + +void PaintLayer::addPoint(const QPointF& point){ + if(points.size() > 0){ + QLineF line(point, points.last()); + if(line.length() < 2) return; + } + points.append(point); + switch (method) { + case Smooth: + path = SmoothCurveGenerator::generateSmoothCurve(points); + break; + case PaintPath: + if(points.size() == 1){ + path.moveTo(points[0]); + } + else{ + path.lineTo(points.last()); + } + break; + } + update(); +} + +void PaintLayer::setMethod(PaintMethod method) { + this->method = method; +} + +void PaintLayer::setParameter(const QString &name, const QVariant &var) { + if(name == "color") { + QColor color = var.value(); + pen.setColor(color); + } + if(name == "width") { + pen.setWidth(var.toInt()); + } +} + +void PaintLayer::setEnable(bool enable) { + this->enable = false; +} + + +QPainterPath SmoothCurveGenerator::generateSmoothCurve(QList points, bool closed, double tension, int numberOfSegments) { + QList ps; + + foreach (QPointF p, points) { + ps << p.x() << p.y(); + } + + return SmoothCurveGenerator::generateSmoothCurve(ps, closed, tension, numberOfSegments); +} + +QPainterPath SmoothCurveGenerator::generateSmoothCurve(QList points, bool closed, double tension, int numberOfSegments) { + if(points.size() < 4){ + return QPainterPath(); + } + QList ps(points); // clone array so we don't change the original points + QList result; // generated smooth curve coordinates + double x, y; + double t1x, t2x, t1y, t2y; + double c1, c2, c3, c4; + double st; + + // The algorithm require a previous and next point to the actual point array. + // Check if we will draw closed or open curve. + // If closed, copy end points to beginning and first points to end + // If open, duplicate first points to befinning, end points to end + if (closed) { + ps.prepend(points[points.length() - 1]); + ps.prepend(points[points.length() - 2]); + ps.prepend(points[points.length() - 1]); + ps.prepend(points[points.length() - 2]); + ps.append(points[0]); + ps.append(points[1]); + } else { + ps.prepend(points[1]); // copy 1st point and insert at beginning + ps.prepend(points[0]); + ps.append(points[points.length() - 2]); // copy last point and append + ps.append(points[points.length() - 1]); + } + + // 1. loop goes through point array + // 2. loop goes through each segment between the 2 points + 1e point before and after + for (int i = 2; i < (ps.length() - 4); i += 2) { + // calculate tension vectors + t1x = (ps[i + 2] - ps[i - 2]) * tension; + t2x = (ps[i + 4] - ps[i - 0]) * tension; + t1y = (ps[i + 3] - ps[i - 1]) * tension; + t2y = (ps[i + 5] - ps[i + 1]) * tension; + + for (int t = 0; t <= numberOfSegments; t++) { + // calculate step + st = (double)t / (double)numberOfSegments; + + // calculate cardinals + c1 = 2 * qPow(st, 3) - 3 * qPow(st, 2) + 1; + c2 = -2 * qPow(st, 3) + 3 * qPow(st, 2); + c3 = qPow(st, 3) - 2 * qPow(st, 2) + st; + c4 = qPow(st, 3) - qPow(st, 2); + + // calculate x and y cords with common control vectors + x = c1 * ps[i] + c2 * ps[i + 2] + c3 * t1x + c4 * t2x; + y = c1 * ps[i + 1] + c2 * ps[i + 3] + c3 * t1y + c4 * t2y; + + //store points in array + result << x << y; + } + } + + // 使用的平滑曲线的坐标创建 QPainterPath + QPainterPath path; + path.moveTo(result[0], result[1]); + for (int i = 2; i < result.length() - 2; i += 2) { + path.lineTo(result[i+0], result[i+1]); + } + + if (closed) { + path.closeSubpath(); + } + + return path; +} diff --git a/GraphicsScene/Layer/paintlayer.h b/GraphicsScene/Layer/paintlayer.h new file mode 100644 index 0000000..51406f6 --- /dev/null +++ b/GraphicsScene/Layer/paintlayer.h @@ -0,0 +1,51 @@ +#ifndef PAINTLAYER_H +#define PAINTLAYER_H +#include "layerbase.h" +#include +#include +#include + +class PaintLayer : public LayerBase { +public: + enum PaintMethod{PaintPath, Smooth}; + PaintLayer(const QString& name, + ILayerControl* manager, + QGraphicsItem* parent=nullptr); + void reset() override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; + QRectF boundingRect()const override; + QPainterPath shape()const override; + void mousePressEvent(QGraphicsSceneMouseEvent *event) override; + void addPoint(const QPointF& point); + void setMethod(PaintMethod method); + void setParameter(const QString &name, const QVariant &var) override; + void setEnable(bool enable) override; +private: + QList points; + PaintMethod method; + QPainterPath path; + QPen pen; +}; + +class SmoothCurveGenerator { +public: + /** +* @brief generateSmoothCurve 的重载函数 +*/ + static QPainterPath generateSmoothCurve(QList points, bool closed = false, double tension = 0.5, int numberOfSegments = 16); + +/** +* @brief 使用传入的曲线顶点坐标创建平滑曲线。 +* +* @param points 曲线顶点坐标数组, +* points[i+0] 是第 i 个点的 x 坐标, +* points[i+1] 是第 i 个点的 y 坐标 +* @param closed 曲线是否封闭,默认不封闭 +* @param tension 密集程度,默认为 0.5 +* @param numberOfSegments 平滑曲线 2 个顶点间的线段数,默认为 16 +* @return 平滑曲线的 QPainterPath +*/ + static QPainterPath generateSmoothCurve(QListpoints, bool closed = false, double tension = 0.5, int numberOfSegments = 16); +}; + +#endif // PAINTLAYER_H diff --git a/GraphicsScene/Layer/piclayer.cpp b/GraphicsScene/Layer/piclayer.cpp index 25cbaf3..77e7c8e 100644 --- a/GraphicsScene/Layer/piclayer.cpp +++ b/GraphicsScene/Layer/piclayer.cpp @@ -62,3 +62,7 @@ void PicLayer::endSave(){ void PicLayer::reset(){ mask = QRectF(); } + +void PicLayer::setEnable(bool enable) { + this->enable = enableBound && enable; +} diff --git a/GraphicsScene/Layer/piclayer.h b/GraphicsScene/Layer/piclayer.h index 53fde0b..be46a7f 100644 --- a/GraphicsScene/Layer/piclayer.h +++ b/GraphicsScene/Layer/piclayer.h @@ -15,6 +15,7 @@ class PicLayer : public LayerBase QPainterPath shape() const override; void onImageSet() override; void reset() override; + void setEnable(bool enable) override; private: bool enableBound; RectLayer* rectLayer; diff --git a/GraphicsScene/Layer/rectlayer.cpp b/GraphicsScene/Layer/rectlayer.cpp index cc29e6a..7f3fe77 100644 --- a/GraphicsScene/Layer/rectlayer.cpp +++ b/GraphicsScene/Layer/rectlayer.cpp @@ -254,3 +254,11 @@ void RectLayer::getFocus(){ void RectLayer::loseFocus(){ hideButtons(); } + +void RectLayer::setRect(const QRectF &rect){ + setPos(rect.topLeft()); + this->rect.setWidth(rect.width()); + this->rect.setHeight(rect.height()); + setBounding(this->rect); + update(); +} diff --git a/GraphicsScene/Layer/rectlayer.h b/GraphicsScene/Layer/rectlayer.h index 82388cc..a01608d 100644 --- a/GraphicsScene/Layer/rectlayer.h +++ b/GraphicsScene/Layer/rectlayer.h @@ -35,6 +35,7 @@ class RectLayer : public LayerBase bool contains(const QPointF& point)const override; void setBoundEffect(); void setButtonFocus(bool enable); + void setRect(const QRectF& rect); signals: void sizeChange(); diff --git a/GraphicsScene/paintarea.cpp b/GraphicsScene/paintarea.cpp index a13be4b..fadb0fa 100644 --- a/GraphicsScene/paintarea.cpp +++ b/GraphicsScene/paintarea.cpp @@ -19,11 +19,11 @@ PaintArea::PaintArea(QWidget* parent) : } void PaintArea::mousePressEvent(QGraphicsSceneMouseEvent *event){ + press = true; for(auto& layer: layers){ if((layer->isEnable() || layer->isErase()) && layer->contains(layer->mapFromScene(event->scenePos()))){ // sendEvent(layer, event); inLayer = true; - press = true; mouseGrabber = layer; } } @@ -35,7 +35,7 @@ void PaintArea::mousePressEvent(QGraphicsSceneMouseEvent *event){ void PaintArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event){ QGraphicsScene::mouseMoveEvent(event); - if(!inLayer){ + if(!inLayer && press){ if(container != NULL) container->layerMouseMoveEvent(event); return; } @@ -43,12 +43,15 @@ void PaintArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event){ } void PaintArea::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ - if(!inLayer){ + if(!inLayer && press){ + press = false; if(container != NULL) container->layerMouseReleaseEvent(event); return; } + else{ + press = false; + } // if(press) sendEvent(mouseGrabber, event); - press = false; inLayer = false; QGraphicsScene::mouseReleaseEvent(event); } diff --git a/capture.pro b/capture.pro index 9c1ba28..3a5a3fe 100644 --- a/capture.pro +++ b/capture.pro @@ -20,9 +20,11 @@ QMAKE_LFLAGS_RELEASE = $$QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO SOURCES += \ GraphicsScene/Container/geolayercontainer.cpp \ GraphicsScene/Container/layercontainer.cpp \ + GraphicsScene/Container/paintlayercontainer.cpp \ GraphicsScene/Container/textlayercontainer.cpp \ GraphicsScene/Layer/arrowlayer.cpp \ GraphicsScene/Layer/layerbase.cpp \ + GraphicsScene/Layer/paintlayer.cpp \ GraphicsScene/Layer/piclayer.cpp \ GraphicsScene/Layer/rectlayer.cpp \ GraphicsScene/Layer/rootlayer.cpp \ @@ -128,9 +130,11 @@ HEADERS += \ Base/WindowBase.h \ GraphicsScene/Container/geolayercontainer.h \ GraphicsScene/Container/layercontainer.h \ + GraphicsScene/Container/paintlayercontainer.h \ GraphicsScene/Container/textlayercontainer.h \ GraphicsScene/Layer/arrowlayer.h \ GraphicsScene/Layer/layerbase.h \ + GraphicsScene/Layer/paintlayer.h \ GraphicsScene/Layer/piclayer.h \ GraphicsScene/Layer/rectlayer.h \ GraphicsScene/Layer/rootlayer.h \ From a88c46c68c0cd284cf937e635eff8592194007f2 Mon Sep 17 00:00:00 2001 From: xinhecuican <2686462757@qq.com> Date: Tue, 5 Dec 2023 14:11:14 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E9=A9=AC=E8=B5=9B=E5=85=8B=E9=87=8D?= =?UTF-8?q?=E5=86=99=EF=BC=8C=E4=BD=BF=E7=94=A8opencv=E7=9A=84=E9=AB=98?= =?UTF-8?q?=E6=96=AF=E6=A8=A1=E7=B3=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Container/blurlayercontainer.cpp | 46 ++++++++++++ GraphicsScene/Container/blurlayercontainer.h | 19 +++++ GraphicsScene/Layer/blurlayer.cpp | 75 +++++++++++++++++++ GraphicsScene/Layer/blurlayer.h | 26 +++++++ capture.pro | 4 + 5 files changed, 170 insertions(+) create mode 100644 GraphicsScene/Container/blurlayercontainer.cpp create mode 100644 GraphicsScene/Container/blurlayercontainer.h create mode 100644 GraphicsScene/Layer/blurlayer.cpp create mode 100644 GraphicsScene/Layer/blurlayer.h diff --git a/GraphicsScene/Container/blurlayercontainer.cpp b/GraphicsScene/Container/blurlayercontainer.cpp new file mode 100644 index 0000000..8970862 --- /dev/null +++ b/GraphicsScene/Container/blurlayercontainer.cpp @@ -0,0 +1,46 @@ +#include "blurlayercontainer.h" +#include +#include "../paintarea.h" + +BlurLayerContainer::BlurLayerContainer(PaintArea* area) : + LayerContainer(area), + windowSize(10) +{ + blurLayer = new BlurLayer("blur", area, area->getRootLayer()); + blurLayer->setEnable(false); + area->addLayer(blurLayer); +} + +QWidget* BlurLayerContainer::onValid(QWidget *widgetParent) { + area->setEnable(false); + if(widget == NULL) { + widget = new QWidget(widgetParent); + QHBoxLayout* layout = new QHBoxLayout(); + QSpinBox* mosaicSize = new QSpinBox(widgetParent); + mosaicSize->setRange(2, 30); + mosaicSize->setValue(4); + mosaicSize->setSingleStep(2); + mosaicSize->setAccelerated(true); + mosaicSize->setWrapping(true); + mosaicSize->setKeyboardTracking(true); + connect(mosaicSize, static_cast(&QSpinBox::valueChanged), this, [=](int value) { + windowSize = value; + }); + layout->addWidget(mosaicSize); + widget->setLayout(layout); + } + return widget; +} + +void BlurLayerContainer::layerMousePressEvent(QGraphicsSceneMouseEvent *event) { + blurLayer->setParameter("windowSize", windowSize); + blurLayer->addPoint(event->scenePos().toPoint()); +} + +void BlurLayerContainer::layerMouseMoveEvent(QGraphicsSceneMouseEvent *event) { + blurLayer->addPoint(event->scenePos().toPoint()); +} + +void BlurLayerContainer::layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event) { + blurLayer->addPoint(event->scenePos().toPoint()); +} diff --git a/GraphicsScene/Container/blurlayercontainer.h b/GraphicsScene/Container/blurlayercontainer.h new file mode 100644 index 0000000..6f05f68 --- /dev/null +++ b/GraphicsScene/Container/blurlayercontainer.h @@ -0,0 +1,19 @@ +#ifndef BLURLAYERCONTAINER_H +#define BLURLAYERCONTAINER_H +#include "layercontainer.h" +#include "../Layer/blurlayer.h" + +class BlurLayerContainer : public LayerContainer +{ +public: + BlurLayerContainer(PaintArea* area); + void layerMousePressEvent(QGraphicsSceneMouseEvent *event) override; + void layerMouseMoveEvent(QGraphicsSceneMouseEvent *event) override; + void layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; + QWidget * onValid(QWidget *widgetParent) override; +private: + BlurLayer* blurLayer; + int windowSize; +}; + +#endif // BLURLAYERCONTAINER_H diff --git a/GraphicsScene/Layer/blurlayer.cpp b/GraphicsScene/Layer/blurlayer.cpp new file mode 100644 index 0000000..523ff63 --- /dev/null +++ b/GraphicsScene/Layer/blurlayer.cpp @@ -0,0 +1,75 @@ +#include "blurlayer.h" +#include +#include "../../Helper/imagehelper.h" +#include +using namespace cv; + +BlurLayer::BlurLayer(const QString& name, + ILayerControl* manager, + QGraphicsItem* parent) + : LayerBase(name, manager, parent), + range(4), + windowSize(20) +{ + if(manager->isImageValid()){ + use = QBitArray(manager->getOriginImage().height() * manager->getOriginImage().width()); + } +} + +void BlurLayer::onImageSet() { + use.fill(false); + use.resize(manager->getOriginImage().height() * manager->getOriginImage().width()); +} + +QRectF BlurLayer::boundingRect()const { + return bound; +} + +void BlurLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { +} + +void BlurLayer::addPoint(const QPoint &point) { + auto image = manager->getOriginImage(); + QPoint leftTop = point - QPoint(windowSize, windowSize); + if(leftTop.x() < 0) leftTop.setX(0); + if(leftTop.y() < 0) leftTop.setY(0); + QPoint rightBotttom = point + QPoint(windowSize, windowSize); + if(rightBotttom.x() >= image.width()) rightBotttom.setX(image.width() - 1); + if(rightBotttom.y() >= image.height()) rightBotttom.setY(image.height() - 1); + QRect boundRect(leftTop, rightBotttom); + if(boundRect.width() <= 0 || boundRect.height() <= 0) return; + bound = bound.united(boundRect); + + QImage maskImage = image.copy(boundRect); + Mat maskMat = ImageHelper::QImage2Mat(maskImage); + Mat dst; + cv::GaussianBlur(maskMat, dst, Size(9, 9), 11); + maskImage = ImageHelper::Mat2QImage(dst); + for(int i=leftTop.x(); imodifyImage(QPoint(i, k), maskImage.pixel(i-leftTop.x(),k-leftTop.y())); + } + } + } + update(); +} + +void BlurLayer::reset() { + use.resize(0); +} + +void BlurLayer::setParameter(const QString &name, const QVariant &var) { + if(name == "range") { + range = var.toInt(); + } + if(name == "windowSize") { + windowSize = var.toInt(); + } +} + +void BlurLayer::setEnable(bool enable) { + this->enable = false; +} diff --git a/GraphicsScene/Layer/blurlayer.h b/GraphicsScene/Layer/blurlayer.h new file mode 100644 index 0000000..1241fd9 --- /dev/null +++ b/GraphicsScene/Layer/blurlayer.h @@ -0,0 +1,26 @@ +#ifndef BLURLAYER_H +#define BLURLAYER_H +#include "layerbase.h" +#include + +class BlurLayer : public LayerBase +{ +public: + BlurLayer(const QString& name, + ILayerControl* manager, + QGraphicsItem* parent=nullptr); + void reset() override; + void setParameter(const QString &name, const QVariant &var) override; + QRectF boundingRect()const override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; + void onImageSet() override; + void addPoint(const QPoint& point); + void setEnable(bool enable) override; +private: + QBitArray use; + QRectF bound; + int range; + int windowSize; +}; + +#endif // BLURLAYER_H diff --git a/capture.pro b/capture.pro index 3a5a3fe..3e532f7 100644 --- a/capture.pro +++ b/capture.pro @@ -18,11 +18,13 @@ QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO QMAKE_LFLAGS_RELEASE = $$QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO SOURCES += \ + GraphicsScene/Container/blurlayercontainer.cpp \ GraphicsScene/Container/geolayercontainer.cpp \ GraphicsScene/Container/layercontainer.cpp \ GraphicsScene/Container/paintlayercontainer.cpp \ GraphicsScene/Container/textlayercontainer.cpp \ GraphicsScene/Layer/arrowlayer.cpp \ + GraphicsScene/Layer/blurlayer.cpp \ GraphicsScene/Layer/layerbase.cpp \ GraphicsScene/Layer/paintlayer.cpp \ GraphicsScene/Layer/piclayer.cpp \ @@ -128,11 +130,13 @@ HEADERS += \ Base/Serializable.h \ Base/TabBase.h \ Base/WindowBase.h \ + GraphicsScene/Container/blurlayercontainer.h \ GraphicsScene/Container/geolayercontainer.h \ GraphicsScene/Container/layercontainer.h \ GraphicsScene/Container/paintlayercontainer.h \ GraphicsScene/Container/textlayercontainer.h \ GraphicsScene/Layer/arrowlayer.h \ + GraphicsScene/Layer/blurlayer.h \ GraphicsScene/Layer/layerbase.h \ GraphicsScene/Layer/paintlayer.h \ GraphicsScene/Layer/piclayer.h \ From a3bbe0f8f3301c636d52f43d6db820c9893bb52f Mon Sep 17 00:00:00 2001 From: xinhecuican <2686462757@qq.com> Date: Sat, 9 Dec 2023 16:23:08 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E6=B7=BB=E5=8A=A0grabcut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Container/blurlayercontainer.cpp | 58 +++- GraphicsScene/Container/blurlayercontainer.h | 3 + .../Container/masklayercontainer.cpp | 46 +++ GraphicsScene/Container/masklayercontainer.h | 15 + .../Container/paintlayercontainer.cpp | 2 +- .../Container/textlayercontainer.cpp | 1 + GraphicsScene/Layer/arrowlayer.cpp | 8 + GraphicsScene/Layer/arrowlayer.h | 2 + GraphicsScene/Layer/blurlayer.cpp | 6 +- GraphicsScene/Layer/blurlayer.h | 3 +- GraphicsScene/Layer/cliplayerbase.h | 21 ++ GraphicsScene/Layer/grabcutlayer.cpp | 89 ++++++ GraphicsScene/Layer/grabcutlayer.h | 31 +++ GraphicsScene/Layer/layerbase.cpp | 8 +- GraphicsScene/Layer/layerbase.h | 4 +- GraphicsScene/Layer/masklayer.cpp | 262 ++++++++++++++++++ GraphicsScene/Layer/masklayer.h | 52 ++++ GraphicsScene/Layer/paintlayer.cpp | 10 +- GraphicsScene/Layer/paintlayer.h | 3 +- GraphicsScene/Layer/piclayer.cpp | 10 +- GraphicsScene/Layer/piclayer.h | 3 +- GraphicsScene/Layer/rectlayer.cpp | 4 + GraphicsScene/Layer/rectlayer.h | 1 + GraphicsScene/Layer/textlayer.cpp | 6 +- GraphicsScene/Layer/textlayer.h | 3 +- GraphicsScene/Widgets/clipregion.cpp | 235 ++++++++++++++++ GraphicsScene/Widgets/clipregion.h | 46 +++ GraphicsScene/Widgets/colorpicker.cpp | 79 ++++++ GraphicsScene/Widgets/colorpicker.h | 31 +++ GraphicsScene/Widgets/defaulttoolbar.cpp | 37 +++ GraphicsScene/Widgets/defaulttoolbar.h | 11 + GraphicsScene/Widgets/grabcuthandler.cpp | 102 +++++++ GraphicsScene/Widgets/grabcuthandler.h | 41 +++ GraphicsScene/Widgets/layertoolbar.cpp | 10 + GraphicsScene/Widgets/layertoolbar.h | 2 + GraphicsScene/ilayercontrol.cpp | 10 +- GraphicsScene/ilayercontrol.h | 4 +- GraphicsScene/layermanager.cpp | 2 +- GraphicsScene/paintarea.cpp | 30 +- GraphicsScene/paintarea.h | 6 +- Helper/imagehelper.cpp | 1 + Resource/Languages/chinese.xml | 1 + Resource/Resources.qrc | 1 + Resource/blur.svg | 1 + capture.pro | 15 + .../Widgets/Scroll_handler/scroll_worker.cpp | 2 +- 46 files changed, 1293 insertions(+), 25 deletions(-) create mode 100644 GraphicsScene/Container/masklayercontainer.cpp create mode 100644 GraphicsScene/Container/masklayercontainer.h create mode 100644 GraphicsScene/Layer/cliplayerbase.h create mode 100644 GraphicsScene/Layer/grabcutlayer.cpp create mode 100644 GraphicsScene/Layer/grabcutlayer.h create mode 100644 GraphicsScene/Layer/masklayer.cpp create mode 100644 GraphicsScene/Layer/masklayer.h create mode 100644 GraphicsScene/Widgets/clipregion.cpp create mode 100644 GraphicsScene/Widgets/clipregion.h create mode 100644 GraphicsScene/Widgets/colorpicker.cpp create mode 100644 GraphicsScene/Widgets/colorpicker.h create mode 100644 GraphicsScene/Widgets/defaulttoolbar.cpp create mode 100644 GraphicsScene/Widgets/defaulttoolbar.h create mode 100644 GraphicsScene/Widgets/grabcuthandler.cpp create mode 100644 GraphicsScene/Widgets/grabcuthandler.h create mode 100644 Resource/blur.svg diff --git a/GraphicsScene/Container/blurlayercontainer.cpp b/GraphicsScene/Container/blurlayercontainer.cpp index 8970862..baba9fa 100644 --- a/GraphicsScene/Container/blurlayercontainer.cpp +++ b/GraphicsScene/Container/blurlayercontainer.cpp @@ -1,21 +1,52 @@ #include "blurlayercontainer.h" #include #include "../paintarea.h" +#include "../../Helper/mstring.h" +#include "../../Helper/imagehelper.h" +#include BlurLayerContainer::BlurLayerContainer(PaintArea* area) : LayerContainer(area), + type(0), windowSize(10) { blurLayer = new BlurLayer("blur", area, area->getRootLayer()); blurLayer->setEnable(false); + grabcutLayer = new GrabcutLayer("grabcut", area, area->getRootLayer()); area->addLayer(blurLayer); + area->addLayer(grabcutLayer); } QWidget* BlurLayerContainer::onValid(QWidget *widgetParent) { - area->setEnable(false); + area->setEnable(false, blurLayer->type()); + if(type == 1){ + grabcutLayer->setEnableShow(); + } if(widget == NULL) { widget = new QWidget(widgetParent); QHBoxLayout* layout = new QHBoxLayout(); + + QButtonGroup* group = new QButtonGroup(widgetParent); + group->setExclusive(true); + connect(group, static_cast(&QButtonGroup::buttonClicked), + this, [=](int id) { + type = id; + if(type == 1){ + grabcutLayer->setEnableShow(); + } + }); + QToolButton* mosaicButton = new QToolButton(widgetParent); + mosaicButton->setToolTip(MString::search("{capture_mosaic}马赛克")); + mosaicButton->setIcon(ImageHelper::getIcon("blur")); + mosaicButton->setCheckable(true); + mosaicButton->setChecked(true); + group->addButton(mosaicButton, 0); + QToolButton* grabcutButton = new QToolButton(widgetParent); + grabcutButton->setToolTip(MString::search("{QbgMYc4u4H}透明")); + grabcutButton->setIcon(ImageHelper::getIcon("mosaic")); + grabcutButton->setCheckable(true); + group->addButton(grabcutButton, 1); + QSpinBox* mosaicSize = new QSpinBox(widgetParent); mosaicSize->setRange(2, 30); mosaicSize->setValue(4); @@ -26,6 +57,8 @@ QWidget* BlurLayerContainer::onValid(QWidget *widgetParent) { connect(mosaicSize, static_cast(&QSpinBox::valueChanged), this, [=](int value) { windowSize = value; }); + layout->addWidget(mosaicButton); + layout->addWidget(grabcutButton); layout->addWidget(mosaicSize); widget->setLayout(layout); } @@ -33,14 +66,29 @@ QWidget* BlurLayerContainer::onValid(QWidget *widgetParent) { } void BlurLayerContainer::layerMousePressEvent(QGraphicsSceneMouseEvent *event) { - blurLayer->setParameter("windowSize", windowSize); - blurLayer->addPoint(event->scenePos().toPoint()); + if(type == 0){ + blurLayer->setParameter("windowSize", windowSize); + blurLayer->addPoint(event->scenePos().toPoint()); + } + else if(type == 1){ + grabcutLayer->addPoint(event->scenePos(), event->button() == Qt::RightButton, false); + } } void BlurLayerContainer::layerMouseMoveEvent(QGraphicsSceneMouseEvent *event) { - blurLayer->addPoint(event->scenePos().toPoint()); + if(type == 0){ + blurLayer->addPoint(event->scenePos().toPoint()); + } + else if(type == 1){ + grabcutLayer->addPoint(event->scenePos(), event->button() == Qt::RightButton, false); + } } void BlurLayerContainer::layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - blurLayer->addPoint(event->scenePos().toPoint()); + if(type == 0){ + blurLayer->addPoint(event->scenePos().toPoint()); + } + else if(type == 1){ + grabcutLayer->addPoint(event->scenePos(), event->button() == Qt::RightButton, true); + } } diff --git a/GraphicsScene/Container/blurlayercontainer.h b/GraphicsScene/Container/blurlayercontainer.h index 6f05f68..58374fb 100644 --- a/GraphicsScene/Container/blurlayercontainer.h +++ b/GraphicsScene/Container/blurlayercontainer.h @@ -2,6 +2,7 @@ #define BLURLAYERCONTAINER_H #include "layercontainer.h" #include "../Layer/blurlayer.h" +#include "../Layer/grabcutlayer.h" class BlurLayerContainer : public LayerContainer { @@ -13,6 +14,8 @@ class BlurLayerContainer : public LayerContainer QWidget * onValid(QWidget *widgetParent) override; private: BlurLayer* blurLayer; + GrabcutLayer* grabcutLayer; + int type; int windowSize; }; diff --git a/GraphicsScene/Container/masklayercontainer.cpp b/GraphicsScene/Container/masklayercontainer.cpp new file mode 100644 index 0000000..9669d12 --- /dev/null +++ b/GraphicsScene/Container/masklayercontainer.cpp @@ -0,0 +1,46 @@ +#include "masklayercontainer.h" +#include "../paintarea.h" +#include + +MaskLayerContainer::MaskLayerContainer(PaintArea* area) : LayerContainer(area) +{ + maskLayer = new MaskLayer("mask", area, area->getRootLayer()); + area->addLayer(maskLayer); +} + +QWidget* MaskLayerContainer::onValid(QWidget *widgetParent) { + area->setEnable(false, maskLayer->type()); + maskLayer->setEnable(true, maskLayer->type()); + if(widget == NULL){ + widget = new QWidget(widgetParent); + QHBoxLayout* layout = new QHBoxLayout(); + + QButtonGroup* modeGroup = new QButtonGroup(widgetParent); + modeGroup->setExclusive(true); + + QToolButton* rectCapture = new QToolButton(widgetParent); + rectCapture->setIcon(ImageHelper::getIcon("rect")); + rectCapture->setToolTip(MString::search("{OBwjJUhTkh}矩形窗口")); + rectCapture->setChecked(true); + rectCapture->setCheckable(true); + rectCapture->setIconSize(QSize(36, 36)); + QToolButton* freeCapture = new QToolButton(widgetParent); + freeCapture->setIcon(ImageHelper::getIcon("painterpath")); + freeCapture->setIconSize(QSize(36, 36)); + freeCapture->setCheckable(true); + modeGroup->addButton(rectCapture, 0); + modeGroup->addButton(freeCapture, 1); + connect(modeGroup, static_cast(&QButtonGroup::buttonClicked) + , this, [=](int id) { + if(id == 0) { + Config::setConfig(Config::capture_mode, Config::RECT_CAPTURE); + } else if(id == 1) { + Config::setConfig(Config::capture_mode, Config::FREE_CAPTURE); + } + }); + layout->addWidget(rectCapture); + layout->addWidget(freeCapture); + widget->setLayout(layout); + } + return widget; +} diff --git a/GraphicsScene/Container/masklayercontainer.h b/GraphicsScene/Container/masklayercontainer.h new file mode 100644 index 0000000..aba1f36 --- /dev/null +++ b/GraphicsScene/Container/masklayercontainer.h @@ -0,0 +1,15 @@ +#ifndef MASKLAYERCONTAINER_H +#define MASKLAYERCONTAINER_H +#include "layercontainer.h" +#include "../Layer/masklayer.h" + +class MaskLayerContainer : public LayerContainer +{ +public: + MaskLayerContainer(PaintArea* area); + QWidget * onValid(QWidget *widgetParent) override; +private: + MaskLayer* maskLayer; +}; + +#endif // MASKLAYERCONTAINER_H diff --git a/GraphicsScene/Container/paintlayercontainer.cpp b/GraphicsScene/Container/paintlayercontainer.cpp index 4830613..ca13618 100644 --- a/GraphicsScene/Container/paintlayercontainer.cpp +++ b/GraphicsScene/Container/paintlayercontainer.cpp @@ -18,7 +18,7 @@ PaintLayerContainer::PaintLayerContainer(PaintArea* area) : } QWidget* PaintLayerContainer::onValid(QWidget *widgetParent) { - area->setEnable(false); + area->setEnable(false, 102405); if(widget == NULL){ widget = new QWidget(widgetParent); QHBoxLayout* layout = new QHBoxLayout(); diff --git a/GraphicsScene/Container/textlayercontainer.cpp b/GraphicsScene/Container/textlayercontainer.cpp index d4d1113..112d912 100644 --- a/GraphicsScene/Container/textlayercontainer.cpp +++ b/GraphicsScene/Container/textlayercontainer.cpp @@ -34,6 +34,7 @@ void TextLayerContainer::layerMousePressEvent(QGraphicsSceneMouseEvent *event){ } QWidget* TextLayerContainer::onValid(QWidget *widgetParent){ + area->setEnable(true); if(widget == NULL){ widget = new QWidget(widgetParent); QHBoxLayout* layout = new QHBoxLayout(); diff --git a/GraphicsScene/Layer/arrowlayer.cpp b/GraphicsScene/Layer/arrowlayer.cpp index 25a979f..fe2409e 100644 --- a/GraphicsScene/Layer/arrowlayer.cpp +++ b/GraphicsScene/Layer/arrowlayer.cpp @@ -157,3 +157,11 @@ void ArrowLayer::setEndPoint(const QPointF &point) { this->endPt = point; setLine(beginPt, endPt); } + +int ArrowLayer::getZValue() const{ + return 2; +} + +int ArrowLayer::type() const{ + return 102400; +} diff --git a/GraphicsScene/Layer/arrowlayer.h b/GraphicsScene/Layer/arrowlayer.h index 895f3f4..13dfcdc 100644 --- a/GraphicsScene/Layer/arrowlayer.h +++ b/GraphicsScene/Layer/arrowlayer.h @@ -26,6 +26,8 @@ class ArrowLayer : public LayerBase void getFocus() override; void loseFocus() override; void setEndPoint(const QPointF& point); + int getZValue() const override; + int type() const override; private slots: void posChangeFunc(ExpandButton::ButtonDirection dir, qreal x, qreal y); diff --git a/GraphicsScene/Layer/blurlayer.cpp b/GraphicsScene/Layer/blurlayer.cpp index 523ff63..49cba2c 100644 --- a/GraphicsScene/Layer/blurlayer.cpp +++ b/GraphicsScene/Layer/blurlayer.cpp @@ -70,6 +70,10 @@ void BlurLayer::setParameter(const QString &name, const QVariant &var) { } } -void BlurLayer::setEnable(bool enable) { +void BlurLayer::setEnable(bool enable, int index) { this->enable = false; } + +int BlurLayer::type() const{ + return 102401; +} diff --git a/GraphicsScene/Layer/blurlayer.h b/GraphicsScene/Layer/blurlayer.h index 1241fd9..ededcb8 100644 --- a/GraphicsScene/Layer/blurlayer.h +++ b/GraphicsScene/Layer/blurlayer.h @@ -15,7 +15,8 @@ class BlurLayer : public LayerBase void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; void onImageSet() override; void addPoint(const QPoint& point); - void setEnable(bool enable) override; + void setEnable(bool enable, int index=0) override; + int type() const override; private: QBitArray use; QRectF bound; diff --git a/GraphicsScene/Layer/cliplayerbase.h b/GraphicsScene/Layer/cliplayerbase.h new file mode 100644 index 0000000..f2043d0 --- /dev/null +++ b/GraphicsScene/Layer/cliplayerbase.h @@ -0,0 +1,21 @@ +#ifndef CLIPLAYERBASE_H +#define CLIPLAYERBASE_H +#include "layerbase.h" + +class ClipLayerBase : public LayerBase +{ + Q_OBJECT +public: + ClipLayerBase(const QString& name, + ILayerControl* manager, + QGraphicsItem* parent) : + LayerBase(name, manager, parent) {} + virtual ~ClipLayerBase(){} + virtual QRectF getClipRect()=0; + virtual QPainterPath getClipPath()=0; +signals: + void boundChangeBegin(); + void boundChange(QRectF rect); +}; + +#endif // CLIPLAYERBASE_H diff --git a/GraphicsScene/Layer/grabcutlayer.cpp b/GraphicsScene/Layer/grabcutlayer.cpp new file mode 100644 index 0000000..36e6d52 --- /dev/null +++ b/GraphicsScene/Layer/grabcutlayer.cpp @@ -0,0 +1,89 @@ +#include "grabcutlayer.h" +#include +#include "../../Helper/imagehelper.h" +#include "../../Helper/debug.h" +#include + +GrabcutLayer::GrabcutLayer(const QString& name, + ILayerControl* manager, + QGraphicsItem* parent) + : LayerBase(name, manager, parent), + background(true), + enableShow(false) +{ + handler = new GrabcutHandler(this); + connect(handler, &GrabcutHandler::finish, this, [=](QImage mask){ + manager->maskImage(mask); + update(); + }); +} + +void GrabcutLayer::addPoint(const QPointF &point, bool background, bool isEnd){ + this->background = background; + if(currentPath.elementCount() == 0){ + currentPath.moveTo(point); + } + else{ + currentPath.lineTo(point); + } + bound = bound.united(currentPath.boundingRect()); + if(isEnd){ + if(background) backgroundPaths.append(currentPath); + else foregroundPaths.append(currentPath); + currentPath = QPainterPath(); + if(foregroundPaths.size() != 0 && backgroundPaths.size() != 0){ + handler->start(manager->getOriginImage(), foregroundPaths, backgroundPaths); + } + } + update(); +} + +QRectF GrabcutLayer::boundingRect() const{ + return bound; +} + +void GrabcutLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ + if(enableShow){ + QPen pen; + pen.setColor(QColor(255, 0, 0, 128)); + pen.setWidth(5); + painter->setPen(pen); + for(int i=0; idrawPath(foregroundPaths[i]); + } + pen.setColor(QColor(0, 0, 255, 128)); + painter->setPen(pen); + for(int i=0; idrawPath(backgroundPaths[i]); + } + if(background) pen.setColor(QColor(0, 0, 255, 128)); + else pen.setColor(QColor(255, 0, 0, 128)); + painter->setPen(pen); + painter->drawPath(currentPath); + } +} + +void GrabcutLayer::setEnable(bool enable, int index){ + enableShow = false; + this->enable = false; +} + +void GrabcutLayer::makeEnable(){ + enable = true; +} + +int GrabcutLayer::type() const{ + return 102402; +} + +void GrabcutLayer::reset(){ + +} + +int GrabcutLayer::getZValue() const{ + return 2; +} + +void GrabcutLayer::setEnableShow(){ + enableShow = true; +} diff --git a/GraphicsScene/Layer/grabcutlayer.h b/GraphicsScene/Layer/grabcutlayer.h new file mode 100644 index 0000000..b8beca0 --- /dev/null +++ b/GraphicsScene/Layer/grabcutlayer.h @@ -0,0 +1,31 @@ +#ifndef GRABCUTLAYER_H +#define GRABCUTLAYER_H +#include "layerbase.h" +#include "../Widgets/grabcuthandler.h" + +class GrabcutLayer : public LayerBase +{ +public: + GrabcutLayer(const QString& name, + ILayerControl* manager, + QGraphicsItem* parent=nullptr); + void reset() override; + void addPoint(const QPointF& point, bool background=true, bool isEnd=false); + void makeEnable(); + void setEnable(bool enable, int index=0) override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; + QRectF boundingRect()const override; + int type() const override; + int getZValue() const override; + void setEnableShow(); +private: + QList foregroundPaths; + QList backgroundPaths; + QPainterPath currentPath; + QRectF bound; + bool background; + GrabcutHandler* handler; + bool enableShow; +}; + +#endif // GRABCUTLAYER_H diff --git a/GraphicsScene/Layer/layerbase.cpp b/GraphicsScene/Layer/layerbase.cpp index d04ef08..d7d9a07 100644 --- a/GraphicsScene/Layer/layerbase.cpp +++ b/GraphicsScene/Layer/layerbase.cpp @@ -35,10 +35,16 @@ void LayerBase::setErase(bool enable){ erase = enable; } -void LayerBase::setEnable(bool enable){ +void LayerBase::setEnable(bool enable, int index){ this->enable = enable; } int LayerBase::getZValue() const { return 0; } + +void LayerBase::reset() { + enable = false; + erase = false; + isSaving = false; +} diff --git a/GraphicsScene/Layer/layerbase.h b/GraphicsScene/Layer/layerbase.h index 33d5c0d..b4d5dc1 100644 --- a/GraphicsScene/Layer/layerbase.h +++ b/GraphicsScene/Layer/layerbase.h @@ -16,11 +16,11 @@ class LayerBase : public QGraphicsObject QString getName()const; virtual const QString getHelp(){return "";}; virtual void setErase(bool enable); - virtual void setEnable(bool enable); + virtual void setEnable(bool enable, int index=0); virtual void setParameter(const QString& name, const QVariant& var){}; virtual void prepareSave(); virtual void endSave(); - virtual void reset()=0; + virtual void reset(); virtual int getZValue() const; virtual void getFocus(){} virtual void loseFocus(){} diff --git a/GraphicsScene/Layer/masklayer.cpp b/GraphicsScene/Layer/masklayer.cpp new file mode 100644 index 0000000..648e06f --- /dev/null +++ b/GraphicsScene/Layer/masklayer.cpp @@ -0,0 +1,262 @@ +#include "masklayer.h" +#include "../../Manager/config.h" +#include "../../Helper/math.h" +#include "../../Manager/uimanager.h" +#include "../../Helper/plist.h" + +MaskLayer::MaskLayer(const QString& name, + ILayerControl* manager, + QGraphicsItem* parent) + : ClipLayerBase(name, manager, parent) +{ + borderData = UIManager::instance()->getBorderData(); + backgroundColor = UIManager::instance()->getCaptureBackground(); + backgroundColor = QColor(0, 0, 0, 100); + borderData.width = 2; + colorPicker = new ColorPicker(manager, this); + colorPicker->hide(); +} + +QRectF MaskLayer::boundingRect() const { + return bound; +} + +void MaskLayer::onImageSet() { + bound = manager->getImage().rect(); +} + + +void MaskLayer::mousePressEvent(QGraphicsSceneMouseEvent *event) { + button = event->button(); + if(button != Qt::LeftButton || !enable) + return; + if(Config::getConfig(Config::capture_mode) == Config::FREE_CAPTURE) { + freeCapturePath.clear(); + freeCapturePath.moveTo(mapFromScene(event->scenePos())); + } + beginPoint = mapFromScene(event->scenePos()); + endPoint = beginPoint; + isDrag = false; + beginClip = true; + for(int i=0; icontain(regions[i]->mapFromParent(beginPoint))) { + isDrag = true; + break; + } + } + for(int i=0; icontain(regions[i]->mapFromParent(beginPoint))) { + isDrag = true; + break; + } + } + if(!isDrag){ + regionChangeBegin(beginPoint); + } + emit boundChangeBegin(); +} + +void MaskLayer::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { + if(!isDrag || !enable) { + update(); + regionMove(mapFromScene(event->scenePos())); + } + if(Config::getConfig(Config::capture_mode) == Config::FREE_CAPTURE) + freeCapturePath.lineTo(mapFromScene(event->scenePos())); + else + endPoint = mapFromScene(event->scenePos()); + +} + +void MaskLayer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { + beginClip = false; + QRectF new_rect; + if(Config::getConfig(Config::capture_mode) == Config::FREE_CAPTURE) + new_rect = freeCapturePath.boundingRect(); + else + new_rect = Math::buildRect(beginPoint, mapFromScene(event->scenePos())); + if(new_rect.width() < 10 || new_rect.height() < 10 || isDrag || button != Qt::LeftButton || !enable) { + regionChanged(); + return; + } + if(Config::getConfig(Config::capture_mode) == Config::FREE_CAPTURE) { + freeCapturePath.lineTo(mapFromScene(event->scenePos())); + freeCapturePath.closeSubpath(); + freeCapturePath = freeCapturePath.simplified(); + QList polygons = freeCapturePath.toSubpathPolygons(); + + for(QPolygonF polygon : polygons) { + ClipRegion* new_region = new ClipRegion(polygon, true, this); + free_regions.append(new_region); + } + } else { + addRegion(new_rect); + } + update(); + regionChanged(); +} + +void MaskLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + if(!isSaving) { + painter->fillRect(bound, QColor(0, 0, 0, 1)); + QPen pen; + pen.setColor(borderData.color); + pen.setWidth(borderData.width); + painter->setPen(pen); + + QPainterPath origin; + origin.addRect(bound); + QPainterPath path; + path.setFillRule(Qt::WindingFill); + if(!isDrag && beginClip && button == Qt::LeftButton) { + if(Config::getConfig(Config::capture_mode) == Config::FREE_CAPTURE) { + QPen tmp_pen = pen; + pen.setColor(QColor(41, 141, 255)); + pen.setWidth(3); + painter->setPen(pen); + painter->drawPath(freeCapturePath); + pen = tmp_pen; + painter->setPen(pen); + } else + path.addRect(Math::buildRect(beginPoint, endPoint)); + } + QPolygonF polygon; + for(ClipRegion* region : regions) { + polygon = polygon.united(region->getPolygon()); + } + for(ClipRegion* region : free_regions) { + polygon = polygon.united(region->getPolygon()); + } + path.addPolygon(polygon); + path = path.simplified(); + painter->drawPath(path); + origin = origin.subtracted(path); + painter->fillPath(origin, backgroundColor); + } +} + +void MaskLayer::addRegion(const QPolygonF& polygon) { + PList intersect_path; + auto iter = regions.begin(); + int i=0; + while(iter != regions.end()) { + if(iter.i->t()->intersect(polygon)) { + intersect_path.append(regions.at(i)); + iter = regions.erase(iter); + } else { + i++; + iter++; + } + } + ClipRegion* newRegion = new ClipRegion(polygon, this); + for(ClipRegion* region : intersect_path) { + newRegion->united(region); + } + intersect_path.clear_all(); + regions.append(newRegion); + connect(newRegion, &ClipRegion::regionChangeBegin, this, [=](QPointF point){ + regionChangeBegin(point); + }); + connect(newRegion, &ClipRegion::regionChange, this, [=]() { + regionChanged(); + }); + connect(newRegion, &ClipRegion::regionMove, this, [=](QPointF point){ + regionMove(point); + }); + connect(newRegion, &ClipRegion::regionPress, this, [=](){ + emit boundChangeBegin(); + }); +} + +void MaskLayer::prepareSave() { + for(ClipRegion* region : regions) { + region->hideNormal(); + } + for(ClipRegion* region: free_regions) { + region->hideNormal(); + } + ClipLayerBase::prepareSave(); +} + +void MaskLayer::endSave() { + clearRegion(); + ClipLayerBase::endSave(); +} + +QRectF MaskLayer::getClipRect() { + QPainterPath path = getClipPath(); + return path.boundingRect(); +} + +void MaskLayer::clearRegion() { + for(ClipRegion* region : regions) { + delete region; + } + for(ClipRegion* region : free_regions) { + delete region; + } + regions.clear(); + free_regions.clear(); +} + +QPainterPath MaskLayer::getClipPath() { + QPainterPath path; + for(int i=0; igetPolygon(); + path.addPolygon(temp_polygon); + } + for(int i=0; igetPolygon(); + path.addPolygon(temp_polygon); + } + return path; +} + +int MaskLayer::getRegionCount() { + return regions.size() + free_regions.size(); +} + +void MaskLayer::regionChangeBegin(const QPointF &point) { + colorPicker->show(); + colorPicker->setPosition(point); + emit boundChangeBegin(); +} + +void MaskLayer::regionMove(const QPointF &point) { + colorPicker->setPosition(point); +} + +void MaskLayer::regionChanged() { + colorPicker->hide(); + emit boundChange(getClipRect()); +} + +void MaskLayer::reset() { + isDrag = false; + beginClip = false; + clearRegion(); + freeCapturePath.clear(); +} + +int MaskLayer::getZValue() const { + return 1; +} + +void MaskLayer::setEnable(bool enable, int index){ + if(index == type() && enable){ + this->enable = true; + for(auto& region : regions){ + region->setEnable(true); + } + } + else{ + this->enable = false; + for(auto& region : regions){ + region->setEnable(false); + } + } +} + +int MaskLayer::type() const{ + return 102404; +} diff --git a/GraphicsScene/Layer/masklayer.h b/GraphicsScene/Layer/masklayer.h new file mode 100644 index 0000000..c1d730c --- /dev/null +++ b/GraphicsScene/Layer/masklayer.h @@ -0,0 +1,52 @@ +#ifndef MASKLAYER_H +#define MASKLAYER_H +#include "cliplayerbase.h" +#include "../Widgets/clipregion.h" +#include "../Widgets/colorpicker.h" + +class MaskLayer : public ClipLayerBase +{ + Q_OBJECT +public: + MaskLayer(const QString& name, + ILayerControl* manager, + QGraphicsItem* parent=nullptr); + QRectF boundingRect() const override; + void mousePressEvent(QGraphicsSceneMouseEvent *event) override; + void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override; + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; + void reset() override; + QRectF getClipRect() override; + void onImageSet() override; + void regionChangeBegin(const QPointF& point); + void regionMove(const QPointF& point); + void regionChanged(); + void clearRegion(); + int getRegionCount(); + void prepareSave() override; + void endSave() override; + QPainterPath getClipPath() override; + int getZValue() const override; + void setEnable(bool enable, int index=0) override; + int type() const override; +private: + void addRegion(const QPolygonF& polygon); + +private: + QPainterPath path; + QList regions; + QList free_regions; + QRectF bound; + QPainterPath freeCapturePath; + QPointF beginPoint; + QPointF endPoint; + bool isDrag; + bool beginClip; + Qt::MouseButton button; + PaintData borderData; + QColor backgroundColor; + ColorPicker* colorPicker; +}; + +#endif // MASKLAYER_H diff --git a/GraphicsScene/Layer/paintlayer.cpp b/GraphicsScene/Layer/paintlayer.cpp index bea0b94..4d7f73d 100644 --- a/GraphicsScene/Layer/paintlayer.cpp +++ b/GraphicsScene/Layer/paintlayer.cpp @@ -68,7 +68,11 @@ void PaintLayer::setParameter(const QString &name, const QVariant &var) { } } -void PaintLayer::setEnable(bool enable) { +void PaintLayer::setEnable(bool enable, int index) { + if(index == type()){ + this->enable = enable; + return; + } this->enable = false; } @@ -153,3 +157,7 @@ QPainterPath SmoothCurveGenerator::generateSmoothCurve(QList points, boo return path; } + +int PaintLayer::type() const{ + return 102405; +} diff --git a/GraphicsScene/Layer/paintlayer.h b/GraphicsScene/Layer/paintlayer.h index 51406f6..cd95a3b 100644 --- a/GraphicsScene/Layer/paintlayer.h +++ b/GraphicsScene/Layer/paintlayer.h @@ -19,7 +19,8 @@ class PaintLayer : public LayerBase { void addPoint(const QPointF& point); void setMethod(PaintMethod method); void setParameter(const QString &name, const QVariant &var) override; - void setEnable(bool enable) override; + void setEnable(bool enable, int index=0) override; + int type() const override; private: QList points; PaintMethod method; diff --git a/GraphicsScene/Layer/piclayer.cpp b/GraphicsScene/Layer/piclayer.cpp index 77e7c8e..29ab143 100644 --- a/GraphicsScene/Layer/piclayer.cpp +++ b/GraphicsScene/Layer/piclayer.cpp @@ -63,6 +63,14 @@ void PicLayer::reset(){ mask = QRectF(); } -void PicLayer::setEnable(bool enable) { +void PicLayer::setEnable(bool enable, int index) { + if(index == type()){ + this->enable = enable; + return; + } this->enable = enableBound && enable; } + +int PicLayer::type() const{ + return 102406; +} diff --git a/GraphicsScene/Layer/piclayer.h b/GraphicsScene/Layer/piclayer.h index be46a7f..8ce4599 100644 --- a/GraphicsScene/Layer/piclayer.h +++ b/GraphicsScene/Layer/piclayer.h @@ -15,7 +15,8 @@ class PicLayer : public LayerBase QPainterPath shape() const override; void onImageSet() override; void reset() override; - void setEnable(bool enable) override; + void setEnable(bool enable, int index=0) override; + int type() const override; private: bool enableBound; RectLayer* rectLayer; diff --git a/GraphicsScene/Layer/rectlayer.cpp b/GraphicsScene/Layer/rectlayer.cpp index 7f3fe77..ce4d5f2 100644 --- a/GraphicsScene/Layer/rectlayer.cpp +++ b/GraphicsScene/Layer/rectlayer.cpp @@ -262,3 +262,7 @@ void RectLayer::setRect(const QRectF &rect){ setBounding(this->rect); update(); } + +int RectLayer::type() const{ + return 102407; +} diff --git a/GraphicsScene/Layer/rectlayer.h b/GraphicsScene/Layer/rectlayer.h index a01608d..f827873 100644 --- a/GraphicsScene/Layer/rectlayer.h +++ b/GraphicsScene/Layer/rectlayer.h @@ -36,6 +36,7 @@ class RectLayer : public LayerBase void setBoundEffect(); void setButtonFocus(bool enable); void setRect(const QRectF& rect); + int type() const override; signals: void sizeChange(); diff --git a/GraphicsScene/Layer/textlayer.cpp b/GraphicsScene/Layer/textlayer.cpp index 3ea046a..c2af8cb 100644 --- a/GraphicsScene/Layer/textlayer.cpp +++ b/GraphicsScene/Layer/textlayer.cpp @@ -57,7 +57,7 @@ void TextLayer::setParameter(const QString &name, const QVariant &var){ } } -void TextLayer::setEnable(bool enable){ +void TextLayer::setEnable(bool enable, int index){ LayerBase::setEnable(enable); textItem->setEnable(enable); } @@ -75,3 +75,7 @@ bool TextLayer::contains(const QPointF &point) const{ } return false; } + +int TextLayer::type() const{ + return 102408; +} diff --git a/GraphicsScene/Layer/textlayer.h b/GraphicsScene/Layer/textlayer.h index 19a6a45..ac84c45 100644 --- a/GraphicsScene/Layer/textlayer.h +++ b/GraphicsScene/Layer/textlayer.h @@ -18,9 +18,10 @@ class TextLayer : public LayerBase void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; void prepareSave() override; void setParameter(const QString &name, const QVariant &var) override; - void setEnable(bool enable) override; + void setEnable(bool enable, int index=0) override; const QString getHelp() override; bool contains(const QPointF& point)const override; + int type() const override; signals: void formatChange(const QFont& font, const QBrush& brush); diff --git a/GraphicsScene/Widgets/clipregion.cpp b/GraphicsScene/Widgets/clipregion.cpp new file mode 100644 index 0000000..10854ee --- /dev/null +++ b/GraphicsScene/Widgets/clipregion.cpp @@ -0,0 +1,235 @@ +#include "clipregion.h" +#include +#include + +ClipRegion::ClipRegion(QPolygonF polygon, QGraphicsItem* parent) : QGraphicsObject(parent) +{ + this->polygon = polygon; + isButtonHide = false; + is_enable = true; + setFlag(QGraphicsItem::ItemIsMovable); + remapPoint(); +} + +ClipRegion::ClipRegion(QPolygonF polygon, bool isButtonHide, QGraphicsItem* parent) : QGraphicsObject(parent) + , isButtonHide(isButtonHide) + , polygon(polygon) +{ + setFlag(QGraphicsItem::ItemIsMovable); + emit regionChange(); +} + +ClipRegion::~ClipRegion() +{ +} + +QRectF ClipRegion::boundingRect() const +{ + return polygon.united(childrenBoundingRect()).boundingRect(); +} + +QPainterPath ClipRegion::shape() const +{ + QPainterPath path; + path.addPolygon(polygon); + return path; +} + +void ClipRegion::addRect(QRectF rect) +{ + this->polygon = polygon.united(rect); + remapPoint(); +} + +void ClipRegion::addPolygon(QPolygonF polygon) +{ + this->polygon = this->polygon.united(polygon); + remapPoint(); +} + +void ClipRegion::united(QPolygonF polygon) +{ + this->polygon = this->polygon.united(polygon); + remapPoint(); +} + +void ClipRegion::united(ClipRegion* region) +{ + this->polygon = polygon.united(region->polygon); + remapPoint(); +} + +bool ClipRegion::intersect(QRectF rect) +{ + return polygon.intersects(rect); +} + +bool ClipRegion::intersect(QPolygonF polygon) +{ + return this->polygon.intersects(polygon); +} + +void ClipRegion::remapPoint() +{ + if(isButtonHide) + return; + for(int i=buttons.size(); i, qreal, qreal, int, int)>(&ExpandButton::posChange), this, [=](QList index, qreal dx, qreal dy, int x_neigh, int y_neigh){ + for(int i=0; i neigh_index = buttons[x_neigh]->getIndex(); + for(int i=0; igetIndex(); + for(int i=0; isetPosition(buttons[x_neigh]->pos() + QPointF(dx, 0)); + buttons[y_neigh]->setPosition(buttons[y_neigh]->pos() + QPointF(0, dy)); + emit regionMove(polygon[index[0]]); + update(); + }); + connect(button, &ExpandButton::posTo, this, [=](ExpandButton::ButtonDirection dir, qreal x, qreal y){ + emit regionChange(); + }); + buttons.append(button); + } + for(int i=0; ihide(); + buttons[i]->clearIndex(); + } + QList pos_list = polygon.toPolygon().toList(); + int button_num = 0; + for(int i=0; igetPos() == pos_list[i]) + { + buttons[k]->setIndex(i); + success = true; + if(buttons[k]->setNeighbor(buttons[button_num-1]->getPos(), button_num-1)) + { + buttons[button_num-1]->setNeighbor(buttons[k]->getPos(), k); + } + break; + } + } + if(!success) + { + buttons[button_num]->show(); + buttons[button_num]->setIndex(i); + buttons[button_num]->setIntPos(pos_list[i]); + buttons[button_num]->setPosition(polygon[i]); + for(int k=button_num-1; k>=0; k--) + { + if(buttons[button_num]->setNeighbor(buttons[k]->getPos(), k)) + { + buttons[k]->setNeighbor(buttons[button_num]->getPos(), button_num); + break; + } + } + button_num++; + } + } + emit regionChange(); +} + +QPolygonF ClipRegion::getPolygon() +{ + return polygon; +} + +void ClipRegion::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + +} + +bool ClipRegion::contain(QPointF point) +{ + return polygon.contains(point); +} + +void ClipRegion::move(qreal dx, qreal dy) +{ + polygon.translate(dx, dy); + for(int i=0; imoveBy(dx, dy); + } + update(); +} + +void ClipRegion::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + if(!is_enable) + return; + begin_point = event->pos(); + emit regionPress(); +} + +void ClipRegion::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + if(!is_enable) + return; + QPointF delta = event->pos() - begin_point; + begin_point = event->pos(); + move(delta.x(), delta.y()); +} + +void ClipRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if(!is_enable) + return; + emit regionChange(); +} + +void ClipRegion::hideButton() +{ + isButtonHide = true; + for(ExpandButton* button: buttons) + { + button->hide(); + } + update(); +} + +void ClipRegion::setEnable(bool enable) +{ + is_enable = enable; + if(is_enable) + showNormal(); + else + hideNormal(); +} + +void ClipRegion::hideNormal() +{ + for(ExpandButton* button: buttons) + { + button->hide(); + } + update(); +} + +void ClipRegion::showNormal() +{ + for(ExpandButton* button: buttons) + { + button->show(); + } + update(); +} diff --git a/GraphicsScene/Widgets/clipregion.h b/GraphicsScene/Widgets/clipregion.h new file mode 100644 index 0000000..1506ddb --- /dev/null +++ b/GraphicsScene/Widgets/clipregion.h @@ -0,0 +1,46 @@ +#ifndef CLIPREGION_H +#define CLIPREGION_H +#include +#include "expandbutton.h" + +class ClipRegion : public QGraphicsObject +{ + Q_OBJECT +public: + ClipRegion(QPolygonF polygon, QGraphicsItem* parent=nullptr); + ClipRegion(QPolygonF polygon, bool isButtonHide, QGraphicsItem* parent=nullptr); + ~ClipRegion(); + bool intersect(QRectF rect); + bool intersect(QPolygonF polygon); + void addRect(QRectF rect); + void addPolygon(QPolygonF polygon); + void united(QPolygonF polygon); + void united(ClipRegion* region); + bool contain(QPointF point); + void move(qreal dx, qreal dy); + void mousePressEvent(QGraphicsSceneMouseEvent* event)override; + void mouseMoveEvent(QGraphicsSceneMouseEvent* event)override; + void mouseReleaseEvent(QGraphicsSceneMouseEvent* event)override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; + void hideButton(); + void setEnable(bool enable); + QPolygonF getPolygon(); + QPainterPath shape()const override; + QRectF boundingRect() const override; + void hideNormal(); + void showNormal(); +signals: + void regionPress(); + void regionChangeBegin(QPointF point); + void regionChange(); + void regionMove(QPointF point); +private: + void remapPoint(); + bool isButtonHide; + bool is_enable; + QPolygonF polygon; + QList buttons; + QPointF begin_point; +}; + +#endif // CLIPREGION_H diff --git a/GraphicsScene/Widgets/colorpicker.cpp b/GraphicsScene/Widgets/colorpicker.cpp new file mode 100644 index 0000000..cf88d53 --- /dev/null +++ b/GraphicsScene/Widgets/colorpicker.cpp @@ -0,0 +1,79 @@ +#include "colorpicker.h" +#include +#include +#include "../../Helper/PaintHelper.h" + +ColorPicker::ColorPicker(ILayerControl* manager, QGraphicsItem* parent) : QGraphicsObject(parent) +{ + this->manager = manager; + screenGeometry = ImageHelper::getCurrentGeometry(); + int widthpx = pt2px(pixelWidthPT); + pixelWidthPX = (widthpx | 0b1) * 5; + int heightpx = pt2px(pixelHeightPT); + pixelHeightPX = (heightpx | 0b1) * 5; +} + +void ColorPicker::setPosition(QPointF point){ + this->point = point; + if(point.x() + pixelWidthPX + offsetX > screenGeometry.right()){ + bound.setLeft(point.x()- pixelWidthPX - offsetX); + } + else{ + bound.setLeft(point.x() + offsetX); + } + if(point.y() + pixelHeightPX + 20 + offsetY > screenGeometry.bottom()){ + bound.setTop(point.y()- pixelHeightPX - 20 - offsetY); + } + else{ + bound.setTop(point.y() + offsetY); + } + bound.setHeight(pixelHeightPX+20); + bound.setWidth(pixelWidthPX); +} + +QRectF ColorPicker::boundingRect() const{ + // QRectF ans = bound; + // ans.setTopLeft(ans.topLeft() - QPointF(shadowWidth, shadowWidth)); + // ans.setBottomRight(ans.bottomRight() + QPointF(shadowWidth, shadowWidth)); + return bound; +} + +QPainterPath ColorPicker::shape() const{ + QPainterPath path; + // QRectF ans = bound; + // ans.setTopLeft(ans.topLeft() - QPointF(shadowWidth, shadowWidth)); + // ans.setBottomRight(ans.bottomRight() + QPointF(shadowWidth, shadowWidth)); + // path.addRect(ans); + path.addRect(bound); + return path; +} + +void ColorPicker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ + QImage image = manager->getImage(); + QImage image1 = QImage(pixelWidthPX, pixelHeightPX,QImage::Format_RGB32); + for(int i=0; i=image.width() ? image.width()-1 : i+point.x() - pixelWidthPX/10; + int y = k+point.y()-pixelHeightPX/10 < 0 ? 0 : k+point.y()+pixelHeightPX/10>=image.height() ? image.height()-1 : k+point.y()-pixelHeightPX/10; + image1.setPixel(j, m, image.pixel(x, y)); + } + } + } + } + QImage image2 = QImage(20, 20, QImage::Format_RGB32); + QRgb rgb = image.pixel(point.x(), point.y()); + image2.fill(rgb); + painter->drawImage(bound.left(), bound.top(), image1); + painter->drawImage(bound.left(), bound.top()+pixelHeightPX, image2); + QRect textBound(bound.left()+20, bound.top()+pixelHeightPX, pixelWidthPX-20, 20); + painter->fillRect(textBound, QColor(255, 255, 255)); + painter->drawText(textBound, Qt::AlignCenter, "("+QString::number(qRed(rgb)) + "," + QString::number(qGreen(rgb)) + "," + QString::number(qBlue(rgb)) + ")"); + PaintHelper::paintShadow(painter, bound, shadowWidth, QColor(50, 50, 50, 120)); + painter->setCompositionMode(QPainter::RasterOp_SourceOrNotDestination); + double middlex = (double)(pixelWidthPX) / 2.0; + double middley = (double)(pixelHeightPX) / 2.0; + painter->drawLine(bound.left()+middlex-10, bound.top()+middley, bound.left()+middlex+10, bound.top()+middley); + painter->drawLine(bound.left()+middlex, bound.top()+middley-10, bound.left()+middlex, bound.top()+middley+10); +} diff --git a/GraphicsScene/Widgets/colorpicker.h b/GraphicsScene/Widgets/colorpicker.h new file mode 100644 index 0000000..e6cdb6b --- /dev/null +++ b/GraphicsScene/Widgets/colorpicker.h @@ -0,0 +1,31 @@ +#ifndef COLORPICKER_H +#define COLORPICKER_H +#include +#include +#include "../../Helper/common.h" +#include "../../Helper/imagehelper.h" +#include "../ilayercontrol.h" + +class ColorPicker : public QGraphicsObject +{ +public: + ColorPicker(ILayerControl* manager, QGraphicsItem* parent=nullptr); + void setPosition(QPointF point); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; + QPainterPath shape()const override; + QRectF boundingRect() const override; +private: + QPointF point; + QRect bound; + QRect screenGeometry; + ILayerControl* manager; + int pixelWidthPX; + int pixelHeightPX; + int shadowWidth = 10; + const int offsetX = 30; + const int offsetY = 20; + const int pixelWidthPT = 15; + const int pixelHeightPT = 10; +}; + +#endif // COLORPICKER_H diff --git a/GraphicsScene/Widgets/defaulttoolbar.cpp b/GraphicsScene/Widgets/defaulttoolbar.cpp new file mode 100644 index 0000000..5b2a1bd --- /dev/null +++ b/GraphicsScene/Widgets/defaulttoolbar.cpp @@ -0,0 +1,37 @@ +#include "defaulttoolbar.h" +#include "../Container/blurlayercontainer.h" +#include "../Container/geolayercontainer.h" +#include "../Container/masklayercontainer.h" +#include "../Container/paintlayercontainer.h" +#include "../Container/textlayercontainer.h" + +DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar(area, parent) +{ + GeoLayerContainer* geoLayerContainer = new GeoLayerContainer(area); + addContainer("shape", "", geoLayerContainer, true); + BlurLayerContainer* blurLayerContainer = new BlurLayerContainer(area); + addContainer("mosaic", "", blurLayerContainer, true); + QToolButton* cursorButton = new QToolButton(this); + cursorButton->setIcon(QIcon(":/image/cursor.png")); + cursorButton->setToolTip(MString::search("{l4yTU9QXUd}指针")); + cursorButton->setCursor(QCursor(QPixmap(":/image/cursor.png"), 0, 0)); + MaskLayerContainer* maskLayerContainer = new MaskLayerContainer(area); + addContainer(cursorButton, maskLayerContainer, true); + setContainer(maskLayerContainer); + PaintLayerContainer* paintLayerContainer = new PaintLayerContainer(area); + addContainer("pencil", "", paintLayerContainer, true); + TextLayerContainer* textLayerContainer = new TextLayerContainer(area); + addContainer("text", "", textLayerContainer, true); + + ClipLayerBase* clipLayer = area->getClipLayer(); + if(clipLayer != NULL){ + connect(clipLayer, &ClipLayerBase::boundChangeBegin, this, [=](){ + hideAll(); + }); + connect(clipLayer, &ClipLayerBase::boundChange, this, [=](QRectF bound){ + moveTo(bound); + showAll(); + }); + } + hide(); +} diff --git a/GraphicsScene/Widgets/defaulttoolbar.h b/GraphicsScene/Widgets/defaulttoolbar.h new file mode 100644 index 0000000..6dee40f --- /dev/null +++ b/GraphicsScene/Widgets/defaulttoolbar.h @@ -0,0 +1,11 @@ +#ifndef DEFAULTTOOLBAR_H +#define DEFAULTTOOLBAR_H +#include "layertoolbar.h" + +class DefaultToolbar : public LayerToolBar +{ +public: + DefaultToolbar(PaintArea* area, QWidget* parent=nullptr); +}; + +#endif // DEFAULTTOOLBAR_H diff --git a/GraphicsScene/Widgets/grabcuthandler.cpp b/GraphicsScene/Widgets/grabcuthandler.cpp new file mode 100644 index 0000000..3f05532 --- /dev/null +++ b/GraphicsScene/Widgets/grabcuthandler.cpp @@ -0,0 +1,102 @@ +#include "grabcuthandler.h" +#include +#include +#include +#include +#include "../../Helper/imagehelper.h" +#include "../../Helper/debug.h" +#include + +GrabcutHandler::GrabcutHandler(QObject* parent) + : QObject(parent), + _finish(false), + working(false), + waiting(false) +{ + qRegisterMetaType>("QList"); + worker = new GrabcutWorker(); + worker->moveToThread(&thread); + connect(this, &GrabcutHandler::startWork, worker, &GrabcutWorker::work); + connect(worker, &GrabcutWorker::finish, this, [=](QImage mask){ + emit finish(mask); + if(waiting){ + emit startWork(waitImage, waitfgd, waitbgd); + waiting = false; + return; + } + _finish = true; + working = false; + }); + thread.start(); +} + +GrabcutHandler::~GrabcutHandler(){ + thread.quit(); + thread.wait(); + worker->deleteLater(); +} + +void GrabcutHandler::start(QImage image, QList fgd, QList bgd){ + if(working){ + waitImage = image; + waitfgd = fgd; + waitbgd = bgd; + waiting = true; + return; + } + emit startWork(image, fgd, bgd); + _finish = false; + working = true; +} + +bool GrabcutHandler::isFinish(){ + return _finish; +} + +GrabcutWorker::GrabcutWorker(QObject* parent) : QObject(parent){ + +} + +void GrabcutWorker::work(QImage image, QList fgd, QList bgd){ + cv::Mat inputMat = ImageHelper::QImage2Mat(image); + cv::cvtColor(inputMat, inputMat, cv::COLOR_RGBA2RGB); + + cv::Mat maskMat(image.height(), image.width(), CV_8UC1); + maskMat.setTo(cv::Scalar::all(cv::GC_PR_BGD)); + + cv::Mat borderMat; + cv::Canny(inputMat, borderMat, 50, 150); + maskMat.setTo(cv::GC_PR_FGD, borderMat); + for(int i=0; i +#include +#include +#include + +class GrabcutWorker : public QObject { + Q_OBJECT +public: + GrabcutWorker(QObject* parent=nullptr); +public slots: + void work(QImage image, QList fgd, QList bgd); +signals: + void finish(QImage mask); +}; + +class GrabcutHandler : public QObject +{ + Q_OBJECT +public: + GrabcutHandler(QObject* parent=nullptr); + ~GrabcutHandler(); + void start(QImage image, QList fgd, QList bgd); + bool isFinish(); +signals: + void startWork(QImage image, QList fgd, QList bgd); + void finish(QImage mask); + +private: + QThread thread; + GrabcutWorker* worker; + bool _finish; + bool working; + bool waiting; + QImage waitImage; + QList waitfgd; + QList waitbgd; +}; + +#endif // GRABCUTHANDLER_H diff --git a/GraphicsScene/Widgets/layertoolbar.cpp b/GraphicsScene/Widgets/layertoolbar.cpp index eb3e945..2b4f6be 100644 --- a/GraphicsScene/Widgets/layertoolbar.cpp +++ b/GraphicsScene/Widgets/layertoolbar.cpp @@ -103,3 +103,13 @@ void LayerToolBar::onGroupClick(int id){ attributeBar->showWidget(widget); moveTo(mask); } + +void LayerToolBar::hideAll(){ + hide(); + attributeBar->hide(); +} + +void LayerToolBar::showAll(){ + show(); + attributeBar->show(); +} diff --git a/GraphicsScene/Widgets/layertoolbar.h b/GraphicsScene/Widgets/layertoolbar.h index 73ce2c2..679b3e4 100644 --- a/GraphicsScene/Widgets/layertoolbar.h +++ b/GraphicsScene/Widgets/layertoolbar.h @@ -17,6 +17,8 @@ class LayerToolBar : public QToolBar void moveTo(const QRectF& mask); void setBound(const QRectF& bound); void setContainer(LayerContainer* container); + void hideAll(); + void showAll(); private slots: void onGroupClick(int id); diff --git a/GraphicsScene/ilayercontrol.cpp b/GraphicsScene/ilayercontrol.cpp index 03e829b..4535cec 100644 --- a/GraphicsScene/ilayercontrol.cpp +++ b/GraphicsScene/ilayercontrol.cpp @@ -19,7 +19,7 @@ QImage ILayerControl::getImage() const{ void ILayerControl::modifyImage(const QPoint &pos, const QColor& color){ if(!modified){ - modifiedImage = image; + modifiedImage = image.copy(); } modified = true; modifiedImage.setPixel(pos, color.rgba()); @@ -28,3 +28,11 @@ void ILayerControl::modifyImage(const QPoint &pos, const QColor& color){ bool ILayerControl::isImageValid(){ return imageValid; } + +void ILayerControl::maskImage(const QImage &mask){ + if(!modified){ + modifiedImage = image.copy(); + } + modified = true; + modifiedImage.setAlphaChannel(mask); +} diff --git a/GraphicsScene/ilayercontrol.h b/GraphicsScene/ilayercontrol.h index cb01bdf..c02e864 100644 --- a/GraphicsScene/ilayercontrol.h +++ b/GraphicsScene/ilayercontrol.h @@ -20,8 +20,10 @@ class ILayerControl virtual void requestFocus(LayerBase* layer)=0; virtual void removeThis(LayerBase* layer)=0; virtual void modifyImage(const QPoint& pos, const QColor& color); + virtual void maskImage(const QImage& mask); virtual void setEraseEnable(bool enable)=0; - virtual void setEnable(bool enable)=0; + virtual void setEnable(bool enable, int index=0)=0; + virtual QRectF getClipRect()=0; protected: bool imageValid; QImage image; diff --git a/GraphicsScene/layermanager.cpp b/GraphicsScene/layermanager.cpp index 46d8836..34fe3b9 100644 --- a/GraphicsScene/layermanager.cpp +++ b/GraphicsScene/layermanager.cpp @@ -27,7 +27,7 @@ void LayerManager::changeFocusLayer(LayerBase* layer){ } LayerBase* beforeFocusLayer = focusLayer; focusLayer = layer; - focusLayer->getFocus(); + if(focusLayer != NULL) focusLayer->getFocus(); if(beforeFocusLayer != NULL){ beforeFocusLayer->loseFocus(); } diff --git a/GraphicsScene/paintarea.cpp b/GraphicsScene/paintarea.cpp index fadb0fa..68100dd 100644 --- a/GraphicsScene/paintarea.cpp +++ b/GraphicsScene/paintarea.cpp @@ -7,6 +7,7 @@ #include "../Paint/Widgets/history.h" #include #include +#include PaintArea::PaintArea(QWidget* parent) : QGraphicsScene(parent), @@ -14,7 +15,8 @@ PaintArea::PaintArea(QWidget* parent) : inLayer(false), press(false), mouseGrabber(NULL), - rootLayer(new RootLayer(this)) + rootLayer(new RootLayer(this)), + clipLayer(NULL) { } @@ -104,15 +106,22 @@ void PaintArea::setEraseEnable(bool enable){ } } -void PaintArea::setEnable(bool enable){ +void PaintArea::setEnable(bool enable, int index){ for(auto iter=layers.begin(); iter!=layers.end(); iter++){ - iter.value()->setEnable(enable); + iter.value()->setEnable(enable, index); + } + if(!enable){ + changeFocusLayer(NULL); } } void PaintArea::addLayer(LayerBase *layer){ layer->setParentItem(rootLayer); layer->setZValue(layer->getZValue()); + ClipLayerBase* clipLayer = dynamic_cast(layer); + if(clipLayer != NULL) { + this->clipLayer = clipLayer; + } // addItem(layer); LayerManager::addLayer(layer); } @@ -120,6 +129,9 @@ void PaintArea::addLayer(LayerBase *layer){ LayerBase* PaintArea::removeLayer(const QString &name){ LayerBase* layer = LayerManager::removeLayer(name); if(layer != NULL){ + if(layer == this->clipLayer) { + this->clipLayer = NULL; + } removeItem(layer); layer->deleteLater(); } @@ -168,3 +180,15 @@ QGraphicsItem* PaintArea::getRootLayer(){ void PaintArea::removeThis(LayerBase *layer){ removeLayer(layer->getName()); } + +QRectF PaintArea::getClipRect() { + if(clipLayer == NULL) { + qWarning() << "未设置clip layer"; + return QRectF(); + } + return clipLayer->getClipRect(); +} + +ClipLayerBase* PaintArea::getClipLayer(){ + return clipLayer; +} diff --git a/GraphicsScene/paintarea.h b/GraphicsScene/paintarea.h index 047f8cd..df8e158 100644 --- a/GraphicsScene/paintarea.h +++ b/GraphicsScene/paintarea.h @@ -6,6 +6,7 @@ #include #include "Container/layercontainer.h" #include "Layer/rootlayer.h" +#include "Layer/cliplayerbase.h" class PaintArea : public QGraphicsScene, public ILayerControl, public LayerManager { @@ -13,7 +14,7 @@ class PaintArea : public QGraphicsScene, public ILayerControl, public LayerManag PaintArea(QWidget* parent=nullptr); bool save(SaveType type, const QString &path = "") override; void setEraseEnable(bool enable) override; - void setEnable(bool enable) override; + void setEnable(bool enable, int index=0) override; bool hasFocus(LayerBase *layer) override; void requestFocus(LayerBase *layer) override; void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; @@ -26,12 +27,15 @@ class PaintArea : public QGraphicsScene, public ILayerControl, public LayerManag void setImage(const QImage& image); void reset(); QGraphicsItem* getRootLayer(); + QRectF getClipRect() override; + ClipLayerBase* getClipLayer(); private: LayerContainer* container; bool inLayer; bool press; QGraphicsItem* mouseGrabber; RootLayer* rootLayer; + ClipLayerBase* clipLayer; }; #endif // PAINTAREA_H diff --git a/Helper/imagehelper.cpp b/Helper/imagehelper.cpp index 852945d..114e8a8 100644 --- a/Helper/imagehelper.cpp +++ b/Helper/imagehelper.cpp @@ -58,6 +58,7 @@ cv::Mat ImageHelper::QImage2Mat(QImage const& image) { cv::cvtColor(mat, mat, CV_BGR2RGB); break; case QImage::Format_Indexed8: + case QImage::Format_Grayscale8: mat = cv::Mat(image.height(), image.width(), CV_8UC1, (void*)image.constBits(), image.bytesPerLine()); break; } diff --git a/Resource/Languages/chinese.xml b/Resource/Languages/chinese.xml index 11cee67..609f392 100644 --- a/Resource/Languages/chinese.xml +++ b/Resource/Languages/chinese.xml @@ -130,4 +130,5 @@ + diff --git a/Resource/Resources.qrc b/Resource/Resources.qrc index 0339a25..49afb55 100644 --- a/Resource/Resources.qrc +++ b/Resource/Resources.qrc @@ -98,6 +98,7 @@ mouse_right.svg mouse_middle.svg mouse_left.svg + blur.svg custom_button.qss diff --git a/Resource/blur.svg b/Resource/blur.svg new file mode 100644 index 0000000..9fbbea5 --- /dev/null +++ b/Resource/blur.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/capture.pro b/capture.pro index 3e532f7..2f2b66c 100644 --- a/capture.pro +++ b/capture.pro @@ -21,18 +21,25 @@ SOURCES += \ GraphicsScene/Container/blurlayercontainer.cpp \ GraphicsScene/Container/geolayercontainer.cpp \ GraphicsScene/Container/layercontainer.cpp \ + GraphicsScene/Container/masklayercontainer.cpp \ GraphicsScene/Container/paintlayercontainer.cpp \ GraphicsScene/Container/textlayercontainer.cpp \ GraphicsScene/Layer/arrowlayer.cpp \ GraphicsScene/Layer/blurlayer.cpp \ + GraphicsScene/Layer/grabcutlayer.cpp \ GraphicsScene/Layer/layerbase.cpp \ + GraphicsScene/Layer/masklayer.cpp \ GraphicsScene/Layer/paintlayer.cpp \ GraphicsScene/Layer/piclayer.cpp \ GraphicsScene/Layer/rectlayer.cpp \ GraphicsScene/Layer/rootlayer.cpp \ GraphicsScene/Layer/textlayer.cpp \ GraphicsScene/Widgets/attributetoolbar.cpp \ + GraphicsScene/Widgets/clipregion.cpp \ + GraphicsScene/Widgets/colorpicker.cpp \ + GraphicsScene/Widgets/defaulttoolbar.cpp \ GraphicsScene/Widgets/expandbutton.cpp \ + GraphicsScene/Widgets/grabcuthandler.cpp \ GraphicsScene/Widgets/layertoolbar.cpp \ GraphicsScene/Widgets/scrollitem.cpp \ GraphicsScene/Widgets/textitem.cpp \ @@ -133,11 +140,15 @@ HEADERS += \ GraphicsScene/Container/blurlayercontainer.h \ GraphicsScene/Container/geolayercontainer.h \ GraphicsScene/Container/layercontainer.h \ + GraphicsScene/Container/masklayercontainer.h \ GraphicsScene/Container/paintlayercontainer.h \ GraphicsScene/Container/textlayercontainer.h \ GraphicsScene/Layer/arrowlayer.h \ GraphicsScene/Layer/blurlayer.h \ + GraphicsScene/Layer/cliplayerbase.h \ + GraphicsScene/Layer/grabcutlayer.h \ GraphicsScene/Layer/layerbase.h \ + GraphicsScene/Layer/masklayer.h \ GraphicsScene/Layer/paintlayer.h \ GraphicsScene/Layer/piclayer.h \ GraphicsScene/Layer/rectlayer.h \ @@ -146,7 +157,11 @@ HEADERS += \ GraphicsScene/Widgets/FontData.h \ GraphicsScene/Widgets/PaintData.h \ GraphicsScene/Widgets/attributetoolbar.h \ + GraphicsScene/Widgets/clipregion.h \ + GraphicsScene/Widgets/colorpicker.h \ + GraphicsScene/Widgets/defaulttoolbar.h \ GraphicsScene/Widgets/expandbutton.h \ + GraphicsScene/Widgets/grabcuthandler.h \ GraphicsScene/Widgets/layertoolbar.h \ GraphicsScene/Widgets/scrollitem.h \ GraphicsScene/Widgets/textitem.h \ diff --git a/new_capture/Widgets/Scroll_handler/scroll_worker.cpp b/new_capture/Widgets/Scroll_handler/scroll_worker.cpp index 7dc1b50..dd35bae 100644 --- a/new_capture/Widgets/Scroll_handler/scroll_worker.cpp +++ b/new_capture/Widgets/Scroll_handler/scroll_worker.cpp @@ -490,7 +490,7 @@ void Scroll_worker::initMask(int cols, int rows, cv::Mat image) maskImage = cv::Mat(rows, cols, CV_8UC1); cv::Mat borderImage = cv::Mat(rows, cols, CV_8UC1); cv::Canny(image, borderImage, 50, 150); - cv::imwrite("D:/Temp/" + std::to_string(QDateTime::currentMSecsSinceEpoch()) + ".png", borderImage); +// cv::imwrite("D:/Temp/" + std::to_string(QDateTime::currentMSecsSinceEpoch()) + ".png", borderImage); int testCount = (double)(cols) * 0.1; int testStep = cols / testCount; int deprecateCount = 0; From 7ab108f4864dc5e48f81257bea62cb0aa21b641e Mon Sep 17 00:00:00 2001 From: xinhecuican <2686462757@qq.com> Date: Mon, 11 Dec 2023 20:27:58 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E6=B7=BB=E5=8A=A0erase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Container/blurlayercontainer.cpp | 8 +- GraphicsScene/Container/blurlayercontainer.h | 1 + GraphicsScene/Container/geolayercontainer.cpp | 2 + GraphicsScene/Container/layercontainer.h | 4 +- .../Container/paintlayercontainer.cpp | 1 + GraphicsScene/Layer/arrowlayer.cpp | 24 +++- GraphicsScene/Layer/arrowlayer.h | 3 + GraphicsScene/Layer/blurlayer.cpp | 30 ++++- GraphicsScene/Layer/blurlayer.h | 4 + GraphicsScene/Layer/grabcutlayer.cpp | 58 ++++++++- GraphicsScene/Layer/grabcutlayer.h | 5 + GraphicsScene/Layer/layerbase.cpp | 10 -- GraphicsScene/Layer/layerbase.h | 6 +- GraphicsScene/Layer/masklayer.cpp | 4 + GraphicsScene/Layer/masklayer.h | 1 + GraphicsScene/Layer/paintlayer.cpp | 122 +++++++++++++----- GraphicsScene/Layer/paintlayer.h | 15 ++- GraphicsScene/Layer/piclayer.cpp | 7 + GraphicsScene/Layer/piclayer.h | 1 + GraphicsScene/Layer/rectlayer.cpp | 11 +- GraphicsScene/Layer/rectlayer.h | 1 + GraphicsScene/Layer/rootlayer.cpp | 23 +++- GraphicsScene/Layer/rootlayer.h | 4 + GraphicsScene/Layer/textlayer.cpp | 4 + GraphicsScene/Layer/textlayer.h | 2 +- GraphicsScene/Widgets/clipregion.cpp | 4 + GraphicsScene/Widgets/defaulttoolbar.cpp | 39 +++++- GraphicsScene/Widgets/grabcuthandler.cpp | 30 +++-- GraphicsScene/Widgets/layertoolbar.cpp | 56 +++++++- GraphicsScene/Widgets/layertoolbar.h | 8 ++ GraphicsScene/ilayercontrol.cpp | 34 ++++- GraphicsScene/ilayercontrol.h | 1 + GraphicsScene/paintarea.cpp | 17 ++- 33 files changed, 443 insertions(+), 97 deletions(-) diff --git a/GraphicsScene/Container/blurlayercontainer.cpp b/GraphicsScene/Container/blurlayercontainer.cpp index baba9fa..9a23679 100644 --- a/GraphicsScene/Container/blurlayercontainer.cpp +++ b/GraphicsScene/Container/blurlayercontainer.cpp @@ -4,6 +4,7 @@ #include "../../Helper/mstring.h" #include "../../Helper/imagehelper.h" #include +#include BlurLayerContainer::BlurLayerContainer(PaintArea* area) : LayerContainer(area), @@ -71,7 +72,8 @@ void BlurLayerContainer::layerMousePressEvent(QGraphicsSceneMouseEvent *event) { blurLayer->addPoint(event->scenePos().toPoint()); } else if(type == 1){ - grabcutLayer->addPoint(event->scenePos(), event->button() == Qt::RightButton, false); + background = event->button() == Qt::RightButton; + grabcutLayer->addPoint(event->scenePos(), background, false); } } @@ -80,7 +82,7 @@ void BlurLayerContainer::layerMouseMoveEvent(QGraphicsSceneMouseEvent *event) { blurLayer->addPoint(event->scenePos().toPoint()); } else if(type == 1){ - grabcutLayer->addPoint(event->scenePos(), event->button() == Qt::RightButton, false); + grabcutLayer->addPoint(event->scenePos(), background, false); } } @@ -89,6 +91,6 @@ void BlurLayerContainer::layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event) blurLayer->addPoint(event->scenePos().toPoint()); } else if(type == 1){ - grabcutLayer->addPoint(event->scenePos(), event->button() == Qt::RightButton, true); + grabcutLayer->addPoint(event->scenePos(), background, true); } } diff --git a/GraphicsScene/Container/blurlayercontainer.h b/GraphicsScene/Container/blurlayercontainer.h index 58374fb..88de6d3 100644 --- a/GraphicsScene/Container/blurlayercontainer.h +++ b/GraphicsScene/Container/blurlayercontainer.h @@ -17,6 +17,7 @@ class BlurLayerContainer : public LayerContainer GrabcutLayer* grabcutLayer; int type; int windowSize; + bool background; }; #endif // BLURLAYERCONTAINER_H diff --git a/GraphicsScene/Container/geolayercontainer.cpp b/GraphicsScene/Container/geolayercontainer.cpp index a8dc6ca..f7b28f0 100644 --- a/GraphicsScene/Container/geolayercontainer.cpp +++ b/GraphicsScene/Container/geolayercontainer.cpp @@ -119,6 +119,7 @@ void GeoLayerContainer::layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event){ return; } rectId++; + rectLayer->setRect(rect); rectLayer->setEnable(true); rectLayer->setEnableResize(true); rectLayer->setEnableScroll(true); @@ -132,6 +133,7 @@ void GeoLayerContainer::layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event){ return; } arrowId++; + arrowLayer->setLine(beginPoint, endPoint); arrowLayer->setEnable(true); area->addLayer(arrowLayer); break; diff --git a/GraphicsScene/Container/layercontainer.h b/GraphicsScene/Container/layercontainer.h index 82329d4..adc4536 100644 --- a/GraphicsScene/Container/layercontainer.h +++ b/GraphicsScene/Container/layercontainer.h @@ -12,12 +12,12 @@ class LayerContainer : public QObject { public: LayerContainer(PaintArea* area); - virtual ~LayerContainer(){ - } + virtual ~LayerContainer(){} virtual void layerMouseMoveEvent(QGraphicsSceneMouseEvent *event) {} virtual void layerMousePressEvent(QGraphicsSceneMouseEvent* event) {} virtual void layerMouseReleaseEvent(QGraphicsSceneMouseEvent* event) {} virtual QWidget* onValid(QWidget* widgetParent)=0; + virtual void onInvalid(){} protected: PaintArea* area; QWidget* widget; diff --git a/GraphicsScene/Container/paintlayercontainer.cpp b/GraphicsScene/Container/paintlayercontainer.cpp index ca13618..d7c8406 100644 --- a/GraphicsScene/Container/paintlayercontainer.cpp +++ b/GraphicsScene/Container/paintlayercontainer.cpp @@ -104,6 +104,7 @@ void PaintLayerContainer::layerMouseMoveEvent(QGraphicsSceneMouseEvent *event) { void PaintLayerContainer::layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event) { paintLayer->addPoint(event->scenePos()); + paintLayer->end(); paintId++; area->addLayer(paintLayer); } diff --git a/GraphicsScene/Layer/arrowlayer.cpp b/GraphicsScene/Layer/arrowlayer.cpp index fe2409e..0f1c3d2 100644 --- a/GraphicsScene/Layer/arrowlayer.cpp +++ b/GraphicsScene/Layer/arrowlayer.cpp @@ -3,9 +3,9 @@ ArrowLayer::ArrowLayer(const QPointF& beginPt, const QPointF& endPt, const QString& name, ILayerControl* manager, QGraphicsItem* parent) : LayerBase(name, manager, parent){ - setLine(beginPt, endPt); beginButton = new ExpandButton(ExpandButton::W, beginPt, this); endButton = new ExpandButton(ExpandButton::E, endPt, this); + setLine(beginPt, endPt); connect(beginButton, static_cast(&ExpandButton::posChange), this, &ArrowLayer::posChangeFunc); connect(endButton, static_cast(&ExpandButton::posChange), this, &ArrowLayer::posChangeFunc); setAcceptHoverEvents(true); @@ -13,6 +13,7 @@ ArrowLayer::ArrowLayer(const QPointF& beginPt, const QPointF& endPt, const QStri } void ArrowLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + painter->save(); painter->setRenderHint(QPainter::Antialiasing, true); //设置反走样,防锯齿 QPen pen(data.color, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); QBrush brush(data.color, Qt::SolidPattern); @@ -21,6 +22,7 @@ void ArrowLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option QLineF line(beginPt, endPt); painter->drawLine(line); painter->drawPolygon(arrow_points, 3); + painter->restore(); } QRectF ArrowLayer::boundingRect() const { @@ -91,6 +93,8 @@ void ArrowLayer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { void ArrowLayer::setLine(const QPointF& beginPt, const QPointF& endPt) { this->beginPt = beginPt; this->endPt = endPt; + beginButton->setPosition(beginPt); + endButton->setPosition(endPt); createArrow(); } @@ -165,3 +169,21 @@ int ArrowLayer::getZValue() const{ int ArrowLayer::type() const{ return 102400; } + +void ArrowLayer::prepareSave(){ + LayerBase::prepareSave(); + beginButton->hide(); + endButton->hide(); +} + +bool ArrowLayer::contains(const QPointF &point) const{ + if(QGraphicsObject::contains(point)) return true; + for(QGraphicsItem* item: childItems()) { + if(item->isVisible() && item->contains(item->mapFromParent(point)))return true; + } + return false; +} + +void ArrowLayer::onDelete(const QPointF &point){ + manager->removeThis(this); +} diff --git a/GraphicsScene/Layer/arrowlayer.h b/GraphicsScene/Layer/arrowlayer.h index 13dfcdc..ec136da 100644 --- a/GraphicsScene/Layer/arrowlayer.h +++ b/GraphicsScene/Layer/arrowlayer.h @@ -28,6 +28,9 @@ class ArrowLayer : public LayerBase void setEndPoint(const QPointF& point); int getZValue() const override; int type() const override; + void prepareSave() override; + bool contains(const QPointF& point)const override; + void onDelete(const QPointF &point) override; private slots: void posChangeFunc(ExpandButton::ButtonDirection dir, qreal x, qreal y); diff --git a/GraphicsScene/Layer/blurlayer.cpp b/GraphicsScene/Layer/blurlayer.cpp index 49cba2c..83ab703 100644 --- a/GraphicsScene/Layer/blurlayer.cpp +++ b/GraphicsScene/Layer/blurlayer.cpp @@ -43,7 +43,7 @@ void BlurLayer::addPoint(const QPoint &point) { QImage maskImage = image.copy(boundRect); Mat maskMat = ImageHelper::QImage2Mat(maskImage); Mat dst; - cv::GaussianBlur(maskMat, dst, Size(9, 9), 11); + cv::GaussianBlur(maskMat, dst, Size(11, 11), 11); maskImage = ImageHelper::Mat2QImage(dst); for(int i=leftTop.x(); igetOriginImage(); + QPoint leftTop = point - QPoint(windowSize, windowSize); + if(leftTop.x() < 0) leftTop.setX(0); + if(leftTop.y() < 0) leftTop.setY(0); + QPoint rightBotttom = point + QPoint(windowSize, windowSize); + if(rightBotttom.x() >= image.width()) rightBotttom.setX(image.width() - 1); + if(rightBotttom.y() >= image.height()) rightBotttom.setY(image.height() - 1); + QRectF boundRect(leftTop, rightBotttom); + if(boundRect.width() <= 0 || boundRect.height() <= 0) return; + for(int i=leftTop.x(); imodifyImage(QPoint(i, k), image.pixel(i, k)); + } + } + update(); +} + void BlurLayer::reset() { use.resize(0); } @@ -77,3 +97,11 @@ void BlurLayer::setEnable(bool enable, int index) { int BlurLayer::type() const{ return 102401; } + +QRectF BlurLayer::getSaveRect(){ + return QRectF(); +} + +void BlurLayer::onDelete(const QPointF &point){ + deletePoint(point.toPoint()); +} diff --git a/GraphicsScene/Layer/blurlayer.h b/GraphicsScene/Layer/blurlayer.h index ededcb8..1470158 100644 --- a/GraphicsScene/Layer/blurlayer.h +++ b/GraphicsScene/Layer/blurlayer.h @@ -17,7 +17,11 @@ class BlurLayer : public LayerBase void addPoint(const QPoint& point); void setEnable(bool enable, int index=0) override; int type() const override; + QRectF getSaveRect() override; + void onDelete(const QPointF &point) override; private: + void deletePoint(const QPoint& point); + QBitArray use; QRectF bound; int range; diff --git a/GraphicsScene/Layer/grabcutlayer.cpp b/GraphicsScene/Layer/grabcutlayer.cpp index 36e6d52..bc673cf 100644 --- a/GraphicsScene/Layer/grabcutlayer.cpp +++ b/GraphicsScene/Layer/grabcutlayer.cpp @@ -3,6 +3,7 @@ #include "../../Helper/imagehelper.h" #include "../../Helper/debug.h" #include +#include GrabcutLayer::GrabcutLayer(const QString& name, ILayerControl* manager, @@ -13,7 +14,7 @@ GrabcutLayer::GrabcutLayer(const QString& name, { handler = new GrabcutHandler(this); connect(handler, &GrabcutHandler::finish, this, [=](QImage mask){ - manager->maskImage(mask); + manager->remaskImage(mask); update(); }); } @@ -45,8 +46,13 @@ QRectF GrabcutLayer::boundingRect() const{ void GrabcutLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ if(enableShow){ QPen pen; - pen.setColor(QColor(255, 0, 0, 128)); pen.setWidth(5); + if(background) pen.setColor(QColor(0, 0, 255, 128)); + else pen.setColor(QColor(255, 0, 0, 128)); + painter->setPen(pen); + painter->drawPath(currentPath); + + pen.setColor(QColor(255, 0, 0, 128)); painter->setPen(pen); for(int i=0; idrawPath(foregroundPaths[i]); @@ -56,10 +62,6 @@ void GrabcutLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti for(int i=0; idrawPath(backgroundPaths[i]); } - if(background) pen.setColor(QColor(0, 0, 255, 128)); - else pen.setColor(QColor(255, 0, 0, 128)); - painter->setPen(pen); - painter->drawPath(currentPath); } } @@ -87,3 +89,47 @@ int GrabcutLayer::getZValue() const{ void GrabcutLayer::setEnableShow(){ enableShow = true; } + +QRectF GrabcutLayer::getSaveRect(){ + return QRectF(); +} + +void GrabcutLayer::prepareSave(){ + LayerBase::prepareSave(); + enableShow = false; +} + +void GrabcutLayer::deletePath(const QPointF &point){ + auto iter = foregroundPaths.begin(); + while(iter != foregroundPaths.end()){ + if(iter->contains(point)){ + iter = foregroundPaths.erase(iter); + } + else{ + iter++; + } + } + + auto iter2 = backgroundPaths.begin(); + while(iter2 != backgroundPaths.end()){ + if(iter2->contains(point)){ + iter2 = backgroundPaths.erase(iter2); + } + else{ + iter2++; + } + } + if(foregroundPaths.size() != 0 && backgroundPaths.size() != 0){ + handler->start(manager->getOriginImage(), foregroundPaths, backgroundPaths); + } + update(); +} + +void GrabcutLayer::onDelete(const QPointF &point){ + deletePath(point); +} + +void GrabcutLayer::startErase(){ + enableShow = true; + update(); +} diff --git a/GraphicsScene/Layer/grabcutlayer.h b/GraphicsScene/Layer/grabcutlayer.h index b8beca0..6654d1d 100644 --- a/GraphicsScene/Layer/grabcutlayer.h +++ b/GraphicsScene/Layer/grabcutlayer.h @@ -18,7 +18,12 @@ class GrabcutLayer : public LayerBase int type() const override; int getZValue() const override; void setEnableShow(); + QRectF getSaveRect() override; + void prepareSave() override; + void onDelete(const QPointF &point) override; + void startErase() override; private: + void deletePath(const QPointF& point); QList foregroundPaths; QList backgroundPaths; QPainterPath currentPath; diff --git a/GraphicsScene/Layer/layerbase.cpp b/GraphicsScene/Layer/layerbase.cpp index d7d9a07..0dd7b7d 100644 --- a/GraphicsScene/Layer/layerbase.cpp +++ b/GraphicsScene/Layer/layerbase.cpp @@ -4,7 +4,6 @@ LayerBase::LayerBase(const QString& name, ILayerControl* manager, QGraphicsItem* QGraphicsObject(parent), name(name), manager(manager), - erase(false), enable(false), isSaving(false) { @@ -15,10 +14,6 @@ bool LayerBase::isEnable(){ return enable; } -bool LayerBase::isErase(){ - return erase; -} - void LayerBase::prepareSave(){ isSaving = true; } @@ -31,10 +26,6 @@ QString LayerBase::getName() const{ return name; } -void LayerBase::setErase(bool enable){ - erase = enable; -} - void LayerBase::setEnable(bool enable, int index){ this->enable = enable; } @@ -45,6 +36,5 @@ int LayerBase::getZValue() const { void LayerBase::reset() { enable = false; - erase = false; isSaving = false; } diff --git a/GraphicsScene/Layer/layerbase.h b/GraphicsScene/Layer/layerbase.h index b4d5dc1..3c1d1dc 100644 --- a/GraphicsScene/Layer/layerbase.h +++ b/GraphicsScene/Layer/layerbase.h @@ -12,10 +12,8 @@ class LayerBase : public QGraphicsObject explicit LayerBase(const QString& name, ILayerControl* manager, QGraphicsItem* parent=nullptr); virtual ~LayerBase(){} bool isEnable(); - bool isErase(); QString getName()const; virtual const QString getHelp(){return "";}; - virtual void setErase(bool enable); virtual void setEnable(bool enable, int index=0); virtual void setParameter(const QString& name, const QVariant& var){}; virtual void prepareSave(); @@ -25,11 +23,13 @@ class LayerBase : public QGraphicsObject virtual void getFocus(){} virtual void loseFocus(){} virtual void onImageSet(){} + virtual QRectF getSaveRect(){return boundingRect();} + virtual void onDelete(const QPointF& point){} + virtual void startErase(){} protected: QString name; ILayerControl* manager; - bool erase; bool enable; bool isSaving; }; diff --git a/GraphicsScene/Layer/masklayer.cpp b/GraphicsScene/Layer/masklayer.cpp index 648e06f..b230b9e 100644 --- a/GraphicsScene/Layer/masklayer.cpp +++ b/GraphicsScene/Layer/masklayer.cpp @@ -260,3 +260,7 @@ void MaskLayer::setEnable(bool enable, int index){ int MaskLayer::type() const{ return 102404; } + +QRectF MaskLayer::getSaveRect(){ + return getClipRect(); +} diff --git a/GraphicsScene/Layer/masklayer.h b/GraphicsScene/Layer/masklayer.h index c1d730c..ee972d0 100644 --- a/GraphicsScene/Layer/masklayer.h +++ b/GraphicsScene/Layer/masklayer.h @@ -30,6 +30,7 @@ class MaskLayer : public ClipLayerBase int getZValue() const override; void setEnable(bool enable, int index=0) override; int type() const override; + QRectF getSaveRect() override; private: void addRegion(const QPolygonF& polygon); diff --git a/GraphicsScene/Layer/paintlayer.cpp b/GraphicsScene/Layer/paintlayer.cpp index 4d7f73d..dc186cb 100644 --- a/GraphicsScene/Layer/paintlayer.cpp +++ b/GraphicsScene/Layer/paintlayer.cpp @@ -1,5 +1,6 @@ #include "paintlayer.h" #include +#include PaintLayer::PaintLayer(const QString& name, ILayerControl* manager, @@ -7,10 +8,21 @@ PaintLayer::PaintLayer(const QString& name, LayerBase(name, manager, parent) { method = Smooth; + cachePix = QPixmap(manager->getImage().size()); + cachePix.fill(Qt::transparent); + isEnd = false; } QRectF PaintLayer::boundingRect() const { - return path.boundingRect(); + if(!isEnd){ + return QRectF(); + } + else{ + QRectF bound = path.boundingRect(); + bound.setTopLeft(bound.topLeft() - QPointF(pen.width(), pen.width())); + bound.setBottomRight(bound.bottomRight() + QPointF(pen.width(), pen.width())); + return bound; + } } QPainterPath PaintLayer::shape() const { @@ -18,39 +30,25 @@ QPainterPath PaintLayer::shape() const { } void PaintLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - painter->save(); - painter->setRenderHint(QPainter::Antialiasing, true); - painter->drawPath(path); - painter->restore(); + painter->drawPixmap(boundingRect().topLeft(), cachePix); } void PaintLayer::reset(){ manager->removeThis(this); } -void PaintLayer::mousePressEvent(QGraphicsSceneMouseEvent *event){ - -} - void PaintLayer::addPoint(const QPointF& point){ if(points.size() > 0){ QLineF line(point, points.last()); - if(line.length() < 2) return; + if(line.length() < 3) return; } - points.append(point); - switch (method) { - case Smooth: - path = SmoothCurveGenerator::generateSmoothCurve(points); - break; - case PaintPath: - if(points.size() == 1){ - path.moveTo(points[0]); - } - else{ - path.lineTo(points.last()); - } - break; + if(point.x() >= manager->getImage().width() || + point.y() >= manager->getImage().height() || + point.x() < 0 || point.y() < 0){ + return; } + points.append(point); + paintCache(); update(); } @@ -76,8 +74,22 @@ void PaintLayer::setEnable(bool enable, int index) { this->enable = false; } +void PaintLayer::paintCache(){ + if(points.size() < 2) return; + QPainter cachePainter(&cachePix); + cachePainter.setRenderHint(QPainter::Antialiasing, true); + cachePainter.setPen(pen); + QList subPoints; + subPoints.append(points[points.size()-2]); + subPoints.append(points.last()); + QList paintPoints = SmoothCurveGenerator::generateSmoothCurve(subPoints); + for(int i=1; i points, bool closed, double tension, int numberOfSegments) { +QList SmoothCurveGenerator::generateSmoothCurve(QList points, bool closed, double tension, int numberOfSegments) { QList ps; foreach (QPointF p, points) { @@ -87,9 +99,9 @@ QPainterPath SmoothCurveGenerator::generateSmoothCurve(QList points, bo return SmoothCurveGenerator::generateSmoothCurve(ps, closed, tension, numberOfSegments); } -QPainterPath SmoothCurveGenerator::generateSmoothCurve(QList points, bool closed, double tension, int numberOfSegments) { +QList SmoothCurveGenerator::generateSmoothCurve(QList points, bool closed, double tension, int numberOfSegments) { if(points.size() < 4){ - return QPainterPath(); + return QList(); } QList ps(points); // clone array so we don't change the original points QList result; // generated smooth curve coordinates @@ -144,20 +156,60 @@ QPainterPath SmoothCurveGenerator::generateSmoothCurve(QList points, boo } } - // 使用的平滑曲线的坐标创建 QPainterPath - QPainterPath path; - path.moveTo(result[0], result[1]); - for (int i = 2; i < result.length() - 2; i += 2) { - path.lineTo(result[i+0], result[i+1]); + QList resPoints; + for(int i=0; iremoveThis(this); +} + +void PaintLayer::end(){ + prepareGeometryChange(); + switch (method) { + case Smooth:{ + QList smoothPoints = SmoothCurveGenerator::generateSmoothCurve(points); + path = buildPath(smoothPoints); + break; } + case PaintPath:{ + if(points.size() == 1){ + path.moveTo(points[0]); + } + else{ + path.lineTo(points.last()); + } + break; + } + } + isEnd = true; + cachePix.fill(Qt::transparent); + QPainter* cachePainter = new QPainter(&cachePix); + cachePainter->setRenderHint(QPainter::Antialiasing, true); + cachePainter->setPen(pen); + cachePainter->drawPath(path); + delete cachePainter; + cachePix = cachePix.copy(boundingRect().toRect()); +} +QPainterPath PaintLayer::buildPath(QList points){ + if(points.size() <= 1) return QPainterPath(); + QPainterPath path; + path.moveTo(points[0]); + for (int i=1; i < points.length(); i++) { + path.lineTo(points[i]); + } return path; } -int PaintLayer::type() const{ - return 102405; +int PaintLayer::getZValue() const{ + return 1; } diff --git a/GraphicsScene/Layer/paintlayer.h b/GraphicsScene/Layer/paintlayer.h index cd95a3b..80a420e 100644 --- a/GraphicsScene/Layer/paintlayer.h +++ b/GraphicsScene/Layer/paintlayer.h @@ -15,17 +15,26 @@ class PaintLayer : public LayerBase { void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; QRectF boundingRect()const override; QPainterPath shape()const override; - void mousePressEvent(QGraphicsSceneMouseEvent *event) override; void addPoint(const QPointF& point); void setMethod(PaintMethod method); void setParameter(const QString &name, const QVariant &var) override; void setEnable(bool enable, int index=0) override; int type() const override; + void onDelete(const QPointF &point) override; + void end(); + int getZValue() const override; + +private: + QPainterPath buildPath(QList points); + void paintCache(); + private: QList points; PaintMethod method; QPainterPath path; QPen pen; + QPixmap cachePix; + bool isEnd; }; class SmoothCurveGenerator { @@ -33,7 +42,7 @@ class SmoothCurveGenerator { /** * @brief generateSmoothCurve 的重载函数 */ - static QPainterPath generateSmoothCurve(QList points, bool closed = false, double tension = 0.5, int numberOfSegments = 16); + static QList generateSmoothCurve(QList points, bool closed = false, double tension = 0.5, int numberOfSegments = 16); /** * @brief 使用传入的曲线顶点坐标创建平滑曲线。 @@ -46,7 +55,7 @@ class SmoothCurveGenerator { * @param numberOfSegments 平滑曲线 2 个顶点间的线段数,默认为 16 * @return 平滑曲线的 QPainterPath */ - static QPainterPath generateSmoothCurve(QListpoints, bool closed = false, double tension = 0.5, int numberOfSegments = 16); + static QList generateSmoothCurve(QListpoints, bool closed = false, double tension = 0.5, int numberOfSegments = 16); }; #endif // PAINTLAYER_H diff --git a/GraphicsScene/Layer/piclayer.cpp b/GraphicsScene/Layer/piclayer.cpp index 29ab143..0208b4b 100644 --- a/GraphicsScene/Layer/piclayer.cpp +++ b/GraphicsScene/Layer/piclayer.cpp @@ -74,3 +74,10 @@ void PicLayer::setEnable(bool enable, int index) { int PicLayer::type() const{ return 102406; } + +QRectF PicLayer::getSaveRect(){ + if(enableBound){ + return mask; + } + return QRectF(); +} diff --git a/GraphicsScene/Layer/piclayer.h b/GraphicsScene/Layer/piclayer.h index 8ce4599..309164e 100644 --- a/GraphicsScene/Layer/piclayer.h +++ b/GraphicsScene/Layer/piclayer.h @@ -17,6 +17,7 @@ class PicLayer : public LayerBase void reset() override; void setEnable(bool enable, int index=0) override; int type() const override; + QRectF getSaveRect() override; private: bool enableBound; RectLayer* rectLayer; diff --git a/GraphicsScene/Layer/rectlayer.cpp b/GraphicsScene/Layer/rectlayer.cpp index ce4d5f2..aff786e 100644 --- a/GraphicsScene/Layer/rectlayer.cpp +++ b/GraphicsScene/Layer/rectlayer.cpp @@ -61,7 +61,6 @@ void RectLayer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { } void RectLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - painter->setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing, true); paintStyle(painter); painter->drawRect(this->boundingRect()); } @@ -188,12 +187,14 @@ bool RectLayer::contains(const QPointF &point) const { void RectLayer::prepareSave(){ LayerBase::prepareSave(); - showButtons(); + for (ExpandButton* button: buttons) { + button->hide(); + } + if(scrollItem != NULL) scrollItem->hide(); } void RectLayer::endSave(){ LayerBase::endSave(); - hideButtons(); } void RectLayer::initButtons(){ @@ -266,3 +267,7 @@ void RectLayer::setRect(const QRectF &rect){ int RectLayer::type() const{ return 102407; } + +void RectLayer::onDelete(const QPointF &point){ + manager->removeThis(this); +} diff --git a/GraphicsScene/Layer/rectlayer.h b/GraphicsScene/Layer/rectlayer.h index f827873..21d01ef 100644 --- a/GraphicsScene/Layer/rectlayer.h +++ b/GraphicsScene/Layer/rectlayer.h @@ -37,6 +37,7 @@ class RectLayer : public LayerBase void setButtonFocus(bool enable); void setRect(const QRectF& rect); int type() const override; + void onDelete(const QPointF &point) override; signals: void sizeChange(); diff --git a/GraphicsScene/Layer/rootlayer.cpp b/GraphicsScene/Layer/rootlayer.cpp index bc3761d..c6caa28 100644 --- a/GraphicsScene/Layer/rootlayer.cpp +++ b/GraphicsScene/Layer/rootlayer.cpp @@ -3,6 +3,9 @@ RootLayer::RootLayer(PaintArea* area, QGraphicsItem* parent) : QGraphicsItem(parent) { + erase = false; + press = false; + this->area = area; area->addItem(this); } @@ -15,13 +18,29 @@ void RootLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, } void RootLayer::mousePressEvent(QGraphicsSceneMouseEvent *event){ - + press = true; } void RootLayer::mouseMoveEvent(QGraphicsSceneMouseEvent *event){ - + if(press && erase){ + deleteChild(event->scenePos()); + } } void RootLayer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ + press = false; +} + +void RootLayer::setErase(bool enable){ + erase = enable; +} +void RootLayer::deleteChild(const QPointF& point){ + QList layers = area->getLayers(); + for(auto& layer : layers){ + QPointF point1 = layer->mapFromParent(point); + if(layer->contains(point1) && layer->isVisible()){ + layer->onDelete(point1); + } + } } diff --git a/GraphicsScene/Layer/rootlayer.h b/GraphicsScene/Layer/rootlayer.h index b0a2a79..b6744c4 100644 --- a/GraphicsScene/Layer/rootlayer.h +++ b/GraphicsScene/Layer/rootlayer.h @@ -13,8 +13,12 @@ class RootLayer : public QGraphicsItem void mousePressEvent(QGraphicsSceneMouseEvent *event) override; void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; + void setErase(bool enable); private: + void deleteChild(const QPointF& point); PaintArea* area; + bool erase; + bool press; }; #endif // ROOTLAYER_H diff --git a/GraphicsScene/Layer/textlayer.cpp b/GraphicsScene/Layer/textlayer.cpp index c2af8cb..a7275e6 100644 --- a/GraphicsScene/Layer/textlayer.cpp +++ b/GraphicsScene/Layer/textlayer.cpp @@ -79,3 +79,7 @@ bool TextLayer::contains(const QPointF &point) const{ int TextLayer::type() const{ return 102408; } + +void TextLayer::onDelete(const QPointF &point){ + manager->removeThis(this); +} diff --git a/GraphicsScene/Layer/textlayer.h b/GraphicsScene/Layer/textlayer.h index ac84c45..a510b84 100644 --- a/GraphicsScene/Layer/textlayer.h +++ b/GraphicsScene/Layer/textlayer.h @@ -22,7 +22,7 @@ class TextLayer : public LayerBase const QString getHelp() override; bool contains(const QPointF& point)const override; int type() const override; - + void onDelete(const QPointF &point) override; signals: void formatChange(const QFont& font, const QBrush& brush); diff --git a/GraphicsScene/Widgets/clipregion.cpp b/GraphicsScene/Widgets/clipregion.cpp index 10854ee..7b32b2d 100644 --- a/GraphicsScene/Widgets/clipregion.cpp +++ b/GraphicsScene/Widgets/clipregion.cpp @@ -145,6 +145,10 @@ void ClipRegion::remapPoint() button_num++; } } + int buttonSize = buttons.size(); + for(int i=button_num; i +#include "../../Paint/Widgets/history.h" DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar(area, parent) { @@ -23,6 +25,40 @@ DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar( TextLayerContainer* textLayerContainer = new TextLayerContainer(area); addContainer("text", "", textLayerContainer, true); + QToolButton* eraseButton = new QToolButton(this); + eraseButton->setIcon(ImageHelper::getIcon("eraser")); + eraseButton->setToolTip(MString::search("{7cwKObEhcx}擦除")); + addContainer(eraseButton, + [=](){area->setEnable(false);area->setEraseEnable(true);}, + [=](){area->setEraseEnable(false);}, true); + + addSeparator(); + + QToolButton* clipButton = new QToolButton(this); + clipButton->setIcon(ImageHelper::getIcon("clipboard")); + clipButton->setToolTip(MString::search("{ntbJbEqxwF}复制到剪切板")); + connect(clipButton, &QToolButton::clicked, this, [=]() { + if(area->save(ILayerControl::ClipBoard, "")) + WindowManager::changeWindow("tray"); + }); + addWidget(clipButton); + + QToolButton* saveButton = new QToolButton(this); + saveButton->setIcon(ImageHelper::getIcon("save")); + saveButton->setToolTip(MString::search("{pJqTHhEQdb}保存")); + connect(saveButton, &QToolButton::clicked, this, [=]() { + QString fileName = QFileDialog::getSaveFileName(parent, + "保存", + History::instance()->get_last_directory(), + "图片(*.bmp *.jpg *.jpeg *.png);;所有文件(*)"); + if(fileName != "") { + if(area->save(ILayerControl::Persist, fileName)) + WindowManager::changeWindow("tray"); + } + }); + addWidget(saveButton); + + ClipLayerBase* clipLayer = area->getClipLayer(); if(clipLayer != NULL){ connect(clipLayer, &ClipLayerBase::boundChangeBegin, this, [=](){ @@ -33,5 +69,6 @@ DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar( showAll(); }); } - hide(); + adjustSize(); + hideAll(); } diff --git a/GraphicsScene/Widgets/grabcuthandler.cpp b/GraphicsScene/Widgets/grabcuthandler.cpp index 3f05532..9ba3892 100644 --- a/GraphicsScene/Widgets/grabcuthandler.cpp +++ b/GraphicsScene/Widgets/grabcuthandler.cpp @@ -19,13 +19,13 @@ GrabcutHandler::GrabcutHandler(QObject* parent) connect(this, &GrabcutHandler::startWork, worker, &GrabcutWorker::work); connect(worker, &GrabcutWorker::finish, this, [=](QImage mask){ emit finish(mask); + _finish = true; + working = false; if(waiting){ emit startWork(waitImage, waitfgd, waitbgd); waiting = false; return; } - _finish = true; - working = false; }); thread.start(); } @@ -58,6 +58,7 @@ GrabcutWorker::GrabcutWorker(QObject* parent) : QObject(parent){ } void GrabcutWorker::work(QImage image, QList fgd, QList bgd){ + image.save("D:/Temp/" + QString::number(QDateTime::currentMSecsSinceEpoch()) + ".png"); cv::Mat inputMat = ImageHelper::QImage2Mat(image); cv::cvtColor(inputMat, inputMat, cv::COLOR_RGBA2RGB); @@ -67,17 +68,7 @@ void GrabcutWorker::work(QImage image, QList fgd, QList fgd, QListsetExclusive(true); connect(group, static_cast(&QButtonGroup::buttonClicked), this, &LayerToolBar::onGroupClick); @@ -46,6 +47,23 @@ void LayerToolBar::addContainer(const QString &icon, addContainer(toolButton, container, exclude); } +void LayerToolBar::addContainer(QToolButton* button, std::functionconst& f, std::functionconst& leavef, bool exclude){ + if(!exclude){ + connect(button, &QToolButton::clicked, this, f); + } + else{ + button->setCheckable(true); + button->setChecked(false); + group->addButton(button, groupId); + validF[groupId] = f; + invalidF[groupId] = leavef; + groupId++; + containers.append(NULL); + } + addWidget(button); + adjustSize(); +} + void LayerToolBar::moveTo(const QRectF& mask){ this->mask = mask; if(!isVisible()) @@ -98,9 +116,9 @@ void LayerToolBar::setContainer(LayerContainer *container){ } void LayerToolBar::onGroupClick(int id){ - area->setContainer(containers[id]); - QWidget* widget = containers[id]->onValid(attributeBar); - attributeBar->showWidget(widget); + execInvalid(beforeId); + execValid(id); + beforeId = id; moveTo(mask); } @@ -113,3 +131,33 @@ void LayerToolBar::showAll(){ show(); attributeBar->show(); } + +void LayerToolBar::execValid(int id){ + if(containers[id] != NULL){ + area->setContainer(containers[id]); + QWidget* widget = containers[id]->onValid(attributeBar); + attributeBar->showWidget(widget); + } + else{ + auto f = validF.find(id); + if(f != validF.end()){ + f.value()(); + } + area->setContainer(NULL); + attributeBar->adjustSize(); + } +} + +void LayerToolBar::execInvalid(int id){ + if(containers[id] != NULL){ + area->setContainer(containers[id]); + containers[id]->onInvalid(); + } + else{ + auto f = invalidF.find(id); + if(f != invalidF.end()){ + f.value()(); + } + attributeBar->adjustSize(); + } +} diff --git a/GraphicsScene/Widgets/layertoolbar.h b/GraphicsScene/Widgets/layertoolbar.h index 679b3e4..7d766f7 100644 --- a/GraphicsScene/Widgets/layertoolbar.h +++ b/GraphicsScene/Widgets/layertoolbar.h @@ -14,6 +14,7 @@ class LayerToolBar : public QToolBar const QString& tip, LayerContainer* container, bool exclude = false); + void addContainer(QToolButton* button, std::functionconst& f, std::functionconst& leavef, bool exclude=false); void moveTo(const QRectF& mask); void setBound(const QRectF& bound); void setContainer(LayerContainer* container); @@ -23,14 +24,21 @@ class LayerToolBar : public QToolBar private slots: void onGroupClick(int id); +private: + void execValid(int id); + void execInvalid(int id); + private: PaintArea* area; QButtonGroup* group; int groupId; AttributeToolbar* attributeBar; QList containers; + QMap> validF; + QMap> invalidF; QRectF mask; QRectF bound; + int beforeId; }; #endif // LAYERTOOLBAR_H diff --git a/GraphicsScene/ilayercontrol.cpp b/GraphicsScene/ilayercontrol.cpp index 4535cec..7415691 100644 --- a/GraphicsScene/ilayercontrol.cpp +++ b/GraphicsScene/ilayercontrol.cpp @@ -1,4 +1,7 @@ #include "ilayercontrol.h" +#include +#include +#include ILayerControl::ILayerControl() { @@ -22,7 +25,9 @@ void ILayerControl::modifyImage(const QPoint &pos, const QColor& color){ modifiedImage = image.copy(); } modified = true; - modifiedImage.setPixel(pos, color.rgba()); + QRgb* line = (QRgb*)modifiedImage.scanLine(pos.y()); + line[pos.x()] = color.rgb(); +// modifiedImage.setPixel(pos, color.rgba()); } bool ILayerControl::isImageValid(){ @@ -34,5 +39,30 @@ void ILayerControl::maskImage(const QImage &mask){ modifiedImage = image.copy(); } modified = true; - modifiedImage.setAlphaChannel(mask); + for(int i=0; i 8) return; + if(!modified){ + modifiedImage = image.copy(); + } + modified = true; + for(int i=0; iisEnable() || layer->isErase()) && layer->contains(layer->mapFromScene(event->scenePos()))){ + if((layer->isEnable()) && layer->contains(layer->mapFromScene(event->scenePos()))){ // sendEvent(layer, event); inLayer = true; mouseGrabber = layer; @@ -32,10 +32,12 @@ void PaintArea::mousePressEvent(QGraphicsSceneMouseEvent *event){ if(!inLayer){ if(container != NULL) container->layerMousePressEvent(event); } + sendEvent(rootLayer, event); QGraphicsScene::mousePressEvent(event); } void PaintArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event){ + sendEvent(rootLayer, event); QGraphicsScene::mouseMoveEvent(event); if(!inLayer && press){ if(container != NULL) container->layerMouseMoveEvent(event); @@ -48,26 +50,27 @@ void PaintArea::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ if(!inLayer && press){ press = false; if(container != NULL) container->layerMouseReleaseEvent(event); - return; } else{ press = false; } // if(press) sendEvent(mouseGrabber, event); inLayer = false; + sendEvent(rootLayer, event); QGraphicsScene::mouseReleaseEvent(event); } bool PaintArea::save(SaveType type, const QString &path){ - if(path == "") { + if(path == "" && type != ClipBoard) { return false; } for(auto& layer: layers){ layer->prepareSave(); } + update(); QRectF bound; for(auto& layer: layers){ - bound = bound.united(layer->boundingRect()); + bound = bound.united(layer->getSaveRect()); } if(bound == QRectF(0, 0, 0, 0)) @@ -101,9 +104,11 @@ bool PaintArea::save(SaveType type, const QString &path){ } void PaintArea::setEraseEnable(bool enable){ - for(auto iter=layers.begin(); iter!=layers.end(); iter++){ - iter.value()->setErase(enable); + changeFocusLayer(NULL); + for(auto layer : layers){ + layer->startErase(); } + rootLayer->setErase(enable); } void PaintArea::setEnable(bool enable, int index){ From 24cb397e429ae49af83790feca7c9484437aa5f3 Mon Sep 17 00:00:00 2001 From: xinhecuican <2686462757@qq.com> Date: Tue, 12 Dec 2023 21:18:43 +0800 Subject: [PATCH 06/11] =?UTF-8?q?recorder=E9=87=8D=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GraphicsScene/Container/geolayercontainer.cpp | 6 + .../Container/paintlayercontainer.cpp | 3 + GraphicsScene/Layer/arrowlayer.cpp | 8 +- GraphicsScene/Layer/arrowlayer.h | 1 + GraphicsScene/Layer/layerbase.h | 1 + GraphicsScene/Layer/paintlayer.cpp | 8 +- GraphicsScene/Layer/paintlayer.h | 1 + GraphicsScene/Layer/rectlayer.cpp | 9 +- GraphicsScene/Layer/rectlayer.h | 1 + GraphicsScene/Recorder/layerrecord.cpp | 25 +++ GraphicsScene/Recorder/layerrecord.h | 18 ++ GraphicsScene/Recorder/recordbase.h | 17 ++ GraphicsScene/Recorder/recorder.cpp | 46 +++++ GraphicsScene/Recorder/recorder.h | 177 ++++++++++++++++++ GraphicsScene/Widgets/defaulttoolbar.cpp | 28 +++ GraphicsScene/ilayercontrol.h | 2 + GraphicsScene/paintarea.cpp | 15 +- GraphicsScene/paintarea.h | 7 + capture.pro | 5 + 19 files changed, 374 insertions(+), 4 deletions(-) create mode 100644 GraphicsScene/Recorder/layerrecord.cpp create mode 100644 GraphicsScene/Recorder/layerrecord.h create mode 100644 GraphicsScene/Recorder/recordbase.h create mode 100644 GraphicsScene/Recorder/recorder.cpp create mode 100644 GraphicsScene/Recorder/recorder.h diff --git a/GraphicsScene/Container/geolayercontainer.cpp b/GraphicsScene/Container/geolayercontainer.cpp index f7b28f0..f2b2486 100644 --- a/GraphicsScene/Container/geolayercontainer.cpp +++ b/GraphicsScene/Container/geolayercontainer.cpp @@ -7,6 +7,7 @@ #include "../../Helper/math.h" #include "../paintarea.h" #include +#include "../Recorder/layerrecord.h" GeoLayerContainer::GeoLayerContainer(PaintArea* area) : LayerContainer(area), @@ -89,6 +90,7 @@ void GeoLayerContainer::layerMousePressEvent(QGraphicsSceneMouseEvent *event){ } case ARROW: { arrowLayer = new ArrowLayer(beginPoint, beginPoint + QPointF(1, 1), "arrow" + QString::number(arrowId), area, area->getRootLayer()); + arrowLayer->setZValue(arrowLayer->getZValue()); arrowLayer->setEnable(false); break; } @@ -118,6 +120,8 @@ void GeoLayerContainer::layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event){ rectLayer->deleteLater(); return; } + LayerRecord* record = new LayerRecord(true, rectLayer, (rectLayer->type() << 4) + rectId); + area->record(record); rectId++; rectLayer->setRect(rect); rectLayer->setEnable(true); @@ -132,6 +136,8 @@ void GeoLayerContainer::layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event){ arrowLayer->deleteLater(); return; } + LayerRecord* record = new LayerRecord(true, arrowLayer, (arrowLayer->type() << 4) + arrowId); + area->record(record); arrowId++; arrowLayer->setLine(beginPoint, endPoint); arrowLayer->setEnable(true); diff --git a/GraphicsScene/Container/paintlayercontainer.cpp b/GraphicsScene/Container/paintlayercontainer.cpp index d7c8406..0e771ae 100644 --- a/GraphicsScene/Container/paintlayercontainer.cpp +++ b/GraphicsScene/Container/paintlayercontainer.cpp @@ -7,6 +7,7 @@ #include "../../Helper/math.h" #include "../paintarea.h" #include +#include "../Recorder/layerrecord.h" PaintLayerContainer::PaintLayerContainer(PaintArea* area) : LayerContainer(area), @@ -105,6 +106,8 @@ void PaintLayerContainer::layerMouseMoveEvent(QGraphicsSceneMouseEvent *event) { void PaintLayerContainer::layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event) { paintLayer->addPoint(event->scenePos()); paintLayer->end(); + LayerRecord* record = new LayerRecord(true, paintLayer, (paintLayer->type() << 4) + paintId); + area->record(record); paintId++; area->addLayer(paintLayer); } diff --git a/GraphicsScene/Layer/arrowlayer.cpp b/GraphicsScene/Layer/arrowlayer.cpp index 0f1c3d2..14fab37 100644 --- a/GraphicsScene/Layer/arrowlayer.cpp +++ b/GraphicsScene/Layer/arrowlayer.cpp @@ -1,5 +1,6 @@ #include "arrowlayer.h" #include "../../Manager/uimanager.h" +#include "../Recorder/layerrecord.h" ArrowLayer::ArrowLayer(const QPointF& beginPt, const QPointF& endPt, const QString& name, ILayerControl* manager, QGraphicsItem* parent) : LayerBase(name, manager, parent){ @@ -10,6 +11,9 @@ ArrowLayer::ArrowLayer(const QPointF& beginPt, const QPointF& endPt, const QStri connect(endButton, static_cast(&ExpandButton::posChange), this, &ArrowLayer::posChangeFunc); setAcceptHoverEvents(true); data = UIManager::instance()->getArrowData(); + if(name != ""){ + index = name.mid(5).toInt(); + } } void ArrowLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { @@ -185,5 +189,7 @@ bool ArrowLayer::contains(const QPointF &point) const{ } void ArrowLayer::onDelete(const QPointF &point){ - manager->removeThis(this); + hide(); + LayerRecord* record = new LayerRecord(false, this, (type() << 4) + index); + manager->record(record); } diff --git a/GraphicsScene/Layer/arrowlayer.h b/GraphicsScene/Layer/arrowlayer.h index ec136da..96998dc 100644 --- a/GraphicsScene/Layer/arrowlayer.h +++ b/GraphicsScene/Layer/arrowlayer.h @@ -48,6 +48,7 @@ private slots: ExpandButton* endButton; QCursor outCursor; PaintData data; + int index; const float ExtRefArrowLenght = 10;//箭头末端大小的长度, const float ExtRefArrowDegrees = M_PI / 6;//箭头末端顶角的一半 }; diff --git a/GraphicsScene/Layer/layerbase.h b/GraphicsScene/Layer/layerbase.h index 3c1d1dc..41c6598 100644 --- a/GraphicsScene/Layer/layerbase.h +++ b/GraphicsScene/Layer/layerbase.h @@ -26,6 +26,7 @@ class LayerBase : public QGraphicsObject virtual QRectF getSaveRect(){return boundingRect();} virtual void onDelete(const QPointF& point){} virtual void startErase(){} + virtual void release(){manager->removeThis(this);} protected: QString name; diff --git a/GraphicsScene/Layer/paintlayer.cpp b/GraphicsScene/Layer/paintlayer.cpp index dc186cb..7ddee6e 100644 --- a/GraphicsScene/Layer/paintlayer.cpp +++ b/GraphicsScene/Layer/paintlayer.cpp @@ -1,6 +1,7 @@ #include "paintlayer.h" #include #include +#include "../Recorder/layerrecord.h" PaintLayer::PaintLayer(const QString& name, ILayerControl* manager, @@ -11,6 +12,9 @@ PaintLayer::PaintLayer(const QString& name, cachePix = QPixmap(manager->getImage().size()); cachePix.fill(Qt::transparent); isEnd = false; + if(name != ""){ + index = name.mid(4).toInt(); + } } QRectF PaintLayer::boundingRect() const { @@ -169,7 +173,9 @@ int PaintLayer::type() const{ } void PaintLayer::onDelete(const QPointF &point){ - manager->removeThis(this); + hide(); + LayerRecord* record = new LayerRecord(false, this, (type() << 4) + index); + manager->record(record); } void PaintLayer::end(){ diff --git a/GraphicsScene/Layer/paintlayer.h b/GraphicsScene/Layer/paintlayer.h index 80a420e..3c9a51b 100644 --- a/GraphicsScene/Layer/paintlayer.h +++ b/GraphicsScene/Layer/paintlayer.h @@ -35,6 +35,7 @@ class PaintLayer : public LayerBase { QPen pen; QPixmap cachePix; bool isEnd; + int index; }; class SmoothCurveGenerator { diff --git a/GraphicsScene/Layer/rectlayer.cpp b/GraphicsScene/Layer/rectlayer.cpp index aff786e..03c5ecd 100644 --- a/GraphicsScene/Layer/rectlayer.cpp +++ b/GraphicsScene/Layer/rectlayer.cpp @@ -1,5 +1,6 @@ #include "rectlayer.h" #include +#include "../Recorder/layerrecord.h" RectLayer::RectLayer( const QRectF& rect, @@ -21,6 +22,9 @@ RectLayer::RectLayer( setPos(rect.topLeft()); this->rect = QRectF(QPointF(0, 0), QSize(rect.width(), rect.height())); setBounding(this->rect); + if(name != ""){ + index = name.mid(4).toInt(); + } } void RectLayer::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { @@ -269,5 +273,8 @@ int RectLayer::type() const{ } void RectLayer::onDelete(const QPointF &point){ - manager->removeThis(this); + hide(); + update(); + LayerRecord* record = new LayerRecord(false, this, (type() << 4) + index); + manager->record(record); } diff --git a/GraphicsScene/Layer/rectlayer.h b/GraphicsScene/Layer/rectlayer.h index 21d01ef..c80c430 100644 --- a/GraphicsScene/Layer/rectlayer.h +++ b/GraphicsScene/Layer/rectlayer.h @@ -59,6 +59,7 @@ private slots: PaintData paintData; QPointF beginPoint; QCursor outCursor; + int index; }; #endif // RECTLAYER_H diff --git a/GraphicsScene/Recorder/layerrecord.cpp b/GraphicsScene/Recorder/layerrecord.cpp new file mode 100644 index 0000000..aead0cd --- /dev/null +++ b/GraphicsScene/Recorder/layerrecord.cpp @@ -0,0 +1,25 @@ +#include "layerrecord.h" + +LayerRecord::LayerRecord(bool show, LayerBase* layer, int type) + : RecordBase(type), + layer(layer), + show(show) +{ + +} + +void LayerRecord::undo(){ + if(show) layer->hide(); + else layer->show(); + layer->update(); +} + +void LayerRecord::redo(){ + if(show) layer->show(); + else layer->hide(); + layer->update(); +} + +void LayerRecord::release(){ + layer->release(); +} diff --git a/GraphicsScene/Recorder/layerrecord.h b/GraphicsScene/Recorder/layerrecord.h new file mode 100644 index 0000000..543a651 --- /dev/null +++ b/GraphicsScene/Recorder/layerrecord.h @@ -0,0 +1,18 @@ +#ifndef LAYERRECORD_H +#define LAYERRECORD_H +#include "recordbase.h" +#include "../Layer/layerbase.h" + +class LayerRecord : public RecordBase +{ +public: + LayerRecord(bool show, LayerBase* layer, int type); + void redo() override; + void undo() override; + void release() override; +private: + LayerBase* layer; + bool show; +}; + +#endif // LAYERRECORD_H diff --git a/GraphicsScene/Recorder/recordbase.h b/GraphicsScene/Recorder/recordbase.h new file mode 100644 index 0000000..6940a8e --- /dev/null +++ b/GraphicsScene/Recorder/recordbase.h @@ -0,0 +1,17 @@ +#ifndef RECORDBASE_H +#define RECORDBASE_H + + +class RecordBase +{ +public: + RecordBase(){type = 0;} + RecordBase(int index){this->type = index;} + virtual ~RecordBase(){} + virtual void undo()=0; + virtual void redo()=0; + virtual void release()=0; + int type; +}; + +#endif // RECORDBASE_H diff --git a/GraphicsScene/Recorder/recorder.cpp b/GraphicsScene/Recorder/recorder.cpp new file mode 100644 index 0000000..a2cdf9f --- /dev/null +++ b/GraphicsScene/Recorder/recorder.cpp @@ -0,0 +1,46 @@ +#include "recorder.h" +#include + +Recorder::Recorder(QObject* parent) : QObject(parent) +{ +} + +Recorder::~Recorder() +{ + stack.free(); +} + +void Recorder::back() +{ + stack.pop(); + emit recordChange(); +} + +void Recorder::forward() +{ + stack.forward(); + emit recordChange(); +} + +void Recorder::record(RecordBase* element) +{ + stack.push(element); + emit recordChange(); +} + + +void Recorder::reset() +{ + stack.reset(); + emit recordChange(); +} + +bool Recorder::undoAvailiable() +{ + return stack.canUndo(); +} + +bool Recorder::redoAvailiable() +{ + return stack.canRedo(); +} diff --git a/GraphicsScene/Recorder/recorder.h b/GraphicsScene/Recorder/recorder.h new file mode 100644 index 0000000..5e3fa54 --- /dev/null +++ b/GraphicsScene/Recorder/recorder.h @@ -0,0 +1,177 @@ +#ifndef Recorder_H +#define Recorder_H +#include +#include "recordbase.h" +#include +#include "../../Helper/debug.h" +#include +#include +#include + +class Recorder : public QObject +{ + Q_OBJECT +public: + Recorder(QObject* parent=nullptr); + ~Recorder(); + void record(RecordBase* record); + void reset(); + void back(); + void forward(); + bool undoAvailiable(); + bool redoAvailiable(); +signals: + void recordChange(); + +private: + struct RecordElement{ + RecordElement* next; + RecordElement* before; + RecordElement* siblingBefore; + RecordElement* siblingNext; + RecordBase* record; + RecordElement(){ + next = NULL; + before = NULL; + record = NULL; + siblingNext = NULL; + siblingBefore = NULL; + } + RecordElement(RecordBase* record){ + next = NULL; + before = NULL; + this->record = record; + siblingNext = NULL; + siblingBefore = NULL; + } + RecordElement(RecordElement* before, RecordElement* next, RecordBase* record){ + this->before = before; + this->next = next; + this->record = record; + siblingNext = NULL; + siblingBefore = NULL; + } + }; + + struct RecordStack{ + int limit; + int index; + RecordElement* root; + RecordElement* current; + QMap> siblingMap; + RecordStack() + : limit(0), + index(0){ + root = new RecordElement; + root->next = root; + root->before = root; + current = root; + } + + void reset(){ + RecordElement* iter = root->next + ; + while(iter->next != root){ + RecordElement* temp = iter; + iter = iter->next; + delete temp; + } + root->next = root; + root->before = root; + current = root; + limit = 0; + index = 0; + } + + void free(){ + reset(); + delete root; + } + + bool canUndo(){ + return index > 0; + } + + bool canRedo(){ + return index < limit; + } + + void push(RecordBase* record){ + if(current->next == root){ + RecordElement* recordElement = new RecordElement(current, current->next, record); + current->next->before = recordElement; + current->next = recordElement; + addSibling(record, recordElement); + current = recordElement; + } + else{ + current = current->next; + removeSibling(); + addSibling(record, current); + current->record->release(); + current->record = record; + } + index++; + limit = index; + } + + void forward(){ + if(!canRedo()) return; + current = current->next; + current->record->redo(); + index++; + } + + void pop(){ + if(!canUndo()) return; + current->record->undo(); + current = current->before; + index--; + } + + void addSibling(RecordBase* record, RecordElement* recordElement){ + recordElement->siblingNext = NULL; + recordElement->siblingBefore = NULL; + auto find = siblingMap.find(record->type); + if(find != siblingMap.end()){ + find.value().second->siblingNext = recordElement; + recordElement->siblingBefore = find.value().second; + } + else{ + siblingMap.insert(record->type, QPair(recordElement, recordElement)); + } + } + + void removeSibling(){ + auto find = siblingMap.find(current->record->type); + if(find != siblingMap.end()){ + if(find.value().first == current){ + RecordElement* tmp = current->siblingNext; + while(tmp != NULL){ + tmp->before->next = tmp->next; + tmp->next->before = tmp->before; + RecordElement* tmp1 = tmp; + tmp = tmp->siblingNext; + delete tmp1; + } + siblingMap.remove(current->record->type); + } + else{ + if(current == find.value().second){ + siblingMap[current->record->type].second = current->siblingBefore; + } + if(current->siblingNext != NULL){ + current->siblingNext->before = current->before; + } + current->siblingBefore->next = current->next; + } + } + } + + }; + +private: + RecordStack stack; +}; + +#endif // Recorder_H diff --git a/GraphicsScene/Widgets/defaulttoolbar.cpp b/GraphicsScene/Widgets/defaulttoolbar.cpp index abee9f3..64e8de7 100644 --- a/GraphicsScene/Widgets/defaulttoolbar.cpp +++ b/GraphicsScene/Widgets/defaulttoolbar.cpp @@ -34,6 +34,34 @@ DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar( addSeparator(); + QToolButton* undoButton = new QToolButton(this); + undoButton->setIcon(ImageHelper::getIcon("undo")); + undoButton->setToolTip(MString::search("{h5KymvIMTN}撤销")); + connect(undoButton, &QToolButton::clicked, this, [=]() { + area->getRecorder()->back(); + }); + addWidget(undoButton); + + QToolButton* redoButton = new QToolButton(this); + redoButton->setToolTip(MString::search("{a7CaC7NOL5}恢复")); + redoButton->setIcon(ImageHelper::getIcon("redo")); + connect(redoButton, &QToolButton::clicked, this, [=]() { + area->getRecorder()->forward(); + }); + addWidget(redoButton); + connect(area, &PaintArea::recordChange, this, [=]() { + if(!area->getRecorder()->undoAvailiable()) { + undoButton->setEnabled(false); + } else { + undoButton->setEnabled(true); + } + if(!area->getRecorder()->redoAvailiable()) { + redoButton->setEnabled(false); + } else { + redoButton->setEnabled(true); + } + }); + QToolButton* clipButton = new QToolButton(this); clipButton->setIcon(ImageHelper::getIcon("clipboard")); clipButton->setToolTip(MString::search("{ntbJbEqxwF}复制到剪切板")); diff --git a/GraphicsScene/ilayercontrol.h b/GraphicsScene/ilayercontrol.h index 0e16959..33c977a 100644 --- a/GraphicsScene/ilayercontrol.h +++ b/GraphicsScene/ilayercontrol.h @@ -1,6 +1,7 @@ #ifndef ILAYERCONTROL_H #define ILAYERCONTROL_H #include +#include "Recorder/recorder.h" class LayerBase; /** @@ -25,6 +26,7 @@ class ILayerControl virtual void setEraseEnable(bool enable)=0; virtual void setEnable(bool enable, int index=0)=0; virtual QRectF getClipRect()=0; + virtual void record(RecordBase* record)=0; protected: bool imageValid; QImage image; diff --git a/GraphicsScene/paintarea.cpp b/GraphicsScene/paintarea.cpp index 15bfd6d..9f612fd 100644 --- a/GraphicsScene/paintarea.cpp +++ b/GraphicsScene/paintarea.cpp @@ -16,8 +16,12 @@ PaintArea::PaintArea(QWidget* parent) : press(false), mouseGrabber(NULL), rootLayer(new RootLayer(this)), - clipLayer(NULL) + clipLayer(NULL), + recorder(new Recorder(this)) { + connect(recorder, &Recorder::recordChange, this, [=](){ + emit recordChange(); + }); } void PaintArea::mousePressEvent(QGraphicsSceneMouseEvent *event){ @@ -176,6 +180,7 @@ void PaintArea::reset(){ for(LayerBase* layer : layers){ layer->reset(); } + recorder->reset(); } QGraphicsItem* PaintArea::getRootLayer(){ @@ -197,3 +202,11 @@ QRectF PaintArea::getClipRect() { ClipLayerBase* PaintArea::getClipLayer(){ return clipLayer; } + +void PaintArea::record(RecordBase *record){ + recorder->record(record); +} + +Recorder* PaintArea::getRecorder(){ + return recorder; +} diff --git a/GraphicsScene/paintarea.h b/GraphicsScene/paintarea.h index df8e158..6c07fee 100644 --- a/GraphicsScene/paintarea.h +++ b/GraphicsScene/paintarea.h @@ -10,6 +10,7 @@ class PaintArea : public QGraphicsScene, public ILayerControl, public LayerManager { + Q_OBJECT public: PaintArea(QWidget* parent=nullptr); bool save(SaveType type, const QString &path = "") override; @@ -29,6 +30,11 @@ class PaintArea : public QGraphicsScene, public ILayerControl, public LayerManag QGraphicsItem* getRootLayer(); QRectF getClipRect() override; ClipLayerBase* getClipLayer(); + void record(RecordBase *record) override; + Recorder* getRecorder(); +signals: + void recordChange(); + private: LayerContainer* container; bool inLayer; @@ -36,6 +42,7 @@ class PaintArea : public QGraphicsScene, public ILayerControl, public LayerManag QGraphicsItem* mouseGrabber; RootLayer* rootLayer; ClipLayerBase* clipLayer; + Recorder* recorder; }; #endif // PAINTAREA_H diff --git a/capture.pro b/capture.pro index 2f2b66c..355a0f7 100644 --- a/capture.pro +++ b/capture.pro @@ -34,6 +34,8 @@ SOURCES += \ GraphicsScene/Layer/rectlayer.cpp \ GraphicsScene/Layer/rootlayer.cpp \ GraphicsScene/Layer/textlayer.cpp \ + GraphicsScene/Recorder/layerrecord.cpp \ + GraphicsScene/Recorder/recorder.cpp \ GraphicsScene/Widgets/attributetoolbar.cpp \ GraphicsScene/Widgets/clipregion.cpp \ GraphicsScene/Widgets/colorpicker.cpp \ @@ -154,6 +156,9 @@ HEADERS += \ GraphicsScene/Layer/rectlayer.h \ GraphicsScene/Layer/rootlayer.h \ GraphicsScene/Layer/textlayer.h \ + GraphicsScene/Recorder/layerrecord.h \ + GraphicsScene/Recorder/recordbase.h \ + GraphicsScene/Recorder/recorder.h \ GraphicsScene/Widgets/FontData.h \ GraphicsScene/Widgets/PaintData.h \ GraphicsScene/Widgets/attributetoolbar.h \ From 69d2f2d12aac01a597405ef1b8d2fbb3544d3e2e Mon Sep 17 00:00:00 2001 From: xinhecuican <2686462757@qq.com> Date: Wed, 13 Dec 2023 15:56:38 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=89=A9=E4=BD=99?= =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Container/videolayercontainer.cpp | 116 ++++++++++++++++++ GraphicsScene/Container/videolayercontainer.h | 17 +++ GraphicsScene/Widgets/defaulttoolbar.cpp | 81 +++++++++++- GraphicsScene/Widgets/defaulttoolbar.h | 6 + GraphicsScene/paintarea.cpp | 38 ++++++ GraphicsScene/paintarea.h | 3 + Manager/config.h | 3 +- Resource/default.json | 5 +- capture.pro | 2 + 9 files changed, 267 insertions(+), 4 deletions(-) create mode 100644 GraphicsScene/Container/videolayercontainer.cpp create mode 100644 GraphicsScene/Container/videolayercontainer.h diff --git a/GraphicsScene/Container/videolayercontainer.cpp b/GraphicsScene/Container/videolayercontainer.cpp new file mode 100644 index 0000000..58f55f9 --- /dev/null +++ b/GraphicsScene/Container/videolayercontainer.cpp @@ -0,0 +1,116 @@ +#include "videolayercontainer.h" +#include "../paintarea.h" +#include +#include "../../Helper/mstring.h" +#include +#include +#include +#include "../../Helper/imagehelper.h" +#include +#include +#include "../../Manager/config.h" + +VideoLayerContainer::VideoLayerContainer(PaintArea* area) : LayerContainer(area) +{ + +} + +QWidget* VideoLayerContainer::onValid(QWidget *widgetParent){ + if(widget == NULL){ + widget = new QWidget(widgetParent); + QHBoxLayout* layout = new QHBoxLayout(); + + QRadioButton* enableAudioButton = new QRadioButton(widgetParent); + enableAudioButton->setText(MString::search("{rh0LYgOmDD}录制声音")); + enableAudioButton->setChecked(true); + enableAudioButton->setCheckable(true); + info.enableAudio = true; + info.channel = 2; + connect(enableAudioButton, &QRadioButton::clicked, this, [=](bool check){ + info.enableAudio = check; + }); + + QComboBox* deviceSelector = new QComboBox(widgetParent); + int nDeviceNum = waveInGetNumDevs(); + for (int i = 0; i < nDeviceNum; ++i) + { + WAVEINCAPS wic; + waveInGetDevCaps(i, &wic, sizeof(wic)); + + //转成utf-8 + int nSize = WideCharToMultiByte(CP_UTF8, 0, wic.szPname, wcslen(wic.szPname), NULL, 0, NULL, NULL); + std::shared_ptr spDeviceName(new char[nSize + 1]); + memset(spDeviceName.get(), 0, nSize + 1); + WideCharToMultiByte(CP_UTF8, 0, wic.szPname, wcslen(wic.szPname), spDeviceName.get(), nSize, NULL, NULL); + deviceSelector->addItem(spDeviceName.get()); + } + info.audioDeviceIndex = 0; + deviceSelector->setMaximumWidth(150); + connect(deviceSelector, static_cast(&QComboBox::currentIndexChanged), this, [=](int index){ + info.audioDeviceIndex = index; + }); + + QLabel* fpsLabel = new QLabel("fps", widgetParent); + QSpinBox* fpsSelector = new QSpinBox(widgetParent); + fpsSelector->setRange(1, 60); + fpsSelector->setValue(20); + info.fps = 20; + fpsSelector->setAccelerated(true); + fpsSelector->setWrapping(true); // 开启循环 + fpsSelector->setKeyboardTracking(true); + connect(fpsSelector, static_cast(&QSpinBox::valueChanged), this, [=](int index){ + info.fps = index; + }); + + QToolButton* pathChooseButton = new QToolButton(widgetParent); + pathChooseButton->setIcon(ImageHelper::getIcon("folder")); + pathChooseButton->setToolTip(Config::getConfig(Config::video_save_path)); + connect(pathChooseButton, &QToolButton::clicked, this, [=](){ + QString result = QFileDialog::getExistingDirectory(widgetParent, MString::search("{nmqfWFejoz}选择保存目录"), Config::getConfig(Config::video_save_path)); + if(result != ""){ + Config::setConfig(Config::video_save_path, result); + Config::updateConfig(Config::video_save_path); + pathChooseButton->setToolTip(result); + } + }); + + QLineEdit* fileNameEdit = new QLineEdit(widgetParent); + fileNameEdit->setPlaceholderText(MString::search("{cR3jOHb9Qw}新建")); + name = MString::search("{cR3jOHb9Qw}新建"); + fileNameEdit->setMaxLength(20); + connect(fileNameEdit, &QLineEdit::textChanged, this, [=](QString text){ + name = text; + if(text == ""){ + name = MString::search("{cR3jOHb9Qw}新建"); + } + }); + + QComboBox* suffixSelector = new QComboBox(widgetParent); + suffixSelector->addItem("mp4"); + suffixSelector->addItem("gif"); + suffix = "mp4"; + connect(suffixSelector, static_cast(&QComboBox::currentIndexChanged), this, [=](int index){ + if(index == 0){ + suffix = "mp4"; + } + else if(index == 1){ + suffix = "gif"; + } + }); + + QToolButton* helpButton = new QToolButton(widgetParent); + helpButton->setIcon(ImageHelper::getIcon("help")); + helpButton->setToolTip(MString::search("{SHLK0bd4wt}开始录屏: F5\n暂停/恢复录屏: F6\n结束录屏: F7")); + + layout->addWidget(enableAudioButton); + layout->addWidget(deviceSelector); + layout->addWidget(fpsLabel); + layout->addWidget(fpsSelector); + layout->addWidget(pathChooseButton); + layout->addWidget(fileNameEdit); + layout->addWidget(suffixSelector); + layout->addWidget(helpButton); + widget->setLayout(layout); + } + return widget; +} diff --git a/GraphicsScene/Container/videolayercontainer.h b/GraphicsScene/Container/videolayercontainer.h new file mode 100644 index 0000000..0af1ff6 --- /dev/null +++ b/GraphicsScene/Container/videolayercontainer.h @@ -0,0 +1,17 @@ +#ifndef VIDEOLAYERCONTAINER_H +#define VIDEOLAYERCONTAINER_H +#include "layercontainer.h" +#include "ecvideocapture.h" + +class VideoLayerContainer : public LayerContainer +{ +public: + VideoLayerContainer(PaintArea* area); + QWidget * onValid(QWidget *widgetParent) override; +private: + RecordInfo info; + QString name; + QString suffix; +}; + +#endif // VIDEOLAYERCONTAINER_H diff --git a/GraphicsScene/Widgets/defaulttoolbar.cpp b/GraphicsScene/Widgets/defaulttoolbar.cpp index 64e8de7..31ab2be 100644 --- a/GraphicsScene/Widgets/defaulttoolbar.cpp +++ b/GraphicsScene/Widgets/defaulttoolbar.cpp @@ -6,9 +6,10 @@ #include "../Container/textlayercontainer.h" #include #include "../../Paint/Widgets/history.h" +#include DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar(area, parent) -{ +{ GeoLayerContainer* geoLayerContainer = new GeoLayerContainer(area); addContainer("shape", "", geoLayerContainer, true); BlurLayerContainer* blurLayerContainer = new BlurLayerContainer(area); @@ -62,6 +63,17 @@ DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar( } }); + QToolButton* ocrButton = new QToolButton(this); + ocrButton->setIcon(ImageHelper::getIcon("ocr")); + ocrButton->setToolTip(MString::search("{SvJhCjRGF0}提取文字")); + connect(ocrButton, &QToolButton::clicked, this, [=]() { + if(area->save(ILayerControl::Temp, "ocr/1.png")) { + WindowManager::changeWindow("tray"); + ocrProcess.start(); + } + }); + addWidget(ocrButton); + QToolButton* clipButton = new QToolButton(this); clipButton->setIcon(ImageHelper::getIcon("clipboard")); clipButton->setToolTip(MString::search("{ntbJbEqxwF}复制到剪切板")); @@ -86,6 +98,30 @@ DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar( }); addWidget(saveButton); + QToolButton* pinButton = new QToolButton(this); + pinButton->setToolTip(MString::search("{BNzMH1dcwW}钉住")); + pinButton->setIcon(ImageHelper::getIcon("pin")); + connect(pinButton, &QToolButton::clicked, this, [=](){ + QImage image = area->getSaveImage(); + WindowManager::changeWindow("PinWindow", QPixmap::fromImage(image), area->getSaveRect().toRect()); + }); + addWidget(pinButton); + + QToolButton* okButton = new QToolButton(this); + okButton->setIcon(ImageHelper::getIcon("ok")); + connect(okButton, &QToolButton::clicked, this, [=]() { + QImage image = area->getSaveImage(); + QRect bound = area->getSaveRect().toRect(); + bound.moveTo(0, 0); + WindowManager::changeWindow("PaintWindow", QPixmap::fromImage(image), bound); + }); + + QToolButton* cancelButton = new QToolButton(this); + cancelButton->setIcon(ImageHelper::getIcon("cancel")); + connect(cancelButton, &QToolButton::clicked, this, [=]() { + WindowManager::changeWindow("tray"); + }); + ClipLayerBase* clipLayer = area->getClipLayer(); if(clipLayer != NULL){ @@ -100,3 +136,46 @@ DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar( adjustSize(); hideAll(); } + +void DefaultToolbar::initOcr() { + const QString queryCPUNumberOfCores = "wmic cpu get NumberOfCores"; + QProcess queryCPU; + QPair pairResult; + queryCPU.start(queryCPUNumberOfCores); + queryCPU.waitForFinished(); + QString result = QString::fromLocal8Bit(queryCPU.readAllStandardOutput()); + QStringList list = queryCPUNumberOfCores.split(" "); + result = result.remove(list.last(), Qt::CaseInsensitive); + result = result.replace("\r", ""); + result = result.replace("\n", ""); + result = result.simplified(); + pairResult.first = result.toInt(); + int numCore = pairResult.first; + QStringList args; + QDir dir("ocr/models"); + QDir dir2("ocr"); + args << "--models" << "models/" + << "--det" << "ch_PP-OCRv3_det_infer.onnx" + << "--cls" << "ch_ppocr_mobile_v2.0_cls_infer.onnx" + << "--rec" << "ch_PP-OCRv3_rec_infer.onnx" + << "--keys" << "ppocr_keys_v1.txt" + << "--image" << "1.png" + << "--numThread" << QString::number(numCore) + << "--padding" << "50" + << "--maxSideLen" << "1024" + << "--boxScoreThresh" << "0.5" + << "--boxThresh" << "0.3" + << "--unClipRatio" << "1.6" + << "--doAngle" << "1" + << "--mostAngle" << "1"; + ocrProcess.setProgram(dir2.absolutePath() + "/RapidOcrOnnx.exe"); + ocrProcess.setArguments(args); + ocrProcess.setWorkingDirectory(dir2.absolutePath()); + connect(&ocrProcess, static_cast(&QProcess::finished), this, [=](int exitCode, QProcess::ExitStatus exitStatus) { + if(exitStatus == QProcess::NormalExit) { + showOcrResultProcess.startDetached(); + } + }); + showOcrResultProcess.setProgram("OcrViewer.exe"); + showOcrResultProcess.setWorkingDirectory(QDir::currentPath()); +} diff --git a/GraphicsScene/Widgets/defaulttoolbar.h b/GraphicsScene/Widgets/defaulttoolbar.h index 6dee40f..75d9f79 100644 --- a/GraphicsScene/Widgets/defaulttoolbar.h +++ b/GraphicsScene/Widgets/defaulttoolbar.h @@ -1,11 +1,17 @@ #ifndef DEFAULTTOOLBAR_H #define DEFAULTTOOLBAR_H #include "layertoolbar.h" +#include class DefaultToolbar : public LayerToolBar { public: DefaultToolbar(PaintArea* area, QWidget* parent=nullptr); +private: + void initOcr(); +private: + QProcess ocrProcess; + QProcess showOcrResultProcess; }; #endif // DEFAULTTOOLBAR_H diff --git a/GraphicsScene/paintarea.cpp b/GraphicsScene/paintarea.cpp index 9f612fd..dedf276 100644 --- a/GraphicsScene/paintarea.cpp +++ b/GraphicsScene/paintarea.cpp @@ -107,6 +107,44 @@ bool PaintArea::save(SaveType type, const QString &path){ return true; } +QImage PaintArea::getSaveImage(){ + for(auto& layer: layers){ + layer->prepareSave(); + } + update(); + QRectF bound; + for(auto& layer: layers){ + bound = bound.united(layer->getSaveRect()); + } + + if(bound == QRectF(0, 0, 0, 0)) + return QImage(); + + cv::Mat ans(bound.height(), bound.width(), CV_8UC4); + for(int i=0; i 32700 ? 32700 : bound.height() - i; + QRect temp_rect(bound.left(), bound.top()+i, bound.width(), height); + QImage image(bound.width(), height, QImage::Format_ARGB32); + // image.fill(Qt::transparent); + QPainter painter(&image); + render(&painter, QRectF(QPointF(0, 0), image.size()), temp_rect); + cv::Mat temp_mat = ImageHelper::QImage2Mat(image); + temp_mat.copyTo(ans(cv::Rect(0, i, bound.width(), height))); + } + for(auto& layer: layers){ + layer->endSave(); + } + return ImageHelper::Mat2QImage(ans); +} + +QRectF PaintArea::getSaveRect(){ + QRectF bound; + for(auto& layer: layers){ + bound = bound.united(layer->getSaveRect()); + } + return bound; +} + void PaintArea::setEraseEnable(bool enable){ changeFocusLayer(NULL); for(auto layer : layers){ diff --git a/GraphicsScene/paintarea.h b/GraphicsScene/paintarea.h index 6c07fee..8e88cc9 100644 --- a/GraphicsScene/paintarea.h +++ b/GraphicsScene/paintarea.h @@ -32,6 +32,9 @@ class PaintArea : public QGraphicsScene, public ILayerControl, public LayerManag ClipLayerBase* getClipLayer(); void record(RecordBase *record) override; Recorder* getRecorder(); + QImage getSaveImage(); + QRectF getSaveRect(); + signals: void recordChange(); diff --git a/Manager/config.h b/Manager/config.h index d196dd4..8582c1f 100644 --- a/Manager/config.h +++ b/Manager/config.h @@ -31,7 +31,8 @@ class Config : Serializable { show_update_box, ui_theme_name, receive_beta, - show_guidance + show_guidance, + video_save_path ); /** diff --git a/Resource/default.json b/Resource/default.json index e0541ac..8a224ed 100644 --- a/Resource/default.json +++ b/Resource/default.json @@ -16,10 +16,11 @@ "test_setting": 0, "total_capture_save_path": "Data/ScreenShot/", "middle_button_type": 1, - "version": "0.7.4", + "version": "0.8.0", "clip_voice": true, "show_update_box": false, "ui_theme_name": "default", "receive_beta": false, - "show_guidance": false + "show_guidance": false, + "video_save_path": "" } diff --git a/capture.pro b/capture.pro index 355a0f7..2f02f5d 100644 --- a/capture.pro +++ b/capture.pro @@ -24,6 +24,7 @@ SOURCES += \ GraphicsScene/Container/masklayercontainer.cpp \ GraphicsScene/Container/paintlayercontainer.cpp \ GraphicsScene/Container/textlayercontainer.cpp \ + GraphicsScene/Container/videolayercontainer.cpp \ GraphicsScene/Layer/arrowlayer.cpp \ GraphicsScene/Layer/blurlayer.cpp \ GraphicsScene/Layer/grabcutlayer.cpp \ @@ -145,6 +146,7 @@ HEADERS += \ GraphicsScene/Container/masklayercontainer.h \ GraphicsScene/Container/paintlayercontainer.h \ GraphicsScene/Container/textlayercontainer.h \ + GraphicsScene/Container/videolayercontainer.h \ GraphicsScene/Layer/arrowlayer.h \ GraphicsScene/Layer/blurlayer.h \ GraphicsScene/Layer/cliplayerbase.h \ From d9332f2ad84c918d4e96036f7082d6b70fe95e43 Mon Sep 17 00:00:00 2001 From: xinhecuican <2686462757@qq.com> Date: Wed, 13 Dec 2023 19:22:46 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Container/videolayercontainer.cpp | 2 + GraphicsScene/Widgets/attributetoolbar.cpp | 2 + GraphicsScene/Widgets/defaulttoolbar.cpp | 5 +- GraphicsScene/Widgets/layertoolbar.cpp | 3 + GraphicsScene/Widgets/layertoolbar.h | 2 +- GraphicsScene/paintarea.cpp | 6 +- {Paint/Widgets => Manager}/history.cpp | 37 +- {Paint/Widgets => Manager}/history.h | 14 +- Manager/update.cpp | 2 +- Paint/Data/Common.h | 85 -- Paint/Data/History_data.h | 15 - Paint/Data/Ilayer.h | 40 - Paint/Data/fontdata.cpp | 10 - Paint/Data/fontdata.h | 14 - Paint/Data/paint_data.h | 31 - Paint/Data/scroll_button.cpp | 22 - Paint/Data/scroll_button.h | 19 - Paint/Data/stretch_button.cpp | 103 --- Paint/Data/stretch_button.h | 36 - Paint/PaintWindow.cpp | 578 -------------- Paint/Widgets/Layer_list/list_item.cpp | 62 -- Paint/Widgets/Layer_list/list_item.h | 23 - Paint/Widgets/Layer_list/list_widget.cpp | 113 --- Paint/Widgets/Layer_list/list_widget.h | 22 - .../Layers/LayerItems/expandbutton.cpp | 170 ---- .../Widgets/Layers/LayerItems/expandbutton.h | 53 -- Paint/Widgets/Layers/LayerItems/paintitem.cpp | 69 -- Paint/Widgets/Layers/LayerItems/paintitem.h | 33 - Paint/Widgets/Layers/LayerItems/picitem.cpp | 76 -- Paint/Widgets/Layers/LayerItems/picitem.h | 28 - .../Widgets/Layers/LayerItems/scrollitem.cpp | 59 -- Paint/Widgets/Layers/LayerItems/scrollitem.h | 21 - Paint/Widgets/Layers/arrowlayer.cpp | 167 ---- Paint/Widgets/Layers/arrowlayer.h | 47 -- Paint/Widgets/Layers/baselayer.h | 25 - Paint/Widgets/Layers/blurlayer.cpp | 213 ----- Paint/Widgets/Layers/blurlayer.h | 50 -- Paint/Widgets/Layers/paintlayer.cpp | 145 ---- Paint/Widgets/Layers/paintlayer.h | 48 -- Paint/Widgets/Layers/picture_layer.cpp | 92 --- Paint/Widgets/Layers/picture_layer.h | 47 -- Paint/Widgets/Layers/rect_layer.cpp | 265 ------- Paint/Widgets/Layers/rect_layer.h | 61 -- Paint/Widgets/Layers/shapelayer.cpp | 310 -------- Paint/Widgets/Layers/shapelayer.h | 56 -- Paint/Widgets/Layers/text_layer.cpp | 189 ----- Paint/Widgets/Layers/text_layer.h | 54 -- Paint/Widgets/PaintArea.cpp | 449 ----------- Paint/Widgets/PaintArea.h | 66 -- Paint/Widgets/Panels/close_dialog.cpp | 137 ---- Paint/Widgets/Panels/close_dialog.h | 21 - Paint/Widgets/Panels/color_selector.cpp | 111 --- Paint/Widgets/Panels/color_selector.h | 35 - Paint/Widgets/Panels/flow_edit_panel.cpp | 211 ----- Paint/Widgets/Panels/flow_edit_panel.h | 39 - Paint/Widgets/Panels/paint_setting_panel.cpp | 437 ----------- Paint/Widgets/Panels/paint_setting_panel.h | 51 -- .../Widgets/Recorder_element/paint_record.cpp | 18 - Paint/Widgets/Recorder_element/paint_record.h | 17 - .../Recorder_element/paintdeleterecord.cpp | 23 - .../Recorder_element/paintdeleterecord.h | 19 - .../Recorder_element/resize_record.cpp | 24 - .../Widgets/Recorder_element/resize_record.h | 19 - .../Widgets/Recorder_element/shaperecord.cpp | 22 - Paint/Widgets/Recorder_element/shaperecord.h | 18 - Paint/Widgets/recorder.cpp | 83 -- Paint/Widgets/recorder.h | 141 ---- Paint/Widgets/style_manager.cpp | 92 --- Paint/Widgets/style_manager.h | 28 - Style_widget/colorwidget.cpp | 6 +- .../ScrollHandler}/Scroll_handle_global.cpp | 0 .../ScrollHandler}/Scroll_handler_global.h | 0 .../ScrollHandler}/dispatcher_worker.cpp | 0 .../ScrollHandler}/dispatcher_worker.h | 0 .../ScrollHandler}/scroll_dispatcher.cpp | 0 .../ScrollHandler}/scroll_dispatcher.h | 0 .../ScrollHandler}/scroll_handle.cpp | 0 .../ScrollHandler}/scroll_handle.h | 0 .../ScrollHandler}/scroll_worker.cpp | 0 .../ScrollHandler}/scroll_worker.h | 0 .../Widgets}/videocapture.cpp | 0 .../Widgets}/videocapture.h | 0 .../capturewindow.cpp | 148 ++-- .../capturewindow.h | 16 +- Windows/paintwindow.cpp | 285 +++++++ Paint/PaintWindow.h => Windows/paintwindow.h | 26 +- Windows/pinwindow.h | 2 +- Windows/scrollerwindow.cpp | 12 +- Windows/scrollerwindow.h | 8 +- .../windowfilter.cpp | 2 +- Windows/windowfilter.h | 320 ++++++++ capture.pro | 115 +-- main.cpp | 24 +- new_capture/Widgets/attributetoolbar.cpp | 37 - new_capture/Widgets/attributetoolbar.h | 19 - new_capture/Widgets/capturetip.cpp | 30 - new_capture/Widgets/capturetip.h | 11 - new_capture/Widgets/cliplayer.cpp | 728 ------------------ new_capture/Widgets/cliplayer.h | 130 ---- new_capture/Widgets/clipregion.cpp | 234 ------ new_capture/Widgets/clipregion.h | 46 -- new_capture/Widgets/colorpicker.cpp | 81 -- new_capture/Widgets/colorpicker.h | 32 - new_capture/Widgets/masklayer.cpp | 236 ------ new_capture/Widgets/masklayer.h | 49 -- new_capture/Widgets/mosicsample.cpp | 60 -- new_capture/Widgets/mosicsample.h | 20 - new_capture/Widgets/videotoolbar.cpp | 119 --- new_capture/Widgets/videotoolbar.h | 19 - new_capture/window_fliter.h | 320 -------- 110 files changed, 773 insertions(+), 7947 deletions(-) rename {Paint/Widgets => Manager}/history.cpp (94%) rename {Paint/Widgets => Manager}/history.h (73%) delete mode 100644 Paint/Data/Common.h delete mode 100644 Paint/Data/History_data.h delete mode 100644 Paint/Data/Ilayer.h delete mode 100644 Paint/Data/fontdata.cpp delete mode 100644 Paint/Data/fontdata.h delete mode 100644 Paint/Data/paint_data.h delete mode 100644 Paint/Data/scroll_button.cpp delete mode 100644 Paint/Data/scroll_button.h delete mode 100644 Paint/Data/stretch_button.cpp delete mode 100644 Paint/Data/stretch_button.h delete mode 100644 Paint/PaintWindow.cpp delete mode 100644 Paint/Widgets/Layer_list/list_item.cpp delete mode 100644 Paint/Widgets/Layer_list/list_item.h delete mode 100644 Paint/Widgets/Layer_list/list_widget.cpp delete mode 100644 Paint/Widgets/Layer_list/list_widget.h delete mode 100644 Paint/Widgets/Layers/LayerItems/expandbutton.cpp delete mode 100644 Paint/Widgets/Layers/LayerItems/expandbutton.h delete mode 100644 Paint/Widgets/Layers/LayerItems/paintitem.cpp delete mode 100644 Paint/Widgets/Layers/LayerItems/paintitem.h delete mode 100644 Paint/Widgets/Layers/LayerItems/picitem.cpp delete mode 100644 Paint/Widgets/Layers/LayerItems/picitem.h delete mode 100644 Paint/Widgets/Layers/LayerItems/scrollitem.cpp delete mode 100644 Paint/Widgets/Layers/LayerItems/scrollitem.h delete mode 100644 Paint/Widgets/Layers/arrowlayer.cpp delete mode 100644 Paint/Widgets/Layers/arrowlayer.h delete mode 100644 Paint/Widgets/Layers/baselayer.h delete mode 100644 Paint/Widgets/Layers/blurlayer.cpp delete mode 100644 Paint/Widgets/Layers/blurlayer.h delete mode 100644 Paint/Widgets/Layers/paintlayer.cpp delete mode 100644 Paint/Widgets/Layers/paintlayer.h delete mode 100644 Paint/Widgets/Layers/picture_layer.cpp delete mode 100644 Paint/Widgets/Layers/picture_layer.h delete mode 100644 Paint/Widgets/Layers/rect_layer.cpp delete mode 100644 Paint/Widgets/Layers/rect_layer.h delete mode 100644 Paint/Widgets/Layers/shapelayer.cpp delete mode 100644 Paint/Widgets/Layers/shapelayer.h delete mode 100644 Paint/Widgets/Layers/text_layer.cpp delete mode 100644 Paint/Widgets/Layers/text_layer.h delete mode 100644 Paint/Widgets/PaintArea.cpp delete mode 100644 Paint/Widgets/PaintArea.h delete mode 100644 Paint/Widgets/Panels/close_dialog.cpp delete mode 100644 Paint/Widgets/Panels/close_dialog.h delete mode 100644 Paint/Widgets/Panels/color_selector.cpp delete mode 100644 Paint/Widgets/Panels/color_selector.h delete mode 100644 Paint/Widgets/Panels/flow_edit_panel.cpp delete mode 100644 Paint/Widgets/Panels/flow_edit_panel.h delete mode 100644 Paint/Widgets/Panels/paint_setting_panel.cpp delete mode 100644 Paint/Widgets/Panels/paint_setting_panel.h delete mode 100644 Paint/Widgets/Recorder_element/paint_record.cpp delete mode 100644 Paint/Widgets/Recorder_element/paint_record.h delete mode 100644 Paint/Widgets/Recorder_element/paintdeleterecord.cpp delete mode 100644 Paint/Widgets/Recorder_element/paintdeleterecord.h delete mode 100644 Paint/Widgets/Recorder_element/resize_record.cpp delete mode 100644 Paint/Widgets/Recorder_element/resize_record.h delete mode 100644 Paint/Widgets/Recorder_element/shaperecord.cpp delete mode 100644 Paint/Widgets/Recorder_element/shaperecord.h delete mode 100644 Paint/Widgets/recorder.cpp delete mode 100644 Paint/Widgets/recorder.h delete mode 100644 Paint/Widgets/style_manager.cpp delete mode 100644 Paint/Widgets/style_manager.h rename {new_capture/Widgets/Scroll_handler => Windows/ScrollHandler}/Scroll_handle_global.cpp (100%) rename {new_capture/Widgets/Scroll_handler => Windows/ScrollHandler}/Scroll_handler_global.h (100%) rename {new_capture/Widgets/Scroll_handler => Windows/ScrollHandler}/dispatcher_worker.cpp (100%) rename {new_capture/Widgets/Scroll_handler => Windows/ScrollHandler}/dispatcher_worker.h (100%) rename {new_capture/Widgets/Scroll_handler => Windows/ScrollHandler}/scroll_dispatcher.cpp (100%) rename {new_capture/Widgets/Scroll_handler => Windows/ScrollHandler}/scroll_dispatcher.h (100%) rename {new_capture/Widgets/Scroll_handler => Windows/ScrollHandler}/scroll_handle.cpp (100%) rename {new_capture/Widgets/Scroll_handler => Windows/ScrollHandler}/scroll_handle.h (100%) rename {new_capture/Widgets/Scroll_handler => Windows/ScrollHandler}/scroll_worker.cpp (100%) rename {new_capture/Widgets/Scroll_handler => Windows/ScrollHandler}/scroll_worker.h (100%) rename {new_capture/Widgets/VideoHandler => Windows/Widgets}/videocapture.cpp (100%) rename {new_capture/Widgets/VideoHandler => Windows/Widgets}/videocapture.h (100%) rename new_capture/CaptureWindow.cpp => Windows/capturewindow.cpp (69%) rename new_capture/CaptureWindow.h => Windows/capturewindow.h (83%) create mode 100644 Windows/paintwindow.cpp rename Paint/PaintWindow.h => Windows/paintwindow.h (62%) rename new_capture/Window_fliter.cpp => Windows/windowfilter.cpp (88%) create mode 100644 Windows/windowfilter.h delete mode 100644 new_capture/Widgets/attributetoolbar.cpp delete mode 100644 new_capture/Widgets/attributetoolbar.h delete mode 100644 new_capture/Widgets/capturetip.cpp delete mode 100644 new_capture/Widgets/capturetip.h delete mode 100644 new_capture/Widgets/cliplayer.cpp delete mode 100644 new_capture/Widgets/cliplayer.h delete mode 100644 new_capture/Widgets/clipregion.cpp delete mode 100644 new_capture/Widgets/clipregion.h delete mode 100644 new_capture/Widgets/colorpicker.cpp delete mode 100644 new_capture/Widgets/colorpicker.h delete mode 100644 new_capture/Widgets/masklayer.cpp delete mode 100644 new_capture/Widgets/masklayer.h delete mode 100644 new_capture/Widgets/mosicsample.cpp delete mode 100644 new_capture/Widgets/mosicsample.h delete mode 100644 new_capture/Widgets/videotoolbar.cpp delete mode 100644 new_capture/Widgets/videotoolbar.h delete mode 100644 new_capture/window_fliter.h diff --git a/GraphicsScene/Container/videolayercontainer.cpp b/GraphicsScene/Container/videolayercontainer.cpp index 58f55f9..77c5f56 100644 --- a/GraphicsScene/Container/videolayercontainer.cpp +++ b/GraphicsScene/Container/videolayercontainer.cpp @@ -9,6 +9,8 @@ #include #include #include "../../Manager/config.h" +#include +#pragma comment(lib, "Winmm.lib") VideoLayerContainer::VideoLayerContainer(PaintArea* area) : LayerContainer(area) { diff --git a/GraphicsScene/Widgets/attributetoolbar.cpp b/GraphicsScene/Widgets/attributetoolbar.cpp index f577baf..9acb7f2 100644 --- a/GraphicsScene/Widgets/attributetoolbar.cpp +++ b/GraphicsScene/Widgets/attributetoolbar.cpp @@ -8,6 +8,8 @@ AttributeToolbar::AttributeToolbar(QWidget* parent) : QWidget(parent) { layout->setSpacing(3); layout->setContentsMargins(3, 2, 3, 2); setLayout(layout); + setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); + setWindowFlag(Qt::WindowSystemMenuHint, false); } void AttributeToolbar::addWidget(QWidget *widget) { diff --git a/GraphicsScene/Widgets/defaulttoolbar.cpp b/GraphicsScene/Widgets/defaulttoolbar.cpp index 31ab2be..f6ccaae 100644 --- a/GraphicsScene/Widgets/defaulttoolbar.cpp +++ b/GraphicsScene/Widgets/defaulttoolbar.cpp @@ -5,7 +5,7 @@ #include "../Container/paintlayercontainer.h" #include "../Container/textlayercontainer.h" #include -#include "../../Paint/Widgets/history.h" +#include "../../Manager/history.h" #include DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar(area, parent) @@ -115,12 +115,14 @@ DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar( bound.moveTo(0, 0); WindowManager::changeWindow("PaintWindow", QPixmap::fromImage(image), bound); }); + addWidget(okButton); QToolButton* cancelButton = new QToolButton(this); cancelButton->setIcon(ImageHelper::getIcon("cancel")); connect(cancelButton, &QToolButton::clicked, this, [=]() { WindowManager::changeWindow("tray"); }); + addWidget(cancelButton); ClipLayerBase* clipLayer = area->getClipLayer(); @@ -133,6 +135,7 @@ DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar( showAll(); }); } + adjustSize(); hideAll(); } diff --git a/GraphicsScene/Widgets/layertoolbar.cpp b/GraphicsScene/Widgets/layertoolbar.cpp index 02de74c..56c3ace 100644 --- a/GraphicsScene/Widgets/layertoolbar.cpp +++ b/GraphicsScene/Widgets/layertoolbar.cpp @@ -15,6 +15,9 @@ LayerToolBar::LayerToolBar(PaintArea* area, QWidget* parent) : { group->setExclusive(true); connect(group, static_cast(&QButtonGroup::buttonClicked), this, &LayerToolBar::onGroupClick); + setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); + setWindowFlag(Qt::WindowSystemMenuHint, false); + setMovable(false); } void LayerToolBar::addContainer(QToolButton* button, LayerContainer* container, bool exclude){ diff --git a/GraphicsScene/Widgets/layertoolbar.h b/GraphicsScene/Widgets/layertoolbar.h index 7d766f7..7d70b0b 100644 --- a/GraphicsScene/Widgets/layertoolbar.h +++ b/GraphicsScene/Widgets/layertoolbar.h @@ -21,7 +21,7 @@ class LayerToolBar : public QToolBar void hideAll(); void showAll(); -private slots: +public slots: void onGroupClick(int id); private: diff --git a/GraphicsScene/paintarea.cpp b/GraphicsScene/paintarea.cpp index dedf276..ddabf91 100644 --- a/GraphicsScene/paintarea.cpp +++ b/GraphicsScene/paintarea.cpp @@ -4,7 +4,7 @@ #include "opencv2/opencv.hpp" #include #include "../Helper/imagehelper.h" -#include "../Paint/Widgets/history.h" +#include "../Manager/history.h" #include #include #include @@ -97,9 +97,7 @@ bool PaintArea::save(SaveType type, const QString &path){ } else{ cv::imwrite(path.toLocal8Bit().toStdString(), ans); - History_data::save_type saveType = History_data::Editable; - if(type == Persist) saveType = History_data::Persist; - History::instance()->log(saveType, path); + History::instance()->log(type, path); } for(auto& layer: layers){ layer->endSave(); diff --git a/Paint/Widgets/history.cpp b/Manager/history.cpp similarity index 94% rename from Paint/Widgets/history.cpp rename to Manager/history.cpp index 29e5295..65729c4 100644 --- a/Paint/Widgets/history.cpp +++ b/Manager/history.cpp @@ -2,14 +2,15 @@ #include #include #include -#include "../../Helper/debug.h" +#include "Helper/debug.h" #include -#include "../../Manager/config.h" +#include "Manager/config.h" #include +#include History::History() { - data = QList(); + data = QList(); history_num = 0; last_directory = "C:/"; is_change = true; @@ -33,7 +34,7 @@ History* History::instance() return _instance; } -void History::log(History_data::save_type type, QString file_name) +void History::log(ILayerControl::SaveType type, QString file_name) { is_change = true; QFile file("Data/history.xml"); @@ -46,16 +47,16 @@ void History::log(History_data::save_type type, QString file_name) return; } qint64 time = QDateTime::currentDateTime().currentSecsSinceEpoch(); - History_data temp_data; + HistoryData temp_data; temp_data.type = type; temp_data.time = time; temp_data.file_name = file_name; data.append(temp_data); init(); - if(type == History_data::Persist) + if(type == ILayerControl::Persist) { -// int index = file_name.lastIndexOf('/'); -// last_directory = file_name.mid(0, index+1); + // int index = file_name.lastIndexOf('/'); + // last_directory = file_name.mid(0, index+1); last_directory = file_name; QDomNodeList list = doc.elementsByTagName("history"); list.at(0).toElement().setAttribute("directory", last_directory); @@ -91,15 +92,15 @@ void History::log(History_data::save_type type, QString file_name) element.appendChild(element2); element.appendChild(element3); history.appendChild(element); - History_data temp_data; + HistoryData temp_data; temp_data.type = type; temp_data.time = time; temp_data.file_name = file_name; data.append(temp_data); - if(type == History_data::Persist) + if(type == ILayerControl::Persist) { -// int index = file_name.lastIndexOf('/'); -// last_directory = file_name.mid(0, index+1); + // int index = file_name.lastIndexOf('/'); + // last_directory = file_name.mid(0, index+1); last_directory = file_name; history.setAttribute("directory", last_directory); } @@ -108,7 +109,7 @@ void History::log(History_data::save_type type, QString file_name) { history.setAttribute("history_num", ++history_num); } - else if(History::instance()->data[0].type == History_data::Editable) + else if(History::instance()->data[0].type == ILayerControl::Temp) { QString file_name = History::instance()->data[0].file_name; if(file_name.contains("Data/Temp")) @@ -291,9 +292,9 @@ void History::load_info() time = element2.attribute("sum").toLongLong(); } } - History_data history_data; + HistoryData history_data; history_data.time = time; - history_data.type = (History_data::save_type)type; + history_data.type = (ILayerControl::SaveType)type; history_data.file_name = file_name; data.append(history_data); } @@ -382,7 +383,7 @@ int History::get_history_num() return history_num; } -History_data History::get(int i) +HistoryData History::get(int i) { return data[i]; } @@ -428,9 +429,9 @@ void History::update() time = element2.attribute("sum").toLongLong(); } } - History_data history_data; + HistoryData history_data; history_data.time = time; - history_data.type = (History_data::save_type)type; + history_data.type = (ILayerControl::SaveType)type; history_data.file_name = file_name; data.append(history_data); } diff --git a/Paint/Widgets/history.h b/Manager/history.h similarity index 73% rename from Paint/Widgets/history.h rename to Manager/history.h index f102bc7..3194f67 100644 --- a/Paint/Widgets/history.h +++ b/Manager/history.h @@ -1,8 +1,14 @@ #ifndef HISTORY_H #define HISTORY_H -#include "../Data/History_data.h" #include #include +#include "../GraphicsScene/ilayercontrol.h" + +struct HistoryData{ + ILayerControl::SaveType type; + qint64 time; + QString file_name; +}; class History { @@ -10,13 +16,13 @@ class History History(); ~History(); static History* instance(); - void log(History_data::save_type type, QString file_name); + void log(ILayerControl::SaveType type, QString file_name); void log_color(QColor color); void remove_color(QColor color); void load(QString file_name); QString get_last_directory(); int get_history_num(); - History_data get(int i); + HistoryData get(int i); bool is_change; void update(); QList get_color(); @@ -24,7 +30,7 @@ class History QString getVideoSavePath(); private: static History* _instance; - QList data; + QList data; void load_info(); void init(); int history_num; diff --git a/Manager/update.cpp b/Manager/update.cpp index 92c266f..a412de6 100644 --- a/Manager/update.cpp +++ b/Manager/update.cpp @@ -10,7 +10,7 @@ #include #include "KeyManager.h" #include "WindowManager.h" -#include "../Paint/Widgets/history.h" +#include "../Manager/history.h" Update::Update() { newest_data = UpdateData(); diff --git a/Paint/Data/Common.h b/Paint/Data/Common.h deleted file mode 100644 index b86e2cf..0000000 --- a/Paint/Data/Common.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef COMMON_H -#define COMMON_H -#include "paint_data.h" -#include -#include -#include -enum SHAPE_TYPE {TEXT, DELETE_SHAPE, BLUR, RECTANGLE, PAINT_ARROW, MASK}; -enum PAINT_STATE {IDLE, PAINT, ARROW, SHAPE, ERASE}; -enum direction {NW, NE, SW, SE, N, W, S, E}; - -struct font_data { - QFont font; - QColor color; -}; - -struct paint_node { - int len; - font_data data; - paint_node* next; -}; - -struct PaintInfo { - PaintInfo() {}; - PaintInfo(PaintData* style, QVector paint_path) { - style_info = style; - path = paint_path; - } - PaintData* style_info; - QVector path; -}; - -struct Line { - QPoint bp; - QPoint ep; - Line() {}; - Line(QPoint begin, QPoint end) { - bp = begin; - ep = end; - } - - float cross_product(Line line) { - int x1 = ep.x() - bp.x(); - int y1 = ep.y() - bp.y(); - int x2 = line.ep.x() - line.bp.x(); - int y2 = line.ep.y() - line.bp.y(); - return x1 * y2 - x2 * y1; - } - - float cross_product(Line l1, Line l2) { - int x1 = l1.ep.x() - l1.bp.x(); - int y1 = l1.ep.y() - l1.bp.y(); - int x2 = l2.ep.x() - l2.bp.x(); - int y2 = l2.ep.y() - l2.bp.y(); - return x1 * y2 - x2 * y1; - } - - Line normalize(Line line) { - QPoint v = line.ep - line.bp; - float len = v.x() * v.x() + v.y() * v.y(); - v.setX((float)v.x() / len); - v.setY((float)v.y() / len); - Line ans; - ans.bp = QPoint(0, 0); - ans.ep = v; - return ans; - } - - Line normalize() { - QPoint v = ep - bp; - float len = v.x() * v.x() + v.y() * v.y(); - v.setX((float)v.x() / len); - v.setY((float)v.y() / len); - Line ans; - ans.bp = QPoint(0, 0); - ans.ep = v; - return ans; - } - - float angle(Line line) { - Line normal = normalize(line); - Line this_normal = normalize(); - return asin(cross_product(this_normal, normal)); - } -}; -#endif // COMMON_H diff --git a/Paint/Data/History_data.h b/Paint/Data/History_data.h deleted file mode 100644 index b7d1ef3..0000000 --- a/Paint/Data/History_data.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef HISTORY_DATA_H -#define HISTORY_DATA_H -#include -class History_data -{ -public: - enum save_type{Editable//可编辑 - ,Persist};//不可编辑 - qint64 time; - QString file_name; - save_type type; - -}; - -#endif // HISTORY_DATA_H diff --git a/Paint/Data/Ilayer.h b/Paint/Data/Ilayer.h deleted file mode 100644 index 85f0c45..0000000 --- a/Paint/Data/Ilayer.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef ILAYER_H -#define ILAYER_H -#include -#include "paint_data.h" -#include "Base/RecordElement.h" -#include -#include "Common.h" -#include -#include -#include - -/** - * @deprecated - */ -class Ilayer : public QWidget { -public: - Ilayer(QWidget* parent=nullptr):QWidget(parent) {}; - virtual void paint(QPainter* painter, QList disable_color, bool is_save)=0; - virtual void setName(QString name)=0; - virtual QPolygon bounded_rect()=0; - virtual QString getName()=0; - virtual ~Ilayer() {}; - virtual void getFocus() {}; - virtual void loseFocus() {}; - virtual bool focuseable() { - return false; - }; - - virtual void mouseEnter(int key_code) {}; - virtual void mouseMove(int dx, int dy) {}; - virtual void mouseRelease() {}; - virtual void doubleClick() {}; - - virtual void onSizeChange(int index, int dx, int dy) {}; - virtual void onPaintChange(int index, PaintInfo info) {}; -signals: - void update_rect(QRect rect); -}; - -#endif // ILAYER_H diff --git a/Paint/Data/fontdata.cpp b/Paint/Data/fontdata.cpp deleted file mode 100644 index 253b6ea..0000000 --- a/Paint/Data/fontdata.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "fontdata.h" - -FontData::FontData() { - -} - -FontData::FontData(QFont font, QColor color) { - this->font = font; - this->color = color; -} diff --git a/Paint/Data/fontdata.h b/Paint/Data/fontdata.h deleted file mode 100644 index 20afd3d..0000000 --- a/Paint/Data/fontdata.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef FONTDATA_H -#define FONTDATA_H -#include -#include - -class FontData { -public: - FontData(); - FontData(QFont font, QColor color); - QFont font; - QColor color; -}; - -#endif // FONTDATA_H diff --git a/Paint/Data/paint_data.h b/Paint/Data/paint_data.h deleted file mode 100644 index ebe98a7..0000000 --- a/Paint/Data/paint_data.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef PAINT_DATA_H -#define PAINT_DATA_H -#include - -struct PaintData { -public: - PaintData() {}; - PaintData(QColor color, double width, QColor back_color=QColor(255, 255, 255), - Qt::PenCapStyle cap_style=Qt::SquareCap, - Qt::PenJoinStyle join_style=Qt::RoundJoin) { - this->color = color; - this->width = width; - this->cap_style = cap_style; - this->join_style = join_style; - this->back_color = back_color; - } - void copy_to(PaintData* data) { - data->color = color; - data->width = width; - data->cap_style = cap_style; - data->join_style = join_style; - data->back_color = back_color; - } - QColor color; - int width;//笔的粗细 - Qt::PenCapStyle cap_style; - Qt::PenJoinStyle join_style; - QColor back_color; -}; - -#endif // PAINT_DATA_H diff --git a/Paint/Data/scroll_button.cpp b/Paint/Data/scroll_button.cpp deleted file mode 100644 index c0631c8..0000000 --- a/Paint/Data/scroll_button.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "scroll_button.h" -#include - -Scroll_button::Scroll_button(QWidget* parent) : QPushButton(parent) -{ - parent->installEventFilter(this); -} - -void Scroll_button::mouseMoveEvent(QMouseEvent *event) -{ - emit button_move(this->pos() + event->pos()); -} - -void Scroll_button::mouseReleaseEvent(QMouseEvent *event) -{ - emit button_release(this->pos() + event->pos()); -} - -void Scroll_button::mousePressEvent(QMouseEvent *event) -{ - emit button_click(this->pos() + event->pos()); -} diff --git a/Paint/Data/scroll_button.h b/Paint/Data/scroll_button.h deleted file mode 100644 index 9c5d25e..0000000 --- a/Paint/Data/scroll_button.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef SCROLL_BUTTON_H -#define SCROLL_BUTTON_H -#include - -class Scroll_button : public QPushButton -{ - Q_OBJECT -public: - Scroll_button(QWidget* parent); - void mouseMoveEvent(QMouseEvent* event)override; - void mousePressEvent(QMouseEvent* event)override; - void mouseReleaseEvent(QMouseEvent* event)override; -signals: - void button_click(QPoint pos); - void button_move(QPoint pos); - void button_release(QPoint pos); -}; - -#endif // SCROLL_BUTTON_H diff --git a/Paint/Data/stretch_button.cpp b/Paint/Data/stretch_button.cpp deleted file mode 100644 index 92be3c4..0000000 --- a/Paint/Data/stretch_button.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include "stretch_button.h" -#include -#include - -Stretch_button::Stretch_button() -{ - -} - -Stretch_button::Stretch_button(direction dir, QWidget* parent):QPushButton(parent) -{ - this->dir = dir; - setFixedSize(2 * OFFSET, 2 * OFFSET); - is_set_constraint = false; - show(); -} - -Stretch_button::Stretch_button(int index, QWidget* parent) : QPushButton(parent) -{ - this->index = index; - setFixedSize(2 * OFFSET, 2 * OFFSET); - is_set_constraint = false; - show(); -} - -Stretch_button::~Stretch_button() -{ -} - -void Stretch_button::mouseMoveEvent(QMouseEvent *event) -{ - if(!is_click) - { - return; - } - int dx = event->globalPos().x() - point.x(); - int dy = event->globalPos().y() - point.y(); - point = event->globalPos(); - int sum1 = this->pos().x() + dx; - int sum2 = this->pos().y() + dy; - bool larger_x = sum1 > constraint.right() - OFFSET ? true : false; - bool larger_y = sum2 > constraint.bottom() - OFFSET? true : false; - bool small_x = sum1 < constraint.left() - OFFSET? true : false; - bool small_y = sum2 < constraint.top() - OFFSET? true : false; - if(is_set_constraint) - { - if(larger_x) - { - dx = constraint.right() - pos().x() - OFFSET; - } - if(larger_y) - { - dy = constraint.bottom() - pos().y() - OFFSET; - } - if(small_x) - { - dx = constraint.left() - pos().x() - OFFSET; - } - if(small_y) - { - dy = constraint.top() - pos().y() - OFFSET; - } - } - deltax += dx; - deltay += dy; - this->move(this->pos().x() + dx, this->pos().y() + dy); - emit button_move(dir, dx, dy); - emit buttonMove(index, dx, dy); -} - -void Stretch_button::mousePressEvent(QMouseEvent *event) -{ - if(event->button() == Qt::LeftButton) - { - is_click = true; - } - point = event->globalPos(); - deltax = 0; - deltay = 0; - emit button_click(true); -} - -void Stretch_button::mouseReleaseEvent(QMouseEvent *event) -{ - is_click = false; - emit button_click(false, deltax, deltay); -} - -void Stretch_button::set_constraint(QRect rect) -{ - constraint = rect; - is_set_constraint = true; -} - -void Stretch_button::translate(int dx, int dy) -{ - this->move(pos().x() + dx, pos().y() + dy); -} - -void Stretch_button::setIndex(int index) -{ - this->index = index; -} diff --git a/Paint/Data/stretch_button.h b/Paint/Data/stretch_button.h deleted file mode 100644 index 46edd6b..0000000 --- a/Paint/Data/stretch_button.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef STRETCH_BUTTON_H -#define STRETCH_BUTTON_H -#include -#include "Common.h" - -class Stretch_button : public QPushButton -{ - Q_OBJECT -public: - static const int OFFSET = 5; - - Stretch_button(); - ~Stretch_button(); - Stretch_button(direction dir, QWidget* parent); - Stretch_button(int index, QWidget* parent); - void set_constraint(QRect rect); - void mousePressEvent(QMouseEvent* event); - void mouseMoveEvent(QMouseEvent* event); - void mouseReleaseEvent(QMouseEvent* event); - void translate(int dx, int dy); - void setIndex(int index); -signals: - void button_move(direction dir, int dx, int dy); - void buttonMove(int index, int dx, int dy); - void button_click(bool is_enter, int dx=10000, int dy=10000); -private: - direction dir; - int index; - QPoint point; - bool is_click; - QRect constraint; - bool is_set_constraint; - int deltax, deltay; -}; - -#endif // STRETCH_BUTTON_H diff --git a/Paint/PaintWindow.cpp b/Paint/PaintWindow.cpp deleted file mode 100644 index 2f5b5d1..0000000 --- a/Paint/PaintWindow.cpp +++ /dev/null @@ -1,578 +0,0 @@ -#include "PaintWindow.h" -//#include "ui_paint_window.h" -#include -#include -#include "Manager/WindowManager.h" -#include -#include -#include -#include -#include "Widgets/recorder.h" -#include "Widgets/style_manager.h" -#include "Widgets/history.h" -#include -#include -#include "Manager/config.h" -#include -#include "Manager/KeyManager.h" -#include -#include -#include -#include "Paint/Widgets/Panels/close_dialog.h" -#include "Paint/Widgets/Panels/paint_setting_panel.h" -#include "Paint/Widgets/Panels/flow_edit_panel.h" -#include "opencv2/core.hpp" -#include "opencv2/opencv.hpp" -#include "Style_widget/titlebar.h" -#include "Style_widget/framelesshelper.h" -#include "Paint/Widgets/Layers/baselayer.h" -#include "Paint/Data/History_data.h" -#include -#include -#include -#include "Helper/imagehelper.h" -#include "Helper/common.h" - -PaintWindow::PaintWindow(QWidget *parent) : - WindowBase(parent) -// ui(new Ui::PaintWindow) -{ - // ui->setupUi(this); - centralWidget = new QWidget(this); - toolbar = new QToolBar(this); - setCentralWidget(centralWidget); - addToolBar(Qt::TopToolBarArea, toolbar); - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - Titlebar* title_bar = new Titlebar(this); - installEventFilter(title_bar); - FramelessHelper* helper = new FramelessHelper(this); - helper->activateOn(this); - helper->setWidgetResizable(true); - helper->setWidgetMovable(true); - helper->setTitleHeight(30); - helper->setRubberBandOnResize(true); - setWindowFlags (Qt::FramelessWindowHint); - setWindowTitle("简截"); - setWindowIcon(QIcon(":/image/avator.png")); -// connect(title_bar, &Titlebar::minimize, this, [=]() { -// WindowManager::changeWindow("tray"); -// }); - qRegisterMetaType("BaseLayer"); - menu_bar = new QMenuBar(this); - QWidget* menu_widget = new QWidget(this); - QVBoxLayout* menu_layout = new QVBoxLayout(); - menu_layout->setMargin(0); - menu_layout->addWidget(title_bar); - menu_layout->addWidget(menu_bar); - menu_widget->setLayout(menu_layout); - menu_widget->setStyleSheet("background-color: rgb(255, 255, 255)"); - setMenuWidget(menu_widget); - - layout = new QHBoxLayout(centralWidget); - Paint_setting_panel::instance(this); - - this->area = new PaintArea(this); - paint_panel = new QGraphicsView(this->area, this); - paint_panel->setFrameShape(QFrame::NoFrame); - paint_panel->setBackgroundRole(QPalette::Light); - paint_panel->setAlignment(Qt::AlignCenter); - paint_panel->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - paint_panel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - //paint_panel->setWidgetResizable(true); - paint_panel->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); - pen_cursor = QCursor(QPixmap(":/image/pencil.png"), 0, 24); - - layout->addWidget(paint_panel); - centralWidget->setLayout(layout); - set_menubar(); - set_toolbar(); - initSettingPanel(); - addToolBarBreak(); - setMinimumSize(400, 200); -} - -PaintWindow::~PaintWindow() { - // delete ui; -} - -void PaintWindow::loadKeyEvent(QString name) { - // if(!KeyManager::isContainsWindow("PaintWindow")) - // { - KeyManager::instance()->addFunc(this, name, "undo", [=](bool is_enter) { - if(is_enter) Recorder::instance()->back(); - }); - KeyManager::instance()->addFunc(this, name, "redo", [=](bool is_enter) { - if(is_enter) Recorder::instance()->forward(); - }); - KeyManager::instance()->addFunc(this, name, "save", [=](bool is_enter) { - if(is_enter) { - QString file_name = QFileDialog::getSaveFileName(this,"保存", - History::instance()->get_last_directory(), "图片(*.bmp *.jpg *.jpeg *.png);;所有文件(*)"); - KeyManager::instance()->clearKeys("PaintWindow"); - if(file_name != "") { - area->save(History_data::Persist, file_name); - WindowManager::changeWindow("tray"); - } - } - }); - KeyManager::instance()->addFunc(this, name, "new_capture", [=](bool is_enter) { - if(is_enter) { - if(Config::getConfig(Config::capture_mode) == (int)Config::TOTAL_CAPTURE) { - QTimer::singleShot(200, this, [=]() { - QPixmap map = ImageHelper::grabScreen(); - WindowManager::changeWindow("PaintWindow", map, ImageHelper::getCurrentScreen()->geometry()); - if(Config::getConfig(Config::clip_voice)) - QSound::play(":/audio/screenshot.wav"); - }); - - return; - } else { - changeWindowHelper(); - } - Config::setConfig(Config::capture_mode, Config::RECT_CAPTURE); - } - }); - KeyManager::instance()->addFunc(this, name, "delete_shape", [=](bool is_enter) { - if(is_enter) { - // area->delete_shape(); - } - }); - // } -} - -void PaintWindow::set_menubar() { - QMenu* file_setting_menu = new QMenu(this); - file_setting_menu->setTitle(MString::search("{m2Llo9nJ9o}文件")); - QAction* open_action = new QAction(MString::search("{zA7Twj1QhJ}打开"), file_setting_menu); - file_setting_menu->addAction(MString::search("{zA7Twj1QhJ}打开"), open_action, [=]() { - QString file_name = QFileDialog::getOpenFileName(this, - "打开", - History::instance()->get_last_directory(), - "图片(*.bmp *.jpg *.jpeg *.png);;所有文件(*)"); - if(file_name.isEmpty()) { - return; - } else { - QPixmap pixmap; - if(!pixmap.load(file_name)) { - qWarning("文件打开失败"); - return; - } - QRect rect = pixmap.rect(); - rect.moveTo(0, 0); - receiveData(pixmap, rect); - } - }); - QAction* save_action = new QAction(MString::search("{0EtTa6lKzl}另存为"), file_setting_menu); - file_setting_menu->addAction(MString::search("{0EtTa6lKzl}另存为"), save_action, [=]() { - QString file_name = QFileDialog::getSaveFileName(this, - "保存", - History::instance()->get_last_directory(), - "图片(*.bmp *.jpg *.jpeg *.png);;所有文件(*)"); - if(file_name != "") { - area->save(History_data::Persist, file_name); - WindowManager::changeWindow("tray"); - } - }); - QAction* history_action = new QAction(MString::search("{Mo0LoFqQqT}历史"), menu_bar); - QMenu* history_menu = new QMenu(MString::search("{Mo0LoFqQqT}历史"), menu_bar); - connect(history_action, &QAction::hovered, this, [=]() { //动态生成菜单项 - if(History::instance()->is_change) { //hovered会一直触发,防止重复调用函数导致闪屏 - History::instance()->is_change = false; - history_menu->clear(); - QList history_actions; - int history_num = History::instance()->get_history_num(); - for(int i=history_num-1; i>=0; i--) { - History_data data = History::instance()->get(i); - QString file_name = data.type == History_data::Persist ? - data.file_name.mid(data.file_name.lastIndexOf('/')+1) : - QDateTime::fromSecsSinceEpoch(data.time).toString("yyyy.MM.dd hh:mm:ss"); - - QAction* action = new QAction(history_menu); - action->setText(file_name); - connect(action, &QAction::triggered, this, [=]() { - QPixmap pixmap; - - if(!pixmap.load(data.file_name)) { - qWarning("文件不存在"); - return; - } - QRect rect = pixmap.rect(); - rect.moveTo(0, 0); - // area->pic_save = true;//不需要添加记录 - receiveData(pixmap, rect); - }); - history_actions.append(action); - } - history_menu->addActions(history_actions); - } - }); - history_action->setMenu(history_menu); - file_setting_menu->addAction(history_action); - menu_bar->addMenu(file_setting_menu); -} - -void PaintWindow::set_toolbar() { - QToolButton* new_button = new QToolButton(this); - connect(new_button, &QToolButton::clicked, this, [=]() { - if(Config::getConfig(Config::capture_mode) == Config::TOTAL_CAPTURE) { - WindowManager::changeWindow("tray"); - QTimer::singleShot(200, this, [=]() { - QPixmap map = ImageHelper::grabScreen(); - WindowManager::changeWindow("PaintWindow", map, ImageHelper::getCurrentScreen()->geometry()); - }); - return; - } else { - changeWindowHelper(); - } - }); - new_button->setText(MString::search("{cR3jOHb9Qw}新建")); - new_button->setIcon(ImageHelper::getIcon("capture")); - new_button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - toolbar->addWidget(new_button); - - QToolButton* mode_button = new QToolButton(this); - mode_button->setText(MString::search(MString::search("{7yUWnx82jI}模式"))); - mode_button->setIcon(ImageHelper::getIcon("mode")); - mode_button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - mode_button->setPopupMode(QToolButton::InstantPopup); - QMenu* mode_menu = new QMenu(this); - mode_menu->addAction(MString::search("{OBwjJUhTkh}矩形窗口")); - mode_menu->addAction(MString::search("{FHFzLMcLYa}全屏")); - mode_menu->addAction(MString::search("{fnGapBU4vo}自由截图")); - mode_menu->addAction(MString::search("{ETY295cnab}滚动截屏")); - QList actions = mode_menu->actions(); - for(int i=0; isetCheckable(true); - actions[i]->setData(QVariant(i)); - } - actions[Config::getConfig(Config::capture_mode)]->setChecked(true); - connect(mode_menu, &QMenu::triggered, this, [=](QAction* action) { - QVariant index_var = action->data(); - int index = index_var.toInt(); - for(int i=0; isetChecked(false); - } - action->setChecked(true); - Config::setConfig(Config::capture_mode, index); - }); - mode_button->setMenu(mode_menu); - toolbar->addWidget(mode_button); - - QToolButton* clipboard_button = new QToolButton(this); - clipboard_button->setIcon(ImageHelper::getIcon("clipboard")); - clipboard_button->setToolTip(MString::search("{ntbJbEqxwF}复制到剪切板")); - connect(clipboard_button, &QToolButton::clicked, this, [=]() { - area->save2Clipboard(); - }); - toolbar->addWidget(clipboard_button); - - QToolButton* save_button = new QToolButton(this); - save_button->setIcon(ImageHelper::getIcon("save")); - save_button->setToolTip(MString::search("{pJqTHhEQdb}保存")); - connect(save_button, &QToolButton::clicked, this, [=]() { - QString file_name = QFileDialog::getSaveFileName(this, - "保存", - History::instance()->get_last_directory(), - "图片(*.bmp *.jpg *.jpeg *.png);;所有文件(*)"); - if(file_name != "") { - area->save(History_data::Persist, file_name); - WindowManager::changeWindow("tray"); - } - }); - toolbar->addWidget(save_button); - toolbar->addSeparator(); - - QToolButton* undo_button = new QToolButton(this); - undo_button->setIcon(ImageHelper::getIcon("undo")); - undo_button->setToolTip(MString::search("{h5KymvIMTN}撤销")); - connect(undo_button, &QPushButton::clicked, this, [=]() { - Recorder::instance()->back(); - }); - toolbar->addWidget(undo_button); - QToolButton* redo_button = new QToolButton(this); - redo_button->setToolTip(MString::search("{a7CaC7NOL5}恢复")); - redo_button->setIcon(ImageHelper::getIcon("redo")); - connect(redo_button, &QPushButton::clicked, this, [=]() { - Recorder::instance()->forward(); - }); - toolbar->addWidget(redo_button); - - connect(Recorder::instance(), &Recorder::recordChange, this, [=]() { - if(!Recorder::instance()->undoAvaliable()) { - undo_button->setEnabled(false); - } else { - undo_button->setEnabled(true); - } - if(!Recorder::instance()->redoAvaliable()) { - redo_button->setEnabled(false); - } else { - redo_button->setEnabled(true); - } - }); - - QToolButton* ocrButton = new QToolButton(this); - ocrButton->setIcon(ImageHelper::getIcon("ocr")); - ocrButton->setToolTip(MString::search("{SvJhCjRGF0}提取文字")); - connect(ocrButton, &QToolButton::clicked, this, [=]() { - if(area->save(History_data::Editable, "ocr/1.png")) { - area->startOcr(); - } - }); - toolbar->addWidget(ocrButton); - - toolbar->addSeparator(); - paint_button_group = new QButtonGroup(this); - paint_button_group->setExclusive(true); - cursor_button = new QToolButton(this); - cursor_button->setIcon(ImageHelper::getIcon("cursor")); - cursor_button->setToolTip(MString::search("{l4yTU9QXUd}指针")); - cursor_button->setCursor(QCursor(QPixmap(":/image/cursor.png"), 0, 0)); - cursor_button->setCheckable(true); - paint_button_group->addButton(cursor_button, 0); - toolbar->addWidget(cursor_button); - - pencil_button = new QToolButton(this); - pencil_button->setIcon(ImageHelper::getIcon("pencil")); - // pencil_button->setToolTip(); - pencil_button->setCheckable(true); - pencil_button->setChecked(true); - pencil_button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - pencil_button->setPopupMode(QToolButton::InstantPopup); - QMenu* pen_menu = new QMenu(this); - pen_menu->addAction(MString::search("{ndvChZ2O6z}笔")); - pen_menu->addAction(MString::search("{j54u1kWtCx}荧光笔")); - QList penactions = pen_menu->actions(); - for(int i=0; isetCheckable(true); - penactions[i]->setData(QVariant(i)); - } - penactions[0]->setChecked(true); - connect(pen_menu, &QMenu::triggered, this, [=](QAction* action) { - QVariant index_var = action->data(); - int index = index_var.toInt(); - for(int i=0; isetChecked(false); - } - action->setChecked(true); - switch(index) { - case 0: - Style_manager::instance()->change_pen(UIManager::instance()->getPencilData()); - pen_cursor = QCursor(QPixmap(":/image/pencil.png"), 0, 24); - break; - case 1: - Style_manager::instance()->change_pen(UIManager::instance()->getHighlighterData()); - pen_cursor = QCursor(QPixmap(":/image/highlighter_cursor.png"), 0, 24); - break; - } - paint_button_group->buttonClicked(1); - }); - pencil_button->setMenu(pen_menu); - // area->setCursor(QCursor(QPixmap(":/image/pencil.png"), 0, 24)); - paint_button_group->addButton(pencil_button, 1); - toolbar->addWidget(pencil_button); - - // QToolButton* highlighter_button = new QToolButton(this); - // highlighter_button->setToolTip(MString::search("{j54u1kWtCx}荧光笔")); - // highlighter_button->setIcon(QIcon(":/image/highlighter.png")); - // highlighter_button->setCheckable(true); - // paint_button_group->addButton(highlighter_button, 2); - // toolbar->addWidget(highlighter_button); - - QToolButton* shape_button = new QToolButton(this); - shape_button->setToolTip(MString::search("{25JzGpOvFt}形状")); - shape_button->setIcon(ImageHelper::getIcon("shape")); - shape_button->setCheckable(true); - paint_button_group->addButton(shape_button, 2); - toolbar->addWidget(shape_button); - - QToolButton* erase_button = new QToolButton(this); - erase_button->setToolTip(MString::search("{7cwKObEhcx}擦除")); - erase_button->setIcon(ImageHelper::getIcon("eraser")); - erase_button->setCheckable(true); - paint_button_group->addButton(erase_button, 3); - toolbar->addWidget(erase_button); - connect(paint_button_group, static_cast(&QButtonGroup::buttonClicked) - , this, [=](int id) { - switch (id) { - case 0: - area->stateChange(ARROW); - cursor_button->setChecked(true); - paint_panel->viewport()->setCursor(QCursor(QPixmap(":/image/cursor.png"), 0, 0)); - break; - case 1: - area->stateChange(PAINT); - pencil_button->setChecked(true); - paint_panel->viewport()->setCursor(pen_cursor); - break; - case 2: - area->stateChange(SHAPE); - shape_button->setChecked(true); - break; - case 3: - area->stateChange(ERASE); - erase_button->setChecked(true); - paint_panel->viewport()->setCursor(QCursor(QPixmap(":/image/eraser.png"), 4, 20)); - break; - } - paint_panel->update(); - Paint_setting_panel::instance()->set_style(); - area->update(); - }); - paint_button_group->buttonClicked(1); - - QToolButton* more_button = new QToolButton(this); - more_button->setToolTip(MString::search("{dAIlC0hPf5}更多画图选项")); - more_button->setIcon(ImageHelper::getIcon("more")); - connect(more_button, &QToolButton::clicked, this, &PaintWindow::showSettingPanel); - toolbar->addWidget(more_button); - - QToolButton* setting_button = new QToolButton(this); - setting_button->setToolTip(MString::search("{dTUpYwhZRM}设置")); - setting_button->setIcon(ImageHelper::getIcon("setting")); - connect(setting_button, &QToolButton::clicked, this, [=]() { - WindowManager::openWindow("Setting"); - }); - toolbar->addWidget(setting_button); - toolbar->addSeparator(); - - // QToolButton* test_button = new QToolButton(this); - // test_button->setText("test"); - // connect(test_button, &QToolButton::clicked, this, [=](){ - // QString file_name = QFileDialog::getOpenFileName(this, - // "保存", - // History::instance()->get_last_directory(), - // "图片(*.bmp *.jpg *.jpeg *.png);;所有文件(*)"); - // QString file_name2 = QFileDialog::getOpenFileName(this, - // "保存", - // History::instance()->get_last_directory(), - // "图片(*.bmp *.jpg *.jpeg *.png);;所有文件(*)"); - // cv::Mat image1 = cv::imread(file_name.toStdString()); - // cv::Mat image2 = cv::imread(file_name2.toStdString()); - // cv::resize(image1, image1, cv::Size(image2.cols, image1.rows)); - // cv::Mat ans_image = cv::Mat(image1.rows+image2.rows, image1.cols, CV_8UC3); - // image1.copyTo(ans_image(cv::Rect(0, 0, image1.cols, image1.rows))); - // image2.copyTo(ans_image(cv::Rect(0, image1.rows, image1.cols, image2.rows))); - - // vector compression_params; - // compression_params.push_back(cv::IMWRITE_PNG_COMPRESSION); - // compression_params.push_back(5); // 无压缩png. - // compression_params.push_back(IMWRITE_PNG_STRATEGY); - // compression_params.push_back(IMWRITE_PNG_STRATEGY_FILTERED); - // imwrite("F:/dinfo/test.png", ans_image, compression_params); - // }); - // toolbar->addWidget(test_button); -} - -void PaintWindow::receiveData(QVariant data1, QVariant data2){ - QPixmap pix = data1.value(); - QRect rect = data2.value(); - if(pix.isNull()){ - pix = QPixmap(100, 100); - } - reset(); - area->setPic(pix, rect);//在这个函数中还设置了paint_panel的大小 - paint_panel->update(); - paint_button_group->buttonClicked(1); - if(Config::getConfig(Config::auto_copy_to_clipboard)) { - QClipboard *clip=QApplication::clipboard(); - clip->setPixmap(pix); - } - QScreen* screen = ImageHelper::getCurrentScreen(); - QRect geometry = screen->availableGeometry(); - int currentWidth = rect.width() + 100; - int currentHeight = rect.height() + 140; - if(currentWidth >= (double)geometry.width() - || currentHeight >= (double)geometry.height()) { - showMaximized(); - } else { - resize(currentWidth, currentHeight);//设置主窗口大小,否则窗口大小不会变化 - //左上角移动到指定位置,截图越大越向(0, 0)点接近 - move(geometry.x() + (geometry.width()-currentWidth)/2, geometry.y() + (geometry.height() - currentHeight) / 2); - } - paint_panel->verticalScrollBar()->setValue(rect.height() / 2); - paint_panel->horizontalScrollBar()->setValue(rect.width() / 2); -} - -void PaintWindow::closeEvent(QCloseEvent *event) { - event->ignore(); - // if(Config::get_config(Config::show_close_dialog)) - // { - // Close_dialog* close_dialog = new Close_dialog(area, this); - // connect(close_dialog, &Close_dialog::hide_paint, this, [=](){ - // WindowManager::changeWindow("MainWindow"); - // WindowManager::hideNow(); - // }); - // close_dialog->show(); - // } - if(Config::getConfig(Config::hide_to_tray)) { - WindowManager::changeWindow("tray"); - - } else { - WindowManager::close(); - } -} - -void PaintWindow::reset() { - if(area->needSave()) { - QDir dir; - if(!dir.exists("Data/Temp")) { - dir.mkpath("Data/Temp"); - } - QDateTime time = QDateTime::currentDateTime(); - QString path = "Data/Temp/" + time.toString("dd_mm_yyyy_hh_mm_ss") + "/"; - if(!dir.exists(path)) { - dir.mkpath(path); - } - path += "main.png"; - area->save(History_data::Editable, path); - } - pencil_button->setChecked(true); - area->reset(); - Flow_edit_panel::instance()->reset(); - addToolBar(Flow_edit_panel::instance()); - Flow_edit_panel::instance()->hide(); - Style_manager::instance()->reset(); - Recorder::instance()->reset(); -} - -void PaintWindow::onWindowCancel() { - -} - -void PaintWindow::onWindowSelect() { - setWindowFlag(Qt::WindowSystemMenuHint, true); -} - -void PaintWindow::onPaintWindowClose() { -} - -void PaintWindow::onWindowClose() { - // delete Style_manager::instance(); - // delete Recorder::instance(); - // delete History::instance(); - QClipboard *clip=QApplication::clipboard(); - if(Config::getConfig(Config::auto_copy_to_clipboard)) { - clip->clear(); - } -} - -void PaintWindow::showSettingPanel() { - if(Paint_setting_panel::instance()->isVisible()) { - Paint_setting_panel::instance()->hide(); - } else { - addDockWidget(Qt::RightDockWidgetArea, Paint_setting_panel::instance()); - Paint_setting_panel::instance()->show(); - } -} - -void PaintWindow::initSettingPanel() { - connect(Paint_setting_panel::instance(), &Paint_setting_panel::paint_shape, this, - [=](SHAPE_TYPE type) { - if(type == DELETE_SHAPE) { - area->stateChange(ERASE); - } else { - area->paintShape(type); - paint_button_group->buttonClicked(2); - } - }); -} diff --git a/Paint/Widgets/Layer_list/list_item.cpp b/Paint/Widgets/Layer_list/list_item.cpp deleted file mode 100644 index a25102b..0000000 --- a/Paint/Widgets/Layer_list/list_item.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "list_item.h" -#include -#include -#include -#include "Helper/imagehelper.h" - -List_item::List_item() -{ - -} - -List_item::List_item(QWidget* parent, QString text, bool useable) :QWidget(parent) -{ - QHBoxLayout* layout = new QHBoxLayout(this); - QVBoxLayout* move_button_layout = new QVBoxLayout(this); - QToolButton* up_button = new QToolButton(this); - up_button->setIcon(ImageHelper::getIcon("up")); - up_button->setIconSize(QSize(20, 20)); - QToolButton* down_button = new QToolButton(this); - down_button->setIcon(ImageHelper::getIcon("down")); - down_button->setIconSize(QSize(20, 20)); - connect(up_button, &QPushButton::clicked, this, [=](){ - emit button_click(UP); - }); - connect(down_button, &QPushButton::clicked, this, [=](){ - emit button_click(DOWN); - }); - move_button_layout->addWidget(up_button); - move_button_layout->addWidget(down_button); - layout->addLayout(move_button_layout); - - name = new QLineEdit(this); - name->setText(text); - name->setAlignment(Qt::AlignLeft); - connect(name, &QLineEdit::returnPressed, this, [=](){ - emit text_change(name->text()); - }); - QToolButton* close_button = new QToolButton(this); - close_button->setIcon(ImageHelper::getIcon("cancel")); - connect(close_button, &QPushButton::clicked, this, [=](){ - emit button_click(CLOSE); - }); - if(!useable) - { - name->setReadOnly(true); - close_button->setEnabled(false); - } - layout->addWidget(name); - layout->addWidget(close_button); - setLayout(layout); -} - -QString List_item::getName() -{ - return name->text(); -} - -void List_item::setName(QString name) -{ - this->name->setText(name); - update(); -} diff --git a/Paint/Widgets/Layer_list/list_item.h b/Paint/Widgets/Layer_list/list_item.h deleted file mode 100644 index f482fba..0000000 --- a/Paint/Widgets/Layer_list/list_item.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef LIST_ITEM_H -#define LIST_ITEM_H -#include -#include -#include - -class List_item : public QWidget -{ - Q_OBJECT -public: - enum button_type{UP, DOWN, CLOSE, APPEND}; - List_item(); - List_item(QWidget* parent, QString text, bool useable); - void setName(QString name); - QString getName(); -signals: - void text_change(QString text); - void button_click(button_type index); -private: - QLineEdit* name; -}; - -#endif // LIST_ITEM_H diff --git a/Paint/Widgets/Layer_list/list_widget.cpp b/Paint/Widgets/Layer_list/list_widget.cpp deleted file mode 100644 index 20c6661..0000000 --- a/Paint/Widgets/Layer_list/list_widget.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include "list_widget.h" -#include -#include - - -List_widget::List_widget() -{ - -} - -List_widget::List_widget(QWidget* parent) : QListWidget(parent) -{ - setViewMode(QListView::ListMode); - setFlow(QListView::TopToBottom); - setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); - - QPushButton* add_widget_button = new QPushButton(this); - add_widget_button->setIcon(QIcon(":/image/add.svg")); - connect(add_widget_button, &QPushButton::clicked, this, [=](){ - emit button_click(-1, List_item::APPEND); - }); - QListWidgetItem* item = new QListWidgetItem(this); - add_widget_button->setFixedSize(24, 24); - item->setSizeHint(QSize(100, 48)); - this->addItem(item); - this->setItemWidget(item, add_widget_button); -} - -void List_widget::add_widget(QString name) -{ - QListWidgetItem* item = new QListWidgetItem(); - item->setSizeHint(QSize(100, 48)); - insertItem(count()-1, item); - List_item* list_widget = new List_item(this, name, name == "第0层" ? false : true); - connect(list_widget, &List_item::text_change, this, [=](QString text){ - emit text_change(this->indexFromItem(item).row(), text); - }); - connect(list_widget, &List_item::button_click, this, [=](List_item::button_type index){ - int row = this->indexFromItem(item).row(); - if((index == List_item::UP && row <= 0) || (index == List_item::DOWN && row >= this->count()-2) - || (index == List_item::CLOSE && (row < 0 || row > this->count() - 2)))//最后一个是添加按钮 - { - return; - } - emit button_click(row, index); - if(index == List_item::UP) - { - swap_item(row-1, row); - scrollToItem(this->item(row-1)); - this->setItemSelected(this->item(row-1), true); - } - else if(index == List_item::DOWN) - { - swap_item(row, row+1); - scrollToItem(this->item(row+1)); - this->setItemSelected(this->item(row+1), true); - } - else if(index == List_item::CLOSE) - { - remove_item(row); - } - }); - this->setItemWidget(item, list_widget); -} - -void List_widget::remove_item(int row) -{ - QListWidgetItem *item = this->item(row); - QWidget *widget = itemWidget(item); - if (nullptr != widget) - { - removeItemWidget(item); - widget->deleteLater(); - } - - item = takeItem(row); - delete item; - item = nullptr; -} - -void List_widget::swap_item(int first_row, int second_row) -{ - //保证first row永远在second_row之前,方便后面的处理 - if (first_row > second_row) - { - int temp = first_row; - first_row = second_row; - second_row = temp; - } - else if (first_row == second_row)//相同的两行不允许进行后续交换操作 - { - return; - } - if (second_row > 0) - { - QListWidgetItem* item1 = item(first_row); - QListWidgetItem* item2 = item(second_row); - List_item* widget1 = static_cast(itemWidget(item1)); - List_item* widget2 = static_cast(itemWidget(item2)); - QString name1 = widget1->getName(); - widget1->setName(widget2->getName()); - widget2->setName(name1); - } -} -/* -void List_widget::wheelEvent(QWheelEvent* event) -{ - int degress = event->angleDelta().ry() * 0.5; - if(event->orientation() == Qt::Vertical) - verticalScrollBar()->setValue(verticalScrollBar()->value() - degress); - event->accept(); -} -*/ diff --git a/Paint/Widgets/Layer_list/list_widget.h b/Paint/Widgets/Layer_list/list_widget.h deleted file mode 100644 index bb29ca0..0000000 --- a/Paint/Widgets/Layer_list/list_widget.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef LIST_WIDGET_H -#define LIST_WIDGET_H -#include -#include "list_item.h" - -class List_widget : public QListWidget -{ - Q_OBJECT -public: - List_widget(); - List_widget(QWidget* parent=nullptr); - void add_widget(QString name); - //void wheelEvent(QWheelEvent* event)override; -signals: - void text_change(int index, QString text); - void button_click(int index, List_item::button_type button_type); -private: - void remove_item(int row); - void swap_item(int before, int after); -}; - -#endif // LIST_WIDGET_H diff --git a/Paint/Widgets/Layers/LayerItems/expandbutton.cpp b/Paint/Widgets/Layers/LayerItems/expandbutton.cpp deleted file mode 100644 index 2e8ae2c..0000000 --- a/Paint/Widgets/Layers/LayerItems/expandbutton.cpp +++ /dev/null @@ -1,170 +0,0 @@ -#include "expandbutton.h" -#include -#include -#include - -ExpandButton::ExpandButton() -{ - is_limit = false; - is_capture = false; - setAcceptHoverEvents(true); -} - -ExpandButton::ExpandButton(QGraphicsItem* parent) : QGraphicsObject(parent) -{ - is_limit = false; - is_capture = false; - setAcceptHoverEvents(true); -} - -ExpandButton::ExpandButton(direction dir, QPointF pos, QGraphicsItem* parent): QGraphicsObject(parent) -{ - this->dir = dir; - setPos(pos); - setAcceptHoverEvents(true); - is_limit = false; - is_capture = false; -} - -void ExpandButton::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - begin_point = event->scenePos(); - record_point = event->scenePos(); - emit posChangeBegin(begin_point.x(), begin_point.y()); -} - -void ExpandButton::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - QPointF delta_point = event->scenePos() - begin_point; - begin_point = event->scenePos(); - QPointF after_point = pos() + delta_point; - if(is_limit && (after_point.x() > limit.right() || after_point.x() < limit.left() - || after_point.y() > limit.bottom() || after_point.y() < limit.top())) - { - return; - } - moveBy(delta_point.x(), delta_point.y()); - emit posChange(dir, delta_point.x(), delta_point.y()); - emit posChange(index, delta_point.x(), delta_point.y(), x_neighbor_index, y_neighbor_index); -} - -void ExpandButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - QPointF delta_point = event->scenePos() - begin_point; - begin_point = event->scenePos(); - QPointF after_point = pos() + delta_point; - if(is_limit && (after_point.x() > limit.right() || after_point.x() < limit.left() - || after_point.y() > limit.bottom() || after_point.y() < limit.top())) - { - return; - } - moveBy(delta_point.x(), delta_point.y()); - delta_point = event->scenePos() - record_point; - emit posTo(dir, delta_point.x(), delta_point.y()); -} - -void ExpandButton::hoverEnterEvent(QGraphicsSceneHoverEvent *event) -{ - out_cursor = cursor(); - if(is_capture) - { - setCursor(Qt::PointingHandCursor); - } - if(dir == N || dir == S) - { - setCursor(Qt::SizeVerCursor); - } - else if(dir == W || dir == E) - { - setCursor(Qt::SizeHorCursor); - } - else if(dir == NE || dir == SW) - { - setCursor(Qt::SizeBDiagCursor); - } - else - { - setCursor(Qt::SizeFDiagCursor); - } -} - -void ExpandButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) -{ - setCursor(out_cursor); -} - -void ExpandButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - QBrush brush(QColor(255, 255, 255, 128)); - painter->setBrush(brush); - painter->drawEllipse(QPointF(0, 0), radius, radius); -} - -QRectF ExpandButton::boundingRect() const -{ - return QRectF(-QPointF(radius, radius), QPointF(radius, radius)); -} - -QPainterPath ExpandButton::shape() const -{ - QPainterPath path; - path.addEllipse(QRectF(-QPointF(radius, radius), QPointF(radius, radius))); - return path; -} - -void ExpandButton::setLimit(QRectF rect) -{ - is_limit = true; - limit = rect; -} - -void ExpandButton::setIndex(int index) -{ - this->index.append(index); - is_capture = true; -} - -void ExpandButton::setPosition(QPointF pos) -{ - setPos(pos); -} - -bool ExpandButton::setNeighbor(QPoint pos, int index) -{ - if(this->pos().x() == pos.x()) - { - x_neighbor_index = index; - return true; - } - else if(this->pos().y() == pos.y()) - { - y_neighbor_index = index; - return true; - } - return false; -} - -void ExpandButton::setIntPos(QPoint pos) -{ - this->int_point = pos; -} - -QPoint ExpandButton::getPos() -{ - return int_point; -} - -void ExpandButton::clearIndex() -{ - index.clear(); -} - -QList ExpandButton::getIndex() -{ - return index; -} - -void ExpandButton::setButtonIndex(int index) -{ - buttonIndex = index; -} diff --git a/Paint/Widgets/Layers/LayerItems/expandbutton.h b/Paint/Widgets/Layers/LayerItems/expandbutton.h deleted file mode 100644 index 90dcd3b..0000000 --- a/Paint/Widgets/Layers/LayerItems/expandbutton.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef EXPANDBUTTON_H -#define EXPANDBUTTON_H -#include -#include "Paint/Data/Common.h" -#include -#include - -class ExpandButton : public QGraphicsObject -{ - Q_OBJECT -public: - ExpandButton(); - ExpandButton(QGraphicsItem* parent=nullptr); - ExpandButton(direction dir, QPointF pos, QGraphicsItem* parent=nullptr); - void mousePressEvent(QGraphicsSceneMouseEvent *event) override; - void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; - void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; - void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; - void setLimit(QRectF rect); - void setIndex(int index); - void setButtonIndex(int index); - void setPosition(QPointF pos); - void setIntPos(QPoint pos); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; - QRectF boundingRect() const override; - QPainterPath shape() const override; - bool setNeighbor(QPoint pos, int index); - QPoint getPos(); - void clearIndex(); - QList getIndex(); -signals: - void posChangeBegin(qreal x, qreal y); - void posChange(direction dir, qreal x, qreal y); - void posChange(QList index, qreal x, qreal y, int x_neighbor_index, int y_neighbor_index); - void posTo(direction dir, qreal x, qreal y); -private: - direction dir; - QList index; - int buttonIndex; - int x_neighbor_index; - int y_neighbor_index; - QCursor out_cursor; - QPointF begin_point; - QPointF record_point; - QPoint int_point; - QRectF limit; - bool is_limit; - bool is_capture; - const qreal radius = 5; -}; - -#endif // EXPANDBUTTON_H diff --git a/Paint/Widgets/Layers/LayerItems/paintitem.cpp b/Paint/Widgets/Layers/LayerItems/paintitem.cpp deleted file mode 100644 index 386cfd9..0000000 --- a/Paint/Widgets/Layers/LayerItems/paintitem.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "paintitem.h" -#include "Helper/math.h" -#include "Helper/debug.h" - -PaintItem::PaintItem(PaintInfo info, QGraphicsItem* parent) : QGraphicsObject(parent) { - this->info = info; - setCacheMode(ItemCoordinateCache); - pen.setColor(info.style_info->color); - pen.setWidth(info.style_info->width); - pen.setCapStyle(info.style_info->cap_style); - pen.setJoinStyle(info.style_info->join_style); - if(info.path.size() != 0) { - path = QPainterPath(); - path.moveTo(info.path.at(0)); - boundRect.setTopLeft(info.path.at(0)); - } - _isEnd = false; -} - -QRectF PaintItem::boundingRect() const { - return Math::resizeRect(boundRect, info.style_info->width+1, info.style_info->width+1); -} - -void PaintItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - if(!_isEnd) { - paintLine(painter); - } -// for(int i=0; idrawLine(info.path.at(i), info.path.at(i+1)); -// } -} - -void PaintItem::paintLine(QPainter *painter) { - painter->setPen(pen); - painter->drawPath(path); -} - -QPainterPath PaintItem::shape() const { - QPainterPath shape; - shape.addPolygon(QPolygonF(info.path)); - return shape; -} - -void PaintItem::addPoint(QPointF point, bool updateGlobal) { - QPointF lastPoint = info.path.last(); - info.path.append(point); - this->path.lineTo(point); - if(boundRect.left() > point.x()) { - boundRect.setLeft(point.x()); - } - if(boundRect.right() < point.x()) { - boundRect.setRight(point.x()); - } - if(boundRect.top() > point.y()) { - boundRect.setTop(point.y()); - } - if(boundRect.bottom() < point.y()) { - boundRect.setBottom(point.y()); - } - if(updateGlobal) - update(); - else - update(Math::resizeRect(Math::buildRect(lastPoint, point), info.style_info->width+1, info.style_info->width+1)); -} - - -void PaintItem::setEnd() { - _isEnd = true; -} diff --git a/Paint/Widgets/Layers/LayerItems/paintitem.h b/Paint/Widgets/Layers/LayerItems/paintitem.h deleted file mode 100644 index e9a38ab..0000000 --- a/Paint/Widgets/Layers/LayerItems/paintitem.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef PAINTITEM_H -#define PAINTITEM_H - -#include -#include -#include "Base/RecordElement.h" -#include "Paint/Data/paint_data.h" -#include "Paint/Data/Ilayer.h" -#include -#include "Paint/Data/Common.h" -#include -#include - -class PaintItem : public QGraphicsObject { -public: - PaintItem() {} - PaintItem(PaintInfo info, QGraphicsItem* parent=nullptr); - QRectF boundingRect() const override; - void addPoint(QPointF point, bool updateGlobal=false); - QPainterPath shape() const override; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr)override; - void paintLine(QPainter* painter); - void setEnd(); -private: - PaintInfo info; - QVector points; - QPen pen; - QRectF boundRect; - QPainterPath path; - bool _isEnd; -}; - -#endif // PAINTITEM_H diff --git a/Paint/Widgets/Layers/LayerItems/picitem.cpp b/Paint/Widgets/Layers/LayerItems/picitem.cpp deleted file mode 100644 index 6ea0768..0000000 --- a/Paint/Widgets/Layers/LayerItems/picitem.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "picitem.h" -#include -PicItem::PicItem(QGraphicsItem* parent) : QGraphicsItem(parent) -{ - -} - -void PicItem::setPix(const QPixmap &pix){ - prepareGeometryChange(); - this->pix = pix; - mask_pix = pix; - this->bound.setHeight(pix.height()); - this->bound.setWidth(pix.width()); - mask = this->bound; - update(); -} - -void PicItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ - painter->drawPixmap(bound.topLeft(), mask_pix, bound); -} - -void PicItem::reset(){ - pix = QPixmap(); - mask_pix = QPixmap(); -} - -void PicItem::setMask(QRectF mask){ - prepareGeometryChange(); - this->mask = mask; -} - -void PicItem::setDisableColor(int index, QColor color) { - if(index != -1) { - disable_color.removeAt(index); - } else { - disable_color.append(color); - } - QImage temp = pix.toImage(); - for(QColor color : disable_color) { - QImage mask = temp.createMaskFromColor(color.rgb(), Qt::MaskOutColor); - temp.setAlphaChannel(mask); - } - for(QColor color: save_disable_color) { - QImage mask = temp.createMaskFromColor(color.rgb(), Qt::MaskOutColor); - temp.setAlphaChannel(mask); - } - mask_pix = QPixmap::fromImage(temp); - update(); -} - -void PicItem::setSaveDisableColor(int index, QColor color) { - if(index != -1) { - save_disable_color.removeAt(index); - } else { - save_disable_color.append(color); - } - QImage temp = pix.toImage(); - for(QColor color: save_disable_color) { - QImage mask = temp.createMaskFromColor(color.rgb(), Qt::MaskOutColor); - temp.setAlphaChannel(mask); - } - for(QColor color : disable_color) { - QImage mask = temp.createMaskFromColor(color.rgb(), Qt::MaskOutColor); - temp.setAlphaChannel(mask); - } - mask_pix = QPixmap::fromImage(temp); - update(); -} - -bool PicItem::containsPicture() { - return !pix.isNull(); -} - -QRectF PicItem::boundingRect() const{ - return mask; -} diff --git a/Paint/Widgets/Layers/LayerItems/picitem.h b/Paint/Widgets/Layers/LayerItems/picitem.h deleted file mode 100644 index f6e3542..0000000 --- a/Paint/Widgets/Layers/LayerItems/picitem.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef PICITEM_H -#define PICITEM_H -#include - -class PicItem : public QGraphicsItem -{ -public: - PicItem(QGraphicsItem* parent=nullptr); - void reset(); - void setEnableMove(bool enable); - void setDisableColor(int index, QColor color); - void setSaveDisableColor(int index, QColor color); - bool containsPicture(); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) override; - QRectF boundingRect() const override; - void setPix(const QPixmap& pix); - void setMask(QRectF mask); -private: - QPixmap pix; - QRectF bound; - QRectF mask; - QList disable_color; - QList save_disable_color; - QPixmap mask_pix; -}; - -#endif // PICITEM_H diff --git a/Paint/Widgets/Layers/LayerItems/scrollitem.cpp b/Paint/Widgets/Layers/LayerItems/scrollitem.cpp deleted file mode 100644 index a9ab6b0..0000000 --- a/Paint/Widgets/Layers/LayerItems/scrollitem.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "scrollitem.h" -#include -#include -#include -#include -#include -#include -#include - -ScrollItem::ScrollItem(QGraphicsItem* parent) : QGraphicsObject(parent) -{ - pix = QPixmap(":/image/rotate.png"); - pix.scaled(16, 16); - setCursor(QCursor(pix)); -} - -void ScrollItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - painter->drawPixmap(QPointF(-pix.width()/2.0, -pix.height()/2.0), pix); -} - -QRectF ScrollItem::boundingRect() const -{ - return QRectF(QPointF(-pix.width()/2.0, -pix.height()/2.0), QSizeF(pix.width(), pix.height())); -} - -void ScrollItem::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - begin_point = event->scenePos(); -} - -void ScrollItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - begin_point = mapToParent(mapFromScene(begin_point)); - QVector2D start_vec(begin_point.x(), begin_point.y()); - start_vec.normalize(); - QPointF point = mapToParent(mapFromScene(event->scenePos())); - QVector2D end_vec(point.x(), point.y()); - end_vec.normalize(); - - qreal dotValue = QVector2D::dotProduct(start_vec, end_vec); - if (dotValue > 1.0) - dotValue = 1.0; - else if (dotValue < -1.0) - dotValue = -1.0; - - dotValue = qAcos(dotValue); - - qreal angle = dotValue * 1.0 / (M_PI / 180); - - QVector3D crossValue = QVector3D::crossProduct( \ - QVector3D(start_vec, 1.0), \ - QVector3D(end_vec, 1.0)); - - if (crossValue.z() < 0) - angle = -angle; - emit angleChange(angle); - begin_point = event->scenePos(); -} diff --git a/Paint/Widgets/Layers/LayerItems/scrollitem.h b/Paint/Widgets/Layers/LayerItems/scrollitem.h deleted file mode 100644 index cda4f59..0000000 --- a/Paint/Widgets/Layers/LayerItems/scrollitem.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef SCROLLITEM_H -#define SCROLLITEM_H -#include - -class ScrollItem : public QGraphicsObject -{ - Q_OBJECT -public: - ScrollItem(QGraphicsItem* parent); - QRectF boundingRect()const override; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr)override; - void mousePressEvent(QGraphicsSceneMouseEvent *event) override; - void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; -signals: - void angleChange(qreal angle); -private: - QPixmap pix; - QPointF begin_point; -}; - -#endif // SCROLLITEM_H diff --git a/Paint/Widgets/Layers/arrowlayer.cpp b/Paint/Widgets/Layers/arrowlayer.cpp deleted file mode 100644 index 06a1747..0000000 --- a/Paint/Widgets/Layers/arrowlayer.cpp +++ /dev/null @@ -1,167 +0,0 @@ -#include "arrowlayer.h" -#include -#include -#include -#include "Paint/Widgets/style_manager.h" - -ArrowLayer::ArrowLayer(QGraphicsItem* parent, QPointF begin_point, QPointF end_point) - : QGraphicsObject(parent), - is_focus(true), - enable_move(true) { - setLine(begin_point, end_point); - begin_button = new ExpandButton(W, begin_point, this); - end_button = new ExpandButton(E, end_point, this); - setAcceptHoverEvents(true); - connect(begin_button, static_cast(&ExpandButton::posChange), this, &ArrowLayer::posChangeFunc); - connect(end_button, static_cast(&ExpandButton::posChange), this, &ArrowLayer::posChangeFunc); - data = Style_manager::instance()->get_now(); -} - -void ArrowLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - painter->setRenderHint(QPainter::Antialiasing, true); //设置反走样,防锯齿 - QPen pen(data.color, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); - QBrush brush(data.color, Qt::SolidPattern); - painter->setPen(pen); - painter->setBrush(brush); - QLineF line(begin_point, end_point); - painter->drawLine(line); - painter->drawPolygon(arrow_points, 3); -} - -QRectF ArrowLayer::boundingRect() const { - QRectF ans(begin_point, end_point); - ans.setTopLeft(ans.topLeft() - QPointF(3, 3)); - ans.setBottomRight(ans.bottomRight() + QPointF(3, 3)); - return ans; -} - -QPainterPath ArrowLayer::shape() const { - QLineF line(begin_point, end_point); - line = line.unitVector(); - QLineF vertical_line = line; - vertical_line.setAngle(line.angle() + 90); - qreal half_width = ExtRefArrowLenght * sin(ExtRefArrowDegrees) + 5; - QPainterPath path; - QLineF new_line = vertical_line; - new_line.setLength(half_width); - path.moveTo(new_line.p2()); - QPointF delta = new_line.p2() - new_line.p1(); - path.lineTo(end_point + delta); - path.lineTo(end_point - delta); - path.lineTo(begin_point - delta); - for(QGraphicsItem* item : childItems()) { - path.addPath(item->shape()); - } - path = path.simplified(); - return path; -} - -void ArrowLayer::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - out_cursor = cursor(); - if(enable_move) { - setCursor(Qt::SizeAllCursor); - showButtons(); - } - QGraphicsObject::hoverEnterEvent(event); -} - -void ArrowLayer::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - setCursor(out_cursor); - hideButtons(); - QGraphicsItem::hoverLeaveEvent(event); -} - -void ArrowLayer::mousePressEvent(QGraphicsSceneMouseEvent *event) { - point = event->scenePos(); -} - -void ArrowLayer::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if(enable_move) { - QPointF delta_point = event->scenePos() - point; - point = event->scenePos(); - moveBy(delta_point.x(), delta_point.y()); - } -} - -void ArrowLayer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if(enable_move) { - QPointF delta_point = event->scenePos() - point; - point = event->scenePos(); - moveBy(delta_point.x(), delta_point.y()); - } -} - -void ArrowLayer::setLine(QPointF begin_point, QPointF end_point) { - this->begin_point = begin_point; - this->end_point = end_point; - createArrow(); -} - -void ArrowLayer::createArrow() { - //箭头直线与水平方向的夹角再加pi - float angle = atan2(end_point.y()-begin_point.y(), end_point.x()-begin_point.x()) + 3.1415926; - //这两个值需要根据实际场景的坐标大小进行调整, - - - arrow_points[0] = end_point; - //求得箭头点1坐标 - arrow_points[1].setX(end_point.x() + ExtRefArrowLenght * cos(angle - ExtRefArrowDegrees)); - arrow_points[1].setY(end_point.y() + ExtRefArrowLenght * sin(angle - ExtRefArrowDegrees)); - //求得箭头点2坐标 - arrow_points[2].setX(end_point.x() + ExtRefArrowLenght * cos(angle + ExtRefArrowDegrees)); - arrow_points[2].setY(end_point.y() + ExtRefArrowLenght * sin(angle + ExtRefArrowDegrees)); -} - -void ArrowLayer::posChangeFunc(direction dir, qreal x, qreal y) { - if(dir == W) { - begin_point = begin_point + QPointF(x, y); - createArrow(); - } else { - end_point = end_point + QPointF(x, y); - createArrow(); - } - QRectF rect = boundingRect(); - rect.setTopLeft(rect.topLeft()-QPointF(5, 5)); - rect.setBottomRight(rect.bottomRight()+QPointF(5, 5)); - update(rect); -} - -void ArrowLayer::getFocusFunc() { - showButtons(); - is_focus = true; -} - -void ArrowLayer::loseFocusFunc() { - is_focus = false; - hideButtons(); -} - -void ArrowLayer::showNormal() { - enable_move = true; -} - -void ArrowLayer::hideNormal() { - loseFocusFunc(); - enable_move = false; -} - -void ArrowLayer::showButtons() { - begin_button->show(); - end_button->show(); -} - -void ArrowLayer::hideButtons() { - if(is_focus) { - return; - } - begin_button->hide(); - end_button->hide(); -} - -bool ArrowLayer::acceptFocus() { - return true; -} - -int ArrowLayer::type() const { - return 65537; -} diff --git a/Paint/Widgets/Layers/arrowlayer.h b/Paint/Widgets/Layers/arrowlayer.h deleted file mode 100644 index 3aa0656..0000000 --- a/Paint/Widgets/Layers/arrowlayer.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef ARROWLAYER_H -#define ARROWLAYER_H -#include -#include "baselayer.h" -#include "LayerItems/expandbutton.h" -#include - -class ArrowLayer : public QGraphicsObject, public BaseLayer { - Q_OBJECT -public: - ArrowLayer(QGraphicsItem* parent, QPointF begin_point, QPointF end_point); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; - QRectF boundingRect()const override; - QPainterPath shape()const override; - void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; - void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; - void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; - void mousePressEvent(QGraphicsSceneMouseEvent *event) override; - void setLine(QPointF begin_point, QPointF end_point); - void getFocusFunc() override; - void loseFocusFunc() override; - int type() const override; - Q_INVOKABLE void hideNormal() override; - Q_INVOKABLE void showNormal() override; - Q_INVOKABLE bool acceptFocus() override; -private slots: - void posChangeFunc(direction dir, qreal x, qreal y); -private: - void createArrow(); - void showButtons(); - void hideButtons(); - QPointF arrow_points[3]; - QPointF begin_point; - QPointF end_point; - QPointF point; - ExpandButton* begin_button; - ExpandButton* end_button; - QCursor out_cursor; - bool is_focus; - bool enable_move; - PaintData data; - const float ExtRefArrowLenght = 10;//箭头末端大小的长度, - const float ExtRefArrowDegrees = M_PI / 6;//箭头末端顶角的一半 -}; - -#endif // ARROWLAYER_H diff --git a/Paint/Widgets/Layers/baselayer.h b/Paint/Widgets/Layers/baselayer.h deleted file mode 100644 index 2c5a73a..0000000 --- a/Paint/Widgets/Layers/baselayer.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef BASELAYER_H -#define BASELAYER_H -#include - -class BaseLayer { -public: - virtual void getFocusFunc() {} - virtual void loseFocusFunc() {} - - /** - * @brief hideNormal 当从指针或绘制形状切换成其他模式时调用,为了不在其他模式中显示边框 - */ - Q_INVOKABLE virtual void hideNormal() {} - Q_INVOKABLE virtual void showNormal() {} - - /** - * @brief acceptFocus 是否被 @ref ShapeLayer::childContains() 考虑在内 - * @return - */ - Q_INVOKABLE virtual bool acceptFocus() { - return true; - } -}; - -#endif // BASELAYER_H diff --git a/Paint/Widgets/Layers/blurlayer.cpp b/Paint/Widgets/Layers/blurlayer.cpp deleted file mode 100644 index e0e2321..0000000 --- a/Paint/Widgets/Layers/blurlayer.cpp +++ /dev/null @@ -1,213 +0,0 @@ -#include "blurlayer.h" -#include -#include -#include "Manager/uimanager.h" - -BlurLayer::BlurLayer(QGraphicsItem* parent) : QGraphicsObject(parent), is_setpic(false) { - is_allocate = false; - is_save = false; - unit_size = UIManager::instance()->getMosaicUnitSize(); - range = UIManager::instance()->getMosaicRange(); -} - -void BlurLayer::setPix(const QPixmap& pix, QPoint pos) { - this->pix = pix.toImage(); - left_top = pos; - setPos(pos); - mask = QImage(pix.width(), pix.height(), QImage::Format_ARGB32); - mask.fill(Qt::transparent); - resetMaskSetting(); - this->is_setpic = true; -} - -BlurLayer::~BlurLayer() { - clearMaskUse(); -} - -QRectF BlurLayer::boundingRect()const { - return bound; -} - -QPainterPath BlurLayer::shape() const { - QPainterPath ans; - ans.addRect(bound); - return ans; -} - -void BlurLayer::addPoint(QPoint point) { - point = QPoint(point.x()-left_top.x(), point.y()-left_top.y()); - if(!is_allocate || point.x() < 0 || point.y() < 0 || point.x() > pix.width() || point.y() > pix.height()) - return; - int red = 0; - int blue = 0; - int green = 0; - int times = 0; - int begin_x = point.x() - range - point.x() % maskUnitSize; - int begin_y = point.y() - range - point.y() % maskUnitSize; - int end_x = point.x() + 2 * range > mask.width() ? mask.width() - 1 : point.x() + 2 * range; - int end_y = point.y() + 2 * range > mask.height() ? mask.height() - 1 : point.y() + 2 * range; - if(bound.width() == 0 || bound.height() == 0){ - bound = QRectF(QPointF(begin_x, begin_y), QPointF(end_x, end_y)); - } - else{ - if(bound.left() > begin_x){ - bound.setLeft(begin_x); - } - if(bound.top() > begin_y){ - bound.setTop(begin_y); - } - if(bound.right() < end_x){ - bound.setRight(end_x); - } - if(bound.bottom() < end_y){ - bound.setBottom(end_y); - } - } - - bool allUse = true; - int unitDelta = range / maskUnitSize; - int maskUsex = begin_x / maskUnitSize; - int maskUsey = begin_y / maskUnitSize; - for(int m=maskUsex; m= 0 && n >= 0 && !mask_use[m][n]) { - allUse = false; - break; - } - } - } - if(!allUse) { - for(int i=begin_x; i= 0 && n >= 0) { - QRgb rgb = pix.pixel(m, n); - red += qRed(rgb); - blue += qBlue(rgb); - green += qGreen(rgb); - times++; - } - } - } - if(times != 0) { - QColor color(red/times, green/times, blue/times); - for(int m=i; m= 0 && n >= 0 && m/maskUnitSize < maskUseWidth && n/maskUnitSize < maskUseHeight && !mask_use[m/maskUnitSize][n/maskUnitSize]) - mask.setPixelColor(m, n, color); - } - } - } - } - } - - for(int m=maskUsex; m= 0 && n >= 0) - mask_use[m][n] = true; - } - } - } - update(); -} - -void BlurLayer::deletePoint(QPoint point) { - point = QPoint(point.x()-left_top.x(), point.y()-left_top.y()); - if(is_allocate) { - int begin_x = point.x() - range - point.x() % range; - int begin_y = point.y() - range - point.y() % range; - bool hasUse = false; - int unitDelta = range / maskUnitSize; - int maskUsex = begin_x / maskUnitSize; - int maskUsey = begin_y / maskUnitSize; - for(int m=maskUsex; m= 0 && n >= 0 && mask_use[m][n]) { - hasUse = true; - mask_use[m][n] = false; - } - } - } - if(hasUse) { - for(int i=begin_x; i= 0 && k >= 0) - mask.setPixelColor(i, k, QColor(0, 0, 0, 0)); - } - } - update(); - } - } -} - -void BlurLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { -// if(!is_save) - painter->drawImage(QPointF(0, 0), mask); -} - -bool BlurLayer::isSetPic() { - return is_setpic; -} - -void BlurLayer::showNormal() { - is_save = false; -} - -void BlurLayer::hideNormal() { - is_save = true; -} - -void BlurLayer::setRange(int range) { - this->range = range - range % maskUnitSize; -} - -void BlurLayer::setUnitSize(int unit_size) { - this->unit_size = unit_size - unit_size % maskUnitSize; -} - -void BlurLayer::resetMaskSetting() { - clearMaskUse(); - mask_use = new bool*[pix.width() / maskUnitSize + 1]; - for(int i=0; i -#include "baselayer.h" -#include - - -class BlurLayer : public QGraphicsObject, public BaseLayer -{ - Q_OBJECT -public: - BlurLayer(QGraphicsItem* parent); - ~BlurLayer(); - QRectF boundingRect()const override; - QPainterPath shape()const override; - void setPix(const QPixmap& pix, QPoint pos); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; - void addPoint(QPoint point); - void deletePoint(QPoint point); - bool isSetPic(); - void setRange(int range); - void setUnitSize(int unit_size); - void reset(); - int type() const override; - Q_INVOKABLE void hideNormal() override; - Q_INVOKABLE void showNormal() override; - Q_INVOKABLE bool acceptFocus() override; -private: - void clearMaskUse(); - struct BlurElement{ - QRect bound; - QColor color; - }; - void resetMaskSetting(); - bool is_setpic; - bool is_allocate; - bool** mask_use; - QPoint left_top; - QImage pix; - QImage mask; - int range=12; - int unit_size=4; - const int maskUnitSize=4; - bool is_save; - int maskUseWidth; - int maskUseHeight; - QRectF bound; -}; - -#endif // BLUELAYER_H diff --git a/Paint/Widgets/Layers/paintlayer.cpp b/Paint/Widgets/Layers/paintlayer.cpp deleted file mode 100644 index 475abc9..0000000 --- a/Paint/Widgets/Layers/paintlayer.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#include "paintlayer.h" -#include -#include -#include -#include -#include "Paint/Widgets/recorder.h" -#include "Paint/Widgets/style_manager.h" -#include -#include "Paint/Widgets/recorder.h" -#include "Paint/Widgets/Recorder_element/paintdeleterecord.h" - -PaintLayer:: PaintLayer(QGraphicsItem* parent) : QGraphicsObject(parent) { - this->parent = parent; - is_enable = true; - is_press = false; - is_erase = false; - _isPixSet = false; - setAcceptedMouseButtons(Qt::NoButton); -} - -PaintLayer::~PaintLayer() { - for(QGraphicsItem* line : lines) { - delete line; - } - if(_isPixSet) { - delete pixPainter; - } -} - -void PaintLayer::reset() { - for(QGraphicsItem* line : lines) { - delete line; - } - lines.clear(); - if(_isPixSet) { - delete pixPainter; - _isPixSet = false; - } -} - -void PaintLayer::mousePressEvent(QGraphicsSceneMouseEvent *event) { - updateAnchor = 0; - if(event->button() == Qt::LeftButton) { - is_press = true; - } - if(is_enable) { - PaintData* paint_data = Style_manager::instance()->get(); - PaintInfo info; - info.style_info = paint_data; - info.path.append(mapFromScene(event->scenePos())); - current_item = new PaintItem(info, this); // 添加一个线条 - } - if(is_erase) { - removeLines(mapFromScene(event->scenePos())); - } -} - -void PaintLayer::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if(is_enable && is_press) { - current_item->addPoint(mapFromScene(event->scenePos())); - } - if(is_erase && is_press) { - removeLines(mapFromScene(event->scenePos())); - } -} - -void PaintLayer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if(is_enable && is_press) { - current_item->setEnd(); - current_item->addPoint(mapFromScene(event->scenePos()), true); - current_item->paintLine(pixPainter); - lines.append(current_item); - PaintRecord* record = new PaintRecord(current_item); - Recorder::instance()->record(record); - update(); - } - is_press = false; -} - -void PaintLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - if(_isPixSet) - painter->drawPixmap(0, 0, pix); -} - -void PaintLayer::setEnableDraw(bool enable) { - this->is_enable = enable; -} - -QRectF PaintLayer::boundingRect() const { - return path.boundingRect(); -} - -void PaintLayer::setErase(bool enable) { - is_erase = enable; -} - -void PaintLayer::removeLines(QPointF point) { - QRectF rect(point - QPointF(3, 3), point + QPointF(3, 3)); - QList items; - for(PaintItem* item : lines) { - if(item->shape().intersects(rect)) { - items.append(item); - } - } - for(PaintItem* item: items) { - PaintDeleteRecord* record = new PaintDeleteRecord(this, item, "undoRedoPaintFunc"); - Recorder::instance()->record(record); - lines.removeOne(item); - } - updateLines(); - update(); -} - -void PaintLayer::undoRedoPaintFunc(bool is_undo, PaintItem *item) { - if(is_undo) { - item->show(); - lines.append(item); - } else { - item->hide(); - lines.removeOne(item); - } - updateLines(); -} - -int PaintLayer::type() const { - return 65539; -} - -void PaintLayer::setPix(const QPixmap &pix, QPoint pos) { - _isPixSet = true; - this->pix = QPixmap(pix.width(), pix.height()); - this->pix.fill(Qt::transparent); - setPos(pos); - pixPainter = new QPainter(&this->pix); - pixPainter->setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing, true); -} - -void PaintLayer::updateLines() { - if(!_isPixSet) - return; - pixPainter->fillRect(0, 0, pix.width(), pix.height(), QBrush(Qt::transparent)); - for(int i=0; ipaintLine(pixPainter); - } -} diff --git a/Paint/Widgets/Layers/paintlayer.h b/Paint/Widgets/Layers/paintlayer.h deleted file mode 100644 index 75e3ed2..0000000 --- a/Paint/Widgets/Layers/paintlayer.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef PAINT_LAYER_H -#define PAINT_LAYER_H -#include -#include -#include -#include -#include "Base/RecordElement.h" -#include "Paint/Data/paint_data.h" -#include "Paint/Data/Ilayer.h" -#include -#include "Paint/Widgets/Recorder_element/paint_record.h" -#include "Paint/Data/Common.h" -#include -#include - -class PaintLayer : public QGraphicsObject { - Q_OBJECT -public: - PaintLayer(QGraphicsItem* parent=nullptr); - ~PaintLayer(); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; - void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; - void mousePressEvent(QGraphicsSceneMouseEvent *event) override; - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; - void setEnableDraw(bool enable); - void setPix(const QPixmap& pix, QPoint pos); - void reset(); - void setErase(bool enable); - Q_INVOKABLE void undoRedoPaintFunc(bool is_undo, PaintItem* item); - QRectF boundingRect() const override; - int type() const override; -private: - void removeLines(QPointF point); - void updateLines(); - QList lines; - PaintItem* current_item; - QPainterPath path; - QGraphicsItem* parent; - bool is_enable; - bool is_press; - bool is_erase; - int updateAnchor; - QPixmap pix; - QPainter* pixPainter; - bool _isPixSet; -}; - -#endif // PAINT_LAYER_H diff --git a/Paint/Widgets/Layers/picture_layer.cpp b/Paint/Widgets/Layers/picture_layer.cpp deleted file mode 100644 index aaf7463..0000000 --- a/Paint/Widgets/Layers/picture_layer.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include "picture_layer.h" -#include "Paint/Widgets/recorder.h" -#include -#include -#include "Paint/Widgets/Recorder_element/resize_record.h" -#include "Paint/Widgets/recorder.h" -#include "Helper/imagehelper.h" - -Picture_layer::Picture_layer(QGraphicsItem* parent): QGraphicsObject(parent) { - rect_layer = new RectLayer(this, boundingRect()); - picItem = new PicItem(this); - connect(rect_layer, &RectLayer::sizeChange, this, [=]() { - prepareGeometryChange(); - ResizeRecord* record = new ResizeRecord(this, "undoRedoSizeFunc", - mask, rect_layer->boundingRect()); - Recorder::instance()->record(record); - mask = rect_layer->boundingRect(); - picItem->setMask(mask); - this->update(); - }); -// rect_layer->setAcceptHoverEvents(false); - setAcceptHoverEvents(true); - rect_layer->show(); - rect_layer->setEnableScroll(false); - setCacheMode(CacheMode::ItemCoordinateCache); - setFlag(QGraphicsItem::ItemIsSelectable); -} - -void Picture_layer::setPixmap(const QPixmap &pix) { - this->bound.setHeight(pix.height()); - this->bound.setWidth(pix.width()); - mask = this->bound; - rect_layer->setBounding(this->boundingRect()); - rect_layer->setLimit(bound); - picItem->setPix(pix); -} - -QRectF Picture_layer::boundingRect() const { - return this->mask; -} - -void Picture_layer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { -// painter->drawPixmap(mask.topLeft(), mask_pix, mask); -} - -void Picture_layer::reset() { - picItem->reset(); - bound = QRectF(); - mask = QRectF(); -} - -void Picture_layer::setEnableMove(bool enable) { - rect_layer->setEnableSizeChange(enable); -} - -void Picture_layer::setDisableColor(int index, QColor color) { - picItem->setDisableColor(index, color); -} - -void Picture_layer::setSaveDisableColor(int index, QColor color) { - picItem->setSaveDisableColor(index, color); -} - -bool Picture_layer::containsPicture() { - return picItem->containsPicture(); -} - -void Picture_layer::prepareSave() { - rect_layer->hide(); -} - -void Picture_layer::endSave() { - rect_layer->show(); -} - -void Picture_layer::undoRedoSizeFunc(bool is_undo, QRectF before_rect, QRectF after_rect) { - prepareGeometryChange(); - if(is_undo) { - mask = before_rect; - rect_layer->setBounding(before_rect); - picItem->setMask(mask); - } else { - mask = after_rect; - rect_layer->setBounding(after_rect); - picItem->setMask(mask); - } - update(); -} - -int Picture_layer::type() const { - return 65541; -} diff --git a/Paint/Widgets/Layers/picture_layer.h b/Paint/Widgets/Layers/picture_layer.h deleted file mode 100644 index 4bf9828..0000000 --- a/Paint/Widgets/Layers/picture_layer.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef PICTURE_LAYER_H -#define PICTURE_LAYER_H -#include -#include -#include -#include -#include "Helper/plist.h" -#include "Paint/Data/Ilayer.h" -#include "paintlayer.h" -#include "Base/RecordElement.h" -#include "Paint/Data/stretch_button.h" -#include "Helper/plist.h" -#include -#include "rect_layer.h" -#include -#include "LayerItems/picitem.h" - -class Picture_layer : public QGraphicsObject -{ - Q_OBJECT -public: - enum DragPos{top_left, top_right, down_left, down_right}; - Picture_layer(QGraphicsItem* parent=nullptr); - void setPixmap(const QPixmap& pix); - QRectF boundingRect() const override; - void reset(); - void setEnableMove(bool enable); - void setDisableColor(int index, QColor color); - void setSaveDisableColor(int index, QColor color); - bool containsPicture(); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) override; - void prepareSave(); - void endSave(); - int type() const override; - Q_INVOKABLE void undoRedoSizeFunc(bool is_undo, QRectF before_rect, QRectF after_rect); -private: - - RectLayer* rect_layer; - PicItem* picItem; - QRectF bound; - QList disable_color; - QList save_disable_color; - QRectF mask; -}; - -#endif // PICTURE_LAYER_H diff --git a/Paint/Widgets/Layers/rect_layer.cpp b/Paint/Widgets/Layers/rect_layer.cpp deleted file mode 100644 index bae3697..0000000 --- a/Paint/Widgets/Layers/rect_layer.cpp +++ /dev/null @@ -1,265 +0,0 @@ -#include "rect_layer.h" -#include -#include -#include -#include - -RectLayer::RectLayer(QGraphicsItem* parent, QRectF rect) - : QGraphicsObject(parent), - scroll_item(new ScrollItem(this)), - style(NORMAL), - enable_move(false), - enable_size_change(false), - enable_scroll(true), - force_show(false) { - setAcceptHoverEvents(true); - setPos(rect.topLeft()); - this->rect = QRectF(QPointF(0, 0), QSize(rect.width(), rect.height())); - setBounding(this->rect); - scroll_item->setPos(QPointF(rect.width()/2, -scroll_item->boundingRect().height())); - connect(scroll_item, &ScrollItem::angleChange, this, [=](qreal angle) { - setTransform(transform().rotate(angle)); - }); -} - -void RectLayer::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - out_cursor = cursor(); - if(enable_size_change) { - setCursor(Qt::SizeAllCursor); - showButtons(); - } - QGraphicsItem::hoverEnterEvent(event); -} - -void RectLayer::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - setCursor(out_cursor); - hideButtons(); - QGraphicsItem::hoverLeaveEvent(event); -} - -void RectLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - painter->setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing, true); - paintStyle(painter); - painter->drawRect(this->boundingRect()); -} - -QPainterPath RectLayer::shape() const { - QPainterPath ans; - QRectF tmp1 = rect; - tmp1.setTopLeft(tmp1.topLeft() - QPoint(5, 5)); - tmp1.setBottomRight(tmp1.bottomRight() + QPoint(5, 5)); - ans.addRect(tmp1); - if(rect.width() > 10 && rect.height() > 10) { - QRectF tmp = rect; - tmp.setTopLeft(tmp.topLeft() + QPoint(5, 5)); - tmp.setBottomRight(tmp.bottomRight() - QPoint(5, 5)); - ans.addRect(tmp); - } - return ans; -} - -void RectLayer::mousePressEvent(QGraphicsSceneMouseEvent *event) { - begin_point = event->scenePos(); - emit requestFocus(this, this); -} - -void RectLayer::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if(enable_move) { - QPointF delta = event->scenePos() - begin_point; - begin_point = event->scenePos(); - moveBy(delta.x(), delta.y()); - emit move(delta.x(), delta.y()); - } -} - -void RectLayer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if(enable_move) { - QPointF delta = event->scenePos() - begin_point; - moveBy(delta.x(), delta.y()); - emit move(delta.x(), delta.y()); - } -} - -QRectF RectLayer::boundingRect() const { - return this->rect; -} - -void RectLayer::showButtons() { - if(enable_size_change) { - for(ExpandButton* button: buttons) { - button->show(); - } - } - if(enable_scroll) { - scroll_item->show(); - } -} - -void RectLayer::hideButtons() { - if(force_show) { - return; - } - for(ExpandButton* button: buttons) { - button->hide(); - } - scroll_item->hide(); -} - -void RectLayer::setBounding(QRectF rect) { - this->rect = rect; - if(buttons.size() == 0) { - for(int i=0; i<4; i++) { - direction dir = (direction)i; - QPointF p = rect.topLeft(); - float x = dir == NW || dir == SW ? p.x() : p.x() + rect.width(); - float y = dir == NW || dir == NE ? p.y() : p.y() + rect.height(); - ExpandButton* button = new ExpandButton(dir, QPointF(x, y), this); - connect(button, static_cast(&ExpandButton::posChange), this, &RectLayer::posChangeFunc); - connect(button, &ExpandButton::posTo, this, &RectLayer::posToFunc); - buttons.insert(dir, button); - } - } else { - for(int i=0; isetPos(x, y); - } - } - hideButtons(); -} - -void RectLayer::posChangeFunc(direction dir, qreal x, qreal y) { - QRectF before_rect = rect; - qreal width = buttons[NW]->boundingRect().width(); - before_rect.setTopLeft(before_rect.topLeft() - QPointF(width, width)); - before_rect.setBottomRight(before_rect.bottomRight() + QPointF(width, width)); - QPointF point(x, y); - prepareGeometryChange(); - switch (dir) { - case NW: - rect.setTopLeft(rect.topLeft() + point); - buttons[NE]->moveBy(0, y); - buttons[SW]->moveBy(x, 0); - break; - case NE: - rect.setTopRight(rect.topRight() + point); - buttons[NW]->moveBy(0, y); - buttons[SE]->moveBy(x, 0); - break; - case SW: - rect.setBottomLeft(rect.bottomLeft() + point); - buttons[SE]->moveBy(0, y); - buttons[NW]->moveBy(x, 0); - break; - case SE: - rect.setBottomRight(rect.bottomRight() + point); - buttons[SW]->moveBy(0, y); - buttons[NE]->moveBy(x, 0); - break; - default: - qDebug() << "no implement this direction"; - break; - } - scroll_item->setPos(rect.left()+rect.width()/2, rect.top()-scroll_item->boundingRect().height()); - update(before_rect); -} - -void RectLayer::posToFunc(direction dir, qreal x, qreal y) { - emit sizeChange(); -} - -void RectLayer::setEnableMove(bool enable) { - enable_move = enable; -} - -void RectLayer::setEnableSizeChange(bool enable) { - enable_size_change = enable; -} - -void RectLayer::getFocusFunc() { - showButtons(); - force_show = true; -} - -void RectLayer::loseFocusFunc() { - force_show = false; - hideButtons(); -} - -void RectLayer::setStyle(RECT_STYLE style, PaintData data) { - this->style = style; - this->data = data; - update(); -} - -void RectLayer::paintStyle(QPainter *painter) { - switch(style) { - case NORMAL: - break; - case RED: { - QPen pen; - pen.setColor(QColor(161, 47, 47)); - pen.setWidth(3); - pen.setJoinStyle(Qt::RoundJoin); - painter->setPen(pen); - break; - } - case CUSTOM: { - QPen pen; - pen.setColor(data.color); - pen.setWidth(data.width); - pen.setJoinStyle(data.join_style); - pen.setCapStyle(data.cap_style); - painter->setPen(pen); - break; - } - } -} - -void RectLayer::hideNormal() { - enable_move = false; - enable_size_change = false; - force_show = false; - enable_scroll = false; - hideButtons(); - update(); -} - -void RectLayer::showNormal() { - enable_move = true; - enable_size_change = true; - enable_scroll = true; -} - -void RectLayer::setLimit(QRectF limit) { - for(ExpandButton* button: buttons) { - button->setLimit(limit); - } -} - -void RectLayer::setEnableScroll(bool enable) { - enable_scroll = enable; -} - -bool RectLayer::contains(const QPointF &point) const { - if(QGraphicsObject::contains(point)) return true; - for(QGraphicsItem* item: childItems()) { - if(item->isVisible() && item->contains(item->mapFromParent(point)))return true; - } - return false; -} - -bool RectLayer::acceptFocus() { - return true; -} - -int RectLayer::type() const { - return 65542; -} - -void RectLayer::setRect(QRectF rect) { - this->rect = rect; - update(); -} diff --git a/Paint/Widgets/Layers/rect_layer.h b/Paint/Widgets/Layers/rect_layer.h deleted file mode 100644 index 313e7b5..0000000 --- a/Paint/Widgets/Layers/rect_layer.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef RECT_LAYER_H -#define RECT_LAYER_H -#include -#include "LayerItems/expandbutton.h" -#include "LayerItems/scrollitem.h" -#include -#include "baselayer.h" - -class RectLayer : public QGraphicsObject, public BaseLayer { - Q_OBJECT -public: - enum RECT_STYLE {NORMAL, RED, CUSTOM}; - RectLayer(QGraphicsItem* parent, QRectF rect); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; - QPainterPath shape() const override; - void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; - void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; - void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; - void mousePressEvent(QGraphicsSceneMouseEvent *event) override; - QRectF boundingRect() const override; - void showButtons(); - void hideButtons(); - void setBounding(QRectF rect); - void setLimit(QRectF limit); - void setEnableMove(bool enable); - void setEnableSizeChange(bool enable); - void setEnableScroll(bool enable); - void getFocusFunc() override; - void loseFocusFunc() override; - void setStyle(RECT_STYLE style, PaintData data=PaintData(QColor(161, 47, 47), 3)); - bool contains(const QPointF& point)const override; - int type() const override; - void setRect(QRectF rect); - Q_INVOKABLE void hideNormal() override; - Q_INVOKABLE void showNormal() override; - Q_INVOKABLE bool acceptFocus() override; -signals: - void sizeChange(); - void move(qreal dx, qreal dy); - void requestFocus(BaseLayer* object, QGraphicsObject* object2); - -private slots: - void posChangeFunc(direction dir, qreal x, qreal y); - void posToFunc(direction dir, qreal x, qreal y); -private: - void paintStyle(QPainter* painter); - QCursor out_cursor; - QRectF rect; - QMap buttons; - ScrollItem* scroll_item; - QPointF begin_point; - RECT_STYLE style; - PaintData data; - bool enable_move; - bool enable_size_change; - bool enable_scroll; - bool force_show; -}; - -#endif // RECT_LAYER_H diff --git a/Paint/Widgets/Layers/shapelayer.cpp b/Paint/Widgets/Layers/shapelayer.cpp deleted file mode 100644 index b7d8d0f..0000000 --- a/Paint/Widgets/Layers/shapelayer.cpp +++ /dev/null @@ -1,310 +0,0 @@ -#include "shapelayer.h" -#include -#include "rect_layer.h" -#include "text_layer.h" -#include -#include "Helper/Reflect.h" -#include "Paint/Widgets/recorder.h" -#include "arrowlayer.h" -#include "string.h" -#include "Paint/Widgets/style_manager.h" -#include "Paint/Widgets/Recorder_element/shaperecord.h" -#include "Helper/math.h" - -ShapeLayer::ShapeLayer(QGraphicsItem* parent) : QGraphicsObject(parent) { - is_press = false; - is_enable = false; - is_focus = false; - isRect = false; - focus_item = NULL; - shape = RECTANGLE; - blur_layer = NULL; -// blur_layer = new BlurLayer(this); -} - -void ShapeLayer::reset() { - is_press = false; - is_enable = false; - is_focus = false; - isRect = false; - focus_item = NULL; - shape = RECTANGLE; - blur_layer = NULL; - QList children = childItems(); - for(QGraphicsItem* item: children) { - delete item; - } - if(blur_layer != NULL) - delete blur_layer; - blur_layer = new BlurLayer(this); -} - -void ShapeLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - if(isRect && is_press) { - QPen pen; - pen.setColor(Style_manager::instance()->get_now().color); - pen.setWidth(Style_manager::instance()->get_now().width); - pen.setJoinStyle(Qt::RoundJoin); - switch(shape) { - case RECTANGLE: - painter->setPen(pen); - painter->drawRect(Math::buildRect(begin_point, currentPoint)); - break; - case PAINT_ARROW: - painter->setPen(pen); - painter->drawLine(begin_point, currentPoint); - } - - } -} - -QRectF ShapeLayer::boundingRect() const { - return QRectF(); -} - -void ShapeLayer::setPic(const QPixmap &pix, QPoint point) { - this->pix = pix; - this->point = point; -} - -void ShapeLayer::mousePressEvent(QGraphicsSceneMouseEvent *event) { - begin_point = mapFromScene(event->scenePos()); - if(is_enable && shape != BLUR && event->button() == Qt::LeftButton) { - if(!childContains(mapFromScene(begin_point))) - is_press = true; - } - if(is_focus && focus_item != NULL) { - QGraphicsItem* item = dynamic_cast(focus_item); - QPointF point = item->mapFromParent(mapFromScene(event->scenePos())); - if(!item->contains(point)) { - focus_item_func->loseFocusFunc(); - focus_item = NULL; - } - } - if(is_enable && shape == DELETE_SHAPE) { - is_press = true; - } - if(is_enable && shape == BLUR) { - is_press = true; - if(!blur_layer->isSetPic()) { - blur_layer->setPix(pix, point); - } - } - if(is_enable && (shape == RECTANGLE || shape == PAINT_ARROW)) { - isRect = true; - } -} - -void ShapeLayer::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - currentPoint = mapFromScene(event->scenePos()); - if(is_enable && is_press && shape == BLUR) { - blur_layer->addPoint(currentPoint.toPoint()); - } - if(is_enable && is_press && shape == DELETE_SHAPE) { - blur_layer->deletePoint(currentPoint.toPoint()); - deleteChildrens(currentPoint); - } - if(isRect) { - update(); - } -} - -void ShapeLayer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if(is_enable && is_press) { - is_press = false; - isRect = false; - QPointF point = mapFromScene(event->scenePos()); - qreal left = 0, top=0, bottom=0, right=0; - if(point.x() < begin_point.x()) { - left = point.x(); - right = begin_point.x(); - } else { - left = begin_point.x(); - right = point.x(); - } - - if(point.y() < begin_point.y()) { - top = point.y(); - bottom = begin_point.y(); - } else { - top = begin_point.y(); - bottom = point.y(); - } - QRectF rect(QPointF(left, top), QPointF(right, bottom)); - switch(shape) { - case RECTANGLE: { - if(rect.width() < 10 || rect.height() < 10) - break; - RectLayer* rect_layer = new RectLayer(this, rect); - rect_layer->setStyle(RectLayer::CUSTOM, Style_manager::instance()->get_now()); - rect_layer->setEnableMove(true); - rect_layer->setEnableSizeChange(true); - connect(rect_layer, &RectLayer::requestFocus, this, &ShapeLayer::onRequestFocus); - setFocus(rect_layer, rect_layer); - Recorder::instance()->record(new ShapeRecord(this, rect_layer, "undoRedoShapeFunc", false)); - break; - } - case TEXT: { - if(childContains(begin_point)) { - break; - } - Text_layer* text_layer = new Text_layer(rect, this); - setFocus(text_layer, text_layer); - connect(text_layer, &Text_layer::requestFocus, this, &ShapeLayer::onRequestFocus); - break; - } - case PAINT_ARROW: { - ArrowLayer* arrow_layer = new ArrowLayer(this, begin_point, point); - setFocus(arrow_layer, arrow_layer); - Recorder::instance()->record(new ShapeRecord(this, arrow_layer, "undoRedoShapeFunc", false)); - break; - } - case DELETE_SHAPE: { - - } - } - } -} - -void ShapeLayer::setShape(SHAPE_TYPE shape) { - this->shape = shape; -} - -void ShapeLayer::setEnable(bool enable) { - this->is_enable = enable; - setLayersState(); -} - -void ShapeLayer::setGrabFocus(bool enable) { - is_focus = enable; - setLayersState(); -} - -void ShapeLayer::onRequestFocus(BaseLayer* object, QGraphicsObject* object2) { - if(is_focus) { - focus_item = object2; - focus_item_func = object; - object->getFocusFunc(); - } -// if(shape == DELETE_SHAPE && is_enable) -// { -// Recorder::instance()->removeRecord(object2); -// delete object2; -// focus_item = NULL; -// focus_item_func = NULL; -// } -} - -void ShapeLayer::deleteShape() { -// if(focus_item != NULL) -// { -// Recorder::instance()->removeRecord(focus_item); -// delete focus_item; -// focus_item = NULL; -// focus_item_func = NULL; -// } - shape = DELETE_SHAPE; -} - -void ShapeLayer::setLayersState() { - QList items = childItems(); - const char* method_name; - if(is_enable || is_focus) { - method_name = "showNormal"; - } else { - method_name = "hideNormal"; - - } - for(QGraphicsItem* item: items) { - QGraphicsObject* object = qgraphicsitem_cast(item); - Reflect::invokeMethod(object->metaObject()->className(), object, method_name); - } - if(focus_item != NULL) { - focus_item_func->loseFocusFunc(); - } - - focus_item = NULL; - focus_item_func = NULL; -} - -bool ShapeLayer::childContains(QPointF point) { - QList items = childItems(); - for(QGraphicsItem* item : items) { - QPointF point1 = item->mapFromParent(point); - QGraphicsObject* object = qgraphicsitem_cast(item); - bool ans; - QGenericReturnArgument arg = Reflect::invokeMethod(object->metaObject()->className(), object, "acceptFocus", Q_RETURN_ARG(bool, ans)); - ans = *(bool*)arg.data(); - if(item->contains(point1) && item->isVisible() && ans) { - return true; - } - } - return false; -} - -void ShapeLayer::deleteChildrens(QPointF point) { - QList items = childItems(); - for(QGraphicsItem* item : items) { - QPointF point1 = item->mapFromParent(point); - if(item->contains(point1) && item->isVisible()) { - if(item == focus_item) { - focus_item = NULL; - focus_item_func = NULL; - } - QGraphicsObject* object = qgraphicsitem_cast(item); - if(!strcmp(object->metaObject()->className(), "BlurLayer")) { - continue; - } - item->hide(); - Recorder::instance()->record(new ShapeRecord(this, object, "undoRedoShapeFunc", true)); -// Recorder::instance()->removeRecord(object); -// delete item; - } - } -} - -void ShapeLayer::prepareSave() { - const char* method_name = "hideNormal"; - for(QGraphicsItem* item: childItems()) { - QGraphicsObject* object = qgraphicsitem_cast(item); - - Reflect::invokeMethod(object->metaObject()->className(), object, method_name); - } -} - -void ShapeLayer::endSave() { - const char* method_name = "showNormal"; - for(QGraphicsItem* item: childItems()) { - QGraphicsObject* object = qgraphicsitem_cast(item); - Reflect::invokeMethod(object->metaObject()->className(), object, method_name); - } -} - -void ShapeLayer::setFocus(QGraphicsObject *object, BaseLayer *func) { - if(focus_item != NULL) { - focus_item_func->loseFocusFunc(); - } - - focus_item = object; - focus_item_func = func; - func->getFocusFunc(); -} - -void ShapeLayer::changeBlur(bool is_range, int value) { - if(is_range) - blur_layer->setRange(value); - else - blur_layer->setUnitSize(value); -} - -void ShapeLayer::undoRedoShapeFunc(bool show, QGraphicsObject *object) { - if(show) { - object->show(); - } else { - object->hide(); - } -} - -int ShapeLayer::type() const { - return 65543; -} diff --git a/Paint/Widgets/Layers/shapelayer.h b/Paint/Widgets/Layers/shapelayer.h deleted file mode 100644 index 83edf6a..0000000 --- a/Paint/Widgets/Layers/shapelayer.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef SHAPELAYER_H -#define SHAPELAYER_H -#include -#include -#include "Paint/Data/Common.h" -#include -#include "baselayer.h" -#include "blurlayer.h" -#include "rect_layer.h" - -/** - * @brief 绘制矩形,箭头,马赛克等形状的管理类 - */ -class ShapeLayer : public QGraphicsObject { - Q_OBJECT -public: - ShapeLayer(QGraphicsItem* parent=nullptr); - void reset(); - QRectF boundingRect() const override; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; - void mousePressEvent(QGraphicsSceneMouseEvent *event) override; - void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override; - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; - void setEnable(bool enable); - void setShape(SHAPE_TYPE shape); - void setGrabFocus(bool enable); - void deleteShape(); - void prepareSave(); - void endSave(); - void setPic(const QPixmap& pix, QPoint point); - void changeBlur(bool is_range, int value); - Q_INVOKABLE void undoRedoShapeFunc(bool show, QGraphicsObject* object); - int type() const override; -public slots: - void onRequestFocus(BaseLayer* object, QGraphicsObject* object2); - -private: - void setLayersState(); - bool childContains(QPointF point); - void deleteChildrens(QPointF point); - void setFocus(QGraphicsObject* object, BaseLayer* func); - bool is_enable; - bool is_press; - bool is_focus; - SHAPE_TYPE shape; - QPointF begin_point; - QGraphicsObject* focus_item; - BlurLayer* blur_layer; - BaseLayer* focus_item_func; - QPixmap pix; - QPoint point; - QPointF currentPoint; - bool isRect; -}; - -#endif // SHAPELAYER_H diff --git a/Paint/Widgets/Layers/text_layer.cpp b/Paint/Widgets/Layers/text_layer.cpp deleted file mode 100644 index 975b7cf..0000000 --- a/Paint/Widgets/Layers/text_layer.cpp +++ /dev/null @@ -1,189 +0,0 @@ -#include "text_layer.h" -#include "Paint/Widgets/Panels/flow_edit_panel.h" -#include -#include -#include "Manager/uimanager.h" -#include - -Text_layer::Text_layer(QRectF rect, QGraphicsItem* parent) : QGraphicsTextItem(parent) { - setTextInteractionFlags(Qt::TextEditorInteraction); - force_focus = false; - is_brush = false; - setPos(rect.topLeft()); - setFont(UIManager::instance()->getFontData().font); - rect_layer = new RectLayer(this, QRectF(QPointF(0, 0), boundingRect().size())); - rect_layer->setEnableMove(true); - is_enable = true; - connect(rect_layer, &RectLayer::move, this, [=](qreal dx, qreal dy) { - moveBy(dx, dy); - rect_layer->setPos(0, 0); - }); - connect(document(), &QTextDocument::contentsChanged, this, [=]() { - rect_layer->setBounding(boundingRect()); - }); - requestFocus(this, this); - setFocus(); - initFlowEditPanel(); - now_position = 0; - is_commit_string = false; - FontData data = UIManager::instance()->getFontData(); - current_charformat.setFont(data.font); - current_charformat.setForeground(data.color); -} - -void Text_layer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - QGraphicsTextItem::paint(painter, option, widget); -} - -void Text_layer::getFocusFunc() { - Flow_edit_panel::instance()->show(); - force_focus = true; -} - -void Text_layer::loseFocusFunc() { - force_focus = false; - boundHide(); - Flow_edit_panel::instance()->hide(); - if(toPlainText() == "") { - delete this; - } -} - -void Text_layer::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - setFocus(); - if(is_enable) { - boundShow(); - } -} - -void Text_layer::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - if(!force_focus) - clearFocus(); - boundHide(); -} - -void Text_layer::mousePressEvent(QGraphicsSceneMouseEvent *event) { - requestFocus(this, this); - QGraphicsTextItem::mousePressEvent(event); - if(now_position != textCursor().position()) { - onCursorPositionChange(textCursor().position()); - } -} - -void Text_layer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if(textCursor().selectedText().size() != 0 && is_brush) { - QTextCursor text_cursor(document()); - text_cursor.setPosition(textCursor().selectionStart()); - text_cursor.setPosition(textCursor().selectionEnd(), QTextCursor::KeepAnchor); - text_cursor.setCharFormat(brush_format); - onCursorPositionChange(textCursor().position()); - } -} - -void Text_layer::focusInEvent(QFocusEvent *event) { - QGraphicsTextItem::focusInEvent(event); -} - -void Text_layer::focusOutEvent(QFocusEvent* event) { - QGraphicsTextItem::focusOutEvent(event); -} - -void Text_layer::keyPressEvent(QKeyEvent *event) { - requestFocus(this, this); - QGraphicsTextItem::keyPressEvent(event); - if(event->key() == Qt::Key_Right || event->key() == Qt::Key_Left) { - onCursorPositionChange(textCursor().position()); - } -} - -void Text_layer::inputMethodEvent(QInputMethodEvent *event) { - commit_position = textCursor().position(); - is_commit_string = true; - commit_length = event->commitString().length(); - QGraphicsTextItem::inputMethodEvent(event); -} - -void Text_layer::boundShow() { - rect_layer->show(); -} - -void Text_layer::boundHide() { - if(force_focus) { - return; - } - rect_layer->hide(); - update(); -} - -void Text_layer::initFlowEditPanel() { - connect(Flow_edit_panel::instance(), &Flow_edit_panel::font_change, this,[=]() { - if(force_focus) { - setFocus(Qt::OtherFocusReason); - QTextCharFormat format; - format.setForeground(Flow_edit_panel::instance()->get_color()); - format.setFont(Flow_edit_panel::instance()->get_font()); - current_charformat = format; - } - }); - connect(document(), &QTextDocument::cursorPositionChanged, this, [=](const QTextCursor& cursor) { - onCursorPositionChange(cursor.position()); - }); - connect(document(), static_cast(&QTextDocument::contentsChange), - this, [=](int position, int charsRemoved, int charsAdded) { - if(is_brush) { - is_brush = false; - return; - } - QTextCursor text_cursor(document()); - if(!is_commit_string) { - text_cursor.setPosition(position); - text_cursor.setPosition(position+charsAdded, QTextCursor::KeepAnchor); - } else { - if(charsAdded - charsRemoved == commit_length && position == 0) { - text_cursor.setPosition(commit_position); - text_cursor.setPosition(commit_position+commit_length, QTextCursor::KeepAnchor); - } else { - text_cursor.setPosition(position); - text_cursor.setPosition(position+commit_length, QTextCursor::KeepAnchor); - } - } - is_commit_string = false; - text_cursor.setCharFormat(current_charformat); - }); - connect(Flow_edit_panel::instance(), &Flow_edit_panel::text_brush, this, [=]() { - is_brush = true; - brush_format = current_charformat; - }); -} - -void Text_layer::hideNormal() { - QTextCursor text_cursor = textCursor(); - text_cursor.clearSelection(); - setTextCursor(text_cursor); - rect_layer->hide(); - force_focus = false; - is_enable = false; - setTextInteractionFlags(Qt::NoTextInteraction); - update(); -} - -void Text_layer::showNormal() { - is_enable = true; - setTextInteractionFlags(Qt::TextEditorInteraction); - update(); -} - -void Text_layer::onCursorPositionChange(int current) { - now_position = current; - Flow_edit_panel::instance()->set_format(textCursor().charFormat().font(), - textCursor().charFormat().foreground().color()); - current_charformat = textCursor().charFormat(); -} - -bool Text_layer::acceptFocus() { - return true; -} - -int Text_layer::type() const { - return 65544; -} diff --git a/Paint/Widgets/Layers/text_layer.h b/Paint/Widgets/Layers/text_layer.h deleted file mode 100644 index 2af6723..0000000 --- a/Paint/Widgets/Layers/text_layer.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef TEXT_LAYER_H -#define TEXT_LAYER_H -#include -#include -#include -#include -#include "Paint/Data/Ilayer.h" -#include "Helper/plist.h" -#include "Paint/Data/stretch_button.h" -#include "Paint/Data/Common.h" -#include -#include "baselayer.h" -#include "rect_layer.h" - -class Text_layer : public QGraphicsTextItem, public BaseLayer { - Q_OBJECT -public: - Text_layer(QRectF rect, QGraphicsItem* parent=nullptr); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; - void getFocusFunc() override; - void loseFocusFunc() override; - void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; - void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; - void mousePressEvent(QGraphicsSceneMouseEvent *event) override; - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; - void focusInEvent(QFocusEvent *event) override; - void focusOutEvent(QFocusEvent *event) override; - void keyPressEvent(QKeyEvent *event) override; - void inputMethodEvent(QInputMethodEvent* event) override; - int type() const override; - Q_INVOKABLE void hideNormal() override; - Q_INVOKABLE void showNormal() override; - Q_INVOKABLE bool acceptFocus() override; -signals: - void requestFocus(BaseLayer* object, QGraphicsObject* object2); -private: - void boundShow(); - void boundHide(); - void initFlowEditPanel(); - void onCursorPositionChange(int current); - QRectF rect; - RectLayer* rect_layer; - bool force_focus; - bool is_enable; - bool is_commit_string; - bool is_brush; - int commit_length; - int commit_position; - int now_position; - QTextCharFormat brush_format; - QTextCharFormat current_charformat; -}; - -#endif // TEXT_LAYER_H diff --git a/Paint/Widgets/PaintArea.cpp b/Paint/Widgets/PaintArea.cpp deleted file mode 100644 index d34babf..0000000 --- a/Paint/Widgets/PaintArea.cpp +++ /dev/null @@ -1,449 +0,0 @@ -#include "PaintArea.h" -#include "recorder.h" -#include "style_manager.h" -#include -#include -#include "history.h" -#include -#include "Helper/debug.h" -#include -#include -#include "opencv2/core.hpp" -#include "opencv2/opencv.hpp" -#include "Helper/imagehelper.h" -#define WIN32_LEAN_AND_MEAN -#include -#include -#include "Helper/imagehelper.h" -#include -#include "Paint/Widgets/Layers/text_layer.h" -#include //转码 -#include -#include "Paint/Widgets/Layers/rect_layer.h" -#include "Manager/config.h" -#include "Manager/WindowManager.h" -#include -#include -#include "Panels/paint_setting_panel.h" -#include -#include -#include -#include -#include "new_capture/Widgets/Scroll_handler/Scroll_handler_global.h" -#include - -PaintArea::PaintArea(QWidget* parent, bool enable_clip) : QGraphicsScene(parent) { - is_save = false; - is_clip = enable_clip; - state = PAINT; - shape_type = RECTANGLE; - tip = NULL; - initProcess(); - if(!is_clip) { - pic_layer = new Picture_layer(); - addItem(pic_layer); - initSettingPanel(); - clip_layer = NULL; - } else { - pic_layer = NULL; - clip_layer = new ClipLayer(parent, this); - connect(clip_layer, &ClipLayer::requestImage, this, [=]() { - prepareSave(); - QRectF bound = clip_layer->getClipRect(); - bound = bound.united(paint_layer->childrenBoundingRect()); - bound = bound.united(shape_layer->childrenBoundingRect()); - - if(bound == QRectF(0, 0, 0, 0)) - return; - - QImage image(bound.width(), bound.height(), QImage::Format_ARGB32); - image.fill(Qt::transparent); - QPainter painter(&image); - render(&painter, QRectF(QPointF(0, 0), bound.size()), bound); - bound.moveTo(0, 0); - WindowManager::changeWindow("PaintWindow", QPixmap::fromImage(image), bound.toRect()); - endSave(); - }); - connect(clip_layer, &ClipLayer::needClip, this, [=]() { - save2Clipboard(); - WindowManager::changeWindow("tray"); - }); - connect(clip_layer, &ClipLayer::needPin, this, [=](){ - prepareSave(); - QRectF bound = clip_layer->getClipRect(); - bound = bound.united(paint_layer->childrenBoundingRect()); - bound = bound.united(shape_layer->childrenBoundingRect()); - - if(bound == QRectF(0, 0, 0, 0)) - return; - - QImage image(bound.width(), bound.height(), QImage::Format_ARGB32); - image.fill(Qt::transparent); - QPainter painter(&image); - render(&painter, QRectF(QPointF(0, 0), bound.size()), bound); - WindowManager::changeWindow("PinWindow", QPixmap::fromImage(image), bound.toRect()); - endSave(); - }); - connect(clip_layer, &ClipLayer::needSave, this, [=]() { - QString file_name = QFileDialog::getSaveFileName(parent, - "保存", - History::instance()->get_last_directory(), - "图片(*.bmp *.jpg *.jpeg *.png);;所有文件(*)"); - if(file_name != "") { - if(save(History_data::Persist, file_name)) - WindowManager::changeWindow("tray"); - } - }); - connect(clip_layer, &ClipLayer::requestOcr, this, [=]() { - if(save(History_data::Editable, "ocr/1.png")) { - WindowManager::changeWindow("tray"); - startOcr(); - } - }); - connect(clip_layer, &ClipLayer::paintShape, this, [=](SHAPE_TYPE type) { - if(type == DELETE_SHAPE) - deleteShape(); - else - paintShape(type); - }); - connect(clip_layer, &ClipLayer::stateChange, this, [=](PAINT_STATE state) { - stateChange(state); - }); - connect(clip_layer, &ClipLayer::mosaicChange, this, [=](bool is_range, int value) { - shape_layer->changeBlur(is_range, value); - }); - connect(clip_layer, &ClipLayer::needReset, this, [=]() { - reset(); - }); - addItem(clip_layer); - } - paint_layer = new PaintLayer(); - paint_layer->setZValue(1); - addItem(paint_layer); - shape_layer = new ShapeLayer(); - shape_layer->setZValue(2); - if(is_clip) - shape_layer->reset(); - addItem(shape_layer); -} - -void PaintArea::reset() { - if(pic_layer != NULL) { - pic_layer->reset(); - } - if(paint_layer != NULL) { - paint_layer->reset(); - } - if(shape_layer != NULL) { - shape_layer->reset(); - } - if(clip_layer != NULL) { - clip_layer->reset(); - } - is_save = false; -} - -void PaintArea::initProcess() { - QStringList args; - QDir dir("ocr/models"); - QDir dir2("ocr"); - args << "--models" << "models/" - << "--det" << "ch_PP-OCRv3_det_infer.onnx" - << "--cls" << "ch_ppocr_mobile_v2.0_cls_infer.onnx" - << "--rec" << "ch_PP-OCRv3_rec_infer.onnx" - << "--keys" << "ppocr_keys_v1.txt" - << "--image" << "1.png" - << "--numThread" << QString::number(Scroll_handler_global::instance()->num_core) - << "--padding" << "50" - << "--maxSideLen" << "1024" - << "--boxScoreThresh" << "0.5" - << "--boxThresh" << "0.3" - << "--unClipRatio" << "1.6" - << "--doAngle" << "1" - << "--mostAngle" << "1"; - ocrProcess.setProgram(dir2.absolutePath() + "/RapidOcrOnnx.exe"); - ocrProcess.setArguments(args); - ocrProcess.setWorkingDirectory(dir2.absolutePath()); - connect(&ocrProcess, static_cast(&QProcess::finished), this, [=](int exitCode, QProcess::ExitStatus exitStatus) { - if(exitStatus == QProcess::NormalExit) { - showOcrResultProcess.startDetached(); - } - }); - showOcrResultProcess.setProgram("OcrViewer.exe"); - showOcrResultProcess.setWorkingDirectory(QDir::currentPath()); -} - -void PaintArea::setPic(QPixmap pic, QRect rect) { - setSceneRect(0, 0, rect.width()*2, rect.height()*2); - pic_layer->setPos(rect.width() / 2, rect.height() / 2); - pic_layer->setPixmap(pic); - paint_layer->setPix(pic, QPoint(pic.width() / 2, pic.height() / 2)); - shape_layer->setPic(pic, QPoint(pic.width() / 2, pic.height() / 2)); - for(QColor color : History::instance()->get_color()) { - pic_layer->setSaveDisableColor(-1, color); - } -} - -void PaintArea::setClipPic(QPixmap pix) { - setSceneRect(0, 0, pix.width(), pix.height()); - clip_layer->setPic(pix); - shape_layer->setPic(pix, QPoint(0, 0)); - paint_layer->setPix(pix, QPoint(0, 0)); -} - -void PaintArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - sendEvent(paint_layer, event); - sendEvent(shape_layer, event); - if(is_clip) - sendEvent(clip_layer, event); - QGraphicsScene::mouseMoveEvent(event); -} - -void PaintArea::mousePressEvent(QGraphicsSceneMouseEvent *event) { - sendEvent(paint_layer, event); - sendEvent(shape_layer, event); - if(is_clip) - sendEvent(clip_layer, event); - if(event->button() == Qt::BackButton) { - Recorder::instance()->back(); - } else if(event->button() == Qt::ForwardButton) { - Recorder::instance()->forward(); - } - QGraphicsScene::mousePressEvent(event); -} - -void PaintArea::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - sendEvent(paint_layer, event); - sendEvent(shape_layer, event); - if(is_clip) - sendEvent(clip_layer, event); - QGraphicsScene::mouseReleaseEvent(event); -} - -void PaintArea::deleteShape() { - shape_layer->deleteShape(); -} - -void PaintArea::paintShape(SHAPE_TYPE type) { - shape_type = type; - shape_layer->setShape(type); - stateChange(SHAPE); -} - -void PaintArea::setOtherLayer() { - if(paint_layer == NULL && pic_layer != NULL) { - paint_layer = new PaintLayer(pic_layer); - } else if(paint_layer != NULL && pic_layer != NULL) { - paint_layer->setParentItem(pic_layer); - } - if(shape_layer == NULL && pic_layer != NULL) { - shape_layer = new ShapeLayer(pic_layer); - } else if(shape_layer != NULL && pic_layer != NULL) { - shape_layer->setParentItem(pic_layer); - } -} - -void PaintArea::stateChange(PAINT_STATE state) { - if(state == this->state) { - return; - } - // 放弃当前状态函数 - switch(this->state) { - case ERASE: - shape_layer->setEnable(false); - paint_layer->setErase(false); - break; - case PAINT: - paint_layer->setEnableDraw(false); - break; - case ARROW: - if(!is_clip) - pic_layer->setEnableMove(false); - else { - clip_layer->setEnable(false); - } - shape_layer->setGrabFocus(false); - break; - case SHAPE: - shape_layer->setGrabFocus(false); - shape_layer->setEnable(false); - break; - case MASK: - break; - } - this->state = state; - - switch(state) { - case PAINT: - paint_layer->setEnableDraw(true); - break; - case ERASE: - shape_layer->setEnable(true); - shape_layer->setShape(DELETE_SHAPE); - paint_layer->setErase(true); - break; - case ARROW: - if(!is_clip) - pic_layer->setEnableMove(true); - else - clip_layer->setEnable(true); - shape_layer->setGrabFocus(true); - break; - case SHAPE: - shape_layer->setEnable(true); - shape_layer->setGrabFocus(true); - break; - } -} - -void PaintArea::initSettingPanel() { - connect(Paint_setting_panel::instance(), &Paint_setting_panel::disable_color_change, this, - [=](int index, QColor color=QColor()) { - if(pic_layer != NULL) { - pic_layer->setDisableColor(index, color); - } - }); - connect(Paint_setting_panel::instance(), &Paint_setting_panel::saveDisableColorChange, this, - [=](int index, QColor color=QColor()) { - if(pic_layer != NULL) { - pic_layer->setSaveDisableColor(index, color); - } - }); - connect(Paint_setting_panel::instance(), &Paint_setting_panel::layer_rename, this, [=](int index, QString after_name) { - - }); - connect(Paint_setting_panel::instance(), &Paint_setting_panel::remove_layer, this, [=](int index) { - - }); - connect(Paint_setting_panel::instance(), &Paint_setting_panel::change_layer_position, - this, [=](int before_index, int after_index) { - - }); - connect(Paint_setting_panel::instance(), &Paint_setting_panel::requestLayersName, this, [=]() { - }); -} - -bool PaintArea::save(History_data::save_type type, QString path) { - if(path == "") { - return false; - } - prepareSave(); - is_save = true; - QRectF bound; - if(pic_layer != NULL) { - bound = pic_layer->boundingRect(); - bound.moveTo(pic_layer->pos() + bound.topLeft()); - } else { - bound = clip_layer->getClipRect(); - } - bound = bound.united(paint_layer->childrenBoundingRect()); - bound = bound.united(shape_layer->childrenBoundingRect()); - - if(bound == QRectF(0, 0, 0, 0)) - return false; - - cv::Mat ans(bound.height(), bound.width(), CV_8UC4); - for(int i=0; i 32700 ? 32700 : bound.height() - i; - QRect temp_rect(bound.left(), bound.top()+i, bound.width(), height); - QImage image(bound.width(), height, QImage::Format_ARGB32); -// image.fill(Qt::transparent); - QPainter painter(&image); - render(&painter, QRectF(QPointF(0, 0), image.size()), temp_rect); - cv::Mat temp_mat = ImageHelper::QImage2Mat(image); - temp_mat.copyTo(ans(cv::Rect(0, i, bound.width(), height))); - } - cv::imwrite(path.toLocal8Bit().toStdString(), ans); - History::instance()->log(type, path); - endSave(); - return true; -} - -bool PaintArea::save2Clipboard() { - prepareSave(); - QRectF bound; - if(pic_layer != NULL) { - bound = pic_layer->boundingRect(); - bound.moveTo(pic_layer->pos() + bound.topLeft()); - } else { - bound = clip_layer->getClipRect(); - } - bound = bound.united(paint_layer->childrenBoundingRect()); - bound = bound.united(shape_layer->childrenBoundingRect()); - - if(bound == QRectF(0, 0, 0, 0)) - return false; - - QImage image(bound.width(), bound.height(), QImage::Format_ARGB32); - image.fill(Qt::transparent); - QPainter painter(&image); - render(&painter, QRectF(QPointF(0, 0), bound.size()), bound); - QClipboard *clip=QApplication::clipboard(); - clip->setImage(image); - endSave(); - return true; -} - -bool PaintArea::needSave() { - return pic_layer != NULL && pic_layer->containsPicture() && !is_save; -} - -void PaintArea::prepareSave() { - if(pic_layer != NULL) - pic_layer->prepareSave(); - else - clip_layer->prepareSave(); - if(tip != NULL) - tip->hide(); - shape_layer->prepareSave(); - update(); -} - -void PaintArea::endSave() { - if(pic_layer != NULL) - pic_layer->endSave(); - else - clip_layer->endSave(); - if(tip != NULL) - tip->show(); - shape_layer->endSave(); - update(); -} - -void PaintArea::sendRequestImage() { - if(clip_layer != NULL) - clip_layer->sendRequestImage(); -} - -void PaintArea::onViewSet(QWidget* view) { - if(clip_layer != NULL) - clip_layer->setWidgetParent(view); -} - -void PaintArea::clipButtonEnter(int id) { - if(clip_layer != NULL) - clip_layer->buttonEnter(id); -} - -void PaintArea::startOcr() { - ocrProcess.start(); -} - -RecordInfo PaintArea::getRecordInfo() { - if(clip_layer != NULL) - return clip_layer->getRecordInfo(); - return RecordInfo(); -} - -QGraphicsProxyWidget* PaintArea::addTip(QWidget* tip){ - this->tip = tip; - return addWidget(tip); -} - -//void PaintArea::wheelEvent(QGraphicsSceneWheelEvent *event){ -// if(pic_layer != NULL){ -// pic_layer->setCurrentPos(event->scenePos()); -// pic_layer->update(); -// } -// QGraphicsScene::wheelEvent(event); -//} diff --git a/Paint/Widgets/PaintArea.h b/Paint/Widgets/PaintArea.h deleted file mode 100644 index 3d54816..0000000 --- a/Paint/Widgets/PaintArea.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef PAINT_AREA_H -#define PAINT_AREA_H -#include -#include "Paint/Widgets/Layers/picture_layer.h" -#include -#include -#include "Paint/Widgets/Layers/paintlayer.h" -#include "Paint/Data/Ilayer.h" -#include "Paint/Data/Common.h" -#include -#include -#include -#include "Paint/Widgets/Layers/shapelayer.h" -#include "Paint/Data/History_data.h" -#include "new_capture/Widgets/cliplayer.h" -#include - -/** - * @brief 绘图管理类,用来控制图片的显示,保存,状态管理等 - */ -class PaintArea : public QGraphicsScene { - Q_OBJECT -public: - PaintArea(QWidget* parent=nullptr, bool enable_clip=false); - void setPic(QPixmap pic, QRect rect); - void setClipPic(QPixmap pix); - void deleteShape(); - void paintShape(SHAPE_TYPE type); - void reset(); - void stateChange(PAINT_STATE state); - void mousePressEvent(QGraphicsSceneMouseEvent *event) override; - void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; - bool save(History_data::save_type type, QString path); - bool save2Clipboard(); - bool needSave(); - void prepareSave(); - void endSave(); - void sendRequestImage(); - void onViewSet(QWidget* view); - void clipButtonEnter(int id); - void startOcr(); - QGraphicsProxyWidget* addTip(QWidget* tip); -// void wheelEvent(QGraphicsSceneWheelEvent *event) override; - RecordInfo getRecordInfo(); -private: - void setOtherLayer(); - void initSettingPanel(); - void initProcess(); - - const int DEFAULT_LAYER_NUM = 1; - SHAPE_TYPE shape_type; - PAINT_STATE state; - QPointF begin_point; - PaintLayer* paint_layer; - Picture_layer* pic_layer; - ShapeLayer* shape_layer; - ClipLayer* clip_layer; - QWidget* tip; - bool is_save; - bool is_clip; - QProcess ocrProcess; - QProcess showOcrResultProcess; -}; - -#endif // PAINT_AREA_H diff --git a/Paint/Widgets/Panels/close_dialog.cpp b/Paint/Widgets/Panels/close_dialog.cpp deleted file mode 100644 index 8349bd3..0000000 --- a/Paint/Widgets/Panels/close_dialog.cpp +++ /dev/null @@ -1,137 +0,0 @@ -#include "close_dialog.h" -#include -#include -#include -#include -#include -#include "Manager/WindowManager.h" -#include -#include -#include "Paint/Widgets/history.h" -#include -#include "Manager/config.h" - -Close_dialog::Close_dialog() -{ - is_close = true; -} - -Close_dialog::Close_dialog(PaintArea* area, QWidget* parent) : QDialog(parent) -{ - setAttribute(Qt::WA_DeleteOnClose); - QVBoxLayout* layout = new QVBoxLayout(this); - QLabel* warning_icon = new QLabel(this); - warning_icon->setPixmap(QPixmap(":/image/warning.png")); - QGridLayout* grid_layout = new QGridLayout(); - - QButtonGroup* group = new QButtonGroup(this); - QRadioButton* hide_button = new QRadioButton("缩小到系统托盘", this); - hide_button->setCheckable(true); - QRadioButton* close_button = new QRadioButton("直接关闭", this); - close_button->setCheckable(true); - QHBoxLayout* hide_layout = new QHBoxLayout(); - group->addButton(hide_button, 0); - group->addButton(close_button, 1); - group->setExclusive(true); - if(Config::getConfig(Config::hide_to_tray)) - { - hide_button->setChecked(true); - } - else - { - close_button->setChecked(true); - } - connect(group, static_cast(&QButtonGroup::buttonClicked), this, [=](int id){ - if(id == 0) - { - Config::setConfig(Config::hide_to_tray, true); - } - else - { - Config::setConfig(Config::hide_to_tray, false); - } - Config::updateConfig(Config::hide_to_tray); - }); - - hide_layout->addWidget(hide_button); - QHBoxLayout* close_layout = new QHBoxLayout(); - close_layout->addWidget(close_button); - grid_layout->addWidget(warning_icon, 0, 0); - grid_layout->addLayout(hide_layout, 0, 1); - grid_layout->addLayout(close_layout, 1, 1); - layout->addLayout(grid_layout); - QHBoxLayout* button_layout = new QHBoxLayout(); - QDialogButtonBox* buttonBox = new QDialogButtonBox(this);//右下角按钮设置 - QPushButton* ok = new QPushButton(this); - ok->setText("确认"); - ok->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); - QPushButton* close = new QPushButton(this); - close->setText("关闭"); - connect(ok, &QPushButton::clicked, this, [=](){ - if(Config::getConfig(Config::hide_to_tray)) - { -// area->save_temp(); - emit hide_paint(); - is_close = false; - this->close(); - } -// else if(!area->pic_save) -// { -// int ans = QMessageBox::warning( -// this, -// "简截", -// "是否保存该截图\n可以保存为png、jpg、jpeg文件", -// QMessageBox::Cancel | QMessageBox::No| QMessageBox::Ok); -// if(ans == QMessageBox::Ok) -// { -// QString file_name = QFileDialog::getSaveFileName(this, -// "保存", -// History::instance()->get_last_directory(), -// "图片(*.bmp *.jpg *.jpeg *.png);;所有文件(*)"); -// area->save(file_name); -// hide(); -// WindowManager::close(); -// } -// else if(ans == QMessageBox::No) -// { -// hide(); -// WindowManager::close(); -// } -// else -// { -// this->close(); -// } -// } - else - { - WindowManager::close(); - } - }); - connect(close, &QPushButton::clicked, this, [=](){ - this->close(); - }); - buttonBox->addButton(ok, QDialogButtonBox::AcceptRole); - buttonBox->addButton(close, QDialogButtonBox::RejectRole); - QLabel* next_show_label = new QLabel("不再提示此消息", this); - QRadioButton* next_show_button = new QRadioButton(this); - next_show_button->setCheckable(true); - next_show_button->setAutoExclusive(false); - next_show_button->setChecked(!Config::getConfig(Config::show_close_dialog)); - connect(next_show_button, &QRadioButton::toggled, this, [=](bool clicked){ - Config::setConfig(Config::show_close_dialog, !clicked); - Config::updateConfig(Config::show_close_dialog); - }); - button_layout->addWidget(next_show_label); - button_layout->addWidget(next_show_button); - button_layout->addWidget(buttonBox, 0, Qt::AlignRight); - - layout->addLayout(grid_layout); - layout->addLayout(button_layout); - setLayout(layout); -} - -void Close_dialog::closeEvent(QCloseEvent* event) -{ - if(is_close) - WindowManager::close(); -} diff --git a/Paint/Widgets/Panels/close_dialog.h b/Paint/Widgets/Panels/close_dialog.h deleted file mode 100644 index 19f9b40..0000000 --- a/Paint/Widgets/Panels/close_dialog.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef CLOSE_DIALOG_H -#define CLOSE_DIALOG_H -#include -#include "Paint/Widgets/PaintArea.h" - -class Close_dialog : public QDialog -{ - Q_OBJECT -public: - Close_dialog(); - Close_dialog(PaintArea* area, QWidget* parent); - void closeEvent(QCloseEvent *) override; -signals: - void ignore_close(); - void hide_paint(); -private: - PaintArea* area; - bool is_close; -}; - -#endif // CLOSE_DIALOG_H diff --git a/Paint/Widgets/Panels/color_selector.cpp b/Paint/Widgets/Panels/color_selector.cpp deleted file mode 100644 index 6b4647f..0000000 --- a/Paint/Widgets/Panels/color_selector.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include "color_selector.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "Helper/imagehelper.h" - -Color_selector::Color_selector() { - -} - -Color_selector::~Color_selector() { - -} - -Color_selector::Color_selector(QWidget* parent) : QMainWindow(parent) { - setWindowFlag(Qt::FramelessWindowHint); - setAttribute(Qt::WA_TranslucentBackground); - setAttribute(Qt::WA_DeleteOnClose, true); - showFullScreen(); - this->setMouseTracking(true); - setCursor(QCursor(QPixmap(":/image/color_dropper.png"), 0, 32)); - window_w = QApplication::desktop()->width(); - window_h = QApplication::desktop()->height(); - QTimer* timer = new QTimer(this); - connect(timer, &QTimer::timeout, this, [=]() { - region = ImageHelper::grabScreen(pos.x()-5, pos.y()-3, 11, 7).toImage(); - selected_color = cal_dest_color(region.pixel(5, 3)); - decide_region_position(pos); - update(); - }); - timer->start(10); -} - -void Color_selector::paintEvent(QPaintEvent *event) { - if(region.width() < 11) { - return; - } - QPainter painter(this); - painter.fillRect(this->rect(), src); // 设置透明颜色 - QImage image = QImage(110, 70,QImage::Format_RGB32); - for(int i=0; i<11; i++) { - for(int k=0; k<7; k++) { - for(int j=i*10; jpos().x()-5, event->pos().y()-3, 11, 7).toImage(); - selected_color = region.pixel(5, 3); - if(event->button() == Qt::LeftButton) { - emit color_select(selected_color); - } - this->close(); -} - -void Color_selector::mouseMoveEvent(QMouseEvent *event) { - pos = event->pos(); -} - -void Color_selector::decide_region_position(QPoint mouse_pos) { - region_pos.setX(mouse_pos.x()+32); - region_pos.setY(mouse_pos.y()-32-80); - if(mouse_pos.x()+32+110 > window_w) { - region_pos.setX(window_w - 110-32); - } - if(mouse_pos.x()+32 <= 0) { - region_pos.setX(0); - } - if(mouse_pos.y()-32-80 <= 0) { - region_pos.setY(32+70); - } - if(mouse_pos.y()-32-80 >= window_h) { - region_pos.setY(window_h - 80); - } -} - -QColor Color_selector::cal_dest_color(QColor res) { - int ra = res.alpha(); - int rr = res.red(); - int rg = res.green(); - int rb = res.blue(); - - int sa = src.alpha(); - int pre_alpha = 255 - sa; - int desta = (ra-sa) * 255 / pre_alpha; - int destr = rr * 255 / pre_alpha; - int destg = rg * 255 / pre_alpha; - int destb = rb * 255 / pre_alpha; - return QColor(destr, destg, destb, desta); -} diff --git a/Paint/Widgets/Panels/color_selector.h b/Paint/Widgets/Panels/color_selector.h deleted file mode 100644 index d9ce551..0000000 --- a/Paint/Widgets/Panels/color_selector.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef COLOR_SELECTOR_H -#define COLOR_SELECTOR_H -#include -#include -#include -#include -#include - -class Color_selector : public QMainWindow -{ - Q_OBJECT -public: - Color_selector(); - ~Color_selector(); - Color_selector(QWidget* parent); - void paintEvent(QPaintEvent* event) override; - void mousePressEvent(QMouseEvent* event)override; - void mouseMoveEvent(QMouseEvent* event)override; -signals: - void color_select(QColor color); - -private: - bool mouse_press; - QColor selected_color; - QImage region; - QPoint region_pos; - int window_w; - int window_h; - QPoint pos; - void decide_region_position(QPoint mouse_pos); - const QColor src = QColor(0, 0, 0, 1); - QColor cal_dest_color(QColor res); -}; - -#endif // COLOR_SELECTOR_H diff --git a/Paint/Widgets/Panels/flow_edit_panel.cpp b/Paint/Widgets/Panels/flow_edit_panel.cpp deleted file mode 100644 index a5a2a78..0000000 --- a/Paint/Widgets/Panels/flow_edit_panel.cpp +++ /dev/null @@ -1,211 +0,0 @@ -#include "flow_edit_panel.h" -#include -#include -#include "Helper/mstring.h" -#include -#include -#include -#include -#include -#include "Manager/uimanager.h" -#include "Helper/imagehelper.h" - -Flow_edit_panel* Flow_edit_panel::_instance = NULL; - -Flow_edit_panel::Flow_edit_panel() { - fontData = UIManager::instance()->getFontData(); - setObjectName("font_edit_panel"); - setWindowFlags(windowFlags() | Qt::FramelessWindowHint); - setWindowFlag(Qt::WindowSystemMenuHint, false); - QToolButton* brush_button = new QToolButton(this); - brush_button->setIcon(ImageHelper::getIcon("brush")); - brush_button->setToolTip("格式刷"); - connect(brush_button, &QToolButton::clicked, this, [=]() { - emit text_brush(); - }); - addWidget(brush_button); - color_selector_button = new QToolButton(this); - connect(color_selector_button, &QToolButton::clicked, this, [=]() { - QColorDialog dialog; - QColor color = dialog.getColor(color, this, MString::search("{6Of41PN3eL}选择字体颜色"), - QColorDialog::ShowAlphaChannel); - if(this->fontData.color != color) { - int r = 0, g = 0, b = 0; - color.getRgb(&r,&g,&b); - this->fontData.color.setRgb(r, g, b); - color_selector_button->setStyleSheet(QString("background-color: rgb(%1,%2,%3)").arg(r).arg(g).arg(b)); - emit font_change(); - } - }); - int r = 0, g = 0, b = 0; - fontData.color.getRgb(&r,&g,&b); - color_selector_button->setStyleSheet(QString("background-color: rgb(%1,%2,%3)").arg(r).arg(g).arg(b)); - addWidget(color_selector_button); - addSeparator(); - - m_ComboBox=new QComboBox(this); - QStandardItemModel *model=new QStandardItemModel(this); //源数据 - QList row; - QStandardItem *blankitem=new QStandardItem(""); - model->appendRow(blankitem); //增加一行空白 - QList list = get_font_text(); - foreach (QString name, list) { - if(!name.isEmpty()) { - row.clear(); - QStandardItem *item=new QStandardItem(name); - model->appendRow(item); //添加一行,2列数据 - } - } - m_ComboBox->setModel(model); //QComboBox设置数据源 - m_ComboBox->setEditable(true); - QCompleter *completer=new QCompleter(m_ComboBox); - completer->setCaseSensitivity(Qt::CaseInsensitive); - completer->setModel(model); - completer->setCompletionColumn(m_ComboBox->modelColumn()); - completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion); - completer->setMaxVisibleItems(10); //下拉最大高度 - m_ComboBox->setCompleter(completer); //设置自动补全 - // m_ComboBox->setStyleSheet("QComboBox{combobox-popup: 0;}"); //linux系统上,防止下拉框过长,消耗时间较多 - m_ComboBox->setMaxVisibleItems(10); //下拉最大高度 - m_ComboBox->setCurrentText("宋体"); - connect(m_ComboBox, static_cast(&QComboBox::currentIndexChanged) - , this, [=](const QString& text) { - fontData.font.setFamily(text); - clearFocus(); - emit font_change(); - }); - addWidget(m_ComboBox); - addSeparator(); - - width_button = new QComboBox(this); - QList width_text = {"4", "8", "15", "20", "22", "26", "30", "40", "50"}; - width_button->addItems(width_text); - width_button->setEditable(true); - width_button->setCurrentText(QString::number(fontData.font.pointSize())); - connect(width_button, static_cast(&QComboBox::currentIndexChanged) - , this, [=](const QString& text) { - bool success = false; - int num = text.toInt(&success); - if(success && num > 0) { - clearFocus(); - fontData.font.setPointSize(num); - emit font_change(); - } - }); - addWidget(width_button); - addSeparator(); - - bold_button = new QToolButton(this); - bold_button->setIcon(ImageHelper::getIcon("bold", 48, 48)); - bold_button->setCheckable(true); - connect(bold_button, &QToolButton::clicked, this, [=]() { - if(fontData.font.bold()) { - fontData.font.setBold(false); - bold_button->setChecked(false); - } else { - fontData.font.setBold(true); - bold_button->setChecked(true); - } - emit font_change(); - }); - addWidget(bold_button); - italic_button = new QToolButton(this); - italic_button->setIcon(ImageHelper::getIcon("italic", 48, 48)); - italic_button->setCheckable(true); - connect(italic_button, &QToolButton::clicked, this, [=]() { - if(fontData.font.italic()) { - fontData.font.setItalic(false); - italic_button->setChecked(false); - } else { - fontData.font.setItalic(true); - italic_button->setChecked(true); - } - emit font_change(); - }); - addWidget(italic_button); - underline_button = new QToolButton(this); - underline_button->setIcon(ImageHelper::getIcon("underline", 48, 48)); - underline_button->setCheckable(true); - connect(underline_button, &QToolButton::clicked, this, [=]() { - if(fontData.font.underline()) { - fontData.font.setUnderline(false); - underline_button->setChecked(false); - } else { - fontData.font.setUnderline(true); - italic_button->setChecked(true); - } - emit font_change(); - }); - color_selector_button->setFixedSize(m_ComboBox->height(), m_ComboBox->height()); - bold_button->setFixedSize(m_ComboBox->height(), m_ComboBox->height()); - italic_button->setFixedSize(m_ComboBox->height(), m_ComboBox->height()); - underline_button->setFixedSize(m_ComboBox->height(), m_ComboBox->height()); - addWidget(underline_button); - emit font_change();//初始化 -} - -Flow_edit_panel::~Flow_edit_panel() { - _instance = NULL; -} - -Flow_edit_panel* Flow_edit_panel::instance() { - if(_instance == NULL) { - _instance = new Flow_edit_panel(); - } - return _instance; -} - -void Flow_edit_panel::reset() { - setParent(NULL); - fontData = UIManager::instance()->getFontData(); - set_format(fontData.font, fontData.color); -} - -void Flow_edit_panel::set_format(QFont font, QColor color) { - fontData.font = font; - fontData.color = color; - int r = 0, g = 0, b = 0; - color.getRgb(&r,&g,&b); - color_selector_button->setStyleSheet(QString("background-color: rgb(%1,%2,%3)").arg(r).arg(g).arg(b)); - m_ComboBox->setCurrentText(this->fontData.font.family()); - width_button->setCurrentText(QString::number(font.pointSize())); - bold_button->setChecked(font.bold()); - italic_button->setChecked(font.italic()); - underline_button->setChecked(font.underline()); -} - -QList Flow_edit_panel::get_font_text() { - QList font_text = QList({"Agency FB", "Algerian", "Arial", "Arial Black", "Arial Narrow", - "Bauhaus 93", "Bell MT", - "Bodoni MT", "Bodoni MT Black", "Bodoni MT Condensed", "Book Antiqua", "Broadway", - "Calibri", "Calibri Light", "Californian FB", "Calisto MT", - "Candara", "Candara Light", "Castellar", "Centaur", "Century", "Century Gothic", - "Chiller", "Colonna MT", "Comic Sans MS", "Consolas", "Constantia", "Cooper Black", - "Corbel", "Corbel Light", "Courier", "Courier New", "Curlz MT", - "Dubai", "Dubai Light", "Dubai Medium", "Ebrima", "Elephant", "Engravers MT", - "Ink Free", - "Microsoft Himalaya", "Microsoft JhengHei", - "Microsoft New Tai Lue", "Microsoft PhagsPa", "Microsoft Sans Serif", - "Microsoft Tai Le", "Microsoft YaHei UI", "MingLiU-ExtB", - "Mistral", "Modern", "Modern No. 20", "Mongolian Baiti", "Monotype Corsiva", - "MS Gothic", "MS Outlook", "MS PGothic", - "MS Sans Serif", "MS Serif", "MS UI Gothic", "MT Extra", "MV Boli", "Myanmar Text", "Niagara Engraved", - "Niagara Solid", "Nirmala UI", "Nirmala UI Semilight", "NumberOnly", - "Onyx", "Open Sans", "Papyrus", "Parchment", - "Perpetua", - "Ravie", "Rockwell", - "Small Fonts", "Snap ITC", "Stencil", "Sylfaen", "Symbol", "System", - "Tahoma", "Terminal", "Times New Roman", "Verdana", - "仿宋", "华文中宋", "华文仿宋", "华文宋体", "华文彩云", "华文新魏", "华文楷体", - "华文琥珀", "华文细黑", "华文行楷", "华文隶书", "宋体", "幼圆", "微软雅黑", "微软雅黑 Light", "思源黑体", - "新宋体", "方正姚体", "方正粗黑宋简体", "方正舒体", "楷体", "等线", "等线 Light", "隶书", "黑体"}); - return font_text; -} - -QFont Flow_edit_panel::get_font() { - return fontData.font; -} - -QColor Flow_edit_panel::get_color() { - return fontData.color; -} diff --git a/Paint/Widgets/Panels/flow_edit_panel.h b/Paint/Widgets/Panels/flow_edit_panel.h deleted file mode 100644 index 9906bf2..0000000 --- a/Paint/Widgets/Panels/flow_edit_panel.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef FLOW_EDIT_PANEL_H -#define FLOW_EDIT_PANEL_H -#include -#include -#include -#include -#include -#include "Paint/Data/fontdata.h" - -/** - * @brief 绘制文字的工具栏 - */ -class Flow_edit_panel : public QToolBar { - Q_OBJECT -public: - static Flow_edit_panel* instance(); - ~Flow_edit_panel(); - QFont get_font(); - QColor get_color(); - void set_format(QFont font, QColor color); - void reset(); -signals: - void font_change(); - void text_brush();//格式刷 -private: - Flow_edit_panel(); - - static Flow_edit_panel* _instance; - QToolButton* color_selector_button; - QComboBox *m_ComboBox; - QToolButton* bold_button; - QToolButton* italic_button; - QToolButton* underline_button; - QComboBox* width_button; - QList get_font_text(); - FontData fontData; -}; - -#endif // FLOW_EDIT_PANEL_H diff --git a/Paint/Widgets/Panels/paint_setting_panel.cpp b/Paint/Widgets/Panels/paint_setting_panel.cpp deleted file mode 100644 index 8a49d9d..0000000 --- a/Paint/Widgets/Panels/paint_setting_panel.cpp +++ /dev/null @@ -1,437 +0,0 @@ -#include "paint_setting_panel.h" -#include -#include -#include -#include -#include "Paint/Widgets/style_manager.h" -#include "Manager/WindowManager.h" -#include "Helper/debug.h" -#include "Base/WindowBase.h" -#include "Style_widget/spacer.h" -#include -#include "Paint/Widgets/Panels/color_selector.h" -#include -#include -#include "Paint/Widgets/history.h" -#include -#include "Helper/imagehelper.h" - -Paint_setting_panel* Paint_setting_panel::_instance = NULL; - -Paint_setting_panel::Paint_setting_panel() -{ - layout = new QVBoxLayout(this); - init(); -} - -Paint_setting_panel::Paint_setting_panel(QWidget* parent) : QDockWidget(parent) -{ - this->parent = parent; - // setAttribute(Qt::WA_DeleteOnClose); - layout = new QVBoxLayout();//scrollarea的layout - layout->setAlignment(Qt::AlignTop); - init_shape_setting(); - init_pen_setting(); - init_disable_color_setting(); - init_layer_setting(); - init(); -} - -Paint_setting_panel* Paint_setting_panel::instance(QWidget *parent) -{ - if(_instance == NULL) - { - _instance = new Paint_setting_panel(parent); - } - return _instance; -} - -Paint_setting_panel::~Paint_setting_panel() -{ - _instance = NULL; -} - -void Paint_setting_panel::init() -{ - setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - setMinimumSize(100, 100); - setFeatures(QDockWidget::AllDockWidgetFeatures); - area = new QScrollArea(this); - base = new QWidget(this); - base->setLayout(layout); - area->setWidget(base); - area->setFrameShape(QFrame::NoFrame); - setWidget(area); - hide(); - /*QWidget* widget = new QWidget(this); - QHBoxLayout* central_layout = new QHBoxLayout(this); - central_layout->addWidget(area); - widget->setLayout(central_layout); - setWidget(widget);*/ -} - -void Paint_setting_panel::init_shape_setting() -{ - Spacer* spacer = new Spacer("形状绘制", false, this); - QGridLayout* shape_layout = new QGridLayout(); - QToolButton* text_button = new QToolButton(this); - // text_button->setCheckable(true); - // text_button->setChecked(true); - text_button->setToolTip("文本框"); - text_button->setIcon(ImageHelper::getIcon("text")); - connect(text_button, &QToolButton::clicked, this, [=](){ - emit paint_shape(TEXT); - }); - // QToolButton* delete_button = new QToolButton(this); - //// delete_button->setCheckable(true); - // delete_button->setToolTip("删除形状"); - // delete_button->setIcon(QIcon(":/image/delete.svg")); - // connect(delete_button, &QToolButton::clicked, this, [=](){ - // emit paint_shape(DELETE_SHAPE); - // }); - QToolButton* rect_button = new QToolButton(this); - // rect_button->setCheckable(true); - rect_button->setToolTip("矩形"); - rect_button->setIcon(ImageHelper::getIcon("rect")); - connect(rect_button, &QToolButton::clicked, this, [=](){ - emit paint_shape(RECTANGLE); - }); - QToolButton* arrow_button = new QToolButton(this); - // arrow_button->setCheckable(true); - arrow_button->setIcon(ImageHelper::getIcon("paint_arrow")); - arrow_button->setToolTip("{D7HSBXWTLj}箭头"); - connect(arrow_button, &QToolButton::clicked, this, [=](){ - emit paint_shape(PAINT_ARROW); - }); - QToolButton* mosaic_button = new QToolButton(this); - // mosaic_button->setCheckable(true); - mosaic_button->setIcon(ImageHelper::getIcon("mosaic")); - mosaic_button->setToolTip("马赛克"); - connect(mosaic_button, &QToolButton::clicked, this, [=](){ - emit paint_shape(BLUR); - }); - // QButtonGroup* group = new QButtonGroup(this); - // group->addButton(text_button, 0); - // group->addButton(delete_button, 1); - // group->addButton(rect_button, 2); - // group->addButton(arrow_button, 3); - // group->addButton(mosaic_button, 4); - // connect(group, static_cast(&QButtonGroup::buttonClicked), this, [=](int id){ - // switch(id) - // { - // case 0:emit paint_shape(TEXT);break; - // case 1:emit paint_shape(DELETE_SHAPE);break; - // case 2:emit paint_shape(RECTANGLE);break; - // case 3:emit paint_shape(PAINT_ARROW);break; - // case 4:emit paint_shape(BLUR);break; - // } - // }); - shape_layout->setOriginCorner(Qt::TopLeftCorner); - shape_layout->addWidget(text_button, 0, 0); - // shape_layout->addWidget(delete_button, 1, 2); - shape_layout->addWidget(rect_button, 0, 1); - shape_layout->addWidget(arrow_button, 0, 2); - shape_layout->addWidget(mosaic_button, 1, 1); - spacer->add_layout(shape_layout); - layout->addWidget(spacer); -} - -void Paint_setting_panel::init_pen_setting() -{ - Spacer* spacer = new Spacer("{l1DkNbzL1T}画笔设置", false, this); - QHBoxLayout* color_chooser = new QHBoxLayout(); - QLabel* color_label = new QLabel(MString::search("{fYXepa9pHx}画笔颜色: "), this); - color_chooser->addWidget(color_label); - color_button = new QPushButton(this); - connect(color_button, &QPushButton::clicked, this, [=](){ - QColorDialog dialog; - QColor begin_color = Style_manager::instance()->get_now().color; - QColor color = dialog.getColor(begin_color, this, MString::search("{6Of41PN3eL}选择字体颜色"), QColorDialog::ShowAlphaChannel); - if(begin_color != color) - { - Style_manager::instance()->change_color(color); - set_style(); - } - }); - color_chooser->addWidget(color_label); - color_chooser->addWidget(color_button); - spacer->add_layout(color_chooser); - //layout->addLayout(color_chooser); - /* - QHBoxLayout* back_chooser = new QHBoxLayout(); - QLabel* back_label = new QLabel(MString::search("{jEFblEjzoU}背景颜色")); - back_button = new QPushButton(this); - connect(back_button, &QPushButton::clicked, this, [=](){ - QColorDialog dialog; - QColor begin_color = Style_manager::instance()->get_now().back_color; - QColor color = dialog.getColor(begin_color, this, MString::search("{6Of41PN3eL}选择字体颜色"), QColorDialog::ShowAlphaChannel); - if(begin_color != color) - { - Style_manager::instance()->change_back_color(color); - set_style(); - } - }); - back_chooser->addWidget(back_label); - back_chooser->addWidget(back_button); - spacer->add_layout(back_chooser); - - QHBoxLayout* alpha_chooser = new QHBoxLayout(this); - QLabel* alpha_label = new QLabel(MString::search("{VfVCbcOMjR}背景透明度"), this); - QSpinBox* alpha_box = new QSpinBox(this); - alpha_box->setRange(0, 255); - alpha_box->setSingleStep(1); - QSlider* alpha_slider = new QSlider(this); - alpha_slider->setSingleStep(1); - alpha_slider->setMinimum(0); - alpha_slider->setMaximum(255); - alpha_slider->setOrientation(Qt::Horizontal); - int alpha = Style_manager::instance()->get_now().back_color.alpha(); - alpha_slider->setValue(alpha); - alpha_box->setValue(alpha); - connect(alpha_box, static_cast(&QSpinBox::valueChanged), this, [=](int value){ - alpha_slider->setValue(value); - QColor alpha_color = Style_manager::instance()->get_now().back_color; - alpha_color.setAlpha(value); - Style_manager::instance()->change_back_color(alpha_color); - set_style(); - }); - connect(alpha_slider, &QSlider::valueChanged, this, [=](int value){ - alpha_box->setValue(value); - }); - alpha_chooser->addWidget(alpha_label); - alpha_chooser->addWidget(alpha_box); - alpha_chooser->addWidget(alpha_slider); - spacer->add_layout(alpha_chooser);*/ - - QLabel* width_label = new QLabel(MString::search("{zW4GVylzEh}画笔宽度: "), this); - width_button = new QComboBox(this); - QList width_text = {"4", "8", "12", "16", "20", "24", "28", "40", "50"}; - width_button->addItems(width_text); - width_button->setEditable(true); - connect(width_button, static_cast(&QComboBox::currentIndexChanged) - , this, [=](const QString& text){ - bool success = false; - int num = text.toInt(&success); - if(success && num > 0) - { - Style_manager::instance()->change_width(num); - } - }); - QHBoxLayout* width_layout = new QHBoxLayout(); - width_layout->addWidget(width_label); - width_layout->addWidget(width_button); - spacer->add_layout(width_layout); - layout->addWidget(spacer); - //layout->addLayout(width_layout); - set_style(); -} - -void Paint_setting_panel::init_disable_color_setting() -{ - Spacer* spacer = new Spacer("{pnbWkrTVVw}透明颜色设置", false, this); - QHBoxLayout* combo_layout = new QHBoxLayout(); - QLabel* combo_label = new QLabel(MString::search("{8RK1prjHf0}透明颜色"), this); - QComboBox* combo = new QComboBox(this); - combo->setEditable(false); - combo->setAutoFillBackground(true); - connect(combo, static_cast(&QComboBox::currentIndexChanged), - this, [=](const QString &text){ - int splitter1 = text.indexOf(','); - int splitter2 = text.indexOf(',', splitter1+1); - int red = text.mid(0, splitter1).toInt(); - int green = text.mid(splitter1+1, splitter2-splitter1-1).toInt(); - int blue = text.mid(splitter2+1).toInt(); - combo->setStyleSheet(QString("background-color: rgb(%1,%2,%3)").arg(red).arg(green).arg(blue)); - }); - QToolButton* add_button = new QToolButton(this); - QToolButton* remove_button = new QToolButton(this); - connect(add_button, &QToolButton::clicked, this, [=](){ - Color_selector* selector = new Color_selector(this); - selector->show(); - selector->update(); - connect(selector, &Color_selector::color_select, this, [=](QColor color){ - combo->addItem(QString::number(color.red())+","+QString::number(color.green()) - +","+QString::number(color.blue())); - QStandardItemModel* model = qobject_cast(combo->model()); - model->item(combo->count()-1)->setBackground(color); - int red, green, blue; - color.getRgb(&red, &green, &blue); - red = red + (red - 127) * 0.5; - red = (red < 0x00) ? 0xff+red : (red > 0xff) ? red-0xff : red; - green = green + (green - 127) * 0.5; - green = (green < 0x00) ? 0xff+green : (green > 0xff) ? green - 0xff : green; - blue = blue + (blue - 127) * 0.5; - blue = (blue < 0x00) ? 0xff+blue : (blue > 0xff) ? blue - 0xff : blue; - model->item(combo->count()-1)->setForeground(QColor(red, green, blue)); - combo->setCurrentIndex(combo->count()-1); - emit disable_color_change(-1, color); - }); - }); - connect(remove_button, &QToolButton::clicked, this, [=](){ - if(combo->count()<=0) - { - return; - } - int index = combo->currentIndex(); - combo->removeItem(index); - emit disable_color_change(index); - }); - add_button->setIcon(QIcon(":/image/add.svg")); - remove_button->setIcon(QIcon(":/image/delete.svg")); - - combo_layout->addWidget(combo_label); - combo_layout->addWidget(combo); - combo_layout->addWidget(add_button); - combo_layout->addWidget(remove_button); - - QHBoxLayout* save_layout = new QHBoxLayout(); - QLabel* save_label = new QLabel(MString::search("保存透明颜色"), this); - QComboBox* save_box = new QComboBox(this); - save_box->setEditable(false); - save_box->setAutoFillBackground(true); - QList colors = History::instance()->get_color(); - for(int i=0; iaddItem(QString::number(colors[i].red())+","+QString::number(colors[i].green()) - +","+QString::number(colors[i].blue())); - QStandardItemModel* model = qobject_cast(save_box->model()); - model->item(save_box->count()-1)->setBackground(colors[i]); - int red, green, blue; - colors[i].getRgb(&red, &green, &blue); - red = red + (red - 127) * 0.5; - red = (red < 0x00) ? 0xff+red : (red > 0xff) ? red-0xff : red; - green = green + (green - 127) * 0.5; - green = (green < 0x00) ? 0xff+green : (green > 0xff) ? green - 0xff : green; - blue = blue + (blue - 127) * 0.5; - blue = (blue < 0x00) ? 0xff+blue : (blue > 0xff) ? blue - 0xff : blue; - model->item(save_box->count()-1)->setForeground(QColor(red, green, blue)); - save_box->setCurrentIndex(save_box->count()-1); - } - connect(save_box, static_cast(&QComboBox::currentIndexChanged), - this, [=](const QString &text){ - int splitter1 = text.indexOf(','); - int splitter2 = text.indexOf(',', splitter1+1); - int red = text.mid(0, splitter1).toInt(); - int green = text.mid(splitter1+1, splitter2-splitter1-1).toInt(); - int blue = text.mid(splitter2+1).toInt(); - save_box->setStyleSheet(QString("background-color: rgb(%1,%2,%3)").arg(red).arg(green).arg(blue)); - }); - QToolButton* save_add_button = new QToolButton(this); - QToolButton* save_remove_button = new QToolButton(this); - connect(save_add_button, &QToolButton::clicked, this, [=](){ - Color_selector* selector = new Color_selector(this); - selector->show(); - selector->update(); - connect(selector, &Color_selector::color_select, this, [=](QColor color){ - save_box->addItem(QString::number(color.red())+","+QString::number(color.green()) - +","+QString::number(color.blue())); - QStandardItemModel* model = qobject_cast(save_box->model()); - model->item(save_box->count()-1)->setBackground(color); - int red, green, blue; - color.getRgb(&red, &green, &blue); - red = red + (red - 127) * 0.5; - red = (red < 0x00) ? 0xff+red : (red > 0xff) ? red-0xff : red; - green = green + (green - 127) * 0.5; - green = (green < 0x00) ? 0xff+green : (green > 0xff) ? green - 0xff : green; - blue = blue + (blue - 127) * 0.5; - blue = (blue < 0x00) ? 0xff+blue : (blue > 0xff) ? blue - 0xff : blue; - model->item(save_box->count()-1)->setForeground(QColor(red, green, blue)); - save_box->setCurrentIndex(save_box->count()-1); - History::instance()->log_color(color); - emit saveDisableColorChange(-1, color); - }); - }); - connect(save_remove_button, &QToolButton::clicked, this, [=](){ - if(save_box->count()<=0) - { - return; - } - int index = save_box->currentIndex(); - QString str = save_box->itemText(index); - save_box->removeItem(index); - QStringList list = str.split(','); - QColor color(list[0].toInt(), list[1].toInt(), list[2].toInt()); - History::instance()->remove_color(color); - qDebug() << index; - emit saveDisableColorChange(index); - }); - save_add_button->setIcon(QIcon(":/image/add.svg")); - save_remove_button->setIcon(QIcon(":/image/delete.svg")); - save_layout->addWidget(save_label); - save_layout->addWidget(save_box); - save_layout->addWidget(save_add_button); - save_layout->addWidget(save_remove_button); - spacer->add_layout(save_layout); - spacer->add_layout(combo_layout); - layout->addWidget(spacer); - -} - -void Paint_setting_panel::init_layer_setting() -{ - Spacer* spacer = new Spacer("{i4yFQ5UXBc}层次管理", false, this); - list_widget = new List_widget(this); - connect(list_widget, &List_widget::text_change, this, [=](int index, QString text){ - emit layer_rename(index, text); - }); - connect(list_widget, &List_widget::button_click, this, [=](int index, List_item::button_type type){ - switch(type) - { - case 0: - emit change_layer_position(index, index-1);break; - case 1: - emit change_layer_position(index, index+1);break; - case 2: - emit remove_layer(index);break; - case 3: - emit append_layer(); - break; - } - }); - emit requestLayersName(); - spacer->add_widget(list_widget); - layout->addWidget(spacer); -} - - -void Paint_setting_panel::closeEvent(QCloseEvent *event) -{ - WindowBase* window; - if((window = WindowManager::getWindow("PaintWindow")) != NULL) - { - window->onPaintWindowClose(); - } - else - { - qWarning("warning: paint_setting_panel close after paint window\nPaint" - "_setting_panel:close_event"); - } - event->accept(); -} - - -void Paint_setting_panel::set_style() -{ - QColor color = Style_manager::instance()->get_now().color; - int r = 0, g = 0, b = 0; - color.getRgb(&r,&g,&b); - color_button->setStyleSheet(QString("background-color: rgb(%1,%2,%3)").arg(r).arg(g).arg(b)); - int a = 0; - color = Style_manager::instance()->get_now().back_color; - color.getRgb(&r, &g, &b, &a); - //back_button->setStyleSheet(QString("background-color: rgba(%1, %2, %3, %4)").arg(r).arg(g).arg(b).arg(a)); - width_button->setEditText(QString::number(Style_manager::instance()->get_now().width)); -} - -void Paint_setting_panel::receiveLayerName(QString name) -{ - list_widget->add_widget(name); -} - -void Paint_setting_panel::receiveLayersName(QStringList name) -{ - for(QString str : name) - { - list_widget->add_widget(str); - } -} diff --git a/Paint/Widgets/Panels/paint_setting_panel.h b/Paint/Widgets/Panels/paint_setting_panel.h deleted file mode 100644 index 29e339d..0000000 --- a/Paint/Widgets/Panels/paint_setting_panel.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef PAINT_SETTING_PANEL_H -#define PAINT_SETTING_PANEL_H -#include -#include -#include -#include -#include -#include "Paint/Widgets/Layer_list/list_widget.h" -#include "Paint/Data/Common.h" - -class Paint_setting_panel : public QDockWidget -{ - Q_OBJECT -public: - friend class PaintWindow; - static Paint_setting_panel* instance(QWidget* parent=nullptr); - Paint_setting_panel(); - Paint_setting_panel(QWidget* parent = nullptr); - ~Paint_setting_panel(); - void init(); - void closeEvent(QCloseEvent *event) override; - void set_style(); -signals: - void disable_color_change(int index, QColor color=QColor()); - void saveDisableColorChange(int index, QColor color=QColor()); - void paint_shape(SHAPE_TYPE type); - void layer_rename(int index, QString after_name); - void remove_layer(int index); - void append_layer(); - void change_layer_position(int before_index, int after_index); - void requestLayersName(); -public slots: - void receiveLayerName(QString name); - void receiveLayersName(QStringList name); -private: - static Paint_setting_panel* _instance; - QWidget* parent; - QWidget* base; - QScrollArea* area; - QVBoxLayout* layout; - QPushButton* color_button; - QPushButton* back_button; - QComboBox* width_button; - List_widget* list_widget; - void init_pen_setting(); - void init_layer_setting(); - void init_disable_color_setting(); - void init_shape_setting(); -}; - -#endif // PAINT_SETTING_PANEL_H diff --git a/Paint/Widgets/Recorder_element/paint_record.cpp b/Paint/Widgets/Recorder_element/paint_record.cpp deleted file mode 100644 index 04292a8..0000000 --- a/Paint/Widgets/Recorder_element/paint_record.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "paint_record.h" -#include - -PaintRecord::PaintRecord(PaintItem* item) -{ - this->item = item; - this->baseObject = item; -} - -void PaintRecord::undo() -{ - item->hide(); -} - -void PaintRecord::redo() -{ - item->show(); -} diff --git a/Paint/Widgets/Recorder_element/paint_record.h b/Paint/Widgets/Recorder_element/paint_record.h deleted file mode 100644 index da5f21e..0000000 --- a/Paint/Widgets/Recorder_element/paint_record.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef PAINT_RECORD_H -#define PAINT_RECORD_H -#include "Base/RecordElement.h" -#include "Paint/Data/Common.h" -#include "Paint/Widgets/Layers/LayerItems/paintitem.h" - -class PaintRecord : public RecordElement -{ -public: - PaintRecord(PaintItem* item); - void redo() override; - void undo() override; -private: - PaintItem* item; -}; - -#endif // PAINT_RECORD_H diff --git a/Paint/Widgets/Recorder_element/paintdeleterecord.cpp b/Paint/Widgets/Recorder_element/paintdeleterecord.cpp deleted file mode 100644 index 7dac789..0000000 --- a/Paint/Widgets/Recorder_element/paintdeleterecord.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "paintdeleterecord.h" -#include "Helper/Reflect.h" - -PaintDeleteRecord::PaintDeleteRecord( PaintLayer* layer, PaintItem* item, const char* func_name) -{ - item->hide(); - this->layer = layer; - this->item = item; - this->func = func_name; - this->baseObject = item; -} - -void PaintDeleteRecord::undo() -{ - Reflect::invokeMethod(layer->metaObject()->className(), layer, func, QGenericReturnArgument(), - Q_ARG(bool, true), Q_ARG(PaintItem*, item)); -} - -void PaintDeleteRecord::redo() -{ - Reflect::invokeMethod(layer->metaObject()->className(), layer, func, QGenericReturnArgument(), - Q_ARG(bool, false), Q_ARG(PaintItem*, item)); -} diff --git a/Paint/Widgets/Recorder_element/paintdeleterecord.h b/Paint/Widgets/Recorder_element/paintdeleterecord.h deleted file mode 100644 index 3b28e2a..0000000 --- a/Paint/Widgets/Recorder_element/paintdeleterecord.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef PAINTDELETERECORD_H -#define PAINTDELETERECORD_H -#include "Base/RecordElement.h" -#include "Paint/Widgets/Layers/paintlayer.h" -#include "Paint/Widgets/Layers/LayerItems/paintitem.h" - -class PaintDeleteRecord : public RecordElement -{ -public: - PaintDeleteRecord( PaintLayer* layer, PaintItem* item, const char* func); - void redo() override; - void undo() override; -private: - PaintLayer* layer; - PaintItem* item; - const char* func; -}; - -#endif // PAINTDELETERECORD_H diff --git a/Paint/Widgets/Recorder_element/resize_record.cpp b/Paint/Widgets/Recorder_element/resize_record.cpp deleted file mode 100644 index 06be55f..0000000 --- a/Paint/Widgets/Recorder_element/resize_record.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "resize_record.h" -#include "Helper/Reflect.h" - -ResizeRecord::ResizeRecord(QGraphicsObject* object, const char* func_name, QRectF before_rect, QRectF after_rect) -{ - baseObject = object; - this->object = object; - this->func_name = func_name; - this->before_rect = before_rect; - this->after_rect = after_rect; - this->baseObject = object; -} - -void ResizeRecord::redo() -{ - Reflect::invokeMethod(object->metaObject()->className(), object, func_name, QGenericReturnArgument(), - Q_ARG(bool, false), Q_ARG(QRectF, before_rect), Q_ARG(QRectF, after_rect)); -} - -void ResizeRecord::undo() -{ - Reflect::invokeMethod(object->metaObject()->className(), object, func_name, QGenericReturnArgument(), - Q_ARG(bool, true), Q_ARG(QRectF, before_rect), Q_ARG(QRectF, after_rect)); -} diff --git a/Paint/Widgets/Recorder_element/resize_record.h b/Paint/Widgets/Recorder_element/resize_record.h deleted file mode 100644 index 39dde1f..0000000 --- a/Paint/Widgets/Recorder_element/resize_record.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef RESIZE_RECORD_H -#define RESIZE_RECORD_H -#include "Base/RecordElement.h" -#include - -class ResizeRecord : public RecordElement -{ -public: - ResizeRecord(QGraphicsObject* object, const char* func_name, QRectF before_rect, QRectF after_rect); - void redo() override; - void undo() override; -private: - QGraphicsObject* object; - const char* func_name; - QRectF before_rect; - QRectF after_rect; -}; - -#endif // RESIZE_RECORD_H diff --git a/Paint/Widgets/Recorder_element/shaperecord.cpp b/Paint/Widgets/Recorder_element/shaperecord.cpp deleted file mode 100644 index ce65599..0000000 --- a/Paint/Widgets/Recorder_element/shaperecord.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "shaperecord.h" -#include "Helper/Reflect.h" - -ShapeRecord::ShapeRecord(QGraphicsObject* object, QGraphicsObject* show_object, const char* func_name, bool show) -{ - baseObject = object; - this->object = show_object; - this->func_name = func_name; - this->show = show; -} - -void ShapeRecord::undo() -{ - Reflect::invokeMethod(baseObject->metaObject()->className(), baseObject, func_name, QGenericReturnArgument(), - Q_ARG(bool, show), Q_ARG(QGraphicsObject*, object)); -} - -void ShapeRecord::redo() -{ - Reflect::invokeMethod(baseObject->metaObject()->className(), baseObject, func_name, QGenericReturnArgument(), - Q_ARG(bool, !show), Q_ARG(QGraphicsObject*, object)); -} diff --git a/Paint/Widgets/Recorder_element/shaperecord.h b/Paint/Widgets/Recorder_element/shaperecord.h deleted file mode 100644 index 9729930..0000000 --- a/Paint/Widgets/Recorder_element/shaperecord.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef SHAPERECORD_H -#define SHAPERECORD_H -#include "Base/RecordElement.h" -#include - -class ShapeRecord : public RecordElement -{ -public: - ShapeRecord(QGraphicsObject* object, QGraphicsObject* show_object, const char* func_name, bool origin_show); - void redo() override; - void undo() override; -private: - QGraphicsObject* object; - const char* func_name; - bool show; -}; - -#endif // SHAPERECORD_H diff --git a/Paint/Widgets/recorder.cpp b/Paint/Widgets/recorder.cpp deleted file mode 100644 index d800494..0000000 --- a/Paint/Widgets/recorder.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include "recorder.h" -#include - -Recorder::Recorder() -{ - data = MVector(); -} - -Recorder* Recorder::_instance = NULL; - -Recorder* Recorder::instance() -{ - if(_instance == NULL) - { - _instance = new Recorder(); - } - return _instance; -} - -Recorder::~Recorder() -{ - data.clear(); - _instance = NULL; -} - -void Recorder::back() -{ - RecordElement* element; - //当没到栈底并且当前undo操作不成功时 - if (data.can_undo()) - { - element = data.pop(); - element->undo(); - } - emit recordChange(); -} - -void Recorder::forward() -{ - RecordElement* element; - if (data.can_redo()) - { - element = data.forward(); - element->redo(); - } - emit recordChange(); -} - -void Recorder::removeRecord(QObject* layer) -{ - for(int i=0; ibaseObject == layer) - { - data.remove(i); - i--; - } - } - emit recordChange(); -} - -void Recorder::record(RecordElement* element) -{ - data.push_and_resize(element); - emit recordChange(); -} - - -void Recorder::reset() -{ - data.reset(); - emit recordChange(); -} - -bool Recorder::undoAvaliable() -{ - return data.can_undo(); -} - -bool Recorder::redoAvaliable() -{ - return data.can_redo(); -} diff --git a/Paint/Widgets/recorder.h b/Paint/Widgets/recorder.h deleted file mode 100644 index 99ee614..0000000 --- a/Paint/Widgets/recorder.h +++ /dev/null @@ -1,141 +0,0 @@ -#ifndef Recorder_H -#define Recorder_H -#include -#include "Base/RecordElement.h" -#include -#include "Helper/debug.h" -#include -#include - -class Recorder : public QObject -{ - Q_OBJECT -public: - Recorder(); - ~Recorder(); - static Recorder* instance(); - void record(RecordElement* element); - void reset(); - void back(); - void forward(); - void removeRecord(QObject* item); - bool undoAvaliable(); - bool redoAvaliable(); -signals: - void recordChange(); -private: - struct Record_data - { - Record_data(){}; - Record_data(int index, RecordElement* element) - { - this->index = index; - this->element = element; - } - int index;//在element中的标识 - RecordElement* element; - }; - struct MVector - { - int limit; - int point; - QVector data; - MVector() - { - limit = 0; - point = 0; - } - - void clear() - { - for(int i=0; i 0) - { - return data[--point]; - } - qWarning("下标过小\n位置Recorder::MVector::pop()"); - return NULL; - } - - void push_and_resize(RecordElement* record_data) - { - if(can_redo()) - { - for(int i=point; i limit-1) - { - qWarning("数组下标超界\n位置Recorder::MVector::get()"); - return NULL; - } - return data[i]; - } - - inline bool can_redo(){return point < limit;}; - inline bool can_undo(){return point > 0;}; - - inline int size(){return limit;}; - - inline RecordElement*& forward(){point++;return data[point-1];}; - }; - - static Recorder* _instance; - MVector data; -}; - -#endif // Recorder_H diff --git a/Paint/Widgets/style_manager.cpp b/Paint/Widgets/style_manager.cpp deleted file mode 100644 index b13dc69..0000000 --- a/Paint/Widgets/style_manager.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include "style_manager.h" -#include "../../Manager/uimanager.h" - -Style_manager* Style_manager::_instance = NULL; - -Style_manager::Style_manager() { - data = PList(); - now_data = UIManager::instance()->getPencilData(); - PaintData* temp_data = new PaintData(); - now_data.copy_to(temp_data); - data.append(temp_data); - is_change = false; -} - -Style_manager::~Style_manager() { - data.clear_all(); - _instance = NULL; -} - -Style_manager* Style_manager::instance() { - if(_instance == NULL) { - _instance = new Style_manager(); - } - return _instance; -} - -void Style_manager::reset() { - data.clear_all(); - now_data = UIManager::instance()->getPencilData(); - PaintData* temp_data = new PaintData(); - now_data.copy_to(temp_data); - data.append(temp_data); - is_change = false; -} - -void Style_manager::change_color(QColor color) { - now_data.color = color; - is_change = true; -} - -void Style_manager::change_back_color(QColor color) { - now_data.backColor = color; - is_change = true; -} - -void Style_manager::change_width(double width) { - now_data.width = width; - is_change = true; -} - -void Style_manager::change_cap_style(Qt::PenCapStyle style) { - now_data.capStyle = style; - is_change = true; -} - -void Style_manager::change_join_style(Qt::PenJoinStyle style) { - now_data.joinStyle = style; - is_change = true; -} - -void Style_manager::change_pen(PaintData data) { - if(now_data.color != data.color) - change_color(data.color); - if(now_data.width != data.width) - change_width(data.width); - if(now_data.capStyle != data.capStyle) - change_cap_style(data.capStyle); - if(now_data.joinStyle != data.joinStyle) - change_join_style(data.joinStyle); -} - -PaintData* Style_manager::get() { - if(!is_change) { - return data.last(); - } else { - PaintData* temp_data = new PaintData(); - now_data.copy_to(temp_data); - data.push_back(temp_data); - is_change = false; - return temp_data; - } -} - -PaintData Style_manager::get_now() { - if(is_change) { - PaintData* temp_data = new PaintData(); - now_data.copy_to(temp_data); - data.push_back(temp_data); - is_change = false; - } - return now_data; -} diff --git a/Paint/Widgets/style_manager.h b/Paint/Widgets/style_manager.h deleted file mode 100644 index 8d55d91..0000000 --- a/Paint/Widgets/style_manager.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef STYLE_MANAGER_H -#define STYLE_MANAGER_H -#include "../../Helper/plist.h" -#include "../../GraphicsScene/Widgets/PaintData.h" -#include - -class Style_manager { -public: - Style_manager(); - static Style_manager* instance(); - ~Style_manager(); - void reset(); - void change_color(QColor color); - void change_width(double width); - void change_cap_style(Qt::PenCapStyle style); - void change_join_style(Qt::PenJoinStyle style); - void change_pen(PaintData data); - void change_back_color(QColor color); - PaintData* get(); - PaintData get_now(); -private: - static Style_manager* _instance; - PList data; - PaintData now_data; - bool is_change;//设置改变了就需要加入data备份中 -}; - -#endif // STYLE_MANAGER_H diff --git a/Style_widget/colorwidget.cpp b/Style_widget/colorwidget.cpp index 21680c7..d8e2a13 100644 --- a/Style_widget/colorwidget.cpp +++ b/Style_widget/colorwidget.cpp @@ -2,7 +2,6 @@ #include "ui_ColorWidget.h" #include #include -#include "../Paint/Widgets/style_manager.h" #include #include "../Helper/mstring.h" #include @@ -31,7 +30,6 @@ ColorWidget::ColorWidget(QWidget* parent) : QWidget(parent), ui(new Ui::ColorWid color.getRgb(&r,&g,&b); this->default_color.setRgb(r, g, b); ui->current->setStyleSheet(QString("background-color: rgba(%1,%2,%3, 1)").arg(r).arg(g).arg(b)); - Style_manager::instance()->change_color(default_color); emit colorChange(default_color); } }); @@ -46,7 +44,7 @@ void ColorWidget::setCurrentStyle(QColor color) { default_color = color; default_color.getRgb(&r,&g,&b, &a); ui->current->setStyleSheet(QString("background-color: rgba(%1,%2,%3, 1)").arg(r).arg(g).arg(b)); - Style_manager::instance()->change_color(color); + emit colorChange(default_color); } void ColorWidget::onDefaultClick() { @@ -59,7 +57,7 @@ void ColorWidget::onDefaultClick() { b = ex.capturedTexts().at(3).toInt(); default_color.setRgb(r, g, b); ui->current->setStyleSheet(QString("background-color: rgba(%1,%2,%3, 1)").arg(r).arg(g).arg(b)); - Style_manager::instance()->change_color(default_color); + emit colorChange(default_color); } } diff --git a/new_capture/Widgets/Scroll_handler/Scroll_handle_global.cpp b/Windows/ScrollHandler/Scroll_handle_global.cpp similarity index 100% rename from new_capture/Widgets/Scroll_handler/Scroll_handle_global.cpp rename to Windows/ScrollHandler/Scroll_handle_global.cpp diff --git a/new_capture/Widgets/Scroll_handler/Scroll_handler_global.h b/Windows/ScrollHandler/Scroll_handler_global.h similarity index 100% rename from new_capture/Widgets/Scroll_handler/Scroll_handler_global.h rename to Windows/ScrollHandler/Scroll_handler_global.h diff --git a/new_capture/Widgets/Scroll_handler/dispatcher_worker.cpp b/Windows/ScrollHandler/dispatcher_worker.cpp similarity index 100% rename from new_capture/Widgets/Scroll_handler/dispatcher_worker.cpp rename to Windows/ScrollHandler/dispatcher_worker.cpp diff --git a/new_capture/Widgets/Scroll_handler/dispatcher_worker.h b/Windows/ScrollHandler/dispatcher_worker.h similarity index 100% rename from new_capture/Widgets/Scroll_handler/dispatcher_worker.h rename to Windows/ScrollHandler/dispatcher_worker.h diff --git a/new_capture/Widgets/Scroll_handler/scroll_dispatcher.cpp b/Windows/ScrollHandler/scroll_dispatcher.cpp similarity index 100% rename from new_capture/Widgets/Scroll_handler/scroll_dispatcher.cpp rename to Windows/ScrollHandler/scroll_dispatcher.cpp diff --git a/new_capture/Widgets/Scroll_handler/scroll_dispatcher.h b/Windows/ScrollHandler/scroll_dispatcher.h similarity index 100% rename from new_capture/Widgets/Scroll_handler/scroll_dispatcher.h rename to Windows/ScrollHandler/scroll_dispatcher.h diff --git a/new_capture/Widgets/Scroll_handler/scroll_handle.cpp b/Windows/ScrollHandler/scroll_handle.cpp similarity index 100% rename from new_capture/Widgets/Scroll_handler/scroll_handle.cpp rename to Windows/ScrollHandler/scroll_handle.cpp diff --git a/new_capture/Widgets/Scroll_handler/scroll_handle.h b/Windows/ScrollHandler/scroll_handle.h similarity index 100% rename from new_capture/Widgets/Scroll_handler/scroll_handle.h rename to Windows/ScrollHandler/scroll_handle.h diff --git a/new_capture/Widgets/Scroll_handler/scroll_worker.cpp b/Windows/ScrollHandler/scroll_worker.cpp similarity index 100% rename from new_capture/Widgets/Scroll_handler/scroll_worker.cpp rename to Windows/ScrollHandler/scroll_worker.cpp diff --git a/new_capture/Widgets/Scroll_handler/scroll_worker.h b/Windows/ScrollHandler/scroll_worker.h similarity index 100% rename from new_capture/Widgets/Scroll_handler/scroll_worker.h rename to Windows/ScrollHandler/scroll_worker.h diff --git a/new_capture/Widgets/VideoHandler/videocapture.cpp b/Windows/Widgets/videocapture.cpp similarity index 100% rename from new_capture/Widgets/VideoHandler/videocapture.cpp rename to Windows/Widgets/videocapture.cpp diff --git a/new_capture/Widgets/VideoHandler/videocapture.h b/Windows/Widgets/videocapture.h similarity index 100% rename from new_capture/Widgets/VideoHandler/videocapture.h rename to Windows/Widgets/videocapture.h diff --git a/new_capture/CaptureWindow.cpp b/Windows/capturewindow.cpp similarity index 69% rename from new_capture/CaptureWindow.cpp rename to Windows/capturewindow.cpp index 8820188..3b16f12 100644 --- a/new_capture/CaptureWindow.cpp +++ b/Windows/capturewindow.cpp @@ -1,4 +1,4 @@ -#include "CaptureWindow.h" +#include "capturewindow.h" #include "Manager/WindowManager.h" #include #include @@ -9,31 +9,28 @@ #include #include "hook.h" #include -#include "window_fliter.h" +#include "windowfilter.h" #include "Helper/imagehelper.h" #include #include #include #include -#include "Paint/Widgets/PaintArea.h" +#include "../GraphicsScene/paintarea.h" #include "Helper/GraphicsViewPatch.h" #include -#include "Paint/Widgets/history.h" -#include "Paint/Widgets/style_manager.h" -#include "Paint/Widgets/recorder.h" -#include "Paint/Widgets/Panels/flow_edit_panel.h" +#include "../Manager/history.h" #include "Helper/math.h" #include #include -#include "Widgets/capturetip.h" +//#include "Widgets/capturetip.h" bool CaptureWindow::end_scroll = false; CaptureWindow::CaptureWindow(QWidget *parent) : - WindowBase(parent) + WindowBase(parent) // ui(new Ui::CaptureWindow) { -// ui->setupUi(this); + // ui->setupUi(this); centralWidget = new QWidget(this); setCentralWidget(centralWidget); button_click = false; @@ -49,54 +46,54 @@ CaptureWindow::CaptureWindow(QWidget *parent) : setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_OpaquePaintEvent ); -// showFullScreen(); + // showFullScreen(); this->setMouseTracking(true); centralWidget->setMouseTracking(true); #ifdef QT_NO_DEBUG setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); #endif -// ui->centralwidget->setGeometry(QGuiApplication::primaryScreen()->geometry()); + // ui->centralwidget->setGeometry(QGuiApplication::primaryScreen()->geometry()); setGeometry(ImageHelper::getCurrentScreen()->geometry()); view = new QGraphicsView(this); - area = new PaintArea(view, true); - area->stateChange(ARROW); + area = new PaintArea(view); + defaultToolbar = new DefaultToolbar(area, this); view->setScene(area); view->setStyleSheet(".QGraphicsView{background: transparent;border:0px;}"); view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate); -// view->viewport()->installEventFilter(new GraphicsViewPatch(view)); + // view->viewport()->installEventFilter(new GraphicsViewPatch(view)); view->setFrameShape(QFrame::NoFrame); view->setBackgroundRole(QPalette::Light); view->setAlignment(Qt::AlignCenter); view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); - if((Config::getConfig(Config::show_guidance) & Config::CAPTURE_GUID) == 0){ - tips = new BubbleTipsWidget(this); - tips->setBackColor(255, 255, 255); - tips->setShowHideButton(true); - CaptureTip* captureTip = new CaptureTip(this); - tips->setContent(captureTip); - connect(tips, &BubbleTipsWidget::hideButtonTrigger, this, [=](bool trigger){ - int guidance = Config::getConfig(Config::show_guidance); - if(trigger) - guidance = guidance | Config::CAPTURE_GUID; - else - guidance = guidance & (~Config::CAPTURE_GUID); - Config::setConfig(Config::show_guidance, guidance); - Config::updateConfig(Config::show_guidance); - }); - QGraphicsProxyWidget* proxyTips = area->addTip(tips); - proxyTips->setZValue(10); - } +// if((Config::getConfig(Config::show_guidance) & Config::CAPTURE_GUID) == 0){ +// tips = new BubbleTipsWidget(this); +// tips->setBackColor(255, 255, 255); +// tips->setShowHideButton(true); +// CaptureTip* captureTip = new CaptureTip(this); +// tips->setContent(captureTip); +// connect(tips, &BubbleTipsWidget::hideButtonTrigger, this, [=](bool trigger){ +// int guidance = Config::getConfig(Config::show_guidance); +// if(trigger) +// guidance = guidance | Config::CAPTURE_GUID; +// else +// guidance = guidance & (~Config::CAPTURE_GUID); +// Config::setConfig(Config::show_guidance, guidance); +// Config::updateConfig(Config::show_guidance); +// }); +// QGraphicsProxyWidget* proxyTips = area->addTip(tips); +// proxyTips->setZValue(10); +// } setCentralWidget(view); -// area->onViewSet(view); + // area->onViewSet(view); } CaptureWindow::~CaptureWindow() { -// delete ui + // delete ui if(xHook->isMouseHookRunning()) { xHook->uninstallMouseHook(); } @@ -107,16 +104,16 @@ CaptureWindow::~CaptureWindow() { void CaptureWindow::paintEvent(QPaintEvent *paint_event) { QPainter painter(this); -// if(Config::getConfig(Config::free_capture) && button_click) -// { -// QPen pen; -// pen.setStyle(Qt::DashLine); -// pen.setColor(QColor(123, 123, 233)); -// pen.setWidth(3); -// painter.setPen(pen); -// painter.drawPath(free_paint_path); -// return; -// } + // if(Config::getConfig(Config::free_capture) && button_click) + // { + // QPen pen; + // pen.setStyle(Qt::DashLine); + // pen.setColor(QColor(123, 123, 233)); + // pen.setWidth(3); + // painter.setPen(pen); + // painter.drawPath(free_paint_path); + // return; + // } if(Config::getConfig(Config::capture_mode) == Config::RECT_CAPTURE && isVideoCapture) { QPen pen; pen.setWidth(3); @@ -134,76 +131,79 @@ void CaptureWindow::paintEvent(QPaintEvent *paint_event) { } void CaptureWindow::loadKeyEvent(QString name) { -// if(!KeyManager::isContainsWindow(name)) -// { -KeyManager::instance()->addFunc(this, name, "leave", [=](bool is_enter) { + // if(!KeyManager::isContainsWindow(name)) + // { + KeyManager::instance()->addFunc(this, name, "leave", [=](bool is_enter) { if(is_enter) { WindowManager::changeWindow("tray"); } }); KeyManager::instance()->addFunc(this, name, "capture_rect", [=](bool is_enter) { - if(area->hasFocus() && is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) - area->clipButtonEnter(0); + if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) + defaultToolbar->onGroupClick(0); }); KeyManager::instance()->addFunc(this, name, "capture_mosaic", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) - area->clipButtonEnter(1); + defaultToolbar->onGroupClick(1); }); KeyManager::instance()->addFunc(this, name, "capture_cursor", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) - area->clipButtonEnter(2); + defaultToolbar->onGroupClick(2); }); KeyManager::instance()->addFunc(this, name, "capture_pencil", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) - area->clipButtonEnter(3); + defaultToolbar->onGroupClick(3); }); KeyManager::instance()->addFunc(this, name, "capture_highlighter", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) - area->clipButtonEnter(4); + defaultToolbar->onGroupClick(4); }); KeyManager::instance()->addFunc(this, name, "capture_text", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) - area->clipButtonEnter(5); + defaultToolbar->onGroupClick(5); }); KeyManager::instance()->addFunc(this, name, "capture_erase", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) - area->clipButtonEnter(6); + defaultToolbar->onGroupClick(6); }); KeyManager::instance()->addFunc(this, name, "capture_undo", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) - Recorder::instance()->back(); + area->getRecorder()->back(); }); KeyManager::instance()->addFunc(this, name, "capture_redo", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) - Recorder::instance()->forward(); + area->getRecorder()->forward(); }); KeyManager::instance()->addFunc(this, name, "save2file", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) { QString file_name = QFileDialog::getSaveFileName(this, - "保存", - History::instance()->get_last_directory(), - "图片(*.bmp *.jpg *.jpeg *.png);;所有文件(*)"); + "保存", + History::instance()->get_last_directory(), + "图片(*.bmp *.jpg *.jpeg *.png);;所有文件(*)"); KeyManager::instance()->clearKeys("CaptureWindow"); if(file_name != "") { - if(area->save(History_data::Persist, file_name)) + if(area->save(ILayerControl::Persist, file_name)) WindowManager::changeWindow("tray"); } } }); KeyManager::instance()->addFunc(this, name, "save2clip", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) { - if(area->save2Clipboard()) + if(area->save(ILayerControl::ClipBoard)) WindowManager::changeWindow("tray"); } }); KeyManager::instance()->addFunc(this, name, "enter_capture", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) { - area->sendRequestImage(); + QImage image = area->getSaveImage(); + QRect bound = area->getSaveRect().toRect(); + bound.moveTo(0, 0); + WindowManager::changeWindow("PaintWindow", QPixmap::fromImage(image), bound); } }); KeyManager::instance()->addFunc(this, name, "capture_scrollrect", [=](bool is_enter) { }); -// } + // } } void CaptureWindow::mouseMoveEvent(QMouseEvent *event) { @@ -228,37 +228,33 @@ void CaptureWindow::mouseReleaseEvent(QMouseEvent *event) { void CaptureWindow::onWindowCancel() { button_click = false; -// is_first_capture = true; -// area->reset(); + // is_first_capture = true; + // area->reset(); free_paint_path = QPainterPath(); active_window_bound = QRect(); -// Style_manager::instance()->reset(); -// Recorder::instance()->reset(); + // Style_manager::instance()->reset(); + // Recorder::instance()->reset(); KeyManager::instance()->unRegisterGlobalKey("capture_video_start"); KeyManager::instance()->unRegisterGlobalKey("capture_video_pause"); KeyManager::instance()->unRegisterGlobalKey("capture_video_stop"); } void CaptureWindow::onWindowSelect() { -// Window_fliter::instance()->SnapshotAllWinRect(); + // Window_fliter::instance()->SnapshotAllWinRect(); KeyManager::instance()->registerGlobalKey("capture_video_start"); KeyManager::instance()->registerGlobalKey("capture_video_pause"); KeyManager::instance()->registerGlobalKey("capture_video_stop"); area->reset(); area->update(); - Flow_edit_panel::instance()->reset(); - Style_manager::instance()->reset(); - Recorder::instance()->reset(); setGeometry(ImageHelper::getCurrentGeometry()); view->show(); QPixmap p = ImageHelper::grabScreen(); - area->setClipPic(p); - area->stateChange(ARROW); + area->setImage(p.toImage()); } void CaptureWindow::startCaptureVideo() { if(!(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) { - videoCapture->setCaptureInfo(area->getRecordInfo()); +// videoCapture->setCaptureInfo(area->getRecordInfo()); if(videoCapture->isValid() && !isVideoCapture) { isVideoCapture = true; view->hide(); diff --git a/new_capture/CaptureWindow.h b/Windows/capturewindow.h similarity index 83% rename from new_capture/CaptureWindow.h rename to Windows/capturewindow.h index 93947c6..3aa8f33 100644 --- a/new_capture/CaptureWindow.h +++ b/Windows/capturewindow.h @@ -9,15 +9,15 @@ #include #define WIN32_LEAN_AND_MEAN #include -#include "new_capture/Widgets/Scroll_handler/scroll_dispatcher.h" -#include "opencv2/core/core.hpp" +#include #include #include #include -#include "Paint/Widgets/PaintArea.h" -#include "Helper/EnumReflect.h" -#include "Style_widget/bubbletipswidget.h" -#include "Widgets/VideoHandler/videocapture.h" +#include "../GraphicsScene/paintarea.h" +#include "../Helper/EnumReflect.h" +#include "../Style_widget/bubbletipswidget.h" +#include "Widgets/videocapture.h" +#include "../GraphicsScene/Widgets/defaulttoolbar.h" //namespace Ui { //class CaptureWindow; @@ -42,7 +42,7 @@ class CaptureWindow : public WindowBase { void stopCaptureVideo() override; private: -// Ui::CaptureWindow *ui; + // Ui::CaptureWindow *ui; QWidget* centralWidget; bool button_click; QPainterPath free_paint_path; @@ -59,13 +59,13 @@ class CaptureWindow : public WindowBase { QPoint end_point; bool begin_waiting; //bool combine_image(QImage image); - Scroll_dispatcher* dispatcher; bool is_finish; QGraphicsView* view; PaintArea* area; VideoCaptureHandler* videoCapture; BubbleTipsWidget* tips; bool isVideoCapture; + DefaultToolbar* defaultToolbar; }; #endif // CAPTURE_WINDOW_H diff --git a/Windows/paintwindow.cpp b/Windows/paintwindow.cpp new file mode 100644 index 0000000..9e28072 --- /dev/null +++ b/Windows/paintwindow.cpp @@ -0,0 +1,285 @@ +#include "paintwindow.h" +//#include "ui_paint_window.h" +#include +#include +#include "Manager/WindowManager.h" +#include +#include +#include +#include +#include "../Manager/history.h" +#include +#include +#include "Manager/config.h" +#include +#include "Manager/KeyManager.h" +#include +#include +#include +#include "opencv2/core.hpp" +#include "opencv2/opencv.hpp" +#include "Style_widget/titlebar.h" +#include "Style_widget/framelesshelper.h" +#include +#include +#include +#include "Helper/imagehelper.h" +#include "Helper/common.h" + +PaintWindow::PaintWindow(QWidget *parent) : + WindowBase(parent) +// ui(new Ui::PaintWindow) +{ + // ui->setupUi(this); + centralWidget = new QWidget(this); + setCentralWidget(centralWidget); + addToolBar(Qt::TopToolBarArea, toolbar); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + Titlebar* title_bar = new Titlebar(this); + installEventFilter(title_bar); + FramelessHelper* helper = new FramelessHelper(this); + helper->activateOn(this); + helper->setWidgetResizable(true); + helper->setWidgetMovable(true); + helper->setTitleHeight(30); + helper->setRubberBandOnResize(true); + setWindowFlags (Qt::FramelessWindowHint); + setWindowTitle("简截"); + setWindowIcon(QIcon(":/image/avator.png")); + // connect(title_bar, &Titlebar::minimize, this, [=]() { + // WindowManager::changeWindow("tray"); + // }); + menuBar = new QMenuBar(this); + QWidget* menu_widget = new QWidget(this); + QVBoxLayout* menu_layout = new QVBoxLayout(); + menu_layout->setMargin(0); + menu_layout->addWidget(title_bar); + menu_layout->addWidget(menuBar); + menu_widget->setLayout(menu_layout); + menu_widget->setStyleSheet("background-color: rgb(255, 255, 255)"); + setMenuWidget(menu_widget); + + layout = new QHBoxLayout(centralWidget); + + this->area = new PaintArea(this); + toolbar = new DefaultToolbar(area, this); + + paint_panel = new QGraphicsView(this->area, this); + paint_panel->setFrameShape(QFrame::NoFrame); + paint_panel->setBackgroundRole(QPalette::Light); + paint_panel->setAlignment(Qt::AlignCenter); + paint_panel->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + paint_panel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + //paint_panel->setWidgetResizable(true); + paint_panel->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); + + layout->addWidget(paint_panel); + centralWidget->setLayout(layout); + set_menubar(); + addToolBarBreak(); + setMinimumSize(400, 200); +} + +PaintWindow::~PaintWindow() { + // delete ui; +} + +void PaintWindow::loadKeyEvent(QString name) { + // if(!KeyManager::isContainsWindow("PaintWindow")) + // { + KeyManager::instance()->addFunc(this, name, "undo", [=](bool is_enter) { + if(is_enter) area->getRecorder()->back(); + }); + KeyManager::instance()->addFunc(this, name, "redo", [=](bool is_enter) { + if(is_enter) area->getRecorder()->forward(); + }); + KeyManager::instance()->addFunc(this, name, "save", [=](bool is_enter) { + if(is_enter) { + QString file_name = QFileDialog::getSaveFileName(this,"保存", + History::instance()->get_last_directory(), "图片(*.bmp *.jpg *.jpeg *.png);;所有文件(*)"); + KeyManager::instance()->clearKeys("PaintWindow"); + if(file_name != "") { + area->save(ILayerControl::Persist, file_name); + WindowManager::changeWindow("tray"); + } + } + }); + KeyManager::instance()->addFunc(this, name, "new_capture", [=](bool is_enter) { + if(is_enter) { + if(Config::getConfig(Config::capture_mode) == (int)Config::TOTAL_CAPTURE) { + QTimer::singleShot(200, this, [=]() { + QPixmap map = ImageHelper::grabScreen(); + WindowManager::changeWindow("PaintWindow", map, ImageHelper::getCurrentScreen()->geometry()); + if(Config::getConfig(Config::clip_voice)) + QSound::play(":/audio/screenshot.wav"); + }); + + return; + } else { + changeWindowHelper(); + } + Config::setConfig(Config::capture_mode, Config::RECT_CAPTURE); + } + }); + KeyManager::instance()->addFunc(this, name, "delete_shape", [=](bool is_enter) { + if(is_enter) { + // area->delete_shape(); + } + }); + // } +} + +void PaintWindow::set_menubar() { + QMenu* file_setting_menu = new QMenu(this); + file_setting_menu->setTitle(MString::search("{m2Llo9nJ9o}文件")); + QAction* open_action = new QAction(MString::search("{zA7Twj1QhJ}打开"), file_setting_menu); + file_setting_menu->addAction(MString::search("{zA7Twj1QhJ}打开"), open_action, [=]() { + QString file_name = QFileDialog::getOpenFileName(this, + "打开", + History::instance()->get_last_directory(), + "图片(*.bmp *.jpg *.jpeg *.png);;所有文件(*)"); + if(file_name.isEmpty()) { + return; + } else { + QPixmap pixmap; + if(!pixmap.load(file_name)) { + qWarning("文件打开失败"); + return; + } + QRect rect = pixmap.rect(); + rect.moveTo(0, 0); + receiveData(pixmap, rect); + } + }); + QAction* save_action = new QAction(MString::search("{0EtTa6lKzl}另存为"), file_setting_menu); + file_setting_menu->addAction(MString::search("{0EtTa6lKzl}另存为"), save_action, [=]() { + QString file_name = QFileDialog::getSaveFileName(this, + "保存", + History::instance()->get_last_directory(), + "图片(*.bmp *.jpg *.jpeg *.png);;所有文件(*)"); + if(file_name != "") { + area->save(ILayerControl::Persist, file_name); + WindowManager::changeWindow("tray"); + } + }); + QAction* history_action = new QAction(MString::search("{Mo0LoFqQqT}历史"), menuBar); + QMenu* history_menu = new QMenu(MString::search("{Mo0LoFqQqT}历史"), menuBar); + connect(history_action, &QAction::hovered, this, [=]() { //动态生成菜单项 + if(History::instance()->is_change) { //hovered会一直触发,防止重复调用函数导致闪屏 + History::instance()->is_change = false; + history_menu->clear(); + QList history_actions; + int history_num = History::instance()->get_history_num(); + for(int i=history_num-1; i>=0; i--) { + HistoryData data = History::instance()->get(i); + QString file_name = data.type == ILayerControl::Persist ? + data.file_name.mid(data.file_name.lastIndexOf('/')+1) : + QDateTime::fromSecsSinceEpoch(data.time).toString("yyyy.MM.dd hh:mm:ss"); + + QAction* action = new QAction(history_menu); + action->setText(file_name); + connect(action, &QAction::triggered, this, [=]() { + QPixmap pixmap; + + if(!pixmap.load(data.file_name)) { + qWarning("文件不存在"); + return; + } + QRect rect = pixmap.rect(); + rect.moveTo(0, 0); + // area->pic_save = true;//不需要添加记录 + receiveData(pixmap, rect); + }); + history_actions.append(action); + } + history_menu->addActions(history_actions); + } + }); + history_action->setMenu(history_menu); + file_setting_menu->addAction(history_action); + menuBar->addMenu(file_setting_menu); +} + +void PaintWindow::receiveData(QVariant data1, QVariant data2){ + QPixmap pix = data1.value(); + QRect rect = data2.value(); + if(pix.isNull()){ + pix = QPixmap(100, 100); + } + reset(); + area->setImage(pix.toImage()); + paint_panel->update(); + if(Config::getConfig(Config::auto_copy_to_clipboard)) { + QClipboard *clip=QApplication::clipboard(); + clip->setPixmap(pix); + } + QScreen* screen = ImageHelper::getCurrentScreen(); + QRect geometry = screen->availableGeometry(); + int currentWidth = rect.width() + 100; + int currentHeight = rect.height() + 140; + if(currentWidth >= (double)geometry.width() + || currentHeight >= (double)geometry.height()) { + showMaximized(); + } else { + resize(currentWidth, currentHeight);//设置主窗口大小,否则窗口大小不会变化 + //左上角移动到指定位置,截图越大越向(0, 0)点接近 + move(geometry.x() + (geometry.width()-currentWidth)/2, geometry.y() + (geometry.height() - currentHeight) / 2); + } + paint_panel->verticalScrollBar()->setValue(rect.height() / 2); + paint_panel->horizontalScrollBar()->setValue(rect.width() / 2); +} + +void PaintWindow::closeEvent(QCloseEvent *event) { + event->ignore(); + // if(Config::get_config(Config::show_close_dialog)) + // { + // Close_dialog* close_dialog = new Close_dialog(area, this); + // connect(close_dialog, &Close_dialog::hide_paint, this, [=](){ + // WindowManager::changeWindow("MainWindow"); + // WindowManager::hideNow(); + // }); + // close_dialog->show(); + // } + if(Config::getConfig(Config::hide_to_tray)) { + WindowManager::changeWindow("tray"); + + } else { + WindowManager::close(); + } +} + +void PaintWindow::reset() { + QDir dir; + if(!dir.exists("Data/Temp")) { + dir.mkpath("Data/Temp"); + } + QDateTime time = QDateTime::currentDateTime(); + QString path = "Data/Temp/" + time.toString("dd_mm_yyyy_hh_mm_ss") + "/"; + if(!dir.exists(path)) { + dir.mkpath(path); + } + path += "main.png"; + area->save(ILayerControl::Temp, path); + area->reset(); +} + +void PaintWindow::onWindowCancel() { + +} + +void PaintWindow::onWindowSelect() { + setWindowFlag(Qt::WindowSystemMenuHint, true); +} + +void PaintWindow::onPaintWindowClose() { +} + +void PaintWindow::onWindowClose() { + // delete Style_manager::instance(); + // delete Recorder::instance(); + // delete History::instance(); + QClipboard *clip=QApplication::clipboard(); + if(Config::getConfig(Config::auto_copy_to_clipboard)) { + clip->clear(); + } +} diff --git a/Paint/PaintWindow.h b/Windows/paintwindow.h similarity index 62% rename from Paint/PaintWindow.h rename to Windows/paintwindow.h index a70761f..d21d04e 100644 --- a/Paint/PaintWindow.h +++ b/Windows/paintwindow.h @@ -3,15 +3,15 @@ #include #include -#include "Base/WindowBase.h" -#include "Paint/Widgets/PaintArea.h" +#include "../Base/WindowBase.h" +#include "../GraphicsScene/paintarea.h" #include #include #include -#include "Paint/Widgets/Panels/paint_setting_panel.h" #include #include #include +#include "../GraphicsScene/Widgets/defaulttoolbar.h" //namespace Ui { //class PaintWindow; @@ -25,7 +25,6 @@ class PaintWindow : public WindowBase { Q_INVOKABLE explicit PaintWindow(QWidget *parent = nullptr); ~PaintWindow(); void set_menubar(); - void set_toolbar(); void loadKeyEvent(QString name) override; void reset(); void onWindowCancel() override; @@ -39,26 +38,15 @@ class PaintWindow : public WindowBase { * @param data2 rect: 图像的大小 */ void receiveData(QVariant data1 =QVariant(), QVariant data2 =QVariant()) override; -public slots: -// void append_layer(); -// void remove_layer(int index); -// void layer_rename(int index, QString after_name); -// void change_layer_position(int before_index, int after_index); -// QStringList get_layer_name(); - void showSettingPanel(); + private: -// Ui::PaintWindow *ui; + // Ui::PaintWindow *ui; QWidget* centralWidget; - QToolBar* toolbar; + DefaultToolbar* toolbar; PaintArea* area; QGraphicsView* paint_panel; QHBoxLayout* layout; - QToolButton* pencil_button; - QMenuBar* menu_bar; - QToolButton* cursor_button; - QCursor pen_cursor; - QButtonGroup* paint_button_group; - void initSettingPanel(); + QMenuBar* menuBar; }; #endif // PAINT_WINDOW_H diff --git a/Windows/pinwindow.h b/Windows/pinwindow.h index 64a727e..3ecefcd 100644 --- a/Windows/pinwindow.h +++ b/Windows/pinwindow.h @@ -1,6 +1,6 @@ #ifndef PINWINDOW_H #define PINWINDOW_H -#include "Base/WindowBase.h" +#include "../Base/WindowBase.h" #include "Widgets/pinwidget.h" class PinWindow : public WindowBase diff --git a/Windows/scrollerwindow.cpp b/Windows/scrollerwindow.cpp index bdc7aef..b73174a 100644 --- a/Windows/scrollerwindow.cpp +++ b/Windows/scrollerwindow.cpp @@ -1,14 +1,14 @@ #include "scrollerwindow.h" -#include "Helper/imagehelper.h" +#include "../Helper/imagehelper.h" #include #include -#include "Manager/WindowManager.h" +#include "../Manager/WindowManager.h" #include "hook.h" -#include "new_capture/window_fliter.h" -#include "Helper/math.h" +#include "windowfilter.h" +#include "../Helper/math.h" #include -#include "Manager/KeyManager.h" -#include "Manager/config.h" +#include "../Manager/KeyManager.h" +#include "../Manager/config.h" ScrollerWindow::ScrollerWindow(QWidget* parent) : WindowBase(parent), scrollState(IDLE), beforeState(IDLE), diff --git a/Windows/scrollerwindow.h b/Windows/scrollerwindow.h index e06a40a..cb0fa1f 100644 --- a/Windows/scrollerwindow.h +++ b/Windows/scrollerwindow.h @@ -1,9 +1,9 @@ #ifndef ScrollerWindow_H #define ScrollerWindow_H -#include "Base/WindowBase.h" -#include "Style_widget/bubbletipswidget.h" -#include "new_capture/Widgets/Scroll_handler/scroll_dispatcher.h" -#include "Style_widget/fadelabel.h" +#include "../Base/WindowBase.h" +#include "../Style_widget/bubbletipswidget.h" +#include "ScrollHandler/scroll_dispatcher.h" +#include "../Style_widget/fadelabel.h" class ScrollerWindow : public WindowBase { diff --git a/new_capture/Window_fliter.cpp b/Windows/windowfilter.cpp similarity index 88% rename from new_capture/Window_fliter.cpp rename to Windows/windowfilter.cpp index cc16447..ada2c05 100644 --- a/new_capture/Window_fliter.cpp +++ b/Windows/windowfilter.cpp @@ -1,4 +1,4 @@ -#include "window_fliter.h" +#include "windowfilter.h" HWND Window_fliter::m_hWndTarget = NULL; QVector Window_fliter::m_arSnapshot = QVector(); diff --git a/Windows/windowfilter.h b/Windows/windowfilter.h new file mode 100644 index 0000000..c47eb72 --- /dev/null +++ b/Windows/windowfilter.h @@ -0,0 +1,320 @@ +#ifndef WINDOW_FLITER_H +#define WINDOW_FLITER_H +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +class CSCWinInfo +{ +public: + HWND m_hWnd; + QRect m_rtWin; //window rect + + INT m_nLevel; // 1 - pop up window ; 2N - child window +}; + +class Window_fliter +{ +public: + static Window_fliter* instance() + { + if(_instance == NULL) + { + _instance = new Window_fliter(); + } + return _instance; + } + static BOOL IsFilterWindow(HWND hWnd) + { + DWORD dwProcessID = GetCurrentProcessId(); + if(hWnd != NULL && IsWindow(hWnd)) + { + DWORD dwWinProcessId(0); + GetWindowThreadProcessId(hWnd, &dwWinProcessId); + if(dwProcessID == dwWinProcessId) + { + return TRUE; + } + } + + return FALSE; + } + + static DWORD GetIncludeStyle() + { + return WS_VISIBLE; + } + + static DWORD GetExcludeStyleEx() + { + return WS_EX_TRANSPARENT; + } + + static BOOL IsTargetPopupWindow() + { + return FALSE; + } + BOOL SnapshotAllWinRect() + { + ClearData(); + // cache current window Z order when call this function + EnumWindows(EnumWindowsSnapshotProc, 1); + + return TRUE; + } + + //get from current Z order of desktop + HWND GetHWNDByPoint(QPoint pt) + { + m_hWndTarget = NULL; + + EnumWindows(EnumWindowsRealTimeProc, MAKELPARAM(pt.x(), pt.y())); + + return m_hWndTarget; + } + + QRect GetWinRectByPoint(QPoint ptHit, BOOL bGetInRealTime = FALSE) + { + QRect rtRect(0, 0, 0, 0); + if(bGetInRealTime) //get from current Z order + { + HWND hWndTarget = GetHWNDByPoint(ptHit); + if(hWndTarget != NULL ) + { + RECT rect; + GetWindowRect(hWndTarget, &rect); + rtRect.setTopLeft(QPoint(rect.left, rect.top)); + rtRect.setBottomRight(QPoint(rect.right, rect.bottom)); + } + } + else //get from snapshot cache + { + GetRectByPointFromSnapshot(ptHit, rtRect); + } + + return rtRect; + } + + static bool enableStyle(DWORD style, DWORD exstyle) + { + return (style & WS_VSCROLL) || (exstyle & WS_EX_RIGHTSCROLLBAR) + || (exstyle & WS_EX_LEFTSCROLLBAR); + } + + static bool disableStyle(DWORD style, DWORD exstyle) + { + return (style & WS_DISABLED) || (exstyle & WS_EX_TRANSPARENT) + || (exstyle & WS_EX_NOACTIVATE); + } + + static HWND find_scroll_window(HWND hwnd, QPoint point) + { + scroll_hwnd = NULL; + DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE); + DWORD ex_style = GetWindowLong(hwnd, GWL_EXSTYLE); + qDebug() << hwnd << dwStyle << ex_style; + if(enableStyle(dwStyle, ex_style) && !disableStyle(dwStyle, ex_style)) + { + return hwnd; + } + EnumChildWindows(hwnd, EnumScrollWindowProc, MAKELPARAM(point.x(), point.y())); + return scroll_hwnd; + } + +protected: + static HWND scroll_hwnd; + static BOOL CALLBACK EnumScrollWindowProc(HWND hwnd, LPARAM lParam) + { + DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE); + DWORD ex_style = GetWindowLong(hwnd, GWL_EXSTYLE); + if(!(enableStyle(dwStyle, ex_style) && !disableStyle(dwStyle, ex_style))) + { + EnumChildWindows(hwnd, EnumScrollWindowProc, lParam); + } + else + { + POINT point; + point.x = lParam & 0xffff; + point.y = lParam >> 16; + RECT rect; + GetClientRect(hwnd, &rect); + if(PtInRect(&rect, point)) + { + scroll_hwnd = hwnd; + } + } + return TRUE; + } + + static BOOL CALLBACK EnumWindowsRealTimeProc(HWND hwnd, LPARAM lParam) + { + if(!PtInWinRect(hwnd, QPoint((lParam & 0xffff), (lParam >> 16)))) return TRUE; + + if(ShouldWinBeFiltered(hwnd)) return TRUE; + + m_hWndTarget = hwnd; + + if(IsTargetPopupWindow()) return FALSE; //this is the target window, exit search + + EnumChildWindows(hwnd, EnumChildRealTimeProc, lParam); + + return FALSE; + } + + static BOOL CALLBACK EnumChildRealTimeProc(HWND hwnd, LPARAM lParam) + { + if(!PtInWinRect(hwnd, QPoint((lParam & 0xffff), (lParam >> 16)))) return TRUE; + + if(ShouldWinBeFiltered(hwnd)) return TRUE; + + m_hWndTarget = hwnd; + EnumChildWindows(hwnd, EnumChildRealTimeProc, lParam); + + return FALSE; + } + +protected: + static BOOL CALLBACK EnumWindowsSnapshotProc(HWND hwnd, LPARAM lParam) + { + INT nLevel = lParam; + if(ShouldWinBeFiltered(hwnd)) return TRUE; + + SaveSnapshotWindow(hwnd, nLevel); + + if(!IsTargetPopupWindow()) + { + ++nLevel; + EnumChildWindows(hwnd, EnumChildSnapshotProc, nLevel); + } + + return TRUE; + } + + static BOOL CALLBACK EnumChildSnapshotProc(HWND hwnd, LPARAM lParam) + { + INT nLevel = lParam; + if(ShouldWinBeFiltered(hwnd)) return TRUE; + SaveSnapshotWindow(hwnd, nLevel); + ++nLevel; + EnumChildWindows(hwnd, EnumChildSnapshotProc, nLevel); + + return TRUE; + } + +protected: + static BOOL PtInWinRect(HWND hWnd, QPoint pt) + { + RECT rect1; + GetWindowRect(hWnd, &rect1); + POINT point; + point.x = pt.x(); + point.y = pt.y(); + return PtInRect(&rect1, point); + } + + static BOOL ShouldWinBeFiltered(HWND hWnd) + { + if(IsFilterWindow(hWnd)) return TRUE; + + DWORD dwStyle = GetWindowLong(hWnd, GWL_STYLE); + DWORD dwStyleMust = GetIncludeStyle(); + if((dwStyle & dwStyleMust) != dwStyleMust) return TRUE; + + DWORD dwStyleEx = GetWindowLong(hWnd, GWL_EXSTYLE); + DWORD dwStyleMustNot = GetExcludeStyleEx(); + if((dwStyleMustNot & dwStyleEx) != 0) return TRUE; + + return FALSE; + } + + //find the first window that level is biggest + static BOOL GetRectByPointFromSnapshot(QPoint ptHit, QRect& rtRet) + { + int nCount = m_arSnapshot.size(); + CSCWinInfo* pInfo = NULL; + CSCWinInfo* pTarget = NULL; + for(int i=0; im_nLevel <= pTarget->m_nLevel) + { + break; + } + POINT point; + point.x = ptHit.x(); + point.y = ptHit.y(); + RECT rect; + rect.top = pInfo->m_rtWin.top();rect.left = pInfo->m_rtWin.left(); + rect.right = pInfo->m_rtWin.right(); rect.bottom = pInfo->m_rtWin.bottom(); + if(PtInRect(&rect, point)) + { + if(pTarget == NULL) + { + pTarget = pInfo; + } + else + { + if( pInfo->m_nLevel > pTarget->m_nLevel) + { + pTarget = pInfo; + } + } + } + } + + if(pTarget != NULL) + { + rtRet = pTarget->m_rtWin; + return TRUE; + } + + return FALSE; + } + + static VOID SaveSnapshotWindow(HWND hwnd, INT nLevel) + { + RECT rect2; + POINT point2; + point2.x = 0;point2.y = 0; + GetClientRect(hwnd, &rect2); + ClientToScreen(hwnd, &point2); + QRect rtWin = QRect(QPoint(point2.x, point2.y), QSize(rect2.right, rect2.bottom)); + if(rtWin.isEmpty()) return; + + CSCWinInfo* pInfo = new CSCWinInfo(); + if(pInfo == NULL) return; + + pInfo->m_hWnd = hwnd; + pInfo->m_nLevel = nLevel; + pInfo->m_rtWin = rtWin; + m_arSnapshot.push_back(pInfo); + } + + static VOID ClearData() + { + int nCount = m_arSnapshot.size(); + for(int i=0; i m_arSnapshot; +}; + + + +#endif // WINDOW_FLITER_H diff --git a/capture.pro b/capture.pro index 2f02f5d..7724abb 100644 --- a/capture.pro +++ b/capture.pro @@ -63,37 +63,9 @@ SOURCES += \ Manager/KeyManager.cpp \ Manager/WindowManager.cpp \ Manager/config.cpp \ + Manager/history.cpp \ Manager/uimanager.cpp \ Manager/update.cpp \ - Paint/Data/fontdata.cpp \ - Paint/Data/scroll_button.cpp \ - Paint/Data/stretch_button.cpp \ - Paint/PaintWindow.cpp \ - Paint/Widgets/Layer_list/list_item.cpp \ - Paint/Widgets/Layer_list/list_widget.cpp \ - Paint/Widgets/Layers/LayerItems/expandbutton.cpp \ - Paint/Widgets/Layers/LayerItems/paintitem.cpp \ - Paint/Widgets/Layers/LayerItems/picitem.cpp \ - Paint/Widgets/Layers/LayerItems/scrollitem.cpp \ - Paint/Widgets/Layers/arrowlayer.cpp \ - Paint/Widgets/Layers/blurlayer.cpp \ - Paint/Widgets/Layers/paintlayer.cpp \ - Paint/Widgets/Layers/picture_layer.cpp \ - Paint/Widgets/Layers/rect_layer.cpp \ - Paint/Widgets/Layers/shapelayer.cpp \ - Paint/Widgets/Layers/text_layer.cpp \ - Paint/Widgets/PaintArea.cpp \ - Paint/Widgets/Panels/close_dialog.cpp \ - Paint/Widgets/Panels/color_selector.cpp \ - Paint/Widgets/Panels/flow_edit_panel.cpp \ - Paint/Widgets/Panels/paint_setting_panel.cpp \ - Paint/Widgets/Recorder_element/paint_record.cpp \ - Paint/Widgets/Recorder_element/paintdeleterecord.cpp \ - Paint/Widgets/Recorder_element/resize_record.cpp \ - Paint/Widgets/Recorder_element/shaperecord.cpp \ - Paint/Widgets/history.cpp \ - Paint/Widgets/recorder.cpp \ - Paint/Widgets/style_manager.cpp \ Setting/Widgets/BoolOption.cpp \ Setting/Widgets/ComboOption.cpp \ Setting/Widgets/GlobalKeyOption.cpp \ @@ -114,25 +86,18 @@ SOURCES += \ Tests/configtest.cpp \ Tests/testwidget.cpp \ Windows/Widgets/pinwidget.cpp \ + Windows/Widgets/videocapture.cpp \ + Windows/capturewindow.cpp \ + Windows/paintwindow.cpp \ Windows/pinwindow.cpp \ Windows/scrollerwindow.cpp \ + Windows/windowfilter.cpp \ main.cpp \ - new_capture/CaptureWindow.cpp \ - new_capture/Widgets/Scroll_handler/Scroll_handle_global.cpp \ - new_capture/Widgets/Scroll_handler/dispatcher_worker.cpp \ - new_capture/Widgets/Scroll_handler/scroll_dispatcher.cpp \ - new_capture/Widgets/Scroll_handler/scroll_handle.cpp \ - new_capture/Widgets/Scroll_handler/scroll_worker.cpp \ - new_capture/Widgets/VideoHandler/videocapture.cpp \ - new_capture/Widgets/attributetoolbar.cpp \ - new_capture/Widgets/capturetip.cpp \ - new_capture/Widgets/cliplayer.cpp \ - new_capture/Widgets/clipregion.cpp \ - new_capture/Widgets/colorpicker.cpp \ - new_capture/Widgets/masklayer.cpp \ - new_capture/Widgets/mosicsample.cpp \ - new_capture/Widgets/videotoolbar.cpp \ - new_capture/Window_fliter.cpp + Windows/ScrollHandler/Scroll_handle_global.cpp \ + Windows/ScrollHandler/dispatcher_worker.cpp \ + Windows/ScrollHandler/scroll_dispatcher.cpp \ + Windows/ScrollHandler/scroll_handle.cpp \ + Windows/ScrollHandler/scroll_worker.cpp HEADERS += \ Base/MPool.h \ @@ -199,42 +164,9 @@ HEADERS += \ Manager/KeyManager.h \ Manager/WindowManager.h \ Manager/config.h \ + Manager/history.h \ Manager/uimanager.h \ Manager/update.h \ - Paint/Data/Common.h \ - Paint/Data/History_data.h \ - Paint/Data/Ilayer.h \ - Paint/Data/fontdata.h \ - Paint/Data/paint_data.h \ - Paint/Data/scroll_button.h \ - Paint/Data/stretch_button.h \ - Paint/PaintWindow.h \ - Paint/Widgets/Layer_list/list_item.h \ - Paint/Widgets/Layer_list/list_widget.h \ - Paint/Widgets/Layers/LayerItems/expandbutton.h \ - Paint/Widgets/Layers/LayerItems/paintitem.h \ - Paint/Widgets/Layers/LayerItems/picitem.h \ - Paint/Widgets/Layers/LayerItems/scrollitem.h \ - Paint/Widgets/Layers/arrowlayer.h \ - Paint/Widgets/Layers/baselayer.h \ - Paint/Widgets/Layers/blurlayer.h \ - Paint/Widgets/Layers/paintlayer.h \ - Paint/Widgets/Layers/picture_layer.h \ - Paint/Widgets/Layers/rect_layer.h \ - Paint/Widgets/Layers/shapelayer.h \ - Paint/Widgets/Layers/text_layer.h \ - Paint/Widgets/Panels/close_dialog.h \ - Paint/Widgets/Panels/color_selector.h \ - Paint/Widgets/Panels/flow_edit_panel.h \ - Paint/Widgets/Panels/paint_setting_panel.h \ - Paint/Widgets/Recorder_element/paint_record.h \ - Paint/Widgets/Recorder_element/paintdeleterecord.h \ - Paint/Widgets/Recorder_element/resize_record.h \ - Paint/Widgets/Recorder_element/shaperecord.h \ - Paint/Widgets/history.h \ - Paint/Widgets/PaintArea.h \ - Paint/Widgets/recorder.h \ - Paint/Widgets/style_manager.h \ Setting/Widgets/BoolOption.h \ Setting/Widgets/ComboOption.h \ Setting/Widgets/GlobalKeyOption.h \ @@ -256,24 +188,17 @@ HEADERS += \ Tests/configtest.h \ Tests/testwidget.h \ Windows/Widgets/pinwidget.h \ + Windows/Widgets/videocapture.h \ + Windows/capturewindow.h \ + Windows/paintwindow.h \ Windows/pinwindow.h \ Windows/scrollerwindow.h \ - new_capture/CaptureWindow.h \ - new_capture/Widgets/Scroll_handler/Scroll_handler_global.h \ - new_capture/Widgets/Scroll_handler/dispatcher_worker.h \ - new_capture/Widgets/Scroll_handler/scroll_dispatcher.h \ - new_capture/Widgets/Scroll_handler/scroll_handle.h \ - new_capture/Widgets/Scroll_handler/scroll_worker.h \ - new_capture/Widgets/VideoHandler/videocapture.h \ - new_capture/Widgets/attributetoolbar.h \ - new_capture/Widgets/capturetip.h \ - new_capture/Widgets/cliplayer.h \ - new_capture/Widgets/clipregion.h \ - new_capture/Widgets/colorpicker.h \ - new_capture/Widgets/masklayer.h \ - new_capture/Widgets/mosicsample.h \ - new_capture/Widgets/videotoolbar.h \ - new_capture/window_fliter.h + Windows/windowfilter.h \ + Windows/ScrollHandler/Scroll_handler_global.h \ + Windows/ScrollHandler/dispatcher_worker.h \ + Windows/ScrollHandler/scroll_dispatcher.h \ + Windows/ScrollHandler/scroll_handle.h \ + Windows/ScrollHandler/scroll_worker.h FORMS += \ Setting/setting.ui \ diff --git a/main.cpp b/main.cpp index c6c932e..08f0ec9 100644 --- a/main.cpp +++ b/main.cpp @@ -1,32 +1,23 @@ #include "Setting/setting.h" -#include "new_capture/CaptureWindow.h" +#include "Windows/capturewindow.h" #include "Manager/WindowManager.h" #include #include #include "Manager/config.h" #include "Manager/KeyManager.h" -#include "Paint/PaintWindow.h" +#include "Windows/paintwindow.h" #include "JlCompress.h" #include "Manager/update.h" #include "Style_widget/tray.h" #include #include "MainFilter.h" -#include "Paint/Widgets/history.h" +#include "Manager/history.h" #include #include "Helper/debug.h" -#include "Paint/Widgets/Layers/rect_layer.h" -#include "Paint/Widgets/Layers/text_layer.h" -#include "Paint/Widgets/Layers/picture_layer.h" -#include "Paint/Widgets/Layers/paintlayer.h" -#include "Paint/Widgets/Layers/shapelayer.h" -#include "Paint/Widgets/Layers/blurlayer.h" -#include "Paint/Widgets/Layers/arrowlayer.h" -#include "new_capture/Widgets/cliplayer.h" #include "Helper/log.h" #include #include "Manager/uimanager.h" -#include "Paint/Widgets/Panels/flow_edit_panel.h" #include "Windows/scrollerwindow.h" #include "Windows/pinwindow.h" #ifndef QT_DEBUG @@ -72,7 +63,6 @@ int main(int argc, char *argv[]) { Update::instance()->onFinish(); fliter->deleteLater(); }); - Flow_edit_panel::instance();// 初始化时间过长,提前初始化一次 qInfo() << "程序启动"; int ans = a.exec(); return ans; @@ -86,14 +76,6 @@ void registerClasses() { Reflect::registerClass(); Reflect::registerClass(); Reflect::registerClass(); - Reflect::registerClass(); - Reflect::registerClass(); - Reflect::registerClass(); - Reflect::registerClass< PaintLayer>(); - Reflect::registerClass(); - Reflect::registerClass(); - Reflect::registerClass(); - Reflect::registerClass(); } void setupDebug(){ diff --git a/new_capture/Widgets/attributetoolbar.cpp b/new_capture/Widgets/attributetoolbar.cpp deleted file mode 100644 index c421c1c..0000000 --- a/new_capture/Widgets/attributetoolbar.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "attributetoolbar.h" -#include -#include - -AttributeToolbar::AttributeToolbar(QWidget* parent) : QWidget(parent) { - setAttribute(Qt::WA_StyledBackground); - layout = new QHBoxLayout(); - layout->setSpacing(3); - layout->setContentsMargins(3, 2, 3, 2); - setLayout(layout); -} - -void AttributeToolbar::add(QWidget *widget) { - widget->show(); - widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - layout->addWidget(widget); - adjustSize(); -// actions.append(QToolBar::addWidget(widget)); -} - -void AttributeToolbar::removeAll() { - QLayoutItem *child; - while ((child = layout->takeAt(0)) != nullptr) { - if(child->widget()) { - layout->removeWidget(child->widget()); - child->widget()->hide(); - } - } - update(); -} - -void AttributeToolbar::paintEvent(QPaintEvent *event) { - QStyleOption opt; - opt.init(this); - QPainter p(this); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); -} diff --git a/new_capture/Widgets/attributetoolbar.h b/new_capture/Widgets/attributetoolbar.h deleted file mode 100644 index d6fa38d..0000000 --- a/new_capture/Widgets/attributetoolbar.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef ATTRIBUTETOOLBAR_H -#define ATTRIBUTETOOLBAR_H -#include -#include -#include - -class AttributeToolbar : public QWidget -{ - Q_OBJECT -public: - AttributeToolbar(QWidget* parent=nullptr); - void add(QWidget* widget); - void paintEvent(QPaintEvent *event) override; - void removeAll(); -private: - QHBoxLayout* layout; -}; - -#endif // ATTRIBUTETOOLBAR_H diff --git a/new_capture/Widgets/capturetip.cpp b/new_capture/Widgets/capturetip.cpp deleted file mode 100644 index ce2ca8a..0000000 --- a/new_capture/Widgets/capturetip.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "capturetip.h" -#include -#include -#include "Helper/imagehelper.h" - -CaptureTip::CaptureTip(QWidget* parent) : QWidget(parent) -{ - QVBoxLayout* layout = new QVBoxLayout(); - QHBoxLayout* rightButtonLayout = new QHBoxLayout(); - QLabel* rightButtonLabel = new QLabel(this); - QLabel* rightButtonIcon = new QLabel(this); - rightButtonIcon->setPixmap(ImageHelper::getPixmap("mouse_right", 16, 16)); - rightButtonLabel->setText("退出截图"); - rightButtonLabel->setIndent(4); - rightButtonLayout->addWidget(rightButtonIcon); - rightButtonLayout->addWidget(rightButtonLabel); - - QHBoxLayout* middleButtonLayout = new QHBoxLayout(); - QLabel* middleButtonIcon = new QLabel(this); - QLabel* middleButtonLabel = new QLabel(this); - middleButtonIcon->setPixmap(ImageHelper::getPixmap("mouse_middle", 16, 16)); - middleButtonLabel->setText("复制截图到剪切板"); - middleButtonLabel->setIndent(4); - middleButtonLayout->addWidget(middleButtonIcon); - middleButtonLayout->addWidget(middleButtonLabel); - - layout->addLayout(rightButtonLayout); - layout->addLayout(middleButtonLayout); - setLayout(layout); -} diff --git a/new_capture/Widgets/capturetip.h b/new_capture/Widgets/capturetip.h deleted file mode 100644 index 7353d9e..0000000 --- a/new_capture/Widgets/capturetip.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef CAPTURETIP_H -#define CAPTURETIP_H -#include - -class CaptureTip : public QWidget -{ -public: - CaptureTip(QWidget* parent=nullptr); -}; - -#endif // CAPTURETIP_H diff --git a/new_capture/Widgets/cliplayer.cpp b/new_capture/Widgets/cliplayer.cpp deleted file mode 100644 index dfff1fb..0000000 --- a/new_capture/Widgets/cliplayer.cpp +++ /dev/null @@ -1,728 +0,0 @@ -#include "cliplayer.h" -#include -#include -#include "Helper/math.h" -#include "Helper/plist.h" -#include -#include -#include "Manager/WindowManager.h" -#include -#include -#include -#include -#include "Paint/Widgets/history.h" -#include "Paint/Widgets/recorder.h" -#include -#include "Paint/Widgets/style_manager.h" -#include "Helper/common.h" -#include -#include -#include "Manager/config.h" -#include "Paint/Widgets/Panels/flow_edit_panel.h" -#include -#include -#include "Scroll_handler/Scroll_handler_global.h" - -ClipLayer::ClipLayer(QWidget* widget_parent, QGraphicsScene* scene, QGraphicsItem* parent) : QGraphicsObject(parent), - is_drag(false), - pixSet(false), - begin_clip(false), - is_save(false), - is_enable(true), - scene(scene), - currentshape(SHAPE_RECT) { - widgetParent = widget_parent; - QRect screenGeometry = ImageHelper::getCurrentGeometry(); - screenGeometry.moveTo(0, 0); - screen_rect = screenGeometry; - mask_layer = new MaskLayer(this); - colorPicker = new ColorPicker(this); - colorPicker->hide(); - connect(mask_layer, &MaskLayer::regionChangeBegin, this, [=](QPointF point){ - colorPicker->show(); - colorPicker->setPosition(point); - }); - connect(mask_layer, &MaskLayer::regionMove, this, [=](QPointF point){ - colorPicker->setPosition(point); - }); - connect(mask_layer, &MaskLayer::regionChanged, this, [=]() { - calBarPos(); - colorPicker->hide(); - }); - this->widget_parent = widget_parent; - rect_setting = UIManager::instance()->getRectData(); - arrowSetting = UIManager::instance()->getArrowData(); - pencil_setting = UIManager::instance()->getPencilData(); - highlighter_setting = UIManager::instance()->getHighlighterData(); -// widgetParent = NULL; - toolbar = NULL; - attribute_toolbar = NULL; - setToolBar(); - setAttributeToolbar(); -// if(widgetParent != NULL) { -// toolbar->setParent(widgetParent); -// attribute_toolbar->setParent(widgetParent); -// } -} - -ClipLayer::~ClipLayer() { - delete toolbar; - delete attribute_toolbar; -} - -QPainterPath ClipLayer::shape() const { - QPainterPath path; - path.addRect(screen_rect); - return path; -} - -QRectF ClipLayer::boundingRect() const { - return screen_rect; -} - -void ClipLayer::mousePressEvent(QGraphicsSceneMouseEvent *event) { - button = event->button(); - if(button == Qt::RightButton) { - if(mask_layer->getRegionCount() == 0) { - WindowManager::changeWindow("tray"); - } else { - emit needReset(); - } - } else if(button == Qt::MidButton) { - switch (Config::getConfig(Config::middle_button_type)) { - case PaintWindow: - emit requestImage(); - break; - case Save2Clip: - emit needClip(); - break; - case Save2File: - emit needSave(); - break; - } - } else { - toolbar->hide(); - attribute_toolbar->hide(); - } -} - -void ClipLayer::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { -} - -void ClipLayer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { -// if(!is_enable) - { - calBarPos(); - } -} - -void ClipLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - if(pixSet) { - if(!is_save) { - painter->drawPixmap(QPointF(0, 0), pix); - } else { - painter->drawPixmap(QPointF(0, 0), savePix); - } - } -} - -void ClipLayer::prepareSave() { - mask_layer->prepareSave(); - is_save = true; - QPainterPath path = mask_layer->getPath(); - QPixmap ans; - QPixmap mask = QPixmap(pix.width(), pix.height()); - mask.fill(Qt::transparent); - QPainter painter(&mask); - painter.fillPath(path, QColor(1, 1, 1)); - savePix = pix; - savePix.setMask(mask.createMaskFromColor(QColor(1, 1, 1), Qt::MaskOutColor)); - qInfo() << "正在截图"; -} - -void ClipLayer::endSave() { - is_save = false; - mask_layer->endSave(); -} - -void ClipLayer::capture(QPixmap pix) { - QPainterPath path; - QPolygonF polygon; - QPixmap ans; - QRect rect; - for(int i=0; igetPolygon(); - path.addPolygon(temp_polygon); - polygon = polygon.united(temp_polygon); - } - QPixmap mask = QPixmap(pix.width(), pix.height()); - mask.fill(Qt::transparent); - QPainter painter(&mask); - painter.fillPath(path, QColor(1, 1, 1)); - pix.setMask(mask.createMaskFromColor(QColor(1, 1, 1), Qt::MaskOutColor)); - rect = path.boundingRect().toRect(); - ans = pix.copy(rect); - rect.moveTo(0, 0); - WindowManager::changeWindow("PaintWindow", ans, rect); -} - -void ClipLayer::setPic(QPixmap pix) { - pixSet = true; - this->pix = pix; - colorPicker->setPic(pix); - update(); -} - -QRectF ClipLayer::getClipRect() { - QRectF ans_rect = mask_layer->getClipRect(); - if(ans_rect.left() < 0) - ans_rect.setLeft(0); - if(ans_rect.top() < 0) - ans_rect.setTop(0); - if(ans_rect.bottom() > screen_rect.bottom()) - ans_rect.setBottom(screen_rect.bottom()); - if(ans_rect.right() > screen_rect.right()) - ans_rect.setRight(screen_rect.right()); - return ans_rect; -} - -void ClipLayer::reset() { - QRect screenGeometry = ImageHelper::getCurrentGeometry(); - screenGeometry.moveTo(0, 0); - screen_rect = screenGeometry; - is_save = false; - buttonEnter(2); - mask_layer->reset(); - if(toolbar != NULL) - toolbar->hide(); - if(attribute_toolbar != NULL) - attribute_toolbar->hide(); - update(); -} - -void ClipLayer::sendRequestImage() { - emit requestImage(); -} - -void ClipLayer::setToolBar() { - toolbar = new QToolBar(widgetParent); - toolbar->setWindowFlags(toolbar->windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); - toolbar->setWindowFlag(Qt::WindowSystemMenuHint, false); - toolbar->hide(); - - ocrButton = new QToolButton(toolbar); - ocrButton->setIcon(ImageHelper::getIcon("ocr")); - ocrButton->setToolTip(MString::search("{SvJhCjRGF0}提取文字")); - connect(ocrButton, &QToolButton::clicked, this, [=]() { - emit requestOcr(); - }); - - save_button = new QToolButton(toolbar); - save_button->setIcon(ImageHelper::getIcon("save")); - save_button->setToolTip(MString::search("{pJqTHhEQdb}保存")); - connect(save_button, &QToolButton::clicked, this, [=]() { - emit needSave(); - }); - - clip_button = new QToolButton(toolbar); - clip_button->setIcon(ImageHelper::getIcon("clipboard")); - clip_button->setToolTip(MString::search("{ntbJbEqxwF}复制到剪切板")); - connect(clip_button, &QToolButton::clicked, this, [=]() { - emit needClip(); - }); - - erase_button = new QToolButton(toolbar); - erase_button->setIcon(ImageHelper::getIcon("eraser")); - erase_button->setToolTip(MString::search("{7cwKObEhcx}擦除")); - erase_button->setCheckable(true); - - videoButton = new QToolButton(toolbar); - videoButton->setIcon(ImageHelper::getIcon("videocam")); - videoButton->setToolTip(MString::search("{UowiwjDUIy}视频")); - videoButton->setCheckable(true); - - ok_button = new QToolButton(toolbar); - ok_button->setIcon(ImageHelper::getIcon("ok")); - connect(ok_button, &QToolButton::clicked, this, [=]() { - emit requestImage(); - }); - - cancel_button = new QToolButton(toolbar); - cancel_button->setIcon(ImageHelper::getIcon("cancel")); - connect(cancel_button, &QToolButton::clicked, this, [=]() { - WindowManager::changeWindow("tray"); - }); - - undo_button = new QToolButton(toolbar); - undo_button->setIcon(ImageHelper::getIcon("undo")); - undo_button->setToolTip(MString::search("{h5KymvIMTN}撤销")); - connect(undo_button, &QPushButton::clicked, this, [=]() { - Recorder::instance()->back(); - }); - - redo_button = new QToolButton(toolbar); - redo_button->setToolTip(MString::search("{a7CaC7NOL5}恢复")); - redo_button->setIcon(ImageHelper::getIcon("redo")); - connect(redo_button, &QPushButton::clicked, this, [=]() { - Recorder::instance()->forward(); - }); - connect(Recorder::instance(), &Recorder::recordChange, this, [=]() { - if(!Recorder::instance()->undoAvaliable()) { - undo_button->setEnabled(false); - } else { - undo_button->setEnabled(true); - } - if(!Recorder::instance()->redoAvaliable()) { - redo_button->setEnabled(false); - } else { - redo_button->setEnabled(true); - } - }); - - pinButton = new QToolButton(toolbar); - pinButton->setToolTip(MString::search("{BNzMH1dcwW}钉住")); - pinButton->setIcon(ImageHelper::getIcon("pin")); - connect(pinButton, &QToolButton::clicked, this, [=](){ - emit needPin(); - }); - - mosaic_button = new QToolButton(toolbar); - mosaic_button->setIcon(ImageHelper::getIcon("mosaic")); - mosaic_button->setToolTip("马赛克"); - mosaic_button->setCheckable(true); - - cursor_button = new QToolButton(toolbar); - cursor_button->setIcon(QIcon(":/image/cursor.png")); - cursor_button->setToolTip(MString::search("{l4yTU9QXUd}指针")); - cursor_button->setCursor(QCursor(QPixmap(":/image/cursor.png"), 0, 0)); - cursor_button->setCheckable(true); - cursor_button->setChecked(true); - - pencil_button = new QToolButton(toolbar); - pencil_button->setIcon(ImageHelper::getIcon("pencil")); - pencil_button->setCheckable(true); - - highlighter_button = new QToolButton(toolbar); - highlighter_button->setToolTip(MString::search("{j54u1kWtCx}荧光笔")); - highlighter_button->setIcon(ImageHelper::getIcon("highlighter")); - highlighter_button->setCheckable(true); - - text_button = new QToolButton(toolbar); - text_button->setToolTip("文本框"); - text_button->setIcon(ImageHelper::getIcon("text")); - text_button->setCheckable(true); - - shape_button = new QToolButton(toolbar); - shape_button->setToolTip(MString::search("{25JzGpOvFt}形状")); - shape_button->setIcon(ImageHelper::getIcon("shape")); - shape_button->setCheckable(true); - - button_group = new QButtonGroup(toolbar); - button_group->setExclusive(true); - button_group->addButton(shape_button, 0); - button_group->addButton(mosaic_button, 1); - button_group->addButton(cursor_button, 2); - button_group->addButton(pencil_button, 3); - button_group->addButton(highlighter_button, 4); - button_group->addButton(text_button, 5); - button_group->addButton(erase_button, 6); - button_group->addButton(videoButton, 7); - connect(button_group, static_cast(&QButtonGroup::buttonClicked) - , this, [=](int id) { - onToolbarButtonClick(id); - }); - - toolbar->addWidget(shape_button); - toolbar->addWidget(mosaic_button); - toolbar->addWidget(cursor_button); - toolbar->addWidget(pencil_button); - toolbar->addWidget(highlighter_button); - toolbar->addWidget(text_button); - toolbar->addWidget(erase_button); - toolbar->addWidget(videoButton); - toolbar->addSeparator(); - toolbar->addWidget(undo_button); - toolbar->addWidget(redo_button); - toolbar->addWidget(ocrButton); - toolbar->addWidget(clip_button); - toolbar->addWidget(save_button); - toolbar->addWidget(pinButton); - toolbar->addWidget(ok_button); - toolbar->addWidget(cancel_button); -} - -void ClipLayer::calBarPos() { - if(!toolbar->isVisible()) - toolbar->show(); - if(!attribute_toolbar->isVisible()) - attribute_toolbar->show(); - - if(button_group->checkedButton() == NULL) { - qDebug() << "ClipLayer::calBarPos checked button NULL"; - return; - } - int bar_height = toolbar->height(); - int bar_width = toolbar->width(); - QRectF mask_bound = mask_layer->getClipRect(); - int left = mask_bound.right() - bar_width; - int top = mask_bound.bottom(); - - int attributeBarWidth = attribute_toolbar->width(); - int attributeBarHeight = attribute_toolbar->height(); - int maxWidth = button_group->checkedButton()->pos().x() + attributeBarWidth > bar_width ? button_group->checkedButton()->pos().x() + attributeBarWidth : bar_width; - if(left + maxWidth > screen_rect.right()) { - left = screen_rect.right() - maxWidth; - } - if(left < 0) { - left = 0; - } - if(top + bar_height + attributeBarHeight > screen_rect.bottom()) { - top = screen_rect.bottom() - bar_height - attributeBarHeight; - } - if(top < 0) { - top = 0; - } - if(left == 0 && top == 0){ - QPoint toolbarPos = toolbar->mapToGlobal(QPoint(left, top)); - left = toolbarPos.x(); - top = toolbarPos.y(); - } - toolbar->move(left, top); - attribute_toolbar->move(left + button_group->checkedButton()->pos().x(), top + bar_height); -} - -void ClipLayer::setEnable(bool enable) { - is_enable = enable; - if(!is_enable) { - calBarPos(); - } - mask_layer->setEnable(enable); -} - -void ClipLayer::updateAttributeToolbar(int id) { - switch(before_id) { - case 0: // shape - switch(currentshape) { - case SHAPE_RECT: - rect_setting.color = Style_manager::instance()->get_now().color; - rect_setting.width = Style_manager::instance()->get_now().width; - break; - case SHAPE_ARROW: - arrowSetting.color = Style_manager::instance()->get_now().color; - arrowSetting.width = Style_manager::instance()->get_now().width; - break; - } - break; - case 1: // mosaic - break; - case 2: // cursor - break; - case 3: // pencil - pencil_setting.color = Style_manager::instance()->get_now().color; - pencil_setting.width = Style_manager::instance()->get_now().width; - break; - case 4: // highlighter - highlighter_setting.color = Style_manager::instance()->get_now().color; - highlighter_setting.width = Style_manager::instance()->get_now().width; - break; - } - attribute_toolbar->removeAll(); - initAttributeToolbarWidget(id); - switch(id) { - case 0: // shape - switch(currentshape) { - case SHAPE_RECT: - color_widget->setCurrentStyle(rect_setting.color); - Style_manager::instance()->change_color(rect_setting.color); - Style_manager::instance()->change_width(rect_setting.width); - width_button->setValue(rect_setting.width); - break; - case SHAPE_ARROW: - color_widget->setCurrentStyle(arrowSetting.color); - Style_manager::instance()->change_color(arrowSetting.color); - Style_manager::instance()->change_width(arrowSetting.width); - width_button->setValue(arrowSetting.width); - break; - } - attribute_toolbar->add(rect_button); - attribute_toolbar->add(arrow_button); - attribute_toolbar->add(width_button); - attribute_toolbar->add(color_widget); - break; - case 1: // mosaic - attribute_toolbar->add(mosaic_sample); - attribute_toolbar->add(mosaic_size); - attribute_toolbar->add(mosaic_range); - break; - case 2: // cursor - attribute_toolbar->add(rect_capture); - attribute_toolbar->add(free_capture); - break; - case 3: - color_widget->setCurrentStyle(pencil_setting.color); - Style_manager::instance()->change_color(pencil_setting.color); - Style_manager::instance()->change_width(pencil_setting.width); - width_button->setValue(pencil_setting.width); - attribute_toolbar->add(width_button); - attribute_toolbar->add(color_widget); - break; - case 4: - color_widget->setCurrentStyle(highlighter_setting.color); - Style_manager::instance()->change_color(highlighter_setting.color); - Style_manager::instance()->change_width(highlighter_setting.width); - width_button->setValue(highlighter_setting.width); - attribute_toolbar->add(width_button); - attribute_toolbar->add(color_widget); - break; - case 5: - attribute_toolbar->add(Flow_edit_panel::instance()); - break; - case 7: - attribute_toolbar->add(videoToolbar); - break; - } - calBarPos(); -} - -void ClipLayer::initAttributeToolbarWidget(int id) { - switch(id) { - case 0: - if(shapeGroup == NULL) { - shapeGroup = new QButtonGroup(attribute_toolbar); - shapeGroup->setExclusive(true); - connect(shapeGroup, static_cast(&QButtonGroup::buttonClicked) - , this, [=](int id) { - switch(id) { - case 0: - currentshape = SHAPE_RECT; - break; - case 1: - currentshape = SHAPE_ARROW; - break; - } - onToolbarButtonClick(0); - }); - } - if(rect_button == NULL) { - rect_button = new QToolButton(attribute_toolbar); - rect_button->setObjectName("rectButton"); - rect_button->setToolTip("矩形"); - rect_button->setIcon(ImageHelper::getIcon("rect")); - rect_button->setCheckable(true); - rect_button->setChecked(true); - rect_button->hide(); - shapeGroup->addButton(rect_button, 0); - } - if(arrow_button == NULL) { - arrow_button = new QToolButton(attribute_toolbar); - arrow_button->setObjectName("arrowButton"); - arrow_button->setIcon(ImageHelper::getIcon("paint_arrow")); - arrow_button->setToolTip("{D7HSBXWTLj}箭头"); - arrow_button->setCheckable(true); - arrow_button->hide(); - shapeGroup->addButton(arrow_button, 1); - } - if(color_widget == NULL) { - color_widget = new ColorWidget(attribute_toolbar); - color_widget->hide(); - } - if(width_button == NULL) { - width_button = new QSpinBox(attribute_toolbar); - width_button->setRange(1, 50); - width_button->setValue(3); - width_button->setAccelerated(true); - width_button->setWrapping(true); - width_button->setKeyboardTracking(true); - connect(width_button, static_cast(&QSpinBox::valueChanged), this, [=](int value) { - Style_manager::instance()->change_width(value); - }); - width_button->hide(); - } - break; - case 3: - case 4: - if(color_widget == NULL) { - color_widget = new ColorWidget(attribute_toolbar); - color_widget->hide(); - } - if(width_button == NULL) { - width_button = new QSpinBox(attribute_toolbar); - width_button->setRange(1, 50); - width_button->setValue(3); - width_button->setAccelerated(true); - width_button->setWrapping(true); - width_button->setKeyboardTracking(true); - connect(width_button, static_cast(&QSpinBox::valueChanged), this, [=](int value) { - Style_manager::instance()->change_width(value); - }); - width_button->hide(); - } - break; - case 1: - if(mosaic_sample == NULL) { - mosaic_sample = new MosicSample(attribute_toolbar); - mosaic_size = new QSpinBox(attribute_toolbar); - mosaic_size->setRange(4, 20); - mosaic_size->setValue(4); - mosaic_size->setSingleStep(4); - mosaic_size->setAccelerated(true); - mosaic_size->setWrapping(true); - mosaic_size->setKeyboardTracking(true); - connect(mosaic_size, static_cast(&QSpinBox::valueChanged), this, [=](int value) { - mosaic_sample->setUnitSize(value); - emit mosaicChange(false, value); - }); - mosaic_range = new QSlider(attribute_toolbar); - mosaic_range->setValue(12); - mosaic_range->setMinimum(4); - mosaic_range->setMaximum(48); - mosaic_range->setSingleStep(4); - mosaic_range->setOrientation(Qt::Horizontal); - mosaic_range->setToolTip("12"); - connect(mosaic_range, &QSlider::valueChanged, this, [=]() { - emit mosaicChange(true, mosaic_range->value()); - mosaic_size->setMaximum(mosaic_range->value()); - mosaic_range->setToolTip(QString::number(mosaic_range->value())); - }); - mosaic_sample->hide(); - mosaic_size->hide(); - mosaic_range->hide(); - } - break; - case 2: - if(rect_capture == NULL) { - QButtonGroup* mode_group = new QButtonGroup(attribute_toolbar); - mode_group->setExclusive(true); - - rect_capture = new QToolButton(attribute_toolbar); - rect_capture->setIcon(ImageHelper::getIcon("rect")); - rect_capture->setToolTip(MString::search("{OBwjJUhTkh}矩形窗口")); - rect_capture->setChecked(true); - rect_capture->setCheckable(true); - rect_capture->setIconSize(QSize(36, 36)); - free_capture = new QToolButton(attribute_toolbar); - free_capture->setIcon(ImageHelper::getIcon("painterpath")); - free_capture->setIconSize(QSize(36, 36)); - free_capture->setCheckable(true); - mode_group->addButton(rect_capture, 0); - mode_group->addButton(free_capture, 1); - connect(mode_group, static_cast(&QButtonGroup::buttonClicked) - , this, [=](int id) { - if(id == 0) { - Config::setConfig(Config::capture_mode, Config::RECT_CAPTURE); - } else if(id == 1) { - Config::setConfig(Config::capture_mode, Config::FREE_CAPTURE); - } - }); - rect_capture->hide(); - free_capture->hide(); - } - break; - case 5: - if(Flow_edit_panel::instance()->parent() != attribute_toolbar) { - Flow_edit_panel::instance()->setParent(attribute_toolbar); - Flow_edit_panel::instance()->hide(); - } - break; - case 7: // video - if(videoToolbar == NULL) { - videoToolbar = new VideoToolbar(attribute_toolbar); - videoToolbar->hide(); - } - break; - } -} - -void ClipLayer::setAttributeToolbar() { - attribute_toolbar = new AttributeToolbar(widgetParent); - attribute_toolbar->setWindowFlags(toolbar->windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); - attribute_toolbar->setWindowFlag(Qt::WindowSystemMenuHint, false); - - color_widget = NULL; - width_button = NULL; - mosaic_sample = NULL; - mosaic_size = NULL; - mosaic_range = NULL; - rect_capture = NULL; - free_capture = NULL; - rect_button = NULL; - shapeGroup = NULL; - arrow_button = NULL; - videoToolbar = NULL; - - updateAttributeToolbar(2); -} - -void ClipLayer::setWidgetParent(QWidget *parent) { - widgetParent = parent; - if(attribute_toolbar != NULL) { - toolbar->setParent(parent); - attribute_toolbar->setParent(parent); - } -} - -void ClipLayer::buttonEnter(int id) { - button_group->button(id)->setChecked(true); - onToolbarButtonClick(id); -} - -void ClipLayer::onToolbarButtonClick(int id) { - updateAttributeToolbar(id); - switch(id) { - case 0: // shape - switch(currentshape) { - case SHAPE_RECT: - emit stateChange(SHAPE); - emit paintShape(RECTANGLE); - break; - case SHAPE_ARROW: - emit stateChange(SHAPE); - emit paintShape(PAINT_ARROW); - break; - } - break; - case 1: // mosaic - emit stateChange(SHAPE); - emit paintShape(BLUR); - break; - case 2: // cursor - emit stateChange(ARROW); - break; - case 3: // pencil - emit stateChange(PAINT); - break; - case 4: // highlighter - emit stateChange(PAINT); - break; - case 5: // text - emit stateChange(SHAPE); - emit paintShape(TEXT); - break; - case 6: // erase - emit stateChange(ERASE); - break; - } -} - -RecordInfo ClipLayer::getRecordInfo() { - RecordInfo ans; - if(videoToolbar == NULL) { - ans.fps = 20; - ans.channel = 2; - ans.enableAudio = true; - ans.audioDeviceIndex = 0; - ans.recordPath = QDir::cleanPath(History::instance()->getVideoSavePath() + "/" + "新建.mp4"); - } else { - ans = videoToolbar->getRecordInfo(); - } - ans.bound = getClipRect().toRect(); - if((ans.bound.width() & 1) != 0) { - ans.bound.setWidth(ans.bound.width() - 1); - } - if((ans.bound.height() & 1) != 0) { - ans.bound.setHeight(ans.bound.height() -1); - } - ans.outWidth = ans.bound.width(); - ans.outHeight = ans.bound.height(); - return ans; -} diff --git a/new_capture/Widgets/cliplayer.h b/new_capture/Widgets/cliplayer.h deleted file mode 100644 index 29999a1..0000000 --- a/new_capture/Widgets/cliplayer.h +++ /dev/null @@ -1,130 +0,0 @@ -#ifndef CLIPLAYER_H -#define CLIPLAYER_H -#include -#include "Paint/Widgets/Layers/baselayer.h" -#include "clipregion.h" -#include "masklayer.h" -#include -#include "Paint/Widgets/Layers/picture_layer.h" -#include -#include -#include -#include "Style_widget/colorwidget.h" -#include "attributetoolbar.h" -#include "Paint/Data/paint_data.h" -#include "mosicsample.h" -#include -#include -#include "Helper/EnumReflect.h" -#include "videotoolbar.h" -#include "colorpicker.h" - -/** - * @brief 普通截图的核心类,用来控制工具栏展现,截屏区域显示及图片的显示 - */ -class ClipLayer : public QGraphicsObject { - Q_OBJECT -public: - MAKE_ENUM(MiddleButtonType, - PaintWindow, - Save2Clip, - Save2File - ) - ClipLayer(QWidget* widget_parent, QGraphicsScene* scene, QGraphicsItem* parent=nullptr); - ~ClipLayer(); - QRectF boundingRect()const override; - QPainterPath shape()const override; - void mousePressEvent(QGraphicsSceneMouseEvent *event) override; - void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override; - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; - void setEnable(bool enable); - void prepareSave(); - void endSave(); - void capture(QPixmap pix); - void setPic(QPixmap pix); - QRectF getClipRect(); - void reset(); - void sendRequestImage(); - void setWidgetParent(QWidget* parent); - void buttonEnter(int id); - RecordInfo getRecordInfo(); -signals: - void requestImage(); - void needSave(); - void needClip(); - void needPin(); - void paintShape(SHAPE_TYPE type); - void stateChange(PAINT_STATE state); - void mosaicChange(bool is_range, int value); - void needReset(); - void requestOcr(); -private: - enum ShapeType {SHAPE_RECT, SHAPE_ARROW}; - void setToolBar(); - void setAttributeToolbar(); - void calBarPos(); - void updateAttributeToolbar(int id); - void onToolbarButtonClick(int id); - void initAttributeToolbarWidget(int id); - QPolygonF polygon; - QPointF begin_point; - QPointF end_point; - QRect screen_rect; - QWidget* widget_parent; - bool is_drag; - bool pixSet; - bool begin_clip; - bool is_save; - bool is_enable; - int before_id; - Qt::MouseButton button; - int drag_index; - QList regions; - QPixmap pix; - QPixmap savePix; - MaskLayer* mask_layer; - QToolBar* toolbar; - QGraphicsScene* scene; - AttributeToolbar* attribute_toolbar; - QToolButton* ocrButton; - QToolButton* save_button; - QToolButton* clip_button; - QToolButton* erase_button; - QToolButton* videoButton; - QToolButton* ok_button; - QToolButton* cancel_button; - QToolButton* undo_button; - QToolButton* redo_button; - QToolButton* pinButton; - QToolButton* cursor_button; - QToolButton* pencil_button; - QToolButton* highlighter_button; - QToolButton* rect_button; - QToolButton* text_button; - QToolButton* shape_button; - QToolButton* mosaic_button; - QButtonGroup* button_group; - - QSpinBox* width_button; - PaintData rect_setting; - PaintData arrowSetting; - PaintData pencil_setting; - PaintData highlighter_setting; - ColorWidget* color_widget; - MosicSample* mosaic_sample; - QSpinBox* mosaic_size; - QSlider* mosaic_range; - QToolButton* rect_capture; - QToolButton* free_capture; - QToolButton* arrow_button; - QWidget* widgetParent; - VideoToolbar* videoToolbar; - - ShapeType currentshape; - QButtonGroup* shapeGroup; - - ColorPicker* colorPicker; -}; - -#endif // CLIPREGION_H diff --git a/new_capture/Widgets/clipregion.cpp b/new_capture/Widgets/clipregion.cpp deleted file mode 100644 index 4cbd42e..0000000 --- a/new_capture/Widgets/clipregion.cpp +++ /dev/null @@ -1,234 +0,0 @@ -#include "clipregion.h" -#include -#include - -ClipRegion::ClipRegion(QPolygonF polygon, QGraphicsItem* parent) : QGraphicsObject(parent) -{ - this->polygon = polygon; - isButtonHide = false; - is_enable = true; - setFlag(QGraphicsItem::ItemIsMovable); - remapPoint(); -} - -ClipRegion::ClipRegion(QPolygonF polygon, bool isButtonHide, QGraphicsItem* parent) : QGraphicsObject(parent) - , isButtonHide(isButtonHide) - , polygon(polygon) -{ - setFlag(QGraphicsItem::ItemIsMovable); - emit regionChange(); -} - -ClipRegion::~ClipRegion() -{ -} - -QRectF ClipRegion::boundingRect() const -{ - return polygon.united(childrenBoundingRect()).boundingRect(); -} - -QPainterPath ClipRegion::shape() const -{ - QPainterPath path; - path.addPolygon(polygon); - return path; -} - -void ClipRegion::addRect(QRectF rect) -{ - this->polygon = polygon.united(rect); - remapPoint(); -} - -void ClipRegion::addPolygon(QPolygonF polygon) -{ - this->polygon = this->polygon.united(polygon); - remapPoint(); -} - -void ClipRegion::united(QPolygonF polygon) -{ - this->polygon = this->polygon.united(polygon); - remapPoint(); -} - -void ClipRegion::united(ClipRegion* region) -{ - this->polygon = polygon.united(region->polygon); - remapPoint(); -} - -bool ClipRegion::intersect(QRectF rect) -{ - return polygon.intersects(rect); -} - -bool ClipRegion::intersect(QPolygonF polygon) -{ - return this->polygon.intersects(polygon); -} - -void ClipRegion::remapPoint() -{ - if(isButtonHide) - return; - for(int i=buttons.size(); i, qreal, qreal, int, int)>(&ExpandButton::posChange), this, [=](QList index, qreal dx, qreal dy, int x_neigh, int y_neigh){ - for(int i=0; i neigh_index = buttons[x_neigh]->getIndex(); - for(int i=0; igetIndex(); - for(int i=0; isetPosition(buttons[x_neigh]->pos() + QPointF(dx, 0)); - buttons[y_neigh]->setPosition(buttons[y_neigh]->pos() + QPointF(0, dy)); - emit regionMove(polygon[index[0]]); - update(); - }); - connect(button, &ExpandButton::posTo, this, [=](direction dir, qreal x, qreal y){ - emit regionChange(); - }); - buttons.append(button); - } - for(int i=0; ihide(); - buttons[i]->clearIndex(); - } - QList pos_list = polygon.toPolygon().toList(); - int button_num = 0; - for(int i=0; igetPos() == pos_list[i]) - { - buttons[k]->setIndex(i); - success = true; - if(buttons[k]->setNeighbor(buttons[button_num-1]->getPos(), button_num-1)) - { - buttons[button_num-1]->setNeighbor(buttons[k]->getPos(), k); - } - break; - } - } - if(!success) - { - buttons[button_num]->show(); - buttons[button_num]->setIndex(i); - buttons[button_num]->setIntPos(pos_list[i]); - buttons[button_num]->setPosition(polygon[i]); - for(int k=button_num-1; k>=0; k--) - { - if(buttons[button_num]->setNeighbor(buttons[k]->getPos(), k)) - { - buttons[k]->setNeighbor(buttons[button_num]->getPos(), button_num); - break; - } - } - button_num++; - } - } - emit regionChange(); -} - -QPolygonF ClipRegion::getPolygon() -{ - return polygon; -} - -void ClipRegion::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - -} - -bool ClipRegion::contain(QPointF point) -{ - return polygon.contains(point); -} - -void ClipRegion::move(qreal dx, qreal dy) -{ - polygon.translate(dx, dy); - for(int i=0; imoveBy(dx, dy); - } - update(); -} - -void ClipRegion::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - if(!is_enable) - return; - begin_point = event->pos(); -} - -void ClipRegion::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - if(!is_enable) - return; - QPointF delta = event->pos() - begin_point; - begin_point = event->pos(); - move(delta.x(), delta.y()); -} - -void ClipRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - if(!is_enable) - return; - emit regionChange(); -} - -void ClipRegion::hideNormal() -{ - for(ExpandButton* button: buttons) - { - button->hide(); - } - update(); -} - -void ClipRegion::showNormal() -{ - for(ExpandButton* button: buttons) - { - button->show(); - } - update(); -} - -void ClipRegion::hideButton() -{ - isButtonHide = true; - for(ExpandButton* button: buttons) - { - button->hide(); - } - update(); -} - -void ClipRegion::setEnable(bool enable) -{ - is_enable = enable; - if(is_enable) - showNormal(); - else - hideNormal(); -} diff --git a/new_capture/Widgets/clipregion.h b/new_capture/Widgets/clipregion.h deleted file mode 100644 index e78728f..0000000 --- a/new_capture/Widgets/clipregion.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef CLIPREGION_H -#define CLIPREGION_H -#include -#include "Paint/Widgets/Layers/LayerItems/expandbutton.h" -#include "Paint/Widgets/Layers/baselayer.h" - -class ClipRegion : public QGraphicsObject, public BaseLayer -{ - Q_OBJECT -public: - ClipRegion(QPolygonF polygon, QGraphicsItem* parent=nullptr); - ClipRegion(QPolygonF polygon, bool isButtonHide, QGraphicsItem* parent=nullptr); - ~ClipRegion(); - bool intersect(QRectF rect); - bool intersect(QPolygonF polygon); - void addRect(QRectF rect); - void addPolygon(QPolygonF polygon); - void united(QPolygonF polygon); - void united(ClipRegion* region); - bool contain(QPointF point); - void move(qreal dx, qreal dy); - void mousePressEvent(QGraphicsSceneMouseEvent* event)override; - void mouseMoveEvent(QGraphicsSceneMouseEvent* event)override; - void mouseReleaseEvent(QGraphicsSceneMouseEvent* event)override; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; - void hideButton(); - void setEnable(bool enable); - QPolygonF getPolygon(); - QPainterPath shape()const override; - QRectF boundingRect() const override; - Q_INVOKABLE void hideNormal() override; - Q_INVOKABLE void showNormal() override; -signals: - void regionChangeBegin(QPointF point); - void regionChange(); - void regionMove(QPointF point); -private: - void remapPoint(); - bool isButtonHide; - bool is_enable; - QPolygonF polygon; - QList buttons; - QPointF begin_point; -}; - -#endif // CLIPREGION_H diff --git a/new_capture/Widgets/colorpicker.cpp b/new_capture/Widgets/colorpicker.cpp deleted file mode 100644 index 9fa6ec8..0000000 --- a/new_capture/Widgets/colorpicker.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "colorpicker.h" -#include -#include -#include "Helper/PaintHelper.h" - -ColorPicker::ColorPicker(QGraphicsItem* parent) : QGraphicsObject(parent) -{ - screenGeometry = ImageHelper::getCurrentGeometry(); - int widthpx = pt2px(pixelWidthPT); - pixelWidthPX = (widthpx | 0b1) * 5; - int heightpx = pt2px(pixelHeightPT); - pixelHeightPX = (heightpx | 0b1) * 5; -} - -void ColorPicker::setPic(const QPixmap &pix){ - this->image = pix.toImage(); -} - -void ColorPicker::setPosition(QPointF point){ - this->point = point; - if(point.x() + pixelWidthPX + offsetX > screenGeometry.right()){ - bound.setLeft(point.x()- pixelWidthPX - offsetX); - } - else{ - bound.setLeft(point.x() + offsetX); - } - if(point.y() + pixelHeightPX + 20 + offsetY > screenGeometry.bottom()){ - bound.setTop(point.y()- pixelHeightPX - 20 - offsetY); - } - else{ - bound.setTop(point.y() + offsetY); - } - bound.setHeight(pixelHeightPX+20); - bound.setWidth(pixelWidthPX); -} - -QRectF ColorPicker::boundingRect() const{ -// QRectF ans = bound; -// ans.setTopLeft(ans.topLeft() - QPointF(shadowWidth, shadowWidth)); -// ans.setBottomRight(ans.bottomRight() + QPointF(shadowWidth, shadowWidth)); - return bound; -} - -QPainterPath ColorPicker::shape() const{ - QPainterPath path; -// QRectF ans = bound; -// ans.setTopLeft(ans.topLeft() - QPointF(shadowWidth, shadowWidth)); -// ans.setBottomRight(ans.bottomRight() + QPointF(shadowWidth, shadowWidth)); -// path.addRect(ans); - path.addRect(bound); - return path; -} - -void ColorPicker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ - QImage image1 = QImage(pixelWidthPX, pixelHeightPX,QImage::Format_RGB32); - for(int i=0; i=image.width() ? image.width()-1 : i+point.x() - pixelWidthPX/10; - int y = k+point.y()-pixelHeightPX/10 < 0 ? 0 : k+point.y()+pixelHeightPX/10>=image.height() ? image.height()-1 : k+point.y()-pixelHeightPX/10; - image1.setPixel(j, m, image.pixel(x, y)); - } - } - } - } - QImage image2 = QImage(20, 20, QImage::Format_RGB32); - QRgb rgb = image.pixel(point.x(), point.y()); - image2.fill(rgb); - painter->drawImage(bound.left(), bound.top(), image1); - painter->drawImage(bound.left(), bound.top()+pixelHeightPX, image2); - QRect textBound(bound.left()+20, bound.top()+pixelHeightPX, pixelWidthPX-20, 20); - painter->fillRect(textBound, QColor(255, 255, 255)); - painter->drawText(textBound, Qt::AlignCenter, "("+QString::number(qRed(rgb)) + "," + QString::number(qGreen(rgb)) + "," + QString::number(qBlue(rgb)) + ")"); - PaintHelper::paintShadow(painter, bound, shadowWidth, QColor(50, 50, 50, 120)); - painter->setCompositionMode(QPainter::RasterOp_SourceOrNotDestination); - double middlex = (double)(pixelWidthPX) / 2.0; - double middley = (double)(pixelHeightPX) / 2.0; - painter->drawLine(bound.left()+middlex-10, bound.top()+middley, bound.left()+middlex+10, bound.top()+middley); - painter->drawLine(bound.left()+middlex, bound.top()+middley-10, bound.left()+middlex, bound.top()+middley+10); -} diff --git a/new_capture/Widgets/colorpicker.h b/new_capture/Widgets/colorpicker.h deleted file mode 100644 index 16bb1be..0000000 --- a/new_capture/Widgets/colorpicker.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef COLORPICKER_H -#define COLORPICKER_H -#include -#include -#include "Paint/Widgets/Layers/baselayer.h" -#include "Helper/common.h" -#include "Helper/imagehelper.h" - -class ColorPicker : public QGraphicsObject, public BaseLayer -{ -public: - ColorPicker(QGraphicsItem* parent=nullptr); - void setPic(const QPixmap& pix); - void setPosition(QPointF point); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; - QPainterPath shape()const override; - QRectF boundingRect() const override; -private: - QImage image; - QPointF point; - QRect bound; - QRect screenGeometry; - int pixelWidthPX; - int pixelHeightPX; - int shadowWidth = 10; - const int offsetX = 30; - const int offsetY = 20; - const int pixelWidthPT = 15; - const int pixelHeightPT = 10; -}; - -#endif // COLORPICKER_H diff --git a/new_capture/Widgets/masklayer.cpp b/new_capture/Widgets/masklayer.cpp deleted file mode 100644 index 0f28616..0000000 --- a/new_capture/Widgets/masklayer.cpp +++ /dev/null @@ -1,236 +0,0 @@ -#include "masklayer.h" -#include -#include -#include -#include -#include -#include "Manager/WindowManager.h" -#include "Helper/math.h" -#include "Helper/plist.h" -#include "Manager/config.h" -#include "Manager/uimanager.h" -#include "Helper/imagehelper.h" - -MaskLayer::MaskLayer(QGraphicsItem* parent) : QGraphicsObject(parent) { - is_drag = false; - is_save = false; - begin_clip = false; - is_enable = true; - QRect screenGeometry = ImageHelper::getCurrentGeometry(); - screen_rect = QRectF(0, 0, screenGeometry.width(), screenGeometry.height()); - borderData = UIManager::instance()->getBorderData(); - backgroundColor = UIManager::instance()->getCaptureBackground(); -} - -void MaskLayer::reset() { - QRect screenGeometry = ImageHelper::getCurrentGeometry(); - screen_rect = QRectF(0, 0, screenGeometry.width(), screenGeometry.height()); - is_drag = false; - begin_clip = false; - is_save = false; - clearRegion(); - free_capture_path.clear(); -} - -QPainterPath MaskLayer::shape() const { - QPainterPath path; - path.addRect(screen_rect); - return path; -} - -QRectF MaskLayer::boundingRect() const { - return screen_rect; -} - -void MaskLayer::mousePressEvent(QGraphicsSceneMouseEvent *event) { - button = event->button(); - if(button != Qt::LeftButton || !is_enable) - return; - if(Config::getConfig(Config::capture_mode) == Config::FREE_CAPTURE) { - free_capture_path.clear(); - free_capture_path.moveTo(mapFromScene(event->scenePos())); - } - begin_point = mapFromScene(event->scenePos()); - end_point = begin_point; - is_drag = false; - begin_clip = true; - for(int i=0; icontain(begin_point)) { - is_drag = true; - break; - } - } - for(int i=0; icontain(begin_point)) { - is_drag = true; - break; - } - } - if(!is_drag){ - emit regionChangeBegin(begin_point); - } -} - -void MaskLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - if(!is_save) { - QPen pen; - pen.setColor(borderData.color); - pen.setWidth(borderData.width); - painter->setPen(pen); - - QPainterPath origin; - origin.addRect(screen_rect); - QPainterPath path; - path.setFillRule(Qt::WindingFill); - if(!is_drag && begin_clip && button == Qt::LeftButton) { - if(Config::getConfig(Config::capture_mode) == Config::FREE_CAPTURE) { - QPen tmp_pen = pen; - pen.setColor(QColor(41, 141, 255)); - pen.setWidth(3); - painter->setPen(pen); - painter->drawPath(free_capture_path); - pen = tmp_pen; - painter->setPen(pen); - } else - path.addRect(Math::buildRect(begin_point, end_point)); - } - QPolygonF polygon; - for(ClipRegion* region : regions) { - polygon = polygon.united(region->getPolygon()); - } - for(ClipRegion* region : free_regions) { - polygon = polygon.united(region->getPolygon()); - } - path.addPolygon(polygon); - path = path.simplified(); - painter->drawPath(path); - origin = origin.subtracted(path); - painter->fillPath(origin, backgroundColor); - } -} - -void MaskLayer::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if(!is_drag || !is_enable) { - update(); - emit regionMove(mapFromScene(event->scenePos())); - } - if(Config::getConfig(Config::capture_mode) == Config::FREE_CAPTURE) - free_capture_path.lineTo(mapFromScene(event->scenePos())); - else - end_point = mapFromScene(event->scenePos()); - -} - -void MaskLayer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - begin_clip = false; - QRectF new_rect; - if(Config::getConfig(Config::capture_mode) == Config::FREE_CAPTURE) - new_rect = free_capture_path.boundingRect(); - else - new_rect = Math::buildRect(begin_point, mapFromScene(event->scenePos())); - if(new_rect.width() < 10 || new_rect.height() < 10 || is_drag || button != Qt::LeftButton || !is_enable) { - emit regionChanged(); - return; - } - if(Config::getConfig(Config::capture_mode) == Config::FREE_CAPTURE) { - free_capture_path.lineTo(mapFromScene(event->scenePos())); - free_capture_path.closeSubpath(); - free_capture_path = free_capture_path.simplified(); - QList polygons = free_capture_path.toSubpathPolygons(); - - for(QPolygonF polygon : polygons) { - ClipRegion* new_region = new ClipRegion(polygon, true, this); - free_regions.append(new_region); - } - } else { - addRegion(new_rect); - } - update(); - emit regionChanged(); -} - -void MaskLayer::addRegion(QPolygonF polygon) { - PList intersect_path; - auto iter = regions.begin(); - int i=0; - while(iter != regions.end()) { - if(iter.i->t()->intersect(polygon)) { - intersect_path.append(regions.at(i)); - iter = regions.erase(iter); - } else { - i++; - iter++; - } - } - ClipRegion* new_region = new ClipRegion(polygon, this); - for(ClipRegion* region : intersect_path) { - new_region->united(region); - } - intersect_path.clear_all(); - regions.append(new_region); - connect(new_region, &ClipRegion::regionChangeBegin, this, [=](QPointF point){ - emit regionChangeBegin(point); - }); - connect(new_region, &ClipRegion::regionChange, this, [=]() { - emit regionChanged(); - }); - connect(new_region, &ClipRegion::regionMove, this, [=](QPointF point){ - emit regionMove(point); - }); -} - -void MaskLayer::prepareSave() { - for(ClipRegion* region : regions) { - region->hideNormal(); - } - for(ClipRegion* region: free_regions) { - region->hideNormal(); - } - is_save = true; -} - -void MaskLayer::endSave() { - is_save = false; - clearRegion(); -} - -QRectF MaskLayer::getClipRect() { - QPainterPath path = getPath(); - return path.boundingRect(); -} - -void MaskLayer::clearRegion() { - for(ClipRegion* region : regions) { - delete region; - } - for(ClipRegion* region : free_regions) { - delete region; - } - regions.clear(); - free_regions.clear(); -} - -QPainterPath MaskLayer::getPath() { - QPainterPath path; - for(int i=0; igetPolygon(); - path.addPolygon(temp_polygon); - } - for(int i=0; igetPolygon(); - path.addPolygon(temp_polygon); - } - return path; -} - -int MaskLayer::getRegionCount() { - return regions.size() + free_regions.size(); -} - -void MaskLayer::setEnable(bool enable) { - is_enable = enable; - for(ClipRegion* region : regions) - region->setEnable(enable); - for(ClipRegion* region : free_regions) - region->setEnable(enable); -} diff --git a/new_capture/Widgets/masklayer.h b/new_capture/Widgets/masklayer.h deleted file mode 100644 index bf0783e..0000000 --- a/new_capture/Widgets/masklayer.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef MASKLAYER_H -#define MASKLAYER_H -#include -#include -#include "Paint/Widgets/Layers/baselayer.h" -#include "clipregion.h" -#include - -class MaskLayer : public QGraphicsObject, public BaseLayer { - Q_OBJECT -public: - MaskLayer(QGraphicsItem* parent); - QPainterPath shape()const override; - QRectF boundingRect() const override; - void mousePressEvent(QGraphicsSceneMouseEvent *event) override; - void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override; - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; - void setEnable(bool enable); - void prepareSave(); - void endSave(); - void reset(); - void clearRegion(); - int getRegionCount(); - QRectF getClipRect(); - QPainterPath getPath(); -signals: - void regionChangeBegin(QPointF point); - void regionMove(QPointF point); - void regionChanged(); -private: - void addRegion(QPolygonF polygon); - QPainterPath path; - QList regions; - QList free_regions; - QRectF screen_rect; - Qt::MouseButton button; - QPointF begin_point; - QPointF end_point; - bool is_drag; - bool begin_clip; - bool is_save; - bool is_enable; - QPainterPath free_capture_path; - PaintData borderData; - QColor backgroundColor; -}; - -#endif // MASKLAYER_H diff --git a/new_capture/Widgets/mosicsample.cpp b/new_capture/Widgets/mosicsample.cpp deleted file mode 100644 index 99b270f..0000000 --- a/new_capture/Widgets/mosicsample.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "mosicsample.h" -#include -#include - -MosicSample::MosicSample(QWidget* parent) : QWidget(parent) { - image = QImage(42, 42, QImage::Format_ARGB32); - for(int i=0; i<42; i++) { - for(int k=0; k<42; k++) { - quint32 value = QRandomGenerator::global()->generate(); - image.setPixel(i, k, value); - } - } - mask = QImage(42, 42, QImage::Format_ARGB32); - setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); - setMaximumSize(42, 42); - setMinimumSize(42, 42); - unit_size = 5; - reset(); -} - -void MosicSample::paintEvent(QPaintEvent *event) { - QPainter painter(this); - painter.drawImage(QPoint(0, 0), mask); -} - -void MosicSample::reset() { - for(int i=0; i<42; i+=unit_size) { - for(int k=0; k<42; k+=unit_size) { - int red = 0; - int blue = 0; - int green = 0; - int times = 0; - for(int m=i; m<42 && munit_size = unit_size; - reset(); -} - -void MosicSample::setRange(int range) { - -} diff --git a/new_capture/Widgets/mosicsample.h b/new_capture/Widgets/mosicsample.h deleted file mode 100644 index 04e26f7..0000000 --- a/new_capture/Widgets/mosicsample.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef MOSICSAMPLE_H -#define MOSICSAMPLE_H -#include -#include - -class MosicSample : public QWidget -{ -public: - MosicSample(QWidget* parent=nullptr); - void setRange(int range); - void setUnitSize(int unit_size); - void paintEvent(QPaintEvent *event) override; -private: - void reset(); - QImage image; - QImage mask; - int unit_size; -}; - -#endif // MOSICSAMPLE_H diff --git a/new_capture/Widgets/videotoolbar.cpp b/new_capture/Widgets/videotoolbar.cpp deleted file mode 100644 index 608635d..0000000 --- a/new_capture/Widgets/videotoolbar.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#include "videotoolbar.h" -#include -#include -#include -#include -#include -#include -#include "Paint/Widgets/history.h" -#include -#include "windows.h" -#include -#include -#include "Helper/mstring.h" -#include "Helper/imagehelper.h" -#pragma comment(lib, "Winmm.lib") - -VideoToolbar::VideoToolbar(QWidget* parent) : QWidget(parent) -{ - layout = new QHBoxLayout(); - - QRadioButton* enableAudioButton = new QRadioButton(this); - enableAudioButton->setText(MString::search("{rh0LYgOmDD}录制声音")); - enableAudioButton->setChecked(true); - enableAudioButton->setCheckable(true); - info.enableAudio = true; - info.channel = 2; - connect(enableAudioButton, &QRadioButton::clicked, this, [=](bool check){ - info.enableAudio = check; - }); - - QComboBox* deviceSelector = new QComboBox(this); - int nDeviceNum = waveInGetNumDevs(); - for (int i = 0; i < nDeviceNum; ++i) - { - WAVEINCAPS wic; - waveInGetDevCaps(i, &wic, sizeof(wic)); - - //转成utf-8 - int nSize = WideCharToMultiByte(CP_UTF8, 0, wic.szPname, wcslen(wic.szPname), NULL, 0, NULL, NULL); - std::shared_ptr spDeviceName(new char[nSize + 1]); - memset(spDeviceName.get(), 0, nSize + 1); - WideCharToMultiByte(CP_UTF8, 0, wic.szPname, wcslen(wic.szPname), spDeviceName.get(), nSize, NULL, NULL); - deviceSelector->addItem(spDeviceName.get()); - } - info.audioDeviceIndex = 0; - deviceSelector->setMaximumWidth(150); - connect(deviceSelector, static_cast(&QComboBox::currentIndexChanged), this, [=](int index){ - info.audioDeviceIndex = index; - }); - - QLabel* fpsLabel = new QLabel("fps", this); - QSpinBox* fpsSelector = new QSpinBox(this); - fpsSelector->setRange(1, 60); - fpsSelector->setValue(20); - info.fps = 20; - fpsSelector->setAccelerated(true); - fpsSelector->setWrapping(true); // 开启循环 - fpsSelector->setKeyboardTracking(true); - connect(fpsSelector, static_cast(&QSpinBox::valueChanged), this, [=](int index){ - info.fps = index; - }); - - QToolButton* pathChooseButton = new QToolButton(this); - pathChooseButton->setIcon(ImageHelper::getIcon("folder")); - pathChooseButton->setToolTip(History::instance()->getVideoSavePath()); - connect(pathChooseButton, &QToolButton::clicked, this, [=](){ - QString result = QFileDialog::getExistingDirectory(this, MString::search("{nmqfWFejoz}选择保存目录"), History::instance()->getVideoSavePath()); - if(result != ""){ - History::instance()->setVideoSavePath(result); - pathChooseButton->setToolTip(History::instance()->getVideoSavePath()); - } - }); - - QLineEdit* fileNameEdit = new QLineEdit(this); - fileNameEdit->setPlaceholderText(MString::search("{cR3jOHb9Qw}新建")); - name = MString::search("{cR3jOHb9Qw}新建"); - fileNameEdit->setMaxLength(20); - connect(fileNameEdit, &QLineEdit::textChanged, this, [=](QString text){ - name = text; - if(text == ""){ - name = MString::search("{cR3jOHb9Qw}新建"); - } - }); - - QComboBox* suffixSelector = new QComboBox(this); - suffixSelector->addItem("mp4"); - suffixSelector->addItem("gif"); - suffix = "mp4"; - connect(suffixSelector, static_cast(&QComboBox::currentIndexChanged), this, [=](int index){ - if(index == 0){ - suffix = "mp4"; - } - else if(index == 1){ - suffix = "gif"; - } - }); - - QToolButton* helpButton = new QToolButton(this); - helpButton->setIcon(ImageHelper::getIcon("help")); - helpButton->setToolTip(MString::search("{SHLK0bd4wt}开始录屏: F5\n暂停/恢复录屏: F6\n结束录屏: F7")); - - layout->addWidget(enableAudioButton); - layout->addWidget(deviceSelector); - layout->addWidget(fpsLabel); - layout->addWidget(fpsSelector); - layout->addWidget(pathChooseButton); - layout->addWidget(fileNameEdit); - layout->addWidget(suffixSelector); - layout->addWidget(helpButton); - setLayout(layout); -} - -RecordInfo VideoToolbar::getRecordInfo(){ - info.recordPath = QDir::cleanPath(History::instance()->getVideoSavePath() + "/" + name + "." + suffix); - if(suffix == "gif"){ - info.enableAudio = false; - } - return info; -} diff --git a/new_capture/Widgets/videotoolbar.h b/new_capture/Widgets/videotoolbar.h deleted file mode 100644 index deb0869..0000000 --- a/new_capture/Widgets/videotoolbar.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef VIDEOTOOLBAR_H -#define VIDEOTOOLBAR_H -#include -#include -#include "ecvideocapture.h" - -class VideoToolbar : public QWidget -{ -public: - VideoToolbar(QWidget* parent=nullptr); - RecordInfo getRecordInfo(); -private: - QHBoxLayout* layout; - RecordInfo info; - QString name; - QString suffix; -}; - -#endif // VIDEOTOOLBAR_H diff --git a/new_capture/window_fliter.h b/new_capture/window_fliter.h deleted file mode 100644 index d1b4915..0000000 --- a/new_capture/window_fliter.h +++ /dev/null @@ -1,320 +0,0 @@ -#ifndef WINDOW_FLITER_H -#define WINDOW_FLITER_H -#define WIN32_LEAN_AND_MEAN -#include -#include -#include -class CSCWinInfo -{ -public: - HWND m_hWnd; - QRect m_rtWin; //window rect - - INT m_nLevel; // 1 - pop up window ; 2N - child window -}; - -class Window_fliter -{ -public: - static Window_fliter* instance() - { - if(_instance == NULL) - { - _instance = new Window_fliter(); - } - return _instance; - } - static BOOL IsFilterWindow(HWND hWnd) - { - DWORD dwProcessID = GetCurrentProcessId(); - if(hWnd != NULL && IsWindow(hWnd)) - { - DWORD dwWinProcessId(0); - GetWindowThreadProcessId(hWnd, &dwWinProcessId); - if(dwProcessID == dwWinProcessId) - { - return TRUE; - } - } - - return FALSE; - } - - static DWORD GetIncludeStyle() - { - return WS_VISIBLE; - } - - static DWORD GetExcludeStyleEx() - { - return WS_EX_TRANSPARENT; - } - - static BOOL IsTargetPopupWindow() - { - return FALSE; - } - BOOL SnapshotAllWinRect() - { - ClearData(); - // cache current window Z order when call this function - EnumWindows(EnumWindowsSnapshotProc, 1); - - return TRUE; - } - - //get from current Z order of desktop - HWND GetHWNDByPoint(QPoint pt) - { - m_hWndTarget = NULL; - - EnumWindows(EnumWindowsRealTimeProc, MAKELPARAM(pt.x(), pt.y())); - - return m_hWndTarget; - } - - QRect GetWinRectByPoint(QPoint ptHit, BOOL bGetInRealTime = FALSE) - { - QRect rtRect(0, 0, 0, 0); - if(bGetInRealTime) //get from current Z order - { - HWND hWndTarget = GetHWNDByPoint(ptHit); - if(hWndTarget != NULL ) - { - RECT rect; - GetWindowRect(hWndTarget, &rect); - rtRect.setTopLeft(QPoint(rect.left, rect.top)); - rtRect.setBottomRight(QPoint(rect.right, rect.bottom)); - } - } - else //get from snapshot cache - { - GetRectByPointFromSnapshot(ptHit, rtRect); - } - - return rtRect; - } - - static bool enableStyle(DWORD style, DWORD exstyle) - { - return (style & WS_VSCROLL) || (exstyle & WS_EX_RIGHTSCROLLBAR) - || (exstyle & WS_EX_LEFTSCROLLBAR); - } - - static bool disableStyle(DWORD style, DWORD exstyle) - { - return (style & WS_DISABLED) || (exstyle & WS_EX_TRANSPARENT) - || (exstyle & WS_EX_NOACTIVATE); - } - - static HWND find_scroll_window(HWND hwnd, QPoint point) - { - scroll_hwnd = NULL; - DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE); - DWORD ex_style = GetWindowLong(hwnd, GWL_EXSTYLE); - qDebug() << hwnd << dwStyle << ex_style; - if(enableStyle(dwStyle, ex_style) && !disableStyle(dwStyle, ex_style)) - { - return hwnd; - } - EnumChildWindows(hwnd, EnumScrollWindowProc, MAKELPARAM(point.x(), point.y())); - return scroll_hwnd; - } - - protected: - static HWND scroll_hwnd; - static BOOL CALLBACK EnumScrollWindowProc(HWND hwnd, LPARAM lParam) - { - DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE); - DWORD ex_style = GetWindowLong(hwnd, GWL_EXSTYLE); - if(!(enableStyle(dwStyle, ex_style) && !disableStyle(dwStyle, ex_style))) - { - EnumChildWindows(hwnd, EnumScrollWindowProc, lParam); - } - else - { - POINT point; - point.x = lParam & 0xffff; - point.y = lParam >> 16; - RECT rect; - GetClientRect(hwnd, &rect); - if(PtInRect(&rect, point)) - { - scroll_hwnd = hwnd; - } - } - return TRUE; - } - - static BOOL CALLBACK EnumWindowsRealTimeProc(HWND hwnd, LPARAM lParam) - { - if(!PtInWinRect(hwnd, QPoint((lParam & 0xffff), (lParam >> 16)))) return TRUE; - - if(ShouldWinBeFiltered(hwnd)) return TRUE; - - m_hWndTarget = hwnd; - - if(IsTargetPopupWindow()) return FALSE; //this is the target window, exit search - - EnumChildWindows(hwnd, EnumChildRealTimeProc, lParam); - - return FALSE; - } - - static BOOL CALLBACK EnumChildRealTimeProc(HWND hwnd, LPARAM lParam) - { - if(!PtInWinRect(hwnd, QPoint((lParam & 0xffff), (lParam >> 16)))) return TRUE; - - if(ShouldWinBeFiltered(hwnd)) return TRUE; - - m_hWndTarget = hwnd; - EnumChildWindows(hwnd, EnumChildRealTimeProc, lParam); - - return FALSE; - } - - protected: - static BOOL CALLBACK EnumWindowsSnapshotProc(HWND hwnd, LPARAM lParam) - { - INT nLevel = lParam; - if(ShouldWinBeFiltered(hwnd)) return TRUE; - - SaveSnapshotWindow(hwnd, nLevel); - - if(!IsTargetPopupWindow()) - { - ++nLevel; - EnumChildWindows(hwnd, EnumChildSnapshotProc, nLevel); - } - - return TRUE; - } - - static BOOL CALLBACK EnumChildSnapshotProc(HWND hwnd, LPARAM lParam) - { - INT nLevel = lParam; - if(ShouldWinBeFiltered(hwnd)) return TRUE; - SaveSnapshotWindow(hwnd, nLevel); - ++nLevel; - EnumChildWindows(hwnd, EnumChildSnapshotProc, nLevel); - - return TRUE; - } - - protected: - static BOOL PtInWinRect(HWND hWnd, QPoint pt) - { - RECT rect1; - GetWindowRect(hWnd, &rect1); - POINT point; - point.x = pt.x(); - point.y = pt.y(); - return PtInRect(&rect1, point); - } - - static BOOL ShouldWinBeFiltered(HWND hWnd) - { - if(IsFilterWindow(hWnd)) return TRUE; - - DWORD dwStyle = GetWindowLong(hWnd, GWL_STYLE); - DWORD dwStyleMust = GetIncludeStyle(); - if((dwStyle & dwStyleMust) != dwStyleMust) return TRUE; - - DWORD dwStyleEx = GetWindowLong(hWnd, GWL_EXSTYLE); - DWORD dwStyleMustNot = GetExcludeStyleEx(); - if((dwStyleMustNot & dwStyleEx) != 0) return TRUE; - - return FALSE; - } - - //find the first window that level is biggest - static BOOL GetRectByPointFromSnapshot(QPoint ptHit, QRect& rtRet) - { - int nCount = m_arSnapshot.size(); - CSCWinInfo* pInfo = NULL; - CSCWinInfo* pTarget = NULL; - for(int i=0; im_nLevel <= pTarget->m_nLevel) - { - break; - } - POINT point; - point.x = ptHit.x(); - point.y = ptHit.y(); - RECT rect; - rect.top = pInfo->m_rtWin.top();rect.left = pInfo->m_rtWin.left(); - rect.right = pInfo->m_rtWin.right(); rect.bottom = pInfo->m_rtWin.bottom(); - if(PtInRect(&rect, point)) - { - if(pTarget == NULL) - { - pTarget = pInfo; - } - else - { - if( pInfo->m_nLevel > pTarget->m_nLevel) - { - pTarget = pInfo; - } - } - } - } - - if(pTarget != NULL) - { - rtRet = pTarget->m_rtWin; - return TRUE; - } - - return FALSE; - } - - static VOID SaveSnapshotWindow(HWND hwnd, INT nLevel) - { - RECT rect2; - POINT point2; - point2.x = 0;point2.y = 0; - GetClientRect(hwnd, &rect2); - ClientToScreen(hwnd, &point2); - QRect rtWin = QRect(QPoint(point2.x, point2.y), QSize(rect2.right, rect2.bottom)); - if(rtWin.isEmpty()) return; - - CSCWinInfo* pInfo = new CSCWinInfo(); - if(pInfo == NULL) return; - - pInfo->m_hWnd = hwnd; - pInfo->m_nLevel = nLevel; - pInfo->m_rtWin = rtWin; - m_arSnapshot.push_back(pInfo); - } - - static VOID ClearData() - { - int nCount = m_arSnapshot.size(); - for(int i=0; i m_arSnapshot; -}; - - - -#endif // WINDOW_FLITER_H From 973954d929477357d62e995365c207a4ef61ab67 Mon Sep 17 00:00:00 2001 From: xinhecuican <2686462757@qq.com> Date: Sun, 14 Jan 2024 17:27:44 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E5=AE=8C=E5=96=84PaintWindow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Container/blurlayercontainer.cpp | 14 +- GraphicsScene/Container/geolayercontainer.cpp | 51 +- GraphicsScene/Container/geolayercontainer.h | 7 + GraphicsScene/Container/layercontainer.cpp | 18 + GraphicsScene/Container/layercontainer.h | 4 + .../Container/masklayercontainer.cpp | 18 +- GraphicsScene/Container/masklayercontainer.h | 1 + .../Container/paintlayercontainer.cpp | 32 +- GraphicsScene/Container/paintlayercontainer.h | 6 + .../Container/textlayercontainer.cpp | 29 +- .../Container/videolayercontainer.cpp | 22 +- GraphicsScene/Layer/arrowlayer.cpp | 18 +- GraphicsScene/Layer/arrowlayer.h | 2 + GraphicsScene/Layer/blurlayer.cpp | 1 + GraphicsScene/Layer/grabcutlayer.cpp | 5 +- GraphicsScene/Layer/masklayer.cpp | 7 +- GraphicsScene/Layer/masklayer.h | 1 + GraphicsScene/Layer/paintlayer.cpp | 4 +- GraphicsScene/Layer/piclayer.cpp | 17 +- GraphicsScene/Layer/piclayer.h | 7 +- GraphicsScene/Layer/rectlayer.cpp | 19 +- GraphicsScene/Layer/rectlayer.h | 2 + GraphicsScene/Widgets/attributetoolbar.cpp | 7 +- GraphicsScene/Widgets/defaulttoolbar.cpp | 71 +- GraphicsScene/Widgets/defaulttoolbar.h | 5 + GraphicsScene/Widgets/layertoolbar.cpp | 8 +- GraphicsScene/Widgets/layertoolbar.h | 3 +- GraphicsScene/Widgets/painttoolbar.cpp | 230 ++++++ GraphicsScene/Widgets/painttoolbar.h | 21 + GraphicsScene/paintarea.cpp | 27 +- GraphicsScene/paintarea.h | 5 + Helper/common.h | 4 +- Helper/global.h | 6 + Helper/imagehelper.cpp | 1 + Helper/imagehelper.h | 6 +- MainFilter.cpp | 28 +- Manager/WindowManager.cpp | 20 +- Manager/WindowManager.h | 40 +- Manager/update.cpp | 4 +- Resource/keys.xml | 14 +- Setting/setting.cpp | 2 +- Style_widget/ColorWidget.ui | 697 ------------------ Style_widget/colorwidget.cpp | 51 +- Style_widget/colorwidget.h | 13 +- Windows/capturewindow.cpp | 35 +- Windows/paintwindow.cpp | 61 +- Windows/paintwindow.h | 6 +- Windows/pinwindow.cpp | 12 +- Windows/scrollerwindow.cpp | 9 +- capture.pro | 4 +- theme/default/CaptureWindow.qss | 10 +- 51 files changed, 713 insertions(+), 972 deletions(-) create mode 100644 GraphicsScene/Widgets/painttoolbar.cpp create mode 100644 GraphicsScene/Widgets/painttoolbar.h create mode 100644 Helper/global.h delete mode 100644 Style_widget/ColorWidget.ui diff --git a/GraphicsScene/Container/blurlayercontainer.cpp b/GraphicsScene/Container/blurlayercontainer.cpp index 9a23679..ee1597b 100644 --- a/GraphicsScene/Container/blurlayercontainer.cpp +++ b/GraphicsScene/Container/blurlayercontainer.cpp @@ -23,10 +23,7 @@ QWidget* BlurLayerContainer::onValid(QWidget *widgetParent) { if(type == 1){ grabcutLayer->setEnableShow(); } - if(widget == NULL) { - widget = new QWidget(widgetParent); - QHBoxLayout* layout = new QHBoxLayout(); - + if(!initWidget(widgetParent)){ QButtonGroup* group = new QButtonGroup(widgetParent); group->setExclusive(true); connect(group, static_cast(&QButtonGroup::buttonClicked), @@ -39,12 +36,14 @@ QWidget* BlurLayerContainer::onValid(QWidget *widgetParent) { QToolButton* mosaicButton = new QToolButton(widgetParent); mosaicButton->setToolTip(MString::search("{capture_mosaic}马赛克")); mosaicButton->setIcon(ImageHelper::getIcon("blur")); + mosaicButton->setIconSize(QSize(DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE)); mosaicButton->setCheckable(true); mosaicButton->setChecked(true); group->addButton(mosaicButton, 0); QToolButton* grabcutButton = new QToolButton(widgetParent); grabcutButton->setToolTip(MString::search("{QbgMYc4u4H}透明")); grabcutButton->setIcon(ImageHelper::getIcon("mosaic")); + grabcutButton->setIconSize(QSize(DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE)); grabcutButton->setCheckable(true); group->addButton(grabcutButton, 1); @@ -58,10 +57,9 @@ QWidget* BlurLayerContainer::onValid(QWidget *widgetParent) { connect(mosaicSize, static_cast(&QSpinBox::valueChanged), this, [=](int value) { windowSize = value; }); - layout->addWidget(mosaicButton); - layout->addWidget(grabcutButton); - layout->addWidget(mosaicSize); - widget->setLayout(layout); + addWidget(mosaicButton); + addWidget(grabcutButton); + addWidget(mosaicSize); } return widget; } diff --git a/GraphicsScene/Container/geolayercontainer.cpp b/GraphicsScene/Container/geolayercontainer.cpp index f2b2486..a7c1fb9 100644 --- a/GraphicsScene/Container/geolayercontainer.cpp +++ b/GraphicsScene/Container/geolayercontainer.cpp @@ -21,43 +21,33 @@ GeoLayerContainer::GeoLayerContainer(PaintArea* area) : QWidget* GeoLayerContainer::onValid(QWidget* widgetParent){ area->setEnable(true); - if(widget == NULL){ - widget = new QWidget(widgetParent); - QHBoxLayout* layout = new QHBoxLayout(); + if(!initWidget(widgetParent)){ QButtonGroup* shapeGroup = new QButtonGroup(widgetParent); shapeGroup->setExclusive(true); - connect(shapeGroup, static_cast(&QButtonGroup::buttonClicked), - this, [=](int id) { - switch(id) { - case 0: geoType = RECT; break; - case 1: geoType = ARROW; break; - default: - geoType = id; - qWarning() << "未知形状"; - break; - } - }); + QToolButton* rectButton = new QToolButton(widgetParent); rectButton->setObjectName("rectButton"); rectButton->setToolTip("矩形"); rectButton->setIcon(ImageHelper::getIcon("rect")); + rectButton->setIconSize(QSize(DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE)); rectButton->setCheckable(true); rectButton->setChecked(true); shapeGroup->addButton(rectButton, 0); QToolButton* arrowButton = new QToolButton(widgetParent); arrowButton->setObjectName("arrowButton"); arrowButton->setIcon(ImageHelper::getIcon("paint_arrow")); + arrowButton->setIconSize(QSize(DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE)); arrowButton->setToolTip(MString::search("{D7HSBXWTLj}箭头")); arrowButton->setCheckable(true); shapeGroup->addButton(arrowButton, 1); - ColorWidget* colorWidget = new ColorWidget(widgetParent); + colorWidget = new ColorWidget(widgetParent); connect(colorWidget, &ColorWidget::colorChange, this, [=](const QColor& color){ switch(geoType){ case RECT: rectPaintData.color = color; break; case ARROW: arrowPaintData.color = color; break; } }); - QSpinBox* widthButton = new QSpinBox(widgetParent); + widthButton = new QSpinBox(widgetParent); widthButton->setRange(1, 50); widthButton->setValue(3); widthButton->setAccelerated(true); @@ -69,12 +59,22 @@ QWidget* GeoLayerContainer::onValid(QWidget* widgetParent){ case ARROW: arrowPaintData.width = value; break; } }); - - layout->addWidget(rectButton); - layout->addWidget(arrowButton); - layout->addWidget(colorWidget); - layout->addWidget(widthButton); - widget->setLayout(layout); + connect(shapeGroup, static_cast(&QButtonGroup::buttonClicked), + this, [=](int id) { + switch(id) { + case 0: geoType = RECT; applyData(rectPaintData);break; + case 1: geoType = ARROW; applyData(arrowPaintData);break; + default: + geoType = id; + qWarning() << "未知形状"; + break; + } + }); + applyData(rectPaintData); + addWidget(rectButton); + addWidget(arrowButton); + addWidget(colorWidget); + addWidget(widthButton); } return widget; } @@ -85,11 +85,13 @@ void GeoLayerContainer::layerMousePressEvent(QGraphicsSceneMouseEvent *event){ case RECT: { QRectF rect = Math::buildRect(beginPoint, beginPoint + QPointF(1, 1)); rectLayer = new RectLayer(rect, "rect" + QString::number(rectId), area, area->getRootLayer(), false); + rectLayer->setStyle(rectPaintData); rectLayer->setEnable(false); break; } case ARROW: { arrowLayer = new ArrowLayer(beginPoint, beginPoint + QPointF(1, 1), "arrow" + QString::number(arrowId), area, area->getRootLayer()); + arrowLayer->setStyle(arrowPaintData); arrowLayer->setZValue(arrowLayer->getZValue()); arrowLayer->setEnable(false); break; @@ -146,3 +148,8 @@ void GeoLayerContainer::layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event){ } } } + +void GeoLayerContainer::applyData(PaintData data){ + colorWidget->setCurrentStyle(data.color); + widthButton->setValue(data.width); +} diff --git a/GraphicsScene/Container/geolayercontainer.h b/GraphicsScene/Container/geolayercontainer.h index a54d2d6..d8d2d54 100644 --- a/GraphicsScene/Container/geolayercontainer.h +++ b/GraphicsScene/Container/geolayercontainer.h @@ -4,6 +4,8 @@ #include "../Widgets/PaintData.h" #include "../Layer/rectlayer.h" #include "../Layer/arrowlayer.h" +#include "../../Style_widget/colorwidget.h" +#include class GeoLayerContainer : public LayerContainer { @@ -15,6 +17,9 @@ class GeoLayerContainer : public LayerContainer void layerMouseMoveEvent(QGraphicsSceneMouseEvent *event) override; void layerMousePressEvent(QGraphicsSceneMouseEvent* event) override; void layerMouseReleaseEvent(QGraphicsSceneMouseEvent* event) override; + +private: + void applyData(PaintData data); private: QPointF beginPoint; int geoType; @@ -24,6 +29,8 @@ class GeoLayerContainer : public LayerContainer int arrowId; RectLayer* rectLayer; ArrowLayer* arrowLayer; + ColorWidget* colorWidget; + QSpinBox* widthButton; }; #endif // GEOLAYERCONTAINER_H diff --git a/GraphicsScene/Container/layercontainer.cpp b/GraphicsScene/Container/layercontainer.cpp index fbce170..f72983d 100644 --- a/GraphicsScene/Container/layercontainer.cpp +++ b/GraphicsScene/Container/layercontainer.cpp @@ -7,3 +7,21 @@ LayerContainer::LayerContainer(PaintArea* area): widget(NULL){ } + + +void LayerContainer::addWidget(QWidget *widget){ + this->widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + this->widget->layout()->addWidget(widget); +} + +bool LayerContainer::initWidget(QWidget* parent){ + if(widget == NULL){ + widget = new QWidget(parent); + QHBoxLayout* layout = new QHBoxLayout(); + layout->setSpacing(3); + layout->setContentsMargins(3, 2, 3, 2); + widget->setLayout(layout); + return false; + } + return true; +} diff --git a/GraphicsScene/Container/layercontainer.h b/GraphicsScene/Container/layercontainer.h index adc4536..5e38884 100644 --- a/GraphicsScene/Container/layercontainer.h +++ b/GraphicsScene/Container/layercontainer.h @@ -18,6 +18,10 @@ class LayerContainer : public QObject virtual void layerMouseReleaseEvent(QGraphicsSceneMouseEvent* event) {} virtual QWidget* onValid(QWidget* widgetParent)=0; virtual void onInvalid(){} + +protected: + bool initWidget(QWidget* parent); + void addWidget(QWidget* widget); protected: PaintArea* area; QWidget* widget; diff --git a/GraphicsScene/Container/masklayercontainer.cpp b/GraphicsScene/Container/masklayercontainer.cpp index 9669d12..7b14d7d 100644 --- a/GraphicsScene/Container/masklayercontainer.cpp +++ b/GraphicsScene/Container/masklayercontainer.cpp @@ -11,22 +11,19 @@ MaskLayerContainer::MaskLayerContainer(PaintArea* area) : LayerContainer(area) QWidget* MaskLayerContainer::onValid(QWidget *widgetParent) { area->setEnable(false, maskLayer->type()); maskLayer->setEnable(true, maskLayer->type()); - if(widget == NULL){ - widget = new QWidget(widgetParent); - QHBoxLayout* layout = new QHBoxLayout(); - + if(!initWidget(widgetParent)){ QButtonGroup* modeGroup = new QButtonGroup(widgetParent); modeGroup->setExclusive(true); QToolButton* rectCapture = new QToolButton(widgetParent); rectCapture->setIcon(ImageHelper::getIcon("rect")); + rectCapture->setIconSize(QSize(DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE)); rectCapture->setToolTip(MString::search("{OBwjJUhTkh}矩形窗口")); rectCapture->setChecked(true); rectCapture->setCheckable(true); - rectCapture->setIconSize(QSize(36, 36)); QToolButton* freeCapture = new QToolButton(widgetParent); freeCapture->setIcon(ImageHelper::getIcon("painterpath")); - freeCapture->setIconSize(QSize(36, 36)); + freeCapture->setIconSize(QSize(DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE)); freeCapture->setCheckable(true); modeGroup->addButton(rectCapture, 0); modeGroup->addButton(freeCapture, 1); @@ -38,9 +35,12 @@ QWidget* MaskLayerContainer::onValid(QWidget *widgetParent) { Config::setConfig(Config::capture_mode, Config::FREE_CAPTURE); } }); - layout->addWidget(rectCapture); - layout->addWidget(freeCapture); - widget->setLayout(layout); + addWidget(rectCapture); + addWidget(freeCapture); } return widget; } + +int MaskLayerContainer::regionCount(){ + return maskLayer->getRegionCount(); +} diff --git a/GraphicsScene/Container/masklayercontainer.h b/GraphicsScene/Container/masklayercontainer.h index aba1f36..cfc5cef 100644 --- a/GraphicsScene/Container/masklayercontainer.h +++ b/GraphicsScene/Container/masklayercontainer.h @@ -8,6 +8,7 @@ class MaskLayerContainer : public LayerContainer public: MaskLayerContainer(PaintArea* area); QWidget * onValid(QWidget *widgetParent) override; + int regionCount(); private: MaskLayer* maskLayer; }; diff --git a/GraphicsScene/Container/paintlayercontainer.cpp b/GraphicsScene/Container/paintlayercontainer.cpp index 0e771ae..c80de48 100644 --- a/GraphicsScene/Container/paintlayercontainer.cpp +++ b/GraphicsScene/Container/paintlayercontainer.cpp @@ -20,16 +20,14 @@ PaintLayerContainer::PaintLayerContainer(PaintArea* area) : QWidget* PaintLayerContainer::onValid(QWidget *widgetParent) { area->setEnable(false, 102405); - if(widget == NULL){ - widget = new QWidget(widgetParent); - QHBoxLayout* layout = new QHBoxLayout(); + if(!initWidget(widgetParent)){ QButtonGroup* shapeGroup = new QButtonGroup(widgetParent); shapeGroup->setExclusive(true); connect(shapeGroup, static_cast(&QButtonGroup::buttonClicked), this, [=](int id) { switch(id) { - case 0: type = Pencil; break; - case 1: type = Highlighter; break; + case 0: type = Pencil; applyData(pencilData);break; + case 1: type = Highlighter; applyData(highlighterData);break; default: type = id; qWarning() << "未知形状"; @@ -40,23 +38,25 @@ QWidget* PaintLayerContainer::onValid(QWidget *widgetParent) { pencilButton->setObjectName("pencilButton"); pencilButton->setToolTip("笔"); pencilButton->setIcon(ImageHelper::getIcon("pencil")); + pencilButton->setIconSize(QSize(DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE)); pencilButton->setCheckable(true); pencilButton->setChecked(true); shapeGroup->addButton(pencilButton, 0); QToolButton* highlighterButton = new QToolButton(widgetParent); highlighterButton->setObjectName("highlighterButton"); highlighterButton->setIcon(ImageHelper::getIcon("highlighter")); + highlighterButton->setIconSize(QSize(DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE)); highlighterButton->setToolTip(MString::search("{j54u1kWtCx}荧光笔")); highlighterButton->setCheckable(true); shapeGroup->addButton(highlighterButton, 1); - ColorWidget* colorWidget = new ColorWidget(widgetParent); + colorWidget = new ColorWidget(widgetParent); connect(colorWidget, &ColorWidget::colorChange, this, [=](const QColor& color){ switch(type){ case Pencil: pencilData.color = color; break; case Highlighter: highlighterData.color = color; break; } }); - QSpinBox* widthButton = new QSpinBox(widgetParent); + widthButton = new QSpinBox(widgetParent); widthButton->setRange(1, 50); widthButton->setValue(3); widthButton->setAccelerated(true); @@ -68,12 +68,11 @@ QWidget* PaintLayerContainer::onValid(QWidget *widgetParent) { case Highlighter: highlighterData.width = value; break; } }); - - layout->addWidget(pencilButton); - layout->addWidget(highlighterButton); - layout->addWidget(colorWidget); - layout->addWidget(widthButton); - widget->setLayout(layout); + applyData(pencilData); + addWidget(pencilButton); + addWidget(highlighterButton); + addWidget(colorWidget); + addWidget(widthButton); } return widget; } @@ -97,7 +96,7 @@ void PaintLayerContainer::layerMousePressEvent(QGraphicsSceneMouseEvent *event) void PaintLayerContainer::layerMouseMoveEvent(QGraphicsSceneMouseEvent *event) { qint64 currentTime = QDateTime::currentMSecsSinceEpoch(); - if(currentTime - beforeTime > 30) { + if(currentTime - beforeTime > 20) { beforeTime = currentTime; paintLayer->addPoint(event->scenePos()); } @@ -111,3 +110,8 @@ void PaintLayerContainer::layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event paintId++; area->addLayer(paintLayer); } + +void PaintLayerContainer::applyData(PaintData data){ + colorWidget->setCurrentStyle(data.color); + widthButton->setValue(data.width); +} diff --git a/GraphicsScene/Container/paintlayercontainer.h b/GraphicsScene/Container/paintlayercontainer.h index 4cee46a..3fb4061 100644 --- a/GraphicsScene/Container/paintlayercontainer.h +++ b/GraphicsScene/Container/paintlayercontainer.h @@ -3,6 +3,8 @@ #include "layercontainer.h" #include "../Widgets/PaintData.h" #include "../Layer/paintlayer.h" +#include "../../Style_widget/colorwidget.h" +#include class PaintLayerContainer : public LayerContainer { @@ -14,6 +16,8 @@ class PaintLayerContainer : public LayerContainer void layerMouseMoveEvent(QGraphicsSceneMouseEvent *event) override; void layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; QWidget * onValid(QWidget *widgetParent) override; +private: + void applyData(PaintData data); private: int type; PaintData pencilData; @@ -21,6 +25,8 @@ class PaintLayerContainer : public LayerContainer PaintLayer* paintLayer; int paintId; qint64 beforeTime; + ColorWidget* colorWidget; + QSpinBox* widthButton; }; #endif // PAINTLAYERCONTAINER_H diff --git a/GraphicsScene/Container/textlayercontainer.cpp b/GraphicsScene/Container/textlayercontainer.cpp index 112d912..11fae78 100644 --- a/GraphicsScene/Container/textlayercontainer.cpp +++ b/GraphicsScene/Container/textlayercontainer.cpp @@ -35,12 +35,10 @@ void TextLayerContainer::layerMousePressEvent(QGraphicsSceneMouseEvent *event){ QWidget* TextLayerContainer::onValid(QWidget *widgetParent){ area->setEnable(true); - if(widget == NULL){ - widget = new QWidget(widgetParent); - QHBoxLayout* layout = new QHBoxLayout(); - + if(!initWidget(widgetParent)){ QToolButton* brushButton = new QToolButton(widgetParent); brushButton->setIcon(ImageHelper::getIcon("brush")); + brushButton->setIconSize(QSize(DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE)); brushButton->setToolTip(MString::search("{hULcO1ELot}格式刷")); connect(brushButton, &QToolButton::clicked, this, [=](){ LayerBase* focusLayer = area->getFocusLayer(); @@ -50,6 +48,7 @@ QWidget* TextLayerContainer::onValid(QWidget *widgetParent){ }); colorSelectButton = new QToolButton(widgetParent); + colorSelectButton->setIconSize(QSize(DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE)); int r = 0, g = 0, b = 0; data.color.getRgb(&r,&g,&b); colorSelectButton->setStyleSheet(QString("background-color: rgb(%1,%2,%3)").arg(r).arg(g).arg(b)); @@ -122,6 +121,7 @@ QWidget* TextLayerContainer::onValid(QWidget *widgetParent){ }); boldButton = new QToolButton(widgetParent); boldButton->setIcon(ImageHelper::getIcon("bold", 48, 48)); + boldButton->setIconSize(QSize(DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE)); boldButton->setCheckable(true); connect(boldButton, &QToolButton::clicked, this, [=]() { if(data.font.bold()) { @@ -138,6 +138,7 @@ QWidget* TextLayerContainer::onValid(QWidget *widgetParent){ }); italicButton = new QToolButton(widgetParent); italicButton->setIcon(ImageHelper::getIcon("italic", 48, 48)); + italicButton->setIconSize(QSize(DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE)); italicButton->setCheckable(true); connect(italicButton, &QToolButton::clicked, this, [=]() { if(data.font.italic()) { @@ -154,6 +155,7 @@ QWidget* TextLayerContainer::onValid(QWidget *widgetParent){ }); underlineButton = new QToolButton(widgetParent); underlineButton->setIcon(ImageHelper::getIcon("underline", 48, 48)); + underlineButton->setIconSize(QSize(DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE)); underlineButton->setCheckable(true); connect(underlineButton, &QToolButton::clicked, this, [=]() { if(data.font.underline()) { @@ -168,19 +170,14 @@ QWidget* TextLayerContainer::onValid(QWidget *widgetParent){ focusLayer->setParameter("font", data.font); } }); - colorSelectButton->setFixedSize(fontBox->height(), fontBox->height()); - boldButton->setFixedSize(fontBox->height(), fontBox->height()); - italicButton->setFixedSize(fontBox->height(), fontBox->height()); - underlineButton->setFixedSize(fontBox->height(), fontBox->height()); - layout->addWidget(brushButton); - layout->addWidget(colorSelectButton); - layout->addWidget(fontBox); - layout->addWidget(widthBox); - layout->addWidget(boldButton); - layout->addWidget(italicButton); - layout->addWidget(underlineButton); - widget->setLayout(layout); + addWidget(brushButton); + addWidget(colorSelectButton); + addWidget(fontBox); + addWidget(widthBox); + addWidget(boldButton); + addWidget(italicButton); + addWidget(underlineButton); } return widget; } diff --git a/GraphicsScene/Container/videolayercontainer.cpp b/GraphicsScene/Container/videolayercontainer.cpp index 77c5f56..a849345 100644 --- a/GraphicsScene/Container/videolayercontainer.cpp +++ b/GraphicsScene/Container/videolayercontainer.cpp @@ -18,10 +18,7 @@ VideoLayerContainer::VideoLayerContainer(PaintArea* area) : LayerContainer(area) } QWidget* VideoLayerContainer::onValid(QWidget *widgetParent){ - if(widget == NULL){ - widget = new QWidget(widgetParent); - QHBoxLayout* layout = new QHBoxLayout(); - + if(!initWidget(widgetParent)){ QRadioButton* enableAudioButton = new QRadioButton(widgetParent); enableAudioButton->setText(MString::search("{rh0LYgOmDD}录制声音")); enableAudioButton->setChecked(true); @@ -104,15 +101,14 @@ QWidget* VideoLayerContainer::onValid(QWidget *widgetParent){ helpButton->setIcon(ImageHelper::getIcon("help")); helpButton->setToolTip(MString::search("{SHLK0bd4wt}开始录屏: F5\n暂停/恢复录屏: F6\n结束录屏: F7")); - layout->addWidget(enableAudioButton); - layout->addWidget(deviceSelector); - layout->addWidget(fpsLabel); - layout->addWidget(fpsSelector); - layout->addWidget(pathChooseButton); - layout->addWidget(fileNameEdit); - layout->addWidget(suffixSelector); - layout->addWidget(helpButton); - widget->setLayout(layout); + addWidget(enableAudioButton); + addWidget(deviceSelector); + addWidget(fpsLabel); + addWidget(fpsSelector); + addWidget(pathChooseButton); + addWidget(fileNameEdit); + addWidget(suffixSelector); + addWidget(helpButton); } return widget; } diff --git a/GraphicsScene/Layer/arrowlayer.cpp b/GraphicsScene/Layer/arrowlayer.cpp index 14fab37..53a930c 100644 --- a/GraphicsScene/Layer/arrowlayer.cpp +++ b/GraphicsScene/Layer/arrowlayer.cpp @@ -3,7 +3,8 @@ #include "../Recorder/layerrecord.h" ArrowLayer::ArrowLayer(const QPointF& beginPt, const QPointF& endPt, const QString& name, ILayerControl* manager, QGraphicsItem* parent) : - LayerBase(name, manager, parent){ + LayerBase(name, manager, parent), + press(false){ beginButton = new ExpandButton(ExpandButton::W, beginPt, this); endButton = new ExpandButton(ExpandButton::E, endPt, this); setLine(beginPt, endPt); @@ -74,12 +75,15 @@ void ArrowLayer::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { } void ArrowLayer::mousePressEvent(QGraphicsSceneMouseEvent *event) { - point = event->scenePos(); - manager->requestFocus(this); + if(enable){ + point = event->scenePos(); + manager->requestFocus(this); + press = true; + } } void ArrowLayer::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if(enable) { + if(enable && press) { QPointF delta_point = event->scenePos() - point; point = event->scenePos(); moveBy(delta_point.x(), delta_point.y()); @@ -87,11 +91,12 @@ void ArrowLayer::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { } void ArrowLayer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if(enable) { + if(enable && press) { QPointF delta_point = event->scenePos() - point; point = event->scenePos(); moveBy(delta_point.x(), delta_point.y()); } + press = false; } void ArrowLayer::setLine(const QPointF& beginPt, const QPointF& endPt) { @@ -157,6 +162,9 @@ void ArrowLayer::setParameter(const QString &name, const QVariant &var){ } +void ArrowLayer::setStyle(const PaintData &data){ + this->data = data; +} void ArrowLayer::reset(){ manager->removeThis(this); } diff --git a/GraphicsScene/Layer/arrowlayer.h b/GraphicsScene/Layer/arrowlayer.h index 96998dc..8e4d0ba 100644 --- a/GraphicsScene/Layer/arrowlayer.h +++ b/GraphicsScene/Layer/arrowlayer.h @@ -31,6 +31,7 @@ class ArrowLayer : public LayerBase void prepareSave() override; bool contains(const QPointF& point)const override; void onDelete(const QPointF &point) override; + void setStyle(const PaintData& data); private slots: void posChangeFunc(ExpandButton::ButtonDirection dir, qreal x, qreal y); @@ -49,6 +50,7 @@ private slots: QCursor outCursor; PaintData data; int index; + bool press; const float ExtRefArrowLenght = 10;//箭头末端大小的长度, const float ExtRefArrowDegrees = M_PI / 6;//箭头末端顶角的一半 }; diff --git a/GraphicsScene/Layer/blurlayer.cpp b/GraphicsScene/Layer/blurlayer.cpp index 83ab703..923d2ba 100644 --- a/GraphicsScene/Layer/blurlayer.cpp +++ b/GraphicsScene/Layer/blurlayer.cpp @@ -79,6 +79,7 @@ void BlurLayer::deletePoint(const QPoint &point){ void BlurLayer::reset() { use.resize(0); + LayerBase::reset(); } void BlurLayer::setParameter(const QString &name, const QVariant &var) { diff --git a/GraphicsScene/Layer/grabcutlayer.cpp b/GraphicsScene/Layer/grabcutlayer.cpp index bc673cf..aace1fe 100644 --- a/GraphicsScene/Layer/grabcutlayer.cpp +++ b/GraphicsScene/Layer/grabcutlayer.cpp @@ -79,7 +79,10 @@ int GrabcutLayer::type() const{ } void GrabcutLayer::reset(){ - + enableShow = false; + foregroundPaths.clear(); + backgroundPaths.clear(); + LayerBase::reset(); } int GrabcutLayer::getZValue() const{ diff --git a/GraphicsScene/Layer/masklayer.cpp b/GraphicsScene/Layer/masklayer.cpp index b230b9e..78a9739 100644 --- a/GraphicsScene/Layer/masklayer.cpp +++ b/GraphicsScene/Layer/masklayer.cpp @@ -15,6 +15,8 @@ MaskLayer::MaskLayer(const QString& name, borderData.width = 2; colorPicker = new ColorPicker(manager, this); colorPicker->hide(); + pen.setColor(borderData.color); + pen.setWidth(borderData.width); } QRectF MaskLayer::boundingRect() const { @@ -99,9 +101,6 @@ void MaskLayer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { void MaskLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { if(!isSaving) { painter->fillRect(bound, QColor(0, 0, 0, 1)); - QPen pen; - pen.setColor(borderData.color); - pen.setWidth(borderData.width); painter->setPen(pen); QPainterPath origin; @@ -179,7 +178,6 @@ void MaskLayer::prepareSave() { } void MaskLayer::endSave() { - clearRegion(); ClipLayerBase::endSave(); } @@ -236,6 +234,7 @@ void MaskLayer::reset() { beginClip = false; clearRegion(); freeCapturePath.clear(); + ClipLayerBase::reset(); } int MaskLayer::getZValue() const { diff --git a/GraphicsScene/Layer/masklayer.h b/GraphicsScene/Layer/masklayer.h index ee972d0..9c7a5de 100644 --- a/GraphicsScene/Layer/masklayer.h +++ b/GraphicsScene/Layer/masklayer.h @@ -40,6 +40,7 @@ class MaskLayer : public ClipLayerBase QList free_regions; QRectF bound; QPainterPath freeCapturePath; + QPen pen; QPointF beginPoint; QPointF endPoint; bool isDrag; diff --git a/GraphicsScene/Layer/paintlayer.cpp b/GraphicsScene/Layer/paintlayer.cpp index 7ddee6e..1b0bb3c 100644 --- a/GraphicsScene/Layer/paintlayer.cpp +++ b/GraphicsScene/Layer/paintlayer.cpp @@ -44,7 +44,7 @@ void PaintLayer::reset(){ void PaintLayer::addPoint(const QPointF& point){ if(points.size() > 0){ QLineF line(point, points.last()); - if(line.length() < 3) return; + if(line.length() < 2) return; } if(point.x() >= manager->getImage().width() || point.y() >= manager->getImage().height() || @@ -199,7 +199,7 @@ void PaintLayer::end(){ isEnd = true; cachePix.fill(Qt::transparent); QPainter* cachePainter = new QPainter(&cachePix); - cachePainter->setRenderHint(QPainter::Antialiasing, true); + cachePainter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, true); cachePainter->setPen(pen); cachePainter->drawPath(path); delete cachePainter; diff --git a/GraphicsScene/Layer/piclayer.cpp b/GraphicsScene/Layer/piclayer.cpp index 0208b4b..8436589 100644 --- a/GraphicsScene/Layer/piclayer.cpp +++ b/GraphicsScene/Layer/piclayer.cpp @@ -2,7 +2,7 @@ #include PicLayer::PicLayer(const QString& name, ILayerControl* manager, bool enableBound, QGraphicsItem* parent) : - LayerBase(name, manager, parent), + ClipLayerBase(name, manager, parent), enableBound(enableBound) { if(enableBound){ @@ -66,9 +66,10 @@ void PicLayer::reset(){ void PicLayer::setEnable(bool enable, int index) { if(index == type()){ this->enable = enable; + rectLayer->setEnable(enable); return; } - this->enable = enableBound && enable; +// this->enable = enableBound && enable; } int PicLayer::type() const{ @@ -81,3 +82,15 @@ QRectF PicLayer::getSaveRect(){ } return QRectF(); } + +QRectF PicLayer::getClipRect(){ + return boundingRect(); +} + +QPainterPath PicLayer::getClipPath(){ + return shape(); +} + +void PicLayer::setStyle(const PaintData &data){ + rectLayer->setStyle(data); +} diff --git a/GraphicsScene/Layer/piclayer.h b/GraphicsScene/Layer/piclayer.h index 309164e..5aa817f 100644 --- a/GraphicsScene/Layer/piclayer.h +++ b/GraphicsScene/Layer/piclayer.h @@ -1,9 +1,9 @@ #ifndef PICLAYER_H #define PICLAYER_H -#include "layerbase.h" +#include "cliplayerbase.h" #include "rectlayer.h" -class PicLayer : public LayerBase +class PicLayer : public ClipLayerBase { public: PicLayer(const QString& name, ILayerControl* manager, bool enableBound=true, QGraphicsItem* parent=nullptr); @@ -17,7 +17,10 @@ class PicLayer : public LayerBase void reset() override; void setEnable(bool enable, int index=0) override; int type() const override; + void setStyle(const PaintData& data); QRectF getSaveRect() override; + QRectF getClipRect()override; + QPainterPath getClipPath()override; private: bool enableBound; RectLayer* rectLayer; diff --git a/GraphicsScene/Layer/rectlayer.cpp b/GraphicsScene/Layer/rectlayer.cpp index 03c5ecd..e989ff6 100644 --- a/GraphicsScene/Layer/rectlayer.cpp +++ b/GraphicsScene/Layer/rectlayer.cpp @@ -11,7 +11,8 @@ RectLayer::RectLayer( LayerBase(name, manager, parent), scrollItem(NULL), enableScroll(false), - buttonFocus(false) + buttonFocus(false), + press(false) { this->enableResize = enableResize; paintData.color = QColor(161, 47, 47); @@ -43,12 +44,15 @@ void RectLayer::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { } void RectLayer::mousePressEvent(QGraphicsSceneMouseEvent *event) { - beginPoint = event->scenePos(); - if(manager != NULL) manager->requestFocus(this); + if(enable) { + press = true; + beginPoint = event->scenePos(); + if(manager != NULL) manager->requestFocus(this); + } } void RectLayer::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if(enable) { + if(enable && press) { QPointF delta = event->scenePos() - beginPoint; beginPoint = event->scenePos(); moveBy(delta.x(), delta.y()); @@ -57,11 +61,12 @@ void RectLayer::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { } void RectLayer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if(enable) { + if(enable && press) { QPointF delta = event->scenePos() - beginPoint; moveBy(delta.x(), delta.y()); emit move(delta.x(), delta.y()); } + press = false; } void RectLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { @@ -278,3 +283,7 @@ void RectLayer::onDelete(const QPointF &point){ LayerRecord* record = new LayerRecord(false, this, (type() << 4) + index); manager->record(record); } + +QRectF RectLayer::getSaveRect(){ + return QRectF(pos(), rect.size()); +} diff --git a/GraphicsScene/Layer/rectlayer.h b/GraphicsScene/Layer/rectlayer.h index c80c430..ad383a9 100644 --- a/GraphicsScene/Layer/rectlayer.h +++ b/GraphicsScene/Layer/rectlayer.h @@ -38,6 +38,7 @@ class RectLayer : public LayerBase void setRect(const QRectF& rect); int type() const override; void onDelete(const QPointF &point) override; + QRectF getSaveRect() override; signals: void sizeChange(); @@ -60,6 +61,7 @@ private slots: QPointF beginPoint; QCursor outCursor; int index; + bool press; }; #endif // RECTLAYER_H diff --git a/GraphicsScene/Widgets/attributetoolbar.cpp b/GraphicsScene/Widgets/attributetoolbar.cpp index 9acb7f2..5f95859 100644 --- a/GraphicsScene/Widgets/attributetoolbar.cpp +++ b/GraphicsScene/Widgets/attributetoolbar.cpp @@ -6,7 +6,7 @@ AttributeToolbar::AttributeToolbar(QWidget* parent) : QWidget(parent) { setAttribute(Qt::WA_StyledBackground); layout = new QHBoxLayout(); layout->setSpacing(3); - layout->setContentsMargins(3, 2, 3, 2); + layout->setContentsMargins(0, 0, 0, 0); setLayout(layout); setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); setWindowFlag(Qt::WindowSystemMenuHint, false); @@ -16,6 +16,11 @@ void AttributeToolbar::addWidget(QWidget *widget) { if(!containWidget(widget)){ widgets.append(widget); widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + QList children = widget->children(); + for(auto child : widget->children()){ + if(child->isWidgetType()) + dynamic_cast(child)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + } } widget->show(); layout->addWidget(widget); diff --git a/GraphicsScene/Widgets/defaulttoolbar.cpp b/GraphicsScene/Widgets/defaulttoolbar.cpp index f6ccaae..8aba0bc 100644 --- a/GraphicsScene/Widgets/defaulttoolbar.cpp +++ b/GraphicsScene/Widgets/defaulttoolbar.cpp @@ -1,7 +1,6 @@ #include "defaulttoolbar.h" #include "../Container/blurlayercontainer.h" #include "../Container/geolayercontainer.h" -#include "../Container/masklayercontainer.h" #include "../Container/paintlayercontainer.h" #include "../Container/textlayercontainer.h" #include @@ -9,16 +8,16 @@ #include DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar(area, parent) -{ +{ GeoLayerContainer* geoLayerContainer = new GeoLayerContainer(area); addContainer("shape", "", geoLayerContainer, true); BlurLayerContainer* blurLayerContainer = new BlurLayerContainer(area); addContainer("mosaic", "", blurLayerContainer, true); QToolButton* cursorButton = new QToolButton(this); - cursorButton->setIcon(QIcon(":/image/cursor.png")); + cursorButton->setIcon(ImageHelper::getIcon("cursor")); cursorButton->setToolTip(MString::search("{l4yTU9QXUd}指针")); cursorButton->setCursor(QCursor(QPixmap(":/image/cursor.png"), 0, 0)); - MaskLayerContainer* maskLayerContainer = new MaskLayerContainer(area); + maskLayerContainer = new MaskLayerContainer(area); addContainer(cursorButton, maskLayerContainer, true); setContainer(maskLayerContainer); PaintLayerContainer* paintLayerContainer = new PaintLayerContainer(area); @@ -30,7 +29,7 @@ DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar( eraseButton->setIcon(ImageHelper::getIcon("eraser")); eraseButton->setToolTip(MString::search("{7cwKObEhcx}擦除")); addContainer(eraseButton, - [=](){area->setEnable(false);area->setEraseEnable(true);}, + [=](){area->setEnable(false);area->setEraseEnable(true);attributeBar->removeAll();}, [=](){area->setEraseEnable(false);}, true); addSeparator(); @@ -68,7 +67,7 @@ DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar( ocrButton->setToolTip(MString::search("{SvJhCjRGF0}提取文字")); connect(ocrButton, &QToolButton::clicked, this, [=]() { if(area->save(ILayerControl::Temp, "ocr/1.png")) { - WindowManager::changeWindow("tray"); + WindowManager::instance()->changeWindow("tray"); ocrProcess.start(); } }); @@ -79,7 +78,7 @@ DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar( clipButton->setToolTip(MString::search("{ntbJbEqxwF}复制到剪切板")); connect(clipButton, &QToolButton::clicked, this, [=]() { if(area->save(ILayerControl::ClipBoard, "")) - WindowManager::changeWindow("tray"); + WindowManager::instance()->changeWindow("tray"); }); addWidget(clipButton); @@ -93,7 +92,7 @@ DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar( "图片(*.bmp *.jpg *.jpeg *.png);;所有文件(*)"); if(fileName != "") { if(area->save(ILayerControl::Persist, fileName)) - WindowManager::changeWindow("tray"); + WindowManager::instance()->changeWindow("tray"); } }); addWidget(saveButton); @@ -103,7 +102,7 @@ DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar( pinButton->setIcon(ImageHelper::getIcon("pin")); connect(pinButton, &QToolButton::clicked, this, [=](){ QImage image = area->getSaveImage(); - WindowManager::changeWindow("PinWindow", QPixmap::fromImage(image), area->getSaveRect().toRect()); + WindowManager::instance()->changeWindow("PinWindow", QPixmap::fromImage(image), area->getSaveRect().toRect()); }); addWidget(pinButton); @@ -113,14 +112,14 @@ DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar( QImage image = area->getSaveImage(); QRect bound = area->getSaveRect().toRect(); bound.moveTo(0, 0); - WindowManager::changeWindow("PaintWindow", QPixmap::fromImage(image), bound); + WindowManager::instance()->changeWindow("PaintWindow", QPixmap::fromImage(image), bound); }); addWidget(okButton); QToolButton* cancelButton = new QToolButton(this); cancelButton->setIcon(ImageHelper::getIcon("cancel")); connect(cancelButton, &QToolButton::clicked, this, [=]() { - WindowManager::changeWindow("tray"); + WindowManager::instance()->changeWindow("tray"); }); addWidget(cancelButton); @@ -135,8 +134,45 @@ DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar( showAll(); }); } - - adjustSize(); + area->registerMousePressHook([=](Qt::MouseButton button){ + if(button == Qt::RightButton) { + if(maskLayerContainer->regionCount() == 0) { + WindowManager::instance()->changeWindow("tray"); + } else { + area->reset(); + } + return true; + } else if(button == Qt::MidButton) { + switch (Config::getConfig(Config::middle_button_type)) { + case 0:{ + QImage image = area->getSaveImage(); + QRect bound = area->getSaveRect().toRect(); + bound.moveTo(0, 0); + WindowManager::instance()->changeWindow("PaintWindow", QPixmap::fromImage(image), bound); + break; + } + case 1:{ + if(area->save(ILayerControl::ClipBoard, "")) + WindowManager::instance()->changeWindow("tray"); + break; + } + case 2:{ + QString fileName = QFileDialog::getSaveFileName(parent, + "保存", + History::instance()->get_last_directory(), + "图片(*.bmp *.jpg *.jpeg *.png);;所有文件(*)"); + if(fileName != "") { + if(area->save(ILayerControl::Persist, fileName)) + WindowManager::instance()->changeWindow("tray"); + } + break; + } + } + return true; + } + return false; + }); + initOcr(); hideAll(); } @@ -182,3 +218,12 @@ void DefaultToolbar::initOcr() { showOcrResultProcess.setProgram("OcrViewer.exe"); showOcrResultProcess.setWorkingDirectory(QDir::currentPath()); } + +QWidget* DefaultToolbar::getAttributeBar(){ + return attributeBar; +} + +void DefaultToolbar::reset(){ + setContainer(maskLayerContainer); + hideAll(); +} diff --git a/GraphicsScene/Widgets/defaulttoolbar.h b/GraphicsScene/Widgets/defaulttoolbar.h index 75d9f79..4f2a0ad 100644 --- a/GraphicsScene/Widgets/defaulttoolbar.h +++ b/GraphicsScene/Widgets/defaulttoolbar.h @@ -2,16 +2,21 @@ #define DEFAULTTOOLBAR_H #include "layertoolbar.h" #include +#include "../Container/masklayercontainer.h" class DefaultToolbar : public LayerToolBar { public: DefaultToolbar(PaintArea* area, QWidget* parent=nullptr); + QWidget* getAttributeBar(); + void reset(); private: void initOcr(); + bool mousePressHook(Qt::MouseButton button); private: QProcess ocrProcess; QProcess showOcrResultProcess; + MaskLayerContainer* maskLayerContainer; }; #endif // DEFAULTTOOLBAR_H diff --git a/GraphicsScene/Widgets/layertoolbar.cpp b/GraphicsScene/Widgets/layertoolbar.cpp index 56c3ace..e4b30a7 100644 --- a/GraphicsScene/Widgets/layertoolbar.cpp +++ b/GraphicsScene/Widgets/layertoolbar.cpp @@ -17,7 +17,6 @@ LayerToolBar::LayerToolBar(PaintArea* area, QWidget* parent) : connect(group, static_cast(&QButtonGroup::buttonClicked), this, &LayerToolBar::onGroupClick); setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); setWindowFlag(Qt::WindowSystemMenuHint, false); - setMovable(false); } void LayerToolBar::addContainer(QToolButton* button, LayerContainer* container, bool exclude){ @@ -37,7 +36,6 @@ void LayerToolBar::addContainer(QToolButton* button, LayerContainer* container, containers.append(container); } addWidget(button); - adjustSize(); } void LayerToolBar::addContainer(const QString &icon, @@ -64,7 +62,6 @@ void LayerToolBar::addContainer(QToolButton* button, std::functionconst& containers.append(NULL); } addWidget(button); - adjustSize(); } void LayerToolBar::moveTo(const QRectF& mask){ @@ -125,6 +122,11 @@ void LayerToolBar::onGroupClick(int id){ moveTo(mask); } +void LayerToolBar::simulateClick(int id){ + group->button(id)->setChecked(true); + onGroupClick(id); +} + void LayerToolBar::hideAll(){ hide(); attributeBar->hide(); diff --git a/GraphicsScene/Widgets/layertoolbar.h b/GraphicsScene/Widgets/layertoolbar.h index 7d70b0b..85eb232 100644 --- a/GraphicsScene/Widgets/layertoolbar.h +++ b/GraphicsScene/Widgets/layertoolbar.h @@ -20,6 +20,7 @@ class LayerToolBar : public QToolBar void setContainer(LayerContainer* container); void hideAll(); void showAll(); + void simulateClick(int id); public slots: void onGroupClick(int id); @@ -28,7 +29,7 @@ public slots: void execValid(int id); void execInvalid(int id); -private: +protected: PaintArea* area; QButtonGroup* group; int groupId; diff --git a/GraphicsScene/Widgets/painttoolbar.cpp b/GraphicsScene/Widgets/painttoolbar.cpp new file mode 100644 index 0000000..b355c2c --- /dev/null +++ b/GraphicsScene/Widgets/painttoolbar.cpp @@ -0,0 +1,230 @@ +#include "painttoolbar.h" +#include "../Container/blurlayercontainer.h" +#include "../Container/geolayercontainer.h" +#include "../Container/textlayercontainer.h" +#include "../Layer/piclayer.h" +#include "../../Helper/imagehelper.h" +#include "../../Manager/WindowManager.h" +#include "../../Manager/history.h" +#include +#include "../../Manager/config.h" +#include "../../Helper/common.h" +#include + +PaintToolbar::PaintToolbar(PaintArea* area, QWidget* parent) : LayerToolBar(area, parent) +{ + PicLayer* picLayer = new PicLayer("pic", area, true, NULL); + PaintData data; + data.width = 1; + data.color = QColor(66, 165, 220); + picLayer->setStyle(data); + area->addLayer(picLayer); + + QToolButton* new_button = new QToolButton(this); + connect(new_button, &QToolButton::clicked, this, [=]() { + if(Config::getConfig(Config::capture_mode) == Config::TOTAL_CAPTURE) { + WindowManager::instance()->changeWindow("tray"); + QTimer::singleShot(200, this, [=]() { + QPixmap map = ImageHelper::grabScreen(); + WindowManager::instance()->changeWindow("PaintWindow", map, ImageHelper::getCurrentScreen()->geometry()); + }); + return; + } else { + changeWindowHelper(); + } + }); + new_button->setText(MString::search("{cR3jOHb9Qw}新建")); + new_button->setIcon(ImageHelper::getIcon("capture")); + new_button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + addWidget(new_button); + + QToolButton* modeButton = new QToolButton(this); + modeButton->setText(MString::search(MString::search("{7yUWnx82jI}模式"))); + modeButton->setIcon(ImageHelper::getIcon("mode")); + modeButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + modeButton->setPopupMode(QToolButton::InstantPopup); + QMenu* modeMenu = new QMenu(this); + modeMenu->addAction(MString::search("{OBwjJUhTkh}矩形窗口")); + modeMenu->addAction(MString::search("{FHFzLMcLYa}全屏")); + modeMenu->addAction(MString::search("{fnGapBU4vo}自由截图")); + modeMenu->addAction(MString::search("{ETY295cnab}滚动截屏")); + QList actions = modeMenu->actions(); + for(int i=0; isetCheckable(true); + actions[i]->setData(QVariant(i)); + } + actions[Config::getConfig(Config::capture_mode)]->setChecked(true); + connect(modeMenu, &QMenu::triggered, this, [=](QAction* action) { + QVariant index_var = action->data(); + int index = index_var.toInt(); + for(int i=0; isetChecked(false); + } + action->setChecked(true); + Config::setConfig(Config::capture_mode, index); + }); + modeButton->setMenu(modeMenu); + addWidget(modeButton); + + GeoLayerContainer* geoLayerContainer = new GeoLayerContainer(area); + addContainer("shape", "", geoLayerContainer, true); + BlurLayerContainer* blurLayerContainer = new BlurLayerContainer(area); + addContainer("mosaic", "", blurLayerContainer, true); + QToolButton* cursorButton = new QToolButton(this); + cursorButton->setIcon(ImageHelper::getIcon("cursor")); + cursorButton->setToolTip(MString::search("{l4yTU9QXUd}指针")); + addContainer(cursorButton, + [=](){picLayer->setEnable(true, picLayer->type());attributeBar->removeAll();}, + [=](){picLayer->setEnable(false, picLayer->type());}, true); + paintLayerContainer = new PaintLayerContainer(area); + addContainer("pencil", "", paintLayerContainer, true); + TextLayerContainer* textLayerContainer = new TextLayerContainer(area); + addContainer("text", "", textLayerContainer, true); + setContainer(paintLayerContainer); + picLayer->setEnable(false, picLayer->type()); + + QToolButton* eraseButton = new QToolButton(this); + eraseButton->setIcon(ImageHelper::getIcon("eraser")); + eraseButton->setToolTip(MString::search("{7cwKObEhcx}擦除")); + addContainer(eraseButton, + [=](){area->setEnable(false);area->setEraseEnable(true);attributeBar->removeAll();}, + [=](){area->setEraseEnable(false);}, true); + + addSeparator(); + + QToolButton* undoButton = new QToolButton(this); + undoButton->setIcon(ImageHelper::getIcon("undo")); + undoButton->setToolTip(MString::search("{h5KymvIMTN}撤销")); + connect(undoButton, &QToolButton::clicked, this, [=]() { + area->getRecorder()->back(); + }); + addWidget(undoButton); + + QToolButton* redoButton = new QToolButton(this); + redoButton->setToolTip(MString::search("{a7CaC7NOL5}恢复")); + redoButton->setIcon(ImageHelper::getIcon("redo")); + connect(redoButton, &QToolButton::clicked, this, [=]() { + area->getRecorder()->forward(); + }); + addWidget(redoButton); + connect(area, &PaintArea::recordChange, this, [=]() { + if(!area->getRecorder()->undoAvailiable()) { + undoButton->setEnabled(false); + } else { + undoButton->setEnabled(true); + } + if(!area->getRecorder()->redoAvailiable()) { + redoButton->setEnabled(false); + } else { + redoButton->setEnabled(true); + } + }); + + QToolButton* ocrButton = new QToolButton(this); + ocrButton->setIcon(ImageHelper::getIcon("ocr")); + ocrButton->setToolTip(MString::search("{SvJhCjRGF0}提取文字")); + connect(ocrButton, &QToolButton::clicked, this, [=]() { + if(area->save(ILayerControl::Temp, "ocr/1.png")) { + WindowManager::instance()->changeWindow("tray"); + ocrProcess.start(); + } + }); + addWidget(ocrButton); + + QToolButton* clipButton = new QToolButton(this); + clipButton->setIcon(ImageHelper::getIcon("clipboard")); + clipButton->setToolTip(MString::search("{ntbJbEqxwF}复制到剪切板")); + connect(clipButton, &QToolButton::clicked, this, [=]() { + area->save(ILayerControl::ClipBoard, ""); + }); + addWidget(clipButton); + + QToolButton* saveButton = new QToolButton(this); + saveButton->setIcon(ImageHelper::getIcon("save")); + saveButton->setToolTip(MString::search("{pJqTHhEQdb}保存")); + connect(saveButton, &QToolButton::clicked, this, [=]() { + QString fileName = QFileDialog::getSaveFileName(parent, + "保存", + History::instance()->get_last_directory(), + "图片(*.bmp *.jpg *.jpeg *.png);;所有文件(*)"); + if(fileName != "") { + if(area->save(ILayerControl::Persist, fileName)) + WindowManager::instance()->changeWindow("tray"); + } + }); + addWidget(saveButton); + + QToolButton* pinButton = new QToolButton(this); + pinButton->setToolTip(MString::search("{BNzMH1dcwW}钉住")); + pinButton->setIcon(ImageHelper::getIcon("pin")); + connect(pinButton, &QToolButton::clicked, this, [=](){ + QImage image = area->getSaveImage(); + WindowManager::instance()->changeWindow("PinWindow", QPixmap::fromImage(image), area->getSaveRect().toRect()); + }); + addWidget(pinButton); + + + ClipLayerBase* clipLayer = area->getClipLayer(); + if(clipLayer != NULL){ + connect(clipLayer, &ClipLayerBase::boundChangeBegin, this, [=](){ + hideAll(); + }); + connect(clipLayer, &ClipLayerBase::boundChange, this, [=](QRectF bound){ + moveTo(bound); + showAll(); + }); + } + initOcr(); + hideAll(); +} + +void PaintToolbar::initOcr() { + const QString queryCPUNumberOfCores = "wmic cpu get NumberOfCores"; + QProcess queryCPU; + QPair pairResult; + queryCPU.start(queryCPUNumberOfCores); + queryCPU.waitForFinished(); + QString result = QString::fromLocal8Bit(queryCPU.readAllStandardOutput()); + QStringList list = queryCPUNumberOfCores.split(" "); + result = result.remove(list.last(), Qt::CaseInsensitive); + result = result.replace("\r", ""); + result = result.replace("\n", ""); + result = result.simplified(); + pairResult.first = result.toInt(); + int numCore = pairResult.first; + QStringList args; + QDir dir("ocr/models"); + QDir dir2("ocr"); + args << "--models" << "models/" + << "--det" << "ch_PP-OCRv3_det_infer.onnx" + << "--cls" << "ch_ppocr_mobile_v2.0_cls_infer.onnx" + << "--rec" << "ch_PP-OCRv3_rec_infer.onnx" + << "--keys" << "ppocr_keys_v1.txt" + << "--image" << "1.png" + << "--numThread" << QString::number(numCore) + << "--padding" << "50" + << "--maxSideLen" << "1024" + << "--boxScoreThresh" << "0.5" + << "--boxThresh" << "0.3" + << "--unClipRatio" << "1.6" + << "--doAngle" << "1" + << "--mostAngle" << "1"; + ocrProcess.setProgram(dir2.absolutePath() + "/RapidOcrOnnx.exe"); + ocrProcess.setArguments(args); + ocrProcess.setWorkingDirectory(dir2.absolutePath()); + connect(&ocrProcess, static_cast(&QProcess::finished), this, [=](int exitCode, QProcess::ExitStatus exitStatus) { + if(exitStatus == QProcess::NormalExit) { + showOcrResultProcess.startDetached(); + } + }); + showOcrResultProcess.setProgram("OcrViewer.exe"); + showOcrResultProcess.setWorkingDirectory(QDir::currentPath()); +} + +QWidget* PaintToolbar::getAttributeBar(){ + return attributeBar; +} + +void PaintToolbar::reset(){ + setContainer(paintLayerContainer); +} diff --git a/GraphicsScene/Widgets/painttoolbar.h b/GraphicsScene/Widgets/painttoolbar.h new file mode 100644 index 0000000..7ef9727 --- /dev/null +++ b/GraphicsScene/Widgets/painttoolbar.h @@ -0,0 +1,21 @@ +#ifndef PAINTTOOLBAR_H +#define PAINTTOOLBAR_H +#include "layertoolbar.h" +#include +#include "../Container/paintlayercontainer.h" + +class PaintToolbar : public LayerToolBar +{ +public: + PaintToolbar(PaintArea* area, QWidget* parent=nullptr); + QWidget* getAttributeBar(); + void reset(); +private: + void initOcr(); +private: + QProcess ocrProcess; + QProcess showOcrResultProcess; + PaintLayerContainer* paintLayerContainer; +}; + +#endif // PAINTTOOLBAR_H diff --git a/GraphicsScene/paintarea.cpp b/GraphicsScene/paintarea.cpp index ddabf91..3fc5987 100644 --- a/GraphicsScene/paintarea.cpp +++ b/GraphicsScene/paintarea.cpp @@ -14,10 +14,12 @@ PaintArea::PaintArea(QWidget* parent) : container(NULL), inLayer(false), press(false), + _save(false), mouseGrabber(NULL), rootLayer(new RootLayer(this)), clipLayer(NULL), - recorder(new Recorder(this)) + recorder(new Recorder(this)), + registered(false) { connect(recorder, &Recorder::recordChange, this, [=](){ emit recordChange(); @@ -25,7 +27,11 @@ PaintArea::PaintArea(QWidget* parent) : } void PaintArea::mousePressEvent(QGraphicsSceneMouseEvent *event){ + if(registered){ + if(f(event->button())) return; + } press = true; + for(auto& layer: layers){ if((layer->isEnable()) && layer->contains(layer->mapFromScene(event->scenePos()))){ // sendEvent(layer, event); @@ -85,7 +91,7 @@ bool PaintArea::save(SaveType type, const QString &path){ int height = bound.height() - i > 32700 ? 32700 : bound.height() - i; QRect temp_rect(bound.left(), bound.top()+i, bound.width(), height); QImage image(bound.width(), height, QImage::Format_ARGB32); - // image.fill(Qt::transparent); + image.fill(Qt::transparent); QPainter painter(&image); render(&painter, QRectF(QPointF(0, 0), image.size()), temp_rect); cv::Mat temp_mat = ImageHelper::QImage2Mat(image); @@ -102,6 +108,7 @@ bool PaintArea::save(SaveType type, const QString &path){ for(auto& layer: layers){ layer->endSave(); } + _save = true; return true; } @@ -164,7 +171,7 @@ void PaintArea::addLayer(LayerBase *layer){ layer->setParentItem(rootLayer); layer->setZValue(layer->getZValue()); ClipLayerBase* clipLayer = dynamic_cast(layer); - if(clipLayer != NULL) { + if(clipLayer != NULL && this->clipLayer == NULL) { this->clipLayer = clipLayer; } // addItem(layer); @@ -210,10 +217,11 @@ void PaintArea::reset(){ this->modifiedImage = QImage(); this->modified = false; imageValid = false; - this->container = NULL; inLayer = false; + _save = false; focusLayer = NULL; - for(LayerBase* layer : layers){ + auto layerBak = layers; + for(LayerBase* layer : layerBak){ layer->reset(); } recorder->reset(); @@ -246,3 +254,12 @@ void PaintArea::record(RecordBase *record){ Recorder* PaintArea::getRecorder(){ return recorder; } + +bool PaintArea::isSave(){ + return _save; +} + +void PaintArea::registerMousePressHook(const std::function &f){ + registered = true; + this->f = f; +} diff --git a/GraphicsScene/paintarea.h b/GraphicsScene/paintarea.h index 8e88cc9..237e9ec 100644 --- a/GraphicsScene/paintarea.h +++ b/GraphicsScene/paintarea.h @@ -34,6 +34,8 @@ class PaintArea : public QGraphicsScene, public ILayerControl, public LayerManag Recorder* getRecorder(); QImage getSaveImage(); QRectF getSaveRect(); + bool isSave(); + void registerMousePressHook(std::functionconst& f); signals: void recordChange(); @@ -42,10 +44,13 @@ class PaintArea : public QGraphicsScene, public ILayerControl, public LayerManag LayerContainer* container; bool inLayer; bool press; + bool _save; QGraphicsItem* mouseGrabber; RootLayer* rootLayer; ClipLayerBase* clipLayer; Recorder* recorder; + std::function f; + bool registered; }; #endif // PAINTAREA_H diff --git a/Helper/common.h b/Helper/common.h index ce6d621..ce4e778 100644 --- a/Helper/common.h +++ b/Helper/common.h @@ -37,10 +37,10 @@ static void createDirWithFile(QString filePath) { static void changeWindowHelper(){ if(Config::getConfig(Config::capture_mode) == (int)Config::SCROLL_CAPTURE){ - WindowManager::changeWindow("ScrollerWindow"); + WindowManager::instance()->changeWindow("ScrollerWindow"); } else{ - WindowManager::changeWindow("CaptureWindow"); + WindowManager::instance()->changeWindow("CaptureWindow"); } } diff --git a/Helper/global.h b/Helper/global.h new file mode 100644 index 0000000..3ad37ae --- /dev/null +++ b/Helper/global.h @@ -0,0 +1,6 @@ +#ifndef GLOBAL_H +#define GLOBAL_H + +#define DEFAULT_ICON_SIZE 24 + +#endif // GLOBAL_H diff --git a/Helper/imagehelper.cpp b/Helper/imagehelper.cpp index 114e8a8..dd19bb5 100644 --- a/Helper/imagehelper.cpp +++ b/Helper/imagehelper.cpp @@ -168,6 +168,7 @@ QIcon ImageHelper::getIcon(QString name, int pt_w, int pt_h){ QPixmap ImageHelper::getPixmap(QString name, int pt_w, int pt_h){ QSvgRenderer render; render.load(":/image/" + name + ".svg"); + QPixmap pix(pt2px(pt_w), pt2px(pt_h)); pix.fill(Qt::transparent); QPainter painter(&pix); diff --git a/Helper/imagehelper.h b/Helper/imagehelper.h index 0194c93..deb05d2 100644 --- a/Helper/imagehelper.h +++ b/Helper/imagehelper.h @@ -7,6 +7,8 @@ #define WIN32_LEAN_AND_MEAN #include #include +#include "global.h" + class ImageHelper { public: static QImage Mat2QImage(cv::Mat const& src); @@ -21,8 +23,8 @@ class ImageHelper { static QPixmap grabScreen(int index, WId wid); static QPixmap grabScreen(int x, int y, int width, int height); static QPixmap grabScreen(int index, int x, int y, int width, int height); - static QIcon getIcon(QString name, int pt_w=24, int pt_h=24); - static QPixmap getPixmap(QString name, int pt_w=24, int pt_h=24); + static QIcon getIcon(QString name, int pt_w=DEFAULT_ICON_SIZE, int pt_h=DEFAULT_ICON_SIZE); + static QPixmap getPixmap(QString name, int pt_w=DEFAULT_ICON_SIZE, int pt_h=DEFAULT_ICON_SIZE); }; #endif // IMAGE_HELPER_H diff --git a/MainFilter.cpp b/MainFilter.cpp index b643666..e34d7d7 100644 --- a/MainFilter.cpp +++ b/MainFilter.cpp @@ -60,7 +60,7 @@ bool MainFilter::nativeEventFilter(const QByteArray &eventType, void *message, l changeWindowHelper(); break; case 1: - WindowManager::changeWindow("tray"); + WindowManager::instance()->changeWindow("tray"); QTimer::singleShot(200, this, [=]() { QPixmap map = ImageHelper::grabScreen(); QString save_path = Config::getConfig(Config::total_capture_save_path); @@ -77,18 +77,18 @@ bool MainFilter::nativeEventFilter(const QByteArray &eventType, void *message, l }); break; case 2: - if(WindowManager::getNowWindow() == "CaptureWindow") { - WindowManager::getWindow("CaptureWindow")->startCaptureVideo(); + if(WindowManager::instance()->getNowWindow() == "CaptureWindow") { + WindowManager::instance()->getWindow("CaptureWindow")->startCaptureVideo(); } break; case 3: - if(WindowManager::getNowWindow() == "CaptureWindow") { - WindowManager::getWindow("CaptureWindow")->pauseCaptureVideo(); + if(WindowManager::instance()->getNowWindow() == "CaptureWindow") { + WindowManager::instance()->getWindow("CaptureWindow")->pauseCaptureVideo(); } break; case 4: - if(WindowManager::getNowWindow() == "CaptureWindow") { - WindowManager::getWindow("CaptureWindow")->stopCaptureVideo(); + if(WindowManager::instance()->getNowWindow() == "CaptureWindow") { + WindowManager::instance()->getWindow("CaptureWindow")->stopCaptureVideo(); } break; @@ -101,7 +101,7 @@ bool MainFilter::nativeEventFilter(const QByteArray &eventType, void *message, l } void MainFilter::windowMnaagerThread() { - WindowManager::controlWindowClose(); + WindowManager::instance()->controlWindowClose(); } void MainFilter::stopTimer() { @@ -122,13 +122,13 @@ void MainFilter::setTrayContextMenu() { QAction* close = new QAction(this); close->setText(MString::search("{FuBCvgW4BE}关闭")); connect(close, &QAction::triggered, this, [=]() { - WindowManager::close(); + WindowManager::instance()->close(); }); QAction* setting = new QAction(this); setting->setText(MString::search("{De720dAaY1}设置")); connect(setting, &QAction::triggered, this, [=]() { - WindowManager::changeWindow("Setting"); + WindowManager::instance()->changeWindow("Setting"); }); QAction* update = new QAction(this); @@ -169,14 +169,14 @@ void MainFilter::setTrayContextMenu() { int index = index_var.toInt(); Config::setConfig(Config::capture_mode, index); if(index == (int)Config::RECT_CAPTURE || index == (int)Config::FREE_CAPTURE) - WindowManager::changeWindow("CaptureWindow"); + WindowManager::instance()->changeWindow("CaptureWindow"); else if(index == (int)Config::SCROLL_CAPTURE) - WindowManager::changeWindow("ScrollerWindow"); + WindowManager::instance()->changeWindow("ScrollerWindow"); else if(index == Config::TOTAL_CAPTURE) { - WindowManager::changeWindow("tray"); + WindowManager::instance()->changeWindow("tray"); QTimer::singleShot(200, this, [=]() { QPixmap map = ImageHelper::grabScreen(); - WindowManager::changeWindow("PaintWindow", map, ImageHelper::getCurrentScreen()->geometry()); + WindowManager::instance()->changeWindow("PaintWindow", map, ImageHelper::getCurrentScreen()->geometry()); if(Config::getConfig(Config::clip_voice)) QSound::play(":/audio/screenshot.wav"); }); diff --git a/Manager/WindowManager.cpp b/Manager/WindowManager.cpp index e32cc15..68b54cc 100644 --- a/Manager/WindowManager.cpp +++ b/Manager/WindowManager.cpp @@ -7,12 +7,13 @@ #include "KeyManager.h" #include "../MainFilter.h" -QMap WindowManager::windowList = - QMap(); -QString WindowManager::activeWindow = "tray"; -QString WindowManager::previousWindow = NULL; - -WindowManager::WindowManager() {} +WindowManager::WindowManager() + : activeWindow("tray"), + previousWindow("") +{ + timer = new QTimer(this); + connect(timer, &QTimer::timeout, this, &WindowManager::controlWindowClose); +} //延时删除,加快窗口间的切换速度 void WindowManager::controlWindowClose() { @@ -38,7 +39,7 @@ void WindowManager::controlWindowClose() { temp_list[i]->deleteLater(); } if(windowList.size() == 0) { - MainFilter::instance()->stopTimer(); + timer->stop(); } } @@ -82,8 +83,9 @@ void WindowManager::changeWindow(QString name, QVariant data1, QVariant data2) { } KeyManager::instance()->onWindowChangeEnd(name); } - if(!MainFilter::instance()->isTimerRun()) { - MainFilter::instance()->startTimer(); + if(!timer->isActive()) { + int time = Config::getConfig(Config::clear_interval); + timer->start(time * 1000); } } diff --git a/Manager/WindowManager.h b/Manager/WindowManager.h index 2678b28..4347354 100644 --- a/Manager/WindowManager.h +++ b/Manager/WindowManager.h @@ -8,54 +8,58 @@ #include #include #include +#include "../Helper/Template.h" +#include using namespace std; /** * @brief The WindowManager class * 用来管理窗口的启动,切换和销毁。窗体必须继承@ref WindowBase 并且需要调用@ref Reflect::registerClass() 注册窗体 */ -class WindowManager { +class WindowManager : public QObject{ + Q_OBJECT + DECLARE_INSTANCE(WindowManager) public: friend class MainFilter; WindowManager(); - static void pushWindow(QString name, WindowBase* widget); - + void pushWindow(QString name, WindowBase* widget); /** * @brief changeWindow 切换到某个窗口,如果窗口不存在则创建 * @param name 窗体的类名称 */ - static void changeWindow(QString name, QVariant data1=QVariant(), QVariant data2=QVariant()); + void changeWindow(QString name, QVariant data1=QVariant(), QVariant data2=QVariant()); /** * @brief openWindow 开启窗口,原窗口不关闭 * @param name * @see checkWindow() */ - static void openWindow(QString name); + void openWindow(QString name); /** * @brief checkWindow 切换回原窗口,并关闭当前窗口,切换过去的窗口并未关闭 * @see openWindow() */ - static void checkWindow(); - static QString getNowWindow(); - static void popWindow(); - static bool contains(QString name); - static WindowBase* getWindow(QString name); - static void close(); + void checkWindow(); + QString getNowWindow(); + void popWindow(); + bool contains(QString name); + WindowBase* getWindow(QString name); + void close(); /** * @brief controlWindowClose 控制窗体的销毁,可以通过设置 clear_interval 控制销毁时间 */ - static void controlWindowClose(); - static void closeWindow(QString name); - static void createWindow(QString name); + void controlWindowClose(); + void closeWindow(QString name); + void createWindow(QString name); private: struct WindowData { qint64 time; WindowBase* window; }; - static QMap windowList; - static QString activeWindow; - static QString previousWindow; - static WindowData createData(WindowBase* window); + QMap windowList; + QString activeWindow; + QString previousWindow; + QTimer* timer; + WindowData createData(WindowBase* window); }; diff --git a/Manager/update.cpp b/Manager/update.cpp index a412de6..3b169da 100644 --- a/Manager/update.cpp +++ b/Manager/update.cpp @@ -203,7 +203,7 @@ void Update::on_update() { if(ans == QMessageBox::Yes) { qInfo() << "正在更新"; if(QProcess::startDetached("Upgrate.exe"))//开启更新程序 - WindowManager::close(); + WindowManager::instance()->close(); else qWarning("更新程序未启动"); onFinish(); @@ -213,7 +213,7 @@ void Update::on_update() { QStringList args; args << "terminal"; if(QProcess::startDetached("Upgrate.exe", args))//开启更新程序 - WindowManager::close(); + WindowManager::instance()->close(); else qWarning("更新程序未启动"); onFinish(); diff --git a/Resource/keys.xml b/Resource/keys.xml index 2eeb40f..d67f9ca 100644 --- a/Resource/keys.xml +++ b/Resource/keys.xml @@ -32,10 +32,6 @@ - - - - @@ -52,30 +48,24 @@ - - - + - - - + - - diff --git a/Setting/setting.cpp b/Setting/setting.cpp index df1a844..0e5f7c9 100644 --- a/Setting/setting.cpp +++ b/Setting/setting.cpp @@ -289,7 +289,7 @@ void Setting::aboutTab() { } void Setting::closeEvent(QCloseEvent *event) { - WindowManager::checkWindow(); + WindowManager::instance()->checkWindow(); event->accept(); } diff --git a/Style_widget/ColorWidget.ui b/Style_widget/ColorWidget.ui deleted file mode 100644 index 2b15244..0000000 --- a/Style_widget/ColorWidget.ui +++ /dev/null @@ -1,697 +0,0 @@ - - - ColorWidget - - - - 0 - 0 - 126 - 42 - - - - - 0 - 0 - - - - Form - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 21 - 21 - - - - background-color: rgba(56, 142, 60, 255); - - - - - - - - - - - 21 - 21 - - - - - 21 - 21 - - - - background-color: rgba(255, 255, 255, 255); - - - - - - - - - - - 0 - 0 - - - - - 21 - 21 - - - - - 21 - 21 - - - - background-color: rgba(251, 192, 45, 255) - - - - - - - - - - - 21 - 21 - - - - - 21 - 21 - - - - background-color: rgba(0, 0, 0, 1) - - - - - - - - - - - 0 - 0 - - - - - 21 - 21 - - - - - 21 - 21 - - - - - 0 - 0 - - - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 61 - 0 - - - - - - - 255 - 127 - 127 - - - - - - - 255 - 63 - 63 - - - - - - - 127 - 0 - 0 - - - - - - - 170 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 61 - 0 - - - - - - - 255 - 61 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 127 - 127 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 61 - 0 - - - - - - - 255 - 127 - 127 - - - - - - - 255 - 63 - 63 - - - - - - - 127 - 0 - 0 - - - - - - - 170 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 61 - 0 - - - - - - - 255 - 61 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 127 - 127 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - - - 127 - 0 - 0 - - - - - - - 255 - 61 - 0 - - - - - - - 255 - 127 - 127 - - - - - - - 255 - 63 - 63 - - - - - - - 127 - 0 - 0 - - - - - - - 170 - 0 - 0 - - - - - - - 127 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 127 - 0 - 0 - - - - - - - 255 - 61 - 0 - - - - - - - 255 - 61 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 0 - 0 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - - background-color: rgba(255, 61, 0, 255); - - - - - - - - - - - 21 - 21 - - - - - 21 - 21 - - - - background-color: rgba(2, 136, 209, 255) - - - - - - - - - - - 21 - 21 - - - - - 21 - 21 - - - - background-color: rgba(123, 31, 162, 255); - - - - - - - - - - - 0 - 0 - - - - - 42 - 42 - - - - - 42 - 42 - - - - - - - - - - - - 21 - 21 - - - - - 21 - 21 - - - - background-color: rgba(0, 121, 107, 255); - - - - - - - - - - - diff --git a/Style_widget/colorwidget.cpp b/Style_widget/colorwidget.cpp index d8e2a13..a201e22 100644 --- a/Style_widget/colorwidget.cpp +++ b/Style_widget/colorwidget.cpp @@ -1,27 +1,33 @@ #include "colorwidget.h" -#include "ui_ColorWidget.h" #include #include #include #include "../Helper/mstring.h" #include #include +#include "../Helper/global.h" +#include "../Helper/common.h" -ColorWidget::ColorWidget(QWidget* parent) : QWidget(parent), ui(new Ui::ColorWidget) { - ui->setupUi(this); +ColorWidget::ColorWidget(QWidget* parent) : QWidget(parent) { setAttribute(Qt::WA_StyledBackground); default_color = Qt::red; ex.setPattern("background-color:\\s*rgba\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*\\d+\\s*\\)*"); - connect(ui->red, &QToolButton::clicked, this, &ColorWidget::onDefaultClick); - connect(ui->blue, &QToolButton::clicked, this, &ColorWidget::onDefaultClick); - connect(ui->yellow, &QToolButton::clicked, this, &ColorWidget::onDefaultClick); - connect(ui->green, &QToolButton::clicked, this, &ColorWidget::onDefaultClick); - connect(ui->dark_red, &QToolButton::clicked, this, &ColorWidget::onDefaultClick); - connect(ui->dark_green, &QToolButton::clicked, this, &ColorWidget::onDefaultClick); - connect(ui->black, &QToolButton::clicked, this, &ColorWidget::onDefaultClick); - connect(ui->white, &QToolButton::clicked, this, &ColorWidget::onDefaultClick); - ui->current->setToolTip(MString::search("{DepMhoivvx}当前颜色")); - connect(ui->current, &QToolButton::clicked, this, [=]() { + layout = new QGridLayout(); + layout->setSpacing(0); + layout->setContentsMargins(0, 0, 0, 0); + addDefaultButton(QColor(255, 61, 0), 0, 2); + addDefaultButton(QColor(2, 136, 209), 0, 3); + addDefaultButton(QColor(255, 255, 255), 0, 4); + addDefaultButton(QColor(0, 121, 107), 0, 5); + addDefaultButton(QColor(251, 192, 45), 1, 2); + addDefaultButton(QColor(56, 142, 60), 1, 3); + addDefaultButton(QColor(0, 0, 0), 1, 4); + addDefaultButton(QColor(123, 31, 162), 1, 5); + current = new QToolButton(this); + current->setObjectName("current"); + current->setToolTip(MString::search("{DepMhoivvx}当前颜色")); + current->setMinimumSize(pt2px(DEFAULT_ICON_SIZE), pt2px(DEFAULT_ICON_SIZE)); + connect(current, &QToolButton::clicked, this, [=]() { QColorDialog dialog; QColor color = dialog.getColor(color, this, MString::search("{6Of41PN3eL}选择字体颜色"), QColorDialog::ShowAlphaChannel); @@ -29,21 +35,23 @@ ColorWidget::ColorWidget(QWidget* parent) : QWidget(parent), ui(new Ui::ColorWid int r = 0, g = 0, b = 0; color.getRgb(&r,&g,&b); this->default_color.setRgb(r, g, b); - ui->current->setStyleSheet(QString("background-color: rgba(%1,%2,%3, 1)").arg(r).arg(g).arg(b)); + current->setStyleSheet(QString("background-color: rgba(%1,%2,%3, 1)").arg(r).arg(g).arg(b)); emit colorChange(default_color); } }); + layout->addWidget(current, 0, 0, 2, 2); + setLayout(layout); } ColorWidget::~ColorWidget() { - delete ui; + } void ColorWidget::setCurrentStyle(QColor color) { int r = 0, g = 0, b = 0, a = 0; default_color = color; default_color.getRgb(&r,&g,&b, &a); - ui->current->setStyleSheet(QString("background-color: rgba(%1,%2,%3, 1)").arg(r).arg(g).arg(b)); + current->setStyleSheet(QString("background-color: rgba(%1,%2,%3, 1)").arg(r).arg(g).arg(b)); emit colorChange(default_color); } @@ -56,7 +64,7 @@ void ColorWidget::onDefaultClick() { g = ex.capturedTexts().at(2).toInt(); b = ex.capturedTexts().at(3).toInt(); default_color.setRgb(r, g, b); - ui->current->setStyleSheet(QString("background-color: rgba(%1,%2,%3, 1)").arg(r).arg(g).arg(b)); + current->setStyleSheet(QString("background-color: rgba(%1,%2,%3, 1)").arg(r).arg(g).arg(b)); emit colorChange(default_color); } } @@ -67,3 +75,12 @@ void ColorWidget::paintEvent(QPaintEvent *event) { QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } + +void ColorWidget::addDefaultButton(QColor color, int x, int y){ + QToolButton* button = new QToolButton(this); + button->setMaximumSize(pt2px(DEFAULT_ICON_SIZE)/2, pt2px(DEFAULT_ICON_SIZE)/2); + button->setStyleSheet(QString("background-color: rgba(%1, %2, %3, 1);") + .arg(color.red()).arg(color.green()).arg(color.blue())); + connect(button, &QToolButton::clicked, this, &ColorWidget::onDefaultClick); + layout->addWidget(button, x, y); +} diff --git a/Style_widget/colorwidget.h b/Style_widget/colorwidget.h index 7d67893..c662cc2 100644 --- a/Style_widget/colorwidget.h +++ b/Style_widget/colorwidget.h @@ -4,12 +4,7 @@ #include #include #include - -QT_BEGIN_NAMESPACE -namespace Ui { -class ColorWidget; -} -QT_END_NAMESPACE +#include class ColorWidget : public QWidget { Q_OBJECT @@ -23,10 +18,14 @@ class ColorWidget : public QWidget { private slots: void onDefaultClick(); +private: + void addDefaultButton(QColor color, int x, int y); + private: QRegExp ex; QColor default_color; - Ui::ColorWidget* ui; + QGridLayout* layout; + QToolButton* current; }; #endif // COLORWIDGET_H diff --git a/Windows/capturewindow.cpp b/Windows/capturewindow.cpp index 3b16f12..6469482 100644 --- a/Windows/capturewindow.cpp +++ b/Windows/capturewindow.cpp @@ -22,6 +22,7 @@ #include "Helper/math.h" #include #include +#include "../GraphicsScene/Layer/piclayer.h" //#include "Widgets/capturetip.h" bool CaptureWindow::end_scroll = false; @@ -46,18 +47,21 @@ CaptureWindow::CaptureWindow(QWidget *parent) : setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_OpaquePaintEvent ); + setIconSize(QSize(pt2px(DEFAULT_ICON_SIZE), pt2px(DEFAULT_ICON_SIZE))); // showFullScreen(); this->setMouseTracking(true); centralWidget->setMouseTracking(true); #ifdef QT_NO_DEBUG - setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); + // setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); #endif // ui->centralwidget->setGeometry(QGuiApplication::primaryScreen()->geometry()); setGeometry(ImageHelper::getCurrentScreen()->geometry()); view = new QGraphicsView(this); area = new PaintArea(view); - defaultToolbar = new DefaultToolbar(area, this); + defaultToolbar = new DefaultToolbar(area, view); + PicLayer* picLayer = new PicLayer("pic", area, false, NULL); + area->addLayer(picLayer); view->setScene(area); view->setStyleSheet(".QGraphicsView{background: transparent;border:0px;}"); @@ -135,36 +139,32 @@ void CaptureWindow::loadKeyEvent(QString name) { // { KeyManager::instance()->addFunc(this, name, "leave", [=](bool is_enter) { if(is_enter) { - WindowManager::changeWindow("tray"); + WindowManager::instance()->changeWindow("tray"); } }); KeyManager::instance()->addFunc(this, name, "capture_rect", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) - defaultToolbar->onGroupClick(0); + defaultToolbar->simulateClick(0); }); KeyManager::instance()->addFunc(this, name, "capture_mosaic", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) - defaultToolbar->onGroupClick(1); + defaultToolbar->simulateClick(1); }); KeyManager::instance()->addFunc(this, name, "capture_cursor", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) - defaultToolbar->onGroupClick(2); + defaultToolbar->simulateClick(2); }); KeyManager::instance()->addFunc(this, name, "capture_pencil", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) - defaultToolbar->onGroupClick(3); - }); - KeyManager::instance()->addFunc(this, name, "capture_highlighter", [=](bool is_enter) { - if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) - defaultToolbar->onGroupClick(4); + defaultToolbar->simulateClick(3); }); KeyManager::instance()->addFunc(this, name, "capture_text", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) - defaultToolbar->onGroupClick(5); + defaultToolbar->simulateClick(4); }); KeyManager::instance()->addFunc(this, name, "capture_erase", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) - defaultToolbar->onGroupClick(6); + defaultToolbar->simulateClick(5); }); KeyManager::instance()->addFunc(this, name, "capture_undo", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) @@ -183,14 +183,14 @@ void CaptureWindow::loadKeyEvent(QString name) { KeyManager::instance()->clearKeys("CaptureWindow"); if(file_name != "") { if(area->save(ILayerControl::Persist, file_name)) - WindowManager::changeWindow("tray"); + WindowManager::instance()->changeWindow("tray"); } } }); KeyManager::instance()->addFunc(this, name, "save2clip", [=](bool is_enter) { if(is_enter && !(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE)) { if(area->save(ILayerControl::ClipBoard)) - WindowManager::changeWindow("tray"); + WindowManager::instance()->changeWindow("tray"); } }); KeyManager::instance()->addFunc(this, name, "enter_capture", [=](bool is_enter) { @@ -198,7 +198,7 @@ void CaptureWindow::loadKeyEvent(QString name) { QImage image = area->getSaveImage(); QRect bound = area->getSaveRect().toRect(); bound.moveTo(0, 0); - WindowManager::changeWindow("PaintWindow", QPixmap::fromImage(image), bound); + WindowManager::instance()->changeWindow("PaintWindow", QPixmap::fromImage(image), bound); } }); KeyManager::instance()->addFunc(this, name, "capture_scrollrect", [=](bool is_enter) { @@ -246,6 +246,7 @@ void CaptureWindow::onWindowSelect() { KeyManager::instance()->registerGlobalKey("capture_video_stop"); area->reset(); area->update(); + defaultToolbar->reset(); setGeometry(ImageHelper::getCurrentGeometry()); view->show(); QPixmap p = ImageHelper::grabScreen(); @@ -276,7 +277,7 @@ void CaptureWindow::stopCaptureVideo() { if(!(Config::getConfig(Config::capture_mode) == Config::SCROLL_CAPTURE) && videoCapture->isValid() && isVideoCapture) { isVideoCapture = false; videoCapture->stopCapture(); - WindowManager::changeWindow("tray"); + WindowManager::instance()->changeWindow("tray"); view->show(); } } diff --git a/Windows/paintwindow.cpp b/Windows/paintwindow.cpp index 9e28072..aeed7c1 100644 --- a/Windows/paintwindow.cpp +++ b/Windows/paintwindow.cpp @@ -32,48 +32,54 @@ PaintWindow::PaintWindow(QWidget *parent) : { // ui->setupUi(this); centralWidget = new QWidget(this); + centralWidget->setObjectName("centralWidget"); setCentralWidget(centralWidget); - addToolBar(Qt::TopToolBarArea, toolbar); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - Titlebar* title_bar = new Titlebar(this); - installEventFilter(title_bar); - FramelessHelper* helper = new FramelessHelper(this); - helper->activateOn(this); - helper->setWidgetResizable(true); - helper->setWidgetMovable(true); - helper->setTitleHeight(30); - helper->setRubberBandOnResize(true); - setWindowFlags (Qt::FramelessWindowHint); +// Titlebar* title_bar = new Titlebar(this); +// installEventFilter(title_bar); +// FramelessHelper* helper = new FramelessHelper(this); +// helper->activateOn(this); +// helper->setWidgetResizable(true); +// helper->setWidgetMovable(true); +// helper->setTitleHeight(30); +// helper->setRubberBandOnResize(true); +// setWindowFlags (Qt::FramelessWindowHint); setWindowTitle("简截"); setWindowIcon(QIcon(":/image/avator.png")); // connect(title_bar, &Titlebar::minimize, this, [=]() { - // WindowManager::changeWindow("tray"); + // WindowManager::instance()->changeWindow("tray"); // }); menuBar = new QMenuBar(this); QWidget* menu_widget = new QWidget(this); QVBoxLayout* menu_layout = new QVBoxLayout(); menu_layout->setMargin(0); - menu_layout->addWidget(title_bar); +// menu_layout->addWidget(title_bar); menu_layout->addWidget(menuBar); menu_widget->setLayout(menu_layout); menu_widget->setStyleSheet("background-color: rgb(255, 255, 255)"); setMenuWidget(menu_widget); - layout = new QHBoxLayout(centralWidget); + layout = new QVBoxLayout(centralWidget); this->area = new PaintArea(this); - toolbar = new DefaultToolbar(area, this); + toolbar = new PaintToolbar(area, this); + toolbar->showAll(); + addToolBar(Qt::TopToolBarArea, toolbar); paint_panel = new QGraphicsView(this->area, this); paint_panel->setFrameShape(QFrame::NoFrame); + paint_panel->setViewportUpdateMode(QGraphicsView::FullViewportUpdate); paint_panel->setBackgroundRole(QPalette::Light); paint_panel->setAlignment(Qt::AlignCenter); paint_panel->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); paint_panel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); //paint_panel->setWidgetResizable(true); paint_panel->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); - - layout->addWidget(paint_panel); + QHBoxLayout* toolbarLayout = new QHBoxLayout(); + toolbarLayout->addWidget(toolbar->getAttributeBar()); + toolbarLayout->addStretch(1); + layout->addLayout(toolbarLayout); + layout->addWidget(paint_panel, 1); centralWidget->setLayout(layout); set_menubar(); addToolBarBreak(); @@ -100,7 +106,7 @@ void PaintWindow::loadKeyEvent(QString name) { KeyManager::instance()->clearKeys("PaintWindow"); if(file_name != "") { area->save(ILayerControl::Persist, file_name); - WindowManager::changeWindow("tray"); + WindowManager::instance()->changeWindow("tray"); } } }); @@ -109,7 +115,7 @@ void PaintWindow::loadKeyEvent(QString name) { if(Config::getConfig(Config::capture_mode) == (int)Config::TOTAL_CAPTURE) { QTimer::singleShot(200, this, [=]() { QPixmap map = ImageHelper::grabScreen(); - WindowManager::changeWindow("PaintWindow", map, ImageHelper::getCurrentScreen()->geometry()); + WindowManager::instance()->changeWindow("PaintWindow", map, ImageHelper::getCurrentScreen()->geometry()); if(Config::getConfig(Config::clip_voice)) QSound::play(":/audio/screenshot.wav"); }); @@ -159,7 +165,7 @@ void PaintWindow::set_menubar() { "图片(*.bmp *.jpg *.jpeg *.png);;所有文件(*)"); if(file_name != "") { area->save(ILayerControl::Persist, file_name); - WindowManager::changeWindow("tray"); + WindowManager::instance()->changeWindow("tray"); } }); QAction* history_action = new QAction(MString::search("{Mo0LoFqQqT}历史"), menuBar); @@ -208,6 +214,7 @@ void PaintWindow::receiveData(QVariant data1, QVariant data2){ } reset(); area->setImage(pix.toImage()); + area->setSceneRect(-rect.width()/2, -rect.height()/2, rect.width()*2, rect.height()*2); paint_panel->update(); if(Config::getConfig(Config::auto_copy_to_clipboard)) { QClipboard *clip=QApplication::clipboard(); @@ -221,12 +228,12 @@ void PaintWindow::receiveData(QVariant data1, QVariant data2){ || currentHeight >= (double)geometry.height()) { showMaximized(); } else { - resize(currentWidth, currentHeight);//设置主窗口大小,否则窗口大小不会变化 //左上角移动到指定位置,截图越大越向(0, 0)点接近 move(geometry.x() + (geometry.width()-currentWidth)/2, geometry.y() + (geometry.height() - currentHeight) / 2); + resize(currentWidth, currentHeight);//设置主窗口大小,否则窗口大小不会变化 } - paint_panel->verticalScrollBar()->setValue(rect.height() / 2); - paint_panel->horizontalScrollBar()->setValue(rect.width() / 2); +// paint_panel->verticalScrollBar()->setValue(rect.height() / 2); +// paint_panel->horizontalScrollBar()->setValue(rect.width() / 2); } void PaintWindow::closeEvent(QCloseEvent *event) { @@ -235,16 +242,16 @@ void PaintWindow::closeEvent(QCloseEvent *event) { // { // Close_dialog* close_dialog = new Close_dialog(area, this); // connect(close_dialog, &Close_dialog::hide_paint, this, [=](){ - // WindowManager::changeWindow("MainWindow"); - // WindowManager::hideNow(); + // WindowManager::instance()->changeWindow("MainWindow"); + // WindowManager::instance()->hideNow(); // }); // close_dialog->show(); // } if(Config::getConfig(Config::hide_to_tray)) { - WindowManager::changeWindow("tray"); + WindowManager::instance()->changeWindow("tray"); } else { - WindowManager::close(); + WindowManager::instance()->close(); } } @@ -259,7 +266,7 @@ void PaintWindow::reset() { dir.mkpath(path); } path += "main.png"; - area->save(ILayerControl::Temp, path); + if(!area->isSave() && area->isImageValid()) area->save(ILayerControl::Temp, path); area->reset(); } diff --git a/Windows/paintwindow.h b/Windows/paintwindow.h index d21d04e..6a4f3f1 100644 --- a/Windows/paintwindow.h +++ b/Windows/paintwindow.h @@ -11,7 +11,7 @@ #include #include #include -#include "../GraphicsScene/Widgets/defaulttoolbar.h" +#include "../GraphicsScene/Widgets/painttoolbar.h" //namespace Ui { //class PaintWindow; @@ -42,10 +42,10 @@ class PaintWindow : public WindowBase { private: // Ui::PaintWindow *ui; QWidget* centralWidget; - DefaultToolbar* toolbar; + PaintToolbar* toolbar; PaintArea* area; QGraphicsView* paint_panel; - QHBoxLayout* layout; + QVBoxLayout* layout; QMenuBar* menuBar; }; diff --git a/Windows/pinwindow.cpp b/Windows/pinwindow.cpp index a17064b..4f7b5ef 100644 --- a/Windows/pinwindow.cpp +++ b/Windows/pinwindow.cpp @@ -35,10 +35,10 @@ void PinWindow::receiveData(QVariant data1, QVariant data2){ pinWidgets.removeOne(pinWidget); pinWidget->deleteLater(); if(pinWidgets.size() == 0){ - if(WindowManager::getNowWindow() == "PinWindow"){ - WindowManager::changeWindow("tray"); + if(WindowManager::instance()->getNowWindow() == "PinWindow"){ + WindowManager::instance()->changeWindow("tray"); } - WindowManager::closeWindow("PinWindow"); + WindowManager::instance()->closeWindow("PinWindow"); } }); connect(pinWidget, &PinWidget::closeAll, this, [=](){ @@ -46,10 +46,10 @@ void PinWindow::receiveData(QVariant data1, QVariant data2){ widget->deleteLater(); } pinWidgets.clear(); - if(WindowManager::getNowWindow() == "PinWindow"){ - WindowManager::changeWindow("tray"); + if(WindowManager::instance()->getNowWindow() == "PinWindow"){ + WindowManager::instance()->changeWindow("tray"); } - WindowManager::closeWindow("PinWindow"); + WindowManager::instance()->closeWindow("PinWindow"); }); pinWidget->show(); pinWidgets.append(pinWidget); diff --git a/Windows/scrollerwindow.cpp b/Windows/scrollerwindow.cpp index b73174a..b2d42dc 100644 --- a/Windows/scrollerwindow.cpp +++ b/Windows/scrollerwindow.cpp @@ -50,14 +50,15 @@ ScrollerWindow::ScrollerWindow(QWidget* parent) : WindowBase(parent), connect(timer, &QTimer::timeout, this, [=]() { if(!xHook->isMouseHookRunning() || xHook->uninstallMouseHook()) { timer->stop(); - WindowManager::closeWindow("ScrollerWindow"); + WindowManager::instance()->closeWindow("ScrollerWindow"); } }); connect(dispatcher, &Scroll_dispatcher::finish, this, [=](QImage image) { QPixmap pixmap; pixmap.convertFromImage(image); - WindowManager::changeWindow("PaintWindow", pixmap, QRect(0, 0, image.width(), image.height())); + if(image.width() > 10 && image.height() > 10) + WindowManager::instance()->changeWindow("PaintWindow", pixmap, QRect(0, 0, image.width(), image.height())); timer->start(50); }); @@ -189,7 +190,7 @@ void ScrollerWindow::mousePressEvent(QMouseEvent *event){ bubbleTipsWidget->setFix(false); scrollState = IDLE; } else { - WindowManager::popWindow(); + WindowManager::instance()->popWindow(); timer->start(50); } } @@ -261,7 +262,7 @@ void ScrollerWindow::loadKeyEvent(QString name){ } else if(scrollState == SCROLLRECT_SETTED) { scrollState = IDLE; } else { - WindowManager::changeWindow("tray"); + WindowManager::instance()->changeWindow("tray"); } } }); diff --git a/capture.pro b/capture.pro index 7724abb..9a6b914 100644 --- a/capture.pro +++ b/capture.pro @@ -44,6 +44,7 @@ SOURCES += \ GraphicsScene/Widgets/expandbutton.cpp \ GraphicsScene/Widgets/grabcuthandler.cpp \ GraphicsScene/Widgets/layertoolbar.cpp \ + GraphicsScene/Widgets/painttoolbar.cpp \ GraphicsScene/Widgets/scrollitem.cpp \ GraphicsScene/Widgets/textitem.cpp \ GraphicsScene/ilayercontrol.cpp \ @@ -135,6 +136,7 @@ HEADERS += \ GraphicsScene/Widgets/expandbutton.h \ GraphicsScene/Widgets/grabcuthandler.h \ GraphicsScene/Widgets/layertoolbar.h \ + GraphicsScene/Widgets/painttoolbar.h \ GraphicsScene/Widgets/scrollitem.h \ GraphicsScene/Widgets/textitem.h \ GraphicsScene/ilayercontrol.h \ @@ -148,6 +150,7 @@ HEADERS += \ Helper/Template.h \ Helper/common.h \ Helper/debug.h \ + Helper/global.h \ Helper/imagehelper.h \ Helper/log.h \ Helper/math.h \ @@ -202,7 +205,6 @@ HEADERS += \ FORMS += \ Setting/setting.ui \ - Style_widget/ColorWidget.ui \ Style_widget/bubbletipswidget.ui \ Tests/testwidget.ui diff --git a/theme/default/CaptureWindow.qss b/theme/default/CaptureWindow.qss index 7def221..8354262 100644 --- a/theme/default/CaptureWindow.qss +++ b/theme/default/CaptureWindow.qss @@ -22,14 +22,10 @@ QToolBar::separator { } .ColorWidget QToolButton{ - margin: 1px; - border-radius: 3px; + border-radius: 2px; border: 1px solid #CDCDCD; } -QToolButton#rectButton, QToolButton#arrowButton{ - min-width: 42px; -} QToolButton { @@ -93,7 +89,7 @@ QSpinBox::up-button { margin-right: 2px; min-width: 30px; max-width: 30px; - min-height: 20px; + min-height: 10px; } QSpinBox::up-button:hover { @@ -114,7 +110,7 @@ QSpinBox::down-button { margin-right: 2px; min-width: 30px; max-width: 30px; - min-height: 20px; + min-height: 10px; } QSpinBox::down-button:hover { From 808d556f9a283a8783eed3f6ad9ed5d744e2c89b Mon Sep 17 00:00:00 2001 From: xinhecuican <2686462757@qq.com> Date: Mon, 15 Jan 2024 20:34:17 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E6=B7=BB=E5=8A=A0maskcolor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Container/blurlayercontainer.cpp | 135 ++++++++++++++++-- GraphicsScene/Container/blurlayercontainer.h | 16 +++ GraphicsScene/Container/layercontainer.h | 1 + .../Container/paintlayercontainer.cpp | 6 +- GraphicsScene/Layer/blurlayer.cpp | 1 - GraphicsScene/Layer/grabcutlayer.cpp | 2 + GraphicsScene/Layer/maskcolorlayer.cpp | 51 +++++++ GraphicsScene/Layer/maskcolorlayer.h | 24 ++++ GraphicsScene/Layer/paintlayer.cpp | 2 +- GraphicsScene/Layer/piclayer.cpp | 1 - GraphicsScene/Layer/textlayer.cpp | 4 + GraphicsScene/Layer/textlayer.h | 1 + GraphicsScene/Widgets/colorpicker.cpp | 12 +- GraphicsScene/Widgets/defaulttoolbar.cpp | 15 +- GraphicsScene/Widgets/defaulttoolbar.h | 2 +- GraphicsScene/Widgets/layertoolbar.cpp | 16 +++ GraphicsScene/Widgets/layertoolbar.h | 2 + GraphicsScene/Widgets/painttoolbar.cpp | 1 + GraphicsScene/Widgets/painttoolbar.h | 2 +- GraphicsScene/Widgets/textitem.cpp | 1 + GraphicsScene/ilayercontrol.cpp | 20 +++ GraphicsScene/ilayercontrol.h | 2 + GraphicsScene/paintarea.cpp | 42 ++++-- GraphicsScene/paintarea.h | 10 +- Resource/Languages/chinese.xml | 2 + Resource/Resources.qrc | 1 + Resource/color_mask.svg | 1 + Windows/capturewindow.cpp | 4 +- Windows/paintwindow.cpp | 2 +- capture.pro | 2 + main.cpp | 1 + 31 files changed, 344 insertions(+), 38 deletions(-) create mode 100644 GraphicsScene/Layer/maskcolorlayer.cpp create mode 100644 GraphicsScene/Layer/maskcolorlayer.h create mode 100644 Resource/color_mask.svg diff --git a/GraphicsScene/Container/blurlayercontainer.cpp b/GraphicsScene/Container/blurlayercontainer.cpp index ee1597b..8248b52 100644 --- a/GraphicsScene/Container/blurlayercontainer.cpp +++ b/GraphicsScene/Container/blurlayercontainer.cpp @@ -5,34 +5,49 @@ #include "../../Helper/imagehelper.h" #include #include +#include BlurLayerContainer::BlurLayerContainer(PaintArea* area) : LayerContainer(area), type(0), - windowSize(10) + windowSize(10), + valid(false) { blurLayer = new BlurLayer("blur", area, area->getRootLayer()); blurLayer->setEnable(false); grabcutLayer = new GrabcutLayer("grabcut", area, area->getRootLayer()); + maskColorLayer = new MaskColorLayer("maskColor", area, area->getRootLayer()); + colorPicker = new ColorPicker(area, maskColorLayer); + colorPicker->hide(); area->addLayer(blurLayer); area->addLayer(grabcutLayer); + area->addLayer(maskColorLayer); + area->registerMouseMoveHook([=](QPointF pos){ + if(type == 2 && valid){ + colorPicker->setPosition(pos); + } + }); + area->registerMousePressHook([=](QPointF pos){ + if(type == 2 && valid){ + addColor(area->getImage().pixel(pos.x(), pos.y())); + } + }); + maskColorCombo = NULL; } QWidget* BlurLayerContainer::onValid(QWidget *widgetParent) { + valid = true; area->setEnable(false, blurLayer->type()); if(type == 1){ grabcutLayer->setEnableShow(); + grabcutLayer->setFocus(); + } + else if(type == 2){ + colorPicker->show(); } if(!initWidget(widgetParent)){ QButtonGroup* group = new QButtonGroup(widgetParent); group->setExclusive(true); - connect(group, static_cast(&QButtonGroup::buttonClicked), - this, [=](int id) { - type = id; - if(type == 1){ - grabcutLayer->setEnableShow(); - } - }); QToolButton* mosaicButton = new QToolButton(widgetParent); mosaicButton->setToolTip(MString::search("{capture_mosaic}马赛克")); mosaicButton->setIcon(ImageHelper::getIcon("blur")); @@ -46,6 +61,11 @@ QWidget* BlurLayerContainer::onValid(QWidget *widgetParent) { grabcutButton->setIconSize(QSize(DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE)); grabcutButton->setCheckable(true); group->addButton(grabcutButton, 1); + QToolButton* colorMaskButton = new QToolButton(widgetParent); + colorMaskButton->setIcon(ImageHelper::getIcon("color_mask")); + colorMaskButton->setIconSize(QSize(DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE)); + colorMaskButton->setCheckable(true); + group->addButton(colorMaskButton, 2); QSpinBox* mosaicSize = new QSpinBox(widgetParent); mosaicSize->setRange(2, 30); @@ -57,13 +77,78 @@ QWidget* BlurLayerContainer::onValid(QWidget *widgetParent) { connect(mosaicSize, static_cast(&QSpinBox::valueChanged), this, [=](int value) { windowSize = value; }); + + helpButton = new QToolButton(widgetParent); + helpButton->setIcon(ImageHelper::getIcon("help")); + helpButton->setToolTip(MString::search("{9VxwER0qFT}左键选择保留区域") + + "\n" + + MString::search("{6IqemrYceD}右键选择要删除的颜色")); + helpButton->hide(); + + maskColorCombo = new QComboBox(widgetParent); + maskColorCombo->setEditable(false); + maskColorCombo->setAutoFillBackground(true); + connect(maskColorCombo, static_cast(&QComboBox::currentIndexChanged), + this, [=](const QString &text){ + int splitter1 = text.indexOf(','); + int splitter2 = text.indexOf(',', splitter1+1); + int red = text.mid(0, splitter1).toInt(); + int green = text.mid(splitter1+1, splitter2-splitter1-1).toInt(); + int blue = text.mid(splitter2+1).toInt(); + maskColorCombo->setStyleSheet(QString("background-color: rgb(%1,%2,%3)").arg(red).arg(green).arg(blue)); + }); + maskColorCombo->hide(); + removeButton = new QToolButton(widgetParent); + removeButton->setIcon(ImageHelper::getIcon("delete")); + connect(removeButton, &QToolButton::clicked, this, [=](){ + if(maskColorCombo->count()<=0){ + return; + } + int index = maskColorCombo->currentIndex(); + maskColorCombo->removeItem(index); + maskColorLayer->removeMaskColor(index); + }); + removeButton->hide(); + addWidget(mosaicButton); addWidget(grabcutButton); + addWidget(colorMaskButton); addWidget(mosaicSize); + addWidget(helpButton); + addWidget(maskColorCombo); + addWidget(removeButton); + connect(group, static_cast(&QButtonGroup::buttonClicked), + this, [=](int id) { + type = id; + mosaicSize->hide(); + colorPicker->hide(); + helpButton->hide(); + maskColorCombo->hide(); + removeButton->hide(); + if(type == 0){ + mosaicSize->show(); + } + else if(type == 1){ + grabcutLayer->setFocus(); + grabcutLayer->setEnableShow(); + helpButton->show(); + } + else{ + maskColorCombo->show(); + removeButton->show(); + colorPicker->show(); + } + widgetParent->adjustSize(); + }); } return widget; } +void BlurLayerContainer::onInvalid(){ + valid = false; + colorPicker->hide(); +} + void BlurLayerContainer::layerMousePressEvent(QGraphicsSceneMouseEvent *event) { if(type == 0){ blurLayer->setParameter("windowSize", windowSize); @@ -92,3 +177,37 @@ void BlurLayerContainer::layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event) grabcutLayer->addPoint(event->scenePos(), background, true); } } + +int BlurLayerContainer::getCurrentType(){ + return type; +} + +void BlurLayerContainer::addColor(QColor color){ + maskColorCombo->addItem(QString::number(color.red())+","+QString::number(color.green()) + +","+QString::number(color.blue())); + QStandardItemModel* model = qobject_cast(maskColorCombo->model()); + model->item(maskColorCombo->count()-1)->setBackground(color); + int red, green, blue; + color.getRgb(&red, &green, &blue); + red = red + (red - 127) * 0.5; + red = (red < 0x00) ? 0xff+red : (red > 0xff) ? red-0xff : red; + green = green + (green - 127) * 0.5; + green = (green < 0x00) ? 0xff+green : (green > 0xff) ? green - 0xff : green; + blue = blue + (blue - 127) * 0.5; + blue = (blue < 0x00) ? 0xff+blue : (blue > 0xff) ? blue - 0xff : blue; + model->item(maskColorCombo->count()-1)->setForeground(QColor(red, green, blue)); + maskColorCombo->setCurrentIndex(maskColorCombo->count()-1); + maskColorLayer->addMaskColor(color); + widget->parentWidget()->adjustSize(); +} + +void BlurLayerContainer::reset(){ + if(maskColorCombo != NULL){ + colorPicker->hide(); + helpButton->hide(); + maskColorCombo->hide(); + removeButton->hide(); + maskColorCombo->clear(); + type = 0; + } +} diff --git a/GraphicsScene/Container/blurlayercontainer.h b/GraphicsScene/Container/blurlayercontainer.h index 88de6d3..d2bc7f3 100644 --- a/GraphicsScene/Container/blurlayercontainer.h +++ b/GraphicsScene/Container/blurlayercontainer.h @@ -3,6 +3,9 @@ #include "layercontainer.h" #include "../Layer/blurlayer.h" #include "../Layer/grabcutlayer.h" +#include "../Layer/maskcolorlayer.h" +#include +#include "../Widgets/colorpicker.h" class BlurLayerContainer : public LayerContainer { @@ -12,12 +15,25 @@ class BlurLayerContainer : public LayerContainer void layerMouseMoveEvent(QGraphicsSceneMouseEvent *event) override; void layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; QWidget * onValid(QWidget *widgetParent) override; + void onInvalid() override; + int getCurrentType(); + void reset() override; + +private: + void addColor(QColor color); + private: BlurLayer* blurLayer; GrabcutLayer* grabcutLayer; + MaskColorLayer* maskColorLayer; int type; int windowSize; bool background; + QComboBox* maskColorCombo; + ColorPicker* colorPicker; + bool valid; + QToolButton* helpButton; + QToolButton* removeButton; }; #endif // BLURLAYERCONTAINER_H diff --git a/GraphicsScene/Container/layercontainer.h b/GraphicsScene/Container/layercontainer.h index 5e38884..f8bf4c0 100644 --- a/GraphicsScene/Container/layercontainer.h +++ b/GraphicsScene/Container/layercontainer.h @@ -18,6 +18,7 @@ class LayerContainer : public QObject virtual void layerMouseReleaseEvent(QGraphicsSceneMouseEvent* event) {} virtual QWidget* onValid(QWidget* widgetParent)=0; virtual void onInvalid(){} + virtual void reset(){} protected: bool initWidget(QWidget* parent); diff --git a/GraphicsScene/Container/paintlayercontainer.cpp b/GraphicsScene/Container/paintlayercontainer.cpp index c80de48..8e6536c 100644 --- a/GraphicsScene/Container/paintlayercontainer.cpp +++ b/GraphicsScene/Container/paintlayercontainer.cpp @@ -96,10 +96,10 @@ void PaintLayerContainer::layerMousePressEvent(QGraphicsSceneMouseEvent *event) void PaintLayerContainer::layerMouseMoveEvent(QGraphicsSceneMouseEvent *event) { qint64 currentTime = QDateTime::currentMSecsSinceEpoch(); - if(currentTime - beforeTime > 20) { - beforeTime = currentTime; +// if(currentTime - beforeTime > 20) { +// beforeTime = currentTime; paintLayer->addPoint(event->scenePos()); - } +// } } void PaintLayerContainer::layerMouseReleaseEvent(QGraphicsSceneMouseEvent *event) { diff --git a/GraphicsScene/Layer/blurlayer.cpp b/GraphicsScene/Layer/blurlayer.cpp index 923d2ba..2b04be1 100644 --- a/GraphicsScene/Layer/blurlayer.cpp +++ b/GraphicsScene/Layer/blurlayer.cpp @@ -78,7 +78,6 @@ void BlurLayer::deletePoint(const QPoint &point){ } void BlurLayer::reset() { - use.resize(0); LayerBase::reset(); } diff --git a/GraphicsScene/Layer/grabcutlayer.cpp b/GraphicsScene/Layer/grabcutlayer.cpp index aace1fe..9dba2d6 100644 --- a/GraphicsScene/Layer/grabcutlayer.cpp +++ b/GraphicsScene/Layer/grabcutlayer.cpp @@ -4,6 +4,7 @@ #include "../../Helper/debug.h" #include #include +#include GrabcutLayer::GrabcutLayer(const QString& name, ILayerControl* manager, @@ -12,6 +13,7 @@ GrabcutLayer::GrabcutLayer(const QString& name, background(true), enableShow(false) { + setFlags(QGraphicsItem::ItemIsFocusable); handler = new GrabcutHandler(this); connect(handler, &GrabcutHandler::finish, this, [=](QImage mask){ manager->remaskImage(mask); diff --git a/GraphicsScene/Layer/maskcolorlayer.cpp b/GraphicsScene/Layer/maskcolorlayer.cpp new file mode 100644 index 0000000..28a0de5 --- /dev/null +++ b/GraphicsScene/Layer/maskcolorlayer.cpp @@ -0,0 +1,51 @@ +#include "maskcolorlayer.h" + +MaskColorLayer::MaskColorLayer(const QString& name, + ILayerControl* manager, + QGraphicsItem* parent) + : LayerBase(name, manager, parent) +{ + +} + +QRectF MaskColorLayer::boundingRect() const{ + return QRectF(); +} + +void MaskColorLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ + +} + +void MaskColorLayer::reset(){ + colors.clear(); + LayerBase::reset(); +} + +void MaskColorLayer::setEnable(bool enable, int index){ + this->enable = false; +} + +void MaskColorLayer::addMaskColor(const QColor &color){ + colors.append(color); + manager->maskColor(color); +} + +void MaskColorLayer::removeMaskColor(int index){ + colors.removeAt(index); + manager->resetImage(); + for(QColor color : colors){ + manager->maskColor(color); + } +} + +QList MaskColorLayer::getMaskColors(){ + return colors; +} + +int MaskColorLayer::type() const{ + return 102409; +} + +int MaskColorLayer::getZValue() const{ + return 2; +} diff --git a/GraphicsScene/Layer/maskcolorlayer.h b/GraphicsScene/Layer/maskcolorlayer.h new file mode 100644 index 0000000..7f516c2 --- /dev/null +++ b/GraphicsScene/Layer/maskcolorlayer.h @@ -0,0 +1,24 @@ +#ifndef MASKCOLORLAYER_H +#define MASKCOLORLAYER_H +#include "layerbase.h" + +class MaskColorLayer : public LayerBase +{ +public: + MaskColorLayer(const QString& name, + ILayerControl* manager, + QGraphicsItem* parent=nullptr); + void reset() override; + void addMaskColor(const QColor& color); + void removeMaskColor(int index); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; + QRectF boundingRect()const override; + int type() const override; + void setEnable(bool enable, int index = 0) override; + QList getMaskColors(); + int getZValue() const override; +private: + QList colors; +}; + +#endif // MASKCOLORLAYER_H diff --git a/GraphicsScene/Layer/paintlayer.cpp b/GraphicsScene/Layer/paintlayer.cpp index 1b0bb3c..b92842f 100644 --- a/GraphicsScene/Layer/paintlayer.cpp +++ b/GraphicsScene/Layer/paintlayer.cpp @@ -44,7 +44,7 @@ void PaintLayer::reset(){ void PaintLayer::addPoint(const QPointF& point){ if(points.size() > 0){ QLineF line(point, points.last()); - if(line.length() < 2) return; + if(line.length() < 3) return; } if(point.x() >= manager->getImage().width() || point.y() >= manager->getImage().height() || diff --git a/GraphicsScene/Layer/piclayer.cpp b/GraphicsScene/Layer/piclayer.cpp index 8436589..526c548 100644 --- a/GraphicsScene/Layer/piclayer.cpp +++ b/GraphicsScene/Layer/piclayer.cpp @@ -60,7 +60,6 @@ void PicLayer::endSave(){ } void PicLayer::reset(){ - mask = QRectF(); } void PicLayer::setEnable(bool enable, int index) { diff --git a/GraphicsScene/Layer/textlayer.cpp b/GraphicsScene/Layer/textlayer.cpp index a7275e6..0855d56 100644 --- a/GraphicsScene/Layer/textlayer.cpp +++ b/GraphicsScene/Layer/textlayer.cpp @@ -83,3 +83,7 @@ int TextLayer::type() const{ void TextLayer::onDelete(const QPointF &point){ manager->removeThis(this); } + +int TextLayer::getZValue() const{ + return 2; +} diff --git a/GraphicsScene/Layer/textlayer.h b/GraphicsScene/Layer/textlayer.h index a510b84..16a7d59 100644 --- a/GraphicsScene/Layer/textlayer.h +++ b/GraphicsScene/Layer/textlayer.h @@ -23,6 +23,7 @@ class TextLayer : public LayerBase bool contains(const QPointF& point)const override; int type() const override; void onDelete(const QPointF &point) override; + int getZValue() const override; signals: void formatChange(const QFont& font, const QBrush& brush); diff --git a/GraphicsScene/Widgets/colorpicker.cpp b/GraphicsScene/Widgets/colorpicker.cpp index cf88d53..c0fd2b7 100644 --- a/GraphicsScene/Widgets/colorpicker.cpp +++ b/GraphicsScene/Widgets/colorpicker.cpp @@ -29,6 +29,7 @@ void ColorPicker::setPosition(QPointF point){ } bound.setHeight(pixelHeightPX+20); bound.setWidth(pixelWidthPX); + update(); } QRectF ColorPicker::boundingRect() const{ @@ -49,6 +50,7 @@ QPainterPath ColorPicker::shape() const{ } void ColorPicker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ + if(!manager->isImageValid()) return; QImage image = manager->getImage(); QImage image1 = QImage(pixelWidthPX, pixelHeightPX,QImage::Format_RGB32); for(int i=0; i=image.width() ? image.width()-1 : i+point.x() - pixelWidthPX/10; int y = k+point.y()-pixelHeightPX/10 < 0 ? 0 : k+point.y()+pixelHeightPX/10>=image.height() ? image.height()-1 : k+point.y()-pixelHeightPX/10; - image1.setPixel(j, m, image.pixel(x, y)); + QRgb* line = (QRgb*)image1.scanLine(m); + line[j] = ((QRgb*)image.constScanLine(y))[x]; +// image1.setPixel(j, m, image.pixel(x, y)); } } } } - QImage image2 = QImage(20, 20, QImage::Format_RGB32); QRgb rgb = image.pixel(point.x(), point.y()); - image2.fill(rgb); painter->drawImage(bound.left(), bound.top(), image1); - painter->drawImage(bound.left(), bound.top()+pixelHeightPX, image2); + painter->fillRect(bound.left(), bound.top()+pixelHeightPX, 20, 20, QColor(rgb)); QRect textBound(bound.left()+20, bound.top()+pixelHeightPX, pixelWidthPX-20, 20); painter->fillRect(textBound, QColor(255, 255, 255)); painter->drawText(textBound, Qt::AlignCenter, "("+QString::number(qRed(rgb)) + "," + QString::number(qGreen(rgb)) + "," + QString::number(qBlue(rgb)) + ")"); - PaintHelper::paintShadow(painter, bound, shadowWidth, QColor(50, 50, 50, 120)); +// PaintHelper::paintShadow(painter, bound, shadowWidth, QColor(50, 50, 50, 120)); painter->setCompositionMode(QPainter::RasterOp_SourceOrNotDestination); double middlex = (double)(pixelWidthPX) / 2.0; double middley = (double)(pixelHeightPX) / 2.0; diff --git a/GraphicsScene/Widgets/defaulttoolbar.cpp b/GraphicsScene/Widgets/defaulttoolbar.cpp index 8aba0bc..49698bc 100644 --- a/GraphicsScene/Widgets/defaulttoolbar.cpp +++ b/GraphicsScene/Widgets/defaulttoolbar.cpp @@ -134,12 +134,22 @@ DefaultToolbar::DefaultToolbar(PaintArea* area, QWidget* parent) : LayerToolBar( showAll(); }); } - area->registerMousePressHook([=](Qt::MouseButton button){ + area->installMouseFilter([=](Qt::MouseButton button){ + if(getCurrentGroupContainer() == blurLayerContainer && blurLayerContainer->getCurrentType() == 1 && button != Qt::MiddleButton){ + return false; + } if(button == Qt::RightButton) { if(maskLayerContainer->regionCount() == 0) { WindowManager::instance()->changeWindow("tray"); } else { - area->reset(); + if(area != NULL){ + area->reset(false); + } + for(auto container : containers){ + if(container != NULL) container->reset(); + } + setContainer(maskLayerContainer); + hideAll(); } return true; } else if(button == Qt::MidButton) { @@ -224,6 +234,7 @@ QWidget* DefaultToolbar::getAttributeBar(){ } void DefaultToolbar::reset(){ + LayerToolBar::reset(); setContainer(maskLayerContainer); hideAll(); } diff --git a/GraphicsScene/Widgets/defaulttoolbar.h b/GraphicsScene/Widgets/defaulttoolbar.h index 4f2a0ad..c757e77 100644 --- a/GraphicsScene/Widgets/defaulttoolbar.h +++ b/GraphicsScene/Widgets/defaulttoolbar.h @@ -9,7 +9,7 @@ class DefaultToolbar : public LayerToolBar public: DefaultToolbar(PaintArea* area, QWidget* parent=nullptr); QWidget* getAttributeBar(); - void reset(); + void reset() override; private: void initOcr(); bool mousePressHook(Qt::MouseButton button); diff --git a/GraphicsScene/Widgets/layertoolbar.cpp b/GraphicsScene/Widgets/layertoolbar.cpp index e4b30a7..604305e 100644 --- a/GraphicsScene/Widgets/layertoolbar.cpp +++ b/GraphicsScene/Widgets/layertoolbar.cpp @@ -166,3 +166,19 @@ void LayerToolBar::execInvalid(int id){ attributeBar->adjustSize(); } } + +LayerContainer* LayerToolBar::getCurrentGroupContainer(){ + if(containers.size() == 0){ + return NULL; + } + return containers[group->checkedId()]; +} + +void LayerToolBar::reset(){ + if(area != NULL){ + area->reset(); + } + for(auto container : containers){ + if(container != NULL) container->reset(); + } +} diff --git a/GraphicsScene/Widgets/layertoolbar.h b/GraphicsScene/Widgets/layertoolbar.h index 85eb232..0661ece 100644 --- a/GraphicsScene/Widgets/layertoolbar.h +++ b/GraphicsScene/Widgets/layertoolbar.h @@ -21,6 +21,8 @@ class LayerToolBar : public QToolBar void hideAll(); void showAll(); void simulateClick(int id); + LayerContainer* getCurrentGroupContainer(); + virtual void reset(); public slots: void onGroupClick(int id); diff --git a/GraphicsScene/Widgets/painttoolbar.cpp b/GraphicsScene/Widgets/painttoolbar.cpp index b355c2c..727b362 100644 --- a/GraphicsScene/Widgets/painttoolbar.cpp +++ b/GraphicsScene/Widgets/painttoolbar.cpp @@ -226,5 +226,6 @@ QWidget* PaintToolbar::getAttributeBar(){ } void PaintToolbar::reset(){ + LayerToolBar::reset(); setContainer(paintLayerContainer); } diff --git a/GraphicsScene/Widgets/painttoolbar.h b/GraphicsScene/Widgets/painttoolbar.h index 7ef9727..5f93345 100644 --- a/GraphicsScene/Widgets/painttoolbar.h +++ b/GraphicsScene/Widgets/painttoolbar.h @@ -9,7 +9,7 @@ class PaintToolbar : public LayerToolBar public: PaintToolbar(PaintArea* area, QWidget* parent=nullptr); QWidget* getAttributeBar(); - void reset(); + void reset() override; private: void initOcr(); private: diff --git a/GraphicsScene/Widgets/textitem.cpp b/GraphicsScene/Widgets/textitem.cpp index 9820ebf..be26527 100644 --- a/GraphicsScene/Widgets/textitem.cpp +++ b/GraphicsScene/Widgets/textitem.cpp @@ -140,6 +140,7 @@ void TextItem::getFocus(){ void TextItem::loseFocus(){ forceFocus = false; + clearFocus(); boundHide(); update(); } diff --git a/GraphicsScene/ilayercontrol.cpp b/GraphicsScene/ilayercontrol.cpp index 7415691..bca45da 100644 --- a/GraphicsScene/ilayercontrol.cpp +++ b/GraphicsScene/ilayercontrol.cpp @@ -66,3 +66,23 @@ void ILayerControl::remaskImage(const QImage &mask){ } } } + +void ILayerControl::maskColor(const QColor &color){ + if(!modified){ + modifiedImage = image.copy(); + } + modified = true; + for(int i=0; ibutton())) return; } + for(auto pressFunc : pressFuncs){ + pressFunc(event->scenePos()); + } + press = true; + if(event->button() == Qt::BackButton) { + recorder->back(); + } else if(event->button() == Qt::ForwardButton) { + recorder->forward(); + } for(auto& layer: layers){ if((layer->isEnable()) && layer->contains(layer->mapFromScene(event->scenePos()))){ @@ -47,8 +56,13 @@ void PaintArea::mousePressEvent(QGraphicsSceneMouseEvent *event){ } void PaintArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event){ - sendEvent(rootLayer, event); - QGraphicsScene::mouseMoveEvent(event); + for(auto moveFunc : moveFuncs){ + moveFunc(event->scenePos()); + } + if(press){ + sendEvent(rootLayer, event); + QGraphicsScene::mouseMoveEvent(event); + } if(!inLayer && press){ if(container != NULL) container->layerMouseMoveEvent(event); return; @@ -212,11 +226,13 @@ void PaintArea::setImage(const QImage& image){ update(); } -void PaintArea::reset(){ - this->image = QImage(); +void PaintArea::reset(bool newImage){ + if(newImage){ + this->image = QImage(); + imageValid = false; + } this->modifiedImage = QImage(); this->modified = false; - imageValid = false; inLayer = false; _save = false; focusLayer = NULL; @@ -259,7 +275,15 @@ bool PaintArea::isSave(){ return _save; } -void PaintArea::registerMousePressHook(const std::function &f){ - registered = true; +void PaintArea::installMouseFilter(const std::function &f){ + installed = true; this->f = f; } + +void PaintArea::registerMousePressHook(const std::function &f){ + pressFuncs.append(f); +} + +void PaintArea::registerMouseMoveHook(const std::function &f){ + moveFuncs.append(f); +} diff --git a/GraphicsScene/paintarea.h b/GraphicsScene/paintarea.h index 237e9ec..4ae07a9 100644 --- a/GraphicsScene/paintarea.h +++ b/GraphicsScene/paintarea.h @@ -26,7 +26,7 @@ class PaintArea : public QGraphicsScene, public ILayerControl, public LayerManag void removeThis(LayerBase *layer) override; void setContainer(LayerContainer* container); void setImage(const QImage& image); - void reset(); + void reset(bool newImage=true); QGraphicsItem* getRootLayer(); QRectF getClipRect() override; ClipLayerBase* getClipLayer(); @@ -35,7 +35,9 @@ class PaintArea : public QGraphicsScene, public ILayerControl, public LayerManag QImage getSaveImage(); QRectF getSaveRect(); bool isSave(); - void registerMousePressHook(std::functionconst& f); + void installMouseFilter(std::functionconst& f); + void registerMousePressHook(std::functionconst& f); + void registerMouseMoveHook(std::functionconst& f); signals: void recordChange(); @@ -50,7 +52,9 @@ class PaintArea : public QGraphicsScene, public ILayerControl, public LayerManag ClipLayerBase* clipLayer; Recorder* recorder; std::function f; - bool registered; + QList> pressFuncs; + QList> moveFuncs; + bool installed; }; #endif // PAINTAREA_H diff --git a/Resource/Languages/chinese.xml b/Resource/Languages/chinese.xml index 609f392..155425f 100644 --- a/Resource/Languages/chinese.xml +++ b/Resource/Languages/chinese.xml @@ -131,4 +131,6 @@ + + diff --git a/Resource/Resources.qrc b/Resource/Resources.qrc index 49afb55..261eb66 100644 --- a/Resource/Resources.qrc +++ b/Resource/Resources.qrc @@ -99,6 +99,7 @@ mouse_middle.svg mouse_left.svg blur.svg + color_mask.svg custom_button.qss diff --git a/Resource/color_mask.svg b/Resource/color_mask.svg new file mode 100644 index 0000000..59b0fe7 --- /dev/null +++ b/Resource/color_mask.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Windows/capturewindow.cpp b/Windows/capturewindow.cpp index 6469482..96f9d1f 100644 --- a/Windows/capturewindow.cpp +++ b/Windows/capturewindow.cpp @@ -64,6 +64,8 @@ CaptureWindow::CaptureWindow(QWidget *parent) : area->addLayer(picLayer); view->setScene(area); + view->setMouseTracking(true); + view->viewport()->setMouseTracking(true); view->setStyleSheet(".QGraphicsView{background: transparent;border:0px;}"); view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate); // view->viewport()->installEventFilter(new GraphicsViewPatch(view)); @@ -244,8 +246,6 @@ void CaptureWindow::onWindowSelect() { KeyManager::instance()->registerGlobalKey("capture_video_start"); KeyManager::instance()->registerGlobalKey("capture_video_pause"); KeyManager::instance()->registerGlobalKey("capture_video_stop"); - area->reset(); - area->update(); defaultToolbar->reset(); setGeometry(ImageHelper::getCurrentGeometry()); view->show(); diff --git a/Windows/paintwindow.cpp b/Windows/paintwindow.cpp index aeed7c1..6a1a4c3 100644 --- a/Windows/paintwindow.cpp +++ b/Windows/paintwindow.cpp @@ -267,7 +267,7 @@ void PaintWindow::reset() { } path += "main.png"; if(!area->isSave() && area->isImageValid()) area->save(ILayerControl::Temp, path); - area->reset(); + toolbar->reset(); } void PaintWindow::onWindowCancel() { diff --git a/capture.pro b/capture.pro index 9a6b914..fa023f8 100644 --- a/capture.pro +++ b/capture.pro @@ -29,6 +29,7 @@ SOURCES += \ GraphicsScene/Layer/blurlayer.cpp \ GraphicsScene/Layer/grabcutlayer.cpp \ GraphicsScene/Layer/layerbase.cpp \ + GraphicsScene/Layer/maskcolorlayer.cpp \ GraphicsScene/Layer/masklayer.cpp \ GraphicsScene/Layer/paintlayer.cpp \ GraphicsScene/Layer/piclayer.cpp \ @@ -118,6 +119,7 @@ HEADERS += \ GraphicsScene/Layer/cliplayerbase.h \ GraphicsScene/Layer/grabcutlayer.h \ GraphicsScene/Layer/layerbase.h \ + GraphicsScene/Layer/maskcolorlayer.h \ GraphicsScene/Layer/masklayer.h \ GraphicsScene/Layer/paintlayer.h \ GraphicsScene/Layer/piclayer.h \ diff --git a/main.cpp b/main.cpp index 08f0ec9..c1f9448 100644 --- a/main.cpp +++ b/main.cpp @@ -91,4 +91,5 @@ void preLoad(){ KeyManager::instance()->load(); MString::load_from_file("Data/Languages/"); registerClasses(); + QFont().defaultFamily(); // 提前加载字体文件,大约需要200-300ms } From 48081bedb8be79f73764c375ae91575f68f8d55f Mon Sep 17 00:00:00 2001 From: xinhecuican <2686462757@qq.com> Date: Mon, 15 Jan 2024 20:42:41 +0800 Subject: [PATCH 11/11] update readme --- Doxyfile | 3 +-- Manager/update.cpp | 9 +++++---- README.md | 7 +------ Windows/capturewindow.cpp | 2 +- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Doxyfile b/Doxyfile index 59a8cdc..79b85fb 100644 --- a/Doxyfile +++ b/Doxyfile @@ -48,8 +48,7 @@ PROJECT_NAME = "简截" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 0.7.5 -# With the PROJECT_LOGO tag one can specify a logo or an icon that is included +PROJECT_NUMBER = 0.8.0# With the PROJECT_LOGO tag one can specify a logo or an icon that is included # in the documentation. The maximum height of the logo should not exceed 55 # pixels and the maximum width should not exceed 200 pixels. Doxygen will copy # the logo to the output directory. diff --git a/Manager/update.cpp b/Manager/update.cpp index 3b169da..a95b0fb 100644 --- a/Manager/update.cpp +++ b/Manager/update.cpp @@ -48,12 +48,13 @@ Update::~Update() { } Update* Update::_instance = NULL; -QString Update::version = "0.7.5"; +QString Update::version = "0.8.0"; UpdateData Update::now_version = UpdateData(Update::version, "http://121.37.81.150:8200/easycapture/update/" + Update::version + ".zip", "", - "1. 重构KeyManager\n" - "2. 修复更改快捷键时崩溃的bug\n" - "3. 修复快捷键不生效的bug"); + "1. 重构GraphicsScene\n" + "2. 使用高斯模糊作为马赛克,添加grabcut\n" + "3. 移除录屏\n" + "4. 优化样式"); void Update::serialized(QJsonObject *json) { //append增添版本时用 QJsonObject child; diff --git a/README.md b/README.md index da150fe..e19c765 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ * windows环境 * qt 5.14.2 64位 * opencv 4.5.1 with contrib -* ffmpeg 5.1 * quazip0.7.3 * zlib * qbreakpad @@ -50,16 +49,12 @@ * 透明 - 目前仅可以做到对某一个色素透明,对于渐变和拍屏无效。并且由于文字都是由不同种类像素组成因此无法做到选取文字(正好下学期有图像处理,看看通过反锯齿可以直接把文字的范围弄出来)。 + 单一颜色透明或者使用grabcut处理渐变 * ocr 使用[RapidOCR](https://github.com/RapidAI/RapidOCR)引擎进行识别![](https://xinhecuican.tech/images/简截9.png) -* 录屏 - - 录屏基于[NanaRecorder](https://github.com/onlyet/NanaRecorder)改进而来 - * 贴图 ![](https://xinhecuican.tech/images/简截10.png) diff --git a/Windows/capturewindow.cpp b/Windows/capturewindow.cpp index 96f9d1f..793b575 100644 --- a/Windows/capturewindow.cpp +++ b/Windows/capturewindow.cpp @@ -52,7 +52,7 @@ CaptureWindow::CaptureWindow(QWidget *parent) : this->setMouseTracking(true); centralWidget->setMouseTracking(true); #ifdef QT_NO_DEBUG - // setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); + setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); #endif // ui->centralwidget->setGeometry(QGuiApplication::primaryScreen()->geometry());