Redesign notch context menu to allow quick selection of the notch type.

This commit is contained in:
Roman Telezhynskyi 2023-10-02 18:06:20 +03:00
parent 54a713f545
commit ecf93f8d31
7 changed files with 590 additions and 390 deletions

View File

@ -39,6 +39,7 @@
- New option: Pointer mode.
- Fix GUI freezing while nesting.
- New option: Use Tool Groups.
- Redesign notch context menu to allow quick selection of the notch type.
# Valentina 0.7.52 September 12, 2022
- Fix crash when default locale is ru.

View File

@ -51,6 +51,27 @@
namespace
{
enum class ContextMenuOption : int
{
NoSelection,
Reverse,
NonePassmark,
OneLine,
TwoLines,
ThreeLines,
TMark,
ExternalVMark,
InternalVMark,
UMark,
BoxMark,
CheckMark,
Uniqueness,
TurnPoint,
Excluded,
Delete,
LAST_ONE_DO_NOT_USE
};
auto CuttingPath(quint32 id, const VContainer *data) -> QVector<QPointF>
{
QVector<QPointF> path;
@ -340,85 +361,94 @@ void DialogPiecePath::ShowContextMenu(const QPoint &pos)
return;
}
QScopedPointer<QMenu> menu(new QMenu());
QListWidgetItem *rowItem = ui->listWidget->item(row);
SCASSERT(rowItem != nullptr);
auto rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
QAction *actionPassmark = nullptr;
QAction *actionUniqueness = nullptr;
QAction *actionReverse = nullptr;
QAction *actionTurnPoint = nullptr;
QMenu menu;
QHash<int, QAction *> contextMenu = InitContextMenu(&menu, rowNode);
if (rowNode.GetTypeTool() != Tool::NodePoint)
QAction *selectedAction = menu.exec(ui->listWidget->viewport()->mapToGlobal(pos));
auto selectedOption = static_cast<ContextMenuOption>(
contextMenu.key(selectedAction, static_cast<int>(ContextMenuOption::NoSelection)));
auto SelectPassmarkLineType = [this, &rowNode, rowItem](PassmarkLineType type)
{
actionReverse = menu->addAction(tr("Reverse"));
actionReverse->setCheckable(true);
actionReverse->setChecked(rowNode.GetReverse());
}
else
{
if (m_showMode && GetType() == PiecePathType::CustomSeamAllowance &&
ui->tabWidget->indexOf(ui->tabPassmarks) != -1)
{
actionPassmark = menu->addAction(tr("Passmark"));
actionPassmark->setCheckable(true);
actionPassmark->setChecked(rowNode.IsPassmark());
}
actionUniqueness = menu->addAction(tr("Check uniqueness"));
actionUniqueness->setCheckable(true);
actionUniqueness->setChecked(rowNode.IsCheckUniqueness());
actionTurnPoint = menu->addAction(tr("Turn point"));
actionTurnPoint->setCheckable(true);
actionTurnPoint->setChecked(rowNode.IsTurnPoint());
}
QAction *actionExcluded = menu->addAction(tr("Excluded"));
actionExcluded->setCheckable(true);
actionExcluded->setChecked(rowNode.IsExcluded());
QAction *actionDelete = menu->addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), tr("Delete"));
QAction *selectedAction = menu->exec(ui->listWidget->viewport()->mapToGlobal(pos));
if (selectedAction == actionDelete)
{
delete ui->listWidget->item(row);
}
else if (rowNode.GetTypeTool() != Tool::NodePoint && selectedAction == actionReverse)
{
rowNode.SetReverse(not rowNode.GetReverse());
rowNode.SetPassmark(true);
rowNode.SetPassmarkLineType(type);
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, IsShowNotch()));
}
else if (m_showMode && rowNode.GetTypeTool() == Tool::NodePoint && selectedAction == actionPassmark &&
GetType() == PiecePathType::CustomSeamAllowance && ui->tabWidget->indexOf(ui->tabPassmarks) != -1)
};
Q_STATIC_ASSERT_X(static_cast<int>(ContextMenuOption::LAST_ONE_DO_NOT_USE) == 16, "Not all options were handled.");
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wswitch-default")
switch (selectedOption)
{
rowNode.SetPassmark(not rowNode.IsPassmark());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, IsShowNotch()));
}
else if (selectedAction == actionExcluded)
{
rowNode.SetExcluded(not rowNode.IsExcluded());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, true));
rowItem->setFont(NodeFont(rowItem->font(), rowNode.IsExcluded()));
}
else if (rowNode.GetTypeTool() == Tool::NodePoint && selectedAction == actionUniqueness)
{
rowNode.SetCheckUniqueness(not rowNode.IsCheckUniqueness());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, IsShowNotch()));
}
else if (rowNode.GetTypeTool() == Tool::NodePoint && selectedAction == actionTurnPoint)
{
rowNode.SetTurnPoint(not rowNode.IsTurnPoint());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, IsShowNotch()));
}
case ContextMenuOption::NoSelection:
return;
case ContextMenuOption::Reverse:
rowNode.SetReverse(not rowNode.GetReverse());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, IsShowNotch()));
break;
case ContextMenuOption::NonePassmark:
rowNode.SetPassmark(false);
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, IsShowNotch()));
break;
case ContextMenuOption::OneLine:
SelectPassmarkLineType(PassmarkLineType::OneLine);
break;
case ContextMenuOption::TwoLines:
SelectPassmarkLineType(PassmarkLineType::TwoLines);
break;
case ContextMenuOption::ThreeLines:
SelectPassmarkLineType(PassmarkLineType::ThreeLines);
break;
case ContextMenuOption::TMark:
SelectPassmarkLineType(PassmarkLineType::TMark);
break;
case ContextMenuOption::ExternalVMark:
SelectPassmarkLineType(PassmarkLineType::ExternalVMark);
break;
case ContextMenuOption::InternalVMark:
SelectPassmarkLineType(PassmarkLineType::InternalVMark);
break;
case ContextMenuOption::UMark:
SelectPassmarkLineType(PassmarkLineType::UMark);
break;
case ContextMenuOption::BoxMark:
SelectPassmarkLineType(PassmarkLineType::BoxMark);
break;
case ContextMenuOption::CheckMark:
SelectPassmarkLineType(PassmarkLineType::CheckMark);
break;
case ContextMenuOption::Uniqueness:
rowNode.SetCheckUniqueness(not rowNode.IsCheckUniqueness());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, IsShowNotch()));
break;
case ContextMenuOption::TurnPoint:
rowNode.SetTurnPoint(not rowNode.IsTurnPoint());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, IsShowNotch()));
break;
case ContextMenuOption::Excluded:
rowNode.SetExcluded(not rowNode.IsExcluded());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, true));
rowItem->setFont(NodeFont(rowItem->font(), rowNode.IsExcluded()));
break;
case ContextMenuOption::Delete:
delete ui->listWidget->item(row);
break;
case ContextMenuOption::LAST_ONE_DO_NOT_USE:
Q_UNREACHABLE();
break;
};
QT_WARNING_POP
ValidObjects(PathIsValid());
ListChanged();
@ -2245,3 +2275,81 @@ void DialogPiecePath::InitIcons()
ui->label_10->setPixmap(VTheme::GetPixmapResource(resource, equalIcon));
ui->label_5->setPixmap(VTheme::GetPixmapResource(resource, equalIcon));
}
//---------------------------------------------------------------------------------------------------------------------
auto DialogPiecePath::InitContextMenu(QMenu *menu, const VPieceNode &rowNode) -> QHash<int, QAction *>
{
SCASSERT(menu != nullptr)
QHash<int, QAction *> contextMenu;
if (rowNode.GetTypeTool() != Tool::NodePoint)
{
QAction *actionReverse = menu->addAction(tr("Reverse"));
actionReverse->setCheckable(true);
actionReverse->setChecked(rowNode.GetReverse());
}
else
{
if (m_showMode && GetType() == PiecePathType::CustomSeamAllowance &&
ui->tabWidget->indexOf(ui->tabPassmarks) != -1)
{
QMenu *passmarkSubmenu = menu->addMenu(tr("Passmark"));
QAction *actionNonePassmark = passmarkSubmenu->addAction(tr("None"));
actionNonePassmark->setCheckable(true);
actionNonePassmark->setChecked(!rowNode.IsPassmark());
contextMenu.insert(static_cast<int>(ContextMenuOption::NonePassmark), actionNonePassmark);
Q_STATIC_ASSERT_X(static_cast<int>(PassmarkLineType::LAST_ONE_DO_NOT_USE) == 9,
"Not all types were handled.");
auto InitPassmarkLineTypeAction = [passmarkSubmenu, rowNode](const QString &name, PassmarkLineType lineType)
{
QAction *action = passmarkSubmenu->addAction(name);
action->setCheckable(true);
action->setChecked(rowNode.IsPassmark() && lineType == rowNode.GetPassmarkLineType());
return action;
};
contextMenu.insert(static_cast<int>(ContextMenuOption::OneLine),
InitPassmarkLineTypeAction(tr("One line"), PassmarkLineType::OneLine));
contextMenu.insert(static_cast<int>(ContextMenuOption::TwoLines),
InitPassmarkLineTypeAction(tr("Two lines"), PassmarkLineType::TwoLines));
contextMenu.insert(static_cast<int>(ContextMenuOption::ThreeLines),
InitPassmarkLineTypeAction(tr("Three lines"), PassmarkLineType::ThreeLines));
contextMenu.insert(static_cast<int>(ContextMenuOption::TMark),
InitPassmarkLineTypeAction(tr("T mark"), PassmarkLineType::TMark));
contextMenu.insert(static_cast<int>(ContextMenuOption::ExternalVMark),
InitPassmarkLineTypeAction(tr("External V mark"), PassmarkLineType::ExternalVMark));
contextMenu.insert(static_cast<int>(ContextMenuOption::InternalVMark),
InitPassmarkLineTypeAction(tr("Internal V mark"), PassmarkLineType::InternalVMark));
contextMenu.insert(static_cast<int>(ContextMenuOption::UMark),
InitPassmarkLineTypeAction(tr("U mark"), PassmarkLineType::UMark));
contextMenu.insert(static_cast<int>(ContextMenuOption::BoxMark),
InitPassmarkLineTypeAction(tr("Box mark"), PassmarkLineType::BoxMark));
contextMenu.insert(static_cast<int>(ContextMenuOption::CheckMark),
InitPassmarkLineTypeAction(tr("Check mark"), PassmarkLineType::CheckMark));
}
QAction *actionUniqueness = menu->addAction(tr("Check uniqueness"));
actionUniqueness->setCheckable(true);
actionUniqueness->setChecked(rowNode.IsCheckUniqueness());
contextMenu.insert(static_cast<int>(ContextMenuOption::Uniqueness), actionUniqueness);
QAction *actionTurnPoint = menu->addAction(tr("Turn point"));
actionTurnPoint->setCheckable(true);
actionTurnPoint->setChecked(rowNode.IsTurnPoint());
contextMenu.insert(static_cast<int>(ContextMenuOption::TurnPoint), actionTurnPoint);
}
QAction *actionExcluded = menu->addAction(tr("Excluded"));
actionExcluded->setCheckable(true);
actionExcluded->setChecked(rowNode.IsExcluded());
contextMenu.insert(static_cast<int>(ContextMenuOption::Excluded), actionExcluded);
QAction *actionDelete = menu->addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), tr("Delete"));
contextMenu.insert(static_cast<int>(ContextMenuOption::Delete), actionDelete);
return contextMenu;
}

View File

@ -207,6 +207,8 @@ private:
void InitPassmarkAngleType(const VPieceNode &node);
void InitIcons();
auto InitContextMenu(QMenu *menu, const VPieceNode &rowNode) -> QHash<int, QAction *>;
};
//---------------------------------------------------------------------------------------------------------------------

View File

@ -90,6 +90,27 @@ enum TabOrder
namespace
{
enum class MainPathContextMenuOption : int
{
NoSelection,
Reverse,
NonePassmark,
OneLine,
TwoLines,
ThreeLines,
TMark,
ExternalVMark,
InternalVMark,
UMark,
BoxMark,
CheckMark,
Uniqueness,
TurnPoint,
Excluded,
Delete,
LAST_ONE_DO_NOT_USE
};
//---------------------------------------------------------------------------------------------------------------------
void EnableDefButton(QPushButton *defButton, const QString &formula)
{
@ -774,84 +795,95 @@ void DialogSeamAllowance::ShowMainPathContextMenu(const QPoint &pos)
return;
}
QScopedPointer<QMenu> menu(new QMenu());
QListWidgetItem *rowItem = uiTabPaths->listWidgetMainPath->item(row);
SCASSERT(rowItem != nullptr);
auto rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
QAction *actionPassmark = nullptr;
QAction *actionUniqueness = nullptr;
QAction *actionReverse = nullptr;
QAction *actionTurnPoint = nullptr;
QMenu menu;
QHash<int, QAction *> contextMenu = InitMainPathContextMenu(&menu, rowNode);
if (rowNode.GetTypeTool() != Tool::NodePoint)
QAction *selectedAction = menu.exec(uiTabPaths->listWidgetMainPath->viewport()->mapToGlobal(pos));
auto selectedOption = static_cast<MainPathContextMenuOption>(
contextMenu.key(selectedAction, static_cast<int>(MainPathContextMenuOption::NoSelection)));
auto SelectPassmarkLineType = [this, &rowNode, rowItem](PassmarkLineType type)
{
actionReverse = menu->addAction(tr("Reverse"));
actionReverse->setCheckable(true);
actionReverse->setChecked(rowNode.GetReverse());
}
else
{
if (applyAllowed)
{
actionPassmark = menu->addAction(tr("Passmark"));
actionPassmark->setCheckable(true);
actionPassmark->setChecked(rowNode.IsPassmark());
}
actionUniqueness = menu->addAction(tr("Check uniqueness"));
actionUniqueness->setCheckable(true);
actionUniqueness->setChecked(rowNode.IsCheckUniqueness());
actionTurnPoint = menu->addAction(tr("Turn point"));
actionTurnPoint->setCheckable(true);
actionTurnPoint->setChecked(rowNode.IsTurnPoint());
}
QAction *actionExcluded = menu->addAction(tr("Excluded"));
actionExcluded->setCheckable(true);
actionExcluded->setChecked(rowNode.IsExcluded());
QAction *actionDelete = menu->addAction(QIcon::fromTheme(editDeleteIcon), tr("Delete"));
QAction *selectedAction = menu->exec(uiTabPaths->listWidgetMainPath->viewport()->mapToGlobal(pos));
if (selectedAction == actionDelete)
{
delete uiTabPaths->listWidgetMainPath->item(row);
}
else if (rowNode.GetTypeTool() != Tool::NodePoint && selectedAction == actionReverse)
{
rowNode.SetReverse(not rowNode.GetReverse());
rowNode.SetPassmark(true);
rowNode.SetPassmarkLineType(type);
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, true));
}
else if (selectedAction == actionExcluded)
{
rowNode.SetExcluded(not rowNode.IsExcluded());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, true));
rowItem->setFont(NodeFont(rowItem->font(), rowNode.IsExcluded()));
}
else if (applyAllowed && selectedAction == actionPassmark)
{
rowNode.SetPassmark(not rowNode.IsPassmark());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, true));
}
else if (selectedAction == actionUniqueness)
{
rowNode.SetCheckUniqueness(not rowNode.IsCheckUniqueness());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, true));
}
};
else if (selectedAction == actionTurnPoint)
Q_STATIC_ASSERT_X(static_cast<int>(MainPathContextMenuOption::LAST_ONE_DO_NOT_USE) == 16,
"Not all options were handled.");
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wswitch-default")
switch (selectedOption)
{
rowNode.SetTurnPoint(not rowNode.IsTurnPoint());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, true));
}
case MainPathContextMenuOption::NoSelection:
return;
case MainPathContextMenuOption::Reverse:
rowNode.SetReverse(not rowNode.GetReverse());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, true));
break;
case MainPathContextMenuOption::NonePassmark:
rowNode.SetPassmark(false);
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, true));
break;
case MainPathContextMenuOption::OneLine:
SelectPassmarkLineType(PassmarkLineType::OneLine);
break;
case MainPathContextMenuOption::TwoLines:
SelectPassmarkLineType(PassmarkLineType::TwoLines);
break;
case MainPathContextMenuOption::ThreeLines:
SelectPassmarkLineType(PassmarkLineType::ThreeLines);
break;
case MainPathContextMenuOption::TMark:
SelectPassmarkLineType(PassmarkLineType::TMark);
break;
case MainPathContextMenuOption::ExternalVMark:
SelectPassmarkLineType(PassmarkLineType::ExternalVMark);
break;
case MainPathContextMenuOption::InternalVMark:
SelectPassmarkLineType(PassmarkLineType::InternalVMark);
break;
case MainPathContextMenuOption::UMark:
SelectPassmarkLineType(PassmarkLineType::UMark);
break;
case MainPathContextMenuOption::BoxMark:
SelectPassmarkLineType(PassmarkLineType::BoxMark);
break;
case MainPathContextMenuOption::CheckMark:
SelectPassmarkLineType(PassmarkLineType::CheckMark);
break;
case MainPathContextMenuOption::Uniqueness:
rowNode.SetCheckUniqueness(not rowNode.IsCheckUniqueness());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, true));
break;
case MainPathContextMenuOption::TurnPoint:
rowNode.SetTurnPoint(not rowNode.IsTurnPoint());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, true));
break;
case MainPathContextMenuOption::Excluded:
rowNode.SetExcluded(not rowNode.IsExcluded());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, true));
rowItem->setFont(NodeFont(rowItem->font(), rowNode.IsExcluded()));
break;
case MainPathContextMenuOption::Delete:
delete uiTabPaths->listWidgetMainPath->item(row);
break;
case MainPathContextMenuOption::LAST_ONE_DO_NOT_USE:
Q_UNREACHABLE();
break;
};
QT_WARNING_POP
ValidObjects(MainPathIsValid());
ListChanged();
@ -4492,6 +4524,84 @@ void DialogSeamAllowance::InitIcons()
uiTabPaths->label_3->setPixmap(VTheme::GetPixmapResource(resource, QStringLiteral("32x32/clockwise.png")));
}
//---------------------------------------------------------------------------------------------------------------------
auto DialogSeamAllowance::InitMainPathContextMenu(QMenu *menu, const VPieceNode &rowNode) const -> QHash<int, QAction *>
{
SCASSERT(menu != nullptr)
QHash<int, QAction *> contextMenu;
if (rowNode.GetTypeTool() != Tool::NodePoint)
{
QAction *actionReverse = menu->addAction(tr("Reverse"));
actionReverse->setCheckable(true);
actionReverse->setChecked(rowNode.GetReverse());
contextMenu.insert(static_cast<int>(MainPathContextMenuOption::Reverse), actionReverse);
}
else
{
if (applyAllowed)
{
QMenu *passmarkSubmenu = menu->addMenu(tr("Passmark"));
QAction *actionNonePassmark = passmarkSubmenu->addAction(tr("None"));
actionNonePassmark->setCheckable(true);
actionNonePassmark->setChecked(!rowNode.IsPassmark());
contextMenu.insert(static_cast<int>(MainPathContextMenuOption::NonePassmark), actionNonePassmark);
Q_STATIC_ASSERT_X(static_cast<int>(PassmarkLineType::LAST_ONE_DO_NOT_USE) == 9,
"Not all types were handled.");
auto InitPassmarkLineTypeAction = [passmarkSubmenu, rowNode](const QString &name, PassmarkLineType lineType)
{
QAction *action = passmarkSubmenu->addAction(name);
action->setCheckable(true);
action->setChecked(rowNode.IsPassmark() && lineType == rowNode.GetPassmarkLineType());
return action;
};
contextMenu.insert(static_cast<int>(MainPathContextMenuOption::OneLine),
InitPassmarkLineTypeAction(tr("One line"), PassmarkLineType::OneLine));
contextMenu.insert(static_cast<int>(MainPathContextMenuOption::TwoLines),
InitPassmarkLineTypeAction(tr("Two lines"), PassmarkLineType::TwoLines));
contextMenu.insert(static_cast<int>(MainPathContextMenuOption::ThreeLines),
InitPassmarkLineTypeAction(tr("Three lines"), PassmarkLineType::ThreeLines));
contextMenu.insert(static_cast<int>(MainPathContextMenuOption::TMark),
InitPassmarkLineTypeAction(tr("T mark"), PassmarkLineType::TMark));
contextMenu.insert(static_cast<int>(MainPathContextMenuOption::ExternalVMark),
InitPassmarkLineTypeAction(tr("External V mark"), PassmarkLineType::ExternalVMark));
contextMenu.insert(static_cast<int>(MainPathContextMenuOption::InternalVMark),
InitPassmarkLineTypeAction(tr("Internal V mark"), PassmarkLineType::InternalVMark));
contextMenu.insert(static_cast<int>(MainPathContextMenuOption::UMark),
InitPassmarkLineTypeAction(tr("U mark"), PassmarkLineType::UMark));
contextMenu.insert(static_cast<int>(MainPathContextMenuOption::BoxMark),
InitPassmarkLineTypeAction(tr("Box mark"), PassmarkLineType::BoxMark));
contextMenu.insert(static_cast<int>(MainPathContextMenuOption::CheckMark),
InitPassmarkLineTypeAction(tr("Check mark"), PassmarkLineType::CheckMark));
}
QAction *actionUniqueness = menu->addAction(tr("Check uniqueness"));
actionUniqueness->setCheckable(true);
actionUniqueness->setChecked(rowNode.IsCheckUniqueness());
contextMenu.insert(static_cast<int>(MainPathContextMenuOption::Uniqueness), actionUniqueness);
QAction *actionTurnPoint = menu->addAction(tr("Turn point"));
actionTurnPoint->setCheckable(true);
actionTurnPoint->setChecked(rowNode.IsTurnPoint());
contextMenu.insert(static_cast<int>(MainPathContextMenuOption::TurnPoint), actionTurnPoint);
}
QAction *actionExcluded = menu->addAction(tr("Excluded"));
actionExcluded->setCheckable(true);
actionExcluded->setChecked(rowNode.IsExcluded());
contextMenu.insert(static_cast<int>(MainPathContextMenuOption::Excluded), actionExcluded);
QAction *actionDelete = menu->addAction(QIcon::fromTheme(editDeleteIcon), tr("Delete"));
contextMenu.insert(static_cast<int>(MainPathContextMenuOption::Delete), actionDelete);
return contextMenu;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::SetMoveControls()
{

View File

@ -346,6 +346,8 @@ private:
void InitPassmarkAngleType(const VPieceNode &node);
void InitIcons();
auto InitMainPathContextMenu(QMenu *menu, const VPieceNode &rowNode) const -> QHash<int, QAction *>;
};
//---------------------------------------------------------------------------------------------------------------------

View File

@ -69,7 +69,7 @@ enum class ContextMenuOption : int
{
NoSelection,
ShowLabel,
Passmark,
NonePassmark,
Exclude,
ByLength,
ByPointsIntersection,
@ -89,8 +89,8 @@ enum class ContextMenuOption : int
TwoLines,
ThreeLines,
TMark,
VMark,
VMark2,
ExternalVMark,
InternalVMark,
UMark,
BoxMark,
CheckMark,
@ -326,7 +326,6 @@ auto VNodePoint::InitContextMenu(QMenu *menu, vidtype pieceId, quint32 referens)
InitAngleTypeMenu(menu, pieceId, contextMenu);
InitPassmarkAngleTypeMenu(menu, pieceId, contextMenu);
InitPassmarkLineTypeMenu(menu, pieceId, contextMenu);
auto *separatorAct = new QAction(this);
separatorAct->setSeparator(true);
@ -374,20 +373,53 @@ void VNodePoint::InitPassmarkMenu(QMenu *menu, vidtype pieceId, QHash<int, QActi
const VPiece detail = VAbstractTool::data.GetPiece(pieceId);
const VPiecePath &path = detail.GetPath();
const int nodeIndex = path.indexOfNode(m_id);
if (nodeIndex != -1)
if (nodeIndex == -1)
{
const VPieceNode &node = path.at(nodeIndex);
QAction *actionPassmark = menu->addAction(tr("Passmark"));
actionPassmark->setCheckable(true);
actionPassmark->setChecked(node.IsPassmark());
contextMenu.insert(static_cast<int>(ContextMenuOption::Passmark), actionPassmark);
QAction *actionTurnPoint = menu->addAction(tr("Turn point"));
actionTurnPoint->setCheckable(true);
actionTurnPoint->setChecked(node.IsTurnPoint());
contextMenu.insert(static_cast<int>(ContextMenuOption::TurnPoint), actionTurnPoint);
return;
}
const VPieceNode &node = path.at(nodeIndex);
QMenu *passmarkSubmenu = menu->addMenu(tr("Passmark"));
QAction *actionNonePassmark = passmarkSubmenu->addAction(tr("None"));
actionNonePassmark->setCheckable(true);
actionNonePassmark->setChecked(!node.IsPassmark());
contextMenu.insert(static_cast<int>(ContextMenuOption::NonePassmark), actionNonePassmark);
Q_STATIC_ASSERT_X(static_cast<int>(PassmarkLineType::LAST_ONE_DO_NOT_USE) == 9, "Not all types were handled.");
auto InitPassmarkLineTypeAction = [passmarkSubmenu, node](const QString &name, PassmarkLineType lineType)
{
QAction *action = passmarkSubmenu->addAction(name);
action->setCheckable(true);
action->setChecked(node.IsPassmark() && lineType == node.GetPassmarkLineType());
return action;
};
contextMenu.insert(static_cast<int>(ContextMenuOption::OneLine),
InitPassmarkLineTypeAction(tr("One line"), PassmarkLineType::OneLine));
contextMenu.insert(static_cast<int>(ContextMenuOption::TwoLines),
InitPassmarkLineTypeAction(tr("Two lines"), PassmarkLineType::TwoLines));
contextMenu.insert(static_cast<int>(ContextMenuOption::ThreeLines),
InitPassmarkLineTypeAction(tr("Three lines"), PassmarkLineType::ThreeLines));
contextMenu.insert(static_cast<int>(ContextMenuOption::TMark),
InitPassmarkLineTypeAction(tr("T mark"), PassmarkLineType::TMark));
contextMenu.insert(static_cast<int>(ContextMenuOption::ExternalVMark),
InitPassmarkLineTypeAction(tr("External V mark"), PassmarkLineType::ExternalVMark));
contextMenu.insert(static_cast<int>(ContextMenuOption::InternalVMark),
InitPassmarkLineTypeAction(tr("Internal V mark"), PassmarkLineType::InternalVMark));
contextMenu.insert(static_cast<int>(ContextMenuOption::UMark),
InitPassmarkLineTypeAction(tr("U mark"), PassmarkLineType::UMark));
contextMenu.insert(static_cast<int>(ContextMenuOption::BoxMark),
InitPassmarkLineTypeAction(tr("Box mark"), PassmarkLineType::BoxMark));
contextMenu.insert(static_cast<int>(ContextMenuOption::CheckMark),
InitPassmarkLineTypeAction(tr("Check mark"), PassmarkLineType::CheckMark));
QAction *actionTurnPoint = menu->addAction(tr("Turn point"));
actionTurnPoint->setCheckable(true);
actionTurnPoint->setChecked(node.IsTurnPoint());
contextMenu.insert(static_cast<int>(ContextMenuOption::TurnPoint), actionTurnPoint);
}
//---------------------------------------------------------------------------------------------------------------------
@ -436,29 +468,24 @@ void VNodePoint::InitAngleTypeMenu(QMenu *menu, vidtype pieceId, QHash<int, QAct
//---------------------------------------------------------------------------------------------------------------------
void VNodePoint::InitPassmarkAngleTypeMenu(QMenu *menu, vidtype pieceId, QHash<int, QAction *> &contextMenu)
{
QMenu *passmarkAngleMenu = menu->addMenu(tr("Passmark angle"));
PassmarkAngleType passmarkAngleCurType = PassmarkAngleType::Straightforward;
const VPiece detail = VAbstractTool::data.GetPiece(pieceId);
const VPiecePath &path = detail.GetPath();
const int nodeIndex = path.indexOfNode(m_id);
if (nodeIndex != -1)
if (nodeIndex == -1)
{
const VPieceNode &node = path.at(nodeIndex);
passmarkAngleMenu->setEnabled(node.IsPassmark());
passmarkAngleCurType = node.GetPassmarkAngleType();
}
else
{
passmarkAngleMenu->setVisible(false);
return;
}
auto InitPassmarkAngleAction =
[passmarkAngleMenu, passmarkAngleCurType](const QString &name, PassmarkAngleType checkType)
const VPieceNode &node = path.at(nodeIndex);
QMenu *passmarkAngleMenu = menu->addMenu(tr("Passmark angle"));
auto InitPassmarkAngleAction = [passmarkAngleMenu, node](const QString &name, PassmarkAngleType checkType)
{
QAction *action = passmarkAngleMenu->addAction(name);
action->setCheckable(true);
action->setChecked(passmarkAngleCurType == checkType);
action->setChecked(node.IsPassmark() && node.GetPassmarkAngleType() == checkType);
action->setEnabled(node.IsPassmark());
return action;
};
@ -485,56 +512,6 @@ void VNodePoint::InitPassmarkAngleTypeMenu(QMenu *menu, vidtype pieceId, QHash<i
InitPassmarkAngleAction(tr("Intersection 2 (only right)"), PassmarkAngleType::Intersection2OnlyRight));
}
//---------------------------------------------------------------------------------------------------------------------
void VNodePoint::InitPassmarkLineTypeMenu(QMenu *menu, vidtype pieceId, QHash<int, QAction *> &contextMenu)
{
QMenu *passmarkLineTypeMenu = menu->addMenu(tr("Passmark mark"));
PassmarkLineType passmarkLineCurType = PassmarkLineType::OneLine;
const VPiece detail = VAbstractTool::data.GetPiece(pieceId);
const VPiecePath &path = detail.GetPath();
const int nodeIndex = path.indexOfNode(m_id);
if (nodeIndex != -1)
{
const VPieceNode &node = path.at(nodeIndex);
passmarkLineTypeMenu->setEnabled(node.IsPassmark());
passmarkLineCurType = node.GetPassmarkLineType();
}
else
{
passmarkLineTypeMenu->setVisible(false);
}
auto InitPassmarkLineTypeAction =
[passmarkLineTypeMenu, passmarkLineCurType](const QString &name, PassmarkLineType checkType)
{
QAction *action = passmarkLineTypeMenu->addAction(name);
action->setCheckable(true);
action->setChecked(passmarkLineCurType == checkType);
return action;
};
Q_STATIC_ASSERT_X(static_cast<int>(PassmarkLineType::LAST_ONE_DO_NOT_USE) == 9, "Not all types were handled.");
contextMenu.insert(static_cast<int>(ContextMenuOption::OneLine),
InitPassmarkLineTypeAction(tr("One line"), PassmarkLineType::OneLine));
contextMenu.insert(static_cast<int>(ContextMenuOption::TwoLines),
InitPassmarkLineTypeAction(tr("Two lines"), PassmarkLineType::TwoLines));
contextMenu.insert(static_cast<int>(ContextMenuOption::ThreeLines),
InitPassmarkLineTypeAction(tr("Three lines"), PassmarkLineType::ThreeLines));
contextMenu.insert(static_cast<int>(ContextMenuOption::TMark),
InitPassmarkLineTypeAction(tr("T mark"), PassmarkLineType::TMark));
contextMenu.insert(static_cast<int>(ContextMenuOption::VMark),
InitPassmarkLineTypeAction(tr("External V mark"), PassmarkLineType::ExternalVMark));
contextMenu.insert(static_cast<int>(ContextMenuOption::VMark2),
InitPassmarkLineTypeAction(tr("Internal V mark"), PassmarkLineType::InternalVMark));
contextMenu.insert(static_cast<int>(ContextMenuOption::UMark),
InitPassmarkLineTypeAction(tr("U mark"), PassmarkLineType::UMark));
contextMenu.insert(static_cast<int>(ContextMenuOption::BoxMark),
InitPassmarkLineTypeAction(tr("Box mark"), PassmarkLineType::BoxMark));
contextMenu.insert(static_cast<int>(ContextMenuOption::CheckMark),
InitPassmarkLineTypeAction(tr("Check mark"), PassmarkLineType::CheckMark));
}
//---------------------------------------------------------------------------------------------------------------------
void VNodePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
@ -543,179 +520,180 @@ void VNodePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
return;
}
if (auto *piece = qgraphicsitem_cast<VToolSeamAllowance *>(parentItem()))
auto *piece = qgraphicsitem_cast<VToolSeamAllowance *>(parentItem());
if (piece == nullptr)
{
QMenu menu;
QHash<int, QAction *> contextMenu = InitContextMenu(&menu, piece->getId(), piece->referens());
PieceNodeAngle angleCurType = PieceNodeAngle::ByLength;
PassmarkAngleType passmarkAngleCurType = PassmarkAngleType::Straightforward;
PassmarkLineType passmarkLineCurType = PassmarkLineType::OneLine;
bool isPassmark = false;
const VPiece detail = VAbstractTool::data.GetPiece(piece->getId());
const VPiecePath &path = detail.GetPath();
const int nodeIndex = path.indexOfNode(m_id);
if (nodeIndex != -1)
{
const VPieceNode &node = path.at(nodeIndex);
angleCurType = node.GetAngleType();
passmarkAngleCurType = node.GetPassmarkAngleType();
passmarkLineCurType = node.GetPassmarkLineType();
isPassmark = node.IsPassmark();
}
auto SelectSeamAllowanceAngle = [angleCurType, this](PieceNodeAngle type)
{
if (angleCurType != type)
{
emit ToggleSeamAllowanceAngleType(m_id, type);
}
};
auto SelectPassmarkAngle = [passmarkAngleCurType, this](PassmarkAngleType type)
{
if (passmarkAngleCurType != type)
{
emit TogglePassmarkAngleType(m_id, type);
}
};
auto SelectPassmarkLine = [passmarkLineCurType, this](PassmarkLineType type)
{
if (passmarkLineCurType != type)
{
emit TogglePassmarkLineType(m_id, type);
}
};
QAction *selectedAction = menu.exec(event->screenPos());
ContextMenuOption selectedOption = static_cast<ContextMenuOption>(
contextMenu.key(selectedAction, static_cast<int>(ContextMenuOption::NoSelection)));
Q_STATIC_ASSERT_X(static_cast<int>(ContextMenuOption::LAST_ONE_DO_NOT_USE) == 34,
"Not all options were handled.");
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wswitch-default")
switch (selectedOption)
{
case ContextMenuOption::LAST_ONE_DO_NOT_USE:
Q_UNREACHABLE();
break;
case ContextMenuOption::NoSelection:
return;
case ContextMenuOption::Option:
emit ShowOptions();
break;
case ContextMenuOption::InLayout:
emit ToggleInLayout(selectedAction->isChecked());
break;
case ContextMenuOption::ForbidFlipping:
emit ToggleForbidFlipping(selectedAction->isChecked());
break;
case ContextMenuOption::ForceFlipping:
emit ToggleForceFlipping(selectedAction->isChecked());
break;
case ContextMenuOption::ResetLabelTemplate:
emit ResetPieceLabelTemplate();
break;
case ContextMenuOption::Remove:
try
{
emit Delete();
}
catch (const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return; // Leave this method immediately!!!
}
return; // Leave this method immediately after call!!!
case ContextMenuOption::ShowLabel:
VAbstractApplication::VApp()->getUndoStack()->push(
new ShowLabel(doc, m_id, selectedAction->isChecked()));
break;
case ContextMenuOption::Exclude:
emit ToggleExcludeState(m_id);
break;
case ContextMenuOption::TurnPoint:
emit ToggleTurnPointState(m_id);
break;
case ContextMenuOption::ByLength:
SelectSeamAllowanceAngle(PieceNodeAngle::ByLength);
break;
case ContextMenuOption::ByPointsIntersection:
SelectSeamAllowanceAngle(PieceNodeAngle::ByPointsIntersection);
break;
case ContextMenuOption::ByFirstEdgeSymmetry:
SelectSeamAllowanceAngle(PieceNodeAngle::ByFirstEdgeSymmetry);
break;
case ContextMenuOption::BySecondEdgeSymmetry:
SelectSeamAllowanceAngle(PieceNodeAngle::BySecondEdgeSymmetry);
break;
case ContextMenuOption::ByFirstEdgeRightAngle:
SelectSeamAllowanceAngle(PieceNodeAngle::ByFirstEdgeRightAngle);
break;
case ContextMenuOption::BySecondEdgeRightAngle:
SelectSeamAllowanceAngle(PieceNodeAngle::BySecondEdgeRightAngle);
break;
case ContextMenuOption::Passmark:
emit TogglePassmark(m_id, not isPassmark);
break;
case ContextMenuOption::Straightforward:
SelectPassmarkAngle(PassmarkAngleType::Straightforward);
break;
case ContextMenuOption::Bisector:
SelectPassmarkAngle(PassmarkAngleType::Bisector);
break;
case ContextMenuOption::Intersection:
SelectPassmarkAngle(PassmarkAngleType::Intersection);
break;
case ContextMenuOption::IntersectionOnlyLeft:
SelectPassmarkAngle(PassmarkAngleType::IntersectionOnlyLeft);
break;
case ContextMenuOption::IntersectionOnlyRight:
SelectPassmarkAngle(PassmarkAngleType::IntersectionOnlyRight);
break;
case ContextMenuOption::Intersection2:
SelectPassmarkAngle(PassmarkAngleType::Intersection2);
break;
case ContextMenuOption::Intersection2OnlyLeft:
SelectPassmarkAngle(PassmarkAngleType::Intersection2OnlyLeft);
break;
case ContextMenuOption::Intersection2OnlyRight:
SelectPassmarkAngle(PassmarkAngleType::Intersection2OnlyRight);
break;
case ContextMenuOption::OneLine:
SelectPassmarkLine(PassmarkLineType::OneLine);
break;
case ContextMenuOption::TwoLines:
SelectPassmarkLine(PassmarkLineType::TwoLines);
break;
case ContextMenuOption::ThreeLines:
SelectPassmarkLine(PassmarkLineType::ThreeLines);
break;
case ContextMenuOption::TMark:
SelectPassmarkLine(PassmarkLineType::TMark);
break;
case ContextMenuOption::VMark:
SelectPassmarkLine(PassmarkLineType::ExternalVMark);
break;
case ContextMenuOption::VMark2:
SelectPassmarkLine(PassmarkLineType::InternalVMark);
break;
case ContextMenuOption::UMark:
SelectPassmarkLine(PassmarkLineType::UMark);
break;
case ContextMenuOption::BoxMark:
SelectPassmarkLine(PassmarkLineType::BoxMark);
break;
case ContextMenuOption::CheckMark:
SelectPassmarkLine(PassmarkLineType::CheckMark);
break;
};
QT_WARNING_POP
return;
}
QMenu menu;
QHash<int, QAction *> contextMenu = InitContextMenu(&menu, piece->getId(), piece->referens());
PieceNodeAngle angleCurType = PieceNodeAngle::ByLength;
PassmarkAngleType passmarkAngleCurType = PassmarkAngleType::Straightforward;
PassmarkLineType passmarkLineCurType = PassmarkLineType::OneLine;
const VPiece detail = VAbstractTool::data.GetPiece(piece->getId());
const VPiecePath &path = detail.GetPath();
const int nodeIndex = path.indexOfNode(m_id);
if (nodeIndex != -1)
{
const VPieceNode &node = path.at(nodeIndex);
angleCurType = node.GetAngleType();
passmarkAngleCurType = node.GetPassmarkAngleType();
passmarkLineCurType = node.GetPassmarkLineType();
}
auto SelectSeamAllowanceAngle = [angleCurType, this](PieceNodeAngle type)
{
if (angleCurType != type)
{
emit ToggleSeamAllowanceAngleType(m_id, type);
}
};
auto SelectPassmarkAngle = [passmarkAngleCurType, this](PassmarkAngleType type)
{
if (passmarkAngleCurType != type)
{
emit TogglePassmarkAngleType(m_id, type);
}
};
auto SelectPassmarkLine = [passmarkLineCurType, this](PassmarkLineType type)
{
emit TogglePassmark(m_id, true);
if (passmarkLineCurType != type)
{
emit TogglePassmarkLineType(m_id, type);
}
};
QAction *selectedAction = menu.exec(event->screenPos());
ContextMenuOption selectedOption = static_cast<ContextMenuOption>(
contextMenu.key(selectedAction, static_cast<int>(ContextMenuOption::NoSelection)));
Q_STATIC_ASSERT_X(static_cast<int>(ContextMenuOption::LAST_ONE_DO_NOT_USE) == 34, "Not all options were handled.");
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wswitch-default")
switch (selectedOption)
{
case ContextMenuOption::LAST_ONE_DO_NOT_USE:
Q_UNREACHABLE();
break;
case ContextMenuOption::NoSelection:
return;
case ContextMenuOption::Option:
emit ShowOptions();
break;
case ContextMenuOption::InLayout:
emit ToggleInLayout(selectedAction->isChecked());
break;
case ContextMenuOption::ForbidFlipping:
emit ToggleForbidFlipping(selectedAction->isChecked());
break;
case ContextMenuOption::ForceFlipping:
emit ToggleForceFlipping(selectedAction->isChecked());
break;
case ContextMenuOption::ResetLabelTemplate:
emit ResetPieceLabelTemplate();
break;
case ContextMenuOption::Remove:
try
{
emit Delete();
}
catch (const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return; // Leave this method immediately!!!
}
return; // Leave this method immediately after call!!!
case ContextMenuOption::ShowLabel:
VAbstractApplication::VApp()->getUndoStack()->push(new ShowLabel(doc, m_id, selectedAction->isChecked()));
break;
case ContextMenuOption::Exclude:
emit ToggleExcludeState(m_id);
break;
case ContextMenuOption::TurnPoint:
emit ToggleTurnPointState(m_id);
break;
case ContextMenuOption::ByLength:
SelectSeamAllowanceAngle(PieceNodeAngle::ByLength);
break;
case ContextMenuOption::ByPointsIntersection:
SelectSeamAllowanceAngle(PieceNodeAngle::ByPointsIntersection);
break;
case ContextMenuOption::ByFirstEdgeSymmetry:
SelectSeamAllowanceAngle(PieceNodeAngle::ByFirstEdgeSymmetry);
break;
case ContextMenuOption::BySecondEdgeSymmetry:
SelectSeamAllowanceAngle(PieceNodeAngle::BySecondEdgeSymmetry);
break;
case ContextMenuOption::ByFirstEdgeRightAngle:
SelectSeamAllowanceAngle(PieceNodeAngle::ByFirstEdgeRightAngle);
break;
case ContextMenuOption::BySecondEdgeRightAngle:
SelectSeamAllowanceAngle(PieceNodeAngle::BySecondEdgeRightAngle);
break;
case ContextMenuOption::NonePassmark:
emit TogglePassmark(m_id, false);
break;
case ContextMenuOption::Straightforward:
SelectPassmarkAngle(PassmarkAngleType::Straightforward);
break;
case ContextMenuOption::Bisector:
SelectPassmarkAngle(PassmarkAngleType::Bisector);
break;
case ContextMenuOption::Intersection:
SelectPassmarkAngle(PassmarkAngleType::Intersection);
break;
case ContextMenuOption::IntersectionOnlyLeft:
SelectPassmarkAngle(PassmarkAngleType::IntersectionOnlyLeft);
break;
case ContextMenuOption::IntersectionOnlyRight:
SelectPassmarkAngle(PassmarkAngleType::IntersectionOnlyRight);
break;
case ContextMenuOption::Intersection2:
SelectPassmarkAngle(PassmarkAngleType::Intersection2);
break;
case ContextMenuOption::Intersection2OnlyLeft:
SelectPassmarkAngle(PassmarkAngleType::Intersection2OnlyLeft);
break;
case ContextMenuOption::Intersection2OnlyRight:
SelectPassmarkAngle(PassmarkAngleType::Intersection2OnlyRight);
break;
case ContextMenuOption::OneLine:
SelectPassmarkLine(PassmarkLineType::OneLine);
break;
case ContextMenuOption::TwoLines:
SelectPassmarkLine(PassmarkLineType::TwoLines);
break;
case ContextMenuOption::ThreeLines:
SelectPassmarkLine(PassmarkLineType::ThreeLines);
break;
case ContextMenuOption::TMark:
SelectPassmarkLine(PassmarkLineType::TMark);
break;
case ContextMenuOption::ExternalVMark:
SelectPassmarkLine(PassmarkLineType::ExternalVMark);
break;
case ContextMenuOption::InternalVMark:
SelectPassmarkLine(PassmarkLineType::InternalVMark);
break;
case ContextMenuOption::UMark:
SelectPassmarkLine(PassmarkLineType::UMark);
break;
case ContextMenuOption::BoxMark:
SelectPassmarkLine(PassmarkLineType::BoxMark);
break;
case ContextMenuOption::CheckMark:
SelectPassmarkLine(PassmarkLineType::CheckMark);
break;
};
QT_WARNING_POP
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -106,7 +106,6 @@ private:
void InitPassmarkMenu(QMenu *menu, vidtype pieceId, QHash<int, QAction *> &contextMenu);
void InitAngleTypeMenu(QMenu *menu, vidtype pieceId, QHash<int, QAction *> &contextMenu);
void InitPassmarkAngleTypeMenu(QMenu *menu, vidtype pieceId, QHash<int, QAction *> &contextMenu);
void InitPassmarkLineTypeMenu(QMenu *menu, vidtype pieceId, QHash<int, QAction *> &contextMenu);
};
#endif // VNODEPOINT_H