mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-08-10 19:46:10 +08:00
feat: Add warn/error log buttons
Add buttons to highlight that error or warning messages were logged. Fixes #106
This commit is contained in:
@@ -29,6 +29,8 @@ namespace BlackGui
|
||||
// we are not necessarily the owner of the status bar
|
||||
m_statusBar->removeWidget(m_statusBarLabel);
|
||||
m_statusBar->removeWidget(m_statusBarIcon);
|
||||
m_statusBar->removeWidget(m_errorButton);
|
||||
m_statusBar->removeWidget(m_warningButton);
|
||||
|
||||
// labels will be deleted with status bar
|
||||
if (m_ownedStatusBar) { delete m_statusBar; }
|
||||
@@ -46,11 +48,24 @@ namespace BlackGui
|
||||
m_statusBarLabel = new QLabel(m_statusBar);
|
||||
m_statusBarLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
||||
m_statusBarLabel->setObjectName(QString("lbl_StatusBarLabel").append(m_statusBar->objectName()));
|
||||
m_warningButton = new QPushButton("WARN", m_statusBar);
|
||||
m_warningButton->setObjectName(QString("btn_StatusBarWarn").append(m_statusBar->objectName()));
|
||||
m_warningButton->setHidden(!m_showWarnButtonInitially);
|
||||
m_warningButton->setToolTip("ACK and show logs");
|
||||
connect(m_warningButton, &QPushButton::pressed, this, &CManagedStatusBar::pressedWarnButton);
|
||||
m_errorButton = new QPushButton("ERROR", m_statusBar);
|
||||
m_errorButton->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
|
||||
m_errorButton->setObjectName(QString("btn_StatusBarError").append(m_statusBar->objectName()));
|
||||
m_errorButton->setHidden(!m_showErrorButtonInitially);
|
||||
m_errorButton->setToolTip("ACK and show logs");
|
||||
connect(m_errorButton, &QPushButton::pressed, this, &CManagedStatusBar::pressedErrorButton);
|
||||
|
||||
// use insert to insert from left to right
|
||||
// this keeps any grip on the right size
|
||||
m_statusBar->insertPermanentWidget(0, m_statusBarIcon, 0); // status icon
|
||||
m_statusBar->insertPermanentWidget(1, m_statusBarLabel, 1); // status text
|
||||
m_statusBar->insertPermanentWidget(2, m_warningButton, 0);
|
||||
m_statusBar->insertPermanentWidget(3, m_errorButton, 0);
|
||||
|
||||
// timer
|
||||
m_timerStatusBar.setObjectName(this->objectName().append(":m_timerStatusBar"));
|
||||
@@ -72,6 +87,30 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
void CManagedStatusBar::showWarningButton()
|
||||
{
|
||||
if (!m_warningButton)
|
||||
{
|
||||
m_showWarnButtonInitially = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_warningButton->setHidden(false);
|
||||
}
|
||||
}
|
||||
|
||||
void CManagedStatusBar::showErrorButton()
|
||||
{
|
||||
if (!m_errorButton)
|
||||
{
|
||||
m_showErrorButtonInitially = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_errorButton->setHidden(false);
|
||||
}
|
||||
}
|
||||
|
||||
void CManagedStatusBar::show()
|
||||
{
|
||||
if (!m_statusBar) { return; }
|
||||
@@ -146,4 +185,19 @@ namespace BlackGui
|
||||
m_statusBarIcon->clear();
|
||||
m_statusBarLabel->clear();
|
||||
}
|
||||
|
||||
void CManagedStatusBar::pressedWarnButton()
|
||||
{
|
||||
Q_ASSERT_X(m_warningButton, Q_FUNC_INFO, "Missing warning button");
|
||||
m_warningButton->setHidden(true);
|
||||
emit requestLogPage();
|
||||
}
|
||||
|
||||
void CManagedStatusBar::pressedErrorButton()
|
||||
{
|
||||
Q_ASSERT_X(m_errorButton, Q_FUNC_INFO, "Missing error button");
|
||||
m_errorButton->setHidden(true);
|
||||
emit requestLogPage();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include <QObject>
|
||||
#include <QPushButton>
|
||||
#include <QTimer>
|
||||
|
||||
class QLabel;
|
||||
@@ -35,6 +36,12 @@ namespace BlackGui
|
||||
//! Init
|
||||
void initStatusBar(QStatusBar *statusBar = nullptr);
|
||||
|
||||
//! Show warning log button
|
||||
void showWarningButton();
|
||||
|
||||
//! Show warning error button
|
||||
void showErrorButton();
|
||||
|
||||
//! Show
|
||||
void show();
|
||||
|
||||
@@ -53,15 +60,29 @@ namespace BlackGui
|
||||
//! Enabled size grip
|
||||
void setSizeGripEnabled(bool enabled);
|
||||
|
||||
signals:
|
||||
//! Request to show the log page
|
||||
void requestLogPage();
|
||||
|
||||
private:
|
||||
//! Clear status bar
|
||||
void clearStatusBar();
|
||||
|
||||
//! Pressed the WARN button
|
||||
void pressedWarnButton();
|
||||
|
||||
//! Pressed the ERROR button
|
||||
void pressedErrorButton();
|
||||
|
||||
QStatusBar *m_statusBar = nullptr; //!< the status bar itself
|
||||
QLabel *m_statusBarIcon = nullptr; //!< status bar icon
|
||||
QLabel *m_statusBarLabel = nullptr; //!< status bar label
|
||||
QPushButton *m_warningButton = nullptr; //!< log warning button
|
||||
QPushButton *m_errorButton = nullptr; //!< log error button
|
||||
QTimer m_timerStatusBar { this }; //!< cleaning up status bar (own cleaning as I need to clean window / icon)
|
||||
bool m_ownedStatusBar = false; //!< own status bar or "injected" (e.g.by UI builder)
|
||||
bool m_showWarnButtonInitially = false; //!< should the button be shown initially? Might be set before the button is initialized
|
||||
bool m_showErrorButtonInitially = false; //!< should the button be shown initially? Might be set before the button is initialized
|
||||
Qt::TextElideMode m_elideMode = Qt::ElideMiddle; //!< label text elide
|
||||
BlackMisc::StatusSeverity m_currentSeverity = BlackMisc::StatusSeverity::SeverityDebug; //!< severity currently displayed
|
||||
};
|
||||
|
||||
@@ -718,6 +718,16 @@ QStatusBar QLabel {
|
||||
padding-left: 5px;
|
||||
}
|
||||
|
||||
#btn_StatusBarWarnsb_MainStatusBar {
|
||||
background-color: yellow;
|
||||
color: black;
|
||||
}
|
||||
|
||||
#btn_StatusBarErrorsb_MainStatusBar {
|
||||
background-color: red;
|
||||
color: white;
|
||||
}
|
||||
|
||||
QToolTip {
|
||||
color: black;
|
||||
background-color: darkgray;
|
||||
|
||||
@@ -132,6 +132,7 @@ private:
|
||||
BlackCore::CActionBindings m_menuHotkeyHandlers;
|
||||
BlackGui::CManagedStatusBar m_statusBar;
|
||||
BlackMisc::CLogHistoryReplica m_logHistoryForStatus { this };
|
||||
BlackMisc::CLogHistoryReplica m_logHistoryForLogButtons { this };
|
||||
BlackMisc::CLogHistoryReplica m_logHistoryForOverlay { this };
|
||||
BlackMisc::CSetting<BlackMisc::Audio::TSettings> m_audioSettings { this };
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ void SwiftGuiStd::init()
|
||||
// log messages
|
||||
m_logHistoryForStatus.setFilter(CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityInfo));
|
||||
m_logHistoryForOverlay.setFilter(CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityError));
|
||||
m_logHistoryForLogButtons.setFilter(CLogPattern().withSeverityAtOrAbove(SeverityWarning));
|
||||
connect(&m_logHistoryForStatus, &CLogHistoryReplica::elementAdded, this, [this](const CStatusMessage &message) {
|
||||
m_statusBar.displayStatusMessage(message);
|
||||
ui->comp_MainInfoArea->displayStatusMessage(message);
|
||||
@@ -85,8 +86,19 @@ void SwiftGuiStd::init()
|
||||
//! \todo filter out validation messages at CLogPattern level
|
||||
if (!message.getCategories().contains(CLogCategories::validation())) { ui->fr_CentralFrameInside->showOverlayMessage(message); }
|
||||
});
|
||||
connect(&m_logHistoryForLogButtons, &CLogHistoryReplica::elementAdded, this, [this](const CStatusMessage &message) {
|
||||
if (message.getSeverity() == CStatusMessage::SeverityError)
|
||||
{
|
||||
m_statusBar.showErrorButton();
|
||||
}
|
||||
else if (message.getSeverity() == CStatusMessage::SeverityWarning)
|
||||
{
|
||||
m_statusBar.showWarningButton();
|
||||
}
|
||||
});
|
||||
m_logHistoryForStatus.initialize(sApp->getDataLinkDBus());
|
||||
m_logHistoryForOverlay.initialize(sApp->getDataLinkDBus());
|
||||
m_logHistoryForLogButtons.initialize(sApp->getDataLinkDBus());
|
||||
|
||||
// style
|
||||
this->initStyleSheet();
|
||||
@@ -116,6 +128,7 @@ void SwiftGuiStd::init()
|
||||
|
||||
// info bar and status bar
|
||||
m_statusBar.initStatusBar(ui->sb_MainStatusBar);
|
||||
connect(&m_statusBar, &CManagedStatusBar::requestLogPage, ui->comp_MainInfoArea, &CMainInfoAreaComponent::displayLog);
|
||||
ui->dw_InfoBarStatus->allowStatusBar(false);
|
||||
ui->dw_InfoBarStatus->setPreferredSizeWhenFloating(ui->dw_InfoBarStatus->size()); // set floating size
|
||||
|
||||
|
||||
Reference in New Issue
Block a user