Widget merge.

This commit is contained in:
Leonardo Zide 2020-12-05 12:17:09 -08:00
parent 8d09f90c54
commit 28ccd8f681
7 changed files with 163 additions and 215 deletions

View file

@ -48,6 +48,59 @@ void lcGLWidget::Redraw()
mWidget->update();
}
lcCursor lcGLWidget::GetCursor() const
{
if (mTrackTool == lcTrackTool::Select)
{
if (mMouseModifiers & Qt::ControlModifier)
return lcCursor::SelectAdd;
if (mMouseModifiers & Qt::ShiftModifier)
return lcCursor::SelectRemove;
}
const lcCursor CursorFromTrackTool[static_cast<int>(lcTrackTool::Count)] =
{
lcCursor::Select, // lcTrackTool::None
lcCursor::Brick, // lcTrackTool::Insert
lcCursor::Light, // lcTrackTool::PointLight
lcCursor::Spotlight, // lcTrackTool::SpotLight
lcCursor::Camera, // lcTrackTool::Camera
lcCursor::Select, // lcTrackTool::Select
lcCursor::Move, // lcTrackTool::MoveX
lcCursor::Move, // lcTrackTool::MoveY
lcCursor::Move, // lcTrackTool::MoveZ
lcCursor::Move, // lcTrackTool::MoveXY
lcCursor::Move, // lcTrackTool::MoveXZ
lcCursor::Move, // lcTrackTool::MoveYZ
lcCursor::Move, // lcTrackTool::MoveXYZ
lcCursor::Rotate, // lcTrackTool::RotateX
lcCursor::Rotate, // lcTrackTool::RotateY
lcCursor::Rotate, // lcTrackTool::RotateZ
lcCursor::Rotate, // lcTrackTool::RotateXY
lcCursor::Rotate, // lcTrackTool::RotateXYZ
lcCursor::Move, // lcTrackTool::ScalePlus
lcCursor::Move, // lcTrackTool::ScaleMinus
lcCursor::Delete, // lcTrackTool::Eraser
lcCursor::Paint, // lcTrackTool::Paint
lcCursor::ColorPicker, // lcTrackTool::ColorPicker
lcCursor::Zoom, // lcTrackTool::Zoom
lcCursor::Pan, // lcTrackTool::Pan
lcCursor::RotateX, // lcTrackTool::OrbitX
lcCursor::RotateY, // lcTrackTool::OrbitY
lcCursor::RotateView, // lcTrackTool::OrbitXY
lcCursor::Roll, // lcTrackTool::Roll
lcCursor::ZoomRegion // lcTrackTool::ZoomRegion
};
static_assert(LC_ARRAY_COUNT(CursorFromTrackTool) == static_cast<int>(lcTrackTool::Count), "Array size mismatch.");
if (mTrackTool >= lcTrackTool::None && mTrackTool < lcTrackTool::Count)
return CursorFromTrackTool[static_cast<int>(mTrackTool)];
return lcCursor::Select;
}
void lcGLWidget::SetCursor(lcCursor CursorType)
{
if (mCursor == CursorType)
@ -98,6 +151,55 @@ void lcGLWidget::SetCursor(lcCursor CursorType)
}
}
void lcGLWidget::UpdateCursor()
{
SetCursor(GetCursor());
}
lcTool lcGLWidget::GetCurrentTool() const
{
const lcTool ToolFromTrackTool[static_cast<int>(lcTrackTool::Count)] =
{
lcTool::Select, // lcTrackTool::None
lcTool::Insert, // lcTrackTool::Insert
lcTool::Light, // lcTrackTool::PointLight
lcTool::SpotLight, // lcTrackTool::SpotLight
lcTool::Camera, // lcTrackTool::Camera
lcTool::Select, // lcTrackTool::Select
lcTool::Move, // lcTrackTool::MoveX
lcTool::Move, // lcTrackTool::MoveY
lcTool::Move, // lcTrackTool::MoveZ
lcTool::Move, // lcTrackTool::MoveXY
lcTool::Move, // lcTrackTool::MoveXZ
lcTool::Move, // lcTrackTool::MoveYZ
lcTool::Move, // lcTrackTool::MoveXYZ
lcTool::Rotate, // lcTrackTool::RotateX
lcTool::Rotate, // lcTrackTool::RotateY
lcTool::Rotate, // lcTrackTool::RotateZ
lcTool::Rotate, // lcTrackTool::RotateXY
lcTool::Rotate, // lcTrackTool::RotateXYZ
lcTool::Move, // lcTrackTool::ScalePlus
lcTool::Move, // lcTrackTool::ScaleMinus
lcTool::Eraser, // lcTrackTool::Eraser
lcTool::Paint, // lcTrackTool::Paint
lcTool::ColorPicker, // lcTrackTool::ColorPicker
lcTool::Zoom, // lcTrackTool::Zoom
lcTool::Pan, // lcTrackTool::Pan
lcTool::RotateView, // lcTrackTool::OrbitX
lcTool::RotateView, // lcTrackTool::OrbitY
lcTool::RotateView, // lcTrackTool::OrbitXY
lcTool::Roll, // lcTrackTool::Roll
lcTool::ZoomRegion // lcTrackTool::ZoomRegion
};
static_assert(LC_ARRAY_COUNT(ToolFromTrackTool) == static_cast<int>(lcTrackTool::Count), "Array size mismatch.");
if (mTrackTool >= lcTrackTool::None && mTrackTool < lcTrackTool::Count)
return ToolFromTrackTool[static_cast<int>(mTrackTool)];
return lcTool::Select;
}
lcMatrix44 lcGLWidget::GetProjectionMatrix() const
{
float AspectRatio = (float)mWidth / (float)mHeight;

View file

@ -1,5 +1,7 @@
#pragma once
#include "lc_commands.h"
enum class lcDragState
{
None,
@ -40,6 +42,41 @@ enum class lcTrackButton
Right
};
enum class lcTrackTool
{
None,
Insert,
PointLight,
SpotLight,
Camera,
Select,
MoveX,
MoveY,
MoveZ,
MoveXY,
MoveXZ,
MoveYZ,
MoveXYZ,
RotateX,
RotateY,
RotateZ,
RotateXY,
RotateXYZ,
ScalePlus,
ScaleMinus,
Eraser,
Paint,
ColorPicker,
Zoom,
Pan,
OrbitX,
OrbitY,
OrbitXY,
Roll,
ZoomRegion,
Count
};
class lcGLWidget
{
public:
@ -74,7 +111,7 @@ public:
void SetContext(lcContext* Context);
void MakeCurrent();
void Redraw();
void SetCursor(lcCursor Cursor);
void UpdateCursor();
lcVector3 ProjectPoint(const lcVector3& Point) const;
lcVector3 UnprojectPoint(const lcVector3& Point) const;
@ -86,7 +123,6 @@ public:
virtual void OnDraw() { }
virtual void OnInitialUpdate() { }
virtual void OnUpdateCursor() { }
virtual void OnLeftButtonDown() { }
virtual void OnLeftButtonUp() { }
virtual void OnLeftButtonDoubleClick() { }
@ -109,12 +145,17 @@ public:
lcContext* mContext = nullptr;
protected:
lcCursor GetCursor() const;
void SetCursor(lcCursor Cursor);
lcTool GetCurrentTool() const;
int mMouseX = 0;
int mMouseY = 0;
int mMouseDownX = 0;
int mMouseDownY = 0;
Qt::KeyboardModifiers mMouseModifiers = Qt::NoModifier;
lcTrackTool mTrackTool = lcTrackTool::None;
lcTrackButton mTrackButton = lcTrackButton::None;
lcCursor mCursor = lcCursor::Default;

View file

@ -82,9 +82,6 @@ void lcPreviewDockWidget::SetPreviewLock()
lcPreviewWidget::lcPreviewWidget()
: mLoader(new Project(true)), mViewSphere(this)
{
mTrackTool = lcTrackTool::None;
mTrackButton = lcTrackButton::None;
mLoader->SetActiveModel(0);
mModel = mLoader->GetActiveModel();
@ -225,7 +222,7 @@ void lcPreviewWidget::StartOrbitTracking() // called by viewSphere
{
mTrackTool = lcTrackTool::OrbitXY;
OnUpdateCursor();
UpdateCursor();
OnButtonDown(lcTrackButton::Left);
}
@ -271,24 +268,12 @@ void lcPreviewWidget::DrawViewport()
glEnable(GL_DEPTH_TEST);
}
lcTool lcPreviewWidget::GetCurrentTool() const
{
const lcTool ToolFromTrackTool[] =
{
lcTool::Select, // lcTrackTool::None
lcTool::Pan, // lcTrackTool::Pan
lcTool::RotateView, // lcTrackTool::OrbitXY
};
return ToolFromTrackTool[static_cast<int>(mTrackTool)];
}
void lcPreviewWidget::StartTracking(lcTrackButton TrackButton)
{
mTrackButton = TrackButton;
mMouseDownX = mMouseX;
mMouseDownY = mMouseY;
lcTool Tool = GetCurrentTool(); // Either lcTrackTool::None (LC_TOOL_SELECT) or lcTrackTool::OrbitXY (LC_TOOL_ROTATE_VIEW)
lcTool Tool = GetCurrentTool();
lcModel* ActiveModel = GetActiveModel();
switch (Tool)
@ -306,7 +291,7 @@ void lcPreviewWidget::StartTracking(lcTrackButton TrackButton)
break;
}
OnUpdateCursor();
UpdateCursor();
}
void lcPreviewWidget::StopTracking(bool Accept)
@ -314,7 +299,7 @@ void lcPreviewWidget::StopTracking(bool Accept)
if (mTrackButton == lcTrackButton::None)
return;
lcTool Tool = GetCurrentTool(); // Either lcTrackTool::None (LC_TOOL_SELECT) or lcTrackTool::OrbitXY (LC_TOOL_ROTATE_VIEW)
lcTool Tool = GetCurrentTool();
lcModel* ActiveModel = GetActiveModel();
switch (Tool)
@ -336,7 +321,7 @@ void lcPreviewWidget::StopTracking(bool Accept)
mTrackTool = lcTrackTool::None;
OnUpdateCursor();
UpdateCursor();
}
void lcPreviewWidget::OnButtonDown(lcTrackButton TrackButton)
@ -359,23 +344,6 @@ void lcPreviewWidget::OnButtonDown(lcTrackButton TrackButton)
}
}
lcCursor lcPreviewWidget::GetCursor() const
{
const lcCursor CursorFromTrackTool[] =
{
lcCursor::Select, // lcTrackTool::None
lcCursor::Pan, // lcTrackTool::Pan
lcCursor::RotateView, // lcTrackTool::OrbitXY
};
static_assert(LC_ARRAY_COUNT(CursorFromTrackTool) == static_cast<int>(lcTrackTool::Count), "Tracktool array size mismatch.");
if (mTrackTool < lcTrackTool::Count)
return CursorFromTrackTool[static_cast<int>(mTrackTool)];
return lcCursor::Select;
}
void lcPreviewWidget::OnDraw()
{
if (!mModel)
@ -422,11 +390,6 @@ void lcPreviewWidget::OnDraw()
mContext->ClearResources();
}
void lcPreviewWidget::OnUpdateCursor()
{
SetCursor(GetCursor());
}
void lcPreviewWidget::OnLeftButtonDown()
{
if (mTrackButton != lcTrackButton::None)
@ -443,7 +406,7 @@ void lcPreviewWidget::OnLeftButtonDown()
if (OverrideTool != lcTrackTool::None)
{
mTrackTool = OverrideTool;
OnUpdateCursor();
UpdateCursor();
}
OnButtonDown(lcTrackButton::Left);
@ -473,7 +436,7 @@ void lcPreviewWidget::OnMiddleButtonDown()
if (OverrideTool != lcTrackTool::None)
{
mTrackTool = OverrideTool;
OnUpdateCursor();
UpdateCursor();
}
#endif
OnButtonDown(lcTrackButton::Middle);
@ -503,7 +466,7 @@ void lcPreviewWidget::OnRightButtonDown()
if (OverrideTool != lcTrackTool::None)
{
mTrackTool = OverrideTool;
OnUpdateCursor();
UpdateCursor();
}
OnButtonDown(lcTrackButton::Middle);
@ -531,7 +494,7 @@ void lcPreviewWidget::OnMouseMove()
if (NewTrackTool != mTrackTool)
{
mTrackTool = NewTrackTool;
OnUpdateCursor();
UpdateCursor();
}
return;

View file

@ -32,14 +32,6 @@ protected:
class lcPreviewWidget : public lcGLWidget
{
public:
enum class lcTrackTool
{
None,
Pan,
OrbitXY,
Count
};
lcPreviewWidget();
~lcPreviewWidget();
@ -52,7 +44,6 @@ public:
void UpdatePreview();
bool SetCurrentPiece(const QString& PartType, int ColorCode);
lcModel* GetActiveModel() const;
lcCursor GetCursor() const;
void SetCamera(lcCamera* Camera);
void SetDefaultCamera();
void ZoomExtents();
@ -67,7 +58,6 @@ public:
}
void OnDraw() override;
void OnUpdateCursor() override;
void OnLeftButtonDown() override;
void OnLeftButtonUp() override;
void OnLeftButtonDoubleClick() override;
@ -81,7 +71,6 @@ public:
protected:
void DrawViewport();
lcTool GetCurrentTool() const;
void StartTracking(lcTrackButton TrackButton);
void StopTracking(bool Accept);
void OnButtonDown(lcTrackButton TrackButton);
@ -90,8 +79,6 @@ protected:
lcModel* mModel;
lcViewSphere mViewSphere;
lcTrackTool mTrackTool;
QString mDescription;
bool mIsModel;
};

View file

@ -18,12 +18,9 @@ View::View(lcModel* Model)
{
mModel = Model;
mActiveSubmodelInstance = nullptr;
mCamera = nullptr;
memset(mGridSettings, 0, sizeof(mGridSettings));
mDragState = lcDragState::None;
mTrackButton = lcTrackButton::None;
mTrackTool = lcTrackTool::None;
mTrackToolFromOverlay = false;
View* ActiveView = gMainWindow->GetActiveView();
@ -429,59 +426,6 @@ lcMatrix44 View::GetTileProjectionMatrix(int CurrentRow, int CurrentColumn, int
return lcMatrix44Frustum(Left, Right, Bottom, Top, Near, Far);
}
lcCursor View::GetCursor() const
{
if (mTrackTool == lcTrackTool::Select)
{
if (mMouseModifiers & Qt::ControlModifier)
return lcCursor::SelectAdd;
if (mMouseModifiers & Qt::ShiftModifier)
return lcCursor::SelectRemove;
}
const lcCursor CursorFromTrackTool[static_cast<int>(lcTrackTool::Count)] =
{
lcCursor::Select, // lcTrackTool::None
lcCursor::Brick, // lcTrackTool::Insert
lcCursor::Light, // lcTrackTool::PointLight
lcCursor::Spotlight, // lcTrackTool::SpotLight
lcCursor::Camera, // lcTrackTool::Camera
lcCursor::Select, // lcTrackTool::Select
lcCursor::Move, // lcTrackTool::MoveX
lcCursor::Move, // lcTrackTool::MoveY
lcCursor::Move, // lcTrackTool::MoveZ
lcCursor::Move, // lcTrackTool::MoveXY
lcCursor::Move, // lcTrackTool::MoveXZ
lcCursor::Move, // lcTrackTool::MoveYZ
lcCursor::Move, // lcTrackTool::MoveXYZ
lcCursor::Rotate, // lcTrackTool::RotateX
lcCursor::Rotate, // lcTrackTool::RotateY
lcCursor::Rotate, // lcTrackTool::RotateZ
lcCursor::Rotate, // lcTrackTool::RotateXY
lcCursor::Rotate, // lcTrackTool::RotateXYZ
lcCursor::Move, // lcTrackTool::ScalePlus
lcCursor::Move, // lcTrackTool::ScaleMinus
lcCursor::Delete, // lcTrackTool::Eraser
lcCursor::Paint, // lcTrackTool::Paint
lcCursor::ColorPicker, // lcTrackTool::ColorPicker
lcCursor::Zoom, // lcTrackTool::Zoom
lcCursor::Pan, // lcTrackTool::Pan
lcCursor::RotateX, // lcTrackTool::OrbitX
lcCursor::RotateY, // lcTrackTool::OrbitY
lcCursor::RotateView, // lcTrackTool::OrbitXY
lcCursor::Roll, // lcTrackTool::Roll
lcCursor::ZoomRegion // lcTrackTool::ZoomRegion
};
static_assert(LC_ARRAY_COUNT(CursorFromTrackTool) == static_cast<int>(lcTrackTool::Count), "Array size mismatch.");
if (mTrackTool >= lcTrackTool::None && mTrackTool < lcTrackTool::Count)
return CursorFromTrackTool[static_cast<int>(mTrackTool)];
return lcCursor::Select;
}
void View::ShowContextMenu() const
{
QGLWidget* Widget = (QGLWidget*)mWidget;
@ -1793,55 +1737,6 @@ void View::OnInitialUpdate()
gMainWindow->AddView(this);
}
void View::OnUpdateCursor()
{
SetCursor(GetCursor());
}
lcTool View::GetCurrentTool() const
{
const lcTool ToolFromTrackTool[static_cast<int>(lcTrackTool::Count)] =
{
lcTool::Select, // lcTrackTool::None
lcTool::Insert, // lcTrackTool::Insert
lcTool::Light, // lcTrackTool::PointLight
lcTool::SpotLight, // lcTrackTool::SpotLight
lcTool::Camera, // lcTrackTool::Camera
lcTool::Select, // lcTrackTool::Select
lcTool::Move, // lcTrackTool::MoveX
lcTool::Move, // lcTrackTool::MoveY
lcTool::Move, // lcTrackTool::MoveZ
lcTool::Move, // lcTrackTool::MoveXY
lcTool::Move, // lcTrackTool::MoveXZ
lcTool::Move, // lcTrackTool::MoveYZ
lcTool::Move, // lcTrackTool::MoveXYZ
lcTool::Rotate, // lcTrackTool::RotateX
lcTool::Rotate, // lcTrackTool::RotateY
lcTool::Rotate, // lcTrackTool::RotateZ
lcTool::Rotate, // lcTrackTool::RotateXY
lcTool::Rotate, // lcTrackTool::RotateXYZ
lcTool::Move, // lcTrackTool::ScalePlus
lcTool::Move, // lcTrackTool::ScaleMinus
lcTool::Eraser, // lcTrackTool::Eraser
lcTool::Paint, // lcTrackTool::Paint
lcTool::ColorPicker, // lcTrackTool::ColorPicker
lcTool::Zoom, // lcTrackTool::Zoom
lcTool::Pan, // lcTrackTool::Pan
lcTool::RotateView, // lcTrackTool::OrbitX
lcTool::RotateView, // lcTrackTool::OrbitY
lcTool::RotateView, // lcTrackTool::OrbitXY
lcTool::Roll, // lcTrackTool::Roll
lcTool::ZoomRegion // lcTrackTool::ZoomRegion
};
static_assert(LC_ARRAY_COUNT(ToolFromTrackTool) == static_cast<int>(lcTrackTool::Count), "Array size mismatch.");
if (mTrackTool >= lcTrackTool::None && mTrackTool < lcTrackTool::Count)
return ToolFromTrackTool[static_cast<int>(mTrackTool)];
return lcTool::Select;
}
lcTrackTool View::GetOverrideTrackTool(Qt::MouseButton Button) const
{
if (mTrackToolFromOverlay)
@ -2418,7 +2313,7 @@ void View::UpdateTrackTool()
if (NewTrackTool != mTrackTool)
{
mTrackTool = NewTrackTool;
OnUpdateCursor();
UpdateCursor();
if (Redraw)
gMainWindow->UpdateAllViews();
@ -2499,7 +2394,7 @@ bool View::IsTrackToolAllowed(lcTrackTool TrackTool, quint32 AllowedTransforms)
void View::StartOrbitTracking()
{
mTrackTool = lcTrackTool::OrbitXY;
OnUpdateCursor();
UpdateCursor();
OnButtonDown(lcTrackButton::Left);
}
@ -2561,7 +2456,7 @@ void View::StartTracking(lcTrackButton TrackButton)
break;
}
OnUpdateCursor();
UpdateCursor();
}
void View::StopTracking(bool Accept)
@ -2793,7 +2688,7 @@ void View::OnLeftButtonDown()
if (OverrideTool != lcTrackTool::None)
{
mTrackTool = OverrideTool;
OnUpdateCursor();
UpdateCursor();
}
OnButtonDown(lcTrackButton::Left);
@ -2837,7 +2732,7 @@ void View::OnMiddleButtonDown()
if (OverrideTool != lcTrackTool::None)
{
mTrackTool = OverrideTool;
OnUpdateCursor();
UpdateCursor();
}
#endif
OnButtonDown(lcTrackButton::Middle);
@ -2863,7 +2758,7 @@ void View::OnRightButtonDown()
if (OverrideTool != lcTrackTool::None)
{
mTrackTool = OverrideTool;
OnUpdateCursor();
UpdateCursor();
}
OnButtonDown(lcTrackButton::Right);
@ -2906,7 +2801,7 @@ void View::OnMouseMove()
if (NewTrackTool != mTrackTool)
{
mTrackTool = NewTrackTool;
OnUpdateCursor();
UpdateCursor();
}
return;

View file

@ -3,42 +3,6 @@
#include "lc_glwidget.h"
#include "camera.h"
#include "lc_viewsphere.h"
#include "lc_commands.h"
enum class lcTrackTool
{
None,
Insert,
PointLight,
SpotLight,
Camera,
Select,
MoveX,
MoveY,
MoveZ,
MoveXY,
MoveXZ,
MoveYZ,
MoveXYZ,
RotateX,
RotateY,
RotateZ,
RotateXY,
RotateXYZ,
ScalePlus,
ScaleMinus,
Eraser,
Paint,
ColorPicker,
Zoom,
Pan,
OrbitX,
OrbitY,
OrbitXY,
Roll,
ZoomRegion,
Count
};
class View : public lcGLWidget
{
@ -71,7 +35,6 @@ public:
void OnDraw() override;
void OnInitialUpdate() override;
void OnUpdateCursor() override;
void OnLeftButtonDown() override;
void OnLeftButtonUp() override;
void OnLeftButtonDoubleClick() override;
@ -103,7 +66,6 @@ public:
void SetViewpoint(const lcVector3& Position);
void SetCameraAngles(float Latitude, float Longitude);
void SetDefaultCamera();
lcCursor GetCursor() const;
void ShowContextMenu() const;
lcVector3 GetMoveDirection(const lcVector3& Direction) const;
@ -133,7 +95,6 @@ protected:
void UpdateTrackTool();
bool IsTrackToolAllowed(lcTrackTool TrackTool, quint32 AllowedTransforms) const;
lcTool GetCurrentTool() const;
lcTrackTool GetOverrideTrackTool(Qt::MouseButton Button) const;
float GetOverlayScale() const;
void StartTracking(lcTrackButton TrackButton);
@ -146,7 +107,6 @@ protected:
lcMatrix44 mActiveSubmodelTransform;
lcDragState mDragState;
lcTrackTool mTrackTool;
bool mTrackToolFromOverlay;
bool mTrackUpdated;
lcVector3 mMouseDownPosition;

View file

@ -156,7 +156,7 @@ void lcQGLWidget::keyPressEvent(QKeyEvent* KeyEvent)
if (KeyEvent->key() == Qt::Key_Control || KeyEvent->key() == Qt::Key_Shift)
{
mWidget->SetMouseModifiers(KeyEvent->modifiers());
mWidget->OnUpdateCursor();
mWidget->UpdateCursor();
}
QGLWidget::keyPressEvent(KeyEvent);
@ -167,7 +167,7 @@ void lcQGLWidget::keyReleaseEvent(QKeyEvent* KeyEvent)
if (KeyEvent->key() == Qt::Key_Control || KeyEvent->key() == Qt::Key_Shift)
{
mWidget->SetMouseModifiers(KeyEvent->modifiers());
mWidget->OnUpdateCursor();
mWidget->UpdateCursor();
}
QGLWidget::keyReleaseEvent(KeyEvent);