summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/UI
diff options
context:
space:
mode:
authorMahmoud Badri <mahmoud.badri@qt.io>2019-03-22 11:26:32 +0200
committerMahmoud Badri <mahmoud.badri@qt.io>2019-03-22 11:35:44 +0000
commitff0dba0dbfde3b9f34db4d89a7f94a531bbe547d (patch)
treeef3d43fbee1153dbcfdde52f088c8b3b6bff3c48 /src/Authoring/Studio/UI
parent807585466d6f31ec66baf1218463bc9c75b7d0d2 (diff)
Tweak camera selector
- Removed useless code - Some cleanups Change-Id: I92433ae375026d8f0acbf7d8a4731f65a6ef3ebd Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src/Authoring/Studio/UI')
-rw-r--r--src/Authoring/Studio/UI/EditCameraBar.cpp166
-rw-r--r--src/Authoring/Studio/UI/EditCameraBar.h57
-rw-r--r--src/Authoring/Studio/UI/StudioAppPrefsPage.cpp31
3 files changed, 58 insertions, 196 deletions
diff --git a/src/Authoring/Studio/UI/EditCameraBar.cpp b/src/Authoring/Studio/UI/EditCameraBar.cpp
index eeefbbdc..2789eb6f 100644
--- a/src/Authoring/Studio/UI/EditCameraBar.cpp
+++ b/src/Authoring/Studio/UI/EditCameraBar.cpp
@@ -27,7 +27,6 @@
**
****************************************************************************/
-#include "Qt3DSCommonPrecompile.h"
#include "EditCameraBar.h"
#include "MainFrm.h"
#include "SceneView.h"
@@ -36,72 +35,47 @@
#include "IStudioRenderer.h"
#include <QtWidgets/qcombobox.h>
-#include <QtWidgets/qlabel.h>
-#include <QtWidgets/qabstractitemview.h>
#include <QtWidgets/qlistview.h>
-//==============================================================================
-/**
- * Constructor
- */
-CEditCameraBar::CEditCameraBar(QWidget* parent)
- : QToolBar(parent)
- , m_SceneView(nullptr)
- , m_ActiveCameraIndex(-1)
+CEditCameraBar::CEditCameraBar(QWidget *parent) : QToolBar(parent)
{
- OnCustomizeToolbar();
- auto activated = static_cast<void(QComboBox::*)(int)>(&QComboBox::activated);
- connect(m_CameraSelector, activated, this, &CEditCameraBar::OnCameraChanged);
+ initialize();
+
+ connect(m_CameraSelector, QOverload<int>::of(&QComboBox::currentIndexChanged),
+ this, &CEditCameraBar::handleCameraChanged);
}
-//==============================================================================
-/**
- * Destructor
- */
CEditCameraBar::~CEditCameraBar()
{
delete m_CameraSelector;
}
-//==============================================================================
/**
* Setup the list of edit cameras into the camera combo box
* @param inCameras the container that holds the edit cameras
*/
-void CEditCameraBar::SetupCameras()
+void CEditCameraBar::setupCameras()
{
m_CameraSelector->clear();
Q3DStudio::IStudioRenderer &theRenderer = g_StudioApp.getRenderer();
QStringList theCameraNames;
theRenderer.GetEditCameraList(theCameraNames);
- int idx = 1;
- for (const QString &str : qAsConst(theCameraNames)) {
- m_CameraSelector->addItem(str, QVariant((int)idx));
- idx++;
- }
-
+ m_CameraSelector->addItems(theCameraNames);
m_CameraSelector->addItem(tr("Scene Camera View"));
- m_CameraSelector->setItemData(m_CameraSelector->count() - 1, 0);
m_CameraSelector->insertSeparator(m_CameraSelector->count() - 1);
+
// adding a 1px spacing, else the separator will disappear sometimes (QComboBox bug)
- qobject_cast<QListView*>(m_CameraSelector->view())->setSpacing(1);
-
- long thePreferredView = CStudioPreferences::GetPreferredStartupView();
- long theNumItems = m_CameraSelector->count();
- if (thePreferredView == -1) {
- // deployment view
- m_CameraSelector->setCurrentIndex(theNumItems - 1);
- HandleCameraChanged(theNumItems - 1); // set to the last one
- } else {
- int theIndex;
- if (thePreferredView < theNumItems - 2)
- theIndex = thePreferredView;
- else // possibly from old content where cameras are removed
- theIndex = 0;
- m_CameraSelector->setCurrentIndex(theIndex);
- HandleCameraChanged(theIndex);
- }
+ qobject_cast<QListView *>(m_CameraSelector->view())->setSpacing(1);
+
+ // set initial view
+ int viewIndex = CStudioPreferences::GetPreferredStartupView();
+ // if not set or invalid index, use the scene camera view (last index)
+ if (viewIndex == -1 || viewIndex > m_CameraSelector->count() - 1)
+ viewIndex = m_CameraSelector->count() - 1;
+
+ m_CameraSelector->setCurrentIndex(viewIndex);
+ handleCameraChanged(viewIndex);
QString ctrlKey(QStringLiteral("Ctrl+"));
#ifdef Q_OS_MACOS
@@ -111,117 +85,50 @@ void CEditCameraBar::SetupCameras()
m_CameraSelector->setToolTip(tr("Change Camera View (%1<1..9>)").arg(ctrlKey));
}
-//==============================================================================
-/**
- * Callback method when the camera is changed from the camera selection combo box
- */
-void CEditCameraBar::OnCameraChanged()
-{
- HandleCameraChanged(m_CameraSelector->currentIndex());
-}
-
void CEditCameraBar::setCameraIndex(int inIndex)
{
m_CameraSelector->setCurrentIndex(inIndex);
- OnCameraChanged();
+ handleCameraChanged(inIndex);
}
-//==============================================================================
/**
* Handle the switching of the current edit camera
* @param inIndex the index of the to-be-activated camera in the combo box
*/
-void CEditCameraBar::HandleCameraChanged(int inIndex)
+void CEditCameraBar::handleCameraChanged(int inIndex)
{
Q3DStudio::IStudioRenderer &theRenderer = g_StudioApp.getRenderer();
- QStringList theCameraNames;
- theRenderer.GetEditCameraList(theCameraNames);
- int theNumCameras = theCameraNames.size();
- if (inIndex < theNumCameras) {
- theRenderer.SetEditCamera(inIndex);
- m_ActiveCameraIndex = inIndex;
- if (m_SceneView)
- m_SceneView->setViewMode(CPlayerContainerWnd::VIEW_EDIT);
- } else if (inIndex > theNumCameras) {
- theRenderer.SetEditCamera(-1);
- m_ActiveCameraIndex = inIndex;
- if (m_SceneView)
- m_SceneView->setViewMode(CPlayerContainerWnd::VIEW_SCENE);
- } else {
- m_CameraSelector->setCurrentIndex(m_ActiveCameraIndex);
- }
+
+ // last index is scene camera view, renderer requires index -1 for it
+ theRenderer.SetEditCamera(inIndex == m_CameraSelector->count() - 1 ? -1 : inIndex);
+
if (m_SceneView)
m_SceneView->onEditCameraChanged();
- CMainFrame *theMainFrame = g_StudioApp.m_pMainWnd;
- Q_ASSERT(theMainFrame != nullptr);
-
// if the current tool is camera rotate and has been switch to 2d camera
// set the tool to camera pan
- if (theMainFrame != nullptr) {
- long theToolMode = g_StudioApp.GetToolMode();
- if (!theRenderer.DoesEditCameraSupportRotation(theRenderer.GetEditCamera())
- && theToolMode == STUDIO_TOOLMODE_CAMERA_ROTATE) {
- g_StudioApp.SetToolMode(STUDIO_TOOLMODE_CAMERA_PAN);
- m_SceneView->setViewCursor(); // Just set cursor, we don't want to update previous tool
- }
-
- // Trigger for tool changed. Changing between deployment/edit camera can change the tool
- theMainFrame->OnUpdateToolChange();
+ long theToolMode = g_StudioApp.GetToolMode();
+ if (!theRenderer.DoesEditCameraSupportRotation(theRenderer.GetEditCamera())
+ && theToolMode == STUDIO_TOOLMODE_CAMERA_ROTATE) {
+ g_StudioApp.SetToolMode(STUDIO_TOOLMODE_CAMERA_PAN);
+ m_SceneView->setViewCursor(); // Just set cursor, we don't want to update previous tool
}
+
+ // Trigger for tool changed. Changing between deployment/edit camera can change the tool
+ g_StudioApp.m_pMainWnd->OnUpdateToolChange();
}
-//==============================================================================
/**
* Set the current scene view. This scene view is notified when there is a camera
* changed.
* @param inSceneView the scene view object
*/
-void CEditCameraBar::SetSceneView(CSceneView *inSceneView)
+void CEditCameraBar::setSceneView(CSceneView *inSceneView)
{
m_SceneView = inSceneView;
}
-//==============================================================================
-/**
- * Enable/Disable the edit camera selector combo box.
- * @param inFlag true to enable the camera selector combo box, false to disable
- */
-void CEditCameraBar::Enable(bool inFlag)
-{
- m_CameraSelector->setEnabled(inFlag);
-}
-
-//==============================================================================
-/**
- * When the active camera is changed, the display string needs to be changed. Hence
- * find which entry is the one which is modified and update with the new string
- * @param inCamera the camera that has been modified
- */
-void CEditCameraBar::onEditCameraChanged()
-{
- using qt3ds::QT3DSI32;
- QT3DSI32 cameraIndex = g_StudioApp.getRenderer().GetEditCamera();
- long theNumEntry = m_CameraSelector->count();
- for (long theIndex = 0; theIndex < theNumEntry; ++theIndex) {
- if (m_CameraSelector->itemData(theIndex).toInt() == cameraIndex) {
- if (theIndex != m_CameraSelector->currentIndex()) {
- m_CameraSelector->setCurrentIndex(theIndex);
- HandleCameraChanged(theIndex);
- }
- break;
- }
- }
-}
-
-//==============================================================================
-/**
- * Callback while creating the toolbar in MainFrm. This allows the toolbar to add
- * other controls to it. For this toolbar, we want to add a descriptor and a camera
- * selector dropdown combobox.
- */
-//==============================================================================
-void CEditCameraBar::OnCustomizeToolbar()
+void CEditCameraBar::initialize()
{
// Create the combo box
addWidget(m_CameraSelector = new QComboBox);
@@ -233,6 +140,7 @@ void CEditCameraBar::OnCustomizeToolbar()
#endif
// We need to specify accessibleName and objectName for the combobox, as it's in the toolbar,
// and we want to use a different style for it.
- m_CameraSelector->setAccessibleName(QStringLiteral("cameraSelector"));
- m_CameraSelector->setObjectName(QStringLiteral("cameraSelector"));
+ const QString objName(QStringLiteral("cameraSelector"));
+ m_CameraSelector->setAccessibleName(objName);
+ m_CameraSelector->setObjectName(objName);
}
diff --git a/src/Authoring/Studio/UI/EditCameraBar.h b/src/Authoring/Studio/UI/EditCameraBar.h
index 929a0dc8..fae523c3 100644
--- a/src/Authoring/Studio/UI/EditCameraBar.h
+++ b/src/Authoring/Studio/UI/EditCameraBar.h
@@ -27,68 +27,35 @@
**
****************************************************************************/
-//==============================================================================
-// Prefix
-//==============================================================================
#ifndef INCLUDED_EDIT_CAMERA_BAR
-#define INCLUDED_EDIT_CAMERA_BAR 1
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-
-//==============================================================================
-// Includes
-//==============================================================================
-#include "DispatchListeners.h"
-#include <vector>
+#define INCLUDED_EDIT_CAMERA_BAR
#include <QtWidgets/qtoolbar.h>
QT_BEGIN_NAMESPACE
class QComboBox;
-class QLabel;
QT_END_NAMESPACE
-//==============================================================================
-// Forwards
-//==============================================================================
class CSceneView;
-//==============================================================================
-/**
- * @class CEditCameraBar
- */
-class CEditCameraBar : public QToolBar, public CEditCameraChangeListener
+class CEditCameraBar : public QToolBar
{
Q_OBJECT
-public:
- CEditCameraBar(QWidget* parent = nullptr); // standard constructor
- virtual ~CEditCameraBar();
-
- // Implementation
- // Generated message map functions
- void OnCameraChanged();
- void OnCustomizeToolbar();
public:
- void SetupCameras();
- void SetSceneView(CSceneView *inSceneView);
- void Enable(bool inFlag);
- void setCameraIndex(int inIndex);
- void HandleCameraChanged(int inIndex);
+ CEditCameraBar(QWidget *parent = nullptr);
+ virtual ~CEditCameraBar() override;
- // CEditCameraChangeListener
- void onEditCameraChanged() override;
- void onEditCamerasTransformed() override {}
- void onAuthorZoomChanged() override {}
+ void setupCameras();
+ void setSceneView(CSceneView *inSceneView);
+ void setCameraIndex(int inIndex);
-protected:
- CSceneView *m_SceneView; ///< The scene view object
- long m_ActiveCameraIndex; ///< The index of the active camera in the list
+private:
+ void initialize();
+ void handleCameraChanged(int inIndex);
- // UI Controls definition
- QComboBox* m_CameraSelector; ///< Combo box for selecting edit camera
+ CSceneView *m_SceneView = nullptr;
+ QComboBox *m_CameraSelector = nullptr;
};
#endif
diff --git a/src/Authoring/Studio/UI/StudioAppPrefsPage.cpp b/src/Authoring/Studio/UI/StudioAppPrefsPage.cpp
index 0740d749..08ef1c82 100644
--- a/src/Authoring/Studio/UI/StudioAppPrefsPage.cpp
+++ b/src/Authoring/Studio/UI/StudioAppPrefsPage.cpp
@@ -44,6 +44,7 @@
#include "IStudioRenderer.h"
#include <QtWidgets/qmessagebox.h>
+#include <QtWidgets/qlistview.h>
#include <QtGui/qstandarditemmodel.h>
#include <QtCore/qdiriterator.h>
@@ -203,10 +204,7 @@ void CStudioAppPrefsPage::saveSettings()
CStudioPreferences::SetTimelineSnappingGridResolution((ESnapGridResolution)theCurrentSelection);
// Preferred Startup View
- long theSel = m_ui->m_EditViewStartupView->currentIndex();
- long theNumItems = m_ui->m_EditViewStartupView->count();
- CStudioPreferences::SetPreferredStartupView(
- (theSel == theNumItems - 1) ? -1 : theSel); // -1 for deployment view
+ CStudioPreferences::SetPreferredStartupView(m_ui->m_EditViewStartupView->currentIndex());
// Tool handles
CStudioPreferences::setSelectorLineWidth(m_ui->selectorWidth->value());
@@ -294,29 +292,18 @@ void CStudioAppPrefsPage::onitEditStartViewCombo()
Q3DStudio::IStudioRenderer &theRenderer = g_StudioApp.getRenderer();
QStringList theCameraNames;
theRenderer.GetEditCameraList(theCameraNames);
- for (int idx = 0, end = theCameraNames.size(); idx < end; ++idx) {
- m_ui->m_EditViewStartupView->addItem(
- theCameraNames.at(idx));
- m_ui->m_EditViewStartupView->setItemData(m_ui->m_EditViewStartupView->count() - 1,
- QVariant((int)idx + 1));
- }
+ m_ui->m_EditViewStartupView->addItems(theCameraNames);
+ m_ui->m_EditViewStartupView->addItem(tr("Scene Camera View"));
- m_ui->m_EditViewStartupView->addItem("--------------------------");
- m_ui->m_EditViewStartupView->setItemData(m_ui->m_EditViewStartupView->count() - 1, -1); // set to an invalid pointer
- // make item non-selectable
- QStandardItemModel *model =
- qobject_cast<QStandardItemModel *>(m_ui->m_EditViewStartupView->model());
- QStandardItem *item = model->item(theCameraNames.size());
- item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
+ m_ui->m_EditViewStartupView->insertSeparator(m_ui->m_EditViewStartupView->count() - 1);
- // add the deployment view as the last selection
- m_ui->m_EditViewStartupView->addItem(tr("Scene Camera View"));
- m_ui->m_EditViewStartupView->setItemData(m_ui->m_EditViewStartupView->count() - 1, 0);
+ // adding a 1px spacing, else the separator will disappear sometimes (QComboBox bug)
+ qobject_cast<QListView *>(m_ui->m_EditViewStartupView->view())->setSpacing(1);
long thePreferredView = CStudioPreferences::GetPreferredStartupView();
long theNumItems = m_ui->m_EditViewStartupView->count();
- if (thePreferredView == -1) // deployment view
- m_ui->m_EditViewStartupView->setCurrentIndex(theNumItems - 1); // set to the last one
+ if (thePreferredView == -1) // if not set, set to scene camera view
+ m_ui->m_EditViewStartupView->setCurrentIndex(theNumItems - 1);
else if (thePreferredView < theNumItems - 1)
m_ui->m_EditViewStartupView->setCurrentIndex(thePreferredView);
else // possibly from old content where cameras are removed