From 8f48b09ae3d78ade1da6524ee24b7fa397853bbb Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sun, 5 Jan 2020 11:38:24 -0800 Subject: [PATCH] Added view sphere toggle. Fixes #284. --- common/lc_application.cpp | 2 ++ common/lc_application.h | 1 + common/lc_commands.cpp | 7 +++++++ common/lc_commands.h | 1 + common/lc_mainwindow.cpp | 18 ++++++++++++------ common/lc_mainwindow.h | 2 +- common/lc_profile.cpp | 1 + common/lc_profile.h | 1 + common/lc_viewsphere.cpp | 8 ++++---- qt/lc_qpreferencesdialog.cpp | 33 +++++++++++++++++++-------------- 10 files changed, 49 insertions(+), 25 deletions(-) diff --git a/common/lc_application.cpp b/common/lc_application.cpp index 95037bbc..38e77df3 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -27,6 +27,7 @@ void lcPreferences::LoadDefaults() mDrawGridLines = lcGetProfileInt(LC_PROFILE_GRID_LINES); mGridLineSpacing = lcGetProfileInt(LC_PROFILE_GRID_LINE_SPACING); mGridLineColor = lcGetProfileInt(LC_PROFILE_GRID_LINE_COLOR); + mViewSphereEnabled = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_ENABLED); mViewSphereLocation = (lcViewSphereLocation)lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_LOCATION); mViewSphereSize = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_SIZE); mViewSphereColor = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_COLOR); @@ -51,6 +52,7 @@ void lcPreferences::SaveDefaults() lcSetProfileInt(LC_PROFILE_GRID_LINES, mDrawGridLines); lcSetProfileInt(LC_PROFILE_GRID_LINE_SPACING, mGridLineSpacing); lcSetProfileInt(LC_PROFILE_GRID_LINE_COLOR, mGridLineColor); + lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_ENABLED, mViewSphereSize ? 1 : 0); lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_LOCATION, (int)mViewSphereLocation); lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_SIZE, mViewSphereSize); lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_COLOR, mViewSphereColor); diff --git a/common/lc_application.h b/common/lc_application.h index 3ca55f12..eeb2c8db 100644 --- a/common/lc_application.h +++ b/common/lc_application.h @@ -41,6 +41,7 @@ public: int mGridLineSpacing; quint32 mGridLineColor; bool mFixedAxes; + bool mViewSphereEnabled; lcViewSphereLocation mViewSphereLocation; int mViewSphereSize; quint32 mViewSphereColor; diff --git a/common/lc_commands.cpp b/common/lc_commands.cpp index e775aa6e..2a817374 100644 --- a/common/lc_commands.cpp +++ b/common/lc_commands.cpp @@ -1039,6 +1039,13 @@ lcCommand gCommands[LC_NUM_COMMANDS] = QT_TRANSLATE_NOOP("Status", "Set the current camera to use an orthographic projection"), "" }, + // LC_VIEW_TOGGLE_VIEW_SPHERE + { + QT_TRANSLATE_NOOP("Action", "View.ToggleViewSphere"), + QT_TRANSLATE_NOOP("Menu", "View Sphere"), + QT_TRANSLATE_NOOP("Status", "Toggle the view sphere"), + "" + }, // LC_PIECE_INSERT { QT_TRANSLATE_NOOP("Action", "Piece.Insert"), diff --git a/common/lc_commands.h b/common/lc_commands.h index f7b1095a..53692217 100644 --- a/common/lc_commands.h +++ b/common/lc_commands.h @@ -162,6 +162,7 @@ enum lcCommandId LC_VIEW_PROJECTION_PERSPECTIVE = LC_VIEW_PROJECTION_FIRST, LC_VIEW_PROJECTION_ORTHO, LC_VIEW_PROJECTION_LAST = LC_VIEW_PROJECTION_ORTHO, + LC_VIEW_TOGGLE_VIEW_SPHERE, LC_PIECE_INSERT, LC_PIECE_DELETE, LC_PIECE_DUPLICATE, diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index 463c908c..d0cfef05 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -911,7 +911,7 @@ void lcMainWindow::ModelTabContextMenuRequested(const QPoint& Point) if (mModelTabWidget->count() > 1) Menu->addAction(tr("Close Other Tabs"), this, SLOT(ModelTabCloseOtherTabs())); if (mModelTabWidgetContextMenuIndex == mModelTabWidget->currentIndex()) - Menu->addAction(tr("Reset Views"), this, SLOT(ModelTabResetViews())); + Menu->addAction(mActions[LC_VIEW_RESET_VIEWS]); Menu->exec(QCursor::pos()); delete Menu; @@ -929,11 +929,6 @@ void lcMainWindow::ModelTabCloseOtherTabs() delete mModelTabWidget->widget(0); } -void lcMainWindow::ModelTabResetViews() -{ - ResetViews(); -} - void lcMainWindow::ModelTabClosed(int Index) { if (mModelTabWidget->count() != 1) @@ -1225,6 +1220,13 @@ void lcMainWindow::SetSelectionMode(lcSelectionMode SelectionMode) UpdateSelectionMode(); } +void lcMainWindow::ToggleViewSphere() +{ + lcGetPreferences().mViewSphereEnabled = !lcGetPreferences().mViewSphereEnabled; + + UpdateAllViews(); +} + QByteArray lcMainWindow::GetTabLayout() { QByteArray TabLayoutData; @@ -2641,6 +2643,10 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId) ActiveView->SetProjection(true); break; + case LC_VIEW_TOGGLE_VIEW_SPHERE: + ToggleViewSphere(); + break; + case LC_PIECE_INSERT: if (ActiveModel) ActiveModel->AddPiece(); diff --git a/common/lc_mainwindow.h b/common/lc_mainwindow.h index 66ab81c8..09df3191 100644 --- a/common/lc_mainwindow.h +++ b/common/lc_mainwindow.h @@ -289,6 +289,7 @@ public: void SetCurrentPieceInfo(PieceInfo* Info); void SetShadingMode(lcShadingMode ShadingMode); void SetSelectionMode(lcSelectionMode SelectionMode); + void ToggleViewSphere(); void NewProject(); bool OpenProject(const QString& FileName); @@ -348,7 +349,6 @@ protected slots: void UpdateGamepads(); void ModelTabContextMenuRequested(const QPoint& Point); void ModelTabCloseOtherTabs(); - void ModelTabResetViews(); void ModelTabClosed(int Index); void ModelTabChanged(int Index); void ClipboardChanged(); diff --git a/common/lc_profile.cpp b/common/lc_profile.cpp index 9ce1daec..a666b626 100644 --- a/common/lc_profile.cpp +++ b/common/lc_profile.cpp @@ -68,6 +68,7 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] = lcProfileEntry("Settings", "GridLineSpacing", 5), // LC_PROFILE_GRID_LINE_SPACING lcProfileEntry("Settings", "GridLineColor", LC_RGBA(0, 0, 0, 255)), // LC_PROFILE_GRID_LINE_COLOR lcProfileEntry("Settings", "AASamples", 1), // LC_PROFILE_ANTIALIASING_SAMPLES + lcProfileEntry("Settings", "ViewSphereEnabled", 1), // LC_PROFILE_VIEW_SPHERE_ENABLED lcProfileEntry("Settings", "ViewSphereLocation", (int)lcViewSphereLocation::TOP_RIGHT), // LC_PROFILE_VIEW_SPHERE_LOCATION lcProfileEntry("Settings", "ViewSphereSize", 100), // LC_PROFILE_VIEW_SPHERE_SIZE lcProfileEntry("Settings", "ViewSphereColor", LC_RGBA(255, 255, 255, 255)), // LC_PROFILE_VIEW_SPHERE_COLOR diff --git a/common/lc_profile.h b/common/lc_profile.h index e0efc835..72ef5da3 100644 --- a/common/lc_profile.h +++ b/common/lc_profile.h @@ -16,6 +16,7 @@ enum LC_PROFILE_KEY LC_PROFILE_GRID_LINE_SPACING, LC_PROFILE_GRID_LINE_COLOR, LC_PROFILE_ANTIALIASING_SAMPLES, + LC_PROFILE_VIEW_SPHERE_ENABLED, LC_PROFILE_VIEW_SPHERE_LOCATION, LC_PROFILE_VIEW_SPHERE_SIZE, LC_PROFILE_VIEW_SPHERE_COLOR, diff --git a/common/lc_viewsphere.cpp b/common/lc_viewsphere.cpp index c2e21b7f..a46327a9 100644 --- a/common/lc_viewsphere.cpp +++ b/common/lc_viewsphere.cpp @@ -154,7 +154,7 @@ void lcViewSphere::Draw() const lcPreferences& Preferences = lcGetPreferences(); int ViewportSize = Preferences.mViewSphereSize; - if (ViewportSize == 0) + if (ViewportSize == 0 || !Preferences.mViewSphereEnabled) return; lcContext* Context = mView->mContext; @@ -221,7 +221,7 @@ void lcViewSphere::Draw() bool lcViewSphere::OnLeftButtonDown() { const lcPreferences& Preferences = lcGetPreferences(); - if (Preferences.mViewSphereSize == 0) + if (Preferences.mViewSphereSize == 0 || !Preferences.mViewSphereEnabled) return false; mIntersectionFlags = GetIntersectionFlags(mIntersection); @@ -239,7 +239,7 @@ bool lcViewSphere::OnLeftButtonDown() bool lcViewSphere::OnLeftButtonUp() { const lcPreferences& Preferences = lcGetPreferences(); - if (Preferences.mViewSphereSize == 0) + if (Preferences.mViewSphereSize == 0 || !Preferences.mViewSphereEnabled) return false; if (!mMouseDown) @@ -268,7 +268,7 @@ bool lcViewSphere::OnLeftButtonUp() bool lcViewSphere::OnMouseMove() { const lcPreferences& Preferences = lcGetPreferences(); - if (Preferences.mViewSphereSize == 0) + if (Preferences.mViewSphereSize == 0 || !Preferences.mViewSphereEnabled) return false; if (IsDragging()) diff --git a/qt/lc_qpreferencesdialog.cpp b/qt/lc_qpreferencesdialog.cpp index ca06d391..52fda33f 100644 --- a/qt/lc_qpreferencesdialog.cpp +++ b/qt/lc_qpreferencesdialog.cpp @@ -77,21 +77,26 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO ui->ViewSphereLocationCombo->setCurrentIndex((int)mOptions->Preferences.mViewSphereLocation); - switch (mOptions->Preferences.mViewSphereSize) + if (mOptions->Preferences.mViewSphereEnabled) { - case 200: - ui->ViewSphereSizeCombo->setCurrentIndex(3); - break; - case 100: - ui->ViewSphereSizeCombo->setCurrentIndex(2); - break; - case 50: - ui->ViewSphereSizeCombo->setCurrentIndex(1); - break; - default: - ui->ViewSphereSizeCombo->setCurrentIndex(0); - break; + switch (mOptions->Preferences.mViewSphereSize) + { + case 200: + ui->ViewSphereSizeCombo->setCurrentIndex(3); + break; + case 100: + ui->ViewSphereSizeCombo->setCurrentIndex(2); + break; + case 50: + ui->ViewSphereSizeCombo->setCurrentIndex(1); + break; + default: + ui->ViewSphereSizeCombo->setCurrentIndex(0); + break; + } } + else + ui->ViewSphereSizeCombo->setCurrentIndex(0); ui->studLogo->setChecked(mOptions->StudLogo); if (ui->studLogo->isChecked()) @@ -212,7 +217,7 @@ void lcQPreferencesDialog::accept() mOptions->Preferences.mViewSphereSize = 50; break; default: - mOptions->Preferences.mViewSphereSize = 0; + mOptions->Preferences.mViewSphereEnabled = 0; break; }