This commit is contained in:
Leonardo Zide 2020-12-13 12:05:54 -08:00
parent 05963fc8b0
commit 1012fc20cd
7 changed files with 124 additions and 87 deletions

View file

@ -108,6 +108,32 @@ public:
return mTrackButton != lcTrackButton::None; return mTrackButton != lcTrackButton::None;
} }
int GetWidth() const
{
return mWidth;
}
int GetHeight() const
{
return mHeight;
}
void SetSize(int Width, int Height)
{
mWidth = Width;
mHeight = Height;
}
QGLWidget* GetWidget() const
{
return mWidget;
}
void SetWidget(QGLWidget* Widget)
{
mWidget = Widget;
}
int GetMouseX() const int GetMouseX() const
{ {
return mMouseX; return mMouseX;
@ -164,9 +190,6 @@ public:
virtual void BeginDrag(lcDragState DragState) { Q_UNUSED(DragState); } virtual void BeginDrag(lcDragState DragState) { Q_UNUSED(DragState); }
virtual void EndDrag(bool Accept) { Q_UNUSED(Accept); } virtual void EndDrag(bool Accept) { Q_UNUSED(Accept); }
int mWidth = 1;
int mHeight = 1;
QGLWidget* mWidget = nullptr;
lcContext* mContext = nullptr; lcContext* mContext = nullptr;
signals: signals:
@ -197,6 +220,10 @@ protected:
lcMatrix44 mActiveSubmodelTransform; lcMatrix44 mActiveSubmodelTransform;
lcCamera* mCamera = nullptr; lcCamera* mCamera = nullptr;
QGLWidget* mWidget = nullptr;
int mWidth = 1;
int mHeight = 1;
bool mDeleteContext = true; bool mDeleteContext = true;
static lcGLWidget* mLastFocusedView; static lcGLWidget* mLastFocusedView;

View file

@ -72,7 +72,7 @@ void lcModelTabWidget::ResetLayout()
TopWidget->deleteLater(); TopWidget->deleteLater();
Widget->setFocus(); Widget->setFocus();
SetActiveView((View*)((lcQGLWidget*)Widget)->mWidget); SetActiveView((View*)((lcQGLWidget*)Widget)->GetView());
} }
void lcModelTabWidget::Clear() void lcModelTabWidget::Clear()
@ -84,8 +84,8 @@ void lcModelTabWidget::Clear()
mViews.RemoveAll(); mViews.RemoveAll();
mActiveView = nullptr; mActiveView = nullptr;
lcQGLWidget* Widget = (lcQGLWidget*)layout()->itemAt(0)->widget(); lcQGLWidget* Widget = (lcQGLWidget*)layout()->itemAt(0)->widget();
delete Widget->mWidget; delete Widget->GetView();
Widget->mWidget = nullptr; Widget->SetView(nullptr);
} }
lcMainWindow::lcMainWindow() lcMainWindow::lcMainWindow()
@ -1372,7 +1372,7 @@ QByteArray lcMainWindow::GetTabLayout()
{ {
if (Widget->metaObject() == &lcQGLWidget::staticMetaObject) if (Widget->metaObject() == &lcQGLWidget::staticMetaObject)
{ {
View* CurrentView = (View*)((lcQGLWidget*)Widget)->mWidget; View* CurrentView = (View*)((lcQGLWidget*)Widget)->GetView();
DataStream << (qint32)0; DataStream << (qint32)0;
DataStream << (qint32)(TabWidget->GetActiveView() == CurrentView ? 1 : 0); DataStream << (qint32)(TabWidget->GetActiveView() == CurrentView ? 1 : 0);
@ -1471,7 +1471,7 @@ void lcMainWindow::RestoreTabLayout(const QByteArray& TabLayout)
View* CurrentView = nullptr; View* CurrentView = nullptr;
if (ParentWidget) if (ParentWidget)
CurrentView = (View*)((lcQGLWidget*)ParentWidget)->mWidget; CurrentView = (View*)((lcQGLWidget*)ParentWidget)->GetView();
if (CameraType == 0) if (CameraType == 0)
{ {
@ -1544,7 +1544,7 @@ void lcMainWindow::RestoreTabLayout(const QByteArray& TabLayout)
if (ActiveWidget && TabWidget) if (ActiveWidget && TabWidget)
{ {
View* ActiveView = (View*)((lcQGLWidget*)ActiveWidget)->mWidget; View* ActiveView = (View*)((lcQGLWidget*)ActiveWidget)->GetView();
TabWidget->SetActiveView(ActiveView); TabWidget->SetActiveView(ActiveView);
} }
} }
@ -1621,11 +1621,7 @@ void lcMainWindow::SetCurrentModelTab(lcModel* Model)
NewView = CreateView(Model); NewView = CreateView(Model);
ViewWidget = (lcQGLWidget*)TabWidget->layout()->itemAt(0)->widget(); ViewWidget = (lcQGLWidget*)TabWidget->layout()->itemAt(0)->widget();
ViewWidget->mWidget = NewView; ViewWidget->SetView(NewView);
NewView->mWidget = ViewWidget;
float Scale = ViewWidget->GetDeviceScale();
NewView->mWidth = ViewWidget->width() * Scale;
NewView->mHeight = ViewWidget->height() * Scale;
AddView(NewView); AddView(NewView);
mModelTabWidget->setCurrentWidget(TabWidget); mModelTabWidget->setCurrentWidget(TabWidget);
@ -1914,7 +1910,7 @@ void lcMainWindow::RemoveActiveView()
} }
OtherWidget->setFocus(); OtherWidget->setFocus();
SetActiveView((View*)((lcQGLWidget*)OtherWidget)->mWidget); SetActiveView((View*)((lcQGLWidget*)OtherWidget)->GetView());
} }
void lcMainWindow::ResetViews() void lcMainWindow::ResetViews()

View file

@ -183,8 +183,8 @@ void lcViewSphere::Draw()
return; return;
lcContext* Context = mWidget->mContext; lcContext* Context = mWidget->mContext;
const int Width = mWidget->mWidth; const int Width = mWidget->GetWidth();
const int Height = mWidget->mHeight; const int Height = mWidget->GetHeight();
const int ViewportSize = mSize; const int ViewportSize = mSize;
const int Left = (mLocation == lcViewSphereLocation::BottomLeft || mLocation == lcViewSphereLocation::TopLeft) ? 0 : Width - ViewportSize; const int Left = (mLocation == lcViewSphereLocation::BottomLeft || mLocation == lcViewSphereLocation::TopLeft) ? 0 : Width - ViewportSize;
const int Bottom = (mLocation == lcViewSphereLocation::BottomLeft || mLocation == lcViewSphereLocation::BottomRight) ? 0 : Height - ViewportSize; const int Bottom = (mLocation == lcViewSphereLocation::BottomLeft || mLocation == lcViewSphereLocation::BottomRight) ? 0 : Height - ViewportSize;
@ -323,8 +323,8 @@ bool lcViewSphere::IsDragging() const
std::bitset<6> lcViewSphere::GetIntersectionFlags(lcVector3& Intersection) const std::bitset<6> lcViewSphere::GetIntersectionFlags(lcVector3& Intersection) const
{ {
const int Width = mWidget->mWidth; const int Width = mWidget->GetWidth();
const int Height = mWidget->mHeight; const int Height = mWidget->GetHeight();
const int ViewportSize = mSize; const int ViewportSize = mSize;
const int Left = (mLocation == lcViewSphereLocation::BottomLeft || mLocation == lcViewSphereLocation::TopLeft) ? 0 : Width - ViewportSize; const int Left = (mLocation == lcViewSphereLocation::BottomLeft || mLocation == lcViewSphereLocation::TopLeft) ? 0 : Width - ViewportSize;
const int Bottom = (mLocation == lcViewSphereLocation::BottomLeft || mLocation == lcViewSphereLocation::BottomRight) ? 0 : Height - ViewportSize; const int Bottom = (mLocation == lcViewSphereLocation::BottomLeft || mLocation == lcViewSphereLocation::BottomRight) ? 0 : Height - ViewportSize;

View file

@ -310,10 +310,9 @@ lcMatrix44 View::GetTileProjectionMatrix(int CurrentRow, int CurrentColumn, int
void View::ShowContextMenu() const void View::ShowContextMenu() const
{ {
QGLWidget* Widget = (QGLWidget*)mWidget;
QAction** Actions = gMainWindow->mActions; QAction** Actions = gMainWindow->mActions;
QMenu* Popup = new QMenu(Widget); QMenu* Popup = new QMenu(mWidget);
Popup->addAction(Actions[LC_EDIT_CUT]); Popup->addAction(Actions[LC_EDIT_CUT]);
Popup->addAction(Actions[LC_EDIT_COPY]); Popup->addAction(Actions[LC_EDIT_COPY]);

View file

@ -17,7 +17,7 @@ lcQAboutDialog::lcQAboutDialog(QWidget *parent) :
ui->version->setText(tr("LeoCAD Version %1").arg(QString::fromLatin1(LC_VERSION_TEXT))); ui->version->setText(tr("LeoCAD Version %1").arg(QString::fromLatin1(LC_VERSION_TEXT)));
#endif #endif
QGLWidget* Widget = (QGLWidget*)gMainWindow->GetActiveView()->mWidget; QGLWidget* Widget = gMainWindow->GetActiveView()->GetWidget();
QGLFormat Format = Widget->context()->format(); QGLFormat Format = Widget->context()->format();
int ColorDepth = Format.redBufferSize() + Format.greenBufferSize() + Format.blueBufferSize() + Format.alphaBufferSize(); int ColorDepth = Format.redBufferSize() + Format.greenBufferSize() + Format.blueBufferSize() + Format.alphaBufferSize();

View file

@ -23,21 +23,21 @@ lcQGLWidget::lcQGLWidget(QWidget* Parent, lcGLWidget* Owner)
: QGLWidget(Parent, gWidgetList.isEmpty() ? nullptr : gWidgetList.first()) : QGLWidget(Parent, gWidgetList.isEmpty() ? nullptr : gWidgetList.first())
{ {
mWheelAccumulator = 0; mWheelAccumulator = 0;
mWidget = Owner; mView = Owner;
mWidget->mWidget = this; mView->SetWidget(this);
makeCurrent(); makeCurrent();
if (gWidgetList.isEmpty()) if (gWidgetList.isEmpty())
{ {
// TODO: Find a better place for the grid texture and font // TODO: Find a better place for the grid texture and font
gStringCache.Initialize(mWidget->mContext); gStringCache.Initialize(mView->mContext);
gTexFont.Initialize(mWidget->mContext); gTexFont.Initialize(mView->mContext);
lcInitializeGLExtensions(context()); lcInitializeGLExtensions(context());
lcContext::CreateResources(); lcContext::CreateResources();
View::CreateResources(mWidget->mContext); View::CreateResources(mView->mContext);
lcViewSphere::CreateResources(mWidget->mContext); lcViewSphere::CreateResources(mView->mContext);
if (!gSupportsShaderObjects && lcGetPreferences().mShadingMode == lcShadingMode::DefaultLights) if (!gSupportsShaderObjects && lcGetPreferences().mShadingMode == lcShadingMode::DefaultLights)
lcGetPreferences().mShadingMode = lcShadingMode::Flat; lcGetPreferences().mShadingMode = lcShadingMode::Flat;
@ -51,7 +51,7 @@ lcQGLWidget::lcQGLWidget(QWidget* Parent, lcGLWidget* Owner)
gWidgetList.append(this); gWidgetList.append(this);
mWidget->OnInitialUpdate(); mView->OnInitialUpdate();
setMouseTracking(true); setMouseTracking(true);
@ -71,16 +71,16 @@ lcQGLWidget::~lcQGLWidget()
gStringCache.Reset(); gStringCache.Reset();
gTexFont.Reset(); gTexFont.Reset();
lcGetPiecesLibrary()->ReleaseBuffers(mWidget->mContext); lcGetPiecesLibrary()->ReleaseBuffers(mView->mContext);
View::DestroyResources(mWidget->mContext); View::DestroyResources(mView->mContext);
lcContext::DestroyResources(); lcContext::DestroyResources();
lcViewSphere::DestroyResources(mWidget->mContext); lcViewSphere::DestroyResources(mView->mContext);
delete gPlaceholderMesh; delete gPlaceholderMesh;
gPlaceholderMesh = nullptr; gPlaceholderMesh = nullptr;
} }
delete mWidget; delete mView;
} }
QSize lcQGLWidget::sizeHint() const QSize lcQGLWidget::sizeHint() const
@ -88,10 +88,25 @@ QSize lcQGLWidget::sizeHint() const
return mPreferredSize.isNull() ? QGLWidget::sizeHint() : mPreferredSize; return mPreferredSize.isNull() ? QGLWidget::sizeHint() : mPreferredSize;
} }
void lcQGLWidget::SetView(lcGLWidget* View)
{
mView = View;
if (View)
{
View->SetWidget(this);
const float Scale = GetDeviceScale();
View->SetSize(width() * Scale, height() * Scale);
if (hasFocus())
View->SetFocus(true);
}
}
void lcQGLWidget::SetPreviewPosition(const QRect& ParentRect) void lcQGLWidget::SetPreviewPosition(const QRect& ParentRect)
{ {
lcPreferences& Preferences = lcGetPreferences(); lcPreferences& Preferences = lcGetPreferences();
lcPreviewWidget* Preview = reinterpret_cast<lcPreviewWidget*>(mWidget); lcPreviewWidget* Preview = reinterpret_cast<lcPreviewWidget*>(mView);
setWindowTitle(tr("%1 Preview").arg(Preview->IsModel() ? "Submodel" : "Part")); setWindowTitle(tr("%1 Preview").arg(Preview->IsModel() ? "Submodel" : "Part"));
@ -102,10 +117,6 @@ void lcQGLWidget::SetPreviewPosition(const QRect& ParentRect)
} }
mPreferredSize = QSize(Size[0], Size[1]); mPreferredSize = QSize(Size[0], Size[1]);
float Scale = GetDeviceScale();
Preview->mWidth = width() * Scale;
Preview->mHeight = height() * Scale;
const QRect desktop = QApplication::desktop()->geometry(); const QRect desktop = QApplication::desktop()->geometry();
QPoint pos; QPoint pos;
@ -141,27 +152,26 @@ void lcQGLWidget::SetPreviewPosition(const QRect& ParentRect)
void lcQGLWidget::resizeGL(int Width, int Height) void lcQGLWidget::resizeGL(int Width, int Height)
{ {
mWidget->mWidth = Width; mView->SetSize(Width, Height);
mWidget->mHeight = Height;
} }
void lcQGLWidget::paintGL() void lcQGLWidget::paintGL()
{ {
mWidget->OnDraw(); mView->OnDraw();
} }
void lcQGLWidget::focusInEvent(QFocusEvent* FocusEvent) void lcQGLWidget::focusInEvent(QFocusEvent* FocusEvent)
{ {
if (mWidget) if (mView)
mWidget->SetFocus(true); mView->SetFocus(true);
QGLWidget::focusInEvent(FocusEvent); QGLWidget::focusInEvent(FocusEvent);
} }
void lcQGLWidget::focusOutEvent(QFocusEvent* FocusEvent) void lcQGLWidget::focusOutEvent(QFocusEvent* FocusEvent)
{ {
if (mWidget) if (mView)
mWidget->SetFocus(false); mView->SetFocus(false);
QGLWidget::focusOutEvent(FocusEvent); QGLWidget::focusOutEvent(FocusEvent);
} }
@ -170,8 +180,8 @@ void lcQGLWidget::keyPressEvent(QKeyEvent* KeyEvent)
{ {
if (KeyEvent->key() == Qt::Key_Control || KeyEvent->key() == Qt::Key_Shift) if (KeyEvent->key() == Qt::Key_Control || KeyEvent->key() == Qt::Key_Shift)
{ {
mWidget->SetMouseModifiers(KeyEvent->modifiers()); mView->SetMouseModifiers(KeyEvent->modifiers());
mWidget->UpdateCursor(); mView->UpdateCursor();
} }
QGLWidget::keyPressEvent(KeyEvent); QGLWidget::keyPressEvent(KeyEvent);
@ -181,8 +191,8 @@ void lcQGLWidget::keyReleaseEvent(QKeyEvent* KeyEvent)
{ {
if (KeyEvent->key() == Qt::Key_Control || KeyEvent->key() == Qt::Key_Shift) if (KeyEvent->key() == Qt::Key_Control || KeyEvent->key() == Qt::Key_Shift)
{ {
mWidget->SetMouseModifiers(KeyEvent->modifiers()); mView->SetMouseModifiers(KeyEvent->modifiers());
mWidget->UpdateCursor(); mView->UpdateCursor();
} }
QGLWidget::keyReleaseEvent(KeyEvent); QGLWidget::keyReleaseEvent(KeyEvent);
@ -192,30 +202,30 @@ void lcQGLWidget::mousePressEvent(QMouseEvent* MouseEvent)
{ {
float DeviceScale = GetDeviceScale(); float DeviceScale = GetDeviceScale();
mWidget->SetMousePosition(MouseEvent->x() * DeviceScale, mWidget->mHeight - MouseEvent->y() * DeviceScale - 1); mView->SetMousePosition(MouseEvent->x() * DeviceScale, mView->GetHeight() - MouseEvent->y() * DeviceScale - 1);
mWidget->SetMouseModifiers(MouseEvent->modifiers()); mView->SetMouseModifiers(MouseEvent->modifiers());
switch (MouseEvent->button()) switch (MouseEvent->button())
{ {
case Qt::LeftButton: case Qt::LeftButton:
mWidget->OnLeftButtonDown(); mView->OnLeftButtonDown();
break; break;
case Qt::MidButton: case Qt::MidButton:
mWidget->OnMiddleButtonDown(); mView->OnMiddleButtonDown();
break; break;
case Qt::RightButton: case Qt::RightButton:
mWidget->OnRightButtonDown(); mView->OnRightButtonDown();
break; break;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
case Qt::BackButton: case Qt::BackButton:
mWidget->OnBackButtonDown(); mView->OnBackButtonDown();
break; break;
case Qt::ForwardButton: case Qt::ForwardButton:
mWidget->OnForwardButtonDown(); mView->OnForwardButtonDown();
break; break;
#endif #endif
@ -228,30 +238,30 @@ void lcQGLWidget::mouseReleaseEvent(QMouseEvent* MouseEvent)
{ {
float DeviceScale = GetDeviceScale(); float DeviceScale = GetDeviceScale();
mWidget->SetMousePosition(MouseEvent->x() * DeviceScale, mWidget->mHeight - MouseEvent->y() * DeviceScale - 1); mView->SetMousePosition(MouseEvent->x() * DeviceScale, mView->GetHeight() - MouseEvent->y() * DeviceScale - 1);
mWidget->SetMouseModifiers(MouseEvent->modifiers()); mView->SetMouseModifiers(MouseEvent->modifiers());
switch (MouseEvent->button()) switch (MouseEvent->button())
{ {
case Qt::LeftButton: case Qt::LeftButton:
mWidget->OnLeftButtonUp(); mView->OnLeftButtonUp();
break; break;
case Qt::MidButton: case Qt::MidButton:
mWidget->OnMiddleButtonUp(); mView->OnMiddleButtonUp();
break; break;
case Qt::RightButton: case Qt::RightButton:
mWidget->OnRightButtonUp(); mView->OnRightButtonUp();
break; break;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
case Qt::BackButton: case Qt::BackButton:
mWidget->OnBackButtonUp(); mView->OnBackButtonUp();
break; break;
case Qt::ForwardButton: case Qt::ForwardButton:
mWidget->OnForwardButtonUp(); mView->OnForwardButtonUp();
break; break;
#endif #endif
@ -264,13 +274,13 @@ void lcQGLWidget::mouseDoubleClickEvent(QMouseEvent* MouseEvent)
{ {
float DeviceScale = GetDeviceScale(); float DeviceScale = GetDeviceScale();
mWidget->SetMousePosition(MouseEvent->x() * DeviceScale, mWidget->mHeight - MouseEvent->y() * DeviceScale - 1); mView->SetMousePosition(MouseEvent->x() * DeviceScale, mView->GetHeight() - MouseEvent->y() * DeviceScale - 1);
mWidget->SetMouseModifiers(MouseEvent->modifiers()); mView->SetMouseModifiers(MouseEvent->modifiers());
switch (MouseEvent->button()) switch (MouseEvent->button())
{ {
case Qt::LeftButton: case Qt::LeftButton:
mWidget->OnLeftButtonDoubleClick(); mView->OnLeftButtonDoubleClick();
break; break;
default: default:
break; break;
@ -281,10 +291,10 @@ void lcQGLWidget::mouseMoveEvent(QMouseEvent* MouseEvent)
{ {
float DeviceScale = GetDeviceScale(); float DeviceScale = GetDeviceScale();
mWidget->SetMousePosition(MouseEvent->x() * DeviceScale, mWidget->mHeight - MouseEvent->y() * DeviceScale - 1); mView->SetMousePosition(MouseEvent->x() * DeviceScale, mView->GetHeight() - MouseEvent->y() * DeviceScale - 1);
mWidget->SetMouseModifiers(MouseEvent->modifiers()); mView->SetMouseModifiers(MouseEvent->modifiers());
mWidget->OnMouseMove(); mView->OnMouseMove();
} }
void lcQGLWidget::wheelEvent(QWheelEvent* WheelEvent) void lcQGLWidget::wheelEvent(QWheelEvent* WheelEvent)
@ -302,11 +312,11 @@ void lcQGLWidget::wheelEvent(QWheelEvent* WheelEvent)
float DeviceScale = GetDeviceScale(); float DeviceScale = GetDeviceScale();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
mWidget->SetMousePosition(WheelEvent->position().x() * DeviceScale, mWidget->mHeight - WheelEvent->position().y() * DeviceScale - 1); mView->SetMousePosition(WheelEvent->position().x() * DeviceScale, mView->GetHeight() - WheelEvent->position().y() * DeviceScale - 1);
#else #else
mWidget->SetMousePosition(WheelEvent->x() * DeviceScale, mWidget->mHeight - WheelEvent->y() * DeviceScale - 1); mView->SetMousePosition(WheelEvent->x() * DeviceScale, mView->mHeight - WheelEvent->y() * DeviceScale - 1);
#endif #endif
mWidget->SetMouseModifiers(WheelEvent->modifiers()); mView->SetMouseModifiers(WheelEvent->modifiers());
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
mWheelAccumulator += WheelEvent->angleDelta().y() / 8; mWheelAccumulator += WheelEvent->angleDelta().y() / 8;
@ -317,7 +327,7 @@ void lcQGLWidget::wheelEvent(QWheelEvent* WheelEvent)
if (numSteps) if (numSteps)
{ {
mWidget->OnMouseWheel(numSteps); mView->OnMouseWheel(numSteps);
mWheelAccumulator -= numSteps * 15; mWheelAccumulator -= numSteps * 15;
} }
@ -331,13 +341,13 @@ void lcQGLWidget::dragEnterEvent(QDragEnterEvent* DragEnterEvent)
if (MimeData->hasFormat("application/vnd.leocad-part")) if (MimeData->hasFormat("application/vnd.leocad-part"))
{ {
DragEnterEvent->acceptProposedAction(); DragEnterEvent->acceptProposedAction();
mWidget->BeginDrag(lcDragState::Piece); mView->BeginDrag(lcDragState::Piece);
return; return;
} }
else if (MimeData->hasFormat("application/vnd.leocad-color")) else if (MimeData->hasFormat("application/vnd.leocad-color"))
{ {
DragEnterEvent->acceptProposedAction(); DragEnterEvent->acceptProposedAction();
mWidget->BeginDrag(lcDragState::Color); mView->BeginDrag(lcDragState::Color);
return; return;
} }
@ -346,7 +356,7 @@ void lcQGLWidget::dragEnterEvent(QDragEnterEvent* DragEnterEvent)
void lcQGLWidget::dragLeaveEvent(QDragLeaveEvent* DragLeaveEvent) void lcQGLWidget::dragLeaveEvent(QDragLeaveEvent* DragLeaveEvent)
{ {
mWidget->EndDrag(false); mView->EndDrag(false);
DragLeaveEvent->accept(); DragLeaveEvent->accept();
} }
@ -358,10 +368,10 @@ void lcQGLWidget::dragMoveEvent(QDragMoveEvent* DragMoveEvent)
{ {
float DeviceScale = GetDeviceScale(); float DeviceScale = GetDeviceScale();
mWidget->SetMousePosition(DragMoveEvent->pos().x() * DeviceScale, mWidget->mHeight - DragMoveEvent->pos().y() * DeviceScale - 1); mView->SetMousePosition(DragMoveEvent->pos().x() * DeviceScale, mView->GetHeight() - DragMoveEvent->pos().y() * DeviceScale - 1);
mWidget->SetMouseModifiers(DragMoveEvent->keyboardModifiers()); mView->SetMouseModifiers(DragMoveEvent->keyboardModifiers());
mWidget->OnMouseMove(); mView->OnMouseMove();
DragMoveEvent->accept(); DragMoveEvent->accept();
return; return;
@ -376,7 +386,7 @@ void lcQGLWidget::dropEvent(QDropEvent* DropEvent)
if (MimeData->hasFormat("application/vnd.leocad-part") || MimeData->hasFormat("application/vnd.leocad-color")) if (MimeData->hasFormat("application/vnd.leocad-part") || MimeData->hasFormat("application/vnd.leocad-color"))
{ {
mWidget->EndDrag(true); mView->EndDrag(true);
setFocus(Qt::MouseFocusReason); setFocus(Qt::MouseFocusReason);
DropEvent->accept(); DropEvent->accept();

View file

@ -5,13 +5,20 @@
class lcQGLWidget : public QGLWidget class lcQGLWidget : public QGLWidget
{ {
public: public:
lcQGLWidget(QWidget* Parent, lcGLWidget* Owner); lcQGLWidget(QWidget* Parent, lcGLWidget* View);
~lcQGLWidget(); ~lcQGLWidget();
lcGLWidget* GetView() const
{
return mView;
}
void SetView(lcGLWidget* View);
void SetPreviewPosition(const QRect& ParentRect);
QSize sizeHint() const override; QSize sizeHint() const override;
lcGLWidget* mWidget; protected:
float GetDeviceScale() const float GetDeviceScale() const
{ {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
@ -19,11 +26,8 @@ public:
#else #else
return 1.0f; return 1.0f;
#endif #endif
} }
void SetPreviewPosition(const QRect& ParentRect);
protected:
void resizeGL(int Width, int Height) override; void resizeGL(int Width, int Height) override;
void paintGL() override; void paintGL() override;
void focusInEvent(QFocusEvent* FocusEvent) override; void focusInEvent(QFocusEvent* FocusEvent) override;
@ -40,6 +44,7 @@ protected:
void dragMoveEvent(QDragMoveEvent* DragMoveEvent) override; void dragMoveEvent(QDragMoveEvent* DragMoveEvent) override;
void dropEvent(QDropEvent* DropEvent) override; void dropEvent(QDropEvent* DropEvent) override;
lcGLWidget* mView;
QSize mPreferredSize; QSize mPreferredSize;
int mWheelAccumulator; int mWheelAccumulator;
}; };