mirror of
https://github.com/leozide/leocad
synced 2025-01-18 22:26:44 +01:00
3D Preview - refactor and enable on property tree
This commit is contained in:
parent
506b7a175f
commit
11966ca428
8 changed files with 175 additions and 150 deletions
|
@ -686,84 +686,42 @@ void lcPartSelectionListView::startDrag(Qt::DropActions SupportedActions)
|
||||||
void lcPartSelectionListView::mouseDoubleClickEvent(QMouseEvent *event)
|
void lcPartSelectionListView::mouseDoubleClickEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
QAbstractItemView::mouseDoubleClickEvent(event);
|
QAbstractItemView::mouseDoubleClickEvent(event);
|
||||||
if ( event->button() == Qt::LeftButton ) {
|
if ( event->button() == Qt::LeftButton )
|
||||||
|
{
|
||||||
PreviewSelection(currentIndex().row());
|
PreviewSelection(currentIndex().row());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcPartSelectionListView::PreviewSelection(int InfoIndex)
|
void lcPartSelectionListView::PreviewSelection(int InfoIndex)
|
||||||
{
|
{
|
||||||
|
lcPreferences& Preferences = lcGetPreferences();
|
||||||
|
if (!Preferences.mPreviewEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
PieceInfo* Info = mListModel->GetPieceInfo(InfoIndex);
|
PieceInfo* Info = mListModel->GetPieceInfo(InfoIndex);
|
||||||
if (!Info)
|
if (!Info)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool IsSubfile = Info->IsModel();
|
quint32 ColorCode = lcGetColorCode(mListModel->GetColorIndex());
|
||||||
QString PartType = Info->mFileName;
|
|
||||||
quint32 ColorCode = IsSubfile ? 16 : lcGetColorCode(mListModel->GetColorIndex());
|
|
||||||
const lcPreferences& Preferences = lcGetPreferences();
|
|
||||||
|
|
||||||
if (Preferences.mPreviewPosition != lcPreviewPosition::Floating) {
|
if (Preferences.mPreviewPosition != lcPreviewPosition::Floating)
|
||||||
emit gMainWindow->PreviewPiece(PartType, ColorCode);
|
{
|
||||||
|
gMainWindow->PreviewPiece(Info->mFileName, ColorCode);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Preferences.mPreviewEnabled)
|
|
||||||
return;
|
|
||||||
|
|
||||||
QString TypeLabel = IsSubfile ? "Submodel" : "Part";
|
|
||||||
QString WindowTitle = QString("%1 Preview").arg(TypeLabel);
|
|
||||||
|
|
||||||
lcPreviewWidget* Preview = new lcPreviewWidget();
|
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 && ViewWidget)
|
||||||
if (!Preview->SetCurrentPiece(PartType, ColorCode))
|
{
|
||||||
|
if (!Preview->SetCurrentPiece(Info->mFileName, ColorCode))
|
||||||
QMessageBox::critical(gMainWindow, tr("Error"), tr("Preview %1 failed.").arg(Info->mFileName));
|
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]);
|
else
|
||||||
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 {
|
|
||||||
QMessageBox::critical(gMainWindow, tr("Error"), tr("Preview %1 failed.").arg(Info->mFileName));
|
QMessageBox::critical(gMainWindow, tr("Error"), tr("Preview %1 failed.").arg(Info->mFileName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,23 +16,24 @@ lcPreviewWidget* gPreviewWidget;
|
||||||
lcPreviewDockWidget::lcPreviewDockWidget(QMainWindow* Parent)
|
lcPreviewDockWidget::lcPreviewDockWidget(QMainWindow* Parent)
|
||||||
: QMainWindow(Parent)
|
: QMainWindow(Parent)
|
||||||
{
|
{
|
||||||
Preview = new lcPreviewWidget();
|
mPreview = new lcPreviewWidget();
|
||||||
ViewWidget = new lcQGLWidget(nullptr, Preview, true/*IsView*/, true/*IsPreview*/);
|
mViewWidget = new lcQGLWidget(nullptr, mPreview, true/*IsView*/, true/*IsPreview*/);
|
||||||
setCentralWidget(ViewWidget);
|
setCentralWidget(mViewWidget);
|
||||||
setMinimumSize(200, 200);
|
setMinimumSize(200, 200);
|
||||||
ToolBar = addToolBar(tr("PreviewDescription"));
|
|
||||||
ToolBar->setObjectName("PreviewDescription");
|
mToolBar = addToolBar(tr("PreviewDescription"));
|
||||||
ToolBar->setMovable(false);
|
mToolBar->setObjectName("PreviewDescription");
|
||||||
Label = new QLabel(QString());
|
mToolBar->setMovable(false);
|
||||||
ToolBar->addWidget(Label);
|
mLabel = new QLabel(QString());
|
||||||
|
mToolBar->addWidget(mLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lcPreviewDockWidget::SetCurrentPiece(const QString& PartType, int ColorCode)
|
bool lcPreviewDockWidget::SetCurrentPiece(const QString& PartType, int ColorCode)
|
||||||
{
|
{
|
||||||
Label->setText("Loading...");
|
mLabel->setText(tr("Loading..."));
|
||||||
if (Preview->SetCurrentPiece(PartType, ColorCode))
|
if (mPreview->SetCurrentPiece(PartType, ColorCode))
|
||||||
{
|
{
|
||||||
Label->setText(Preview->GetDescription());
|
mLabel->setText(mPreview->GetDescription());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -40,8 +41,8 @@ bool lcPreviewDockWidget::SetCurrentPiece(const QString& PartType, int ColorCode
|
||||||
|
|
||||||
void lcPreviewDockWidget::ClearPreview()
|
void lcPreviewDockWidget::ClearPreview()
|
||||||
{
|
{
|
||||||
Preview->ClearPreview();
|
mPreview->ClearPreview();
|
||||||
Label->setText(QString());
|
mLabel->setText(QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
lcPreviewWidget::lcPreviewWidget()
|
lcPreviewWidget::lcPreviewWidget()
|
||||||
|
@ -74,6 +75,7 @@ bool lcPreviewWidget::SetCurrentPiece(const QString& PartType, int ColorCode)
|
||||||
|
|
||||||
if (Info)
|
if (Info)
|
||||||
{
|
{
|
||||||
|
mIsModel = Info->IsModel();
|
||||||
mDescription = Info->m_strDescription;
|
mDescription = Info->m_strDescription;
|
||||||
lcModel* ActiveModel = GetActiveModel();
|
lcModel* ActiveModel = GetActiveModel();
|
||||||
|
|
||||||
|
@ -109,6 +111,7 @@ bool lcPreviewWidget::SetCurrentPiece(const QString& PartType, int ColorCode)
|
||||||
mDescription = mModel->GetProperties().mDescription;
|
mDescription = mModel->GetProperties().mDescription;
|
||||||
else
|
else
|
||||||
mDescription = PartType;
|
mDescription = PartType;
|
||||||
|
mIsModel = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZoomExtents();
|
ZoomExtents();
|
||||||
|
@ -272,14 +275,12 @@ void lcPreviewWidget::DrawAxes()
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
|
|
||||||
float TextBuffer[6 * 5 * 3];
|
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);
|
lcVector3 PosX = lcMul30(lcVector3(25.0f, 0.0f, 0.0f), WorldViewMatrix);
|
||||||
gTexFont.GetGlyphTriangles(PosX.x, PosX.y, PosX.z, 'X', TextBuffer);
|
gTexFont.GetGlyphTriangles(PosX.x, PosX.y, PosX.z, 'X', TextBuffer);
|
||||||
lcVector3 PosY = lcMul30(lcVector3(0.0f, 25.0f, 0.0f), WorldViewMatrix);
|
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);
|
lcVector3 PosZ = lcMul30(lcVector3(0.0f, 0.0f, 25.0f), WorldViewMatrix);
|
||||||
gTexFont.GetGlyphTriangles(PosZ.x, PosZ.y, PosZ.z, 'Y', TextBuffer + 5 * 6 * 2);
|
gTexFont.GetGlyphTriangles(PosZ.x, PosZ.y, PosZ.z, 'Z', TextBuffer + 5 * 6 * 2);
|
||||||
/*** Camera globe mod end ***/
|
|
||||||
|
|
||||||
mContext->SetVertexBufferPointer(TextBuffer);
|
mContext->SetVertexBufferPointer(TextBuffer);
|
||||||
mContext->SetVertexFormat(0, 3, 0, 2, 0, false);
|
mContext->SetVertexFormat(0, 3, 0, 2, 0, false);
|
||||||
|
|
|
@ -26,10 +26,10 @@ public:
|
||||||
void ClearPreview();
|
void ClearPreview();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QToolBar *ToolBar;
|
QToolBar* mToolBar;
|
||||||
QLabel *Label;
|
QLabel* mLabel;
|
||||||
lcPreviewWidget *Preview;
|
lcPreviewWidget* mPreview;
|
||||||
lcQGLWidget *ViewWidget;
|
lcQGLWidget* mViewWidget;
|
||||||
};
|
};
|
||||||
|
|
||||||
class lcPreviewWidget : public lcGLWidget
|
class lcPreviewWidget : public lcGLWidget
|
||||||
|
@ -98,6 +98,11 @@ public:
|
||||||
return mTrackButton != lcTrackButton::None;
|
return mTrackButton != lcTrackButton::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsModel() const
|
||||||
|
{
|
||||||
|
return mIsModel;
|
||||||
|
}
|
||||||
|
|
||||||
void OnInitialUpdate() override;
|
void OnInitialUpdate() override;
|
||||||
void OnDraw() override;
|
void OnDraw() override;
|
||||||
void OnUpdateCursor() override;
|
void OnUpdateCursor() override;
|
||||||
|
@ -132,6 +137,7 @@ protected:
|
||||||
lcTrackTool mTrackTool;
|
lcTrackTool mTrackTool;
|
||||||
|
|
||||||
QString mDescription;
|
QString mDescription;
|
||||||
|
bool mIsModel;
|
||||||
|
|
||||||
bool mTrackUpdated;
|
bool mTrackUpdated;
|
||||||
int mMouseDownX;
|
int mMouseDownX;
|
||||||
|
|
|
@ -513,7 +513,8 @@ void lcTimelineWidget::mousePressEvent(QMouseEvent* Event)
|
||||||
void lcTimelineWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
void lcTimelineWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
QTreeWidget::mouseDoubleClickEvent(event);
|
QTreeWidget::mouseDoubleClickEvent(event);
|
||||||
if ( event->button() == Qt::LeftButton ) {
|
if ( event->button() == Qt::LeftButton )
|
||||||
|
{
|
||||||
QTreeWidgetItem* CurrentItem = currentItem();
|
QTreeWidgetItem* CurrentItem = currentItem();
|
||||||
PreviewSelection(CurrentItem);
|
PreviewSelection(CurrentItem);
|
||||||
}
|
}
|
||||||
|
@ -521,6 +522,10 @@ void lcTimelineWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
||||||
|
|
||||||
void lcTimelineWidget::PreviewSelection(QTreeWidgetItem* Current)
|
void lcTimelineWidget::PreviewSelection(QTreeWidgetItem* Current)
|
||||||
{
|
{
|
||||||
|
lcPreferences& Preferences = lcGetPreferences();
|
||||||
|
if (!Preferences.mPreviewEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
lcPiece* Piece = (lcPiece*)Current->data(0, Qt::UserRole).value<uintptr_t>();
|
lcPiece* Piece = (lcPiece*)Current->data(0, Qt::UserRole).value<uintptr_t>();
|
||||||
if (!Piece)
|
if (!Piece)
|
||||||
return;
|
return;
|
||||||
|
@ -529,73 +534,24 @@ void lcTimelineWidget::PreviewSelection(QTreeWidgetItem* Current)
|
||||||
if (!Info)
|
if (!Info)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool IsSubfile = Info->IsModel();
|
if (Preferences.mPreviewPosition != lcPreviewPosition::Floating)
|
||||||
QString PartType = Info->mFileName;
|
{
|
||||||
quint32 ColorCode = IsSubfile ? 16 : Piece->mColorCode;
|
gMainWindow->PreviewPiece(Info->mFileName, Piece->mColorCode);
|
||||||
const lcPreferences& Preferences = lcGetPreferences();
|
|
||||||
|
|
||||||
if (Preferences.mPreviewPosition != lcPreviewPosition::Floating) {
|
|
||||||
emit gMainWindow->PreviewPiece(PartType, ColorCode);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Preferences.mPreviewEnabled)
|
|
||||||
return;
|
|
||||||
|
|
||||||
QString TypeLabel = IsSubfile ? "Submodel" : "Part";
|
|
||||||
QString WindowTitle = QString("%1 Preview").arg(TypeLabel);
|
|
||||||
|
|
||||||
lcPreviewWidget *Preview = new lcPreviewWidget();
|
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 && 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:
|
if (!Preview->SetCurrentPiece(Info->mFileName, Piece->mColorCode))
|
||||||
pos = mapToGlobal(rect().topRight());
|
QMessageBox::critical(gMainWindow, tr("Error"), tr("Part preview for %1 failed.").arg(Info->mFileName));
|
||||||
break;
|
ViewWidget->SetPreviewPosition(rect());
|
||||||
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())
|
else
|
||||||
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 {
|
|
||||||
QMessageBox::critical(gMainWindow, tr("Error"), tr("Preview %1 failed.").arg(Info->mFileName));
|
QMessageBox::critical(gMainWindow, tr("Error"), tr("Preview %1 failed.").arg(Info->mFileName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
#include "lc_mesh.h"
|
#include "lc_mesh.h"
|
||||||
#include "lc_profile.h"
|
#include "lc_profile.h"
|
||||||
|
|
||||||
|
#include "lc_previewwidget.h"
|
||||||
|
|
||||||
static QList<QGLWidget*> gWidgetList;
|
static QList<QGLWidget*> gWidgetList;
|
||||||
|
|
||||||
void lcGLWidget::MakeCurrent()
|
void lcGLWidget::MakeCurrent()
|
||||||
|
@ -166,6 +168,58 @@ QSize lcQGLWidget::sizeHint() const
|
||||||
return preferredSize;
|
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()
|
void lcQGLWidget::initializeGL()
|
||||||
{
|
{
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
|
@ -25,6 +25,8 @@ public:
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetPreviewPosition(const QRect& ParentRect);
|
||||||
|
|
||||||
QTimer mUpdateTimer;
|
QTimer mUpdateTimer;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
#include "lc_library.h"
|
#include "lc_library.h"
|
||||||
#include "lc_qutils.h"
|
#include "lc_qutils.h"
|
||||||
|
|
||||||
|
#include "lc_qglwidget.h"
|
||||||
|
#include "lc_previewwidget.h"
|
||||||
|
|
||||||
// Draw an icon indicating opened/closing branches
|
// Draw an icon indicating opened/closing branches
|
||||||
static QIcon drawIndicatorIcon(const QPalette &palette, QStyle *style)
|
static QIcon drawIndicatorIcon(const QPalette &palette, QStyle *style)
|
||||||
{
|
{
|
||||||
|
@ -761,7 +764,19 @@ void lcQPropertiesTree::slotSetValue(int Value)
|
||||||
{
|
{
|
||||||
QComboBox *editor = (QComboBox*)sender();
|
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();
|
Hide = Piece->GetStepHide();
|
||||||
ColorIndex = Piece->mColorIndex;
|
ColorIndex = Piece->mColorIndex;
|
||||||
Info = Piece->mPieceInfo;
|
Info = Piece->mPieceInfo;
|
||||||
|
lcPreferences& Preferences = lcGetPreferences();
|
||||||
|
if (Preferences.mPreviewEnabled)
|
||||||
|
{
|
||||||
|
quint32 ColorCode = lcGetColorCode(ColorIndex);
|
||||||
|
PreviewSelection(Info->mFileName, ColorCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1108,3 +1129,28 @@ bool lcQPropertiesTree::lastColumn(int column) const
|
||||||
{
|
{
|
||||||
return header()->visualIndex(column) == columnCount() - 1;
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -72,6 +72,8 @@ protected:
|
||||||
|
|
||||||
void getPartProperties(lcPartProperties *properties);
|
void getPartProperties(lcPartProperties *properties);
|
||||||
|
|
||||||
|
void PreviewSelection(const QString& PartType, int ColorCode);
|
||||||
|
|
||||||
lcPropertyWidgetMode mWidgetMode;
|
lcPropertyWidgetMode mWidgetMode;
|
||||||
lcObject* mFocus;
|
lcObject* mFocus;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue