allow a color lozenge behind the text to make it work on any sort of background
svn path=/trunk/KDE/kdelibs/; revision=952083
This commit is contained in:
parent
7e5f781abd
commit
4c009d93d4
@ -62,18 +62,19 @@ namespace Plasma
|
||||
IconWidgetPrivate::IconWidgetPrivate(IconWidget *i)
|
||||
: q(i),
|
||||
iconSvg(0),
|
||||
iconSvgElementChanged(false),
|
||||
fadeIn(false),
|
||||
hoverAnimId(-1),
|
||||
hoverAlpha(20 / 255),
|
||||
iconSize(48, 48),
|
||||
states(IconWidgetPrivate::NoState),
|
||||
orientation(Qt::Vertical),
|
||||
numDisplayLines(2),
|
||||
action(0),
|
||||
activeMargins(0),
|
||||
iconSvgElementChanged(false),
|
||||
fadeIn(false),
|
||||
invertLayout(false),
|
||||
drawBg(false),
|
||||
action(0),
|
||||
activeMargins(0)
|
||||
textBgCustomized(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -85,11 +86,16 @@ IconWidgetPrivate::~IconWidgetPrivate()
|
||||
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 = Theme::defaultTheme()->color(Theme::HighlightColor);
|
||||
}
|
||||
}
|
||||
|
||||
void IconWidgetPrivate::colorConfigChanged()
|
||||
@ -976,11 +982,35 @@ void IconWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
|
||||
shadowOffset = QPoint(0, 1);
|
||||
}
|
||||
|
||||
|
||||
if (state == IconWidgetPrivate::NoState && d->textBgColor != QColor() &&
|
||||
!(d->text.isEmpty() && d->infoText.isEmpty())) {
|
||||
QRectF rect = textBoundingRect.adjusted(-2, -2, 4, 4);
|
||||
painter->setPen(Qt::transparent);
|
||||
QColor color = d->textBgColor;
|
||||
color.setAlpha(60 * 1.0 - d->hoverAlpha);
|
||||
painter->setBrush(color);
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
painter->drawPath(PaintUtils::roundedRectangle(rect, 4));
|
||||
}
|
||||
|
||||
PaintUtils::shadowBlur(shadow, 2, d->shadowColor);
|
||||
painter->drawImage(textBoundingRect.topLeft() + shadowOffset, shadow);
|
||||
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;
|
||||
@ -1188,6 +1218,8 @@ void IconWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
|
||||
bool IconWidget::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
||||
{
|
||||
Q_UNUSED(watched)
|
||||
|
||||
if (event->type() == QEvent::GraphicsSceneDragEnter) {
|
||||
d->hoverEffect(true);
|
||||
update();
|
||||
|
@ -57,6 +57,7 @@ class PLASMA_EXPORT IconWidget : public QGraphicsWidget
|
||||
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 WRITE setSvg)
|
||||
Q_PROPERTY(QAction *action READ action WRITE setAction)
|
||||
@ -131,6 +132,19 @@ 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.
|
||||
|
@ -194,11 +194,10 @@ public:
|
||||
Svg *iconSvg;
|
||||
FrameSvg *background;
|
||||
QString iconSvgElement;
|
||||
bool iconSvgElementChanged;
|
||||
QPixmap iconSvgPixmap;
|
||||
QColor textColor;
|
||||
QColor textBgColor;
|
||||
QColor shadowColor;
|
||||
bool fadeIn;
|
||||
int hoverAnimId;
|
||||
qreal hoverAlpha;
|
||||
QSizeF iconSize;
|
||||
@ -206,8 +205,6 @@ public:
|
||||
IconWidgetStates states;
|
||||
Qt::Orientation orientation;
|
||||
int numDisplayLines;
|
||||
bool invertLayout;
|
||||
bool drawBg;
|
||||
QSizeF currentSize;
|
||||
QPointF clickStartPos;
|
||||
|
||||
@ -218,6 +215,11 @@ public:
|
||||
Margin horizontalMargin[NMargins];
|
||||
Margin *activeMargins;
|
||||
|
||||
bool iconSvgElementChanged : 1;
|
||||
bool fadeIn : 1;
|
||||
bool invertLayout : 1;
|
||||
bool drawBg : 1;
|
||||
bool textBgCustomized : 1;
|
||||
static const int maxDisplayLines = 5;
|
||||
static const int iconActionSize = 26;
|
||||
static const int iconActionMargin = 4;
|
||||
|
Loading…
Reference in New Issue
Block a user