Added toast notifications to the gem catalog
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <QIcon>
|
||||
#include <QToolButton>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QPainter>
|
||||
|
||||
namespace AzQtComponents
|
||||
{
|
||||
@@ -27,6 +28,13 @@ namespace AzQtComponents
|
||||
setAttribute(Qt::WA_ShowWithoutActivating);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
m_borderRadius = toastConfiguration.m_borderRadius;
|
||||
if (m_borderRadius > 0)
|
||||
{
|
||||
setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
}
|
||||
|
||||
m_ui->setupUi(this);
|
||||
|
||||
QIcon toastIcon;
|
||||
@@ -53,6 +61,13 @@ namespace AzQtComponents
|
||||
m_ui->titleLabel->setText(toastConfiguration.m_title);
|
||||
m_ui->mainLabel->setText(toastConfiguration.m_description);
|
||||
|
||||
// hide the optional description if none is provided so the title is centered vertically
|
||||
if (toastConfiguration.m_description.isEmpty())
|
||||
{
|
||||
m_ui->mainLabel->setVisible(false);
|
||||
m_ui->verticalLayout->removeWidget(m_ui->mainLabel);
|
||||
}
|
||||
|
||||
m_lifeSpan.setInterval(aznumeric_cast<int>(toastConfiguration.m_duration.count()));
|
||||
m_closeOnClick = toastConfiguration.m_closeOnClick;
|
||||
|
||||
@@ -68,6 +83,24 @@ namespace AzQtComponents
|
||||
{
|
||||
}
|
||||
|
||||
void ToastNotification::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
if (m_borderRadius > 0)
|
||||
{
|
||||
QPainter p(this);
|
||||
p.setPen(Qt::transparent);
|
||||
QColor painterColor;
|
||||
painterColor.setRgbF(0, 0, 0, 255);
|
||||
p.setBrush(painterColor);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
p.drawRoundedRect(rect(), m_borderRadius, m_borderRadius);
|
||||
}
|
||||
else
|
||||
{
|
||||
QDialog::paintEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void ToastNotification::ShowToastAtCursor()
|
||||
{
|
||||
QPoint globalCursorPos = QCursor::pos();
|
||||
|
||||
@@ -52,6 +52,8 @@ namespace AzQtComponents
|
||||
void mousePressEvent(QMouseEvent* mouseEvent) override;
|
||||
bool eventFilter(QObject* object, QEvent* event) override;
|
||||
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
|
||||
public slots:
|
||||
void StartTimer();
|
||||
void FadeOut();
|
||||
@@ -65,6 +67,7 @@ namespace AzQtComponents
|
||||
|
||||
bool m_closeOnClick;
|
||||
QTimer m_lifeSpan;
|
||||
uint32_t m_borderRadius = 0;
|
||||
|
||||
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
|
||||
AZStd::chrono::milliseconds m_fadeDuration;
|
||||
|
||||
@@ -191,7 +191,7 @@
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
|
||||
+1
@@ -37,6 +37,7 @@ namespace AzQtComponents
|
||||
QString m_title;
|
||||
QString m_description;
|
||||
QString m_customIconImage;
|
||||
uint32_t m_borderRadius = 0;
|
||||
|
||||
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
|
||||
AZStd::chrono::milliseconds m_duration = AZStd::chrono::milliseconds(5000);
|
||||
|
||||
+10
@@ -177,4 +177,14 @@ namespace AzToolsFramework
|
||||
DisplayQueuedNotification();
|
||||
}
|
||||
}
|
||||
|
||||
void ToastNotificationsView::SetOffset(const QPoint& offset)
|
||||
{
|
||||
m_offset = offset;
|
||||
}
|
||||
|
||||
void ToastNotificationsView::SetAnchorPoint(const QPointF& anchorPoint)
|
||||
{
|
||||
m_anchorPoint = anchorPoint;
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -50,6 +50,9 @@ namespace AzToolsFramework
|
||||
void OnShow();
|
||||
void UpdateToastPosition();
|
||||
|
||||
void SetOffset(const QPoint& offset);
|
||||
void SetAnchorPoint(const QPointF& anchorPoint);
|
||||
|
||||
private:
|
||||
ToastId CreateToastNotification(const AzQtComponents::ToastConfiguration& toastConfiguration);
|
||||
void DisplayQueuedNotification();
|
||||
|
||||
Reference in New Issue
Block a user