11 #include "ui_atcbuttoncomponent.h"
18 using namespace swift::misc::aviation;
19 using namespace swift::misc::network;
21 using namespace swift::core::context;
25 CAtcButtonComponent::CAtcButtonComponent(QWidget *parent) : QFrame(parent), ui(new Ui::
CAtcButtonComponent)
31 &CAtcButtonComponent::onChangedAtcStations);
33 &CAtcButtonComponent::onConnectionStatusChanged);
36 this->setVisible(
false);
43 this->setVisible(
false);
44 this->setMinimumHeight(0);
47 if (m_maxNumber < 1) {
return; }
48 const int max = qMin(m_maxNumber, m_rows * m_cols);
50 if (stations.
isEmpty()) {
return; }
53 QGridLayout *layout =
new QGridLayout(
this);
55 layout->setObjectName(
"gl_CAtcButtonComponent");
56 layout->setSpacing(4);
57 layout->setContentsMargins(0, 0, 0, 0);
62 for (
const CAtcStation &station : std::as_const(stations))
67 if (!station.getCallsign().hasAtcSuffix()) {
continue; }
70 QPushButton *button =
new QPushButton(
this);
71 button->setText(station.getCallsignAsString());
72 if (m_withIcons) { button->setIcon(
CIcon(station.toIcon()).
toQIcon()); }
73 QObject::connect(button, &QPushButton::released,
this, &CAtcButtonComponent::onButtonClicked);
74 const CVariant atcv = CVariant::fromValue(station);
75 layout->addWidget(button, row, col++);
82 if (row == m_rows) {
break; }
88 const double a = added;
89 const double c = m_cols;
90 const int rows = qRound(ceil(a / c));
93 this->setVisible(
true);
94 this->setMinimumHeight(rows * 25);
102 if (setMaxElements) { m_maxNumber = rows * cols; }
105 void CAtcButtonComponent::onChangedAtcStations()
107 if (!m_backgroundUpdates) {
return; }
108 if (!this->isVisible()) {
return; }
118 void CAtcButtonComponent::onButtonClicked()
120 QPushButton *button = qobject_cast<QPushButton *>(QObject::sender());
121 if (!button) {
return; }
122 const CVariant v(button->property(
"atc"));
123 if (!v.isValid() || !v.canConvert<
CAtcStation>()) {
return; }
const context::IContextNetwork * getIContextNetwork() const
Direct access to contexts if a CCoreFacade has been initialized.
virtual swift::misc::aviation::CAtcStationList getClosestAtcStationsOnline(int number) const =0
The ATC list with online ATC controllers.
static void deleteLayout(QLayout *layout, bool deleteWidgets)
Delete hierarchy of layouts.
Value object for icons. An icon is stored in the global icon repository and identified by its index....
QIcon toQIcon() const
A QIcon.
bool isEmpty() const
Synonym for empty.
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
const QVariant & getQVariant() const
Return the internal QVariant.
Value object encapsulating information about an ATC station.
Value object for a list of ATC stations.
Value object encapsulating information about a connection status.
bool isDisconnected() const
Query status.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Backend services of the swift project, like dealing with the network or the simulators.
High level reusable GUI components.
Free functions in swift::misc.