diff --git a/src/Editor/WorldEditor/WModifyTab.cpp b/src/Editor/WorldEditor/WModifyTab.cpp index 28c34acc..3c94278d 100644 --- a/src/Editor/WorldEditor/WModifyTab.cpp +++ b/src/Editor/WorldEditor/WModifyTab.cpp @@ -2,6 +2,7 @@ #include "ui_WModifyTab.h" #include "CLinkDialog.h" +#include "CSelectInstanceDialog.h" #include "CWorldEditor.h" #include "Editor/Undo/UndoCommands.h" #include @@ -12,6 +13,7 @@ WModifyTab::WModifyTab(QWidget *pParent) : QWidget(pParent) , ui(new Ui::WModifyTab) + , mIsPicking(false) { ui->setupUi(this); @@ -25,20 +27,28 @@ WModifyTab::WModifyTab(QWidget *pParent) mpOutLinkModel = new CLinkModel(this); mpOutLinkModel->SetConnectionType(eOutgoing); + mpAddFromViewportAction = new QAction("Choose from viewport", this); + mpAddFromListAction = new QAction("Choose from list", this); + mpAddLinkMenu = new QMenu(this); + mpAddLinkMenu->addAction(mpAddFromViewportAction); + mpAddLinkMenu->addAction(mpAddFromListAction); + ui->AddOutgoingConnectionToolButton->setMenu(mpAddLinkMenu); + ui->AddIncomingConnectionToolButton->setMenu(mpAddLinkMenu); + ui->InLinksTableView->setModel(mpInLinkModel); ui->OutLinksTableView->setModel(mpOutLinkModel); ui->InLinksTableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); ui->OutLinksTableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); connect(ui->InLinksTableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(OnLinkTableDoubleClick(QModelIndex))); connect(ui->OutLinksTableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(OnLinkTableDoubleClick(QModelIndex))); - connect(ui->InLinksTableView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(OnIncomingLinksSelectionModified())); - connect(ui->OutLinksTableView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(OnOutgoingLinksSelectionModified())); - connect(ui->AddOutgoingConnectionButton, SIGNAL(clicked()), this, SLOT(OnAddOutgoingLinkClicked())); - connect(ui->AddIncomingConnectionButton, SIGNAL(clicked()), this, SLOT(OnAddIncomingLinkClicked())); - connect(ui->DeleteOutgoingConnectionButton, SIGNAL(clicked()), this, SLOT(OnDeleteOutgoingLinkClicked())); - connect(ui->DeleteIncomingConnectionButton, SIGNAL(clicked()), this, SLOT(OnDeleteIncomingLinkClicked())); - connect(ui->EditOutgoingConnectionButton, SIGNAL(clicked()), this, SLOT(OnEditOutgoingLinkClicked())); - connect(ui->EditIncomingConnectionButton, SIGNAL(clicked()), this, SLOT(OnEditIncomingLinkClicked())); + connect(ui->InLinksTableView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(OnLinksSelectionModified())); + connect(ui->OutLinksTableView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(OnLinksSelectionModified())); + connect(ui->AddOutgoingConnectionToolButton, SIGNAL(triggered(QAction*)), this, SLOT(OnAddLinkActionClicked(QAction*))); + connect(ui->AddIncomingConnectionToolButton, SIGNAL(triggered(QAction*)), this, SLOT(OnAddLinkActionClicked(QAction*))); + connect(ui->DeleteOutgoingConnectionButton, SIGNAL(clicked()), this, SLOT(OnDeleteLinksClicked())); + connect(ui->DeleteIncomingConnectionButton, SIGNAL(clicked()), this, SLOT(OnDeleteLinksClicked())); + connect(ui->EditOutgoingConnectionButton, SIGNAL(clicked()), this, SLOT(OnEditLinkClicked())); + connect(ui->EditIncomingConnectionButton, SIGNAL(clicked()), this, SLOT(OnEditLinkClicked())); ClearUI(); } @@ -58,6 +68,9 @@ void WModifyTab::SetEditor(CWorldEditor *pEditor) void WModifyTab::GenerateUI(QList& Selection) { + if (mIsPicking) + mpWorldEditor->ExitPickMode(); + if (Selection.size() == 1) { if (mpSelectedNode != Selection.front()) @@ -117,45 +130,87 @@ void WModifyTab::OnWorldSelectionTransformed() ui->PropertyView->UpdateEditorProperties(QModelIndex()); } -void WModifyTab::OnOutgoingLinksSelectionModified() +void WModifyTab::OnLinksSelectionModified() { - u32 NumSelectedRows = ui->OutLinksTableView->selectionModel()->selectedRows().size(); - ui->EditOutgoingConnectionButton->setEnabled(NumSelectedRows == 1); + if (sender() == ui->InLinksTableView->selectionModel()) + { + u32 NumSelectedRows = ui->InLinksTableView->selectionModel()->selectedRows().size(); + ui->EditIncomingConnectionButton->setEnabled(NumSelectedRows == 1); + } + else + { + u32 NumSelectedRows = ui->OutLinksTableView->selectionModel()->selectedRows().size(); + ui->EditOutgoingConnectionButton->setEnabled(NumSelectedRows == 1); + } } -void WModifyTab::OnIncomingLinksSelectionModified() -{ - u32 NumSelectedRows = ui->InLinksTableView->selectionModel()->selectedRows().size(); - ui->EditIncomingConnectionButton->setEnabled(NumSelectedRows == 1); -} - -void WModifyTab::OnAddOutgoingLinkClicked() +void WModifyTab::OnAddLinkActionClicked(QAction *pAction) { if (mpSelectedNode && mpSelectedNode->NodeType() == eScriptNode) { - CScriptObject *pInst = static_cast(mpSelectedNode)->Object(); + mAddLinkType = (sender() == ui->AddOutgoingConnectionToolButton ? eOutgoing : eIncoming); + + if (pAction == mpAddFromViewportAction) + { + mpWorldEditor->EnterPickMode(eScriptNode, true, false, false); + connect(mpWorldEditor, SIGNAL(PickModeClick(SRayIntersection,QMouseEvent*)), this, SLOT(OnPickModeClick(SRayIntersection))); + connect(mpWorldEditor, SIGNAL(PickModeExited()), this, SLOT(OnPickModeExit())); + mIsPicking = true; + } + + else if (pAction == mpAddFromListAction) + { + if (mIsPicking) + mpWorldEditor->ExitPickMode(); + + CSelectInstanceDialog Dialog(mpWorldEditor, this); + Dialog.exec(); + CScriptObject *pTarget = Dialog.SelectedInstance(); + + if (pTarget) + { + CLinkDialog *pLinkDialog = mpWorldEditor->LinkDialog(); + CScriptObject *pSelected = static_cast(mpSelectedNode)->Object(); + + CScriptObject *pSender = (mAddLinkType == eOutgoing ? pSelected : pTarget); + CScriptObject *pReceiver = (mAddLinkType == eOutgoing ? pTarget : pSelected); + pLinkDialog->NewLink(pSender, pReceiver); + pLinkDialog->show(); + } + } + } +} + +void WModifyTab::OnPickModeClick(const SRayIntersection& rkIntersect) +{ + mpWorldEditor->ExitPickMode(); + CScriptObject *pTarget = static_cast(rkIntersect.pNode)->Object(); + + if (pTarget) + { CLinkDialog *pDialog = mpWorldEditor->LinkDialog(); - pDialog->NewLink(pInst, nullptr); + CScriptObject *pSelected = static_cast(mpSelectedNode)->Object(); + + CScriptObject *pSender = (mAddLinkType == eOutgoing ? pSelected : pTarget); + CScriptObject *pReceiver = (mAddLinkType == eOutgoing ? pTarget : pSelected); + pDialog->NewLink(pSender, pReceiver); pDialog->show(); } } -void WModifyTab::OnAddIncomingLinkClicked() +void WModifyTab::OnPickModeExit() { - if (mpSelectedNode && mpSelectedNode->NodeType() == eScriptNode) - { - CScriptObject *pInst = static_cast(mpSelectedNode)->Object(); - CLinkDialog *pDialog = mpWorldEditor->LinkDialog(); - pDialog->NewLink(nullptr, pInst); - pDialog->show(); - } + disconnect(mpWorldEditor, SIGNAL(PickModeClick(SRayIntersection,QMouseEvent*)), this, 0); + disconnect(mpWorldEditor, SIGNAL(PickModeExited()), this, 0); + mIsPicking = false; } -void WModifyTab::OnDeleteOutgoingLinkClicked() +void WModifyTab::OnDeleteLinksClicked() { if (mpSelectedNode && mpSelectedNode->NodeType() == eScriptNode) { - QModelIndexList SelectedIndices = ui->OutLinksTableView->selectionModel()->selectedRows(); + ELinkType Type = (sender() == ui->DeleteOutgoingConnectionButton ? eOutgoing : eIncoming); + QModelIndexList SelectedIndices = (Type == eOutgoing ? ui->OutLinksTableView->selectionModel()->selectedRows() : ui->InLinksTableView->selectionModel()->selectedRows()); if (!SelectedIndices.isEmpty()) { @@ -165,59 +220,24 @@ void WModifyTab::OnDeleteOutgoingLinkClicked() Indices << SelectedIndices[iIdx].row(); CScriptObject *pInst = static_cast(mpSelectedNode)->Object(); - CDeleteLinksCommand *pCmd = new CDeleteLinksCommand(mpWorldEditor, pInst, eOutgoing, Indices); + CDeleteLinksCommand *pCmd = new CDeleteLinksCommand(mpWorldEditor, pInst, Type, Indices); mpWorldEditor->UndoStack()->push(pCmd); } } } -void WModifyTab::OnDeleteIncomingLinkClicked() +void WModifyTab::OnEditLinkClicked() { if (mpSelectedNode && mpSelectedNode->NodeType() == eScriptNode) { - QModelIndexList SelectedIndices = ui->InLinksTableView->selectionModel()->selectedRows(); - - if (!SelectedIndices.isEmpty()) - { - QVector Indices; - - for (int iIdx = 0; iIdx < SelectedIndices.size(); iIdx++) - Indices << SelectedIndices[iIdx].row(); - - CScriptObject *pInst = static_cast(mpSelectedNode)->Object(); - CDeleteLinksCommand *pCmd = new CDeleteLinksCommand(mpWorldEditor, pInst, eIncoming, Indices); - mpWorldEditor->UndoStack()->push(pCmd); - } - } -} - -void WModifyTab::OnEditOutgoingLinkClicked() -{ - if (mpSelectedNode && mpSelectedNode->NodeType() == eScriptNode) - { - QModelIndexList SelectedIndices = ui->OutLinksTableView->selectionModel()->selectedRows(); + ELinkType Type = (sender() == ui->EditOutgoingConnectionButton ? eOutgoing : eIncoming); + QModelIndexList SelectedIndices = (Type == eOutgoing ? ui->OutLinksTableView->selectionModel()->selectedRows() : ui->InLinksTableView->selectionModel()->selectedRows()); if (SelectedIndices.size() == 1) { CScriptObject *pInst = static_cast(mpSelectedNode)->Object(); CLinkDialog *pDialog = mpWorldEditor->LinkDialog(); - pDialog->EditLink(pInst->Link(eOutgoing, SelectedIndices.front().row())); - pDialog->show(); - } - } -} - -void WModifyTab::OnEditIncomingLinkClicked() -{ - if (mpSelectedNode && mpSelectedNode->NodeType() == eScriptNode) - { - QModelIndexList SelectedIndices = ui->InLinksTableView->selectionModel()->selectedRows(); - - if (SelectedIndices.size() == 1) - { - CScriptObject *pInst = static_cast(mpSelectedNode)->Object(); - CLinkDialog *pDialog = mpWorldEditor->LinkDialog(); - pDialog->EditLink(pInst->Link(eIncoming, SelectedIndices.front().row())); + pDialog->EditLink(pInst->Link(Type, SelectedIndices.front().row())); pDialog->show(); } } @@ -240,10 +260,7 @@ void WModifyTab::OnLinkTableDoubleClick(QModelIndex Index) CScriptNode *pLinkedNode = pNode->Scene()->ScriptNodeByID(InstanceID); if (pLinkedNode) - { - mpWorldEditor->ClearSelection(); - mpWorldEditor->SelectNode(pLinkedNode); - } + mpWorldEditor->ClearAndSelectNode(pLinkedNode); ui->InLinksTableView->clearSelection(); ui->OutLinksTableView->clearSelection(); diff --git a/src/Editor/WorldEditor/WModifyTab.h b/src/Editor/WorldEditor/WModifyTab.h index dc0480f8..d60ee8fd 100644 --- a/src/Editor/WorldEditor/WModifyTab.h +++ b/src/Editor/WorldEditor/WModifyTab.h @@ -6,11 +6,9 @@ #include #include +#include +#include #include -#include -#include -#include -#include class CWorldEditor; @@ -28,6 +26,12 @@ class WModifyTab : public QWidget CLinkModel *mpInLinkModel; CLinkModel *mpOutLinkModel; + QMenu *mpAddLinkMenu; + QAction *mpAddFromViewportAction; + QAction *mpAddFromListAction; + ELinkType mAddLinkType; + bool mIsPicking; + public: explicit WModifyTab(QWidget *pParent = 0); ~WModifyTab(); @@ -39,14 +43,13 @@ public slots: void OnInstanceLinksModified(const QList& rkInstances); void OnWorldSelectionTransformed(); - void OnOutgoingLinksSelectionModified(); - void OnIncomingLinksSelectionModified(); - void OnAddOutgoingLinkClicked(); - void OnAddIncomingLinkClicked(); - void OnDeleteOutgoingLinkClicked(); - void OnDeleteIncomingLinkClicked(); - void OnEditOutgoingLinkClicked(); - void OnEditIncomingLinkClicked(); + void OnLinksSelectionModified(); + void OnAddLinkActionClicked(QAction *pAction); + void OnPickModeClick(const SRayIntersection& rkIntersect); + void OnPickModeExit(); + void OnDeleteLinksClicked(); + void OnEditLinkClicked(); + private: Ui::WModifyTab *ui; diff --git a/src/Editor/WorldEditor/WModifyTab.ui b/src/Editor/WorldEditor/WModifyTab.ui index 6884c37e..07adde18 100644 --- a/src/Editor/WorldEditor/WModifyTab.ui +++ b/src/Editor/WorldEditor/WModifyTab.ui @@ -155,7 +155,16 @@ - + + + + 0 + 0 + + + + Qt::StrongFocus + @@ -163,16 +172,11 @@ :/icons/Plus.png:/icons/Plus.png - - - - - - + + QToolButton::InstantPopup - - - :/icons/Minus v2.png:/icons/Minus v2.png + + Qt::NoArrow @@ -211,6 +215,17 @@ + + + + + + + + :/icons/Minus v2.png:/icons/Minus v2.png + + + @@ -253,7 +268,16 @@ - + + + + 0 + 0 + + + + Qt::StrongFocus + @@ -261,16 +285,8 @@ :/icons/Plus.png:/icons/Plus.png - - - - - - - - - - :/icons/Minus v2.png:/icons/Minus v2.png + + QToolButton::InstantPopup @@ -303,6 +319,17 @@ + + + + + + + + :/icons/Minus v2.png:/icons/Minus v2.png + + +