mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 08:22:15 -07:00
Make the banner snazzier.
This commit is contained in:
parent
364865487a
commit
b80acd9864
4 changed files with 73 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 <QLabel>
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
#include "banner_widget.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QPainter>
|
||||
#include <QLinearGradient>
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef BANNER_WIDGET_H
|
||||
#define BANNER_WIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue