2013-08-09 06:57:18 +02:00
|
|
|
#include "lc_global.h"
|
2020-12-18 02:59:11 +01:00
|
|
|
#include "lc_viewwidget.h"
|
2015-05-09 21:54:29 +02:00
|
|
|
#include "lc_glextensions.h"
|
2013-08-09 06:57:18 +02:00
|
|
|
#include "project.h"
|
|
|
|
#include "lc_library.h"
|
|
|
|
#include "lc_application.h"
|
2013-08-16 03:25:51 +02:00
|
|
|
#include "lc_mainwindow.h"
|
2017-06-22 06:40:26 +02:00
|
|
|
#include "lc_partselectionwidget.h"
|
2014-04-14 05:20:16 +02:00
|
|
|
#include "lc_context.h"
|
2020-12-25 19:43:22 +01:00
|
|
|
#include "lc_view.h"
|
2014-08-24 00:56:59 +02:00
|
|
|
#include "texfont.h"
|
2018-10-29 01:59:01 +01:00
|
|
|
#include "lc_viewsphere.h"
|
2018-09-24 04:31:33 +02:00
|
|
|
#include "lc_stringcache.h"
|
2014-08-24 00:56:59 +02:00
|
|
|
#include "lc_texture.h"
|
2015-01-08 05:50:38 +01:00
|
|
|
#include "lc_mesh.h"
|
2016-12-28 22:30:31 +01:00
|
|
|
#include "lc_profile.h"
|
2020-10-07 12:07:32 +02:00
|
|
|
#include "lc_previewwidget.h"
|
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
static QList<lcViewWidget*> gWidgetList;
|
2020-12-27 22:05:55 +01:00
|
|
|
bool lcViewWidget::mResourcesLoaded;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2020-12-27 22:05:55 +01:00
|
|
|
#ifdef LC_USE_QOPENGLWIDGET
|
2020-12-25 19:54:33 +01:00
|
|
|
lcViewWidget::lcViewWidget(QWidget* Parent, lcView* View)
|
2020-12-27 22:05:55 +01:00
|
|
|
: lcViewWidgetParent(Parent)
|
|
|
|
#else
|
|
|
|
lcViewWidget::lcViewWidget(QWidget* Parent, lcView* View)
|
|
|
|
: lcViewWidgetParent(Parent, gWidgetList.isEmpty() ? nullptr : gWidgetList.first())
|
|
|
|
#endif
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2015-02-10 23:34:04 +01:00
|
|
|
mWheelAccumulator = 0;
|
2020-12-20 01:05:29 +01:00
|
|
|
mView = View;
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->SetWidget(this);
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2016-12-28 22:30:31 +01:00
|
|
|
gWidgetList.append(this);
|
2014-08-24 00:56:59 +02:00
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
setMouseTracking(true);
|
|
|
|
|
2020-12-20 01:05:29 +01:00
|
|
|
if (View->GetViewType() == lcViewType::View)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
|
|
|
setFocusPolicy(Qt::StrongFocus);
|
2020-11-14 21:47:55 +01:00
|
|
|
setAcceptDrops(true);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
lcViewWidget::~lcViewWidget()
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2016-12-28 22:30:31 +01:00
|
|
|
gWidgetList.removeOne(this);
|
2020-07-11 18:17:43 +02:00
|
|
|
|
2016-12-28 22:30:31 +01:00
|
|
|
if (gWidgetList.isEmpty())
|
2014-08-24 00:56:59 +02:00
|
|
|
{
|
2020-07-11 18:17:43 +02:00
|
|
|
gStringCache.Reset();
|
|
|
|
gTexFont.Reset();
|
|
|
|
|
2020-12-13 21:05:54 +01:00
|
|
|
lcGetPiecesLibrary()->ReleaseBuffers(mView->mContext);
|
2020-12-25 19:54:33 +01:00
|
|
|
lcView::DestroyResources(mView->mContext);
|
2020-12-27 22:05:55 +01:00
|
|
|
mView->mContext->DestroyResources();
|
2020-12-13 21:05:54 +01:00
|
|
|
lcViewSphere::DestroyResources(mView->mContext);
|
2015-01-08 05:50:38 +01:00
|
|
|
|
|
|
|
delete gPlaceholderMesh;
|
2017-04-14 02:26:40 +02:00
|
|
|
gPlaceholderMesh = nullptr;
|
2020-12-27 22:05:55 +01:00
|
|
|
|
|
|
|
mResourcesLoaded = false;
|
2014-08-24 00:56:59 +02:00
|
|
|
}
|
|
|
|
|
2020-12-13 21:05:54 +01:00
|
|
|
delete mView;
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
QSize lcViewWidget::sizeHint() const
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2020-12-27 22:05:55 +01:00
|
|
|
return mPreferredSize.isEmpty() ? lcViewWidgetParent::sizeHint() : mPreferredSize;
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2020-12-25 19:54:33 +01:00
|
|
|
void lcViewWidget::SetView(lcView* View)
|
2020-12-13 21:05:54 +01:00
|
|
|
{
|
|
|
|
mView = View;
|
|
|
|
|
|
|
|
if (View)
|
|
|
|
{
|
2020-12-27 22:05:55 +01:00
|
|
|
#ifdef LC_USE_QOPENGLWIDGET
|
|
|
|
View->mContext->SetGLContext(context());
|
|
|
|
#endif
|
2020-12-13 21:05:54 +01:00
|
|
|
View->SetWidget(this);
|
|
|
|
const float Scale = GetDeviceScale();
|
|
|
|
View->SetSize(width() * Scale, height() * Scale);
|
|
|
|
|
|
|
|
if (hasFocus())
|
|
|
|
View->SetFocus(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
void lcViewWidget::SetPreviewPosition(const QRect& ParentRect)
|
2020-10-07 12:07:32 +02:00
|
|
|
{
|
|
|
|
lcPreferences& Preferences = lcGetPreferences();
|
2020-12-24 20:32:56 +01:00
|
|
|
lcPreview* Preview = reinterpret_cast<lcPreview*>(mView);
|
2020-10-07 12:07:32 +02:00
|
|
|
|
|
|
|
setWindowTitle(tr("%1 Preview").arg(Preview->IsModel() ? "Submodel" : "Part"));
|
|
|
|
|
|
|
|
int Size[2] = { 300,200 };
|
|
|
|
if (Preferences.mPreviewSize == 400)
|
|
|
|
{
|
|
|
|
Size[0] = 400; Size[1] = 300;
|
|
|
|
}
|
2020-11-14 21:47:55 +01:00
|
|
|
mPreferredSize = QSize(Size[0], Size[1]);
|
2020-10-07 12:07:32 +02:00
|
|
|
|
|
|
|
const QRect desktop = QApplication::desktop()->geometry();
|
|
|
|
|
|
|
|
QPoint pos;
|
|
|
|
switch (Preferences.mPreviewLocation)
|
|
|
|
{
|
|
|
|
case lcPreviewLocation::TopRight:
|
|
|
|
pos = mapToGlobal(ParentRect.topRight());
|
|
|
|
break;
|
|
|
|
case lcPreviewLocation::TopLeft:
|
|
|
|
pos = mapToGlobal(ParentRect.topLeft());
|
|
|
|
break;
|
|
|
|
case lcPreviewLocation::BottomRight:
|
|
|
|
pos = mapToGlobal(ParentRect.bottomRight());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pos = mapToGlobal(ParentRect.bottomLeft());
|
|
|
|
break;
|
|
|
|
}
|
2020-12-18 21:15:35 +01:00
|
|
|
|
2020-10-07 12:07:32 +02:00
|
|
|
if (pos.x() < desktop.left())
|
|
|
|
pos.setX(desktop.left());
|
|
|
|
if (pos.y() < desktop.top())
|
|
|
|
pos.setY(desktop.top());
|
|
|
|
|
2020-12-18 21:15:35 +01:00
|
|
|
if ((pos.x() + width()) > desktop.right())
|
|
|
|
pos.setX(desktop.right() - width());
|
2020-10-07 12:07:32 +02:00
|
|
|
if ((pos.y() + height()) > desktop.bottom())
|
|
|
|
pos.setY(desktop.bottom() - height());
|
|
|
|
move(pos);
|
|
|
|
|
|
|
|
setMinimumSize(100,100);
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
2020-12-27 22:05:55 +01:00
|
|
|
void lcViewWidget::initializeGL()
|
|
|
|
{
|
|
|
|
#ifdef LC_USE_QOPENGLWIDGET
|
|
|
|
mView->mContext->SetGLContext(context());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!mResourcesLoaded)
|
|
|
|
{
|
|
|
|
lcInitializeGLExtensions(context());
|
|
|
|
|
|
|
|
// TODO: Find a better place for the grid texture and font
|
|
|
|
gStringCache.Initialize(mView->mContext);
|
|
|
|
gTexFont.Initialize(mView->mContext);
|
|
|
|
|
|
|
|
mView->mContext->CreateResources();
|
|
|
|
lcView::CreateResources(mView->mContext);
|
|
|
|
lcViewSphere::CreateResources(mView->mContext);
|
|
|
|
|
|
|
|
if (!gSupportsShaderObjects && lcGetPreferences().mShadingMode == lcShadingMode::DefaultLights)
|
|
|
|
lcGetPreferences().mShadingMode = lcShadingMode::Flat;
|
|
|
|
|
|
|
|
if (!gSupportsFramebufferObject)
|
|
|
|
gMainWindow->GetPartSelectionWidget()->DisableIconMode();
|
|
|
|
|
|
|
|
gPlaceholderMesh = new lcMesh;
|
|
|
|
gPlaceholderMesh->CreateBox();
|
|
|
|
|
|
|
|
mResourcesLoaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
void lcViewWidget::resizeGL(int Width, int Height)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->SetSize(Width, Height);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
void lcViewWidget::paintGL()
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->OnDraw();
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
void lcViewWidget::focusInEvent(QFocusEvent* FocusEvent)
|
2020-12-12 03:01:04 +01:00
|
|
|
{
|
2020-12-13 21:05:54 +01:00
|
|
|
if (mView)
|
|
|
|
mView->SetFocus(true);
|
2020-12-12 03:01:04 +01:00
|
|
|
|
2020-12-27 22:05:55 +01:00
|
|
|
lcViewWidgetParent::focusInEvent(FocusEvent);
|
2020-12-12 03:01:04 +01:00
|
|
|
}
|
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
void lcViewWidget::focusOutEvent(QFocusEvent* FocusEvent)
|
2020-12-12 03:01:04 +01:00
|
|
|
{
|
2020-12-13 21:05:54 +01:00
|
|
|
if (mView)
|
|
|
|
mView->SetFocus(false);
|
2020-12-12 03:01:04 +01:00
|
|
|
|
2020-12-27 22:05:55 +01:00
|
|
|
lcViewWidgetParent::focusOutEvent(FocusEvent);
|
2020-12-12 03:01:04 +01:00
|
|
|
}
|
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
void lcViewWidget::keyPressEvent(QKeyEvent* KeyEvent)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2020-11-14 21:47:55 +01:00
|
|
|
if (KeyEvent->key() == Qt::Key_Control || KeyEvent->key() == Qt::Key_Shift)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->SetMouseModifiers(KeyEvent->modifiers());
|
|
|
|
mView->UpdateCursor();
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2020-12-27 22:05:55 +01:00
|
|
|
lcViewWidgetParent::keyPressEvent(KeyEvent);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
void lcViewWidget::keyReleaseEvent(QKeyEvent* KeyEvent)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2020-11-14 21:47:55 +01:00
|
|
|
if (KeyEvent->key() == Qt::Key_Control || KeyEvent->key() == Qt::Key_Shift)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->SetMouseModifiers(KeyEvent->modifiers());
|
|
|
|
mView->UpdateCursor();
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2020-12-27 22:05:55 +01:00
|
|
|
lcViewWidgetParent::keyReleaseEvent(KeyEvent);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
void lcViewWidget::mousePressEvent(QMouseEvent* MouseEvent)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2020-12-05 17:45:29 +01:00
|
|
|
float DeviceScale = GetDeviceScale();
|
2014-04-06 23:44:58 +02:00
|
|
|
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->SetMousePosition(MouseEvent->x() * DeviceScale, mView->GetHeight() - MouseEvent->y() * DeviceScale - 1);
|
|
|
|
mView->SetMouseModifiers(MouseEvent->modifiers());
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2020-11-14 21:47:55 +01:00
|
|
|
switch (MouseEvent->button())
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
|
|
|
case Qt::LeftButton:
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->OnLeftButtonDown();
|
2013-08-09 06:57:18 +02:00
|
|
|
break;
|
2015-09-06 21:52:17 +02:00
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
case Qt::MidButton:
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->OnMiddleButtonDown();
|
2013-08-09 06:57:18 +02:00
|
|
|
break;
|
2015-09-06 21:52:17 +02:00
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
case Qt::RightButton:
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->OnRightButtonDown();
|
2013-08-09 06:57:18 +02:00
|
|
|
break;
|
2015-09-06 21:52:17 +02:00
|
|
|
|
2015-09-18 07:53:43 +02:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
2015-09-06 21:52:17 +02:00
|
|
|
case Qt::BackButton:
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->OnBackButtonDown();
|
2015-09-06 21:52:17 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::ForwardButton:
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->OnForwardButtonDown();
|
2015-09-06 21:52:17 +02:00
|
|
|
break;
|
2015-09-18 07:53:43 +02:00
|
|
|
#endif
|
2015-09-06 21:52:17 +02:00
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
void lcViewWidget::mouseReleaseEvent(QMouseEvent* MouseEvent)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2020-12-05 17:45:29 +01:00
|
|
|
float DeviceScale = GetDeviceScale();
|
2014-04-06 23:44:58 +02:00
|
|
|
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->SetMousePosition(MouseEvent->x() * DeviceScale, mView->GetHeight() - MouseEvent->y() * DeviceScale - 1);
|
|
|
|
mView->SetMouseModifiers(MouseEvent->modifiers());
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2020-11-14 21:47:55 +01:00
|
|
|
switch (MouseEvent->button())
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
|
|
|
case Qt::LeftButton:
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->OnLeftButtonUp();
|
2013-08-09 06:57:18 +02:00
|
|
|
break;
|
2015-09-06 21:52:17 +02:00
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
case Qt::MidButton:
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->OnMiddleButtonUp();
|
2013-08-09 06:57:18 +02:00
|
|
|
break;
|
2015-09-06 21:52:17 +02:00
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
case Qt::RightButton:
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->OnRightButtonUp();
|
2013-08-09 06:57:18 +02:00
|
|
|
break;
|
2015-09-06 21:52:17 +02:00
|
|
|
|
2015-09-18 07:53:43 +02:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
2015-09-06 21:52:17 +02:00
|
|
|
case Qt::BackButton:
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->OnBackButtonUp();
|
2015-09-06 21:52:17 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::ForwardButton:
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->OnForwardButtonUp();
|
2015-09-06 21:52:17 +02:00
|
|
|
break;
|
2015-09-18 07:53:43 +02:00
|
|
|
#endif
|
2015-09-06 21:52:17 +02:00
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
void lcViewWidget::mouseDoubleClickEvent(QMouseEvent* MouseEvent)
|
2014-04-26 08:23:12 +02:00
|
|
|
{
|
2020-12-05 17:45:29 +01:00
|
|
|
float DeviceScale = GetDeviceScale();
|
2014-04-26 08:23:12 +02:00
|
|
|
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->SetMousePosition(MouseEvent->x() * DeviceScale, mView->GetHeight() - MouseEvent->y() * DeviceScale - 1);
|
|
|
|
mView->SetMouseModifiers(MouseEvent->modifiers());
|
2014-04-26 08:23:12 +02:00
|
|
|
|
2020-11-14 21:47:55 +01:00
|
|
|
switch (MouseEvent->button())
|
2014-04-26 08:23:12 +02:00
|
|
|
{
|
|
|
|
case Qt::LeftButton:
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->OnLeftButtonDoubleClick();
|
2014-04-26 08:23:12 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
void lcViewWidget::mouseMoveEvent(QMouseEvent* MouseEvent)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2020-12-05 17:45:29 +01:00
|
|
|
float DeviceScale = GetDeviceScale();
|
2014-04-06 23:44:58 +02:00
|
|
|
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->SetMousePosition(MouseEvent->x() * DeviceScale, mView->GetHeight() - MouseEvent->y() * DeviceScale - 1);
|
|
|
|
mView->SetMouseModifiers(MouseEvent->modifiers());
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->OnMouseMove();
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
void lcViewWidget::wheelEvent(QWheelEvent* WheelEvent)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2020-12-12 00:49:32 +01:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
|
|
|
|
if (WheelEvent->angleDelta().y() == 0)
|
|
|
|
#else
|
2020-11-14 21:47:55 +01:00
|
|
|
if ((WheelEvent->orientation() & Qt::Vertical) == 0)
|
2020-12-12 00:49:32 +01:00
|
|
|
#endif
|
2015-02-10 23:34:04 +01:00
|
|
|
{
|
2020-11-14 21:47:55 +01:00
|
|
|
WheelEvent->ignore();
|
2015-02-10 23:34:04 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-05 17:45:29 +01:00
|
|
|
float DeviceScale = GetDeviceScale();
|
2014-04-06 23:44:58 +02:00
|
|
|
|
2020-12-12 00:49:32 +01:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->SetMousePosition(WheelEvent->position().x() * DeviceScale, mView->GetHeight() - WheelEvent->position().y() * DeviceScale - 1);
|
2020-12-12 00:49:32 +01:00
|
|
|
#else
|
2020-12-14 01:53:49 +01:00
|
|
|
mView->SetMousePosition(WheelEvent->x() * DeviceScale, mView->GetHeight() - WheelEvent->y() * DeviceScale - 1);
|
2020-12-12 00:49:32 +01:00
|
|
|
#endif
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->SetMouseModifiers(WheelEvent->modifiers());
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2015-02-07 04:08:18 +01:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
|
2020-11-14 21:47:55 +01:00
|
|
|
mWheelAccumulator += WheelEvent->angleDelta().y() / 8;
|
2015-02-07 04:08:18 +01:00
|
|
|
#else
|
2020-11-14 21:53:58 +01:00
|
|
|
mWheelAccumulator += WheelEvent->delta() / 8;
|
2015-02-07 04:08:18 +01:00
|
|
|
#endif
|
2015-02-10 23:34:04 +01:00
|
|
|
int numSteps = mWheelAccumulator / 15;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2015-02-10 23:34:04 +01:00
|
|
|
if (numSteps)
|
|
|
|
{
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->OnMouseWheel(numSteps);
|
2015-02-10 23:34:04 +01:00
|
|
|
mWheelAccumulator -= numSteps * 15;
|
|
|
|
}
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2020-11-14 21:47:55 +01:00
|
|
|
WheelEvent->accept();
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
void lcViewWidget::dragEnterEvent(QDragEnterEvent* DragEnterEvent)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2020-11-14 21:47:55 +01:00
|
|
|
const QMimeData* MimeData = DragEnterEvent->mimeData();
|
|
|
|
|
|
|
|
if (MimeData->hasFormat("application/vnd.leocad-part"))
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2020-11-14 21:47:55 +01:00
|
|
|
DragEnterEvent->acceptProposedAction();
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->BeginDrag(lcDragState::Piece);
|
2020-11-14 21:47:55 +01:00
|
|
|
return;
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
2020-11-14 21:47:55 +01:00
|
|
|
else if (MimeData->hasFormat("application/vnd.leocad-color"))
|
|
|
|
{
|
|
|
|
DragEnterEvent->acceptProposedAction();
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->BeginDrag(lcDragState::Color);
|
2013-08-09 06:57:18 +02:00
|
|
|
return;
|
2020-10-03 12:02:27 +02:00
|
|
|
}
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2020-11-14 21:47:55 +01:00
|
|
|
DragEnterEvent->ignore();
|
|
|
|
}
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
void lcViewWidget::dragLeaveEvent(QDragLeaveEvent* DragLeaveEvent)
|
2020-11-14 21:47:55 +01:00
|
|
|
{
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->EndDrag(false);
|
2020-11-14 21:47:55 +01:00
|
|
|
DragLeaveEvent->accept();
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
void lcViewWidget::dragMoveEvent(QDragMoveEvent* DragMoveEvent)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2020-11-14 21:47:55 +01:00
|
|
|
const QMimeData* MimeData = DragMoveEvent->mimeData();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2020-11-14 21:47:55 +01:00
|
|
|
if (MimeData->hasFormat("application/vnd.leocad-part") || MimeData->hasFormat("application/vnd.leocad-color"))
|
|
|
|
{
|
2020-12-05 17:45:29 +01:00
|
|
|
float DeviceScale = GetDeviceScale();
|
2014-04-08 03:04:32 +02:00
|
|
|
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->SetMousePosition(DragMoveEvent->pos().x() * DeviceScale, mView->GetHeight() - DragMoveEvent->pos().y() * DeviceScale - 1);
|
|
|
|
mView->SetMouseModifiers(DragMoveEvent->keyboardModifiers());
|
2014-05-27 00:58:08 +02:00
|
|
|
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->OnMouseMove();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2020-11-14 21:47:55 +01:00
|
|
|
DragMoveEvent->accept();
|
|
|
|
return;
|
2018-01-12 19:50:25 +01:00
|
|
|
}
|
|
|
|
|
2020-12-27 22:05:55 +01:00
|
|
|
lcViewWidgetParent::dragMoveEvent(DragMoveEvent);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 02:59:11 +01:00
|
|
|
void lcViewWidget::dropEvent(QDropEvent* DropEvent)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2020-11-14 21:47:55 +01:00
|
|
|
const QMimeData* MimeData = DropEvent->mimeData();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2020-11-14 21:47:55 +01:00
|
|
|
if (MimeData->hasFormat("application/vnd.leocad-part") || MimeData->hasFormat("application/vnd.leocad-color"))
|
|
|
|
{
|
2020-12-13 21:05:54 +01:00
|
|
|
mView->EndDrag(true);
|
2020-11-14 21:47:55 +01:00
|
|
|
setFocus(Qt::MouseFocusReason);
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2020-11-14 21:47:55 +01:00
|
|
|
DropEvent->accept();
|
|
|
|
return;
|
2018-01-12 19:50:25 +01:00
|
|
|
}
|
|
|
|
|
2020-12-27 22:05:55 +01:00
|
|
|
lcViewWidgetParent::dropEvent(DropEvent);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|