LayoutWnd.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "EditorDefs.h"
  9. #include "LayoutWnd.h"
  10. // Qt
  11. #include <QMessageBox>
  12. #include <QToolBar>
  13. #include <QComboBox>
  14. #include <QLabel>
  15. #include <QLineEdit>
  16. #include <QTextDocumentFragment>
  17. #include <AzCore/Interface/Interface.h>
  18. #include <AzQtComponents/Components/Style.h> // for AzQtComponents::Style
  19. // Editor
  20. #include "MainWindow.h"
  21. #include "ViewPane.h"
  22. #include "QtViewPaneManager.h"
  23. #include "ViewManager.h"
  24. #include <AzQtComponents/Components/Style.h>
  25. class CLayoutSplitterHandle
  26. : public QSplitterHandle
  27. {
  28. public:
  29. CLayoutSplitterHandle(Qt::Orientation orientation, CLayoutSplitter* parent)
  30. : QSplitterHandle(orientation, parent)
  31. {
  32. }
  33. protected:
  34. void paintEvent(QPaintEvent*) override
  35. {
  36. // draw nothing for flat look
  37. }
  38. };
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CLayoutSplitter
  41. //////////////////////////////////////////////////////////////////////////
  42. CLayoutSplitter::CLayoutSplitter(QWidget* parent)
  43. : QSplitter(parent)
  44. {
  45. }
  46. CLayoutSplitter::~CLayoutSplitter()
  47. {
  48. }
  49. QSplitterHandle* CLayoutSplitter::createHandle()
  50. {
  51. return new CLayoutSplitterHandle(orientation(), this);
  52. }
  53. //////////////////////////////////////////////////////////////////////////
  54. void CLayoutSplitter::resizeEvent(QResizeEvent* event)
  55. {
  56. QSplitter::resizeEvent(event);
  57. // only the top level splitter should trigger resetting the layout when being resized
  58. if (qobject_cast<CLayoutSplitter*>(parentWidget()) == nullptr)
  59. {
  60. for (CLayoutSplitter* s : findChildren<CLayoutSplitter*>())
  61. {
  62. s->setSizes(QList<int>::fromVector(QVector<int>(s->count(), (s->orientation() == Qt::Horizontal ? s->width() : s->height()) / s->count())));
  63. }
  64. setSizes(QList<int>::fromVector(QVector<int>(count(), (orientation() == Qt::Horizontal ? width() : height()) / count())));
  65. }
  66. }
  67. //////////////////////////////////////////////////////////////////////////
  68. void CLayoutSplitter::CreateLayoutView(int row, int col, int id)
  69. {
  70. assert(row >= 0 && row < 3);
  71. assert(col >= 0 && col < 3);
  72. CLayoutViewPane* viewPane = new CLayoutViewPane(this);
  73. viewPane->setWindowFlags(Qt::Widget);
  74. insertWidget(orientation() == Qt::Horizontal ? col : row, viewPane);
  75. viewPane->SetId(id);
  76. }
  77. //////////////////////////////////////////////////////////////////////////
  78. // CLayoutWnd
  79. //////////////////////////////////////////////////////////////////////////
  80. CLayoutWnd::CLayoutWnd(QSettings* settings, QWidget* parent)
  81. : AzQtComponents::ToolBarArea(parent)
  82. , m_settings(settings)
  83. {
  84. m_bMaximized = false;
  85. m_maximizedView = nullptr;
  86. m_layout = (EViewLayout) - 1;
  87. m_maximizedViewId = 0;
  88. connect(qApp, &QApplication::focusChanged, this, &CLayoutWnd::OnFocusChanged);
  89. setContextMenuPolicy(Qt::NoContextMenu);
  90. }
  91. //////////////////////////////////////////////////////////////////////////
  92. CLayoutWnd::~CLayoutWnd()
  93. {
  94. delete m_splitWnd;
  95. delete m_splitWnd2;
  96. delete m_splitWnd3;
  97. OnDestroy();
  98. }
  99. //////////////////////////////////////////////////////////////////////////
  100. void CLayoutWnd::UnbindViewports()
  101. {
  102. // First unbind all views.
  103. for (int i = 0; i < MAX_VIEWPORTS; i++)
  104. {
  105. CLayoutViewPane* pViewPane = GetViewPane(i);
  106. if (pViewPane)
  107. {
  108. pViewPane->ReleaseViewport();
  109. }
  110. }
  111. if (m_maximizedView)
  112. {
  113. m_maximizedView->ReleaseViewport();
  114. }
  115. }
  116. //////////////////////////////////////////////////////////////////////////
  117. void CLayoutWnd::BindViewports()
  118. {
  119. // First unbind all views.
  120. UnbindViewports();
  121. for (int i = 0; i < MAX_VIEWPORTS; i++)
  122. {
  123. CLayoutViewPane* pViewPane = GetViewPane(i);
  124. if (pViewPane)
  125. {
  126. BindViewport(pViewPane, m_viewType[pViewPane->GetId()]);
  127. }
  128. }
  129. FocusFirstLayoutViewPane(m_splitWnd);
  130. }
  131. //////////////////////////////////////////////////////////////////////////
  132. void CLayoutWnd::BindViewport(CLayoutViewPane* vp, const QString& viewClassName, QWidget* pViewport)
  133. {
  134. assert(vp);
  135. if (!pViewport)
  136. {
  137. vp->SetViewClass(viewClassName);
  138. }
  139. else
  140. {
  141. vp->AttachViewport(pViewport);
  142. }
  143. vp->setVisible(true);
  144. m_viewType[vp->GetId()] = viewClassName;
  145. }
  146. //////////////////////////////////////////////////////////////////////////
  147. void CLayoutWnd::MaximizeViewport(int paneId)
  148. {
  149. // Ignore with full screen layout.
  150. if (m_layout == ET_Layout0 && m_bMaximized)
  151. {
  152. return;
  153. }
  154. QString viewClass = m_viewType[paneId];
  155. if (!m_bMaximized)
  156. {
  157. CLayoutViewPane* pViewPane = GetViewPane(paneId);
  158. m_maximizedViewId = paneId;
  159. m_bMaximized = true;
  160. if (m_maximizedView)
  161. {
  162. if (m_splitWnd)
  163. {
  164. m_splitWnd->setVisible(false);
  165. }
  166. if (pViewPane)
  167. {
  168. MoveViewport(pViewPane, m_maximizedView, viewClass);
  169. }
  170. else
  171. {
  172. BindViewport(m_maximizedView, viewClass);
  173. }
  174. m_maximizedView->setFocus();
  175. SetMainWidget(m_maximizedView);
  176. m_maximizedView->setVisible(true);
  177. MainWindow::instance()->SetActiveView(m_maximizedView);
  178. }
  179. }
  180. else
  181. {
  182. CLayoutViewPane* pViewPane = GetViewPane(m_maximizedViewId);
  183. m_bMaximized = false;
  184. m_maximizedViewId = 0;
  185. if (pViewPane && m_maximizedView)
  186. {
  187. MoveViewport(m_maximizedView, pViewPane, viewClass);
  188. }
  189. if (m_maximizedView)
  190. {
  191. m_maximizedView->setVisible(false);
  192. }
  193. if (m_splitWnd)
  194. {
  195. m_splitWnd->setVisible(true);
  196. SetMainWidget(m_splitWnd);
  197. FocusFirstLayoutViewPane(m_splitWnd);
  198. }
  199. }
  200. }
  201. QString CLayoutWnd::ViewportTypeToClassName(EViewportType viewType)
  202. {
  203. QtViewPane* pane = QtViewPaneManager::instance()->GetViewportPane(viewType);
  204. return pane ? pane->m_name : QString();
  205. }
  206. void CLayoutWnd::CreateLayoutView(CLayoutSplitter* wndSplitter, int row, int col, int id, EViewportType viewType)
  207. {
  208. QString viewClassName = ViewportTypeToClassName(viewType);
  209. wndSplitter->CreateLayoutView(row, col, id);
  210. m_viewType[id] = viewClassName;
  211. }
  212. //////////////////////////////////////////////////////////////////////////
  213. void CLayoutWnd::CreateLayout(EViewLayout layout, bool bBindViewports, EViewportType defaultView)
  214. {
  215. UnbindViewports();
  216. m_layout = layout;
  217. m_bMaximized = false;
  218. if (m_splitWnd)
  219. {
  220. m_splitWnd->setVisible(false);
  221. delete m_splitWnd;
  222. }
  223. delete m_splitWnd2;
  224. delete m_splitWnd3;
  225. if (m_maximizedView)
  226. {
  227. m_maximizedView->setVisible(false);
  228. }
  229. QRect rcView = rect();
  230. // Ensure we delete our old view immediately so it can relinquish its backing ViewportContext
  231. if (m_maximizedView)
  232. {
  233. delete m_maximizedView;
  234. }
  235. m_maximizedView = new CLayoutViewPane(this);
  236. m_maximizedView->SetId(0);
  237. m_maximizedView->setGeometry(rcView);
  238. m_maximizedView->setVisible(false);
  239. m_maximizedView->SetFullscren(true);
  240. if (!CViewManager::IsMultiViewportEnabled())
  241. {
  242. m_viewType[0] = ViewportTypeToClassName(defaultView);
  243. if (bBindViewports)
  244. {
  245. MaximizeViewport(0);
  246. }
  247. }
  248. else
  249. {
  250. switch (layout)
  251. {
  252. case ET_Layout0:
  253. m_viewType[0] = ViewportTypeToClassName(defaultView);
  254. if (bBindViewports)
  255. {
  256. MaximizeViewport(0);
  257. }
  258. break;
  259. case ET_Layout1:
  260. m_splitWnd = new CLayoutSplitter(this);
  261. m_splitWnd->setOrientation(Qt::Horizontal);
  262. CreateLayoutView(m_splitWnd, 0, 0, 2, ET_ViewportCamera);
  263. CreateLayoutView(m_splitWnd, 0, 1, 1, defaultView);
  264. break;
  265. case ET_Layout2:
  266. m_splitWnd = new CLayoutSplitter(this);
  267. m_splitWnd->setOrientation(Qt::Vertical);
  268. CreateLayoutView(m_splitWnd, 0, 0, 2, ET_ViewportCamera);
  269. CreateLayoutView(m_splitWnd, 1, 0, 1, defaultView);
  270. break;
  271. case ET_Layout3:
  272. m_splitWnd = new CLayoutSplitter(this);
  273. m_splitWnd->setOrientation(Qt::Horizontal);
  274. CreateLayoutView(m_splitWnd, 0, 1, 1, defaultView);
  275. m_splitWnd2 = new CLayoutSplitter;
  276. m_splitWnd2->setOrientation(Qt::Vertical);
  277. m_splitWnd->insertWidget(0, m_splitWnd2);
  278. CreateLayoutView(m_splitWnd2, 0, 0, 2, ET_ViewportCamera);
  279. CreateLayoutView(m_splitWnd2, 1, 0, 3, ET_ViewportCamera);
  280. break;
  281. case ET_Layout4:
  282. m_splitWnd = new CLayoutSplitter(this);
  283. m_splitWnd->setOrientation(Qt::Horizontal);
  284. CreateLayoutView(m_splitWnd, 0, 0, 1, defaultView);
  285. m_splitWnd2 = new CLayoutSplitter;
  286. m_splitWnd2->setOrientation(Qt::Vertical);
  287. m_splitWnd->insertWidget(1, m_splitWnd2);
  288. CreateLayoutView(m_splitWnd2, 0, 0, 2, ET_ViewportCamera);
  289. CreateLayoutView(m_splitWnd2, 1, 0, 3, ET_ViewportCamera);
  290. break;
  291. case ET_Layout5:
  292. m_splitWnd = new CLayoutSplitter(this);
  293. m_splitWnd->setOrientation(Qt::Vertical);
  294. CreateLayoutView(m_splitWnd, 1, 0, 1, defaultView);
  295. m_splitWnd2 = new CLayoutSplitter;
  296. m_splitWnd2->setOrientation(Qt::Horizontal);
  297. m_splitWnd->insertWidget(0, m_splitWnd2);
  298. CreateLayoutView(m_splitWnd2, 0, 0, 2, ET_ViewportCamera);
  299. CreateLayoutView(m_splitWnd2, 0, 1, 3, ET_ViewportCamera);
  300. break;
  301. case ET_Layout6:
  302. m_splitWnd = new CLayoutSplitter(this);
  303. m_splitWnd->setOrientation(Qt::Vertical);
  304. CreateLayoutView(m_splitWnd, 0, 0, 1, defaultView);
  305. m_splitWnd2 = new CLayoutSplitter;
  306. m_splitWnd->insertWidget(1, m_splitWnd2);
  307. CreateLayoutView(m_splitWnd2, 0, 0, 2, ET_ViewportCamera);
  308. CreateLayoutView(m_splitWnd2, 0, 1, 3, ET_ViewportCamera);
  309. break;
  310. case ET_Layout7:
  311. m_splitWnd = new CLayoutSplitter(this);
  312. m_splitWnd->setOrientation(Qt::Horizontal);
  313. m_splitWnd2 = new CLayoutSplitter;
  314. m_splitWnd2->setOrientation(Qt::Vertical);
  315. m_splitWnd3 = new CLayoutSplitter;
  316. m_splitWnd3->setOrientation(Qt::Vertical);
  317. m_splitWnd->addWidget(m_splitWnd2);
  318. m_splitWnd->addWidget(m_splitWnd3);
  319. CreateLayoutView(m_splitWnd2, 0, 0, 2, ET_ViewportCamera);
  320. CreateLayoutView(m_splitWnd3, 0, 1, 3, ET_ViewportCamera);
  321. CreateLayoutView(m_splitWnd2, 1, 0, 4, ET_ViewportCamera);
  322. CreateLayoutView(m_splitWnd3, 1, 1, 1, defaultView);
  323. connect(m_splitWnd2, &QSplitter::splitterMoved, m_splitWnd3, &CLayoutSplitter::otherSplitterMoved);
  324. connect(m_splitWnd3, &QSplitter::splitterMoved, m_splitWnd2, &CLayoutSplitter::otherSplitterMoved);
  325. break;
  326. case ET_Layout8:
  327. m_splitWnd = new CLayoutSplitter(this);
  328. m_splitWnd->setOrientation(Qt::Vertical);
  329. CreateLayoutView(m_splitWnd, 1, 0, 1, defaultView);
  330. m_splitWnd2 = new CLayoutSplitter;
  331. m_splitWnd2->setOrientation(Qt::Horizontal);
  332. m_splitWnd->insertWidget(0, m_splitWnd2);
  333. CreateLayoutView(m_splitWnd2, 0, 0, 2, ET_ViewportCamera);
  334. CreateLayoutView(m_splitWnd2, 0, 1, 3, ET_ViewportCamera);
  335. CreateLayoutView(m_splitWnd2, 0, 2, 4, ET_ViewportCamera);
  336. break;
  337. default:
  338. CLogFile::FormatLine("Trying to Create Unknown Layout %d", (int)layout);
  339. QMessageBox::critical(this, QString(), tr("Trying to Create Unknown Layout"));
  340. break;
  341. }
  342. ;
  343. }
  344. if (m_splitWnd)
  345. {
  346. m_splitWnd->setGeometry(rcView);
  347. m_splitWnd->setVisible(true);
  348. FocusFirstLayoutViewPane(m_splitWnd);
  349. SetMainWidget(m_splitWnd);
  350. }
  351. if (bBindViewports && !m_bMaximized)
  352. {
  353. BindViewports();
  354. }
  355. }
  356. //////////////////////////////////////////////////////////////////////////
  357. void CLayoutWnd::SaveConfig()
  358. {
  359. QSettings settings;
  360. settings.beginGroup(GetConfigGroupName());
  361. settings.setValue("Layout", static_cast<int>(m_layout));
  362. settings.setValue("Maximized", m_maximizedViewId);
  363. QString str;
  364. for (int i = 1; i < MAX_VIEWPORTS; i++)
  365. {
  366. str += QString::fromLatin1("%1,").arg(m_viewType[i]);
  367. }
  368. settings.setValue("Viewports", str);
  369. }
  370. //////////////////////////////////////////////////////////////////////////
  371. bool CLayoutWnd::LoadConfig()
  372. {
  373. QSettings settings;
  374. settings.beginGroup(GetConfigGroupName());
  375. int layout = settings.value("Layout", -1).toInt();
  376. int maximizedView = settings.value("Maximized", 0).toInt();
  377. if (layout < 0)
  378. {
  379. return false;
  380. }
  381. CreateLayout((EViewLayout)layout, false);
  382. if (m_splitWnd)
  383. {
  384. const QString str = settings.value("Viewports").toString();
  385. int nIndex = 1;
  386. for (auto resToken : str.split(","))
  387. {
  388. if (nIndex >= MAX_VIEWPORTS)
  389. {
  390. break;
  391. }
  392. if (!resToken.isEmpty())
  393. {
  394. m_viewType[nIndex] = resToken;
  395. }
  396. nIndex++;
  397. }
  398. }
  399. BindViewports();
  400. if (maximizedView || layout == ET_Layout0)
  401. {
  402. MaximizeViewport(maximizedView);
  403. }
  404. return true;
  405. }
  406. //////////////////////////////////////////////////////////////////////////
  407. const char* CLayoutWnd::GetConfigGroupName()
  408. {
  409. return "ViewportLayout";
  410. }
  411. unsigned int CLayoutWnd::GetViewPaneCount()
  412. {
  413. // If there's a maximized viewport, then exactly 1 is visible.
  414. if (m_bMaximized)
  415. {
  416. return 1;
  417. }
  418. unsigned int numPanes = 0;
  419. // Otherwise, go searching through and count how many are visible.
  420. for (QSplitter* splitter : { m_splitWnd, m_splitWnd2, m_splitWnd3 })
  421. {
  422. if (splitter)
  423. {
  424. for (int i = 0; i < splitter->count(); ++i)
  425. {
  426. if (qobject_cast<CLayoutViewPane*>(splitter->widget(i)))
  427. {
  428. numPanes++;
  429. }
  430. }
  431. }
  432. }
  433. return numPanes;
  434. }
  435. CLayoutViewPane* CLayoutWnd::GetViewPaneByIndex(unsigned int index)
  436. {
  437. // If there's a maximized viewport, return it if index 0 is requested.
  438. // (All other index values are invalid in this state)
  439. if (m_bMaximized)
  440. {
  441. if (index == 0)
  442. {
  443. return m_maximizedView;
  444. }
  445. return nullptr;
  446. }
  447. unsigned int curIndex = 0;
  448. // Otherwise, go searching through until we've found the proper number of panes
  449. // and return the one at the correct index.
  450. for (QSplitter* splitter : { m_splitWnd, m_splitWnd2, m_splitWnd3 })
  451. {
  452. if (splitter)
  453. {
  454. for (int i = 0; i < splitter->count(); ++i)
  455. {
  456. if (QWidget* widget = splitter->widget(i))
  457. {
  458. if (CLayoutViewPane* pane = qobject_cast<CLayoutViewPane*>(widget))
  459. {
  460. if (curIndex == index)
  461. {
  462. return pane;
  463. }
  464. curIndex++;
  465. }
  466. }
  467. }
  468. }
  469. }
  470. return nullptr;
  471. }
  472. //////////////////////////////////////////////////////////////////////////
  473. CLayoutViewPane* CLayoutWnd::GetViewPane(int id)
  474. {
  475. QList<QSplitter*> splitters({ m_splitWnd, m_splitWnd2, m_splitWnd3 });
  476. for (QSplitter* splitter : splitters)
  477. {
  478. if (!splitter)
  479. {
  480. continue;
  481. }
  482. for (int i = 0; i < splitter->count(); ++i)
  483. {
  484. QWidget* widget = splitter->widget(i);
  485. if (widget == nullptr)
  486. {
  487. continue;
  488. }
  489. if (CLayoutViewPane* pane = qobject_cast<CLayoutViewPane*>(widget))
  490. {
  491. if (pane && pane->GetId() == id)
  492. {
  493. return pane;
  494. }
  495. }
  496. }
  497. }
  498. return nullptr;
  499. }
  500. //////////////////////////////////////////////////////////////////////////
  501. CLayoutViewPane* CLayoutWnd::FindViewByClass(const QString& viewClassName)
  502. {
  503. if (m_viewType[0] == viewClassName)
  504. {
  505. return m_maximizedView;
  506. }
  507. // Starts from 1, 0 is the maximized view.
  508. for (int i = 1; i < MAX_VIEWPORTS; i++)
  509. {
  510. if (m_viewType[i] == viewClassName)
  511. {
  512. return GetViewPane(i);
  513. }
  514. }
  515. return nullptr;
  516. }
  517. //////////////////////////////////////////////////////////////////////////
  518. bool CLayoutWnd::CycleViewport(EViewportType from, EViewportType to)
  519. {
  520. const QString viewClassName = ViewportTypeToClassName(from);
  521. CLayoutViewPane* vp = FindViewByClass(viewClassName);
  522. if (m_layout == ET_Layout0 && !vp)
  523. {
  524. if (m_maximizedView)
  525. {
  526. if (m_maximizedView->GetViewClass() == viewClassName)
  527. {
  528. vp = m_maximizedView;
  529. }
  530. }
  531. }
  532. if (vp)
  533. {
  534. BindViewport(vp, ViewportTypeToClassName(to));
  535. return true;
  536. }
  537. return false;
  538. }
  539. //////////////////////////////////////////////////////////////////////////
  540. void CLayoutWnd::ResetLayout()
  541. {
  542. // reset the layout settings. Mfc doesn't have a mechanism to delete settings, that I can find, so we use Qt.
  543. m_settings->beginGroup("Editor");
  544. m_settings->remove(GetConfigGroupName());
  545. m_settings->endGroup();
  546. // restore the default layout
  547. CreateLayout(ET_Layout0);
  548. }
  549. //////////////////////////////////////////////////////////////////////////
  550. void CLayoutWnd::Cycle2DViewport()
  551. {
  552. // Cycle between 3 2D viewports.
  553. switch (m_layout)
  554. {
  555. case ET_Layout0:
  556. if (CycleViewport(ET_ViewportCamera, ET_ViewportXY))
  557. {
  558. return;
  559. }
  560. if (CycleViewport(ET_ViewportXY, ET_ViewportXZ))
  561. {
  562. return;
  563. }
  564. if (CycleViewport(ET_ViewportXZ, ET_ViewportYZ))
  565. {
  566. return;
  567. }
  568. if (CycleViewport(ET_ViewportYZ, ET_ViewportCamera))
  569. {
  570. return;
  571. }
  572. break;
  573. default:
  574. if (CycleViewport(ET_ViewportXY, ET_ViewportXZ))
  575. {
  576. return;
  577. }
  578. if (CycleViewport(ET_ViewportXZ, ET_ViewportYZ))
  579. {
  580. return;
  581. }
  582. if (CycleViewport(ET_ViewportYZ, ET_ViewportXY))
  583. {
  584. return;
  585. }
  586. break;
  587. }
  588. }
  589. //////////////////////////////////////////////////////////////////////////
  590. void CLayoutWnd::OnDestroy()
  591. {
  592. if (m_maximizedView)
  593. {
  594. delete m_maximizedView;
  595. m_maximizedView = nullptr;
  596. }
  597. }
  598. void CLayoutWnd::FocusFirstLayoutViewPane(CLayoutSplitter* splitter)
  599. {
  600. // When starting in multi-layout mode we focus the first CLayoutViewPane
  601. // Note that splitter->widget(0) might be another splitter, not a CLayoutViewPane
  602. if (splitter)
  603. {
  604. if (auto view = splitter->findChild<CLayoutViewPane*>())
  605. {
  606. view->setFocus();
  607. MainWindow::instance()->SetActiveView(view);
  608. }
  609. }
  610. }
  611. void CLayoutWnd::MoveViewport(CLayoutViewPane* from, CLayoutViewPane* to, const QString& viewClassName)
  612. {
  613. // First detach from old pane, allowing the viewport to be disconnected from the event bus
  614. // This must be done before re-binding the viewport and connecting to the bus with a new id
  615. auto viewport = from->GetViewport();
  616. from->DetachViewport();
  617. BindViewport(to, viewClassName, viewport);
  618. }
  619. static CLayoutViewPane* layoutViewPaneForChild(QObject* child)
  620. {
  621. CLayoutViewPane* result = nullptr;
  622. while (child)
  623. {
  624. result = qobject_cast<CLayoutViewPane*>(child);
  625. if (result)
  626. {
  627. break;
  628. }
  629. child = child->parent();
  630. }
  631. return result;
  632. }
  633. void CLayoutWnd::OnFocusChanged(QWidget* /* oldWidget */, QWidget* newWidget)
  634. {
  635. if (CLayoutViewPane* layoutViewPane = layoutViewPaneForChild(newWidget))
  636. {
  637. MainWindow::instance()->SetActiveView(layoutViewPane);
  638. }
  639. }
  640. #include <moc_LayoutWnd.cpp>