54 #include "ui_insert_nodes_dialog.h"
55 #include "../vpatterndb/vcontainer.h"
56 #include "../vmisc/vabstractapplication.h"
57 #include "../vmisc/vcommonsettings.h"
71 , m_beep(
new QSound(
qApp->Settings()->getSelectionSound()))
74 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
75 setWindowIcon(QIcon(
":/toolicon/32x32/insert_nodes_icon.png"));
76 ui->statusMsg_Label->setText(
"");
78 ui->nodes_ListWidget->installEventFilter(
this);
80 initializeOkCancel(ui);
84 connect(ui->piece_ComboBox,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
this, [
this]()
114 for (qint32 i = 0; i <
ui->nodes_ListWidget->count(); ++i)
116 VPieceNode node = qvariant_cast<VPieceNode>(
ui->nodes_ListWidget->item(i)->data(Qt::UserRole));
165 [objId](
const VPieceNode &node) { return node.GetId() == objId; });
168 if (nodeIterator ==
m_nodes.cend())
177 qDebug() <<
"Cannot find an object with id" << objId;
181 bool appendCurve =
false;
195 if (previousObj !=
nullptr)
197 GOType previousObjType = previousObj->getType();
204 if (curve->isPointOnCurve(point) &&
205 point != curve->getFirstPoint() &&
206 point != curve->getLastPoint())
208 switch (previousObjType)
253 qDebug() <<
"Ignore unknown object type.";
272 if (nodeIterator !=
m_nodes.end())
289 const int row =
ui->nodes_ListWidget->currentRow();
290 if (
ui->nodes_ListWidget->count() == 0 || row == -1 || row >=
ui->nodes_ListWidget->count())
296 QScopedPointer<QMenu> menu(
new QMenu(
ui->nodes_ListWidget));
299 bool isNotch =
false;
300 QListWidgetItem *rowItem =
ui->nodes_ListWidget->item(row);
302 VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
304 QAction *actionNotch =
nullptr;
305 QAction *actionNone =
nullptr;
306 QAction *actionSlit =
nullptr;
307 QAction *actionTNotch =
nullptr;
308 QAction *actionUNotch =
nullptr;
309 QAction *actionVInternal =
nullptr;
310 QAction *actionVExternal =
nullptr;
311 QAction *actionCastle =
nullptr;
312 QAction *actionDiamond =
nullptr;
313 QAction *actionReverse =
nullptr;
317 actionReverse = menu->addAction(tr(
"Reverse"));
318 actionReverse->setCheckable(
true);
319 actionReverse->setChecked(rowNode.
GetReverse());
324 QMenu *notchMenu = menu->addMenu(tr(
"Notch"));
325 actionNotch = notchMenu->menuAction();
326 actionNotch->setCheckable(
true);
327 actionNotch->setChecked(rowNode.
isNotch());
329 actionNone = notchMenu->addAction( tr(
"None"));
330 actionSlit = notchMenu->addAction(QIcon(
"://icon/24x24/slit_notch.png"), tr(
"Slit"));
331 actionTNotch = notchMenu->addAction(QIcon(
"://icon/24x24/t_notch.png"), tr(
"TNotch"));
332 actionUNotch = notchMenu->addAction(QIcon(
"://icon/24x24/u_notch.png"), tr(
"UNotch"));
333 actionVInternal = notchMenu->addAction(QIcon(
"://icon/24x24/internal_v_notch.png"), tr(
"VInternal"));
334 actionVExternal = notchMenu->addAction(QIcon(
"://icon/24x24/external_v_notch.png"), tr(
"VExternal"));
335 actionCastle = notchMenu->addAction(QIcon(
"://icon/24x24/castle_notch.png"), tr(
"Castle"));
336 actionDiamond = notchMenu->addAction(QIcon(
"://icon/24x24/diamond_notch.png"), tr(
"Diamond"));
339 QAction *actionDelete = menu->addAction(QIcon::fromTheme(
"edit-delete"), tr(
"Delete") + QStringLiteral(
"\tDel"));
340 QAction *selectedAction = menu->exec(
ui->nodes_ListWidget->viewport()->mapToGlobal(pos));
345 rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
346 rowItem->setIcon(QIcon(info.
icon));
347 rowItem->setText(info.
name);
349 else if (selectedAction == actionDelete)
352 if (
ui->nodes_ListWidget->count() == 0)
354 ui->statusMsg_Label->setText(tr(
"No nodes selected. Press Cancel to continue"));
359 if (selectedAction == actionNone)
364 else if (selectedAction == actionSlit)
369 else if (selectedAction == actionTNotch)
374 else if (selectedAction == actionUNotch)
379 else if (selectedAction == actionVInternal)
384 else if (selectedAction == actionVExternal)
389 else if (selectedAction == actionCastle)
394 else if (selectedAction == actionDiamond)
403 rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
404 rowItem->setIcon(QIcon(info.
icon));
405 rowItem->setText(info.
name);
432 if (QListWidget *list = qobject_cast<QListWidget *>(
object))
434 if (event->type() == QEvent::KeyPress)
436 QKeyEvent *keyEvent =
static_cast<QKeyEvent *
>(event);
437 if (keyEvent->key() == Qt::Key_Delete)
439 const int row =
ui->nodes_ListWidget->currentRow();
440 if (
ui->nodes_ListWidget->count() > 0 || row > -1 || row <
ui->nodes_ListWidget->count())
442 QListWidgetItem *rowItem = list->item(row);
461 if (
ui->piece_ComboBox->count() <= 0 ||
ui->piece_ComboBox->currentIndex() == -1)
509 const QString curveName = curveObj->name();
515 nodeId = node.GetId();
520 if (point == curve->getLastPoint())
522 ui->statusMsg_Label->setText(
ui->statusMsg_Label->text() + curveName +
523 tr(
" was auto reversed.") +
"\n");
526 else if (point == curve->getFirstPoint())
532 ui->statusMsg_Label->setText(
ui->statusMsg_Label->text() + curveName +
533 tr(
" may need to be manually reversed.") +
"\n");
546 quint32 curveNodeId = curveNode.
GetId();
549 for (
int i = 0; i <
m_nodes.size(); ++i)
551 nodeId =
m_nodes.value(i).GetId();
556 if (curve->isPointOnCurve(point) &&
557 point != curve->getFirstPoint() &&
558 point != curve->getLastPoint() &&
559 curveNodeId != nodeId)
563 prevNodeId =
m_nodes.value(i - 1).GetId();
565 if (i == 0 || prevNodeId != curveNodeId)
QVector< VPieceNode > m_nodes
virtual void SelectedObject(bool selected, quint32 object, quint32 tool) Q_DECL_OVERRIDE
Ui::InsertNodesDialog * ui
bool correctCurveDirection(quint32 objectId)
virtual ~InsertNodesDialog()
quint32 getLastNodeId() const
QVector< VPieceNode > getNodes() const
quint32 getPieceId() const
InsertNodesDialog(const VContainer *data, quint32 toolId, QWidget *parent=nullptr)
void showContextMenu(const QPoint &pos)
virtual bool eventFilter(QObject *object, QEvent *event) Q_DECL_OVERRIDE
virtual void ShowDialog(bool click) Q_DECL_OVERRIDE
virtual void SetPiecesList(const QVector< quint32 > &list) Q_DECL_OVERRIDE
void insertCurveNodes(VPieceNode curveNode)
virtual void checkState() Q_DECL_FINAL
The VContainer class container of all variables.
const QSharedPointer< VGObject > GetGObject(quint32 id) const
GetGObject returns a point by id.
const QSharedPointer< T > GeometricObject(const quint32 &id) const
The VExceptionBadId class for exception bad id.
void SetExcluded(bool exclude)
void setNotch(bool notch)
void setNotchType(NotchType notchType)
void SetReverse(bool reverse)
The VPointF class keep data of point.