Skip to content

Commit

Permalink
fix: image can be zoomed on when double clicked or using the zoom to …
Browse files Browse the repository at this point in the history
…selected tool
  • Loading branch information
Onetchou committed Apr 10, 2024
1 parent b6f1417 commit 8a71e72
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/app/seamly2d/core/vtooloptionspropertybrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void VToolOptionsPropertyBrowser::clearPropertyBrowser()
void VToolOptionsPropertyBrowser::showItemOptions(QGraphicsItem *item)
{
// This check helps to find missing tools in the switch
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53, "Not all tools were used in switch.");
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 54, "Not all tools were used in switch.");

switch (item->type())
{
Expand Down Expand Up @@ -244,7 +244,7 @@ void VToolOptionsPropertyBrowser::updateOptions()
}

// This check helps to find missing tools in the switch
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53, "Not all tools were used in switch.");
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 54, "Not all tools were used in switch.");

switch (currentItem->type())
{
Expand Down Expand Up @@ -389,7 +389,7 @@ void VToolOptionsPropertyBrowser::userChangedData(VPE::VProperty *property)
}

// This check helps to find missing tools in the switch
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53, "Not all tools were used in switch.");
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 54, "Not all tools were used in switch.");

switch (currentItem->type())
{
Expand Down
3 changes: 2 additions & 1 deletion src/app/seamly2d/dialogs/groups_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
void GroupsWidget::addGroupItem(const quint32 &toolId, const quint32 &objId, const Tool &tooltype)
{
// This check helps to find missing tools in the switch
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53, "Not all tools were used in history.");
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 54, "Not all tools were used in history.");

QString iconFileName = "";
QString objName = tr("Unknown Object");
Expand All @@ -762,6 +762,7 @@ void GroupsWidget::addGroupItem(const quint32 &toolId, const quint32 &objId, con
case Tool::Cut:
case Tool::Midpoint: // Same as Tool::AlongLine, but tool will never have such type
case Tool::ArcIntersectAxis: // Same as Tool::CurveIntersectAxis, but tool will never have such type
case Tool::BackgroundImage:
case Tool::LAST_ONE_DO_NOT_USE:
Q_UNREACHABLE(); //-V501
break;
Expand Down
3 changes: 2 additions & 1 deletion src/app/seamly2d/dialogs/history_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
RowData HistoryDialog::record(const VToolRecord &tool)
{
// This check helps to find missed tools in the switch
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53, "Not all tools were used in history.");
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 54, "Not all tools were used in history.");

RowData rowData;
const quint32 &toolId = tool.getId();
Expand All @@ -293,6 +293,7 @@ RowData HistoryDialog::record(const VToolRecord &tool)
case Tool::Cut:
case Tool::Midpoint:// Same as Tool::AlongLine, but tool will never has such type
case Tool::ArcIntersectAxis:// Same as Tool::CurveIntersectAxis, but tool will never has such type
case Tool::BackgroundImage:
case Tool::LAST_ONE_DO_NOT_USE:
Q_UNREACHABLE(); //-V501
break;
Expand Down
36 changes: 23 additions & 13 deletions src/app/seamly2d/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2813,21 +2813,29 @@ void MainWindow::zoomScaleChanged(qreal scale)
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::zoomToSelected()
{
QGraphicsItem *item = qApp->getCurrentScene()->focusItem();
QRectF rect;

if (qApp->getCurrentScene() == draftScene)
{
ui->view->zoomToRect(doc->ActiveDrawBoundingRect());
if ((item != nullptr) && (item->type() == QGraphicsItem::UserType + static_cast<int>(Tool::BackgroundImage)))
{
rect = item->boundingRect();
rect.translate(item->scenePos());
ui->view->zoomToRect(rect);
}
else
{
ui->view->zoomToRect(doc->ActiveDrawBoundingRect());
}
}
else if (qApp->getCurrentScene() == pieceScene)
{
QGraphicsItem *item = qApp->getCurrentScene()->focusItem();
if ((item != nullptr) && (item->type() == QGraphicsItem::UserType + static_cast<int>(Tool::Piece)))
{
if ((item != nullptr) && (item->type() == QGraphicsItem::UserType + static_cast<int>(Tool::Piece)))
{
QRectF rect;
rect = item->boundingRect();
rect.translate(item->scenePos());
ui->view->zoomToRect(rect);
}
rect = item->boundingRect();
rect.translate(item->scenePos());
ui->view->zoomToRect(rect);
}
}
}
Expand Down Expand Up @@ -2935,7 +2943,7 @@ void MainWindow::initializeToolButtons()
connect(ui->arrowPointer_ToolButton, &QToolButton::clicked, this, &MainWindow::handleArrowTool);

// This check helps to find missed tools
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53, "Check if all tools were connected.");
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 54, "Check if all tools were connected.");

connect(ui->pointAtDistanceAngle_ToolButton, &QToolButton::clicked,
this, &MainWindow::handlePointAtDistanceAngleTool);
Expand Down Expand Up @@ -3471,7 +3479,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
void MainWindow::CancelTool()
{
// This check helps to find missed tools in the switch
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53, "Not all tools were handled.");
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 54, "Not all tools were handled.");

qCDebug(vMainWindow, "Canceling tool.");
dialogTool.clear();
Expand Down Expand Up @@ -3511,6 +3519,7 @@ void MainWindow::CancelTool()
case Tool::NodeElArc:
case Tool::NodeSpline:
case Tool::NodeSplinePath:
case Tool::BackgroundImage:
Q_UNREACHABLE(); //-V501
//Nothing to do here because we can't create this tool from main window.
break;
Expand Down Expand Up @@ -4937,7 +4946,7 @@ void MainWindow::setToolsEnabled(bool enable)
}

// This check helps to find missed tools
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53, "Not all tools were handled.");
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 54, "Not all tools were handled.");

//Toolbox Drafting Tools
//Points
Expand Down Expand Up @@ -5447,7 +5456,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
void MainWindow::LastUsedTool()
{
// This check helps to find missed tools in the switch
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53, "Not all tools were handled.");
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 54, "Not all tools were handled.");

if (currentTool == lastUsedTool)
{
Expand All @@ -5473,6 +5482,7 @@ void MainWindow::LastUsedTool()
case Tool::NodeElArc:
case Tool::NodeSpline:
case Tool::NodeSplinePath:
case Tool::BackgroundImage:
Q_UNREACHABLE(); //-V501
//Nothing to do here because we can't create this tool from main window.
break;
Expand Down
3 changes: 2 additions & 1 deletion src/app/seamly2d/xml/vpattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3973,7 +3973,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
QRectF VPattern::ActiveDrawBoundingRect() const
{
// This check helps to find missed tools in the switch
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53, "Not all tools were used.");
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 54, "Not all tools were used.");

QRectF rect;

Expand All @@ -3992,6 +3992,7 @@ QRectF VPattern::ActiveDrawBoundingRect() const
case Tool::Cut:
case Tool::Midpoint:// Same as Tool::AlongLine, but tool will never has such type
case Tool::ArcIntersectAxis:// Same as Tool::CurveIntersectAxis, but tool will never has such type
case Tool::BackgroundImage:
case Tool::LAST_ONE_DO_NOT_USE:
Q_UNREACHABLE();
break;
Expand Down
16 changes: 8 additions & 8 deletions src/libs/ifc/xml/vabstractpattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1878,7 +1878,7 @@ QVector<VFormulaField> VAbstractPattern::ListPointExpressions() const
// Check if new tool doesn't bring new attribute with a formula.
// If no just increment a number.
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53);
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 54);

QVector<VFormulaField> expressions;
const QDomNodeList list = elementsByTagName(TagPoint);
Expand All @@ -1904,7 +1904,7 @@ QVector<VFormulaField> VAbstractPattern::ListArcExpressions() const
// Check if new tool doesn't bring new attribute with a formula.
// If no just increment number.
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53);
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 54);

QVector<VFormulaField> expressions;
const QDomNodeList list = elementsByTagName(TagArc);
Expand All @@ -1928,7 +1928,7 @@ QVector<VFormulaField> VAbstractPattern::ListElArcExpressions() const
// Check if new tool doesn't bring new attribute with a formula.
// If no just increment number.
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53);
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 54);

QVector<VFormulaField> expressions;
const QDomNodeList list = elementsByTagName(TagElArc);
Expand Down Expand Up @@ -1961,7 +1961,7 @@ QVector<VFormulaField> VAbstractPattern::ListPathPointExpressions() const
// Check if new tool doesn't bring new attribute with a formula.
// If no just increment number.
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53);
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 54);

QVector<VFormulaField> expressions;
const QDomNodeList list = elementsByTagName(AttrPathPoint);
Expand Down Expand Up @@ -1999,7 +1999,7 @@ QVector<VFormulaField> VAbstractPattern::ListOperationExpressions() const
// Check if new tool doesn't bring new attribute with a formula.
// If no just increment number.
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53);
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 54);

QVector<VFormulaField> expressions;
const QDomNodeList list = elementsByTagName(TagOperation);
Expand All @@ -2021,7 +2021,7 @@ QVector<VFormulaField> VAbstractPattern::ListNodesExpressions(const QDomElement
// Check if new tool doesn't bring new attribute with a formula.
// If no just increment number.
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53);
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 54);

QVector<VFormulaField> expressions;

Expand All @@ -2044,7 +2044,7 @@ QVector<VFormulaField> VAbstractPattern::ListPathExpressions() const
// Check if new tool doesn't bring new attribute with a formula.
// If no just increment number.
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53);
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 54);

QVector<VFormulaField> expressions;
const QDomNodeList list = elementsByTagName(TagPath);
Expand Down Expand Up @@ -2082,7 +2082,7 @@ QVector<VFormulaField> VAbstractPattern::ListPieceExpressions() const
// Check if new tool doesn't bring new attribute with a formula.
// If no just increment number.
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 53);
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 54);

QVector<VFormulaField> expressions;
const QDomNodeList list = elementsByTagName(TagPiece);
Expand Down
1 change: 1 addition & 0 deletions src/libs/tools/image_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ void ImageItem::enableSelection(bool enable)
//---------------------------------------------------------------------------------------------------------------------
void ImageItem::enableHovering(bool enable)
{
Q_UNUSED(enable);
}

//---------------------------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/libs/tools/image_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ImageItem : public QObject, public QGraphicsItem
virtual ~ImageItem() = default;

virtual int type() const override {return Type;}
enum {Type = UserType + static_cast<int>(Vis::BackgroundImageItem)};
enum {Type = UserType + static_cast<int>(Tool::BackgroundImage)};

static QList<ImageItem *> allImageItems;

Expand Down
1 change: 1 addition & 0 deletions src/libs/vmisc/def.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ enum class Tool : ToolVisHolderType
EllipticalArc,
AnchorPoint,
InsertNodes,
BackgroundImage,
LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used
};

Expand Down

0 comments on commit 8a71e72

Please sign in to comment.