From e6a2556a80cb0699c3d0ff7feb9b3e7df8a94d92 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sat, 13 Apr 2024 19:17:44 +0300 Subject: [PATCH] plasma: new MultiWidget class Signed-off-by: Ivailo Monev --- includes/CMakeLists.txt | 2 + includes/Plasma/MultiWidget | 1 + kdeui/CMakeLists.txt | 2 + kdeui/util/kdndeventfilter.cpp | 171 ++++ kdeui/util/kdndeventfilter.h | 67 ++ plasma/CMakeLists.txt | 2 + plasma/abstracttoolbox.h | 3 +- plasma/applet.cpp | 5 +- plasma/extenders/extender.cpp | 4 +- plasma/extenders/extenderitem.cpp | 75 +- plasma/popupapplet.cpp | 6 +- plasma/widgets/calendarwidget.h | 2 +- plasma/widgets/iconwidget.cpp | 1554 +++-------------------------- plasma/widgets/iconwidget.h | 315 +----- plasma/widgets/iconwidget_p.h | 411 -------- plasma/widgets/label.cpp | 209 +--- plasma/widgets/label.h | 69 +- plasma/widgets/multiwidget.cpp | 266 +++++ plasma/widgets/multiwidget.h | 94 ++ plasma/widgets/scrollwidget.cpp | 5 - plasma/widgets/separator.h | 21 +- 21 files changed, 867 insertions(+), 2417 deletions(-) create mode 100644 includes/Plasma/MultiWidget create mode 100644 kdeui/util/kdndeventfilter.cpp create mode 100644 kdeui/util/kdndeventfilter.h delete mode 100644 plasma/widgets/iconwidget_p.h create mode 100644 plasma/widgets/multiwidget.cpp create mode 100644 plasma/widgets/multiwidget.h diff --git a/includes/CMakeLists.txt b/includes/CMakeLists.txt index 3abf7a13..cf461789 100644 --- a/includes/CMakeLists.txt +++ b/includes/CMakeLists.txt @@ -41,6 +41,7 @@ install( KPasswdStore KHTTP KDNSSD + KDnDEventFilter KCharMacroExpander KCharsets KCmdLineArgs @@ -473,6 +474,7 @@ install( Plasma/FrameSvg Plasma/GroupBox Plasma/IconWidget + Plasma/MultiWidget Plasma/ItemBackground Plasma/Label Plasma/LineEdit diff --git a/includes/Plasma/MultiWidget b/includes/Plasma/MultiWidget new file mode 100644 index 00000000..4dc9596c --- /dev/null +++ b/includes/Plasma/MultiWidget @@ -0,0 +1 @@ +#include "../../plasma/widgets/multiwidget.h" diff --git a/kdeui/CMakeLists.txt b/kdeui/CMakeLists.txt index 96483008..eee1f4c9 100644 --- a/kdeui/CMakeLists.txt +++ b/kdeui/CMakeLists.txt @@ -166,6 +166,7 @@ set(kdeui_LIB_SRCS util/kcompletionbase.cpp util/kcrash.cpp util/kcursor.cpp + util/kdndeventfilter.cpp util/kguiitem.cpp util/kkeyserver.cpp util/kselectionowner.cpp @@ -430,6 +431,7 @@ install( util/kcompletion.h util/kcrash.h util/kcursor.h + util/kdndeventfilter.h util/kguiitem.h util/kkeyserver.h util/kkeyboardlayout.h diff --git a/kdeui/util/kdndeventfilter.cpp b/kdeui/util/kdndeventfilter.cpp new file mode 100644 index 00000000..0f3263c3 --- /dev/null +++ b/kdeui/util/kdndeventfilter.cpp @@ -0,0 +1,171 @@ +/* + This file is part of the KDE libraries + Copyright (C) 2024 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kdndeventfilter.h" +#include "kglobalsettings.h" +#include "kdebug.h" + +#include +#include + +class KDnDEventFilterPrivate +{ +public: + KDnDEventFilterPrivate(); + + QList objects; + QList items; + QPointF dragstartpos; + + bool filterEvent(QEvent *event); +}; + +KDnDEventFilterPrivate::KDnDEventFilterPrivate() + : dragstartpos(0.0, 0.0) +{ +} + +bool KDnDEventFilterPrivate::filterEvent(QEvent *event) +{ + switch (event->type()) { + case QEvent::MouseButtonPress: { + QMouseEvent* mouseevent = static_cast(event); + dragstartpos = mouseevent->pos(); + qDebug() << Q_FUNC_INFO << event << dragstartpos; + return false; + } + case QEvent::GraphicsSceneMousePress: { + QGraphicsSceneMouseEvent* mouseevent = static_cast(event); + dragstartpos = mouseevent->pos(); + qDebug() << Q_FUNC_INFO << event << dragstartpos; + return false; + } + case QEvent::MouseMove: { + QMouseEvent* mouseevent = static_cast(event); + if (mouseevent->buttons() & Qt::LeftButton && + (mouseevent->pos() - dragstartpos).manhattanLength() > KGlobalSettings::dndEventDelay()) + { + return true; + } + return false; + } + case QEvent::GraphicsSceneMouseMove: { + QGraphicsSceneMouseEvent* mouseevent = static_cast(event); + if (mouseevent->buttons() & Qt::LeftButton && + (mouseevent->pos() - dragstartpos).manhattanLength() > KGlobalSettings::dndEventDelay()) + { + return true; + } + return false; + } + default: { + return false; + } + } + Q_UNREACHABLE(); + return false; +} + +KDnDEventFilter::KDnDEventFilter(QGraphicsItem *parent) + : QGraphicsObject(parent), + d(new KDnDEventFilterPrivate()) +{ +} + +KDnDEventFilter::~KDnDEventFilter() +{ +} + +void KDnDEventFilter::filterObject(QObject *object) +{ + d->objects.append(object); + object->installEventFilter(this); +} + +void KDnDEventFilter::unfilterObject(QObject *object) +{ + d->objects.removeAll(object); + object->removeEventFilter(this); +} + +void KDnDEventFilter::filterItem(QGraphicsItem *item) +{ + d->items.append(item); + item->installSceneEventFilter(this); +} + +void KDnDEventFilter::unfilterItem(QGraphicsItem *item) +{ + d->items.removeAll(item); + item->removeSceneEventFilter(this); +} + +bool KDnDEventFilter::eventFilter(QObject *object, QEvent *event) +{ + if (d->objects.contains(object)) { + if (d->filterEvent(event)) { + qDebug() << Q_FUNC_INFO << event; + emit dragStarted(object); + return true; + } + } + return false; +} + +bool KDnDEventFilter::sceneEventFilter(QGraphicsItem *item, QEvent *event) +{ + if (d->items.contains(item)) { + if (d->filterEvent(event)) { + qDebug() << Q_FUNC_INFO << event; + emit dragStarted(item); + return true; + } + } + return false; +} + +// similar to Plasma::Applet::view(), the important thing is to get a window (preferably active +// one) +QGraphicsView* KDnDEventFilter::dragSceneView(const QGraphicsScene *scene) +{ + if (!scene) { + kWarning() << "No drag-n-drop scene"; + return nullptr; + } + foreach (QGraphicsView *view, scene->views()) { + if (view->isActiveWindow()) { + return view; + } + } + kWarning() << "No active window for drag-n-drop"; + return nullptr; +} + +QRectF KDnDEventFilter::boundingRect() const +{ + // dummy + return QRectF(0, 0, 0, 0); +} + +void KDnDEventFilter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + // dummy +} + +#include "moc_kdndeventfilter.cpp" diff --git a/kdeui/util/kdndeventfilter.h b/kdeui/util/kdndeventfilter.h new file mode 100644 index 00000000..4c8b3f44 --- /dev/null +++ b/kdeui/util/kdndeventfilter.h @@ -0,0 +1,67 @@ +/* + This file is part of the KDE libraries + Copyright (C) 2024 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KDNDEVENTFILTER_H +#define KDNDEVENTFILTER_H + +#include + +#include +#include +#include +#include + +class KDnDEventFilterPrivate; + +/*! + Class to catch Drag-n-Drop events from specified objects + @since 4.24 +*/ +class KDECORE_EXPORT KDnDEventFilter : public QGraphicsObject +{ + Q_OBJECT +public: + KDnDEventFilter(QGraphicsItem *parent = nullptr); + ~KDnDEventFilter(); + + void filterObject(QObject *object); + void unfilterObject(QObject *object); + + void filterItem(QGraphicsItem *item); + void unfilterItem(QGraphicsItem *item); + + static QGraphicsView* dragSceneView(const QGraphicsScene *scene); + +Q_SIGNALS: + void dragStarted(QObject *object); + void dragStarted(QGraphicsItem *item); + +protected: + bool eventFilter(QObject *object, QEvent *event); + bool sceneEventFilter(QGraphicsItem *item, QEvent *event); + + virtual QRectF boundingRect() const; + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + +private: + Q_DISABLE_COPY(KDnDEventFilter); + KDnDEventFilterPrivate * const d; +}; + +#endif // KDNDEVENTFILTER_H diff --git a/plasma/CMakeLists.txt b/plasma/CMakeLists.txt index e5b71818..3b0b1640 100644 --- a/plasma/CMakeLists.txt +++ b/plasma/CMakeLists.txt @@ -77,6 +77,7 @@ set(plasma_LIB_SRCS widgets/frame.cpp widgets/groupbox.cpp widgets/iconwidget.cpp + widgets/multiwidget.cpp widgets/itembackground.cpp widgets/label.cpp widgets/lineedit.cpp @@ -184,6 +185,7 @@ install( widgets/frame.h widgets/groupbox.h widgets/iconwidget.h + widgets/multiwidget.h widgets/itembackground.h widgets/label.h widgets/lineedit.h diff --git a/plasma/abstracttoolbox.h b/plasma/abstracttoolbox.h index 243ac77d..4ed01592 100644 --- a/plasma/abstracttoolbox.h +++ b/plasma/abstracttoolbox.h @@ -78,8 +78,7 @@ public: * * @since 4.6 */ - static KPluginInfo::List listToolBoxInfo(const QString - &parentApp = QString()); + static KPluginInfo::List listToolBoxInfo(const QString &parentApp = QString()); /** * create a toolbox tool from the given action diff --git a/plasma/applet.cpp b/plasma/applet.cpp index 6d39cd08..35a1f405 100644 --- a/plasma/applet.cpp +++ b/plasma/applet.cpp @@ -342,8 +342,7 @@ void Applet::setFailedToLaunch(bool failed, const QString &reason) Label *failureWidget = new Plasma::Label(this); failureWidget->setText(d->visibleFailureText(reason)); - QLabel *label = failureWidget->nativeWidget(); - label->setWordWrap(true); + failureWidget->setWordWrap(true); failureLayout->addItem(failureWidget); Plasma::ToolTipManager::self()->registerWidget(failureIcon); @@ -971,7 +970,7 @@ void Applet::showMessage(const QIcon &icon, const QString &message, const Messag IconWidget *messageIcon = new IconWidget(mainWidget); Label *messageText = new Label(mainWidget); - messageText->nativeWidget()->setWordWrap(true); + messageText->setWordWrap(true); messageLayout->addStretch(); messageLayout->addItem(messageIcon); diff --git a/plasma/extenders/extender.cpp b/plasma/extenders/extender.cpp index 6b4a7e14..201888a2 100644 --- a/plasma/extenders/extender.cpp +++ b/plasma/extenders/extender.cpp @@ -829,14 +829,14 @@ void ExtenderPrivate::updateEmptyExtenderLabel() { if (q->isEmpty() && !emptyExtenderLabel && !emptyExtenderMessage.isEmpty() && !spacerWidget ) { - //add the empty extender label. + // add the empty extender label. emptyExtenderLabel = new Label(q); emptyExtenderLabel->setAlignment(Qt::AlignCenter); emptyExtenderLabel->setText(emptyExtenderMessage); qreal left, top, right, bottom; background->getMargins(left, top, right, bottom); - emptyExtenderLabel->nativeWidget()->setMargin(left + right); + emptyExtenderLabel->setContentsMargins(left, top, right, bottom); emptyExtenderLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); layout->addItem(emptyExtenderLabel); diff --git a/plasma/extenders/extenderitem.cpp b/plasma/extenders/extenderitem.cpp index 8eab8734..aa198beb 100644 --- a/plasma/extenders/extenderitem.cpp +++ b/plasma/extenders/extenderitem.cpp @@ -48,7 +48,7 @@ #include "widgets/iconwidget.h" #include "widgets/pushbutton.h" - +#include "widgets/toolbutton.h" #include "private/extender_p.h" #include "private/extenderapplet_p.h" #include "private/extendergroup_p.h" @@ -181,7 +181,7 @@ ExtenderItem::ExtenderItem(Extender *hostExtender, uint extenderItemId) if (iconName.isEmpty()) { iconName = "utilities-desktop-extra"; } - d->collapseIcon->setIcon(iconName); + d->collapseIcon->setIcon(KIcon(iconName)); //Find the group if it's already there. QString groupName = dg.readEntry("group", ""); @@ -332,7 +332,7 @@ void ExtenderItem::setIcon(const QIcon &icon) void ExtenderItem::setIcon(const QString &icon) { if (icon != d->iconName) { - d->collapseIcon->setIcon(icon); + d->collapseIcon->setIcon(KIcon(icon)); d->iconName = icon; config().writeEntry("extenderIconName", icon); } @@ -833,7 +833,7 @@ void ExtenderItemPrivate::updateToolBox() int returnToSourceIndex = -1; const int startingIndex = 2; // collapse item is index 0, title label is 1 int lastIndex = 2; - const QSizeF widgetSize = collapseIcon->sizeFromIconSize(toolbox->iconSize()); + const QSizeF widgetSize = QSizeF(toolbox->iconSize(), toolbox->iconSize()); QSet shownActions = actionsInOrder.toSet(); @@ -844,8 +844,8 @@ void ExtenderItemPrivate::updateToolBox() if (!widget) { continue; - } else if (qobject_cast(widget)) { - widgetAction = static_cast(widget)->action(); + } else if (qobject_cast(widget)) { + widgetAction = static_cast(widget)->action(); } else if (qobject_cast(widget)) { widgetAction = static_cast(widget)->action(); } else { @@ -879,44 +879,27 @@ void ExtenderItemPrivate::updateToolBox() collapseIcon->setMinimumSize(widgetSize); collapseIcon->setMaximumSize(widgetSize); - //add the actions that are actually set to visible. + // add the actions that are actually set to visible. foreach (QAction *action, actionsInOrder) { if (action->isVisible() && action != closeAction) { - IconWidget *icon = qobject_cast(actionWidgets.value(action)); - PushButton *button = qobject_cast(actionWidgets.value(action)); + ToolButton *tool = qobject_cast(actionWidgets.value(action)); - if (action->icon().isNull() && !action->text().isNull()) { - if (!button) { - button = new PushButton(q); - button->setAction(action); - } - - button->setMinimumHeight(widgetSize.height()); - button->setMaximumHeight(widgetSize.height()); - button->setCursor(Qt::ArrowCursor); - toolboxLayout->insertItem(startingIndex, button); - ++lastIndex; - } else { - if (!icon) { - icon = new IconWidget(q); - icon->setAction(action); - } - - if (action->icon().isNull()) { - icon->setText(action->text()); - } - icon->setMinimumSize(widgetSize); - icon->setMaximumSize(widgetSize); - icon->setCursor(Qt::ArrowCursor); - toolboxLayout->insertItem(startingIndex, icon); - ++lastIndex; + if (!tool) { + tool = new ToolButton(q); + tool->setAction(action); } + + tool->setMinimumHeight(widgetSize.height()); + tool->setMaximumHeight(widgetSize.height()); + tool->setCursor(Qt::ArrowCursor); + toolboxLayout->insertItem(startingIndex, tool); + ++lastIndex; } } - //add the returntosource icon if we are detached, and have a source applet. + // add the returntosource icon if we are detached, and have a source applet. if (returnToSourceVisibility && returnToSourceIndex == -1) { - IconWidget *returnToSourceIcon = new IconWidget(q); + ToolButton *returnToSourceButton = new ToolButton(q); if (!returnToSourceAction) { returnToSourceAction = new QAction(q); returnToSourceAction->setToolTip(i18n("Reattach")); @@ -924,23 +907,23 @@ void ExtenderItemPrivate::updateToolBox() QObject::connect(returnToSourceAction, SIGNAL(triggered()), q, SLOT(returnToSource())); } - returnToSourceIcon->setAction(returnToSourceAction); - returnToSourceIcon->setSvg("widgets/configuration-icons", "return-to-source"); - returnToSourceIcon->setMinimumSize(widgetSize); - returnToSourceIcon->setMaximumSize(widgetSize); - returnToSourceIcon->setCursor(Qt::ArrowCursor); + returnToSourceButton->setAction(returnToSourceAction); + returnToSourceButton->setImage("widgets/configuration-icons", "return-to-source"); + returnToSourceButton->setMinimumSize(widgetSize); + returnToSourceButton->setMaximumSize(widgetSize); + returnToSourceButton->setCursor(Qt::ArrowCursor); if (closeIndex == -1) { - toolboxLayout->addItem(returnToSourceIcon); + toolboxLayout->addItem(returnToSourceButton); } else { - toolboxLayout->insertItem(closeIndex - 1, returnToSourceIcon); + toolboxLayout->insertItem(closeIndex - 1, returnToSourceButton); } ++lastIndex; } - //add the close icon if desired. + // add the close icon if desired. if (destroyActionVisibility && closeIndex == -1) { - IconWidget *destroyButton = new IconWidget(q); + ToolButton *destroyButton = new ToolButton(q); if (!closeAction) { closeAction = new QAction(q); actions.insert("close", closeAction); @@ -951,7 +934,7 @@ void ExtenderItemPrivate::updateToolBox() } destroyButton->setAction(closeAction); - destroyButton->setSvg("widgets/configuration-icons", "close"); + destroyButton->setImage("widgets/configuration-icons", "close"); destroyButton->setMinimumSize(widgetSize); destroyButton->setMaximumSize(widgetSize); destroyButton->setCursor(Qt::ArrowCursor); diff --git a/plasma/popupapplet.cpp b/plasma/popupapplet.cpp index 0a57ac3c..4d415e3e 100644 --- a/plasma/popupapplet.cpp +++ b/plasma/popupapplet.cpp @@ -85,8 +85,8 @@ void PopupApplet::setPopupIcon(const QString &iconName) const QString name = QString("icons/") + iconName.split("-").first(); if (!Plasma::Theme::defaultTheme()->imagePath(name).isEmpty()) { d->createIconWidget(); - d->icon->setSvg(name, iconName); - if (d->icon->svg().isEmpty()) { + d->icon->setImage(name, iconName); + if (d->icon->image().isEmpty()) { setPopupIcon(KIcon(iconName)); } @@ -259,7 +259,7 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints) } //Applet on desktop - if ((((!parentApplet || parentApplet->isContainment() ) && icon && (!icon->svg().isEmpty() || !icon->icon().isNull()) && ((f != Plasma::Vertical && f != Plasma::Horizontal))) || + if ((((!parentApplet || parentApplet->isContainment() ) && icon && (!icon->image().isEmpty() || !icon->icon().isNull()) && ((f != Plasma::Vertical && f != Plasma::Horizontal))) || (((f == Plasma::Vertical && parentSize.width() >= minimum.width()) || (f == Plasma::Horizontal && parentSize.height() >= minimum.height())) && (!q->parentWidget() || (q->parentWidget()->size().width() >= minimum.width() && q->parentWidget()->size().height() >= minimum.height()))))) { diff --git a/plasma/widgets/calendarwidget.h b/plasma/widgets/calendarwidget.h index 44a0a720..98991240 100644 --- a/plasma/widgets/calendarwidget.h +++ b/plasma/widgets/calendarwidget.h @@ -79,4 +79,4 @@ private: }; } -#endif // multiple inclusion guard +#endif // PLASMA_CALENDARWIDGET_H diff --git a/plasma/widgets/iconwidget.cpp b/plasma/widgets/iconwidget.cpp index aa12e069..2bc9ca95 100644 --- a/plasma/widgets/iconwidget.cpp +++ b/plasma/widgets/iconwidget.cpp @@ -1,10 +1,5 @@ /* - * Copyright 2007 by Aaron Seigo - * Copyright 2007 by Riccardo Iaconelli - * Copyright 2007 by Matt Broadstone - * Copyright 2006-2007 Fredrik Höglund - * Copyright 2007 by Marco Martin - * Copyright 2008 by Alexis Ménard + * Copyright 2024 Ivailo Monev * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -23,123 +18,46 @@ */ #include "iconwidget.h" -#include "iconwidget_p.h" -#include "animator.h" -#include "animations/animation.h" -#include "paintutils.h" #include "private/themedwidgetinterface_p.h" -#include "theme.h" #include "svg.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "kiconeffect.h" +#include "kiconloader.h" +#include "kglobalsettings.h" +#include "kdebug.h" namespace Plasma { -IconHoverAnimation::IconHoverAnimation(QObject *parent) - : QObject(parent), m_value(0), m_fadeIn(false) +class IconWidgetPrivate : public ThemedWidgetInterface { -} +public: + IconWidgetPrivate(IconWidget *iconwidget); -qreal IconHoverAnimation::value() const + void svgChanged(); + void iconConfigChanged(); + + Svg *svg; + QString svgelement; + QIcon icon; + QSizeF iconSize; + bool pressed; + bool manualpressed; + bool hovered; +}; + + +IconWidgetPrivate::IconWidgetPrivate(IconWidget *iconwidget) + : ThemedWidgetInterface(iconwidget), + svg(nullptr), + iconSize(16, 16), + pressed(false), + manualpressed(false), + hovered(false) { - return m_value; -} - -bool IconHoverAnimation::fadeIn() const -{ - return m_fadeIn; -} - -QPropertyAnimation *IconHoverAnimation::animation() const -{ - return m_animation.data(); -} - -void IconHoverAnimation::setValue(qreal value) -{ - m_value = value; - QGraphicsWidget *item = static_cast(parent()); - item->update(); -} - -void IconHoverAnimation::setFadeIn(bool fadeIn) -{ - m_fadeIn = fadeIn; -} - -void IconHoverAnimation::setAnimation(QPropertyAnimation *animation) -{ - m_animation = animation; -} - -IconWidgetPrivate::IconWidgetPrivate(IconWidget *i) - : ActionWidgetInterface(i), - iconSvg(0), - hoverAnimation(new IconHoverAnimation(q)), - iconSize(48, 48), - preferredIconSize(-1, -1), - minimumIconSize(-1, -1), - maximumIconSize(-1, -1), - states(IconWidgetPrivate::NoState), - orientation(Qt::Vertical), - numDisplayLines(2), - activeMargins(0), - iconSvgElementChanged(false), - invertLayout(false), - drawBg(false), - textBgCustomized(false) -{ -} - -IconWidgetPrivate::~IconWidgetPrivate() -{ - qDeleteAll(cornerActions); - delete hoverAnimation; -} - -void IconWidgetPrivate::readColors() -{ - textColor = Plasma::Theme::defaultTheme()->color(Theme::TextColor); - - if (qGray(textColor.rgb()) > 192) { - shadowColor = Qt::black; - } else { - shadowColor = Qt::white; - } - - if (!textBgCustomized) { - textBgColor = QColor(); - } -} - -void IconWidgetPrivate::colorConfigChanged() -{ - readColors(); - if (drawBg) { - qreal left, top, right, bottom; - background->getMargins(left, top, right, bottom); - setVerticalMargin(IconWidgetPrivate::ItemMargin, left, top, right, bottom); - setHorizontalMargin(IconWidgetPrivate::ItemMargin, left, top, right, bottom); - } - q->update(); } void IconWidgetPrivate::iconConfigChanged() @@ -149,209 +67,24 @@ void IconWidgetPrivate::iconConfigChanged() } } -IconAction::IconAction(IconWidget *icon, QAction *action) - : m_icon(icon), - m_action(action), - m_hovered(false), - m_pressed(false), - m_selected(false), - m_visible(false) +void IconWidgetPrivate::svgChanged() { -} - -void IconAction::show() -{ - Animation *animation = m_animation.data(); - if (!animation) { - animation = Plasma::Animator::create(Plasma::Animator::PixmapTransitionAnimation, m_icon); - animation->setTargetWidget(m_icon); - m_animation = animation; - } else if (animation->state() == QAbstractAnimation::Running) { - animation->pause(); - } - - rebuildPixmap(); - m_visible = true; - - animation->setProperty("targetPixmap", m_pixmap); - animation->setDirection(QAbstractAnimation::Forward); - animation->start(); -} - -void IconAction::hide() -{ - if (!m_animation) { - return; - } - - Animation *animation = m_animation.data(); - if (animation->state() == QAbstractAnimation::Running) { - animation->pause(); - } - - m_visible = false; - - animation->setDirection(QAbstractAnimation::Backward); - animation->start(QAbstractAnimation::DeleteWhenStopped); -} - -bool IconAction::isVisible() const -{ - return m_visible; -} - -bool IconAction::isAnimating() const -{ - return !m_animation.isNull(); -} - -bool IconAction::isPressed() const -{ - return m_pressed; -} - -bool IconAction::isHovered() const -{ - return m_hovered; -} - -void IconAction::setSelected(bool selected) -{ - m_selected = selected; -} - -bool IconAction::isSelected() const -{ - return m_selected; -} - -void IconAction::setRect(const QRectF &rect) -{ - m_rect = rect; -} - -QRectF IconAction::rect() const -{ - return m_rect; -} - -void IconAction::rebuildPixmap() -{ - // Determine proper QIcon mode based on selection status - QIcon::Mode mode = m_selected ? QIcon::Selected : QIcon::Normal; - - // Draw everything - m_pixmap = QPixmap(26, 26); - m_pixmap.fill(Qt::transparent); - - int element = IconWidgetPrivate::Minibutton; - if (m_pressed) { - element = IconWidgetPrivate::MinibuttonPressed; - } else if (m_hovered) { - element = IconWidgetPrivate::MinibuttonHover; - } - - QPainter painter(&m_pixmap); - m_icon->drawActionButtonBase(&painter, m_pixmap.size(), element); - m_action->icon().paint(&painter, 2, 2, 22, 22, Qt::AlignCenter, mode); -} - -bool IconAction::event(QEvent::Type type, const QPointF &pos) -{ - if (!m_action->isVisible() || !m_action->isEnabled()) { - return false; - } - - if (m_icon->size().width() < m_rect.width() * 2.0 || - m_icon->size().height() < m_rect.height() * 2.0) { - return false; - } - - switch (type) { - case QEvent::GraphicsSceneMousePress: { - setSelected(m_rect.contains(pos)); - return isSelected(); - } - case QEvent::GraphicsSceneMouseMove: { - bool wasSelected = isSelected(); - bool active = m_rect.contains(pos); - setSelected(wasSelected && active); - return (wasSelected != isSelected()) || active; - } - case QEvent::GraphicsSceneMouseRelease: { - // kDebug() << "IconAction::event got a QEvent::MouseButtonRelease, " << isSelected(); - bool wasSelected = isSelected(); - setSelected(false); - if (wasSelected) { - m_action->trigger(); - } - return wasSelected; - } - case QEvent::GraphicsSceneHoverEnter: { - m_pressed = false; - m_hovered = true; - break; - } - case QEvent::GraphicsSceneHoverLeave: { - m_pressed = false; - m_hovered = false; - break; - } - default: { - break; - } - } - - return false; -} - -QAction *IconAction::action() const -{ - return m_action; -} - -void IconAction::paint(QPainter *painter) const -{ - if (!m_action->isVisible() || !m_action->isEnabled()) { - return; - } - - if (m_icon->size().width() < m_rect.width() * 2.0 || - m_icon->size().height() < m_rect.height() * 2.0) { - return; - } - - Animation *animation = m_animation.data(); - if (m_visible && !animation) { - painter->drawPixmap(m_rect.toRect(), m_pixmap); - } else { - painter->drawPixmap(m_rect.toRect(), - animation->property("currentPixmap").value()); - } + q->update(); } IconWidget::IconWidget(QGraphicsItem *parent) : QGraphicsWidget(parent), - d(new IconWidgetPrivate(this)) + d(new IconWidgetPrivate(this)) { - d->init(); -} + setAcceptedMouseButtons(Qt::LeftButton); + setAcceptHoverEvents(true); -IconWidget::IconWidget(const QString &text, QGraphicsItem *parent) - : QGraphicsWidget(parent), - d(new IconWidgetPrivate(this)) -{ - d->init(); - setText(text); -} + d->initTheming(); -IconWidget::IconWidget(const QIcon &icon, const QString &text, QGraphicsItem *parent) - : QGraphicsWidget(parent), - d(new IconWidgetPrivate(this)) -{ - d->init(); - setText(text); - setIcon(icon); + connect( + KGlobalSettings::self(), SIGNAL(iconChanged(int)), + this, SLOT(iconConfigChanged()) + ); } IconWidget::~IconWidget() @@ -359,906 +92,90 @@ IconWidget::~IconWidget() delete d; } -void IconWidgetPrivate::init() +void IconWidget::IconWidget::setImage(const QString &path) { - readColors(); - - iconChangeTimer = new QTimer(q); - iconChangeTimer->setSingleShot(true); - - QObject::connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), q, SLOT(colorConfigChanged())); - QObject::connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), q, SLOT(colorConfigChanged())); - QObject::connect(KGlobalSettings::self(), SIGNAL(iconChanged(int)), q, SLOT(iconConfigChanged())); - - // setAcceptedMouseButtons(Qt::LeftButton); - q->setAcceptHoverEvents(true); - q->setCacheMode(QGraphicsItem::DeviceCoordinateCache); - - background = new Plasma::FrameSvg(q); - background->setImagePath("widgets/viewitem"); - background->setCacheAllRenderedFrames(true); - background->setElementPrefix("hover"); - - // Margins for horizontal mode (list views, tree views, table views) - setHorizontalMargin(IconWidgetPrivate::TextMargin, 1, 1); - setHorizontalMargin(IconWidgetPrivate::IconMargin, 1, 1); - setHorizontalMargin(IconWidgetPrivate::ItemMargin, 0, 0); - - // Margins for vertical mode (icon views) - setVerticalMargin(IconWidgetPrivate::TextMargin, 6, 2); - setVerticalMargin(IconWidgetPrivate::IconMargin, 1, 1); - setVerticalMargin(IconWidgetPrivate::ItemMargin, 0, 0); - - setActiveMargins(); - currentSize = QSizeF(-1, -1); - initTheming(); + setImage(path, QString()); } -void IconWidget::addIconAction(QAction *action) +void IconWidget::setImage(const QString &path, const QString &elementid) { - int count = d->cornerActions.count(); - if (count >= IconWidgetPrivate::LastIconPosition) { - kDebug() << "no more room for more actions!"; - // just overlap it with the last item for now. ugly, but there you go. + d->svgelement = elementid; + if (d->svg) { + d->svg->deleteLater(); + d->svg = nullptr; } - - IconAction *iconAction = new IconAction(this, action); - d->cornerActions.append(iconAction); - connect(action, SIGNAL(destroyed(QObject*)), this, SLOT(actionDestroyed(QObject*))); - - iconAction->setRect(d->actionRect(qMin((IconWidgetPrivate::ActionPosition)count, IconWidgetPrivate::LastIconPosition))); -} - -void IconWidget::removeIconAction(QAction *action) -{ - //WARNING: do NOT access the action pointer passed in, as it may already be - //be destroyed. see IconWidgetPrivate::actionDestroyed(QObject*) - int count = 0; - bool found = false; - foreach (IconAction *iconAction, d->cornerActions) { - if (found) { - iconAction->setRect(d->actionRect((IconWidgetPrivate::ActionPosition)count)); - } else if (!action || iconAction->action() == action) { - delete iconAction; - d->cornerActions.removeAll(iconAction); - } - - if (count < IconWidgetPrivate::LastIconPosition) { - ++count; - } - } - - // redraw since an action has been deleted. - update(); -} - -void IconWidgetPrivate::actionDestroyed(QObject *action) -{ - q->removeIconAction(static_cast(action)); -} - -void IconWidget::setAction(QAction *action) -{ - d->setAction(action); -} - -QAction *IconWidget::action() const -{ - return d->action; -} - -int IconWidget::numDisplayLines() const -{ - return d->numDisplayLines; -} - -void IconWidget::setNumDisplayLines(int numLines) -{ - if (numLines > d->maxDisplayLines) { - d->numDisplayLines = d->maxDisplayLines; - } else { - d->numDisplayLines = numLines; - } -} - -void IconWidget::setDrawBackground(bool draw) -{ - if (d->drawBg != draw) { - d->drawBg = draw; - - QStyle *style = QApplication::style(); - int focusHMargin = draw ? style->pixelMetric(QStyle::PM_FocusFrameHMargin) : 1; - int focusVMargin = draw ? style->pixelMetric(QStyle::PM_FocusFrameVMargin) : 1; - d->setHorizontalMargin(IconWidgetPrivate::TextMargin, focusHMargin, focusVMargin); - d->setHorizontalMargin(IconWidgetPrivate::IconMargin, focusHMargin, focusVMargin); - d->setVerticalMargin(IconWidgetPrivate::IconMargin, focusHMargin, focusVMargin); - d->currentSize = QSizeF(-1, -1); - - if (draw) { - qreal left, top, right, bottom; - d->background->getMargins(left, top, right, bottom); - d->setHorizontalMargin(IconWidgetPrivate::ItemMargin, left, top, right, bottom); - d->setVerticalMargin(IconWidgetPrivate::ItemMargin, left, top, right, bottom); - } else { - d->setHorizontalMargin(IconWidgetPrivate::ItemMargin, 0, 0); - d->setVerticalMargin(IconWidgetPrivate::ItemMargin, 0, 0); - } - - update(); - updateGeometry(); - } -} - -bool IconWidget::drawBackground() const -{ - return d->drawBg; -} - -QPainterPath IconWidget::shape() const -{ - if (!d->drawBg || d->currentSize.width() < 1) { - return QGraphicsItem::shape(); - } - - return PaintUtils::roundedRectangle( - QRectF(QPointF(0.0, 0.0), d->currentSize).adjusted(-2, -2, 2, 2), 10.0); -} - -QSizeF IconWidgetPrivate::displaySizeHint(const QStyleOptionGraphicsItem *option, const qreal width) const -{ - if (text.isEmpty() && infoText.isEmpty()) { - return QSizeF(.0, .0); - } - - QString label = text; - // const qreal maxWidth = (orientation == Qt::Vertical) ? iconSize.width() + 10 : 32757; - // NOTE: find a way to use the other layoutText, it currently returns nominal width, when - // we actually need the actual width. - - qreal textWidth = width - - horizontalMargin[IconWidgetPrivate::TextMargin].left - - horizontalMargin[IconWidgetPrivate::TextMargin].right; - - //allow only five lines of text - const qreal maxHeight = - numDisplayLines * QFontMetrics(q->font()).lineSpacing(); - - // To compute the nominal size for the label + info, we'll just append - // the information string to the label - if (!infoText.isEmpty()) { - label += QString(QChar::LineSeparator) + infoText; - } - - QTextLayout layout; - setLayoutOptions(layout, option, q->orientation()); - layout.setFont(q->font()); - QSizeF size = layoutText(layout, label, QSizeF(textWidth, maxHeight)); - - return addMargin(size, TextMargin); -} - -void IconWidgetPrivate::layoutIcons(const QStyleOptionGraphicsItem *option) -{ - if (option->rect.size() == currentSize) { - return; - } - - currentSize = option->rect.size(); - iconSize = iconSizeForWidgetSize(option, currentSize); - - int count = 0; - foreach (IconAction *iconAction, cornerActions) { - iconAction->setRect(actionRect((IconWidgetPrivate::ActionPosition)count)); - ++count; - } -} - -QSizeF IconWidgetPrivate::iconSizeForWidgetSize(const QStyleOptionGraphicsItem *option, const QSizeF &rect) -{ - setActiveMargins(); - - //calculate icon size based on the available space - qreal iconWidth; - - if (orientation == Qt::Vertical) { - qreal heightAvail; - //if there is text resize the icon in order to make room for the text - if (text.isEmpty() && infoText.isEmpty()) { - heightAvail = rect.height(); - } else { - heightAvail = rect.height() - - displaySizeHint(option, rect.width()).height() - - verticalMargin[IconWidgetPrivate::TextMargin].top - - verticalMargin[IconWidgetPrivate::TextMargin].bottom; - //never make a label higher than half the total height - heightAvail = qMax(heightAvail, rect.height() / 2); - } - - //aspect ratio very "tall" - if (!text.isEmpty() || !infoText.isEmpty()) { - if (rect.width() < heightAvail) { - iconWidth = rect.width() - - verticalMargin[IconWidgetPrivate::IconMargin].left - - verticalMargin[IconWidgetPrivate::IconMargin].right; - } else { - iconWidth = heightAvail - - verticalMargin[IconWidgetPrivate::IconMargin].top - - verticalMargin[IconWidgetPrivate::IconMargin].bottom; - } - } else { - iconWidth = qMin(heightAvail, rect.width()); - } - - iconWidth -= verticalMargin[IconWidgetPrivate::ItemMargin].left + verticalMargin[IconWidgetPrivate::ItemMargin].right; - } else { - //Horizontal layout - //if there is text resize the icon in order to make room for the text - if (text.isEmpty() && infoText.isEmpty()) { - // with no text, we just take up the whole geometry - iconWidth = qMin(rect.height(), rect.width()); - } else { - iconWidth = rect.height() - - horizontalMargin[IconWidgetPrivate::IconMargin].top - - horizontalMargin[IconWidgetPrivate::IconMargin].bottom; - } - iconWidth -= horizontalMargin[IconWidgetPrivate::ItemMargin].top + horizontalMargin[IconWidgetPrivate::ItemMargin].bottom; - } - - QSizeF iconRect(iconWidth, iconWidth); - - if (maximumIconSize.isValid()) { - iconRect = iconRect.boundedTo(maximumIconSize); - } - - return iconRect; -} - -void IconWidget::setSvg(const QString &svgFilePath, const QString &elementId) -{ - if (svgFilePath.isEmpty()) { - if (d->iconSvg) { - d->iconSvg->deleteLater(); - d->iconSvg = 0; - } - return; - } - - if (!d->iconSvg) { - d->iconSvg = new Plasma::Svg(this); - connect(d->iconSvg, SIGNAL(repaintNeeded()), this, SLOT(svgChanged())); - d->oldIcon = d->icon; - } else { - d->oldIcon = d->iconSvg->pixmap(d->iconSvgElement); - } - - d->iconSvg->setImagePath(svgFilePath); - d->iconSvg->setContainsMultipleImages(!elementId.isNull()); - d->iconSvgElement = elementId; - d->iconSvgElementChanged = true; - updateGeometry(); - - if (!(d->states & IconWidgetPrivate::HoverState) && !d->iconChangeTimer->isActive() && !d->oldIcon.isNull()) { - d->animateMainIcon(true, d->states); - } else { - d->oldIcon = QIcon(); - update(); - } - d->iconChangeTimer->start(300); d->icon = QIcon(); + if (path.isEmpty()) { + return; + } + d->svg = new Svg(this); + d->svg->setImagePath(path); + d->svg->setContainsMultipleImages(!elementid.isEmpty()); + connect( + d->svg, SIGNAL(repaintNeeded()), + this, SLOT(svgChanged()) + ); } -QString IconWidget::svg() const +QString IconWidget::image() const { - if (d->iconSvg) { - if (d->iconSvg->isValid() && (d->iconSvgElement.isEmpty() || d->iconSvg->hasElement(d->iconSvgElement))) { - return d->iconSvg->imagePath(); - } else { - return QString(); - } + if (d->svg && d->svg->isValid()) { + return d->svg->imagePath(); } - return QString(); } -QSizeF IconWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const +QSizeF IconWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const { - if (which == Qt::PreferredSize) { - int iconSize; - - if (d->preferredIconSize.isValid()) { - iconSize = qMax(d->preferredIconSize.height(), d->preferredIconSize.width()); - } else if (d->iconSvg) { - QSizeF oldSize = d->iconSvg->size(); - d->iconSvg->resize(); - if (d->iconSvgElement.isNull()) { - iconSize = qMax(d->iconSvg->size().width(), d->iconSvg->size().height()); - } else { - iconSize = qMax(d->iconSvg->elementSize(d->iconSvgElement).width(), d->iconSvg->elementSize(d->iconSvgElement).height()); - } - d->iconSvg->resize(oldSize); - } else { - iconSize = KIconLoader::SizeMedium; - } - - if (constraint.width() > 0 || constraint.height() > 0) { - QSizeF constrainedWidgetSize(constraint); - QSizeF maximumWidgetSize; - - if (d->maximumIconSize.isValid()) { - maximumWidgetSize = - sizeFromIconSize(qMax(d->maximumIconSize.height(), d->maximumIconSize.width())); - } else { - maximumWidgetSize = - QGraphicsWidget::sizeHint(Qt::MaximumSize); - } - - if (constrainedWidgetSize.width() <= 0) { - constrainedWidgetSize.setWidth(maximumWidgetSize.width()); - } - if (constrainedWidgetSize.height() <= 0) { - constrainedWidgetSize.setHeight(maximumWidgetSize.height()); - } - - QStyleOptionGraphicsItem option; - QSizeF iconRect = - d->iconSizeForWidgetSize(&option, constrainedWidgetSize); - iconSize = - qMin(iconSize, qMax(iconRect.width(), iconRect.height())); - } - - return sizeFromIconSize(iconSize); - } else if (which == Qt::MinimumSize) { - if (d->minimumIconSize.isValid()) { - return sizeFromIconSize(qMax(d->minimumIconSize.height(), d->minimumIconSize.width())); - } - - return sizeFromIconSize(KIconLoader::SizeSmall); - } else { - if (d->maximumIconSize.isValid()) { - return sizeFromIconSize(qMax(d->maximumIconSize.height(), d->maximumIconSize.width())); - } - - return QGraphicsWidget::sizeHint(which, constraint); + if (!d->svg && d->icon.pixmap(d->iconSize.toSize()).isNull()) { + return QSizeF(0, 0); } -} - -void IconWidgetPrivate::animateMainIcon(bool show, const IconWidgetStates state) -{ - if (show) { - states = state; - } - - hoverAnimation->setFadeIn(show); - - QPropertyAnimation *animation = hoverAnimation->animation(); - if (!animation) { - animation = new QPropertyAnimation(hoverAnimation, "value"); - animation->setDuration(150); - animation->setEasingCurve(QEasingCurve::OutQuad); - animation->setStartValue(0.0); - animation->setEndValue(1.0); - hoverAnimation->setAnimation(animation); - q->connect(animation, SIGNAL(finished()), q, SLOT(hoverAnimationFinished())); - } else if (animation->state() == QAbstractAnimation::Running) { - animation->pause(); - } - - animation->setDirection(show ? QAbstractAnimation::Forward : QAbstractAnimation::Backward); - animation->start(show ? QAbstractAnimation::KeepWhenStopped : QAbstractAnimation::DeleteWhenStopped); - q->update(); -} - -void IconWidgetPrivate::hoverAnimationFinished() -{ - if (!hoverAnimation->fadeIn()) { - states &= ~IconWidgetPrivate::HoverState; - } -} - -void IconWidgetPrivate::drawBackground(QPainter *painter, IconWidgetState state) -{ - if (!drawBg) { - return; - } - - if (!(states & IconWidgetPrivate::HoverState) && !(states & IconWidgetPrivate::PressedState)) { - return; - } - - if (state == IconWidgetPrivate::PressedState) { - background->setElementPrefix("selected"); - } else { - background->setElementPrefix("hover"); - } - - if (qFuzzyCompare(hoverAnimation->value(), 1)) { - background->resizeFrame(currentSize); - background->paintFrame(painter); - } else if (!qFuzzyCompare(hoverAnimation->value()+1, 1)) { - background->resizeFrame(currentSize); - QPixmap frame = background->framePixmap(); - QPainter bufferPainter(&frame); - bufferPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn); - bufferPainter.fillRect(frame.rect(), QColor(0,0,0, 255*hoverAnimation->value())); - bufferPainter.end(); - painter->drawPixmap(QPoint(0,0), frame); - } -} - -QPixmap IconWidgetPrivate::decoration(const QStyleOptionGraphicsItem *option, bool useHoverEffect, bool usePressedEffect) -{ - QPixmap result; - - QIcon::Mode mode = option->state & QStyle::State_Enabled ? QIcon::Normal : QIcon::Disabled; - QIcon::State state = option->state & QStyle::State_Open ? QIcon::On : QIcon::Off; - - QSize finalSize(iconSize.toSize()); - //for small sizes, use a standard size - if (finalSize.width() < KIconLoader::SizeSmallMedium) { - finalSize = QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall); - } else if (finalSize.width() < KIconLoader::SizeMedium) { - finalSize = QSize(KIconLoader::SizeSmallMedium, KIconLoader::SizeSmallMedium); - } else if (finalSize.width() < KIconLoader::SizeLarge) { - finalSize = QSize(KIconLoader::SizeMedium, KIconLoader::SizeMedium); - } - - if (iconSvg) { - if (iconSvgElementChanged || iconSvgPixmap.size() != iconSize.toSize()) { - //even the svg is returned at standard sizes because: - // * it may have a version optimized for that size - // * look aligned with other icons - iconSvg->resize(finalSize); - iconSvgPixmap = iconSvg->pixmap(iconSvgElement); - iconSvgElementChanged = false; - } - result = iconSvgPixmap; - } else { - //the QIcon isn't filled with available sizes, return a near standard size for small pixmaps - if (!icon.availableSizes().isEmpty()) { - finalSize = icon.actualSize(iconSize.toSize(), mode, state); - } - - result = icon.pixmap(finalSize, mode, state); - } - - if (usePressedEffect) { - result = result.scaled(result.size() * 0.9, Qt::KeepAspectRatio, Qt::SmoothTransformation); - } - - if (!result.isNull() && useHoverEffect) { - KIconEffect *effect = KIconLoader::global()->iconEffect(); - // Note that in KIconLoader terminology, active = hover. - // We're assuming that the icon group is desktop/filemanager, since this - // is KFileItemDelegate. - if (effect->hasEffect(KIconLoader::Desktop, KIconLoader::ActiveState)) { - if (qFuzzyCompare(qreal(1.0), hoverAnimation->value())) { - result = effect->apply(result, KIconLoader::Desktop, KIconLoader::ActiveState); - } else { - result = PaintUtils::transition( - result, - effect->apply(result, KIconLoader::Desktop, - KIconLoader::ActiveState), hoverAnimation->value()); - } - } - } else if (!result.isNull() && !oldIcon.isNull()) { - if (qFuzzyCompare(qreal(1.0), hoverAnimation->value())) { - oldIcon = QIcon(); - } else { - result = PaintUtils::transition( - oldIcon.pixmap(result.size(), mode, state), - result, hoverAnimation->value()); - } - } - - return result; -} - -QPointF IconWidgetPrivate::iconPosition(const QStyleOptionGraphicsItem *option, - const QPixmap &pixmap) const -{ - const QRectF itemRect = subtractMargin(option->rect, IconWidgetPrivate::ItemMargin); - - // Compute the nominal decoration rectangle - const QSizeF size = addMargin(iconSize, IconWidgetPrivate::IconMargin); - - Qt::LayoutDirection direction = iconDirection(option); - - //alignment depends from orientation and option->direction - Qt::Alignment alignment; - if (text.isEmpty() && infoText.isEmpty()) { - alignment = Qt::AlignCenter; - } else if (orientation == Qt::Vertical) { - alignment = Qt::Alignment(Qt::AlignHCenter | Qt::AlignTop); - //Horizontal - } else { - alignment = QStyle::visualAlignment( - direction, Qt::Alignment(Qt::AlignLeft | Qt::AlignVCenter)); - } - - const QRect iconRect = - QStyle::alignedRect(direction, alignment, size.toSize(), itemRect.toRect()); - - // Position the pixmap in the center of the rectangle - QRect pixmapRect = pixmap.rect(); - pixmapRect.moveCenter(iconRect.center()); - - // add a gimmicky margin of 5px to y, TEMP TEMP TEMP - // pixmapRect = pixmapRect.adjusted(0, 5, 0, 0); - - return QPointF(pixmapRect.topLeft()); -} - -QRectF IconWidgetPrivate::labelRectangle(const QStyleOptionGraphicsItem *option, - const QPixmap &icon, - const QString &string) const -{ - Q_UNUSED(string) - - if (icon.isNull()) { - return option->rect; - } - - const QSizeF decoSize = addMargin(iconSize, IconWidgetPrivate::IconMargin); - const QRectF itemRect = subtractMargin(option->rect, IconWidgetPrivate::ItemMargin); - QRectF textArea(QPointF(0, 0), itemRect.size()); - - if (orientation == Qt::Vertical) { - textArea.setTop(decoSize.height() + 1); - } else { - //Horizontal - textArea.setLeft(decoSize.width() + 1); - } - - textArea.translate(itemRect.topLeft()); - return QRectF(QStyle::visualRect(iconDirection(option), option->rect, textArea.toRect())); -} - -// Lays the text out in a rectangle no larger than constraints, eliding it as necessary -QSizeF IconWidgetPrivate::layoutText(QTextLayout &layout, - const QString &text, - const QSizeF &constraints) const -{ - const QSizeF size = layoutText(layout, text, constraints.width()); - - if (size.width() > constraints.width() || size.height() > constraints.height()) { - if (action) { - q->setToolTip(action->toolTip()); - } - const QString elided = elidedText(layout, constraints); - return layoutText(layout, elided, constraints.width()); - } - q->setToolTip(QString()); - - return size; -} - -// Lays the text out in a rectangle no wider than maxWidth -QSizeF IconWidgetPrivate::layoutText(QTextLayout &layout, const QString &text, qreal maxWidth) const -{ - QFontMetricsF metrics(layout.font()); - qreal leading = metrics.leading(); - qreal height = 0.0; - qreal widthUsed = 0.0; - QTextLine line; - - layout.setText(text); - - layout.beginLayout(); - - while ((line = layout.createLine()).isValid()) { - line.setLineWidth(maxWidth); - height += leading; - line.setPosition(QPointF(0.0, height)); - height += line.height(); - widthUsed = qMax(widthUsed, line.naturalTextWidth()); - } - layout.endLayout(); - - return QSizeF(widthUsed, height); -} - -// Elides the text in the layout, by iterating over each line in the layout, eliding -// or word breaking the line if it's wider than the max width, and finally adding an -// ellipses at the end of the last line, if there are more lines than will fit within -// the vertical size constraints. -QString IconWidgetPrivate::elidedText(QTextLayout &layout, const QSizeF &size) const -{ - QFontMetricsF metrics(layout.font()); - const QString text = layout.text(); - qreal maxWidth = size.width(); - qreal maxHeight = size.height(); - qreal height = 0; - - // Elide each line that has already been laid out in the layout. - QString elided; - elided.reserve(text.length()); - - for (int i = 0; i < layout.lineCount(); i++) { - QTextLine line = layout.lineAt(i); - int start = line.textStart(); - int length = line.textLength(); - - height += metrics.leading(); - if (height + line.height() + metrics.lineSpacing() > maxHeight) { - // Unfortunately, if the line ends because of a line separator, - // elidedText() will be too clever and keep adding lines until - // it finds one that's too wide. - if (line.naturalTextWidth() < maxWidth && - start + length > 0 && - text[start + length - 1] == QChar::LineSeparator) { - elided += text.mid(start, length - 1); - } else { - elided += metrics.elidedText(text.mid(start), Qt::ElideRight, maxWidth); - } - break; - } else if (line.naturalTextWidth() > maxWidth) { - elided += metrics.elidedText(text.mid(start, length), Qt::ElideRight, maxWidth); - } else { - elided += text.mid(start, length); - } - - height += line.height(); - } - - return elided; -} - -void IconWidgetPrivate::layoutTextItems(const QStyleOptionGraphicsItem *option, - const QPixmap &icon, QTextLayout *labelLayout, - QTextLayout *infoLayout, QRectF *textBoundingRect) -{ - bool showInformation = false; - - setLayoutOptions(*labelLayout, option, q->orientation()); - - QFontMetricsF fm(labelLayout->font()); - const QRectF textArea = labelRectangle(option, icon, text); - QRectF textRect = subtractMargin(textArea, IconWidgetPrivate::TextMargin); - - //kDebug() << this << "text area" << textArea << "text rect" << textRect; - // Sizes and constraints for the different text parts - QSizeF maxLabelSize = textRect.size(); - QSizeF maxInfoSize = textRect.size(); - QSizeF labelSize; - QSizeF infoSize; - - // If we have additional info text, and there's space for at least two lines of text, - // adjust the max label size to make room for at least one line of the info text - if (!infoText.isEmpty() && textRect.height() >= fm.lineSpacing() * 2) { - infoLayout->setFont(labelLayout->font()); - infoLayout->setTextOption(labelLayout->textOption()); - - maxLabelSize.rheight() -= fm.lineSpacing(); - showInformation = true; - } - - // Lay out the label text, and adjust the max info size based on the label size - labelSize = layoutText(*labelLayout, text, maxLabelSize); - maxInfoSize.rheight() -= labelSize.height(); - - // Lay out the info text - if (showInformation) { - infoSize = layoutText(*infoLayout, infoText, maxInfoSize); - } else { - infoSize = QSizeF(0, 0); - } - // Compute the bounding rect of the text - const Qt::Alignment alignment = labelLayout->textOption().alignment(); - const QSizeF size(qMax(labelSize.width(), infoSize.width()), - labelSize.height() + infoSize.height()); - *textBoundingRect = - QStyle::alignedRect(iconDirection(option), alignment, size.toSize(), textRect.toRect()); - - // Compute the positions where we should draw the layouts - haloRects.clear(); - labelLayout->setPosition(QPointF(textRect.x(), textBoundingRect->y())); - QTextLine line; - for (int i = 0; i < labelLayout->lineCount(); ++i) { - line = labelLayout->lineAt(i); - haloRects.append(line.naturalTextRect().translated(labelLayout->position().toPoint()).toRect()); - } - infoLayout->setPosition(QPointF(textRect.x(), textBoundingRect->y() + labelSize.height())); - for (int i = 0; i < infoLayout->lineCount(); ++i) { - line = infoLayout->lineAt(i); - haloRects.append(line.naturalTextRect().translated(infoLayout->position().toPoint()).toRect()); - } - //kDebug() << "final position is" << labelLayout->position(); -} - -void IconWidgetPrivate::drawTextItems(QPainter *painter, - const QStyleOptionGraphicsItem *option, - const QTextLayout &labelLayout, - const QTextLayout &infoLayout) const -{ - Q_UNUSED(option) - - painter->save(); - painter->setPen(textColor); - - // the translation prevents odd rounding errors in labelLayout.position() - // when applied to the canvas - painter->translate(0.5, 0.5); - - labelLayout.draw(painter, QPointF()); - - if (!infoLayout.text().isEmpty()) { - painter->setPen(textColor); - infoLayout.draw(painter, QPointF()); - } - painter->restore(); + return QGraphicsWidget::sizeHint(which, constraint); } void IconWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - Q_UNUSED(widget); + QPixmap pixmap; + QSizeF paintsize = d->iconSize; + paintsize.scale(option->rect.size(), Qt::KeepAspectRatio); - //Lay out the main icon and action icons - d->layoutIcons(option); - - // Compute the metrics, and lay out the text items - // ======================================================================== - IconWidgetPrivate::IconWidgetState state = IconWidgetPrivate::NoState; - if (d->states & IconWidgetPrivate::ManualPressedState) { - state = IconWidgetPrivate::PressedState; - } else if (d->states & IconWidgetPrivate::PressedState) { - if (d->states & IconWidgetPrivate::HoverState) { - state = IconWidgetPrivate::PressedState; - } - } else if (d->states & IconWidgetPrivate::HoverState) { - state = IconWidgetPrivate::HoverState; + if (d->pressed || d->manualpressed) { + // this magic number seems like it does it + paintsize -= (paintsize / 10); } - QPixmap icon = d->decoration(option, state != IconWidgetPrivate::NoState, state & IconWidgetPrivate::PressedState); - const QPointF iconPos = d->iconPosition(option, icon); - - d->drawBackground(painter, state); - - // draw icon - if (!icon.isNull()) { - painter->drawPixmap(iconPos, icon); - } - - // Draw corner actions - foreach (const IconAction *action, d->cornerActions) { - if (action->isAnimating()) { - action->paint(painter); + if (d->svg) { + d->svg->resize(paintsize); + pixmap = d->svg->pixmap(d->svgelement); + if (pixmap.isNull()) { + return; } - } - - // Draw text last because it is overlayed - QTextLayout labelLayout, infoLayout; - QRectF textBoundingRect; - - d->layoutTextItems(option, icon, &labelLayout, &infoLayout, &textBoundingRect); - - if (d->textBgColor != QColor() && d->textBgColor.alpha() > 0 && - !(d->text.isEmpty() && d->infoText.isEmpty()) && - !textBoundingRect.isEmpty() && - !qFuzzyCompare(d->hoverAnimation->value(), (qreal)1.0)) { - QRectF rect = textBoundingRect.adjusted(-2, -2, 4, 4).toAlignedRect(); - painter->setPen(Qt::transparent); - QColor color = d->textBgColor; - color.setAlpha(60 * (1.0 - d->hoverAnimation->value())); - QLinearGradient gradient(rect.topLeft(), rect.bottomLeft()); - gradient.setColorAt(0, color.lighter(120)); - gradient.setColorAt(1, color.darker(120)); - painter->setBrush(gradient); - gradient.setColorAt(0, color.lighter(130)); - gradient.setColorAt(1, color.darker(130)); - painter->setPen(QPen(gradient, 0)); - painter->setRenderHint(QPainter::Antialiasing); - painter->drawPath(PaintUtils::roundedRectangle(rect.translated(0.5, 0.5), 4)); - } - - - if (d->shadowColor.value() < 128 || textBackgroundColor() != QColor()) { - QPoint shadowPos; - if (d->shadowColor.value() < 128) { - shadowPos = QPoint(1, 2); - } else { - shadowPos = QPoint(0, 0); - } - - QImage shadow(textBoundingRect.size().toSize() + QSize(4, 4), - QImage::Format_ARGB32_Premultiplied); - shadow.fill(Qt::transparent); - { - QPainter buffPainter(&shadow); - buffPainter.translate(-textBoundingRect.x(), -textBoundingRect.y()); - d->drawTextItems(&buffPainter, option, labelLayout, infoLayout); - } - - PaintUtils::shadowBlur(shadow, 2, d->shadowColor); - painter->drawImage(textBoundingRect.topLeft() + shadowPos, shadow); - } else if (!(d->text.isEmpty() && d->infoText.isEmpty()) && - !textBoundingRect.isEmpty()) { - // QRect labelRect = d->labelRectangle(option, icon, d->text).toRect(); - - foreach (const QRect &rect, d->haloRects) { - Plasma::PaintUtils::drawHalo(painter, rect); - } - } - - d->drawTextItems(painter, option, labelLayout, infoLayout); -} - -void IconWidget::setTextBackgroundColor(const QColor &color) -{ - d->textBgCustomized = true; - d->textBgColor = color; - update(); -} - -QColor IconWidget::textBackgroundColor() const -{ - return d->textBgColor; -} - -void IconWidget::drawActionButtonBase(QPainter *painter, const QSize &size, int element) -{ - qreal radius = size.width() / 2; - QRadialGradient gradient(radius, radius, radius, radius, radius); - int alpha; - - if (element == IconWidgetPrivate::MinibuttonPressed) { - alpha = 255; - } else if (element == IconWidgetPrivate::MinibuttonHover) { - alpha = 200; } else { - alpha = 160; + pixmap = d->icon.pixmap(option->rect.size()); + if (pixmap.isNull()) { + return; + } + pixmap = pixmap.scaled(paintsize.toSize()); } - gradient.setColorAt(0, QColor::fromRgb(d->textColor.red(), - d->textColor.green(), - d->textColor.blue(), alpha)); - gradient.setColorAt(1, QColor::fromRgb(d->textColor.red(), - d->textColor.green(), - d->textColor.blue(), 0)); - painter->setBrush(gradient); - painter->setPen(Qt::NoPen); - painter->drawEllipse(QRectF(QPointF(.0, .0), size)); -} - -void IconWidget::setText(const QString &text) -{ - d->text = KGlobal::locale()->removeAcceleratorMarker(text); - // cause a relayout - d->currentSize = QSizeF(-1, -1); - //try to relayout, needed if an icon was never shown before - if (!isVisible()) { - QStyleOptionGraphicsItem styleoption; - d->layoutIcons(&styleoption); + KIconEffect* iconeffect = KIconLoader::global()->iconEffect(); + QStyle* style = widget->style(); + if (!isEnabled()) { + style->drawItemPixmap( + painter, option->rect, Qt::AlignCenter, + iconeffect->apply(pixmap, KIconLoader::Desktop, KIconLoader::DisabledState) + ); + } else if (d->hovered) { + style->drawItemPixmap( + painter, option->rect, Qt::AlignCenter, + iconeffect->apply(pixmap, KIconLoader::Desktop, KIconLoader::ActiveState) + ); + } else { + style->drawItemPixmap( + painter, option->rect, Qt::AlignCenter, + iconeffect->apply(pixmap, KIconLoader::Desktop, KIconLoader::DefaultState) + ); } - updateGeometry(); - if (!parentWidget() || !parentWidget()->layout()) { - resize(preferredSize()); - } -} - -QString IconWidget::text() const -{ - return d->text; -} - -void IconWidget::setInfoText(const QString &text) -{ - d->infoText = text; - // cause a relayout - d->currentSize = QSizeF(-1, -1); - //try to relayout, needed if an icon was never shown before - if (!isVisible()) { - QStyleOptionGraphicsItem styleoption; - d->layoutIcons(&styleoption); - } - updateGeometry(); - if (!parentWidget() || !parentWidget()->layout()) { - resize(preferredSize()); - } -} - -QString IconWidget::infoText() const -{ - return d->infoText; } QIcon IconWidget::icon() const @@ -1266,31 +183,9 @@ QIcon IconWidget::icon() const return d->icon; } -void IconWidget::setIcon(const QString &icon) -{ - if (icon.isEmpty()) { - setIcon(QIcon()); - return; - } - - setIcon(KIcon(icon)); -} - void IconWidget::setIcon(const QIcon &icon) { - setSvg(QString()); - - /*fade to the new icon, but to not bee a too big hog, not do that when: - - the fade animation is already running - - the icon is under mouse - - one betwen the old and new icon is null*/ - if (!(d->states & IconWidgetPrivate::HoverState) && !d->iconChangeTimer->isActive() && d->oldIcon.isNull() && !d->icon.isNull() && !icon.isNull()) { - d->oldIcon = d->icon; - d->animateMainIcon(true, d->states); - } else { - d->oldIcon = QIcon(); - } - d->iconChangeTimer->start(300); + setImage(QString(), QString()); d->icon = icon; update(); } @@ -1300,42 +195,16 @@ QSizeF IconWidget::iconSize() const return d->iconSize; } -void IconWidget::setPreferredIconSize(const QSizeF &size) +void IconWidget::setIconSize(const QSizeF &size) { - d->preferredIconSize = size; + d->iconSize = size; + setPreferredSize(size); updateGeometry(); } -QSizeF IconWidget::preferredIconSize() const +bool IconWidget::isDown() const { - return d->preferredIconSize; -} - -void IconWidget::setMinimumIconSize(const QSizeF &size) -{ - d->minimumIconSize = size; - updateGeometry(); -} - -QSizeF IconWidget::minimumIconSize() const -{ - return d->minimumIconSize; -} - -void IconWidget::setMaximumIconSize(const QSizeF &size) -{ - d->maximumIconSize = size; - updateGeometry(); -} - -QSizeF IconWidget::maximumIconSize() const -{ - return d->maximumIconSize; -} - -bool IconWidget::isDown() -{ - return d->states & IconWidgetPrivate::PressedState; + return (d->pressed || d->manualpressed); } void IconWidget::mousePressEvent(QGraphicsSceneMouseEvent *event) @@ -1344,241 +213,71 @@ void IconWidget::mousePressEvent(QGraphicsSceneMouseEvent *event) QGraphicsWidget::mousePressEvent(event); return; } - - if (KGlobalSettings::singleClick() || (receivers(SIGNAL(clicked()))) > 0) { - d->states |= IconWidgetPrivate::PressedState; - } - d->clickStartPos = scenePos(); - - bool handled = false; - foreach (IconAction *action, d->cornerActions) { - handled = action->event(event->type(), event->pos()); - if (handled) { - break; - } - } - - if (!handled && boundingRect().contains(event->pos())) { - emit pressed(true); - } - + d->pressed = true; + emit pressed(true); update(); } void IconWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if (~d->states & IconWidgetPrivate::PressedState) { - QGraphicsWidget::mouseMoveEvent(event); - return; - } - if (boundingRect().contains(event->pos())) { - if (~d->states & IconWidgetPrivate::HoverState) { - d->states |= IconWidgetPrivate::HoverState; - update(); - } + d->hovered = true; + update(); } else { - if (d->states & IconWidgetPrivate::HoverState) { - d->states &= ~IconWidgetPrivate::HoverState; - update(); - } + d->hovered = false; + d->pressed = false; + update(); } } void IconWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if (~d->states & IconWidgetPrivate::PressedState) { - QGraphicsWidget::mouseReleaseEvent(event); - return; - } - - d->states &= ~IconWidgetPrivate::PressedState; - - //don't pass click when the mouse was moved - bool handled = d->clickStartPos != scenePos(); - if (!handled) { - foreach (IconAction *action, d->cornerActions) { - if (action->event(event->type(), event->pos())) { - handled = true; - break; - } + d->pressed = false; + if (boundingRect().contains(event->pos())) { + emit clicked(); + if (KGlobalSettings::singleClick()) { + emit activated(); } } - - if (!handled) { - if (boundingRect().contains(event->pos())) { - emit clicked(); - if (KGlobalSettings::singleClick()) { - emit activated(); - } - - if (d->action && d->action->menu()) { - d->action->menu()->popup(event->screenPos()); - } - } - emit pressed(false); - } - + emit pressed(false); update(); } void IconWidget::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { - Q_UNUSED(event) - - d->states |= IconWidgetPrivate::PressedState; - + d->pressed = true; emit doubleClicked(); if (!KGlobalSettings::singleClick()) { emit activated(); } - update(); } void IconWidget::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - //kDebug(); - foreach (IconAction *action, d->cornerActions) { - action->show(); - action->event(event->type(), event->pos()); - } - - d->oldIcon = QIcon(); - d->animateMainIcon(true, d->states|IconWidgetPrivate::HoverState); - QGraphicsWidget::hoverEnterEvent(event); + d->hovered = true; + update(); } void IconWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - //kDebug() << d->cornerActions; - foreach (IconAction *action, d->cornerActions) { - action->hide(); - action->event(event->type(), event->pos()); - } - // d->states &= ~IconWidgetPrivate::HoverState; // Will be set once progress is zero again ... - //if an eventfilter stolen the mousereleaseevent remove the pressed state here - d->states &= ~IconWidgetPrivate::PressedState; - - d->animateMainIcon(false, d->states|IconWidgetPrivate::HoverState); - QGraphicsWidget::hoverLeaveEvent(event); + d->hovered = false; + update(); } -bool IconWidget::sceneEventFilter(QGraphicsItem *watched, QEvent *event) +void IconWidget::setPressed() { - Q_UNUSED(watched) - - if (event->type() == QEvent::GraphicsSceneDragEnter) { - d->animateMainIcon(true, d->states|IconWidgetPrivate::HoverState); - } else if (event->type() == QEvent::GraphicsSceneDragLeave) { - d->animateMainIcon(false, d->states|IconWidgetPrivate::HoverState); - } - - return false; -} - -void IconWidget::setPressed(bool pressed) -{ - if (pressed) { - d->states |= IconWidgetPrivate::ManualPressedState; - d->states |= IconWidgetPrivate::PressedState; - } else { - d->states &= ~IconWidgetPrivate::ManualPressedState; - d->states &= ~IconWidgetPrivate::PressedState; - } + d->pressed = true; + d->manualpressed = true; update(); } void IconWidget::setUnpressed() { - setPressed(false); -} - -void IconWidgetPrivate::svgChanged() -{ - iconSvgElementChanged = true; - q->update(); -} - -void IconWidget::setOrientation(Qt::Orientation orientation) -{ - d->orientation = orientation; - resize(sizeFromIconSize(d->iconSize.width())); -} - -Qt::Orientation IconWidget::orientation() const -{ - return d->orientation; -} - -void IconWidget::invertLayout(bool invert) -{ - d->invertLayout = invert; -} - -bool IconWidget::invertedLayout() const -{ - return d->invertLayout; -} - -QSizeF IconWidget::sizeFromIconSize(const qreal iconWidth) const -{ - d->setActiveMargins(); - if (d->text.isEmpty() && d->infoText.isEmpty()) { - //no text, just the icon size - return d->addMargin(QSizeF(iconWidth, iconWidth), IconWidgetPrivate::ItemMargin); - } - - QFontMetricsF fm(font()); - qreal width = 0; - - if (d->orientation == Qt::Vertical) { - width = qMax(d->maxWordWidth(d->text), - d->maxWordWidth(d->infoText)) + - fm.width("xxx") + - d->verticalMargin[IconWidgetPrivate::TextMargin].left + - d->verticalMargin[IconWidgetPrivate::TextMargin].right; - - width = qMax(width, - iconWidth + - d->verticalMargin[IconWidgetPrivate::IconMargin].left + - d->verticalMargin[IconWidgetPrivate::IconMargin].right); - } else { - width = iconWidth + - d->horizontalMargin[IconWidgetPrivate::IconMargin].left + - d->horizontalMargin[IconWidgetPrivate::IconMargin].right + - qMax(fm.width(d->text), fm.width(d->infoText)) + fm.width("xxx") + - d->horizontalMargin[IconWidgetPrivate::TextMargin].left + - d->horizontalMargin[IconWidgetPrivate::TextMargin].right; - } - - qreal height; - qreal textHeight; - - QStyleOptionGraphicsItem option; - option.state = QStyle::State_None; - option.rect = QRect(0, 0, width, QWIDGETSIZE_MAX); - textHeight = d->displaySizeHint(&option, width).height(); - - if (d->orientation == Qt::Vertical) { - height = iconWidth + textHeight + - d->verticalMargin[IconWidgetPrivate::TextMargin].top + - d->verticalMargin[IconWidgetPrivate::TextMargin].bottom + - d->verticalMargin[IconWidgetPrivate::IconMargin].top + - d->verticalMargin[IconWidgetPrivate::IconMargin].bottom; - } else { - //Horizontal - height = qMax(iconWidth + - d->verticalMargin[IconWidgetPrivate::IconMargin].top + - d->verticalMargin[IconWidgetPrivate::IconMargin].bottom, - textHeight + - d->verticalMargin[IconWidgetPrivate::TextMargin].top + - d->verticalMargin[IconWidgetPrivate::TextMargin].bottom); - } - - return d->addMargin(QSizeF(width, height), IconWidgetPrivate::ItemMargin); + d->manualpressed = false; + update(); } void IconWidget::changeEvent(QEvent *event) @@ -1590,4 +289,3 @@ void IconWidget::changeEvent(QEvent *event) } // namespace Plasma #include "moc_iconwidget.cpp" -#include "moc_iconwidget_p.cpp" diff --git a/plasma/widgets/iconwidget.h b/plasma/widgets/iconwidget.h index 9cf8cf0b..5fe803bf 100644 --- a/plasma/widgets/iconwidget.h +++ b/plasma/widgets/iconwidget.h @@ -1,33 +1,27 @@ /* -* Copyright (C) 2007 by Siraj Razick -* Copyright (C) 2007 by Riccardo Iaconelli -* Copyright (C) 2007 by Matt Broadstone -* Copyright 2008 by Alexis Ménard -* -* 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 Library 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. -*/ + * Copyright 2024 Ivailo Monev + * + * 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 Library 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 PLASMA_ICONWIDGET_H #define PLASMA_ICONWIDGET_H -#include -#include -#include -#include -#include +#include +#include #include #include @@ -44,8 +38,7 @@ * contain text. Currently, the IconWidget class is primarily used for desktop items, * but is designed to be used anywhere an icon is needed in an applet. * - * @author Siraj Razick - * @author Matt Broadstone + * @author Siraj Razick */ namespace Plasma { @@ -55,41 +48,16 @@ class IconWidgetPrivate; class PLASMA_EXPORT IconWidget : public QGraphicsWidget { Q_OBJECT - Q_PROPERTY(QString text READ text WRITE setText) - Q_PROPERTY(QString infoText READ infoText WRITE setInfoText) Q_PROPERTY(QIcon icon READ icon WRITE setIcon) - Q_PROPERTY(QColor textBackgroundColor READ textBackgroundColor WRITE setTextBackgroundColor) - Q_PROPERTY(QSizeF iconSize READ iconSize) - Q_PROPERTY(QString svg READ svg WRITE setSvg) - Q_PROPERTY(bool drawBackground READ drawBackground WRITE setDrawBackground) - Q_PROPERTY(QAction *action READ action WRITE setAction) - Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) - Q_PROPERTY(int numDisplayLines READ numDisplayLines WRITE setNumDisplayLines) - Q_PROPERTY(QSizeF preferredIconSize READ preferredIconSize WRITE setPreferredIconSize) - Q_PROPERTY(QSizeF minimumIconSize READ minimumIconSize WRITE setMinimumIconSize) - Q_PROPERTY(QSizeF maximumIconSize READ maximumIconSize WRITE setMaximumIconSize) + Q_PROPERTY(QSizeF iconSize READ iconSize WRITE setIconSize) + Q_PROPERTY(QString image READ image WRITE setImage) public: /** * Creates a new Plasma::IconWidget. * @param parent the QGraphicsItem this icon is parented to. */ - explicit IconWidget(QGraphicsItem *parent = 0); - - /** - * Convenience constructor to create a Plasma::IconWidget with text. - * @param text the text that will be displayed with this icon. - * @param parent the QGraphicsItem this icon is parented to. - */ - explicit IconWidget(const QString &text, QGraphicsItem *parent = 0); - - /** - * Creates a new Plasma::IconWidget with text and an icon. - * @param icon the icon that will be displayed with this icon. - * @param text the text that will be displayed with this icon. - * @param parent The QGraphicsItem this icon is parented to. - */ - IconWidget(const QIcon &icon, const QString &text, QGraphicsItem *parent = 0); + explicit IconWidget(QGraphicsItem *parent = nullptr); /** * Destroys this Plasma::IconWidget. @@ -97,39 +65,26 @@ public: virtual ~IconWidget(); /** - * Returns the text associated with this icon. - */ - QString text() const; - - /** - * Sets the text associated with this icon. - * @param text the text to associate with this icon. - */ - void setText(const QString &text); - - /** - * Convenience method to set the svg image to use when given the filepath and name of svg. - * @param svgFilePath the svg filepath including name of the svg. - * @param svgIconElement the svg element to use when displaying the svg. Defaults to all of them. - */ - void setSvg(const QString &svgFilePath, const QString &svgIconElement = QString()); - - /** - * @return the path to the svg file set, if any + * Sets the path to an image to display. + * + * @param path the path to the image; if a relative path, then a themed image will be loaded. */ - QString svg() const; + void setImage(const QString &path); /** - * Returns the meta text associated with this icon. - */ - QString infoText() const; + * Sets the path to an svg image to display and the id of the used svg element, if necessary. + * + * @param path the path to the image; if a relative path, then a themed image will be loaded. + * @param elementid the id of a svg element. + * + * @since 4.4 + */ + void setImage(const QString &path, const QString &elementid); /** - * Sets the additional information to be displayed by - * this icon. - * @param text additional meta text associated with this icon. - */ - void setInfoText(const QString &text); + * @return the image path being displayed currently, or an empty string if none. + */ + QString image() const; /** * @return the icon associated with this icon. @@ -142,26 +97,6 @@ public: */ void setIcon(const QIcon &icon); - /** - * @return the color to use behind the text of the icon - * @since 4.3 - */ - QColor textBackgroundColor() const; - - /** - * Sets the color to use behind the text of the icon - * @param color the color, or QColor() to reset it to no background color - * @since 4.3 - */ - void setTextBackgroundColor(const QColor &color); - - /** - * Convenience method to set the icon of this Plasma::IconWidget - * using a QString path to the icon. - * @param icon the path to the icon to associate with this Plasma::IconWidget. - */ - Q_INVOKABLE void setIcon(const QString &icon); - /** * @return the size of this Plasma::IconWidget's graphical icon. */ @@ -169,157 +104,22 @@ public: /** * Set the size you prefer the icon will be when positioned in a layout. - * @param preferred icon size, pass an invalid size to unset this value + * @param size icon size, pass an invalid size to unset this value * * @since 4.5 */ - void setPreferredIconSize(const QSizeF &size); + void setIconSize(const QSizeF &size); - /** - * @return The size you prefer the icon will be when positioned in a layout. - * The default is QSizeF(-1, -1); an invalid size means the icon - * will attempt to be at its default and "optimal" size - * - * @since 4.5 - */ - QSizeF preferredIconSize() const; - - /** - * Set the size that should be the minimum beyond the icon shouldn't scale when - * the icon will be when positioned in a layout. - * @param preferred icon size, pass an invalid size to unset this value - * - * @since 4.5 - */ - void setMinimumIconSize(const QSizeF &size); - - /** - * @return The size that should be the minimum beyond the icon shouldn't scale when - * the icon will be when positioned in a layout. - * The default is QSizeF(-1, -1); an invalid size means the icon - * will attempt to be at its default and "optimal" size - * - * @since 4.5 - */ - QSizeF minimumIconSize() const; - - /** - * Set the size that should be the maximum beyond the icon shouldn't scale when - * the icon will be when positioned in a layout. - * @param preferred icon size, pass an invalid size to unset this value - * - * @since 4.5 - */ - void setMaximumIconSize(const QSizeF &size); - - /** - * @return The size that should be the maximum beyond the icon shouldn't scale when - * the icon will be when positioned in a layout. - * The default is QSizeF(-1, -1); an invalid size means the icon - * will attempt to be at its default and "optimal" size - * - * @since 4.5 - */ - QSizeF maximumIconSize() const; - - /** - * Plasma::IconWidget allows the user to specify a number of actions - * (currently four) to be displayed around the widget. This method - * allows for a created QAction to be added to the Plasma::IconWidget. - * @param action the QAction to associate with this icon. - */ - void addIconAction(QAction *action); - - /** - * Removes a previously set iconAction. The action will be removed from the widget - * but will not be deleted. - * - * @param the QAction to be removed, if 0 all actions will be removed - */ - void removeIconAction(QAction *action); - - /** - * Associate an action with this IconWidget - * this makes the IconWidget follow the state of the action, using its icon, text, etc. - * when the IconWidget is clicked, it will also trigger the action. - * Unlike addIconAction, there can be only one associated action. - */ - void setAction(QAction *action); - - /** - * @return the currently associated action, if any. - */ - QAction *action() const; - - /** - * let set the orientation of the icon - * Qt::Vertical: text under the icon - * Qt::Horizontal text at a side of the icon depending - * by the direction of the language - * @param orientation the orientation we want - */ - void setOrientation(Qt::Orientation orientation); - - /** - * @return the orientation of the icon - */ - Qt::Orientation orientation() const; - - /** - * inverts the layout of the icons if the orientation is horizontal, - * normally we get icon on the left with left-to-right languages - * @param invert if we want to invert the layout of icons - */ - void invertLayout(bool invert); - - /** - * @return if the layout of the icons should appear inverted or not - */ - bool invertedLayout() const; - - /** - * @return optimal size given a size for the icon - * @param iconWidth desired width of the icon - */ - Q_INVOKABLE QSizeF sizeFromIconSize(const qreal iconWidth) const; - - /** - * @return the number of lines allowed to display - */ - int numDisplayLines() const; - - /** - * @param numLines the number of lines to show in the display. - */ - void setNumDisplayLines(int numLines); - - /** - * Sets whether or not to draw a background area for the icon - * - * @param draw true if a background should be drawn or not - */ - void setDrawBackground(bool draw); - - /** - * @return true if a background area is to be drawn for the icon - */ - bool drawBackground() const; - - /** - * reimplemented from QGraphicsItem - */ - QPainterPath shape() const; + bool isDown() const; public Q_SLOTS: /** - * Sets the appearance of the icon to pressed or restores the appearance - * to normal. This does not simulate a mouse button press. - * @param pressed whether to appear as pressed (true) or as normal (false) + * Sets the appearance of the icon to pressed. This does not simulate a mouse button press. */ - void setPressed(bool pressed = true); + void setPressed(); /** - * Shortcut for setPressed(false) + * The opposite of setPressed() */ void setUnpressed(); @@ -344,51 +144,28 @@ Q_SIGNALS: void doubleClicked(); /** - * Indicates when the icon has been activated following the single - * or doubleclick settings + * Indicates when the icon has been activated following the single or double-click settings */ void activated(); - /** - * Indicates that something about the icon may have changed (image, text, etc) - * only actually works for icons associated with an action - */ - void changed(); - protected: - bool isDown(); void mousePressEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); - void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); - - bool sceneEventFilter(QGraphicsItem *watched, QEvent *event); void changeEvent(QEvent *event); -public: - /** - * @internal - **/ - void drawActionButtonBase(QPainter *painter, const QSize &size, int element); - private: - Q_PRIVATE_SLOT(d, void syncToAction()) - Q_PRIVATE_SLOT(d, void clearAction()) Q_PRIVATE_SLOT(d, void svgChanged()) - Q_PRIVATE_SLOT(d, void actionDestroyed(QObject *obj)) - Q_PRIVATE_SLOT(d, void hoverAnimationFinished()) - Q_PRIVATE_SLOT(d, void colorConfigChanged()) Q_PRIVATE_SLOT(d, void iconConfigChanged()) Q_PRIVATE_SLOT(d, void setPalette()) IconWidgetPrivate * const d; friend class IconWidgetPrivate; - friend class PopupAppletPrivate; }; } // namespace Plasma -#endif +#endif // PLASMA_ICONWIDGET_H diff --git a/plasma/widgets/iconwidget_p.h b/plasma/widgets/iconwidget_p.h deleted file mode 100644 index 06d704b1..00000000 --- a/plasma/widgets/iconwidget_p.h +++ /dev/null @@ -1,411 +0,0 @@ -/* - * Copyright (C) 2007 by Aaron Seigo - * Copyright (C) 2007 by Matt Broadstone - * Copyright (C) 2006-2007 Fredrik Höglund - * - * 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 Library 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 PLASMA_ICONWIDGET_P_H -#define PLASMA_ICONWIDGET_P_H - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "iconwidget.h" -#include "framesvg.h" -#include "private/actionwidgetinterface_p.h" -#include "theme.h" - -#include -#include -#include -#include - -namespace Plasma -{ - -class Animation; -class IconHoverAnimation; - -class IconHoverAnimation : public QObject -{ - Q_OBJECT - Q_PROPERTY(qreal value READ value WRITE setValue) - -public: - IconHoverAnimation(QObject *parent = 0); - - qreal value() const; - - bool fadeIn() const; - void setFadeIn(bool fadeIn); - - QPropertyAnimation *animation() const; - void setAnimation(QPropertyAnimation *animation); - -protected slots: - void setValue(qreal value); - -private: - qreal m_value; - bool m_fadeIn; - QWeakPointer m_animation; -}; - -class PLASMA_EXPORT IconAction -{ -public: - IconAction(IconWidget *icon, QAction *action); - - void show(); - void hide(); - bool isVisible() const; - bool isAnimating() const; - - QAction *action() const; - - void paint(QPainter *painter) const; - bool event(QEvent::Type type, const QPointF &pos); - - void setSelected(bool selected); - bool isSelected() const; - - bool isHovered() const; - bool isPressed() const; - - void setRect(const QRectF &rect); - QRectF rect() const; - -private: - void rebuildPixmap(); - - IconWidget *m_icon; - QAction *m_action; - QPixmap m_pixmap; - QRectF m_rect; - - bool m_hovered; - bool m_pressed; - bool m_selected; - bool m_visible; - - QWeakPointer m_animation; -}; - -struct Margin -{ - qreal left, right, top, bottom; -}; - -class IconWidgetPrivate : public ActionWidgetInterface -{ -public: - enum MarginType { - ItemMargin = 0, - TextMargin, - IconMargin, - NMargins - }; - - enum IconWidgetState { - NoState = 0, - HoverState = 1, - PressedState = 2, - ManualPressedState = 4 - }; - Q_DECLARE_FLAGS(IconWidgetStates, IconWidgetState) - - IconWidgetPrivate(IconWidget *i); - ~IconWidgetPrivate(); - - void changed() - { - emit q->changed(); - } - - void drawBackground(QPainter *painter, IconWidgetState state); - void drawText(QPainter *painter); - void drawTextItems(QPainter *painter, const QStyleOptionGraphicsItem *option, - const QTextLayout &labelLayout, const QTextLayout &infoLayout) const; - - QPixmap decoration(const QStyleOptionGraphicsItem *option, bool useHoverEffect, bool usePressedEffect); - QPointF iconPosition(const QStyleOptionGraphicsItem *option, const QPixmap &pixmap) const; - - QSizeF displaySizeHint(const QStyleOptionGraphicsItem *option, const qreal width) const; - - QString elidedText(QTextLayout &layout, - const QSizeF &maxSize) const; - - QSizeF layoutText(QTextLayout &layout, - const QString &text, const QSizeF &constraints) const; - - QSizeF layoutText(QTextLayout &layout, const QString &text, - qreal maxWidth) const; - - QRectF labelRectangle(const QStyleOptionGraphicsItem *option, - const QPixmap &icon, const QString &string) const; - - void layoutTextItems(const QStyleOptionGraphicsItem *option, - const QPixmap &icon, QTextLayout *labelLayout, - QTextLayout *infoLayout, QRectF *textBoundingRect); - - int maxWordWidth(const QString text) const; - - inline void setLayoutOptions(QTextLayout &layout, - const QStyleOptionGraphicsItem *options, - const Qt::Orientation orientation) const; - - inline Qt::LayoutDirection iconDirection(const QStyleOptionGraphicsItem *option) const; - - enum { - Minibutton = 64, - MinibuttonHover = 128, - MinibuttonPressed = 256 - }; - - enum ActionPosition { - TopLeft = 0, - TopRight, - BottomLeft, - BottomRight, - LastIconPosition = BottomRight - }; - - // Margin functions - inline void setActiveMargins(); - void setVerticalMargin(MarginType type, qreal left, qreal right, qreal top, qreal bottom); - void setHorizontalMargin(MarginType type, qreal left, qreal right, qreal top, qreal bottom); - inline void setVerticalMargin(MarginType type, qreal hor, qreal ver); - inline void setHorizontalMargin(MarginType type, qreal hor, qreal ver); - inline QRectF addMargin(const QRectF &rect, MarginType type) const; - inline QRectF subtractMargin(const QRectF &rect, MarginType type) const; - inline QSizeF addMargin(const QSizeF &size, MarginType type) const; - inline QSizeF subtractMargin(const QSizeF &size, MarginType type) const; - inline QRectF actionRect(ActionPosition position) const; - - void actionDestroyed(QObject *obj); - void svgChanged(); - - void readColors(); - void colorConfigChanged(); - void iconConfigChanged(); - void hoverAnimationFinished(); - void init(); - void layoutIcons(const QStyleOptionGraphicsItem *option); - QSizeF iconSizeForWidgetSize(const QStyleOptionGraphicsItem *option, const QSizeF &widgetSize); - void animateMainIcon(bool, const IconWidgetStates state); - - QString text; - QString infoText; - Svg *iconSvg; - FrameSvg *background; - QString iconSvgElement; - QPixmap iconSvgPixmap; - QColor textColor; - QColor textBgColor; - QColor shadowColor; - IconHoverAnimation *hoverAnimation; - QSizeF iconSize; - QSizeF preferredIconSize; - QSizeF minimumIconSize; - QSizeF maximumIconSize; - QIcon icon; - QIcon oldIcon; - IconWidgetStates states; - Qt::Orientation orientation; - int numDisplayLines; - QSizeF currentSize; - QPointF clickStartPos; - QList haloRects; - QTimer *iconChangeTimer; - - QList cornerActions; - - Margin verticalMargin[NMargins]; - Margin horizontalMargin[NMargins]; - Margin *activeMargins; - - bool iconSvgElementChanged; - bool invertLayout; - bool drawBg; - bool textBgCustomized; - static const int maxDisplayLines = 5; - static const int iconActionSize = 26; - static const int iconActionMargin = 4; -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(IconWidgetPrivate::IconWidgetStates) - -// Inline methods -void IconWidgetPrivate::setLayoutOptions(QTextLayout &layout, - const QStyleOptionGraphicsItem *option, - const Qt::Orientation orientation) const -{ - QTextOption textoption; - textoption.setTextDirection(option->direction); - if (orientation == Qt::Horizontal) { - textoption.setAlignment(Qt::Alignment(Qt::AlignLeft|Qt::AlignVCenter)); - } else { - textoption.setAlignment(Qt::AlignCenter); - } - - textoption.setWrapMode(QTextOption::WordWrap); // NOTE: assumption as well - - layout.setFont(q->font()); - layout.setTextOption(textoption); -} - -Qt::LayoutDirection IconWidgetPrivate::iconDirection(const QStyleOptionGraphicsItem *option) const -{ - Qt::LayoutDirection direction; - - if (invertLayout && orientation == Qt::Horizontal) { - if (option->direction == Qt::LeftToRight) { - direction = Qt::RightToLeft; - } else { - direction = Qt::LeftToRight; - } - } else { - direction = option->direction; - } - - return direction; -} - -void IconWidgetPrivate::setActiveMargins() -{ - //sync here itemmargin with contentsrect, not overly pretty but it's where it's more reliable - qreal left, top, right, bottom; - q->getContentsMargins(&left, &top, &right, &bottom); - if (left || top || right || bottom) { - verticalMargin[ItemMargin].left = horizontalMargin[ItemMargin].left = left; - verticalMargin[ItemMargin].top = horizontalMargin[ItemMargin].top = top; - verticalMargin[ItemMargin].right = horizontalMargin[ItemMargin].right = right; - verticalMargin[ItemMargin].bottom = horizontalMargin[ItemMargin].bottom = bottom; - } - activeMargins = (orientation == Qt::Horizontal ? horizontalMargin : verticalMargin); -} - -void IconWidgetPrivate::setVerticalMargin(MarginType type, qreal left, qreal top, - qreal right, qreal bottom) -{ - verticalMargin[type].left = left; - verticalMargin[type].right = right; - verticalMargin[type].top = top; - verticalMargin[type].bottom = bottom; -} - -void IconWidgetPrivate::setHorizontalMargin(MarginType type, qreal left, qreal top, - qreal right, qreal bottom) -{ - horizontalMargin[type].left = left; - horizontalMargin[type].right = right; - horizontalMargin[type].top = top; - horizontalMargin[type].bottom = bottom; -} - -void IconWidgetPrivate::setVerticalMargin(MarginType type, qreal horizontal, qreal vertical) -{ - setVerticalMargin(type, horizontal, vertical, horizontal, vertical); -} - -void IconWidgetPrivate::setHorizontalMargin(MarginType type, qreal horizontal, qreal vertical) -{ - setHorizontalMargin(type, horizontal, vertical, horizontal, vertical); -} - -QRectF IconWidgetPrivate::addMargin(const QRectF &rect, MarginType type) const -{ - Q_ASSERT(activeMargins); - - const Margin &m = activeMargins[type]; - return rect.adjusted(-m.left, -m.top, m.right, m.bottom); -} - -QRectF IconWidgetPrivate::subtractMargin(const QRectF &rect, MarginType type) const -{ - Q_ASSERT(activeMargins); - - const Margin &m = activeMargins[type]; - return rect.adjusted(m.left, m.top, -m.right, -m.bottom); -} - -QSizeF IconWidgetPrivate::addMargin(const QSizeF &size, MarginType type) const -{ - Q_ASSERT(activeMargins); - - const Margin &m = activeMargins[type]; - return QSizeF(size.width() + m.left + m.right, size.height() + m.top + m.bottom); -} - -QSizeF IconWidgetPrivate::subtractMargin(const QSizeF &size, MarginType type) const -{ - Q_ASSERT(activeMargins); - - const Margin &m = activeMargins[type]; - return QSizeF(size.width() - m.left - m.right, size.height() - m.top - m.bottom); -} - -int IconWidgetPrivate::maxWordWidth(const QString text) const -{ - QFontMetricsF fm = Plasma::Theme::defaultTheme()->fontMetrics(); - QStringList words = text.split(' '); - - qreal maxWidth = 0; - foreach (const QString &word, words) { - maxWidth = qMax(maxWidth, fm.width(word)); - } - return maxWidth; -} - -QRectF IconWidgetPrivate::actionRect(ActionPosition position) const -{ - switch (position) { - case TopLeft: - return QRectF(iconActionMargin, - iconActionMargin, - iconActionSize, - iconActionSize); - case TopRight: - return QRectF(currentSize.width() - iconActionSize - iconActionMargin, - iconActionMargin, - iconActionSize, - iconActionSize); - case BottomLeft: - return QRectF(iconActionMargin, - currentSize.height() - iconActionSize - iconActionMargin, - iconActionSize, - iconActionSize); - //BottomRight - default: - return QRectF(currentSize.width() - iconActionSize - iconActionMargin, - currentSize.height() - iconActionSize - iconActionMargin, - iconActionSize, - iconActionSize); - } -} - -} // Namespace - -#endif - diff --git a/plasma/widgets/label.cpp b/plasma/widgets/label.cpp index da1418d8..82224c31 100644 --- a/plasma/widgets/label.cpp +++ b/plasma/widgets/label.cpp @@ -19,21 +19,10 @@ #include "label.h" -#include -#include -#include -#include -#include #include -#include - -#include -#include -#include +#include #include "private/themedwidgetinterface_p.h" -#include "svg.h" -#include "theme.h" namespace Plasma { @@ -43,70 +32,22 @@ class LabelPrivate : public ThemedWidgetInterface