From 8f1f10be6c4c88a99ac06d7910c7e1d30204e451 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sat, 23 Mar 2024 09:10:43 +0200 Subject: [PATCH] plasma: do not fade the end of the text from Plasma::Label it causes undesired look in the weather applet for example Signed-off-by: Ivailo Monev --- plasma/widgets/label.cpp | 57 ++++------------------------------------ plasma/widgets/label.h | 3 --- 2 files changed, 5 insertions(+), 55 deletions(-) diff --git a/plasma/widgets/label.cpp b/plasma/widgets/label.cpp index acc461ed..63e225c6 100644 --- a/plasma/widgets/label.cpp +++ b/plasma/widgets/label.cpp @@ -81,7 +81,7 @@ public: pm = QPixmap(absImagePath); } - static_cast(q->widget())->setPixmap(pm); + q->nativeWidget()->setPixmap(pm); } QString imagePath; @@ -117,13 +117,13 @@ Label::~Label() void Label::setText(const QString &text) { d->hasLinks = text.contains("(widget())->setText(text); + nativeWidget()->setText(text); updateGeometry(); } QString Label::text() const { - return static_cast(widget())->text(); + return nativeWidget()->text(); } void Label::setImage(const QString &path) @@ -153,12 +153,12 @@ QString Label::image() const void Label::setScaledContents(bool scaled) { - static_cast(widget())->setScaledContents(scaled); + nativeWidget()->setScaledContents(scaled); } bool Label::hasScaledContents() const { - return static_cast(widget())->hasScaledContents(); + return nativeWidget()->hasScaledContents(); } void Label::setTextSelectable(bool enable) @@ -260,53 +260,6 @@ void Label::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } } -void Label::paint(QPainter *painter, - const QStyleOptionGraphicsItem *option, - QWidget *widget) -{ - QLabel *native = nativeWidget(); - QFontMetrics fm = native->font(); - - //indirect painting still used for fade out - if (native->wordWrap() || native->text().isEmpty() || size().width() >= fm.width(native->text())) { - QGraphicsProxyWidget::paint(painter, option, widget); - } else { - const int gradientLength = 25; - QPixmap buffer(contentsRect().size().toSize()); - buffer.fill(Qt::transparent); - - QPainter buffPainter(&buffer); - - QGraphicsProxyWidget::paint(&buffPainter, option, widget); - - QLinearGradient gr; - - buffPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn); - buffPainter.setPen(Qt::NoPen); - - if (option->direction == Qt::LeftToRight) { - gr.setStart(size().width()-gradientLength, 0); - gr.setFinalStop(size().width(), 0); - gr.setColorAt(0, Qt::black); - gr.setColorAt(1, Qt::transparent); - buffPainter.setBrush(gr); - - buffPainter.drawRect(QRect(gr.start().toPoint(), QSize(gradientLength, size().height()))); - } else { - gr.setStart(0, 0); - gr.setFinalStop(gradientLength, 0); - gr.setColorAt(0, Qt::transparent); - gr.setColorAt(1, Qt::black); - buffPainter.setBrush(gr); - - buffPainter.drawRect(QRect(0, 0, gradientLength, size().height())); - } - - buffPainter.end(); - painter->drawPixmap(contentsRect(), buffer, buffer.rect()); - } -} - void Label::changeEvent(QEvent *event) { d->changeEvent(event); diff --git a/plasma/widgets/label.h b/plasma/widgets/label.h index b8a481ef..7cae7222 100644 --- a/plasma/widgets/label.h +++ b/plasma/widgets/label.h @@ -164,9 +164,6 @@ protected: void resizeEvent(QGraphicsSceneResizeEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void paint(QPainter *painter, - const QStyleOptionGraphicsItem *option, - QWidget *widget); void changeEvent(QEvent *event); bool event(QEvent *event); QVariant itemChange(GraphicsItemChange change, const QVariant & value);