mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
refs #568, allow to confirm (OK/CANCEL) in overlay window
So we can display status messages in the same step and decide what to do
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Network;
|
||||
using namespace BlackGui::Models;
|
||||
using namespace BlackGui::Views;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -24,6 +25,12 @@ namespace BlackGui
|
||||
{
|
||||
this->init(w, h);
|
||||
connect(&CStyleSheetUtility::instance(), &CStyleSheetUtility::styleSheetsChanged, this, &COverlayMessages::ps_onStyleSheetsChanged);
|
||||
connect(this->ui->pb_Ok, &QPushButton::clicked, this, &COverlayMessages::ps_okClicked);
|
||||
connect(this->ui->pb_Cancel, &QPushButton::clicked, this, &COverlayMessages::ps_cancelClicked);
|
||||
|
||||
this->ui->tvp_StatusMessages->setResizeMode(CStatusMessageView::ResizingAuto);
|
||||
this->ui->fr_Confirmation->setVisible(false);
|
||||
this->setDefaultConfirmationButton(QMessageBox::Cancel);
|
||||
}
|
||||
|
||||
COverlayMessages::COverlayMessages(const QString &headerText, int w, int h, QWidget *parent) :
|
||||
@@ -62,6 +69,22 @@ namespace BlackGui
|
||||
// stlye sheet
|
||||
}
|
||||
|
||||
void COverlayMessages::ps_okClicked()
|
||||
{
|
||||
this->m_lastConfirmation = QMessageBox::Ok;
|
||||
if (this->m_okLambda)
|
||||
{
|
||||
this->m_okLambda();
|
||||
}
|
||||
this->close();
|
||||
}
|
||||
|
||||
void COverlayMessages::ps_cancelClicked()
|
||||
{
|
||||
this->m_lastConfirmation = QMessageBox::Cancel;
|
||||
this->close();
|
||||
}
|
||||
|
||||
bool COverlayMessages::useSmall() const
|
||||
{
|
||||
return (this->width() < 400);
|
||||
@@ -149,9 +172,56 @@ namespace BlackGui
|
||||
this->setHeader("Text message");
|
||||
}
|
||||
|
||||
void COverlayMessages::setConfirmationMessage(const QString &message)
|
||||
{
|
||||
if (message.isEmpty())
|
||||
{
|
||||
this->ui->fr_Confirmation->setVisible(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->ui->fr_Confirmation->setVisible(true);
|
||||
this->ui->lbl_Confirmation->setText(message);
|
||||
}
|
||||
}
|
||||
|
||||
void COverlayMessages::showMessagesWithConfirmation(const CStatusMessageList &messages, const QString &confirmationMessage, std::function<void ()> okLambda, int defaultButton, int timeOutMs)
|
||||
{
|
||||
this->setConfirmationMessage(confirmationMessage);
|
||||
this->showMessages(messages, timeOutMs);
|
||||
this->m_okLambda = okLambda;
|
||||
this->setDefaultConfirmationButton(defaultButton);
|
||||
}
|
||||
|
||||
void COverlayMessages::setDefaultConfirmationButton(int button)
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
case QMessageBox::Ok:
|
||||
this->ui->pb_Cancel->setDefault(false);
|
||||
this->ui->pb_Cancel->setAutoDefault(false);
|
||||
this->ui->pb_Ok->setDefault(true);
|
||||
this->ui->pb_Ok->setAutoDefault(true);
|
||||
this->m_lastConfirmation = QMessageBox::Ok;
|
||||
this->ui->pb_Ok->setFocus();
|
||||
break;
|
||||
case QMessageBox::Cancel:
|
||||
this->ui->pb_Ok->setDefault(false);
|
||||
this->ui->pb_Ok->setAutoDefault(false);
|
||||
this->ui->pb_Cancel->setDefault(true);
|
||||
this->ui->pb_Cancel->setAutoDefault(true);
|
||||
this->m_lastConfirmation = QMessageBox::Cancel;
|
||||
this->ui->pb_Cancel->setFocus();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void COverlayMessages::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (this->isVisible() && event->key() == Qt::Key_Escape)
|
||||
if (!this->isVisible()) { QFrame::keyPressEvent(event); }
|
||||
if (event->key() == Qt::Key_Escape)
|
||||
{
|
||||
this->close();
|
||||
event->accept();
|
||||
@@ -166,6 +236,9 @@ namespace BlackGui
|
||||
{
|
||||
this->hide();
|
||||
this->setEnabled(false);
|
||||
this->ui->fr_Confirmation->setVisible(false);
|
||||
this->m_lastConfirmation = QMessageBox::Cancel;
|
||||
this->m_okLambda = nullptr;
|
||||
}
|
||||
|
||||
void COverlayMessages::display(int timeOutMs)
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include <QFrame>
|
||||
#include <QScopedPointer>
|
||||
#include <QTimer>
|
||||
#include <QMessageBox>
|
||||
#include <functional>
|
||||
|
||||
namespace Ui { class COverlayMessages; }
|
||||
|
||||
@@ -56,6 +58,19 @@ namespace BlackGui
|
||||
//! Set header text
|
||||
void setHeaderText(const QString &header);
|
||||
|
||||
//! Set the message and show the confirmation frame
|
||||
void setConfirmationMessage(const QString &message);
|
||||
|
||||
//! Show multiple messages with confirmation bar
|
||||
void showMessagesWithConfirmation(const BlackMisc::CStatusMessageList &messages,
|
||||
const QString &confirmationMessage,
|
||||
std::function<void()> okLambda,
|
||||
int defaultButton = QMessageBox::Cancel,
|
||||
int timeOutMs = -1);
|
||||
|
||||
//! Set the default confirmation button
|
||||
void setDefaultConfirmationButton(int button = QMessageBox::Cancel);
|
||||
|
||||
public slots:
|
||||
//! Show multiple messages
|
||||
void showMessages(const BlackMisc::CStatusMessageList &messages, int timeOutMs = -1);
|
||||
@@ -86,21 +101,28 @@ namespace BlackGui
|
||||
//! Stylesheet changed
|
||||
void ps_onStyleSheetsChanged();
|
||||
|
||||
//! Small
|
||||
bool useSmall() const;
|
||||
//! OK clicked (only when confirmation bar is active)
|
||||
void ps_okClicked();
|
||||
|
||||
//! Cancel clicked (only when confirmation bar is active)
|
||||
void ps_cancelClicked();
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::COverlayMessages> ui;
|
||||
QString m_header;
|
||||
QTimer m_autoCloseTimer { this };
|
||||
QString m_header;
|
||||
int m_lastConfirmation = QMessageBox::Cancel;
|
||||
std::function<void()> m_okLambda;
|
||||
QTimer m_autoCloseTimer { this };
|
||||
|
||||
//! Init widget
|
||||
void init(int w, int h);
|
||||
|
||||
//! Set header text
|
||||
void setHeader(const QString &header);
|
||||
};
|
||||
|
||||
//! Small
|
||||
bool useSmall() const;
|
||||
};
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -275,6 +275,54 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="fr_Confirmation">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="hl_ConfirmationFrame">
|
||||
<property name="leftMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="lbl_Confirmation">
|
||||
<property name="text">
|
||||
<string>Message goes here</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pb_Ok">
|
||||
<property name="text">
|
||||
<string>OK</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pb_Cancel">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
<property name="default">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
@@ -296,6 +344,16 @@
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>pb_Ok</tabstop>
|
||||
<tabstop>pb_Cancel</tabstop>
|
||||
<tabstop>tb_Close</tabstop>
|
||||
<tabstop>tvp_StatusMessages</tabstop>
|
||||
<tabstop>le_TmReceived</tabstop>
|
||||
<tabstop>le_TmTo</tabstop>
|
||||
<tabstop>le_TmFrom</tabstop>
|
||||
<tabstop>te_TmText</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../blackmisc/blackmisc.qrc"/>
|
||||
</resources>
|
||||
|
||||
@@ -31,6 +31,14 @@ namespace BlackGui
|
||||
if (!m_overlayMessages) { return; }
|
||||
}
|
||||
|
||||
void COverlayMessagesFrame::showMessagesWithConfirmation(const BlackMisc::CStatusMessageList &messages, const QString &confirmationMessage, std::function<void ()> okLambda, int defaultButton, int timeOutMs)
|
||||
{
|
||||
if (messages.isEmpty()) { return; }
|
||||
this->initInnerFrame();
|
||||
this->m_overlayMessages->showMessagesWithConfirmation(messages, confirmationMessage, okLambda, defaultButton, timeOutMs);
|
||||
this->repaint();
|
||||
}
|
||||
|
||||
void COverlayMessagesFrame::showMessage(const BlackMisc::CStatusMessage &message, int timeOutMs)
|
||||
{
|
||||
if (message.isEmpty()) { return; }
|
||||
|
||||
@@ -38,6 +38,13 @@ namespace BlackGui
|
||||
//! Hide the inner frame
|
||||
void hideStatusMessagesFrame();
|
||||
|
||||
//! \copydoc COverlayMessages::showMessagesWithConfirmation
|
||||
void showMessagesWithConfirmation(const BlackMisc::CStatusMessageList &messages,
|
||||
const QString &confirmationMessage,
|
||||
std::function<void()> okLambda,
|
||||
int defaultButton = QMessageBox::Cancel,
|
||||
int timeOutMs = -1);
|
||||
|
||||
public slots:
|
||||
//! \copydoc COverlayMessages::showMessages
|
||||
void showMessages(const BlackMisc::CStatusMessageList &messages, int timeOutMs = -1);
|
||||
|
||||
Reference in New Issue
Block a user