use svg again to draw the toolbox background
svn path=/trunk/KDE/kdelibs/; revision=917956
This commit is contained in:
parent
6547a25fa5
commit
83bfa46f88
@ -174,14 +174,13 @@ DesktopToolBox::DesktopToolBox(Containment *parent)
|
||||
{
|
||||
d->containment = parent;
|
||||
setZValue(10000000);
|
||||
setFlag(ItemClipsToShape, true);
|
||||
setFlag(ItemClipsChildrenToShape, false);
|
||||
setFlag(ItemIgnoresTransformations, true);
|
||||
setIsMovable(true);
|
||||
assignColors();
|
||||
|
||||
d->background = new Plasma::FrameSvg();
|
||||
d->background->setImagePath("widgets/translucentbackground");
|
||||
d->background->setImagePath("widgets/toolbox");
|
||||
|
||||
connect(Plasma::Animator::self(), SIGNAL(movementFinished(QGraphicsItem*)),
|
||||
this, SLOT(toolMoved(QGraphicsItem*)));
|
||||
@ -223,50 +222,53 @@ void DesktopToolBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
|
||||
QPainterPath p = shape();
|
||||
|
||||
QPoint iconPos;
|
||||
QPointF gradientCenter;
|
||||
QRect backgroundRect;
|
||||
const QRectF rect = boundingRect();
|
||||
const QSize icons = iconSize();
|
||||
bool atCorner;
|
||||
QString cornerElement;
|
||||
|
||||
switch (corner()) {
|
||||
case TopRight:
|
||||
iconPos = QPoint((int)rect.right() - icons.width() + 2, 2);
|
||||
gradientCenter = rect.topRight();
|
||||
cornerElement = "desktop-northeast";
|
||||
backgroundRect = d->background->elementRect(cornerElement).toRect();
|
||||
backgroundRect.moveTopRight(rect.topRight().toPoint());
|
||||
atCorner = true;
|
||||
break;
|
||||
case Top:
|
||||
iconPos = QPoint(rect.center().x() - icons.width() / 2, 2);
|
||||
gradientCenter = QPoint(rect.center().x(), rect.y());
|
||||
atCorner = false;
|
||||
d->background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::LeftBorder|FrameSvg::RightBorder);
|
||||
break;
|
||||
case TopLeft:
|
||||
iconPos = QPoint(2, 2);
|
||||
gradientCenter = rect.topLeft();
|
||||
cornerElement = "desktop-northwest";
|
||||
backgroundRect = d->background->elementRect(cornerElement).toRect();
|
||||
backgroundRect.moveTopLeft(rect.topLeft().toPoint());
|
||||
atCorner = true;
|
||||
break;
|
||||
case Left:
|
||||
iconPos = QPoint(2, rect.center().y() - icons.height() / 2);
|
||||
gradientCenter = QPointF(rect.left(), rect.center().y());
|
||||
atCorner = false;
|
||||
d->background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::TopBorder|FrameSvg::RightBorder);
|
||||
break;
|
||||
case Right:
|
||||
iconPos = QPoint((int)rect.right() - icons.width() + 2,
|
||||
rect.center().y() - icons.height() / 2);
|
||||
gradientCenter = QPointF(rect.right(), rect.center().y());
|
||||
atCorner = false;
|
||||
d->background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::TopBorder|FrameSvg::LeftBorder);
|
||||
break;
|
||||
case BottomLeft:
|
||||
iconPos = QPoint(2, rect.bottom() - icons.height() - 2);
|
||||
gradientCenter = rect.bottomLeft();
|
||||
cornerElement = "desktop-southwest";
|
||||
backgroundRect = d->background->elementRect(cornerElement).toRect();
|
||||
backgroundRect.moveBottomLeft(rect.bottomLeft().toPoint());
|
||||
atCorner = true;
|
||||
break;
|
||||
case Bottom:
|
||||
iconPos = QPoint(rect.center().x() - icons.width() / 2,
|
||||
rect.bottom() - icons.height() - 2);
|
||||
gradientCenter = QPointF(rect.center().x(), rect.bottom());
|
||||
atCorner = false;
|
||||
d->background->setEnabledBorders(FrameSvg::TopBorder|FrameSvg::LeftBorder|FrameSvg::RightBorder);
|
||||
break;
|
||||
@ -274,27 +276,15 @@ void DesktopToolBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
|
||||
default:
|
||||
iconPos = QPoint((int)rect.right() - icons.width() + 2,
|
||||
(int)rect.bottom() - icons.height() - 2);
|
||||
gradientCenter = rect.bottomRight();
|
||||
cornerElement = "desktop-southeast";
|
||||
backgroundRect = d->background->elementRect(cornerElement).toRect();
|
||||
backgroundRect.moveBottomRight(rect.bottomRight().toPoint());
|
||||
atCorner = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (atCorner) {
|
||||
d->bgColor.setAlpha(64);
|
||||
d->fgColor.setAlpha(64);
|
||||
QRadialGradient gradient(gradientCenter, size() + d->animCircleFrame);
|
||||
gradient.setFocalPoint(gradientCenter);
|
||||
gradient.setColorAt(0, d->bgColor);
|
||||
gradient.setColorAt(.87, d->bgColor);
|
||||
gradient.setColorAt(.97, d->fgColor);
|
||||
d->fgColor.setAlpha(0);
|
||||
gradient.setColorAt(1, d->fgColor);
|
||||
painter->save();
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
painter->setBrush(gradient);
|
||||
painter->drawPath(p);
|
||||
painter->restore();
|
||||
d->background->paint(painter, backgroundRect, cornerElement);
|
||||
} else {
|
||||
d->background->resizeFrame(rect.size());
|
||||
d->background->paintFrame(painter);
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <plasma/applet.h>
|
||||
#include <plasma/paintutils.h>
|
||||
#include <plasma/theme.h>
|
||||
#include <plasma/svg.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
@ -53,6 +54,7 @@ public:
|
||||
bool toggled;
|
||||
QColor fgColor;
|
||||
QColor bgColor;
|
||||
Plasma::Svg *background;
|
||||
};
|
||||
|
||||
PanelToolBox::PanelToolBox(Containment *parent)
|
||||
@ -62,7 +64,6 @@ PanelToolBox::PanelToolBox(Containment *parent)
|
||||
connect(this, SIGNAL(toggled()), this, SLOT(toggle()));
|
||||
|
||||
setZValue(10000000);
|
||||
setFlag(ItemClipsToShape, true);
|
||||
setFlag(ItemClipsChildrenToShape, false);
|
||||
//panel toolbox is allowed to zoom, otherwise a part of it will be displayed behind the desktop
|
||||
//toolbox when the desktop is zoomed out
|
||||
@ -70,6 +71,10 @@ PanelToolBox::PanelToolBox(Containment *parent)
|
||||
assignColors();
|
||||
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
|
||||
this, SLOT(assignColors()));
|
||||
|
||||
d->background = new Plasma::Svg();
|
||||
d->background->setImagePath("widgets/toolbox");
|
||||
d->background->setContainsMultipleImages(true);
|
||||
}
|
||||
|
||||
PanelToolBox::~PanelToolBox()
|
||||
@ -118,33 +123,34 @@ void PanelToolBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
|
||||
const qreal progress = d->animFrame / size();
|
||||
|
||||
QRect backgroundRect;
|
||||
QPoint gradientCenter;
|
||||
QRectF rect = boundingRect();
|
||||
QString cornerElement;
|
||||
|
||||
if (corner() == ToolBox::Bottom) {
|
||||
gradientCenter = QPoint(rect.center().x(), rect.bottom());
|
||||
cornerElement = "panel-south";
|
||||
|
||||
backgroundRect = d->background->elementRect(cornerElement).toRect();
|
||||
backgroundRect.moveBottomLeft(shape().boundingRect().bottomLeft().toPoint());
|
||||
} else if (corner() == ToolBox::Right) {
|
||||
gradientCenter = QPoint(rect.right(), rect.center().y());
|
||||
cornerElement = "panel-east";
|
||||
|
||||
backgroundRect = d->background->elementRect(cornerElement).toRect();
|
||||
backgroundRect.moveTopRight(shape().boundingRect().topRight().toPoint());
|
||||
} else {
|
||||
gradientCenter = QPoint(rect.right(), rect.center().y());
|
||||
cornerElement = "panel-west";
|
||||
|
||||
backgroundRect = d->background->elementRect(cornerElement).toRect();
|
||||
backgroundRect.moveTopLeft(shape().boundingRect().topLeft().toPoint());
|
||||
}
|
||||
|
||||
{
|
||||
QRadialGradient gradient(gradientCenter, size() - 2);
|
||||
gradient.setFocalPoint(gradientCenter);
|
||||
d->bgColor.setAlpha(64);
|
||||
d->fgColor.setAlpha(64);
|
||||
gradient.setColorAt(0, d->bgColor);
|
||||
gradient.setColorAt(.85, d->bgColor);
|
||||
gradient.setColorAt(.95, d->fgColor);
|
||||
d->fgColor.setAlpha(0);
|
||||
gradient.setColorAt(1, d->fgColor);
|
||||
|
||||
painter->save();
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
painter->setBrush(gradient);
|
||||
QPainterPath p = shape();
|
||||
painter->drawPath(p);
|
||||
painter->restore();
|
||||
}
|
||||
d->background->paint(painter, backgroundRect, cornerElement);
|
||||
|
||||
|
||||
QRect iconRect;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user