From 06654c04955ed7d1cbbe46e8820d1ab490d57570 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Fri, 24 May 2024 11:34:45 +0300 Subject: [PATCH] plasma: drop Plasma::ItemBackground class unused, tho the svg that it paints is used in multiple places as base. perhaps the class was not flexible enough? Signed-off-by: Ivailo Monev --- includes/CMakeLists.txt | 1 - includes/Plasma/ItemBackground | 1 - plasma/CMakeLists.txt | 2 - plasma/delegate.cpp | 4 +- plasma/widgets/itembackground.cpp | 345 ------------------------------ plasma/widgets/itembackground.h | 122 ----------- 6 files changed, 2 insertions(+), 473 deletions(-) delete mode 100644 includes/Plasma/ItemBackground delete mode 100644 plasma/widgets/itembackground.cpp delete mode 100644 plasma/widgets/itembackground.h diff --git a/includes/CMakeLists.txt b/includes/CMakeLists.txt index f8659743..00233a68 100644 --- a/includes/CMakeLists.txt +++ b/includes/CMakeLists.txt @@ -430,7 +430,6 @@ install( Plasma/FrameSvg Plasma/GroupBox Plasma/IconWidget - Plasma/ItemBackground Plasma/Label Plasma/LineEdit Plasma/Meter diff --git a/includes/Plasma/ItemBackground b/includes/Plasma/ItemBackground deleted file mode 100644 index 0f0346d7..00000000 --- a/includes/Plasma/ItemBackground +++ /dev/null @@ -1 +0,0 @@ -#include "../../plasma/widgets/itembackground.h" diff --git a/plasma/CMakeLists.txt b/plasma/CMakeLists.txt index 3fd45eab..00022c74 100644 --- a/plasma/CMakeLists.txt +++ b/plasma/CMakeLists.txt @@ -69,7 +69,6 @@ set(plasma_LIB_SRCS widgets/frame.cpp widgets/groupbox.cpp widgets/iconwidget.cpp - widgets/itembackground.cpp widgets/label.cpp widgets/lineedit.cpp widgets/meter.cpp @@ -173,7 +172,6 @@ install( widgets/frame.h widgets/groupbox.h widgets/iconwidget.h - widgets/itembackground.h widgets/label.h widgets/lineedit.h widgets/meter.h diff --git a/plasma/delegate.cpp b/plasma/delegate.cpp index 77c68019..3bd50816 100644 --- a/plasma/delegate.cpp +++ b/plasma/delegate.cpp @@ -338,7 +338,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, if (option.direction == Qt::LeftToRight) { if (((titleRect.width() + decorationRect.width() + 10) > option.rect.width() || (subTitleRect.width() + decorationRect.width() + 15) > option.rect.width()) && - (titleRect.width() > 120 || subTitleRect.width() > 120)) { + (titleRect.width() > 120 || subTitleRect.width() > 120)) { QPainter p(&buffer); p.setCompositionMode(QPainter::CompositionMode_DestinationOut); p.setPen(Qt::NoPen); @@ -359,7 +359,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, } else { if (((titleRect.width() + decorationRect.width() + 10) > option.rect.width() || (subTitleRect.width() + decorationRect.width() + 15 )> option.rect.width()) && - (titleRect.width() > 120 || subTitleRect.width() > 120)) { + (titleRect.width() > 120 || subTitleRect.width() > 120)) { buffer.fill(Qt::transparent); QPainter p(&buffer); p.setCompositionMode(QPainter::CompositionMode_DestinationOut); diff --git a/plasma/widgets/itembackground.cpp b/plasma/widgets/itembackground.cpp deleted file mode 100644 index 3a7461bd..00000000 --- a/plasma/widgets/itembackground.cpp +++ /dev/null @@ -1,345 +0,0 @@ -/*************************************************************************** - * Copyright 2009 by Alessandro Diaferia * - * Copyright 2009 by Marco Martin * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Library General Public License as * - * published by the Free Software Foundation; either version 2, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * - ***************************************************************************/ -#include "itembackground.h" - -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace Plasma -{ - -class ItemBackgroundPrivate -{ -public: - ItemBackgroundPrivate(ItemBackground *parent) - : q(parent), - target(nullptr), - opacity(1.0), - fading(false), - fadeIn(false), - immediate(false) - { - } - - void animationUpdate(qreal progress); - void targetDestroyed(QObject*); - void frameSvgChanged(); - void refreshCurrentTarget(); - - ItemBackground * const q; - QGraphicsItem *target; - Plasma::FrameSvg *frameSvg; - QRectF oldGeometry; - QRectF newGeometry; - QPropertyAnimation *anim; - qreal opacity; - bool fading; - bool fadeIn; - bool immediate; -}; - -ItemBackground::ItemBackground(QGraphicsWidget *parent) - : QGraphicsWidget(parent), - d(new ItemBackgroundPrivate(this)) -{ - d->frameSvg = new Plasma::FrameSvg(this); - d->anim = new QPropertyAnimation(this, "animationUpdate", this); - d->anim->setStartValue(0); - d->anim->setEndValue(1); - - d->frameSvg->setImagePath("widgets/viewitem"); - d->frameSvg->setEnabledBorders(Plasma::FrameSvg::AllBorders); - d->frameSvg->setCacheAllRenderedFrames(true); - d->frameSvg->setElementPrefix("hover"); - - setCacheMode(DeviceCoordinateCache); - setFlag(ItemIsMovable, false); - setFlag(ItemIsSelectable, false); - setFlag(ItemIsFocusable, false); - - setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); - - qreal l, t, r, b; - d->frameSvg->getMargins(l, t, r, b); - setContentsMargins(l, t, r, b); - - connect(d->frameSvg, SIGNAL(repaintNeeded()), this, SLOT(frameSvgChanged())); - - setAcceptedMouseButtons(0); - setZValue(-800); -} - -ItemBackground::~ItemBackground() -{ - delete d; -} - -QRectF ItemBackground::target() const -{ - return d->newGeometry; -} - -void ItemBackground::setTarget(const QRectF &newGeometry) -{ - d->oldGeometry = geometry(); - d->newGeometry = newGeometry; - - if (!isVisible() && (!d->target || !d->target->isVisible())) { - setGeometry(d->newGeometry); - targetReached(newGeometry); - if (d->target) { - emit targetItemReached(d->target); - } - return; - } - - QGraphicsWidget *pw = parentWidget(); - if (pw) { - d->newGeometry = d->newGeometry.intersected(QRectF(QPointF(0,0), pw->size())); - } - - if (d->anim->state() != QAbstractAnimation::Stopped) { - d->anim->stop(); - } - - if (d->target && d->target->isVisible() && !isVisible()) { - setZValue(d->target->zValue()-1); - setGeometry(newGeometry); - d->oldGeometry = newGeometry; - show(); - } else { - d->fading = false; - d->opacity = 1; - d->anim->start(); - } - -} - -void ItemBackground::setTargetItem(QGraphicsItem *target) -{ - if (d->target && d->target != target) { - QObject *obj = 0; - if (d->target->isWidget()) { - obj = static_cast(d->target); - obj->removeEventFilter(this); - } else { - d->target->removeSceneEventFilter(this); - obj = dynamic_cast(d->target); - } - - if (obj) { - disconnect(obj, 0, this, 0); - } - } - - if (!target) { - hide(); - } - - bool newTarget = (d->target != target); - d->target = target; - if (target) { - setZValue(target->zValue() - 1); - if (parentItem() != target->parentItem()) { - QTransform t = transform(); - setTransform(QTransform()); - QRectF geom = mapToScene(geometry()).boundingRect(); - setGeometry(mapFromScene(geom).boundingRect()); - setTransform(t); - } - - QRectF rect = target->boundingRect(); - rect.moveTopLeft(mapToParent(mapFromScene(target->mapToScene(QPointF(0, 0))))); - - setTarget(rect); - - - if (newTarget) { - QObject *obj = 0; - if (target->isWidget()) { - obj = static_cast(target); - obj->installEventFilter(this); - } else { - d->target->installSceneEventFilter(this); - obj = dynamic_cast(target); - } - - if (obj) { - connect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(targetDestroyed(QObject*))); - } - } - } -} - -QGraphicsItem *ItemBackground::targetItem() const -{ - return d->target; -} - -bool ItemBackground::eventFilter(QObject *watched, QEvent *event) -{ - QGraphicsWidget *targetWidget = static_cast(d->target); - if (watched == targetWidget) { - if (event->type() == QEvent::GraphicsSceneResize || - event->type() == QEvent::GraphicsSceneMove) { - // We need to wait for the parent widget to resize... - QTimer::singleShot(0, this, SLOT(refreshCurrentTarget()) ); - } else if (event->type() == QEvent::Show) { - setTargetItem(targetWidget); - } - } - - return false; -} - -bool ItemBackground::sceneEventFilter(QGraphicsItem *watched, QEvent *event) -{ - if (watched == d->target) { - if (event->type() == QEvent::GraphicsSceneMove) { - QTimer::singleShot(0, this, SLOT(refreshCurrentTarget()) ); - } - } - - return false; -} - -void ItemBackground::resizeEvent(QGraphicsSceneResizeEvent *) -{ - d->frameSvg->resizeFrame(size()); -} - -QVariant ItemBackground::itemChange(GraphicsItemChange change, const QVariant &value) -{ - if (d->immediate) { - return value; - } - - if (change == ItemVisibleChange) { - bool visible = value.toBool(); - bool retVisible = visible; - if (visible == isVisible() || d->anim->state() == QAbstractAnimation::Stopped) { - retVisible = true; - } - d->fading = true; - d->fadeIn = visible; - - if (d->anim->state() != QAbstractAnimation::Stopped) { - d->anim->stop(); - } - - d->anim->setDuration(250); - d->anim->start(); - - return retVisible; - - } - return value; -} - -void ItemBackground::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - Q_UNUSED(widget) - - if (qFuzzyCompare(d->opacity, (qreal)1.0)) { - d->frameSvg->paintFrame(painter, option->rect.topLeft()); - } else if (qFuzzyCompare(d->opacity+1, (qreal)1.0)) { - return; - } else { - QPixmap framePix = d->frameSvg->framePixmap(); - QPainter bufferPainter(&framePix); - bufferPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn); - bufferPainter.fillRect(framePix.rect(), QColor(0, 0, 0, 255 * d->opacity)); - bufferPainter.end(); - painter->drawPixmap(framePix.rect(), framePix, framePix.rect()); - } -} - -void ItemBackground::setAnimationUpdate(qreal progress) -{ - d->animationUpdate(progress); -} - -qreal ItemBackground::animationUpdate() const -{ - return d->opacity; -} - -void ItemBackgroundPrivate::animationUpdate(qreal progress) -{ - if (progress == 1) { - if ((!fading) || (fadeIn)) { - emit q->targetReached(newGeometry); - if (target) { - emit q->targetItemReached(target); - } - } - } - - if (fading) { - opacity = fadeIn?progress:1-progress; - if (!fadeIn && qFuzzyCompare(opacity+1, (qreal)1.0)) { - immediate = true; - q->hide(); - immediate = false; - } - } else if (oldGeometry != newGeometry) { - q->setGeometry(oldGeometry.x() + (newGeometry.x() - oldGeometry.x()) * progress, - oldGeometry.y() + (newGeometry.y() - oldGeometry.y()) * progress, - oldGeometry.width() + (newGeometry.width() - oldGeometry.width()) * progress, - oldGeometry.height() + (newGeometry.height() - oldGeometry.height()) * progress); - } - - q->update(); - emit q->animationStep(progress); -} - -void ItemBackgroundPrivate::targetDestroyed(QObject*) -{ - target = 0; - q->setTargetItem(0); -} - -void ItemBackgroundPrivate::frameSvgChanged() -{ - qreal l, t, r, b; - frameSvg->getMargins(l, t, r, b); - q->setContentsMargins(l, t, r, b); - q->update(); - emit q->appearanceChanged(); -} - -void ItemBackgroundPrivate::refreshCurrentTarget() -{ - q->setTargetItem(target); -} - -} // Plasma namespace - - -#include "moc_itembackground.cpp" - - diff --git a/plasma/widgets/itembackground.h b/plasma/widgets/itembackground.h deleted file mode 100644 index a587fa44..00000000 --- a/plasma/widgets/itembackground.h +++ /dev/null @@ -1,122 +0,0 @@ -/*************************************************************************** - * Copyright 2009 by Alessandro Diaferia * - * Copyright 2009 by Marco Martin * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Library General Public License as * - * published by the Free Software Foundation; either version 2, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * - ***************************************************************************/ - -#ifndef ITEMBACKGROUND_H -#define ITEMBACKGROUND_H - -#include - -#include - -/** - * @class ItemBackground plasma/widgets/itembackground.h - * - * @short a background for QGraphicsWidget based item views with animation effects - * - * @since 4.4 - */ -namespace Plasma { - -class FrameSvg; -class ItemBackgroundPrivate; - -class PLASMA_EXPORT ItemBackground : public QGraphicsWidget -{ - Q_OBJECT - Q_PROPERTY(QRectF target READ target WRITE setTarget) - Q_PROPERTY(QGraphicsItem* targetItem READ targetItem WRITE setTargetItem) - Q_PROPERTY(qreal animationUpdate READ animationUpdate WRITE setAnimationUpdate) - -public: - ItemBackground(QGraphicsWidget *parent = 0); - ~ItemBackground(); - - /** - * Sets a new target geometry we want at the end of animation - * - * @param newGeometry the final geometry target - */ - void setTarget(const QRectF &newGeometry); - - /** - * @return the current target rect; may be empty if there is no target currently set - */ - QRectF target() const; - - /** - * set the ItemBackground geometry to be the target geometry, plus the ItemBackground margins - */ - void setTargetItem(QGraphicsItem *target); - - /** - * @return the target item, if any - */ - QGraphicsItem *targetItem() const; - - /** - * @reimp from QGraphicsWidget - */ - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - -Q_SIGNALS: - /** - * Emitted when the visual layout and appearance changes. Useful for synchronizing - * content margins. - */ - void appearanceChanged(); - - /** - * Emitted at each animation frame. Useful for synchronizing item animations - */ - void animationStep(qreal progress); - - /** - * Emitted when the target has been reached. Useful to consider this instead of - * the corresponding hoverEnterEvent; - */ - void targetReached(QRectF); - - /** - * Emitted when the target has been reached. Useful to consider this instead of - * the corresponding hoverEnterEvent; - */ - void targetItemReached(QGraphicsItem *); - -protected: - QVariant itemChange(GraphicsItemChange change, const QVariant &value); - bool eventFilter(QObject *watched, QEvent *event); - bool sceneEventFilter(QGraphicsItem *watched, QEvent *event); - void resizeEvent(QGraphicsSceneResizeEvent *); - -private: - void setAnimationUpdate(qreal progress); - qreal animationUpdate() const; - -private: - Q_PRIVATE_SLOT(d, void targetDestroyed(QObject*)) - Q_PRIVATE_SLOT(d, void frameSvgChanged()) - Q_PRIVATE_SLOT(d, void refreshCurrentTarget()) - - friend class ItemBackgroundPrivate; - ItemBackgroundPrivate * const d; -}; -} - -#endif