3D Preview - refactor and enable on property tree

This commit is contained in:
Trevor SANDY 2020-10-07 12:07:32 +02:00
parent 506b7a175f
commit 11966ca428
8 changed files with 175 additions and 150 deletions

View file

@ -686,84 +686,42 @@ void lcPartSelectionListView::startDrag(Qt::DropActions SupportedActions)
void lcPartSelectionListView::mouseDoubleClickEvent(QMouseEvent *event)
{
QAbstractItemView::mouseDoubleClickEvent(event);
if ( event->button() == Qt::LeftButton ) {
if ( event->button() == Qt::LeftButton )
{
PreviewSelection(currentIndex().row());
}
}
}
void lcPartSelectionListView::PreviewSelection(int InfoIndex)
{
lcPreferences& Preferences = lcGetPreferences();
if (!Preferences.mPreviewEnabled)
return;
PieceInfo* Info = mListModel->GetPieceInfo(InfoIndex);
if (!Info)
return;
bool IsSubfile = Info->IsModel();
QString PartType = Info->mFileName;
quint32 ColorCode = IsSubfile ? 16 : lcGetColorCode(mListModel->GetColorIndex());
const lcPreferences& Preferences = lcGetPreferences();
quint32 ColorCode = lcGetColorCode(mListModel->GetColorIndex());
if (Preferences.mPreviewPosition != lcPreviewPosition::Floating) {
emit gMainWindow->PreviewPiece(PartType, ColorCode);
if (Preferences.mPreviewPosition != lcPreviewPosition::Floating)
{
gMainWindow->PreviewPiece(Info->mFileName, ColorCode);
return;
}
if (!Preferences.mPreviewEnabled)
return;
lcPreviewWidget* Preview = new lcPreviewWidget();
QString TypeLabel = IsSubfile ? "Submodel" : "Part";
QString WindowTitle = QString("%1 Preview").arg(TypeLabel);
lcQGLWidget* ViewWidget = new lcQGLWidget(nullptr, Preview, true/*isView*/, true/*isPreview*/);
lcPreviewWidget *Preview = new lcPreviewWidget();
lcQGLWidget *ViewWidget = new lcQGLWidget(nullptr, Preview, true/*isView*/, true/*isPreview*/);
if (Preview && ViewWidget) {
if (!Preview->SetCurrentPiece(PartType, ColorCode))
if (Preview && ViewWidget)
{
if (!Preview->SetCurrentPiece(Info->mFileName, ColorCode))
QMessageBox::critical(gMainWindow, tr("Error"), tr("Preview %1 failed.").arg(Info->mFileName));
ViewWidget->setWindowTitle(WindowTitle);
int Size[2] = { 300,200 };
if (Preferences.mPreviewSize == 400) {
Size[0] = 400; Size[1] = 300;
}
ViewWidget->preferredSize = QSize(Size[0], Size[1]);
float Scale = ViewWidget->deviceScale();
Preview->mWidth = ViewWidget->width() * Scale;
Preview->mHeight = ViewWidget->height() * Scale;
const QRect desktop = QApplication::desktop()->geometry();
QPoint pos;
switch (Preferences.mPreviewLocation)
{
case lcPreviewLocation::TopRight:
pos = mapToGlobal(rect().topRight());
break;
case lcPreviewLocation::TopLeft:
pos = mapToGlobal(rect().topLeft());
break;
case lcPreviewLocation::BottomRight:
pos = mapToGlobal(rect().bottomRight());
break;
default:
pos = mapToGlobal(rect().bottomLeft());
break;
}
if (pos.x() < desktop.left())
pos.setX(desktop.left());
if (pos.y() < desktop.top())
pos.setY(desktop.top());
if ((pos.x() + ViewWidget->width()) > desktop.width())
pos.setX(desktop.width() - ViewWidget->width());
if ((pos.y() + ViewWidget->height()) > desktop.bottom())
pos.setY(desktop.bottom() - ViewWidget->height());
ViewWidget->move(pos);
ViewWidget->setMinimumSize(100,100);
ViewWidget->show();
ViewWidget->setFocus();
} else {
}
else
{
QMessageBox::critical(gMainWindow, tr("Error"), tr("Preview %1 failed.").arg(Info->mFileName));
}
}

View file

@ -16,23 +16,24 @@ lcPreviewWidget* gPreviewWidget;
lcPreviewDockWidget::lcPreviewDockWidget(QMainWindow* Parent)
: QMainWindow(Parent)
{
Preview = new lcPreviewWidget();
ViewWidget = new lcQGLWidget(nullptr, Preview, true/*IsView*/, true/*IsPreview*/);
setCentralWidget(ViewWidget);
mPreview = new lcPreviewWidget();
mViewWidget = new lcQGLWidget(nullptr, mPreview, true/*IsView*/, true/*IsPreview*/);
setCentralWidget(mViewWidget);
setMinimumSize(200, 200);
ToolBar = addToolBar(tr("PreviewDescription"));
ToolBar->setObjectName("PreviewDescription");
ToolBar->setMovable(false);
Label = new QLabel(QString());
ToolBar->addWidget(Label);
mToolBar = addToolBar(tr("PreviewDescription"));
mToolBar->setObjectName("PreviewDescription");
mToolBar->setMovable(false);
mLabel = new QLabel(QString());
mToolBar->addWidget(mLabel);
}
bool lcPreviewDockWidget::SetCurrentPiece(const QString& PartType, int ColorCode)
{
Label->setText("Loading...");
if (Preview->SetCurrentPiece(PartType, ColorCode))
mLabel->setText(tr("Loading..."));
if (mPreview->SetCurrentPiece(PartType, ColorCode))
{
Label->setText(Preview->GetDescription());
mLabel->setText(mPreview->GetDescription());
return true;
}
return false;
@ -40,8 +41,8 @@ bool lcPreviewDockWidget::SetCurrentPiece(const QString& PartType, int ColorCode
void lcPreviewDockWidget::ClearPreview()
{
Preview->ClearPreview();
Label->setText(QString());
mPreview->ClearPreview();
mLabel->setText(QString());
}
lcPreviewWidget::lcPreviewWidget()
@ -74,6 +75,7 @@ bool lcPreviewWidget::SetCurrentPiece(const QString& PartType, int ColorCode)
if (Info)
{
mIsModel = Info->IsModel();
mDescription = Info->m_strDescription;
lcModel* ActiveModel = GetActiveModel();
@ -109,6 +111,7 @@ bool lcPreviewWidget::SetCurrentPiece(const QString& PartType, int ColorCode)
mDescription = mModel->GetProperties().mDescription;
else
mDescription = PartType;
mIsModel = true;
}
ZoomExtents();
@ -272,14 +275,12 @@ void lcPreviewWidget::DrawAxes()
glEnable(GL_BLEND);
float TextBuffer[6 * 5 * 3];
/*** Native viewer camera globe mod, switch Y and Z axis with -Y(LC -Z) in the up direction ***/
lcVector3 PosX = lcMul30(lcVector3(25.0f, 0.0f, 0.0f), WorldViewMatrix);
gTexFont.GetGlyphTriangles(PosX.x, PosX.y, PosX.z, 'X', TextBuffer);
lcVector3 PosY = lcMul30(lcVector3(0.0f, 25.0f, 0.0f), WorldViewMatrix);
gTexFont.GetGlyphTriangles(PosY.x, PosY.y, PosY.z, 'Z', TextBuffer + 5 * 6);
gTexFont.GetGlyphTriangles(PosY.x, PosY.y, PosY.z, 'Y', TextBuffer + 5 * 6);
lcVector3 PosZ = lcMul30(lcVector3(0.0f, 0.0f, 25.0f), WorldViewMatrix);
gTexFont.GetGlyphTriangles(PosZ.x, PosZ.y, PosZ.z, 'Y', TextBuffer + 5 * 6 * 2);
/*** Camera globe mod end ***/
gTexFont.GetGlyphTriangles(PosZ.x, PosZ.y, PosZ.z, 'Z', TextBuffer + 5 * 6 * 2);
mContext->SetVertexBufferPointer(TextBuffer);
mContext->SetVertexFormat(0, 3, 0, 2, 0, false);
@ -625,4 +626,4 @@ void lcPreviewWidget::OnMouseWheel(float Direction)
{
mModel->Zoom(mCamera, (int)(((mInputState.Modifiers & Qt::ControlModifier) ? 100 : 10) * Direction));
Redraw();
}
}

View file

@ -21,15 +21,15 @@ class lcPreviewDockWidget : public QMainWindow
Q_OBJECT
public:
explicit lcPreviewDockWidget(QMainWindow *parent = nullptr);
bool SetCurrentPiece(const QString &PartType, int ColorCode);
explicit lcPreviewDockWidget(QMainWindow* parent = nullptr);
bool SetCurrentPiece(const QString& PartType, int ColorCode);
void ClearPreview();
protected:
QToolBar *ToolBar;
QLabel *Label;
lcPreviewWidget *Preview;
lcQGLWidget *ViewWidget;
QToolBar* mToolBar;
QLabel* mLabel;
lcPreviewWidget* mPreview;
lcQGLWidget* mViewWidget;
};
class lcPreviewWidget : public lcGLWidget
@ -98,6 +98,11 @@ public:
return mTrackButton != lcTrackButton::None;
}
bool IsModel() const
{
return mIsModel;
}
void OnInitialUpdate() override;
void OnDraw() override;
void OnUpdateCursor() override;
@ -132,10 +137,11 @@ protected:
lcTrackTool mTrackTool;
QString mDescription;
bool mIsModel;
bool mTrackUpdated;
int mMouseDownX;
int mMouseDownY;
};
extern lcPreviewWidget* gPreviewWidget;
extern lcPreviewWidget* gPreviewWidget;

View file

@ -513,7 +513,8 @@ void lcTimelineWidget::mousePressEvent(QMouseEvent* Event)
void lcTimelineWidget::mouseDoubleClickEvent(QMouseEvent *event)
{
QTreeWidget::mouseDoubleClickEvent(event);
if ( event->button() == Qt::LeftButton ) {
if ( event->button() == Qt::LeftButton )
{
QTreeWidgetItem* CurrentItem = currentItem();
PreviewSelection(CurrentItem);
}
@ -521,6 +522,10 @@ void lcTimelineWidget::mouseDoubleClickEvent(QMouseEvent *event)
void lcTimelineWidget::PreviewSelection(QTreeWidgetItem* Current)
{
lcPreferences& Preferences = lcGetPreferences();
if (!Preferences.mPreviewEnabled)
return;
lcPiece* Piece = (lcPiece*)Current->data(0, Qt::UserRole).value<uintptr_t>();
if (!Piece)
return;
@ -529,73 +534,24 @@ void lcTimelineWidget::PreviewSelection(QTreeWidgetItem* Current)
if (!Info)
return;
bool IsSubfile = Info->IsModel();
QString PartType = Info->mFileName;
quint32 ColorCode = IsSubfile ? 16 : Piece->mColorCode;
const lcPreferences& Preferences = lcGetPreferences();
if (Preferences.mPreviewPosition != lcPreviewPosition::Floating) {
emit gMainWindow->PreviewPiece(PartType, ColorCode);
if (Preferences.mPreviewPosition != lcPreviewPosition::Floating)
{
gMainWindow->PreviewPiece(Info->mFileName, Piece->mColorCode);
return;
}
if (!Preferences.mPreviewEnabled)
return;
QString TypeLabel = IsSubfile ? "Submodel" : "Part";
QString WindowTitle = QString("%1 Preview").arg(TypeLabel);
lcPreviewWidget *Preview = new lcPreviewWidget();
lcQGLWidget *ViewWidget = new lcQGLWidget(nullptr, Preview, true/*isView*/, true/*isPreview*/);
lcQGLWidget *ViewWidget = new lcQGLWidget(nullptr, Preview, true/*isView*/, true/*isPreview*/);
if (Preview && ViewWidget) {
if (!Preview->SetCurrentPiece(PartType, ColorCode))
QMessageBox::critical(gMainWindow, tr("Error"), tr("Part preview for %1 failed.").arg(PartType));
ViewWidget->setWindowTitle(WindowTitle);
int Size[2] = { 300,200 };
if (Preferences.mPreviewSize == 400) {
Size[0] = 400; Size[1] = 300;
}
ViewWidget->preferredSize = QSize(Size[0], Size[1]);
float Scale = ViewWidget->deviceScale();
Preview->mWidth = ViewWidget->width() * Scale;
Preview->mHeight = ViewWidget->height() * Scale;
const QRect desktop = QApplication::desktop()->geometry();
QPoint pos;
switch (Preferences.mPreviewLocation)
{
case lcPreviewLocation::TopRight:
pos = mapToGlobal(rect().topRight());
break;
case lcPreviewLocation::TopLeft:
pos = mapToGlobal(rect().topLeft());
break;
case lcPreviewLocation::BottomRight:
pos = mapToGlobal(rect().bottomRight());
break;
default:
pos = mapToGlobal(rect().bottomLeft());
break;
}
if (pos.x() < desktop.left())
pos.setX(desktop.left());
if (pos.y() < desktop.top())
pos.setY(desktop.top());
if ((pos.x() + ViewWidget->width()) > desktop.width())
pos.setX(desktop.width() - ViewWidget->width());
if ((pos.y() + ViewWidget->height()) > desktop.bottom())
pos.setY(desktop.bottom() - ViewWidget->height());
ViewWidget->move(pos);
ViewWidget->setMinimumSize(100,100);
ViewWidget->show();
ViewWidget->setFocus();
} else {
if (Preview && ViewWidget)
{
if (!Preview->SetCurrentPiece(Info->mFileName, Piece->mColorCode))
QMessageBox::critical(gMainWindow, tr("Error"), tr("Part preview for %1 failed.").arg(Info->mFileName));
ViewWidget->SetPreviewPosition(rect());
}
else
{
QMessageBox::critical(gMainWindow, tr("Error"), tr("Preview %1 failed.").arg(Info->mFileName));
}
}

View file

@ -16,6 +16,8 @@
#include "lc_mesh.h"
#include "lc_profile.h"
#include "lc_previewwidget.h"
static QList<QGLWidget*> gWidgetList;
void lcGLWidget::MakeCurrent()
@ -166,6 +168,58 @@ QSize lcQGLWidget::sizeHint() const
return preferredSize;
}
void lcQGLWidget::SetPreviewPosition(const QRect& ParentRect)
{
lcPreferences& Preferences = lcGetPreferences();
lcPreviewWidget* Preview = reinterpret_cast<lcPreviewWidget*>(widget);
setWindowTitle(tr("%1 Preview").arg(Preview->IsModel() ? "Submodel" : "Part"));
int Size[2] = { 300,200 };
if (Preferences.mPreviewSize == 400)
{
Size[0] = 400; Size[1] = 300;
}
preferredSize = QSize(Size[0], Size[1]);
float Scale = deviceScale();
Preview->mWidth = width() * Scale;
Preview->mHeight = height() * Scale;
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;
}
if (pos.x() < desktop.left())
pos.setX(desktop.left());
if (pos.y() < desktop.top())
pos.setY(desktop.top());
if ((pos.x() + width()) > desktop.width())
pos.setX(desktop.width() - width());
if ((pos.y() + height()) > desktop.bottom())
pos.setY(desktop.bottom() - height());
move(pos);
setMinimumSize(100,100);
show();
setFocus();
}
void lcQGLWidget::initializeGL()
{
glEnable(GL_DEPTH_TEST);

View file

@ -25,6 +25,8 @@ public:
#endif
}
void SetPreviewPosition(const QRect& ParentRect);
QTimer mUpdateTimer;
protected:

View file

@ -12,6 +12,9 @@
#include "lc_library.h"
#include "lc_qutils.h"
#include "lc_qglwidget.h"
#include "lc_previewwidget.h"
// Draw an icon indicating opened/closing branches
static QIcon drawIndicatorIcon(const QPalette &palette, QStyle *style)
{
@ -761,7 +764,19 @@ void lcQPropertiesTree::slotSetValue(int Value)
{
QComboBox *editor = (QComboBox*)sender();
Model->SetSelectedPiecesPieceInfo((PieceInfo*)editor->itemData(Value).value<void*>());
PieceInfo* Info = (PieceInfo*)editor->itemData(Value).value<void*>();
Model->SetSelectedPiecesPieceInfo(Info);
lcPreferences& Preferences = lcGetPreferences();
if (Preferences.mPreviewEnabled && Preferences.mPreviewPosition != lcPreviewPosition::Floating)
{
int ColorIndex = gDefaultColor;
lcObject* Focus = gMainWindow->GetActiveModel()->GetFocusObject();
if (Focus && Focus->IsPiece())
ColorIndex = ((lcPiece*)Focus)->mColorIndex;
quint32 ColorCode = lcGetColorCode(ColorIndex);
PreviewSelection(Info->mFileName, ColorCode);
}
}
}
}
@ -924,6 +939,12 @@ void lcQPropertiesTree::SetPiece(const lcArray<lcObject*>& Selection, lcObject*
Hide = Piece->GetStepHide();
ColorIndex = Piece->mColorIndex;
Info = Piece->mPieceInfo;
lcPreferences& Preferences = lcGetPreferences();
if (Preferences.mPreviewEnabled)
{
quint32 ColorCode = lcGetColorCode(ColorIndex);
PreviewSelection(Info->mFileName, ColorCode);
}
}
else
{
@ -1108,3 +1129,28 @@ bool lcQPropertiesTree::lastColumn(int column) const
{
return header()->visualIndex(column) == columnCount() - 1;
}
void lcQPropertiesTree::PreviewSelection(const QString &PartType, int ColorCode)
{
lcPreferences& Preferences = lcGetPreferences();
if (Preferences.mPreviewPosition != lcPreviewPosition::Floating)
{
gMainWindow->PreviewPiece(PartType, ColorCode);
return;
}
lcPreviewWidget *Preview = new lcPreviewWidget();
lcQGLWidget *ViewWidget = new lcQGLWidget(nullptr, Preview, true/*isView*/, true/*isPreview*/);
if (Preview && ViewWidget)
{
if (!Preview->SetCurrentPiece(PartType, ColorCode))
QMessageBox::critical(gMainWindow, tr("Error"), tr("Part preview for %1 failed.").arg(PartType));
ViewWidget->SetPreviewPosition(rect());
}
else
{
QMessageBox::critical(gMainWindow, tr("Error"), tr("Preview %1 failed.").arg(PartType));
}
}

View file

@ -72,6 +72,8 @@ protected:
void getPartProperties(lcPartProperties *properties);
void PreviewSelection(const QString& PartType, int ColorCode);
lcPropertyWidgetMode mWidgetMode;
lcObject* mFocus;