mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 08:52:15 -07:00
Give the banner widget a buddy and the ability to show/hide the buddy when clicked.
This commit is contained in:
parent
b80acd9864
commit
9089eeecf2
3 changed files with 40 additions and 10 deletions
|
|
@ -13,9 +13,10 @@ EdhrecCommanderApiResponseCardListDisplayWidget::EdhrecCommanderApiResponseCardL
|
|||
layout = new QVBoxLayout(this);
|
||||
setLayout(layout);
|
||||
|
||||
auto header = new BannerWidget(toDisplay.header, Qt::Vertical, 80, this);
|
||||
auto header = new BannerWidget(this, toDisplay.header);
|
||||
|
||||
flowWidget = new FlowWidget(this, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAlwaysOff);
|
||||
header->setBuddy(flowWidget);
|
||||
|
||||
foreach (EdhrecCommanderApiResponseCardDetails card_detail, toDisplay.cardViews) {
|
||||
auto widget = new EdhrecCommanderApiResponseCardDetailsDisplayWidget(flowWidget, card_detail);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
#include "banner_widget.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QPainter>
|
||||
#include <QLinearGradient>
|
||||
|
||||
BannerWidget::BannerWidget(const QString& text, Qt::Orientation orientation, int transparency, QWidget* parent)
|
||||
#include <QLinearGradient>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
BannerWidget::BannerWidget(QWidget *parent, const QString &text, Qt::Orientation orientation, int transparency)
|
||||
: QWidget(parent), gradientOrientation(orientation), transparency(qBound(0, transparency, 100))
|
||||
{
|
||||
// Create the banner label and set properties
|
||||
|
|
@ -19,6 +21,20 @@ BannerWidget::BannerWidget(const QString& text, Qt::Orientation orientation, int
|
|||
|
||||
// Set minimum height for the widget
|
||||
setMinimumHeight(100);
|
||||
connect(this, &BannerWidget::buddyVisibilityChanged, this, &BannerWidget::toggleBuddyVisibility);
|
||||
}
|
||||
|
||||
void BannerWidget::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
QWidget::mousePressEvent(event);
|
||||
emit buddyVisibilityChanged();
|
||||
}
|
||||
|
||||
void BannerWidget::toggleBuddyVisibility() const
|
||||
{
|
||||
if (buddy) {
|
||||
buddy->setVisible(!buddy->isVisible());
|
||||
}
|
||||
}
|
||||
|
||||
void BannerWidget::paintEvent(QPaintEvent* event)
|
||||
|
|
|
|||
|
|
@ -1,23 +1,36 @@
|
|||
#ifndef BANNER_WIDGET_H
|
||||
#define BANNER_WIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
|
||||
class BannerWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit BannerWidget(const QString& text, Qt::Orientation orientation = Qt::Vertical, int transparency = 80, QWidget* parent = nullptr);
|
||||
explicit BannerWidget(QWidget *parent,
|
||||
const QString &text,
|
||||
Qt::Orientation orientation = Qt::Vertical,
|
||||
int transparency = 80);
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void setBuddy(QWidget *_buddy)
|
||||
{
|
||||
buddy = _buddy;
|
||||
}
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
private:
|
||||
QLabel* bannerLabel;
|
||||
QLabel *bannerLabel;
|
||||
Qt::Orientation gradientOrientation;
|
||||
int transparency; // Transparency percentage for the gradient
|
||||
QWidget *buddy;
|
||||
signals:
|
||||
void buddyVisibilityChanged();
|
||||
private slots:
|
||||
void toggleBuddyVisibility() const;
|
||||
};
|
||||
|
||||
#endif //BANNER_WIDGET_H
|
||||
#endif // BANNER_WIDGET_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue