mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 06:35:52 +08:00
As of workshop RW/KB
* Allow to "jump" to text message channel from ATC / aircraft * changed timer connections for components to new SLOT syntax * housekeeping: ** new function in network context for station by callsign ** refactored textmessage component, allow to select tab by slot ** wired up signal / slots in main GUI ** removed unused functions ** allow to select area and "myself" in infoarea
This commit is contained in:
@@ -32,7 +32,7 @@ namespace BlackGui
|
||||
ui->setupUi(this);
|
||||
this->tabBar()->setExpanding(false);
|
||||
this->ui->tvp_AirportsInRange->setResizeMode(CAirportView::ResizingOnce);
|
||||
m_updateTimer = new CUpdateTimer(SLOT(update()), this);
|
||||
m_updateTimer = new CUpdateTimer(&CAircraftComponent::update, this);
|
||||
|
||||
connect(this->ui->tvp_AircraftInRange, &CAircraftView::rowCountChanged, this, &CAircraftComponent::ps_onRowCountChanged);
|
||||
connect(this->ui->tvp_AirportsInRange, &CAircraftView::rowCountChanged, this, &CAircraftComponent::ps_onRowCountChanged);
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace BlackGui
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->tabBar()->setExpanding(false);
|
||||
this->m_updateTimer = new CUpdateTimer(SLOT(update()), this);
|
||||
this->m_updateTimer = new CUpdateTimer(&CAtcStationComponent::update, this);
|
||||
|
||||
// some icons
|
||||
this->ui->pb_AtcStationsAtisReload->setIcon(CIcons::atis());
|
||||
@@ -275,6 +275,14 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
const QString &CAtcStationComponent::originator()
|
||||
{
|
||||
// string is generated once, the timestamp allows to use multiple
|
||||
// components (as long as they are not generated at the same ms)
|
||||
static const QString o = QString("ATCSTATIOCOMPONENT:").append(QString::number(QDateTime::currentMSecsSinceEpoch()));
|
||||
return o;
|
||||
}
|
||||
|
||||
void CAtcStationComponent::ps_onlineAtcStationSelected(QModelIndex index)
|
||||
{
|
||||
this->ui->te_AtcStationsOnlineInfo->setText(""); // reset
|
||||
|
||||
@@ -118,6 +118,7 @@ namespace BlackGui
|
||||
|
||||
private:
|
||||
void updateTreeView();
|
||||
const QString &originator();
|
||||
|
||||
QScopedPointer<Ui::CAtcStationComponent> ui;
|
||||
CUpdateTimer *m_updateTimer = nullptr;
|
||||
@@ -126,14 +127,6 @@ namespace BlackGui
|
||||
QDateTime m_timestampLastReadBookedStations = CUpdateTimer::epoch(); //!< stations read
|
||||
QDateTime m_timestampBookedStationsChanged = CUpdateTimer::epoch(); //!< stations marked as changed
|
||||
|
||||
const QString &originator()
|
||||
{
|
||||
// string is generated once, the timestamp allows to use multiple
|
||||
// components (as long as they are not generated at the same ms)
|
||||
static const QString o = QString("ATCSTATIOCOMPONENT:").append(QString::number(QDateTime::currentMSecsSinceEpoch()));
|
||||
return o;
|
||||
}
|
||||
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -79,5 +79,17 @@ namespace BlackGui
|
||||
return mw ? mw->getWidget() : nullptr;
|
||||
}
|
||||
|
||||
void CEnableForDockWidgetInfoArea::displayMyself()
|
||||
{
|
||||
// if we are already visible, we are done
|
||||
if (this->isVisibleWidget()) { return; }
|
||||
|
||||
// select myself
|
||||
if (getParentInfoArea())
|
||||
{
|
||||
getParentInfoArea()->selectArea(this->getDockWidgetInfoArea());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -55,6 +55,9 @@ namespace BlackGui
|
||||
//! Main application window widget if any
|
||||
QWidget *mainApplicationWindowWidget() const;
|
||||
|
||||
//! Display myself
|
||||
void displayMyself();
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
//! \remarks Normally the infoa area will be provided later \sa setParentDockWidgetInfoArea
|
||||
|
||||
@@ -45,6 +45,11 @@ namespace BlackGui
|
||||
return this->ui->comp_Aircraft;
|
||||
}
|
||||
|
||||
CMappingComponent *CMainInfoAreaComponent::getMappingComponet()
|
||||
{
|
||||
return this->ui->comp_Mappings;
|
||||
}
|
||||
|
||||
CUserComponent *CMainInfoAreaComponent::getUserComponent()
|
||||
{
|
||||
return this->ui->comp_Users;
|
||||
|
||||
@@ -62,6 +62,9 @@ namespace BlackGui
|
||||
//! Aircrafts
|
||||
CAircraftComponent *getAircraftComponent();
|
||||
|
||||
//! Mappings
|
||||
CMappingComponent *getMappingComponet();
|
||||
|
||||
//! User component
|
||||
CUserComponent *getUserComponent();
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace BlackGui
|
||||
this->ui->tvp_LiveData->setIconMode(true);
|
||||
this->ui->tvp_LiveData->setAutoResizeFrequency(10); // only resize every n-th time
|
||||
this->addOrUpdateByName("info", "no data yet", CIcons::StandardIconWarning16);
|
||||
m_updateTimer = new CUpdateTimer(SLOT(update()), this);
|
||||
m_updateTimer = new CUpdateTimer(&CSimulatorComponent::update, this);
|
||||
}
|
||||
|
||||
CSimulatorComponent::~CSimulatorComponent()
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "blackmisc/notificationsounds.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/simplecommandparser.h"
|
||||
#include "blackmisc/simulation/simulatedaircraftlist.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QMenu>
|
||||
@@ -26,6 +27,7 @@ using namespace BlackMisc::Network;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Settings;
|
||||
using namespace BlackMisc::Simulation;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -48,7 +50,7 @@ namespace BlackGui
|
||||
CTextMessageComponent::~CTextMessageComponent()
|
||||
{ }
|
||||
|
||||
QWidget *CTextMessageComponent::getTabWidget(CTextMessageComponent::Tab tab)
|
||||
QWidget *CTextMessageComponent::getTabWidget(CTextMessageComponent::Tab tab) const
|
||||
{
|
||||
switch (tab)
|
||||
{
|
||||
@@ -67,9 +69,15 @@ namespace BlackGui
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Text messages received or send, append to GUI
|
||||
*/
|
||||
void CTextMessageComponent::selectTabWidget(CTextMessageComponent::Tab tab)
|
||||
{
|
||||
QWidget *w = getTabWidget(tab);
|
||||
if (w)
|
||||
{
|
||||
this->ui->tw_TextMessages->setCurrentWidget(w);
|
||||
}
|
||||
}
|
||||
|
||||
void CTextMessageComponent::displayTextMessage(const CTextMessageList &messages)
|
||||
{
|
||||
if (messages.isEmpty()) return;
|
||||
@@ -178,7 +186,7 @@ namespace BlackGui
|
||||
CCallsign cs = textMessage.getSenderCallsign();
|
||||
if (cs.isEmpty()) return false;
|
||||
QWidget *tab = this->findTextMessageTabByName(cs.getStringAsSet());
|
||||
if (!tab) return false;
|
||||
if (!tab) { return false; }
|
||||
return this->ui->tw_TextMessages->currentWidget() == tab;
|
||||
}
|
||||
else
|
||||
@@ -198,6 +206,11 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
bool CTextMessageComponent::isNetworkConnected() const
|
||||
{
|
||||
return this->getIContextNetwork() && this->getIContextNetwork()->isConnected() ;
|
||||
}
|
||||
|
||||
void CTextMessageComponent::showCurrentFrequenciesFromCockpit()
|
||||
{
|
||||
const CAircraft ownAircraft = this->getOwnAircraft();
|
||||
@@ -212,6 +225,12 @@ namespace BlackGui
|
||||
this->ui->tw_TextMessages->setTabText(this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesCOM2), f2);
|
||||
}
|
||||
|
||||
QWidget *CTextMessageComponent::addNewTextMessageTab(const CCallsign &callsign)
|
||||
{
|
||||
Q_ASSERT(!callsign.isEmpty());
|
||||
return addNewTextMessageTab(callsign.asString());
|
||||
}
|
||||
|
||||
QWidget *CTextMessageComponent::addNewTextMessageTab(const QString &tabName)
|
||||
{
|
||||
QWidget *newTab = new QWidget(this);
|
||||
@@ -242,10 +261,8 @@ namespace BlackGui
|
||||
if (!textMessage.isPrivateMessage()) { return; }
|
||||
CCallsign cs = textMessage.getRecipientCallsign();
|
||||
if (cs.isEmpty()) { return; }
|
||||
QString csStr(cs.asString());
|
||||
QWidget *tab = this->findTextMessageTabByName(csStr);
|
||||
if (tab == nullptr) { tab = this->findTextMessageTabByName(csStr); }
|
||||
if (tab == nullptr) { tab = this->addNewTextMessageTab(csStr); }
|
||||
QWidget *tab = this->findTextMessageTabByCallsign(cs);
|
||||
if (tab == nullptr) { tab = this->addNewTextMessageTab(cs); }
|
||||
Q_ASSERT(tab != nullptr);
|
||||
CTextMessageTextEdit *textEdit = tab->findChild<CTextMessageTextEdit *>();
|
||||
Q_ASSERT(textEdit != nullptr);
|
||||
@@ -259,6 +276,34 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
const CAircraft CTextMessageComponent::getOwnAircraft() const
|
||||
{
|
||||
Q_ASSERT(this->getIContextOwnAircraft());
|
||||
return this->getIContextOwnAircraft()->getOwnAircraft();
|
||||
}
|
||||
|
||||
QWidget *CTextMessageComponent::findTextMessageTabByCallsign(const CCallsign &callsign, bool callsignResolution) const
|
||||
{
|
||||
QWidget *w = findTextMessageTabByName(callsign.asString());
|
||||
if (w) { return w; }
|
||||
if (!callsignResolution) { return nullptr; }
|
||||
|
||||
// resolve callsign
|
||||
CAtcStation station(getIContextNetwork()->getOnlineStationForCallsign(callsign));
|
||||
if (!station.getCallsign().isEmpty())
|
||||
{
|
||||
if (this->getOwnAircraft().getCom1System().isActiveFrequencyWithin25kHzChannel(station.getFrequency()))
|
||||
{
|
||||
return getTabWidget(TextMessagesCom1);
|
||||
}
|
||||
else if (this->getOwnAircraft().getCom2System().isActiveFrequencyWithin25kHzChannel(station.getFrequency()))
|
||||
{
|
||||
return getTabWidget(TextMessagesCom2);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QWidget *CTextMessageComponent::findTextMessageTabByName(const QString &name) const
|
||||
{
|
||||
if (name.isEmpty()) { return nullptr; }
|
||||
@@ -400,5 +445,30 @@ namespace BlackGui
|
||||
return false; // we never handle the message directly, but forward it
|
||||
}
|
||||
|
||||
void CTextMessageComponent::showCorrespondingTab(const CCallsign &callsign)
|
||||
{
|
||||
Q_ASSERT(getIContextOwnAircraft());
|
||||
Q_ASSERT(getIContextNetwork());
|
||||
|
||||
if (callsign.isEmpty())
|
||||
{
|
||||
CLogMessage(this).warning("No callsign to display text message");
|
||||
return;
|
||||
}
|
||||
QWidget *w = findTextMessageTabByCallsign(callsign, true);
|
||||
if (!w && getIContextNetwork())
|
||||
{
|
||||
CSimulatedAircraft aircraft(getIContextNetwork()->getAircraftForCallsign(callsign));
|
||||
if (!aircraft.getCallsign().isEmpty())
|
||||
{
|
||||
// we assume a private message
|
||||
w = this->addNewTextMessageTab(aircraft.getCallsign());
|
||||
}
|
||||
}
|
||||
if (!w) { return; }
|
||||
this->ui->tw_TextMessages->setCurrentWidget(w);
|
||||
this->displayMyself();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -68,7 +68,10 @@ namespace BlackGui
|
||||
void onTextMessageSent(const BlackMisc::Network::CTextMessage &sentMessage);
|
||||
|
||||
//! Used to allow direct input from global command line when visible
|
||||
virtual bool handleGlobalCommandLine(const QString &commandLine, const QString &originator);
|
||||
bool handleGlobalCommandLine(const QString &commandLine, const QString &originator);
|
||||
|
||||
//! Display the tab for given callsign
|
||||
void showCorrespondingTab(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
|
||||
protected:
|
||||
//! \copydoc CRuntimeBasedComponent::runtimeHasBeenSet
|
||||
@@ -76,16 +79,24 @@ namespace BlackGui
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::CTextMessageComponent> ui;
|
||||
CTextMessageTextEdit *m_currentTextEdit = nullptr; //!< text edit currently visible
|
||||
|
||||
//! Enum to widget
|
||||
QWidget *getTabWidget(Tab tab);
|
||||
QWidget *getTabWidget(Tab tab) const;
|
||||
|
||||
//! Select given tab
|
||||
void selectTabWidget(Tab tab);
|
||||
|
||||
//! New message tab for given callsign
|
||||
QWidget *addNewTextMessageTab(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
|
||||
//! Add new text message tab
|
||||
//! \param tabName name of the new tab, usually the channel name
|
||||
//! \return
|
||||
QWidget *addNewTextMessageTab(const QString &tabName);
|
||||
|
||||
//! Find text message tab by callsign
|
||||
QWidget *findTextMessageTabByCallsign(const BlackMisc::Aviation::CCallsign &callsign, bool callsignResolution = false) const;
|
||||
|
||||
//! Find text message tab by its name
|
||||
QWidget *findTextMessageTabByName(const QString &name) const;
|
||||
|
||||
@@ -93,13 +104,13 @@ namespace BlackGui
|
||||
void addPrivateChannelTextMessage(const BlackMisc::Network::CTextMessage &textMessage);
|
||||
|
||||
//! own aircraft
|
||||
const BlackMisc::Aviation::CAircraft getOwnAircraft() const { Q_ASSERT(this->getIContextOwnAircraft()); return this->getIContextOwnAircraft()->getOwnAircraft(); }
|
||||
const BlackMisc::Aviation::CAircraft getOwnAircraft() const;
|
||||
|
||||
//! For this text message's recepient, is the current tab selected?
|
||||
bool isCorrespondingTextMessageTabSelected(BlackMisc::Network::CTextMessage textMessage) const;
|
||||
|
||||
//! Network connected?
|
||||
bool isNetworkConnected() const { return this->getIContextNetwork() && this->getIContextNetwork()->isConnected() ; }
|
||||
bool isNetworkConnected() const;
|
||||
|
||||
//! Show current frequencies
|
||||
void showCurrentFrequenciesFromCockpit();
|
||||
@@ -124,7 +135,7 @@ namespace BlackGui
|
||||
//! Close text message tab
|
||||
void ps_closeTextMessageTab();
|
||||
|
||||
//! Top level was changed
|
||||
//! Top level was changed (used to enable elements when floating)
|
||||
void ps_topLevelChanged(QWidget *widget, bool topLevel);
|
||||
|
||||
//! Command line entered
|
||||
|
||||
@@ -13,19 +13,11 @@ namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
CUpdateTimer::CUpdateTimer(const char *slot, QObject *parent) :
|
||||
QObject(parent)
|
||||
void CUpdateTimer::initTimers()
|
||||
{
|
||||
Q_ASSERT(parent);
|
||||
this->m_timer = new QTimer(this);
|
||||
this->m_timerSingleShot = new QTimer(this);
|
||||
this->m_timerSingleShot->setSingleShot(true);
|
||||
|
||||
bool c = this->connect(this->m_timer, SIGNAL(timeout()), parent, slot);
|
||||
Q_ASSERT(c);
|
||||
c = this->connect(this->m_timerSingleShot, SIGNAL(timeout()), parent, slot);
|
||||
Q_ASSERT(c);
|
||||
Q_UNUSED(c);
|
||||
}
|
||||
|
||||
CUpdateTimer::~CUpdateTimer()
|
||||
@@ -54,5 +46,6 @@ namespace BlackGui
|
||||
this->m_timer->start(); // restart other timer
|
||||
this->m_timerSingleShot->start(10);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -25,8 +25,18 @@ namespace BlackGui
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
CUpdateTimer(const char *slot, QObject *parent);
|
||||
//! Construct a timer which forwards messages to the given slot of parent.
|
||||
template <typename F, typename P>
|
||||
CUpdateTimer(F slot, P *parent) : QObject(parent)
|
||||
{
|
||||
Q_ASSERT(parent);
|
||||
this->initTimers();
|
||||
bool c = this->connect(this->m_timer, &QTimer::timeout, parent, slot);
|
||||
Q_ASSERT(c);
|
||||
c = this->connect(this->m_timerSingleShot, &QTimer::timeout, parent, slot);
|
||||
Q_ASSERT(c);
|
||||
Q_UNUSED(c);
|
||||
}
|
||||
|
||||
//! Destructor
|
||||
~CUpdateTimer();
|
||||
@@ -55,6 +65,7 @@ namespace BlackGui
|
||||
void fireTimer();
|
||||
|
||||
private:
|
||||
void initTimers(); //!< init timers
|
||||
QTimer *m_timer = nullptr; //!< periodically updating
|
||||
QTimer *m_timerSingleShot = nullptr; //!< single update
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace BlackGui
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->tabBar()->setExpanding(false);
|
||||
this->m_updateTimer = new CUpdateTimer(SLOT(update()), this);
|
||||
this->m_updateTimer = new CUpdateTimer(&CUserComponent::update, this);
|
||||
|
||||
connect(this->ui->tvp_AllUsers, &CUserView::rowCountChanged, this, &CUserComponent::ps_onCountChanged);
|
||||
connect(this->ui->tvp_Clients, &CClientView::rowCountChanged, this, &CUserComponent::ps_onCountChanged);
|
||||
|
||||
Reference in New Issue
Block a user