diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index 9a4b16ded..2cf9ffd98 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -80,6 +80,7 @@ set(cockatrice_SOURCES src/utility/logger.cpp src/client/ui/widgets/cards/card_info_picture_enlarged_widget.cpp src/client/ui/widgets/cards/card_info_picture_with_text_overlay_widget.cpp + src/client/ui/widgets/general/display/banner_widget.cpp src/client/ui/widgets/general/display/labeled_input.cpp src/client/ui/widgets/general/display/dynamic_font_size_label.cpp src/client/ui/widgets/general/display/dynamic_font_size_push_button.cpp diff --git a/cockatrice/src/client/tabs/api/edhrec/edhrec_commander_api_response_card_list_display_widget.cpp b/cockatrice/src/client/tabs/api/edhrec/edhrec_commander_api_response_card_list_display_widget.cpp index 0ede07892..079bb61f4 100644 --- a/cockatrice/src/client/tabs/api/edhrec/edhrec_commander_api_response_card_list_display_widget.cpp +++ b/cockatrice/src/client/tabs/api/edhrec/edhrec_commander_api_response_card_list_display_widget.cpp @@ -1,5 +1,6 @@ #include "edhrec_commander_api_response_card_list_display_widget.h" +#include "../../../ui/widgets/general/display/banner_widget.h" #include "edhrec_commander_api_response_card_details_display_widget.h" #include @@ -12,8 +13,7 @@ EdhrecCommanderApiResponseCardListDisplayWidget::EdhrecCommanderApiResponseCardL layout = new QVBoxLayout(this); setLayout(layout); - auto header = new QLabel(this); - header->setText(toDisplay.header); + auto header = new BannerWidget(toDisplay.header, Qt::Vertical, 80, this); flowWidget = new FlowWidget(this, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAlwaysOff); diff --git a/cockatrice/src/client/ui/widgets/general/display/banner_widget.cpp b/cockatrice/src/client/ui/widgets/general/display/banner_widget.cpp new file mode 100644 index 000000000..a557d9a93 --- /dev/null +++ b/cockatrice/src/client/ui/widgets/general/display/banner_widget.cpp @@ -0,0 +1,47 @@ +#include "banner_widget.h" +#include +#include +#include + +BannerWidget::BannerWidget(const QString& text, Qt::Orientation orientation, int transparency, QWidget* parent) + : QWidget(parent), gradientOrientation(orientation), transparency(qBound(0, transparency, 100)) +{ + // Create the banner label and set properties + bannerLabel = new QLabel(text, this); + bannerLabel->setAlignment(Qt::AlignCenter); + bannerLabel->setStyleSheet("font-size: 24px; font-weight: bold; color: white;"); + + // Layout to center the banner label + QVBoxLayout* layout = new QVBoxLayout(this); + layout->addWidget(bannerLabel); + layout->setContentsMargins(0, 20, 0, 20); // Space for the gradient + setLayout(layout); + + // Set minimum height for the widget + setMinimumHeight(100); +} + +void BannerWidget::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event); + + QPainter painter(this); + + // Calculate alpha based on transparency percentage + int alpha = (255 * transparency) / 100; + + // Determine gradient direction + QLinearGradient gradient; + if (gradientOrientation == Qt::Vertical) { + gradient = QLinearGradient(rect().topLeft(), rect().bottomLeft()); + } else { + gradient = QLinearGradient(rect().topLeft(), rect().topRight()); + } + + // Set neutral gradient colors with calculated transparency + gradient.setColorAt(0, QColor(200, 200, 200, alpha)); // Light grey with alpha + gradient.setColorAt(1, QColor(100, 100, 100, alpha / 1.5)); // Darker grey, slightly more transparent + + // Fill the widget background with the gradient + painter.fillRect(rect(), gradient); +} diff --git a/cockatrice/src/client/ui/widgets/general/display/banner_widget.h b/cockatrice/src/client/ui/widgets/general/display/banner_widget.h new file mode 100644 index 000000000..6e141e9f4 --- /dev/null +++ b/cockatrice/src/client/ui/widgets/general/display/banner_widget.h @@ -0,0 +1,23 @@ +#ifndef BANNER_WIDGET_H +#define BANNER_WIDGET_H + +#include +#include + +class BannerWidget : public QWidget +{ + Q_OBJECT + +public: + explicit BannerWidget(const QString& text, Qt::Orientation orientation = Qt::Vertical, int transparency = 80, QWidget* parent = nullptr); + +protected: + void paintEvent(QPaintEvent* event) override; + +private: + QLabel* bannerLabel; + Qt::Orientation gradientOrientation; + int transparency; // Transparency percentage for the gradient +}; + +#endif //BANNER_WIDGET_H