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/CDrawUtil.h>
|
||||||
#include <Core/Render/CGraphics.h>
|
#include <Core/Render/CGraphics.h>
|
||||||
|
|
||||||
|
#include <QCursor>
|
||||||
|
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
CBasicViewport::CBasicViewport(QWidget *pParent) :
|
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)
|
// Run mouse release if we didn't just exit mouse input (or regardless on left click)
|
||||||
if (!fromMouseInput || (pEvent->button() == Qt::LeftButton))
|
if (!fromMouseInput || (pEvent->button() == Qt::LeftButton))
|
||||||
OnMouseRelease(pEvent);
|
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*/)
|
void CBasicViewport::mouseMoveEvent(QMouseEvent* /*pEvent*/)
|
||||||
|
@ -161,9 +170,7 @@ void CBasicViewport::focusOutEvent(QFocusEvent*)
|
||||||
|
|
||||||
void CBasicViewport::contextMenuEvent(QContextMenuEvent *pEvent)
|
void CBasicViewport::contextMenuEvent(QContextMenuEvent *pEvent)
|
||||||
{
|
{
|
||||||
// Only allow context menu if we aren't exiting mouse input mode.
|
pEvent->ignore();
|
||||||
if (!mMouseMoved && (mMoveTimer.Time() < 0.5))
|
|
||||||
ContextMenu(pEvent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBasicViewport::SetGameMode(bool Enabled)
|
void CBasicViewport::SetGameMode(bool Enabled)
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
#include "CSceneViewport.h"
|
#include "CSceneViewport.h"
|
||||||
|
#include "UICommon.h"
|
||||||
#include "Editor/Undo/UndoCommands.h"
|
#include "Editor/Undo/UndoCommands.h"
|
||||||
#include <Core/Render/SViewInfo.h>
|
#include <Core/Render/SViewInfo.h>
|
||||||
|
#include <Core/Resource/Script/CScriptLayer.h>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
CSceneViewport::CSceneViewport(QWidget *pParent)
|
CSceneViewport::CSceneViewport(QWidget *pParent)
|
||||||
: CBasicViewport(pParent),
|
: CBasicViewport(pParent),
|
||||||
|
@ -9,7 +12,9 @@ CSceneViewport::CSceneViewport(QWidget *pParent)
|
||||||
mDrawSky(true),
|
mDrawSky(true),
|
||||||
mGizmoTransforming(false),
|
mGizmoTransforming(false),
|
||||||
mpHoverNode(nullptr),
|
mpHoverNode(nullptr),
|
||||||
mHoverPoint(CVector3f::skZero)
|
mHoverPoint(CVector3f::skZero),
|
||||||
|
mpContextMenu(nullptr),
|
||||||
|
mpMenuNode(nullptr)
|
||||||
{
|
{
|
||||||
mpRenderer = new CRenderer();
|
mpRenderer = new CRenderer();
|
||||||
mpRenderer->SetClearColor(CColor::skBlack);
|
mpRenderer->SetClearColor(CColor::skBlack);
|
||||||
|
@ -17,6 +22,8 @@ CSceneViewport::CSceneViewport(QWidget *pParent)
|
||||||
|
|
||||||
mViewInfo.pScene = mpScene;
|
mViewInfo.pScene = mpScene;
|
||||||
mViewInfo.pRenderer = mpRenderer;
|
mViewInfo.pRenderer = mpRenderer;
|
||||||
|
|
||||||
|
CreateContextMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
CSceneViewport::~CSceneViewport()
|
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 ************
|
// ************ PROTECTED SLOTS ************
|
||||||
void CSceneViewport::CheckUserInput()
|
void CSceneViewport::CheckUserInput()
|
||||||
{
|
{
|
||||||
|
@ -184,8 +216,36 @@ void CSceneViewport::Paint()
|
||||||
mpRenderer->EndFrame();
|
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()
|
void CSceneViewport::OnResize()
|
||||||
|
@ -257,5 +317,30 @@ void CSceneViewport::OnMouseRelease(QMouseEvent *pEvent)
|
||||||
mpEditor->UpdateSelectionUI();
|
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;
|
CSceneNode *mpHoverNode;
|
||||||
CVector3f mHoverPoint;
|
CVector3f mHoverPoint;
|
||||||
|
|
||||||
|
// Context Menu
|
||||||
|
QMenu *mpContextMenu;
|
||||||
|
QAction *mpHideNodeAction;
|
||||||
|
QAction *mpHideTypeAction;
|
||||||
|
QAction *mpHideLayerAction;
|
||||||
|
QAction *mpHideUnhideSeparator;
|
||||||
|
QAction *mpUnhideAllAction;
|
||||||
|
CSceneNode *mpMenuNode;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CSceneViewport(QWidget *pParent = 0);
|
CSceneViewport(QWidget *pParent = 0);
|
||||||
~CSceneViewport();
|
~CSceneViewport();
|
||||||
|
@ -37,6 +46,9 @@ public:
|
||||||
void keyPressEvent(QKeyEvent* pEvent);
|
void keyPressEvent(QKeyEvent* pEvent);
|
||||||
void keyReleaseEvent(QKeyEvent* pEvent);
|
void keyReleaseEvent(QKeyEvent* pEvent);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void CreateContextMenu();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void GizmoMoved();
|
void GizmoMoved();
|
||||||
void CameraOrbit();
|
void CameraOrbit();
|
||||||
|
@ -48,6 +60,12 @@ protected slots:
|
||||||
void OnResize();
|
void OnResize();
|
||||||
void OnMouseClick(QMouseEvent *pEvent);
|
void OnMouseClick(QMouseEvent *pEvent);
|
||||||
void OnMouseRelease(QMouseEvent *pEvent);
|
void OnMouseRelease(QMouseEvent *pEvent);
|
||||||
|
|
||||||
|
void OnHideNode();
|
||||||
|
void OnHideType();
|
||||||
|
void OnHideLayer();
|
||||||
|
void OnUnhideAll();
|
||||||
|
void OnContextMenuClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CSCENEVIEWPORT_H
|
#endif // CSCENEVIEWPORT_H
|
||||||
|
|
|
@ -330,6 +330,18 @@
|
||||||
</attribute>
|
</attribute>
|
||||||
<widget class="QWidget" name="MainDockContents">
|
<widget class="QWidget" name="MainDockContents">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<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>
|
<item>
|
||||||
<widget class="QTabWidget" name="TabWidget">
|
<widget class="QTabWidget" name="TabWidget">
|
||||||
<property name="focusPolicy">
|
<property name="focusPolicy">
|
||||||
|
@ -342,7 +354,7 @@
|
||||||
<enum>QTabWidget::Rounded</enum>
|
<enum>QTabWidget::Rounded</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>1</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
<size>
|
<size>
|
||||||
|
|
|
@ -17,21 +17,42 @@
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
<property name="rightMargin">
|
<property name="rightMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTabWidget" name="TabWidget">
|
<widget class="QTabWidget" name="TabWidget">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="ShowLayersTab">
|
<widget class="QWidget" name="ShowLayersTab">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Layer</string>
|
<string>Layer</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<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>
|
<item>
|
||||||
<widget class="QTreeView" name="LayersTreeView">
|
<widget class="QTreeView" name="LayersTreeView">
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::NoFrame</enum>
|
||||||
|
</property>
|
||||||
<property name="verticalScrollMode">
|
<property name="verticalScrollMode">
|
||||||
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||||
</property>
|
</property>
|
||||||
|
@ -47,11 +68,26 @@
|
||||||
<string>Type</string>
|
<string>Type</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<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>
|
<item>
|
||||||
<widget class="QTreeView" name="TypesTreeView">
|
<widget class="QTreeView" name="TypesTreeView">
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true"/>
|
<string notr="true"/>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::NoFrame</enum>
|
||||||
|
</property>
|
||||||
<property name="alternatingRowColors">
|
<property name="alternatingRowColors">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
@ -18,13 +18,13 @@
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="topMargin">
|
<property name="topMargin">
|
||||||
<number>9</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="rightMargin">
|
<property name="rightMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>9</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTabWidget" name="ObjectsTabWidget">
|
<widget class="QTabWidget" name="ObjectsTabWidget">
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>276</width>
|
<width>276</width>
|
||||||
<height>439</height>
|
<height>457</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -137,7 +137,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>276</width>
|
<width>276</width>
|
||||||
<height>439</height>
|
<height>457</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
|
Loading…
Reference in New Issue