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

View File

@ -51,6 +51,27 @@
namespace 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> auto CuttingPath(quint32 id, const VContainer *data) -> QVector<QPointF>
{ {
QVector<QPointF> path; QVector<QPointF> path;
@ -340,85 +361,94 @@ void DialogPiecePath::ShowContextMenu(const QPoint &pos)
return; return;
} }
QScopedPointer<QMenu> menu(new QMenu());
QListWidgetItem *rowItem = ui->listWidget->item(row); QListWidgetItem *rowItem = ui->listWidget->item(row);
SCASSERT(rowItem != nullptr); SCASSERT(rowItem != nullptr);
auto rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole)); auto rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
QAction *actionPassmark = nullptr; QMenu menu;
QAction *actionUniqueness = nullptr; QHash<int, QAction *> contextMenu = InitContextMenu(&menu, rowNode);
QAction *actionReverse = nullptr;
QAction *actionTurnPoint = nullptr;
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")); rowNode.SetPassmark(true);
actionReverse->setCheckable(true); rowNode.SetPassmarkLineType(type);
actionReverse->setChecked(rowNode.GetReverse()); rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
} rowItem->setText(GetNodeName(data, rowNode, IsShowNotch()));
else };
{
if (m_showMode && GetType() == PiecePathType::CustomSeamAllowance && Q_STATIC_ASSERT_X(static_cast<int>(ContextMenuOption::LAST_ONE_DO_NOT_USE) == 16, "Not all options were handled.");
ui->tabWidget->indexOf(ui->tabPassmarks) != -1)
{ QT_WARNING_PUSH
actionPassmark = menu->addAction(tr("Passmark")); QT_WARNING_DISABLE_GCC("-Wswitch-default")
actionPassmark->setCheckable(true); switch (selectedOption)
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)
{ {
case ContextMenuOption::NoSelection:
return;
case ContextMenuOption::Reverse:
rowNode.SetReverse(not rowNode.GetReverse()); rowNode.SetReverse(not rowNode.GetReverse());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, IsShowNotch())); rowItem->setText(GetNodeName(data, rowNode, IsShowNotch()));
} break;
else if (m_showMode && rowNode.GetTypeTool() == Tool::NodePoint && selectedAction == actionPassmark && case ContextMenuOption::NonePassmark:
GetType() == PiecePathType::CustomSeamAllowance && ui->tabWidget->indexOf(ui->tabPassmarks) != -1) rowNode.SetPassmark(false);
{
rowNode.SetPassmark(not rowNode.IsPassmark());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, IsShowNotch())); rowItem->setText(GetNodeName(data, rowNode, IsShowNotch()));
} break;
else if (selectedAction == actionExcluded) 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()); rowNode.SetExcluded(not rowNode.IsExcluded());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, true)); rowItem->setText(GetNodeName(data, rowNode, true));
rowItem->setFont(NodeFont(rowItem->font(), rowNode.IsExcluded())); rowItem->setFont(NodeFont(rowItem->font(), rowNode.IsExcluded()));
} break;
else if (rowNode.GetTypeTool() == Tool::NodePoint && selectedAction == actionUniqueness) case ContextMenuOption::Delete:
{ delete ui->listWidget->item(row);
rowNode.SetCheckUniqueness(not rowNode.IsCheckUniqueness()); break;
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); case ContextMenuOption::LAST_ONE_DO_NOT_USE:
rowItem->setText(GetNodeName(data, rowNode, IsShowNotch())); Q_UNREACHABLE();
} break;
else if (rowNode.GetTypeTool() == Tool::NodePoint && selectedAction == actionTurnPoint) };
{ QT_WARNING_POP
rowNode.SetTurnPoint(not rowNode.IsTurnPoint());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, IsShowNotch()));
}
ValidObjects(PathIsValid()); ValidObjects(PathIsValid());
ListChanged(); ListChanged();
@ -2245,3 +2275,81 @@ void DialogPiecePath::InitIcons()
ui->label_10->setPixmap(VTheme::GetPixmapResource(resource, equalIcon)); ui->label_10->setPixmap(VTheme::GetPixmapResource(resource, equalIcon));
ui->label_5->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 InitPassmarkAngleType(const VPieceNode &node);
void InitIcons(); void InitIcons();
auto InitContextMenu(QMenu *menu, const VPieceNode &rowNode) -> QHash<int, QAction *>;
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -90,6 +90,27 @@ enum TabOrder
namespace 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) void EnableDefButton(QPushButton *defButton, const QString &formula)
{ {
@ -774,84 +795,95 @@ void DialogSeamAllowance::ShowMainPathContextMenu(const QPoint &pos)
return; return;
} }
QScopedPointer<QMenu> menu(new QMenu());
QListWidgetItem *rowItem = uiTabPaths->listWidgetMainPath->item(row); QListWidgetItem *rowItem = uiTabPaths->listWidgetMainPath->item(row);
SCASSERT(rowItem != nullptr); SCASSERT(rowItem != nullptr);
auto rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole)); auto rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
QAction *actionPassmark = nullptr; QMenu menu;
QAction *actionUniqueness = nullptr; QHash<int, QAction *> contextMenu = InitMainPathContextMenu(&menu, rowNode);
QAction *actionReverse = nullptr;
QAction *actionTurnPoint = nullptr;
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")); rowNode.SetPassmark(true);
actionReverse->setCheckable(true); rowNode.SetPassmarkLineType(type);
actionReverse->setChecked(rowNode.GetReverse()); rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
} rowItem->setText(GetNodeName(data, rowNode, true));
else };
{
if (applyAllowed) Q_STATIC_ASSERT_X(static_cast<int>(MainPathContextMenuOption::LAST_ONE_DO_NOT_USE) == 16,
{ "Not all options were handled.");
actionPassmark = menu->addAction(tr("Passmark"));
actionPassmark->setCheckable(true); QT_WARNING_PUSH
actionPassmark->setChecked(rowNode.IsPassmark()); QT_WARNING_DISABLE_GCC("-Wswitch-default")
} switch (selectedOption)
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)
{ {
case MainPathContextMenuOption::NoSelection:
return;
case MainPathContextMenuOption::Reverse:
rowNode.SetReverse(not rowNode.GetReverse()); rowNode.SetReverse(not rowNode.GetReverse());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, true)); rowItem->setText(GetNodeName(data, rowNode, true));
} break;
else if (selectedAction == actionExcluded) 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()); rowNode.SetExcluded(not rowNode.IsExcluded());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, true)); rowItem->setText(GetNodeName(data, rowNode, true));
rowItem->setFont(NodeFont(rowItem->font(), rowNode.IsExcluded())); rowItem->setFont(NodeFont(rowItem->font(), rowNode.IsExcluded()));
} break;
else if (applyAllowed && selectedAction == actionPassmark) case MainPathContextMenuOption::Delete:
{ delete uiTabPaths->listWidgetMainPath->item(row);
rowNode.SetPassmark(not rowNode.IsPassmark()); break;
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); case MainPathContextMenuOption::LAST_ONE_DO_NOT_USE:
rowItem->setText(GetNodeName(data, rowNode, true)); Q_UNREACHABLE();
} break;
else if (selectedAction == actionUniqueness) };
{ QT_WARNING_POP
rowNode.SetCheckUniqueness(not rowNode.IsCheckUniqueness());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, true));
}
else if (selectedAction == actionTurnPoint)
{
rowNode.SetTurnPoint(not rowNode.IsTurnPoint());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(data, rowNode, true));
}
ValidObjects(MainPathIsValid()); ValidObjects(MainPathIsValid());
ListChanged(); ListChanged();
@ -4492,6 +4524,84 @@ void DialogSeamAllowance::InitIcons()
uiTabPaths->label_3->setPixmap(VTheme::GetPixmapResource(resource, QStringLiteral("32x32/clockwise.png"))); 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() void DialogSeamAllowance::SetMoveControls()
{ {

View File

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

View File

@ -69,7 +69,7 @@ enum class ContextMenuOption : int
{ {
NoSelection, NoSelection,
ShowLabel, ShowLabel,
Passmark, NonePassmark,
Exclude, Exclude,
ByLength, ByLength,
ByPointsIntersection, ByPointsIntersection,
@ -89,8 +89,8 @@ enum class ContextMenuOption : int
TwoLines, TwoLines,
ThreeLines, ThreeLines,
TMark, TMark,
VMark, ExternalVMark,
VMark2, InternalVMark,
UMark, UMark,
BoxMark, BoxMark,
CheckMark, CheckMark,
@ -326,7 +326,6 @@ auto VNodePoint::InitContextMenu(QMenu *menu, vidtype pieceId, quint32 referens)
InitAngleTypeMenu(menu, pieceId, contextMenu); InitAngleTypeMenu(menu, pieceId, contextMenu);
InitPassmarkAngleTypeMenu(menu, pieceId, contextMenu); InitPassmarkAngleTypeMenu(menu, pieceId, contextMenu);
InitPassmarkLineTypeMenu(menu, pieceId, contextMenu);
auto *separatorAct = new QAction(this); auto *separatorAct = new QAction(this);
separatorAct->setSeparator(true); 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 VPiece detail = VAbstractTool::data.GetPiece(pieceId);
const VPiecePath &path = detail.GetPath(); const VPiecePath &path = detail.GetPath();
const int nodeIndex = path.indexOfNode(m_id); const int nodeIndex = path.indexOfNode(m_id);
if (nodeIndex != -1) if (nodeIndex == -1)
{ {
return;
}
const VPieceNode &node = path.at(nodeIndex); const VPieceNode &node = path.at(nodeIndex);
QAction *actionPassmark = menu->addAction(tr("Passmark")); QMenu *passmarkSubmenu = menu->addMenu(tr("Passmark"));
actionPassmark->setCheckable(true);
actionPassmark->setChecked(node.IsPassmark()); QAction *actionNonePassmark = passmarkSubmenu->addAction(tr("None"));
contextMenu.insert(static_cast<int>(ContextMenuOption::Passmark), actionPassmark); 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")); QAction *actionTurnPoint = menu->addAction(tr("Turn point"));
actionTurnPoint->setCheckable(true); actionTurnPoint->setCheckable(true);
actionTurnPoint->setChecked(node.IsTurnPoint()); actionTurnPoint->setChecked(node.IsTurnPoint());
contextMenu.insert(static_cast<int>(ContextMenuOption::TurnPoint), actionTurnPoint); 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) 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 VPiece detail = VAbstractTool::data.GetPiece(pieceId);
const VPiecePath &path = detail.GetPath(); const VPiecePath &path = detail.GetPath();
const int nodeIndex = path.indexOfNode(m_id); const int nodeIndex = path.indexOfNode(m_id);
if (nodeIndex != -1) if (nodeIndex == -1)
{ {
const VPieceNode &node = path.at(nodeIndex); return;
passmarkAngleMenu->setEnabled(node.IsPassmark());
passmarkAngleCurType = node.GetPassmarkAngleType();
}
else
{
passmarkAngleMenu->setVisible(false);
} }
auto InitPassmarkAngleAction = const VPieceNode &node = path.at(nodeIndex);
[passmarkAngleMenu, passmarkAngleCurType](const QString &name, PassmarkAngleType checkType)
QMenu *passmarkAngleMenu = menu->addMenu(tr("Passmark angle"));
auto InitPassmarkAngleAction = [passmarkAngleMenu, node](const QString &name, PassmarkAngleType checkType)
{ {
QAction *action = passmarkAngleMenu->addAction(name); QAction *action = passmarkAngleMenu->addAction(name);
action->setCheckable(true); action->setCheckable(true);
action->setChecked(passmarkAngleCurType == checkType); action->setChecked(node.IsPassmark() && node.GetPassmarkAngleType() == checkType);
action->setEnabled(node.IsPassmark());
return action; return action;
}; };
@ -485,56 +512,6 @@ void VNodePoint::InitPassmarkAngleTypeMenu(QMenu *menu, vidtype pieceId, QHash<i
InitPassmarkAngleAction(tr("Intersection 2 (only right)"), PassmarkAngleType::Intersection2OnlyRight)); 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) void VNodePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{ {
@ -543,15 +520,18 @@ void VNodePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
return; return;
} }
if (auto *piece = qgraphicsitem_cast<VToolSeamAllowance *>(parentItem())) auto *piece = qgraphicsitem_cast<VToolSeamAllowance *>(parentItem());
if (piece == nullptr)
{ {
return;
}
QMenu menu; QMenu menu;
QHash<int, QAction *> contextMenu = InitContextMenu(&menu, piece->getId(), piece->referens()); QHash<int, QAction *> contextMenu = InitContextMenu(&menu, piece->getId(), piece->referens());
PieceNodeAngle angleCurType = PieceNodeAngle::ByLength; PieceNodeAngle angleCurType = PieceNodeAngle::ByLength;
PassmarkAngleType passmarkAngleCurType = PassmarkAngleType::Straightforward; PassmarkAngleType passmarkAngleCurType = PassmarkAngleType::Straightforward;
PassmarkLineType passmarkLineCurType = PassmarkLineType::OneLine; PassmarkLineType passmarkLineCurType = PassmarkLineType::OneLine;
bool isPassmark = false;
const VPiece detail = VAbstractTool::data.GetPiece(piece->getId()); const VPiece detail = VAbstractTool::data.GetPiece(piece->getId());
const VPiecePath &path = detail.GetPath(); const VPiecePath &path = detail.GetPath();
@ -562,7 +542,6 @@ void VNodePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
angleCurType = node.GetAngleType(); angleCurType = node.GetAngleType();
passmarkAngleCurType = node.GetPassmarkAngleType(); passmarkAngleCurType = node.GetPassmarkAngleType();
passmarkLineCurType = node.GetPassmarkLineType(); passmarkLineCurType = node.GetPassmarkLineType();
isPassmark = node.IsPassmark();
} }
auto SelectSeamAllowanceAngle = [angleCurType, this](PieceNodeAngle type) auto SelectSeamAllowanceAngle = [angleCurType, this](PieceNodeAngle type)
@ -583,6 +562,8 @@ void VNodePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
auto SelectPassmarkLine = [passmarkLineCurType, this](PassmarkLineType type) auto SelectPassmarkLine = [passmarkLineCurType, this](PassmarkLineType type)
{ {
emit TogglePassmark(m_id, true);
if (passmarkLineCurType != type) if (passmarkLineCurType != type)
{ {
emit TogglePassmarkLineType(m_id, type); emit TogglePassmarkLineType(m_id, type);
@ -593,8 +574,7 @@ void VNodePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
ContextMenuOption selectedOption = static_cast<ContextMenuOption>( ContextMenuOption selectedOption = static_cast<ContextMenuOption>(
contextMenu.key(selectedAction, static_cast<int>(ContextMenuOption::NoSelection))); contextMenu.key(selectedAction, static_cast<int>(ContextMenuOption::NoSelection)));
Q_STATIC_ASSERT_X(static_cast<int>(ContextMenuOption::LAST_ONE_DO_NOT_USE) == 34, Q_STATIC_ASSERT_X(static_cast<int>(ContextMenuOption::LAST_ONE_DO_NOT_USE) == 34, "Not all options were handled.");
"Not all options were handled.");
QT_WARNING_PUSH QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wswitch-default") QT_WARNING_DISABLE_GCC("-Wswitch-default")
@ -632,8 +612,7 @@ void VNodePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
} }
return; // Leave this method immediately after call!!! return; // Leave this method immediately after call!!!
case ContextMenuOption::ShowLabel: case ContextMenuOption::ShowLabel:
VAbstractApplication::VApp()->getUndoStack()->push( VAbstractApplication::VApp()->getUndoStack()->push(new ShowLabel(doc, m_id, selectedAction->isChecked()));
new ShowLabel(doc, m_id, selectedAction->isChecked()));
break; break;
case ContextMenuOption::Exclude: case ContextMenuOption::Exclude:
emit ToggleExcludeState(m_id); emit ToggleExcludeState(m_id);
@ -659,8 +638,8 @@ void VNodePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
case ContextMenuOption::BySecondEdgeRightAngle: case ContextMenuOption::BySecondEdgeRightAngle:
SelectSeamAllowanceAngle(PieceNodeAngle::BySecondEdgeRightAngle); SelectSeamAllowanceAngle(PieceNodeAngle::BySecondEdgeRightAngle);
break; break;
case ContextMenuOption::Passmark: case ContextMenuOption::NonePassmark:
emit TogglePassmark(m_id, not isPassmark); emit TogglePassmark(m_id, false);
break; break;
case ContextMenuOption::Straightforward: case ContextMenuOption::Straightforward:
SelectPassmarkAngle(PassmarkAngleType::Straightforward); SelectPassmarkAngle(PassmarkAngleType::Straightforward);
@ -698,10 +677,10 @@ void VNodePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
case ContextMenuOption::TMark: case ContextMenuOption::TMark:
SelectPassmarkLine(PassmarkLineType::TMark); SelectPassmarkLine(PassmarkLineType::TMark);
break; break;
case ContextMenuOption::VMark: case ContextMenuOption::ExternalVMark:
SelectPassmarkLine(PassmarkLineType::ExternalVMark); SelectPassmarkLine(PassmarkLineType::ExternalVMark);
break; break;
case ContextMenuOption::VMark2: case ContextMenuOption::InternalVMark:
SelectPassmarkLine(PassmarkLineType::InternalVMark); SelectPassmarkLine(PassmarkLineType::InternalVMark);
break; break;
case ContextMenuOption::UMark: case ContextMenuOption::UMark:
@ -715,7 +694,6 @@ void VNodePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
break; break;
}; };
QT_WARNING_POP QT_WARNING_POP
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

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