swift
Loading...
Searching...
No Matches
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
14#include "gui/showhidebar.h"
15
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);
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())
70 {
71 return;
72 }
73
74 // manually setting size, all other approaches failed
75 static const QSize defaultSizeShown(500, 600);
76 static const QSize defaultSizeHidden(300, 150);
77
78 // keep old size
79 const QSize manuallySetSize = this->window()->size();
80
81 // hide area
82 ui->comp_CockpitInfoArea->setVisible(show);
83
84 // adjust size
85 if (show)
86 {
87 ui->comp_CockpitInfoArea->setMinimumHeight(m_minHeightInfoArea);
88 if (m_sizeFloatingShown.isValid())
89 {
90 this->window()->resize(m_sizeFloatingShown);
91 if (considerCurrentSize)
92 {
93 m_sizeFloatingHidden = manuallySetSize;
94 } // for next time
95 }
96 else
97 {
98 // manually setting size, all other approaches failed
99 this->window()->resize(defaultSizeShown);
100 m_sizeFloatingShown = this->window()->size();
101 }
102 }
103 else
104 {
105 ui->comp_CockpitInfoArea->setMinimumHeight(0);
106 this->window()->setMinimumSize(defaultSizeHidden);
107 if (m_sizeFloatingHidden.isValid())
108 {
109 this->window()->resize(m_sizeFloatingHidden);
110 if (considerCurrentSize)
111 {
112 m_sizeFloatingShown = manuallySetSize;
113 }
114 }
115 else
116 {
117 // manually setting size, all other approaches failed
118 this->window()->resize(defaultSizeHidden);
119 m_sizeFloatingHidden = this->window()->size();
120 }
121 }
122 }
123
132
133 void CCockpitComponent::onRequestTextMessageCom1() { emit requestTextMessageEntryTab(TextMessagesCom1); }
134
135 void CCockpitComponent::onRequestTextMessageCom2() { emit requestTextMessageEntryTab(TextMessagesCom2); }
136
137 void CCockpitComponent::onATCStationsChanged()
138 {
139 // void
140 }
141
142 void CCockpitComponent::onToggleFloating(bool floating)
143 {
144 ui->wip_CockpitComPanelShowHideBar->setVisible(floating);
145 if (floating)
146 {
147 // use the toggle method to set the sizes
148 this->toggleShowHideDetails(this->isInfoAreaShown(), false);
149 }
150 else
151 {
152 const QSize sizeMinimum(200, 100); // set when docked, must fit into parent info area
153 ui->comp_CockpitInfoArea->setVisible(true);
154 this->window()->setMinimumSize(sizeMinimum);
155 }
156 }
157} // 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.
COverlayMessagesFrameEnableForDockWidgetInfoArea(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
Constructor.
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.
bool isInfoAreaShown() const
Is the info area shown?
bool setParentDockWidgetInfoArea(swift::gui::CDockWidgetInfoArea *parentDockableWidget)
Corresponding dockable widget in info area.
void setSelectedTransponderModeStateIdent()
Set to ident (transponder state).
CCockpitComponent(QWidget *parent=nullptr)
Constructor.
High level reusable GUI components.
void topLevelChanged(bool topLevel)
virtual bool event(QEvent *e) override
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
bool isValid() const const
QueuedConnection
QWidget(QWidget *parent, Qt::WindowFlags f)
void setMinimumSize(const QSize &)
virtual void mouseDoubleClickEvent(QMouseEvent *event)
void show()
QWidget * window() const const