Signed-off-by: AMZN-alexpete <26804013+AMZN-alexpete@users.noreply.github.com>
This commit is contained in:
@@ -22,6 +22,7 @@ namespace AzQtComponents
|
||||
, m_closeOnClick(true)
|
||||
, m_ui(new Ui::ToastNotification())
|
||||
, m_fadeAnimation(nullptr)
|
||||
, m_configuration(toastConfiguration)
|
||||
{
|
||||
setProperty("HasNoWindowDecorations", true);
|
||||
|
||||
@@ -80,7 +81,13 @@ namespace AzQtComponents
|
||||
}
|
||||
|
||||
ToastNotification::~ToastNotification()
|
||||
{
|
||||
{
|
||||
}
|
||||
|
||||
bool ToastNotification::IsDuplicate(const ToastConfiguration& toastConfiguration)
|
||||
{
|
||||
return toastConfiguration.m_title == m_configuration.m_title
|
||||
&& toastConfiguration.m_description == m_configuration.m_description;
|
||||
}
|
||||
|
||||
void ToastNotification::paintEvent(QPaintEvent* event)
|
||||
|
||||
@@ -45,6 +45,8 @@ namespace AzQtComponents
|
||||
void ShowToastAtPoint(const QPoint& screenPosition, const QPointF& anchorPoint);
|
||||
|
||||
void UpdatePosition(const QPoint& screenPosition, const QPointF& anchorPoint);
|
||||
|
||||
bool IsDuplicate(const ToastConfiguration& toastConfiguration);
|
||||
|
||||
// QDialog
|
||||
void showEvent(QShowEvent* showEvent) override;
|
||||
@@ -64,7 +66,7 @@ namespace AzQtComponents
|
||||
|
||||
private:
|
||||
QPropertyAnimation* m_fadeAnimation;
|
||||
|
||||
ToastConfiguration m_configuration;
|
||||
bool m_closeOnClick;
|
||||
QTimer m_lifeSpan;
|
||||
uint32_t m_borderRadius = 0;
|
||||
|
||||
+34
@@ -63,6 +63,12 @@ namespace AzToolsFramework
|
||||
|
||||
ToastId ToastNotificationsView::ShowToastNotification(const AzQtComponents::ToastConfiguration& toastConfiguration)
|
||||
{
|
||||
// reject duplicate messages
|
||||
if (m_rejectDuplicates && DuplicateNotificationInQueue(toastConfiguration))
|
||||
{
|
||||
return ToastId();
|
||||
}
|
||||
|
||||
ToastId toastId = CreateToastNotification(toastConfiguration);
|
||||
m_queuedNotifications.emplace_back(toastId);
|
||||
|
||||
@@ -70,10 +76,28 @@ namespace AzToolsFramework
|
||||
{
|
||||
DisplayQueuedNotification();
|
||||
}
|
||||
else if (m_queuedNotifications.size() >= m_maxQueuedNotifications)
|
||||
{
|
||||
// hiding the active toast will cause the next toast to be displayed
|
||||
HideToastNotification(m_activeNotification);
|
||||
}
|
||||
|
||||
return toastId;
|
||||
}
|
||||
|
||||
bool ToastNotificationsView::DuplicateNotificationInQueue(const AzQtComponents::ToastConfiguration& toastConfiguration)
|
||||
{
|
||||
for (auto iter : m_notifications)
|
||||
{
|
||||
if (iter.second && iter.second->IsDuplicate(toastConfiguration))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
ToastId ToastNotificationsView::ShowToastAtCursor(const AzQtComponents::ToastConfiguration& toastConfiguration)
|
||||
{
|
||||
ToastId toastId = CreateToastNotification(toastConfiguration);
|
||||
@@ -187,4 +211,14 @@ namespace AzToolsFramework
|
||||
{
|
||||
m_anchorPoint = anchorPoint;
|
||||
}
|
||||
|
||||
void ToastNotificationsView::SetMaxQueuedNotifications(AZ::u32 maxQueuedNotifications)
|
||||
{
|
||||
m_maxQueuedNotifications = maxQueuedNotifications;
|
||||
}
|
||||
|
||||
void ToastNotificationsView::SetRejectDuplicates(bool rejectDuplicates)
|
||||
{
|
||||
m_rejectDuplicates = rejectDuplicates;
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -52,10 +52,13 @@ namespace AzToolsFramework
|
||||
|
||||
void SetOffset(const QPoint& offset);
|
||||
void SetAnchorPoint(const QPointF& anchorPoint);
|
||||
void SetMaxQueuedNotifications(AZ::u32 maxQueuedNotifications);
|
||||
void SetRejectDuplicates(bool rejectDuplicates);
|
||||
|
||||
private:
|
||||
ToastId CreateToastNotification(const AzQtComponents::ToastConfiguration& toastConfiguration);
|
||||
void DisplayQueuedNotification();
|
||||
bool DuplicateNotificationInQueue(const AzQtComponents::ToastConfiguration& toastConfiguration);
|
||||
QPoint GetGlobalPoint();
|
||||
|
||||
ToastId m_activeNotification;
|
||||
@@ -64,5 +67,7 @@ namespace AzToolsFramework
|
||||
|
||||
QPoint m_offset = QPoint(10, 10);
|
||||
QPointF m_anchorPoint = QPointF(1, 0);
|
||||
AZ::u32 m_maxQueuedNotifications = 5;
|
||||
bool m_rejectDuplicates = true;
|
||||
};
|
||||
} // AzToolsFramework
|
||||
|
||||
Reference in New Issue
Block a user