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)
|
IconWidgetPrivate::IconWidgetPrivate(IconWidget *i)
|
||||||
: q(i),
|
: q(i),
|
||||||
iconSvg(0),
|
iconSvg(0),
|
||||||
iconSvgElementChanged(false),
|
|
||||||
fadeIn(false),
|
|
||||||
hoverAnimId(-1),
|
hoverAnimId(-1),
|
||||||
hoverAlpha(20 / 255),
|
hoverAlpha(20 / 255),
|
||||||
iconSize(48, 48),
|
iconSize(48, 48),
|
||||||
states(IconWidgetPrivate::NoState),
|
states(IconWidgetPrivate::NoState),
|
||||||
orientation(Qt::Vertical),
|
orientation(Qt::Vertical),
|
||||||
numDisplayLines(2),
|
numDisplayLines(2),
|
||||||
|
action(0),
|
||||||
|
activeMargins(0),
|
||||||
|
iconSvgElementChanged(false),
|
||||||
|
fadeIn(false),
|
||||||
invertLayout(false),
|
invertLayout(false),
|
||||||
drawBg(false),
|
drawBg(false),
|
||||||
action(0),
|
textBgCustomized(false)
|
||||||
activeMargins(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,11 +86,16 @@ IconWidgetPrivate::~IconWidgetPrivate()
|
|||||||
void IconWidgetPrivate::readColors()
|
void IconWidgetPrivate::readColors()
|
||||||
{
|
{
|
||||||
textColor = Plasma::Theme::defaultTheme()->color(Theme::TextColor);
|
textColor = Plasma::Theme::defaultTheme()->color(Theme::TextColor);
|
||||||
|
|
||||||
if (qGray(textColor.rgb()) > 192) {
|
if (qGray(textColor.rgb()) > 192) {
|
||||||
shadowColor = Qt::black;
|
shadowColor = Qt::black;
|
||||||
} else {
|
} else {
|
||||||
shadowColor = Qt::white;
|
shadowColor = Qt::white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!textBgCustomized) {
|
||||||
|
textBgColor = Theme::defaultTheme()->color(Theme::HighlightColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IconWidgetPrivate::colorConfigChanged()
|
void IconWidgetPrivate::colorConfigChanged()
|
||||||
@ -976,11 +982,35 @@ void IconWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
|
|||||||
shadowOffset = QPoint(0, 1);
|
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);
|
PaintUtils::shadowBlur(shadow, 2, d->shadowColor);
|
||||||
painter->drawImage(textBoundingRect.topLeft() + shadowOffset, shadow);
|
painter->drawImage(textBoundingRect.topLeft() + shadowOffset, shadow);
|
||||||
d->drawTextItems(painter, option, labelLayout, infoLayout);
|
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)
|
void IconWidget::drawActionButtonBase(QPainter *painter, const QSize &size, int element)
|
||||||
{
|
{
|
||||||
qreal radius = size.width() / 2;
|
qreal radius = size.width() / 2;
|
||||||
@ -1188,10 +1218,12 @@ void IconWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|||||||
|
|
||||||
bool IconWidget::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
bool IconWidget::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::GraphicsSceneDragEnter){
|
Q_UNUSED(watched)
|
||||||
|
|
||||||
|
if (event->type() == QEvent::GraphicsSceneDragEnter) {
|
||||||
d->hoverEffect(true);
|
d->hoverEffect(true);
|
||||||
update();
|
update();
|
||||||
}else if (event->type() == QEvent::GraphicsSceneDragLeave){
|
} else if (event->type() == QEvent::GraphicsSceneDragLeave) {
|
||||||
d->hoverEffect(false);
|
d->hoverEffect(false);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ class PLASMA_EXPORT IconWidget : public QGraphicsWidget
|
|||||||
Q_PROPERTY(QString text READ text WRITE setText)
|
Q_PROPERTY(QString text READ text WRITE setText)
|
||||||
Q_PROPERTY(QString infoText READ infoText WRITE setInfoText)
|
Q_PROPERTY(QString infoText READ infoText WRITE setInfoText)
|
||||||
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
|
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
|
||||||
|
Q_PROPERTY(QColor textBackgroundColor READ textBackgroundColor WRITE setTextBackgroundColor)
|
||||||
Q_PROPERTY(QSizeF iconSize READ iconSize)
|
Q_PROPERTY(QSizeF iconSize READ iconSize)
|
||||||
Q_PROPERTY(QString svg WRITE setSvg)
|
Q_PROPERTY(QString svg WRITE setSvg)
|
||||||
Q_PROPERTY(QAction *action READ action WRITE setAction)
|
Q_PROPERTY(QAction *action READ action WRITE setAction)
|
||||||
@ -131,6 +132,19 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setIcon(const QIcon &icon);
|
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
|
* Convenience method to set the icon of this Plasma::IconWidget
|
||||||
* using a QString path to the icon.
|
* using a QString path to the icon.
|
||||||
|
@ -194,11 +194,10 @@ public:
|
|||||||
Svg *iconSvg;
|
Svg *iconSvg;
|
||||||
FrameSvg *background;
|
FrameSvg *background;
|
||||||
QString iconSvgElement;
|
QString iconSvgElement;
|
||||||
bool iconSvgElementChanged;
|
|
||||||
QPixmap iconSvgPixmap;
|
QPixmap iconSvgPixmap;
|
||||||
QColor textColor;
|
QColor textColor;
|
||||||
|
QColor textBgColor;
|
||||||
QColor shadowColor;
|
QColor shadowColor;
|
||||||
bool fadeIn;
|
|
||||||
int hoverAnimId;
|
int hoverAnimId;
|
||||||
qreal hoverAlpha;
|
qreal hoverAlpha;
|
||||||
QSizeF iconSize;
|
QSizeF iconSize;
|
||||||
@ -206,8 +205,6 @@ public:
|
|||||||
IconWidgetStates states;
|
IconWidgetStates states;
|
||||||
Qt::Orientation orientation;
|
Qt::Orientation orientation;
|
||||||
int numDisplayLines;
|
int numDisplayLines;
|
||||||
bool invertLayout;
|
|
||||||
bool drawBg;
|
|
||||||
QSizeF currentSize;
|
QSizeF currentSize;
|
||||||
QPointF clickStartPos;
|
QPointF clickStartPos;
|
||||||
|
|
||||||
@ -218,6 +215,11 @@ public:
|
|||||||
Margin horizontalMargin[NMargins];
|
Margin horizontalMargin[NMargins];
|
||||||
Margin *activeMargins;
|
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 maxDisplayLines = 5;
|
||||||
static const int iconActionSize = 26;
|
static const int iconActionSize = 26;
|
||||||
static const int iconActionMargin = 4;
|
static const int iconActionMargin = 4;
|
||||||
|
Loading…
Reference in New Issue
Block a user