-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: [UI] Add some new features #112
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#include "maskitem.h" | ||
#include "pagescene.h" | ||
#include "pageitem_p.h" | ||
#include <QPainter> | ||
REGISTITEMCLASS(MaskItem, MaskItemType) | ||
|
||
MaskItem::MaskItem(PageScene *scene): | ||
PageItem(nullptr) | ||
{ | ||
setZValue(10000); | ||
if (scene != nullptr) { | ||
setRect(scene->sceneRect()); | ||
} else { | ||
setRect(QRectF(0, 0, 1920, 1080)); | ||
} | ||
} | ||
|
||
int MaskItem::type() const | ||
{ | ||
return MaskItemType; | ||
} | ||
|
||
QRectF MaskItem::itemRect() const | ||
{ | ||
return rect(); | ||
} | ||
|
||
void MaskItem::setRect(const QRectF &rect) | ||
{ | ||
prepareGeometryChange(); | ||
m_rect = rect; | ||
updateShape(); | ||
} | ||
|
||
QRectF MaskItem::rect() const | ||
{ | ||
return m_rect; | ||
} | ||
|
||
bool MaskItem::contains(const QPointF &point) const | ||
{ | ||
return false; | ||
} | ||
|
||
bool MaskItem::isPosPenetrable(const QPointF &posLocal) | ||
{ | ||
return true; | ||
} | ||
|
||
bool MaskItem::isRectPenetrable(const QRectF &rectLocal) | ||
{ | ||
return true; | ||
} | ||
|
||
void MaskItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | ||
{ | ||
painter->setBrush(Qt::transparent); | ||
painter->setPen(Qt::NoPen); | ||
painter->drawRect(orgRect()); | ||
PageItem::paint(painter, option, widget); | ||
|
||
if (pageScene()->page()->currentTool() == cut) { | ||
PageItem* cutItem = nullptr; | ||
QList<PageItem *> pageItems = pageScene()->allPageItems(); | ||
foreach (auto item, pageItems) { | ||
if (item && item->type() == CutType) { | ||
cutItem = item; | ||
break; | ||
} | ||
} | ||
|
||
if (cutItem && cutItem->isVisible()) { | ||
painter->save(); | ||
QRectF layerRct = mapToScene(itemRect()).boundingRect(); | ||
QRectF cutRct = cutItem->mapToScene(cutItem->itemRect()).boundingRect(); | ||
QRegion r1(cutRct.toRect()); | ||
QRegion r2(layerRct.toRect()); | ||
QRegion r3 = r2.subtracted(r1); | ||
QPainterPath path; | ||
path.addRegion(r3); | ||
|
||
QColor background(0, 0, 0, 51); | ||
painter->setPen(Qt::NoPen); | ||
painter->setBrush(background); | ||
painter->drawPath(path); | ||
painter->restore(); | ||
} | ||
} | ||
} | ||
|
||
void MaskItem::updateShape() | ||
{ | ||
// QRectF rct; | ||
// if (scene() != nullptr) { | ||
// rct = scene()->sceneRect(); | ||
// } | ||
// setRect(rct); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#ifndef MASKITEM_H | ||
#define MASKITEM_H | ||
#include "pageitem.h" | ||
|
||
class PageScene; | ||
class MaskItem: public PageItem | ||
{ | ||
public: | ||
MaskItem(PageScene *scene = nullptr); | ||
|
||
int type() const override; | ||
|
||
/** | ||
* @brief type 图元的包裹矩形 | ||
*/ | ||
QRectF itemRect() const override; | ||
|
||
/** | ||
* @brief setRect 设置蒙板矩形 | ||
*/ | ||
void setRect(const QRectF &rect); | ||
|
||
/** | ||
* @brief rect 蒙板矩形 | ||
*/ | ||
QRectF rect() const; | ||
|
||
private: | ||
|
||
bool contains(const QPointF &point) const override; | ||
bool isPosPenetrable(const QPointF &posLocal) override; | ||
bool isRectPenetrable(const QRectF &rectLocal) override; | ||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, | ||
QWidget *widget) override; | ||
void updateShape() override; | ||
|
||
QRectF m_rect; | ||
}; | ||
Q_DECLARE_METATYPE(MaskItem *) | ||
|
||
#endif // MASKITEM_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/drawboard/drawboard/res/toolIconsNew/crop_highlight_20px.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没用就移除了