Added viewport context menus
This commit is contained in:
parent
aa5453b84a
commit
ee5d5fae0a
|
@ -3,6 +3,8 @@
|
|||
#include <Core/Render/CDrawUtil.h>
|
||||
#include <Core/Render/CGraphics.h>
|
||||
|
||||
#include <QCursor>
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
CBasicViewport::CBasicViewport(QWidget *pParent) :
|
||||
|
@ -110,6 +112,13 @@ void CBasicViewport::mouseReleaseEvent(QMouseEvent *pEvent)
|
|||
// Run mouse release if we didn't just exit mouse input (or regardless on left click)
|
||||
if (!fromMouseInput || (pEvent->button() == Qt::LeftButton))
|
||||
OnMouseRelease(pEvent);
|
||||
|
||||
// Send context menu event to subclass if needed
|
||||
if ((pEvent->button() == Qt::RightButton) && (mMoveTimer.Time() <= 0.3) && !mMouseMoved)
|
||||
{
|
||||
QContextMenuEvent Event(QContextMenuEvent::Mouse, QCursor::pos());
|
||||
this->ContextMenu(&Event);
|
||||
}
|
||||
}
|
||||
|
||||
void CBasicViewport::mouseMoveEvent(QMouseEvent* /*pEvent*/)
|
||||
|
@ -161,9 +170,7 @@ void CBasicViewport::focusOutEvent(QFocusEvent*)
|
|||
|
||||
void CBasicViewport::contextMenuEvent(QContextMenuEvent *pEvent)
|
||||
{
|
||||
// Only allow context menu if we aren't exiting mouse input mode.
|
||||
if (!mMouseMoved && (mMoveTimer.Time() < 0.5))
|
||||
ContextMenu(pEvent);
|
||||
pEvent->ignore();
|
||||
}
|
||||
|
||||
void CBasicViewport::SetGameMode(bool Enabled)
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#include "CSceneViewport.h"
|
||||
#include "UICommon.h"
|
||||
#include "Editor/Undo/UndoCommands.h"
|
||||
#include <Core/Render/SViewInfo.h>
|
||||
#include <Core/Resource/Script/CScriptLayer.h>
|
||||
#include <QMenu>
|
||||
|
||||
CSceneViewport::CSceneViewport(QWidget *pParent)
|
||||
: CBasicViewport(pParent),
|
||||
|
@ -9,7 +12,9 @@ CSceneViewport::CSceneViewport(QWidget *pParent)
|
|||
mDrawSky(true),
|
||||
mGizmoTransforming(false),
|
||||
mpHoverNode(nullptr),
|
||||
mHoverPoint(CVector3f::skZero)
|
||||
mHoverPoint(CVector3f::skZero),
|
||||
mpContextMenu(nullptr),
|
||||
mpMenuNode(nullptr)
|
||||
{
|
||||
mpRenderer = new CRenderer();
|
||||
mpRenderer->SetClearColor(CColor::skBlack);
|
||||
|
@ -17,6 +22,8 @@ CSceneViewport::CSceneViewport(QWidget *pParent)
|
|||
|
||||
mViewInfo.pScene = mpScene;
|
||||
mViewInfo.pRenderer = mpRenderer;
|
||||
|
||||
CreateContextMenu();
|
||||
}
|
||||
|
||||
CSceneViewport::~CSceneViewport()
|
||||
|
@ -130,6 +137,31 @@ void CSceneViewport::keyReleaseEvent(QKeyEvent* pEvent)
|
|||
}
|
||||
}
|
||||
|
||||
// ************ PROTECTED ************
|
||||
void CSceneViewport::CreateContextMenu()
|
||||
{
|
||||
mpContextMenu = new QMenu(this);
|
||||
|
||||
mpHideNodeAction = new QAction("HideNode", this);
|
||||
connect(mpHideNodeAction, SIGNAL(triggered()), this, SLOT(OnHideNode()));
|
||||
|
||||
mpHideTypeAction = new QAction("HideType", this);
|
||||
connect(mpHideTypeAction, SIGNAL(triggered()), this, SLOT(OnHideType()));
|
||||
|
||||
mpHideLayerAction = new QAction("HideLayer", this);
|
||||
connect(mpHideLayerAction, SIGNAL(triggered()), this, SLOT(OnHideLayer()));
|
||||
|
||||
mpHideUnhideSeparator = new QAction(this);
|
||||
mpHideUnhideSeparator->setSeparator(true);
|
||||
|
||||
mpUnhideAllAction = new QAction("Unhide all", this);
|
||||
connect(mpUnhideAllAction, SIGNAL(triggered()), this, SLOT(OnUnhideAll()));
|
||||
|
||||
QList<QAction*> Actions;
|
||||
Actions << mpHideNodeAction << mpHideTypeAction << mpHideLayerAction << mpHideUnhideSeparator << mpUnhideAllAction;
|
||||
mpContextMenu->addActions(Actions);
|
||||
}
|
||||
|
||||
// ************ PROTECTED SLOTS ************
|
||||
void CSceneViewport::CheckUserInput()
|
||||
{
|
||||
|
@ -184,8 +216,36 @@ void CSceneViewport::Paint()
|
|||
mpRenderer->EndFrame();
|
||||
}
|
||||
|
||||
void CSceneViewport::ContextMenu(QContextMenuEvent* /*pEvent*/)
|
||||
void CSceneViewport::ContextMenu(QContextMenuEvent* pEvent)
|
||||
{
|
||||
// mpHoverNode is cleared during mouse input, so this call is necessary. todo: better way?
|
||||
SceneRayCast(CastRay());
|
||||
|
||||
// Set up actions
|
||||
TString NodeName;
|
||||
bool HasHoverNode = (mpHoverNode && mpHoverNode->NodeType() != eStaticNode);
|
||||
bool IsScriptNode = (mpHoverNode && mpHoverNode->NodeType() == eScriptNode);
|
||||
|
||||
mpHideNodeAction->setVisible(HasHoverNode);
|
||||
mpHideTypeAction->setVisible(IsScriptNode);
|
||||
mpHideLayerAction->setVisible(IsScriptNode);
|
||||
mpHideUnhideSeparator->setVisible(HasHoverNode);
|
||||
|
||||
if (IsScriptNode)
|
||||
{
|
||||
CScriptNode *pScript = static_cast<CScriptNode*>(mpHoverNode);
|
||||
NodeName = pScript->Object()->InstanceName();
|
||||
mpHideTypeAction->setText( QString("Hide all %1 objects").arg(TO_QSTRING(pScript->Template()->TemplateName())) );
|
||||
mpHideLayerAction->setText( QString("Hide layer %1").arg(TO_QSTRING(pScript->Object()->Layer()->Name())) );
|
||||
}
|
||||
else if (HasHoverNode)
|
||||
NodeName = mpHoverNode->Name();
|
||||
|
||||
mpHideNodeAction->setText(QString("Hide %1").arg(TO_QSTRING(NodeName)));
|
||||
|
||||
// Show menu
|
||||
mpMenuNode = mpHoverNode;
|
||||
mpContextMenu->exec(pEvent->pos());
|
||||
}
|
||||
|
||||
void CSceneViewport::OnResize()
|
||||
|
@ -257,5 +317,30 @@ void CSceneViewport::OnMouseRelease(QMouseEvent *pEvent)
|
|||
mpEditor->UpdateSelectionUI();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CSceneViewport::OnHideNode()
|
||||
{
|
||||
mpMenuNode->SetVisible(false);
|
||||
}
|
||||
|
||||
void CSceneViewport::OnHideType()
|
||||
{
|
||||
static_cast<CScriptNode*>(mpMenuNode)->Template()->SetVisible(false);
|
||||
}
|
||||
|
||||
void CSceneViewport::OnHideLayer()
|
||||
{
|
||||
static_cast<CScriptNode*>(mpMenuNode)->Object()->Layer()->SetVisible(false);
|
||||
}
|
||||
|
||||
void CSceneViewport::OnUnhideAll()
|
||||
{
|
||||
// implement when scene iterator exists!
|
||||
}
|
||||
|
||||
void CSceneViewport::OnContextMenuClose()
|
||||
{
|
||||
mpContextMenu = nullptr;
|
||||
mpMenuNode = nullptr;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,15 @@ class CSceneViewport : public CBasicViewport
|
|||
CSceneNode *mpHoverNode;
|
||||
CVector3f mHoverPoint;
|
||||
|
||||
// Context Menu
|
||||
QMenu *mpContextMenu;
|
||||
QAction *mpHideNodeAction;
|
||||
QAction *mpHideTypeAction;
|
||||
QAction *mpHideLayerAction;
|
||||
QAction *mpHideUnhideSeparator;
|
||||
QAction *mpUnhideAllAction;
|
||||
CSceneNode *mpMenuNode;
|
||||
|
||||
public:
|
||||
CSceneViewport(QWidget *pParent = 0);
|
||||
~CSceneViewport();
|
||||
|
@ -37,6 +46,9 @@ public:
|
|||
void keyPressEvent(QKeyEvent* pEvent);
|
||||
void keyReleaseEvent(QKeyEvent* pEvent);
|
||||
|
||||
protected:
|
||||
void CreateContextMenu();
|
||||
|
||||
signals:
|
||||
void GizmoMoved();
|
||||
void CameraOrbit();
|
||||
|
@ -48,6 +60,12 @@ protected slots:
|
|||
void OnResize();
|
||||
void OnMouseClick(QMouseEvent *pEvent);
|
||||
void OnMouseRelease(QMouseEvent *pEvent);
|
||||
|
||||
void OnHideNode();
|
||||
void OnHideType();
|
||||
void OnHideLayer();
|
||||
void OnUnhideAll();
|
||||
void OnContextMenuClose();
|
||||
};
|
||||
|
||||
#endif // CSCENEVIEWPORT_H
|
||||
|
|
|
@ -330,6 +330,18 @@
|
|||
</attribute>
|
||||
<widget class="QWidget" name="MainDockContents">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="TabWidget">
|
||||
<property name="focusPolicy">
|
||||
|
@ -342,7 +354,7 @@
|
|||
<enum>QTabWidget::Rounded</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
|
|
|
@ -17,21 +17,42 @@
|
|||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="TabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="ShowLayersTab">
|
||||
<attribute name="title">
|
||||
<string>Layer</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTreeView" name="LayersTreeView">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="verticalScrollMode">
|
||||
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||
</property>
|
||||
|
@ -47,11 +68,26 @@
|
|||
<string>Type</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTreeView" name="TypesTreeView">
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>9</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>9</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="ObjectsTabWidget">
|
||||
|
@ -65,7 +65,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>276</width>
|
||||
<height>439</height>
|
||||
<height>457</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -137,7 +137,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>276</width>
|
||||
<height>439</height>
|
||||
<height>457</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
|
|
Loading…
Reference in New Issue