diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index 04cbf300..a07674c7 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -778,12 +778,36 @@ View* lcMainWindow::CreateView(lcModel* Model) return NewView; } -void lcMainWindow::PreviewPiece(const QString &PartType, int ColorCode) +void lcMainWindow::PreviewPiece(const QString& PartId, int ColorCode) { - if (mPreviewWidget) { - if (!mPreviewWidget->SetCurrentPiece(PartType, ColorCode)) - QMessageBox::critical(gMainWindow, tr("Error"), tr("Part preview for % failed.").arg(PartType)); + lcPreferences& Preferences = lcGetPreferences(); + + if (!Preferences.mPreviewEnabled) + return; + + if (Preferences.mPreviewPosition != lcPreviewPosition::Floating) + { + if (mPreviewWidget && mPreviewWidget->SetCurrentPiece(PartId, ColorCode)) + return; } + else + { + lcPreviewWidget* Preview = new lcPreviewWidget(); + lcViewWidget* ViewWidget = new lcViewWidget(nullptr, Preview); + + if (Preview && ViewWidget) + { + ViewWidget->setAttribute(Qt::WA_DeleteOnClose, true); + + if (Preview->SetCurrentPiece(PartId, ColorCode)) + { + ViewWidget->SetPreviewPosition(rect()); + return; + } + } + } + + QMessageBox::information(this, tr("Error"), tr("Part preview for '%1' failed.").arg(PartId)); } void lcMainWindow::CreatePreviewWidget() @@ -802,14 +826,14 @@ void lcMainWindow::CreatePreviewWidget() connect(mPreviewToolBar, SIGNAL(topLevelChanged(bool)), this, SLOT(EnableWindowFlags(bool))); } -void lcMainWindow::TogglePreviewWidget(bool visible) +void lcMainWindow::TogglePreviewWidget(bool Visible) { if (mPreviewToolBar) { - if (visible) + if (Visible) mPreviewToolBar->show(); else mPreviewToolBar->hide(); - } else if (visible) { + } else if (Visible) { CreatePreviewWidget(); } } diff --git a/common/lc_mainwindow.h b/common/lc_mainwindow.h index 1ff8c307..d9d6243a 100644 --- a/common/lc_mainwindow.h +++ b/common/lc_mainwindow.h @@ -354,8 +354,8 @@ public: public slots: void ProjectFileChanged(const QString& Path); - void PreviewPiece(const QString &, int); - void TogglePreviewWidget(bool); + void PreviewPiece(const QString& PartId, int ColorCode); + void TogglePreviewWidget(bool Visible); protected slots: void ViewFocusReceived(); diff --git a/common/lc_partselectionwidget.cpp b/common/lc_partselectionwidget.cpp index e5dec8fc..6e3528b6 100644 --- a/common/lc_partselectionwidget.cpp +++ b/common/lc_partselectionwidget.cpp @@ -682,48 +682,24 @@ void lcPartSelectionListView::startDrag(Qt::DropActions SupportedActions) Drag->exec(Qt::CopyAction); } -void lcPartSelectionListView::mouseDoubleClickEvent(QMouseEvent *event) +void lcPartSelectionListView::mouseDoubleClickEvent(QMouseEvent* MouseEvent) { - QAbstractItemView::mouseDoubleClickEvent(event); - if ( event->button() == Qt::LeftButton ) - { + if (MouseEvent->button() == Qt::LeftButton ) PreviewSelection(currentIndex().row()); - } + + QListView::mouseDoubleClickEvent(MouseEvent); } void lcPartSelectionListView::PreviewSelection(int InfoIndex) { - lcPreferences& Preferences = lcGetPreferences(); - if (!Preferences.mPreviewEnabled) - return; - PieceInfo* Info = mListModel->GetPieceInfo(InfoIndex); + if (!Info) return; quint32 ColorCode = lcGetColorCode(mListModel->GetColorIndex()); - if (Preferences.mPreviewPosition != lcPreviewPosition::Floating) - { - gMainWindow->PreviewPiece(Info->mFileName, ColorCode); - return; - } - - lcPreviewWidget* Preview = new lcPreviewWidget(); - - lcViewWidget* ViewWidget = new lcViewWidget(nullptr, Preview); - - if (Preview && ViewWidget) - { - ViewWidget->setAttribute(Qt::WA_DeleteOnClose, true); - if (!Preview->SetCurrentPiece(Info->mFileName, ColorCode)) - QMessageBox::critical(gMainWindow, tr("Error"), tr("Preview %1 failed.").arg(Info->mFileName)); - ViewWidget->SetPreviewPosition(rect()); - } - else - { - QMessageBox::critical(gMainWindow, tr("Error"), tr("Preview %1 failed.").arg(Info->mFileName)); - } + gMainWindow->PreviewPiece(Info->mFileName, ColorCode); } lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent) diff --git a/common/lc_partselectionwidget.h b/common/lc_partselectionwidget.h index 9997bdd9..b0881818 100644 --- a/common/lc_partselectionwidget.h +++ b/common/lc_partselectionwidget.h @@ -188,7 +188,7 @@ public slots: protected: void SetIconSize(int Size); void PreviewSelection(int InfoIndex); - void mouseDoubleClickEvent(QMouseEvent *event) override; + void mouseDoubleClickEvent(QMouseEvent* MouseEvent) override; lcPartSelectionListModel* mListModel; lcPartSelectionWidget* mPartSelectionWidget; diff --git a/common/lc_timelinewidget.cpp b/common/lc_timelinewidget.cpp index 4765892b..c28426dc 100644 --- a/common/lc_timelinewidget.cpp +++ b/common/lc_timelinewidget.cpp @@ -509,44 +509,33 @@ void lcTimelineWidget::mousePressEvent(QMouseEvent* Event) QTreeWidget::mousePressEvent(Event); } -void lcTimelineWidget::mouseDoubleClickEvent(QMouseEvent *event) +void lcTimelineWidget::mouseDoubleClickEvent(QMouseEvent* MouseEvent) { - QTreeWidget::mouseDoubleClickEvent(event); - if ( event->button() == Qt::LeftButton ) + if (MouseEvent->button() == Qt::LeftButton) { - lcPreferences& Preferences = lcGetPreferences(); - if (Preferences.mPreviewEnabled && Preferences.mPreviewPosition == lcPreviewPosition::Floating) - { - QTreeWidgetItem* CurrentItem = currentItem(); - PreviewSelection(CurrentItem); - } + QTreeWidgetItem* CurrentItem = currentItem(); + PreviewSelection(CurrentItem); } + + QTreeWidget::mouseDoubleClickEvent(MouseEvent); } -void lcTimelineWidget::PreviewSelection(QTreeWidgetItem* Current) +void lcTimelineWidget::PreviewSelection(QTreeWidgetItem* CurrentItem) { - lcPiece* Piece = (lcPiece*)Current->data(0, Qt::UserRole).value(); + if (!CurrentItem) + return; + + lcPiece* Piece = (lcPiece*)CurrentItem->data(0, Qt::UserRole).value(); + if (!Piece) return; PieceInfo* Info = Piece->mPieceInfo; + if (!Info) return; - lcPreviewWidget* Preview = new lcPreviewWidget(); - - lcViewWidget* ViewWidget = new lcViewWidget(nullptr, Preview); - - 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)); - } + gMainWindow->PreviewPiece(Info->mFileName, Piece->mColorCode); } void lcTimelineWidget::UpdateModel() diff --git a/common/lc_timelinewidget.h b/common/lc_timelinewidget.h index 96b3c5bd..6163221b 100644 --- a/common/lc_timelinewidget.h +++ b/common/lc_timelinewidget.h @@ -26,7 +26,7 @@ public slots: protected: void dropEvent(QDropEvent* DropEvent) override; void mousePressEvent(QMouseEvent* MouseEvent) override; - void mouseDoubleClickEvent(QMouseEvent *event) override; + void mouseDoubleClickEvent(QMouseEvent* MouseEvent) override; void UpdateModel(); void UpdateCurrentStepItem(); diff --git a/common/lc_viewwidget.cpp b/common/lc_viewwidget.cpp index 69fae72f..836adf4a 100644 --- a/common/lc_viewwidget.cpp +++ b/common/lc_viewwidget.cpp @@ -135,13 +135,14 @@ void lcViewWidget::SetPreviewPosition(const QRect& ParentRect) 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.x() + width()) > desktop.right()) + pos.setX(desktop.right() - width()); if ((pos.y() + height()) > desktop.bottom()) pos.setY(desktop.bottom() - height()); move(pos); diff --git a/qt/lc_qpropertiestree.cpp b/qt/lc_qpropertiestree.cpp index 23b53dbd..ad89ddc0 100644 --- a/qt/lc_qpropertiestree.cpp +++ b/qt/lc_qpropertiestree.cpp @@ -774,7 +774,7 @@ void lcQPropertiesTree::slotSetValue(int Value) if (Focus && Focus->IsPiece()) ColorIndex = ((lcPiece*)Focus)->mColorIndex; quint32 ColorCode = lcGetColorCode(ColorIndex); - PreviewSelection(Info->mFileName, ColorCode); + gMainWindow->PreviewPiece(Info->mFileName, ColorCode); } } } @@ -952,7 +952,7 @@ void lcQPropertiesTree::SetPiece(const lcArray& Selection, lcObject* if (Preferences.mPreviewEnabled && Preferences.mPreviewPosition != lcPreviewPosition::Floating) { quint32 ColorCode = lcGetColorCode(ColorIndex); - PreviewSelection(Info->mFileName, ColorCode); + gMainWindow->PreviewPiece(Info->mFileName, ColorCode); } } else @@ -1138,28 +1138,3 @@ 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(); - - lcViewWidget* ViewWidget = new lcViewWidget(nullptr, Preview); - - 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)); - } -} diff --git a/qt/lc_qpropertiestree.h b/qt/lc_qpropertiestree.h index 53c2ba71..7ea77165 100644 --- a/qt/lc_qpropertiestree.h +++ b/qt/lc_qpropertiestree.h @@ -72,8 +72,6 @@ protected: void getPartProperties(lcPartProperties *properties); - void PreviewSelection(const QString& PartType, int ColorCode); - lcPropertyWidgetMode mWidgetMode; lcObject* mFocus;