swift
enablefordockwidgetinfoarea.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include <QDockWidget>
7 #include <QMetaObject>
8 #include <QObject>
9 #include <QPointer>
10 #include <QTimer>
11 #include <QtGlobal>
12 
13 #include "gui/dockwidgetinfoarea.h"
15 #include "gui/guiutility.h"
16 #include "gui/infoarea.h"
17 
18 using namespace swift::misc::aviation;
19 using namespace swift::gui;
20 
21 namespace swift::gui
22 {
23  CEnableForDockWidgetInfoArea::CEnableForDockWidgetInfoArea(CDockWidgetInfoArea *parentInfoArea)
24  {
25  // it the parent is already an info area at this time, we keep it
26  // otherwise we expect the info area to set it later
27  m_parentDockableInfoArea = parentInfoArea;
28  }
29 
30  bool CEnableForDockWidgetInfoArea::setParentDockWidgetInfoArea(CDockWidgetInfoArea *parentDockableWidget)
31  {
32  // sanity check
33  if (m_parentDockableInfoArea)
34  {
35  // we already have a value
36  // changes should not happen
37  Q_ASSERT_X(m_parentDockableInfoArea == parentDockableWidget, Q_FUNC_INFO,
38  "Reassigned parent dock widget area");
39  return m_parentDockableInfoArea == parentDockableWidget;
40  }
41 
42  m_parentDockableInfoArea = parentDockableWidget;
43  QMetaObject::Connection con = QDockWidget::connect(parentDockableWidget, &QDockWidget::destroyed, [this] {
44  // break dependency to dockable widget
45  m_parentDockableInfoArea = nullptr;
46  });
47  Q_ASSERT_X(con, Q_FUNC_INFO, "Connection failed");
48  m_connections.append(con);
49  return true;
50  }
51 
52  CInfoArea *CEnableForDockWidgetInfoArea::getParentInfoArea() const
53  {
54  Q_ASSERT(m_parentDockableInfoArea);
55  if (!m_parentDockableInfoArea) { return nullptr; }
56  return m_parentDockableInfoArea->getParentInfoArea();
57  }
58 
59  bool CEnableForDockWidgetInfoArea::isParentDockWidgetFloating() const
60  {
61  if (!m_parentDockableInfoArea) { return false; } // not floating if not yet initialized
62  return m_parentDockableInfoArea->isFloating();
63  }
64 
65  bool CEnableForDockWidgetInfoArea::isVisibleWidget() const
66  {
67  if (!m_parentDockableInfoArea)
68  {
69  return false;
70  } // can happen function is used while dock widget not yet fully initialized
71  return m_parentDockableInfoArea->isVisibleWidget();
72  }
73 
74  CEnableForFramelessWindow *CEnableForDockWidgetInfoArea::mainApplicationWindow() const
75  {
76  CEnableForFramelessWindow *mw = CGuiUtility::mainFramelessEnabledWindow();
77  return mw;
78  }
79 
80  QWidget *CEnableForDockWidgetInfoArea::mainApplicationWindowWidget() const
81  {
82  CEnableForFramelessWindow *mw = this->mainApplicationWindow();
83  return mw ? mw->getWidget() : nullptr;
84  }
85 
86  void CEnableForDockWidgetInfoArea::displayMyself()
87  {
88  // if we are already visible, we are done
89  if (this->isVisibleWidget()) { return; }
90 
91  // select myself
92  if (this->getParentInfoArea()) { this->getParentInfoArea()->selectArea(this->getDockWidgetInfoArea()); }
93  }
94 } // namespace swift::gui
Specialized class for dock widgets serving as info area.
Main window which can be frameless.
QWidget * getWidget() const
Corresponding QMainWindow.
Info area, hosting dockable widgets.
Definition: infoarea.h:41
GUI related classes.