-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
2,764 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
//============================================================================= | ||
// Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved. | ||
/// @author AMD Developer Tools Team | ||
/// @file | ||
/// @brief Implementation of the custom banner widget. | ||
//============================================================================= | ||
|
||
#include "banner_widget.h" | ||
#include "ui_banner_widget.h" | ||
|
||
#include <QPainter> | ||
|
||
// Static strings used for label widgets. | ||
static const QString kBannerText = "[Notification message]"; | ||
static const QString kCloseLink = "Close"; | ||
static const QString kCloseText = QChar(0x2A2F); | ||
static const QString kShowDetailsText = "See details"; | ||
static const QString kShowDetailsLink = "ShowDetails"; | ||
static const QString kDontShowAgainText = "Do not show again"; | ||
static const QString kDontShowAgainLink = "DontShowAgain"; | ||
static const QString kStyledButtonHtml = "<a style=\"text-decoration:none; color:black; font-size:xx-large; font-weight:600;\" href=\"%1\">%2</a>"; | ||
static const QString kCloseToolTip = "Close the notification banner."; | ||
|
||
BannerWidget::BannerWidget(QWidget* parent) | ||
: QWidget(parent) | ||
, ui_(new Ui::BannerWidget) | ||
{ | ||
ui_->setupUi(this); | ||
Init(); | ||
} | ||
|
||
BannerWidget::~BannerWidget() | ||
{ | ||
} | ||
|
||
void BannerWidget::Init() | ||
{ | ||
SetNotificationText(kBannerText); | ||
ui_->show_details_label_->SetLink(kShowDetailsText, kShowDetailsLink); | ||
ui_->dont_show_again_label_->SetLink(kDontShowAgainText, kDontShowAgainLink); | ||
ui_->close_button_->setText(kStyledButtonHtml.arg(kCloseLink, kCloseText)); | ||
ui_->close_button_->setWindowTitle(kCloseToolTip); | ||
|
||
connect(ui_->show_details_label_, &QLabel::linkActivated, this, &BannerWidget::HandleShowDetailsClicked); | ||
connect(ui_->dont_show_again_label_, &QLabel::linkActivated, this, &BannerWidget::HandleDontShowAgainClicked); | ||
connect(ui_->close_button_, &QLabel::linkActivated, this, &BannerWidget::HandleCloseClicked); | ||
|
||
// Install an event filter to handle propagating text color to the child labels. | ||
installEventFilter(this); | ||
|
||
// Hide the banner until it is needed. | ||
hide(); | ||
} | ||
|
||
void BannerWidget::paintEvent(QPaintEvent* event) | ||
{ | ||
QWidget::paintEvent(event); | ||
|
||
QPainter painter(this); | ||
|
||
// Draw background for the button. | ||
painter.setBrush(QBrush(palette().color(QPalette::Window))); | ||
painter.drawRect(0, 0, width(), height()); | ||
} | ||
|
||
bool BannerWidget::eventFilter(QObject* object, QEvent* event) | ||
{ | ||
const bool return_value = QWidget::eventFilter(object, event); | ||
|
||
if ((event->type() == QEvent::PaletteChange) || (event->type() == QEvent::Polish)) | ||
{ | ||
// Propagate the text color to the child label widgets. | ||
const QColor text_color = palette().color(QPalette::WindowText); | ||
|
||
// Iterate over all child widgets and set the text color for labels. | ||
for (QObject* child : children()) | ||
{ | ||
QLabel* label = qobject_cast<QLabel*>(child); | ||
if (label != nullptr) | ||
{ | ||
// Get the label's palette and set the text color. | ||
QPalette palette = label->palette(); | ||
palette.setColor(QPalette::WindowText, text_color); | ||
label->setPalette(palette); | ||
} | ||
} | ||
} | ||
|
||
return return_value; | ||
} | ||
|
||
void BannerWidget::HandleShowDetailsClicked(const QString& link) | ||
{ | ||
if (link == kShowDetailsLink) | ||
{ | ||
emit ShowDetailsClicked(); | ||
} | ||
} | ||
|
||
void BannerWidget::SetNotificationText(const QString& notification_text) | ||
{ | ||
ui_->message_label_->setText(notification_text); | ||
} | ||
|
||
void BannerWidget::HandleDontShowAgainClicked(const QString& link) | ||
{ | ||
if (link == kDontShowAgainLink) | ||
{ | ||
DontShowAgainQuery(); | ||
} | ||
} | ||
|
||
void BannerWidget::HandleCloseClicked(const QString& link) | ||
{ | ||
if (link == kCloseLink) | ||
{ | ||
hide(); | ||
emit CloseClicked(); | ||
} | ||
} | ||
|
||
void BannerWidget::DontShowAgainQuery() | ||
{ | ||
emit DontShowAgainRequested(); | ||
} | ||
|
||
void BannerWidget::SetLinkColor(const QColor& color) | ||
{ | ||
ui_->show_details_label_->SetLinkColor(color); | ||
ui_->dont_show_again_label_->SetLinkColor(color); | ||
} | ||
|
||
void BannerWidget::SetDisabledLinkColor(const QColor& color) | ||
{ | ||
ui_->show_details_label_->SetDisabledLinkColor(color); | ||
ui_->dont_show_again_label_->SetDisabledLinkColor(color); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
//============================================================================= | ||
// Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved. | ||
/// @author AMD Developer Tools Team | ||
/// @file | ||
/// @brief Header for the custom banner widget. | ||
//============================================================================= | ||
|
||
#ifndef QTCOMMON_CUSTOM_WIDGETS_BANNER_WIDGET_H_ | ||
#define QTCOMMON_CUSTOM_WIDGETS_BANNER_WIDGET_H_ | ||
|
||
#include <QString> | ||
#include <QWidget> | ||
|
||
namespace Ui | ||
{ | ||
class BannerWidget; | ||
} | ||
|
||
/// @brief A custom widget for displaying a banner with a message and links. | ||
class BannerWidget : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
/// @brief Constructor | ||
/// | ||
/// @param [in] parent The parent of the banner widget. | ||
explicit BannerWidget(QWidget* parent = nullptr); | ||
|
||
/// @brief Destructor. | ||
virtual ~BannerWidget(); | ||
|
||
/// @brief Set the text for the notification. | ||
/// | ||
/// @param [in] notification_text The text to display in the notification. | ||
void SetNotificationText(const QString& notification_text); | ||
|
||
/// @brief Set text color used for links on the banner. | ||
/// | ||
/// @param [in] color The text color for the link. | ||
void SetLinkColor(const QColor& color); | ||
|
||
/// @brief Set the text color used for disabled links on the banner. | ||
/// | ||
/// @param [in] color The text color for the disabled link. | ||
void SetDisabledLinkColor(const QColor& color); | ||
|
||
/// @brief Emits a signal indicating that the user has clicked the "Do not show again" link. | ||
virtual void DontShowAgainQuery(); | ||
|
||
protected: | ||
/// @brief Overridden paint event for this widget. | ||
/// | ||
/// @param event The paint event | ||
virtual void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE; | ||
|
||
/// @brief Event filter for the banner widget. | ||
/// | ||
/// Handles updating the text color for child labels. | ||
/// | ||
/// @param [in] object The object that the event is for. | ||
/// @param [in] event The event that occurred. | ||
/// | ||
/// @return True if the event was handled, false otherwise. | ||
bool eventFilter(QObject* object, QEvent* event); | ||
|
||
signals: | ||
/// @brief Signal emitted when the "show details" link is clicked. | ||
void ShowDetailsClicked(); | ||
|
||
/// @brief Signal emitted when the "Do not show again" link is clicked. | ||
void DontShowAgainRequested(); | ||
|
||
/// @brief Signal emitted when the close button is clicked. | ||
void CloseClicked(); | ||
|
||
private slots: | ||
/// @brief Slot to handle the show details link being clicked. | ||
/// | ||
/// @param link The link that was clicked. | ||
void HandleShowDetailsClicked(const QString& link); | ||
|
||
/// @brief Slot to handle the close button being clicked. | ||
/// | ||
/// @param link The link that was clicked. | ||
void HandleCloseClicked(const QString& link); | ||
|
||
/// @brief Slot to handle the "don't show again" link being clicked. | ||
/// | ||
/// @param link The link that was clicked. | ||
void HandleDontShowAgainClicked(const QString& link); | ||
|
||
private: | ||
/// @brief Intializes the widget, adds subwidgets and inserts the banner into a parent layout if one exists. | ||
void Init(); | ||
|
||
protected: | ||
Ui::BannerWidget* ui_; ///< The Qt ui form. | ||
}; | ||
#endif // QTCOMMON_CUSTOM_WIDGETS_BANNER_WIDGET_H_ |
Oops, something went wrong.