mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 10:55:32 +08:00
Ref T617, display real name for private messages
* search by callsign first * add real name to tab * flag if real name is to be shown
This commit is contained in:
@@ -32,7 +32,7 @@
|
|||||||
<string>Overlay</string>
|
<string>Overlay</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Ovl.:</string>
|
<string>Overlay:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <Qt>
|
#include <Qt>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
#include <QStringBuilder>
|
||||||
|
|
||||||
using namespace BlackCore;
|
using namespace BlackCore;
|
||||||
using namespace BlackCore::Context;
|
using namespace BlackCore::Context;
|
||||||
@@ -399,6 +400,9 @@ namespace BlackGui
|
|||||||
|
|
||||||
ui->tw_TextMessages->setTabText(ui->tw_TextMessages->indexOf(ui->tb_TextMessagesCOM1), f1);
|
ui->tw_TextMessages->setTabText(ui->tw_TextMessages->indexOf(ui->tb_TextMessagesCOM1), f1);
|
||||||
ui->tw_TextMessages->setTabText(ui->tw_TextMessages->indexOf(ui->tb_TextMessagesCOM2), f2);
|
ui->tw_TextMessages->setTabText(ui->tw_TextMessages->indexOf(ui->tb_TextMessagesCOM2), f2);
|
||||||
|
|
||||||
|
// update tabs
|
||||||
|
this->updateAllTabs();
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *CTextMessageComponent::addNewTextMessageTab(const CCallsign &callsign)
|
QWidget *CTextMessageComponent::addNewTextMessageTab(const CCallsign &callsign)
|
||||||
@@ -411,7 +415,8 @@ namespace BlackGui
|
|||||||
const QString style = this->getStyleSheet();
|
const QString style = this->getStyleSheet();
|
||||||
const bool supervisor = callsign.isSupervisorCallsign();
|
const bool supervisor = callsign.isSupervisorCallsign();
|
||||||
QWidget *newTabWidget = new QWidget(this);
|
QWidget *newTabWidget = new QWidget(this);
|
||||||
newTabWidget->setObjectName("Tab widget " + tabName);
|
newTabWidget->setObjectName(u"Tab widget " % tabName);
|
||||||
|
newTabWidget->setProperty("callsign", callsign.asString());
|
||||||
QPushButton *closeButton = new QPushButton("Close", newTabWidget);
|
QPushButton *closeButton = new QPushButton("Close", newTabWidget);
|
||||||
QVBoxLayout *layout = new QVBoxLayout(newTabWidget);
|
QVBoxLayout *layout = new QVBoxLayout(newTabWidget);
|
||||||
CTextMessageTextEdit *textEdit = new CTextMessageTextEdit(newTabWidget);
|
CTextMessageTextEdit *textEdit = new CTextMessageTextEdit(newTabWidget);
|
||||||
@@ -426,7 +431,7 @@ namespace BlackGui
|
|||||||
textEdit->setProperty("supervisormsg", supervisor);
|
textEdit->setProperty("supervisormsg", supervisor);
|
||||||
textEdit->setStyleSheetForContent(style);
|
textEdit->setStyleSheetForContent(style);
|
||||||
|
|
||||||
const int index = ui->tw_TextMessages->addTab(newTabWidget, tabName);
|
const int index = ui->tw_TextMessages->addTab(newTabWidget, this->getCallsignAndRealName(callsign));
|
||||||
QToolButton *closeButtonInTab = new QToolButton(newTabWidget);
|
QToolButton *closeButtonInTab = new QToolButton(newTabWidget);
|
||||||
closeButtonInTab->setText("[X]");
|
closeButtonInTab->setText("[X]");
|
||||||
closeButtonInTab->setProperty("supervisormsg", supervisor);
|
closeButtonInTab->setProperty("supervisormsg", supervisor);
|
||||||
@@ -442,15 +447,52 @@ namespace BlackGui
|
|||||||
closeButtonInTab->setProperty("tabName", tabName);
|
closeButtonInTab->setProperty("tabName", tabName);
|
||||||
closeButton->setProperty("tabName", tabName);
|
closeButton->setProperty("tabName", tabName);
|
||||||
|
|
||||||
connect(closeButton, &QPushButton::released, this, &CTextMessageComponent::closeTextMessageTab);
|
connect(closeButton, &QPushButton::released, this, &CTextMessageComponent::closeTextMessageTab);
|
||||||
connect(closeButtonInTab, &QPushButton::released, this, &CTextMessageComponent::closeTextMessageTab);
|
connect(closeButtonInTab, &QPushButton::released, this, &CTextMessageComponent::closeTextMessageTab);
|
||||||
|
|
||||||
|
this->setTabWidgetDescription(callsign, index);
|
||||||
|
return newTabWidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CTextMessageComponent::setTabWidgetDescription(const CCallsign &callsign, int widgetIndex)
|
||||||
|
{
|
||||||
|
if (callsign.isEmpty()) { return; }
|
||||||
|
|
||||||
|
QString realName;
|
||||||
if (sGui && !sGui->isShuttingDown() && sGui->getIContextNetwork())
|
if (sGui && !sGui->isShuttingDown() && sGui->getIContextNetwork())
|
||||||
{
|
{
|
||||||
const QString realName = sGui->getIContextNetwork()->getUserForCallsign(CCallsign(tabName)).getRealName();
|
realName = sGui->getIContextNetwork()->getUserForCallsign(callsign).getRealName();
|
||||||
if (!realName.isEmpty()) { ui->tw_TextMessages->setTabToolTip(index, realName); }
|
if (!realName.isEmpty()) { ui->tw_TextMessages->setTabToolTip(widgetIndex, realName); }
|
||||||
|
}
|
||||||
|
const QString tt = realName.isEmpty() ? callsign.asString() : callsign.asString() % u": " % realName;
|
||||||
|
ui->tw_TextMessages->setTabText(widgetIndex, tt);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CTextMessageComponent::getCallsignAndRealName(const CCallsign &callsign) const
|
||||||
|
{
|
||||||
|
if (callsign.isEmpty()) { return {}; }
|
||||||
|
if (m_showRealNames && sGui && !sGui->isShuttingDown() && sGui->getIContextNetwork())
|
||||||
|
{
|
||||||
|
const QString realName = sGui->getIContextNetwork()->getUserForCallsign(callsign).getRealName();
|
||||||
|
if (!realName.isEmpty())
|
||||||
|
{
|
||||||
|
return callsign.asString() % u": " % realName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return callsign.asString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CTextMessageComponent::updateAllTabs()
|
||||||
|
{
|
||||||
|
for (int index = ui->tw_TextMessages->count() - 1; index >= 0; index--)
|
||||||
|
{
|
||||||
|
QWidget *tab = ui->tw_TextMessages->widget(index);
|
||||||
|
if (!tab) { continue; }
|
||||||
|
if (!tab->toolTip().isEmpty()) { continue; }
|
||||||
|
const QString cs = tab->property("callsign").toString();
|
||||||
|
if (cs.isEmpty()) { continue; }
|
||||||
|
this->setTabWidgetDescription(CCallsign(cs), index);
|
||||||
}
|
}
|
||||||
return newTabWidget;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTextMessageComponent::addPrivateChannelTextMessage(const CTextMessage &textMessage)
|
void CTextMessageComponent::addPrivateChannelTextMessage(const CTextMessage &textMessage)
|
||||||
@@ -490,6 +532,16 @@ namespace BlackGui
|
|||||||
|
|
||||||
QWidget *CTextMessageComponent::findTextMessageTabByCallsign(const CCallsign &callsign, bool callsignResolution) const
|
QWidget *CTextMessageComponent::findTextMessageTabByCallsign(const CCallsign &callsign, bool callsignResolution) const
|
||||||
{
|
{
|
||||||
|
// search the private message tabs by property first
|
||||||
|
for (int index = ui->tw_TextMessages->count() - 1; index >= 0; index--)
|
||||||
|
{
|
||||||
|
QWidget *tab = ui->tw_TextMessages->widget(index);
|
||||||
|
if (tab && tab->property("callsign").toString() == callsign.asString())
|
||||||
|
{
|
||||||
|
return tab;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QWidget *w = this->findTextMessageTabByName(callsign.asString());
|
QWidget *w = this->findTextMessageTabByName(callsign.asString());
|
||||||
if (w) { return w; }
|
if (w) { return w; }
|
||||||
if (!callsignResolution) { return nullptr; }
|
if (!callsignResolution) { return nullptr; }
|
||||||
@@ -618,7 +670,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
// not a standard channel
|
// not a standard channel
|
||||||
bool isNumber;
|
bool isNumber;
|
||||||
const QString selectedTabText = ui->tw_TextMessages->tabText(index).trimmed();
|
const QString selectedTabText = firstPartOfTabText(ui->tw_TextMessages->tabText(index).trimmed());
|
||||||
const double frequency = selectedTabText.toDouble(&isNumber);
|
const double frequency = selectedTabText.toDouble(&isNumber);
|
||||||
if (isNumber)
|
if (isNumber)
|
||||||
{
|
{
|
||||||
@@ -637,8 +689,7 @@ namespace BlackGui
|
|||||||
cmd.append(selectedTabText);
|
cmd.append(selectedTabText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cmd.append(" ").append(enteredLine);
|
return cmd % u" " % enteredLine;
|
||||||
return cmd;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -775,5 +826,16 @@ namespace BlackGui
|
|||||||
m_activeReceive = receive;
|
m_activeReceive = receive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CTextMessageComponent::firstPartOfTabText(const QString &tabText)
|
||||||
|
{
|
||||||
|
if (tabText.isEmpty()) { return {}; }
|
||||||
|
int index = tabText.indexOf(':');
|
||||||
|
if (index < 0) { index = tabText.indexOf(' '); }
|
||||||
|
if (index >= 0)
|
||||||
|
{
|
||||||
|
return tabText.left(index);
|
||||||
|
}
|
||||||
|
return tabText;
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -84,6 +84,12 @@ namespace BlackGui
|
|||||||
//! Remove the all tab, the operation cannot be undone
|
//! Remove the all tab, the operation cannot be undone
|
||||||
void removeAllMessagesTab();
|
void removeAllMessagesTab();
|
||||||
|
|
||||||
|
//! Showing real names
|
||||||
|
bool isShowingRealNames() const { return m_showRealNames; }
|
||||||
|
|
||||||
|
//! Showing real names
|
||||||
|
void setShowingRealNames(bool show) { m_showRealNames = show; }
|
||||||
|
|
||||||
// ---------- overlay test messages -------------
|
// ---------- overlay test messages -------------
|
||||||
|
|
||||||
//! Used as overlay and not dock widget
|
//! Used as overlay and not dock widget
|
||||||
@@ -120,6 +126,7 @@ namespace BlackGui
|
|||||||
bool m_usedAsOverlayWidget = false; //!< disables dockwidget parts if used as overlay widget
|
bool m_usedAsOverlayWidget = false; //!< disables dockwidget parts if used as overlay widget
|
||||||
bool m_activeSend = true; //!< ignore sent messages
|
bool m_activeSend = true; //!< ignore sent messages
|
||||||
bool m_activeReceive = true; //!< ignore received messages
|
bool m_activeReceive = true; //!< ignore received messages
|
||||||
|
bool m_showRealNames = true;
|
||||||
|
|
||||||
//! Enum to widget
|
//! Enum to widget
|
||||||
QWidget *getTabWidget(TextMessageTab tab) const;
|
QWidget *getTabWidget(TextMessageTab tab) const;
|
||||||
@@ -210,17 +217,29 @@ namespace BlackGui
|
|||||||
//! Close text message tab
|
//! Close text message tab
|
||||||
void closeTextMessageTab();
|
void closeTextMessageTab();
|
||||||
|
|
||||||
|
//! Update all tabs
|
||||||
|
void updateAllTabs();
|
||||||
|
|
||||||
//! Top level was changed (used to enable elements when floating)
|
//! Top level was changed (used to enable elements when floating)
|
||||||
void topLevelChanged(QWidget *widget, bool topLevel);
|
void topLevelChanged(QWidget *widget, bool topLevel);
|
||||||
|
|
||||||
//! Command line entered
|
//! Command line entered
|
||||||
void textMessageEntered();
|
void textMessageEntered();
|
||||||
|
|
||||||
|
//! Set the real name widget tooltip
|
||||||
|
void setTabWidgetDescription(const BlackMisc::Aviation::CCallsign &callsign, int widgetIndex);
|
||||||
|
|
||||||
|
//! Callsign and relanme if possible
|
||||||
|
QString getCallsignAndRealName(const BlackMisc::Aviation::CCallsign &callsign) const;
|
||||||
|
|
||||||
//! Visible widget hack
|
//! Visible widget hack
|
||||||
bool isVisibleWidgetHack() const;
|
bool isVisibleWidgetHack() const;
|
||||||
|
|
||||||
//! Emit the display in info window signal
|
//! Emit the display in info window signal
|
||||||
void emitDisplayInInfoWindow(const BlackMisc::CVariant &message, int displayDurationMs);
|
void emitDisplayInInfoWindow(const BlackMisc::CVariant &message, int displayDurationMs);
|
||||||
|
|
||||||
|
//! Get the 1st part of the tab text, "DAMBZ: Joe Doe" -> "DAMBZ", "123.45 Foo" -> "123.45"
|
||||||
|
static QString firstPartOfTabText(const QString &tabText);
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
Reference in New Issue
Block a user