swift
cockpitcomponent.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 <QtGlobal>
8 
9 #include "ui_cockpitcomponent.h"
10 
13 #include "gui/dockwidgetinfoarea.h"
14 #include "gui/showhidebar.h"
15 
16 namespace swift::gui::components
17 {
20  {
21  ui->setupUi(this);
22  ui->wip_CockpitComPanelShowHideBar->setVisible(false);
23  m_minHeightInfoArea = ui->comp_CockpitInfoArea->minimumHeight();
24 
25  connect(ui->wip_CockpitComPanelShowHideBar, &CShowHideBar::toggleShowHide, this,
26  &CCockpitComponent::onToggleShowHideDetails, Qt::QueuedConnection);
27  connect(ui->comp_CockpitComComponent, &CCockpitComComponent::requestCom1TextMessage, this,
28  &CCockpitComponent::onRequestTextMessageCom1, Qt::QueuedConnection);
29  connect(ui->comp_CockpitComComponent, &CCockpitComComponent::requestCom2TextMessage, this,
30  &CCockpitComponent::onRequestTextMessageCom2, Qt::QueuedConnection);
31  }
32 
34 
36  {
37  Q_ASSERT(parentDockableWidget);
38  bool ok = CEnableForDockWidgetInfoArea::setParentDockWidgetInfoArea(parentDockableWidget);
39  if (ok && parentDockableWidget)
40  {
41  ok = connect(parentDockableWidget, &QDockWidget::topLevelChanged, this,
42  &CCockpitComponent::onToggleFloating, Qt::QueuedConnection);
43  }
44  return ok;
45  }
46 
47  bool CCockpitComponent::isInfoAreaShown() const { return ui->wip_CockpitComPanelShowHideBar->isShown(); }
48 
50  {
51  ui->comp_CockpitComComponent->setTransponderModeStateIdent();
52  }
53 
55  {
56  ui->comp_CockpitInfoArea->selectArea(CCockpitInfoAreaComponent::InfoAreaAudio);
57  }
58 
59  void CCockpitComponent::onToggleShowHideDetails(bool show)
60  {
61  // use the toggle method to set the sizes
62  this->toggleShowHideDetails(show, true);
63  }
64 
65  void CCockpitComponent::toggleShowHideDetails(bool show, bool considerCurrentSize)
66  {
67  Q_ASSERT(this->isParentDockWidgetFloating()); // show hide should not be visible if docked
68  Q_ASSERT(this->window());
69  if (!this->isParentDockWidgetFloating()) { return; }
70 
71  // manually setting size, all other approaches failed
72  static const QSize defaultSizeShown(500, 600);
73  static const QSize defaultSizeHidden(300, 150);
74 
75  // keep old size
76  const QSize manuallySetSize = this->window()->size();
77 
78  // hide area
79  ui->comp_CockpitInfoArea->setVisible(show);
80 
81  // adjust size
82  if (show)
83  {
84  ui->comp_CockpitInfoArea->setMinimumHeight(m_minHeightInfoArea);
85  if (m_sizeFloatingShown.isValid())
86  {
87  this->window()->resize(m_sizeFloatingShown);
88  if (considerCurrentSize) { m_sizeFloatingHidden = manuallySetSize; } // for next time
89  }
90  else
91  {
92  // manually setting size, all other approaches failed
93  this->window()->resize(defaultSizeShown);
94  m_sizeFloatingShown = this->window()->size();
95  }
96  }
97  else
98  {
99  ui->comp_CockpitInfoArea->setMinimumHeight(0);
100  this->window()->setMinimumSize(defaultSizeHidden);
101  if (m_sizeFloatingHidden.isValid())
102  {
103  this->window()->resize(m_sizeFloatingHidden);
104  if (considerCurrentSize) { m_sizeFloatingShown = manuallySetSize; }
105  }
106  else
107  {
108  // manually setting size, all other approaches failed
109  this->window()->resize(defaultSizeHidden);
110  m_sizeFloatingHidden = this->window()->size();
111  }
112  }
113  }
114 
116  {
117  if (event) { emit requestTextMessageEntryTab(TextMessagesAll); }
118  COverlayMessagesFrame::mouseDoubleClickEvent(event);
119  }
120 
121  void CCockpitComponent::onRequestTextMessageCom1() { emit requestTextMessageEntryTab(TextMessagesCom1); }
122 
123  void CCockpitComponent::onRequestTextMessageCom2() { emit requestTextMessageEntryTab(TextMessagesCom2); }
124 
125  void CCockpitComponent::onATCStationsChanged()
126  {
127  // void
128  }
129 
130  void CCockpitComponent::onToggleFloating(bool floating)
131  {
132  ui->wip_CockpitComPanelShowHideBar->setVisible(floating);
133  if (floating)
134  {
135  // use the toggle method to set the sizes
136  this->toggleShowHideDetails(this->isInfoAreaShown(), false);
137  }
138  else
139  {
140  const QSize sizeMinimum(200, 100); // set when docked, must fit into parent info area
141  ui->comp_CockpitInfoArea->setVisible(true);
142  this->window()->setMinimumSize(sizeMinimum);
143  }
144  }
145 } // namespace swift::gui::components
Specialized class for dock widgets serving as info area.
bool isParentDockWidgetFloating() const
Is the parent dockable widget floating?
virtual bool setParentDockWidgetInfoArea(CDockWidgetInfoArea *parentDockableWidget)
Corresponding dockable widget in info area.
Using this class provides a QFrame with the overlay and dock widget functionality already integrated.
void requestTextMessageEntryTab(components::TextMessageTab tab)
Request an text message entry.
void toggleShowHide(bool show)
Show or hide cockpit details.
void requestCom1TextMessage()
Request COM text messages.
void requestCom2TextMessage()
Request COM text messages.
Cockpit component: COM unit, show / hide bar, voice rooms.
bool isInfoAreaShown() const
Is the info area shown?
virtual bool setParentDockWidgetInfoArea(swift::gui::CDockWidgetInfoArea *parentDockableWidget)
Corresponding dockable widget in info area.
void setSelectedTransponderModeStateIdent()
Set to ident (transponder state)
CCockpitComponent(QWidget *parent=nullptr)
Constructor.
virtual void mouseDoubleClickEvent(QMouseEvent *event)
High level reusable GUI components.
Definition: aboutdialog.cpp:13