3D Preview - refactor and enable on property tree

This commit is contained in:
Trevor SANDY
2020-10-07 15:44:14 +02:00
parent 506b7a175f
commit 11966ca428
8 changed files with 175 additions and 150 deletions
+19 -61
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));
}
}