3D Preview

3D Preview - restore doc format
This commit is contained in:
Trevor SANDY
2020-10-03 12:02:27 +02:00
parent 8223b61a24
commit a239e504ec
24 changed files with 1811 additions and 305 deletions
+93
View File
@@ -5,6 +5,9 @@
#include "pieceinf.h"
#include "lc_mainwindow.h"
#include "lc_qglwidget.h"
#include "lc_previewwidget.h"
lcTimelineWidget::lcTimelineWidget(QWidget* Parent)
: QTreeWidget(Parent)
{
@@ -507,6 +510,96 @@ void lcTimelineWidget::mousePressEvent(QMouseEvent* Event)
QTreeWidget::mousePressEvent(Event);
}
void lcTimelineWidget::mouseDoubleClickEvent(QMouseEvent *event)
{
QTreeWidget::mouseDoubleClickEvent(event);
if ( event->button() == Qt::LeftButton ) {
QTreeWidgetItem* CurrentItem = currentItem();
PreviewSelection(CurrentItem);
}
}
void lcTimelineWidget::PreviewSelection(QTreeWidgetItem* Current)
{
lcPiece* Piece = (lcPiece*)Current->data(0, Qt::UserRole).value<uintptr_t>();
if (!Piece)
return;
PieceInfo* Info = Piece->mPieceInfo;
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);
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*/);
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 {
QMessageBox::critical(gMainWindow, tr("Error"), tr("Preview %1 failed.").arg(Info->mFileName));
}
}
void lcTimelineWidget::UpdateModel()
{
QList<QPair<lcPiece*, lcStep>> PieceSteps;