Skip to content

Commit

Permalink
QtCommon v4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosier committed Sep 5, 2024
1 parent 6377814 commit 78e1cee
Show file tree
Hide file tree
Showing 25 changed files with 2,764 additions and 81 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(QtCommon)

# Define version information
set(QTCOMMON_MAJOR_VERSION 4)
set(QTCOMMON_MINOR_VERSION 0)
set(QTCOMMON_MINOR_VERSION 1)
if (NOT QTCOMMON_PATCH_NUMBER)
set(QTCOMMON_PATCH_NUMBER 0)
endif ()
Expand Down
15 changes: 15 additions & 0 deletions source/qt_common/custom_widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ set(CMAKE_AUTOUIC ON)
# Add all header and source files within the directory to the library.
file (GLOB CPP_INC
"arrow_icon_combo_box.h"
"banner_widget.h"
"check_box_widget.h"
"colored_legend_graphics_view.h"
"colored_legend_scene.h"
"completion_bar_widget.h"
"donut_pie_widget.h"
"double_slider_widget.h"
"driver_overrides_model.h"
"driver_overrides_notification_banner.h"
"driver_overrides_notification_config_widget.h"
"driver_overrides_tree_widget.h"
"elided_line_label.h"
"expanding_scroll_area.h"
"file_loading_widget.h"
Expand All @@ -38,6 +43,7 @@ file (GLOB CPP_INC
"scaled_header_view.h"
"scaled_label.h"
"scaled_line_edit.h"
"scaled_link_label.h"
"scaled_menu_bar.h"
"scaled_push_button.h"
"scaled_spin_box.h"
Expand All @@ -61,18 +67,26 @@ file (GLOB CPP_INC

# Add any .ui files
file (GLOB UI_SRC
"banner_widget.ui"
"driver_overrides_notification_config_widget.ui"
"driver_overrides_tree_widget.ui"
"message_overlay.ui"
)

# Add all source files found within this directory.
file (GLOB CPP_SRC
"arrow_icon_combo_box.cpp"
"banner_widget.cpp"
"check_box_widget.cpp"
"colored_legend_graphics_view.cpp"
"colored_legend_scene.cpp"
"completion_bar_widget.cpp"
"donut_pie_widget.cpp"
"double_slider_widget.cpp"
"driver_overrides_model.cpp"
"driver_overrides_notification_banner.cpp"
"driver_overrides_notification_config_widget.cpp"
"driver_overrides_tree_widget.cpp"
"elided_line_label.cpp"
"expanding_scroll_area.cpp"
"file_loading_widget.cpp"
Expand All @@ -98,6 +112,7 @@ file (GLOB CPP_SRC
"scaled_header_view.cpp"
"scaled_label.cpp"
"scaled_line_edit.cpp"
"scaled_link_label.cpp"
"scaled_menu_bar.cpp"
"scaled_push_button.cpp"
"scaled_spin_box.cpp"
Expand Down
137 changes: 137 additions & 0 deletions source/qt_common/custom_widgets/banner_widget.cpp
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);
}
100 changes: 100 additions & 0 deletions source/qt_common/custom_widgets/banner_widget.h
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_
Loading

0 comments on commit 78e1cee

Please sign in to comment.