[FrameSvg] Cache shadow margins and honor prefixes

This commit is contained in:
Mikel Johnson 2020-11-24 20:26:58 +03:00 committed by Marco Martin
parent 472f4212a9
commit 2f7563d6eb
3 changed files with 82 additions and 41 deletions

View File

@ -220,40 +220,27 @@ qreal FrameSvg::marginSize(const Plasma::Types::MarginEdge edge) const
qreal FrameSvg::shadowMarginSize(const Plasma::Types::MarginEdge edge) const
{
if (!d->frame) {
return .0;
}
if (d->frame->noBorderPadding) {
return .0;
}
switch (edge) {
case Plasma::Types::TopMargin: {
const QSize marginHint = this->elementSize(QStringLiteral("shadow-hint-top-margin"));
if (marginHint.isValid()) {
return marginHint.height();
} else {
return .0;
}
}
case Plasma::Types::LeftMargin: {
const QSize marginHint = this->elementSize(QStringLiteral("shadow-hint-left-margin"));
if (marginHint.isValid()) {
return marginHint.width();
} else {
return .0;
}
}
case Plasma::Types::RightMargin: {
const QSize marginHint = this->elementSize(QStringLiteral("shadow-hint-right-margin"));
if (marginHint.isValid()) {
return marginHint.width();
} else {
return .0;
}
}
//Plasma::BottomMargin
default: {
const QSize marginHint = this->elementSize(QStringLiteral("shadow-hint-bottom-margin"));
if (marginHint.isValid()) {
return marginHint.height();
} else {
return .0;
}
}
case Plasma::Types::TopMargin:
return d->frame->shadowTopMargin;
case Plasma::Types::LeftMargin:
return d->frame->shadowLeftMargin;
case Plasma::Types::RightMargin:
return d->frame->shadowRightMargin;
//Plasma::BottomMargin
default:
return d->frame->shadowBottomMargin;
}
}
@ -309,6 +296,19 @@ void FrameSvg::getFixedMargins(qreal &left, qreal &top, qreal &right, qreal &bot
bottom = d->frame->fixedBottomMargin;
}
void FrameSvg::getShadowMargins(qreal &left, qreal &top, qreal &right, qreal &bottom) const
{
if (!d->frame || d->frame->noBorderPadding) {
left = top = right = bottom = 0;
return;
}
top = d->frame->shadowTopMargin;
left = d->frame->shadowLeftMargin;
right = d->frame->shadowRightMargin;
bottom = d->frame->shadowBottomMargin;
}
QRectF FrameSvg::contentsRect() const
{
if (d->frame) {
@ -810,6 +810,12 @@ void FrameSvgPrivate::updateSizes(FrameData *frame) const
frame->topMargin = frame->topHeight = 0;
}
if (q->hasElement(frame->prefix % QLatin1String("hint-shadow-top-margin"))) {
frame->shadowTopMargin = q->elementSize(frame->prefix % QLatin1String("hint-shadow-top-margin")).height();
} else {
frame->shadowTopMargin = 0;
}
frame->fixedLeftWidth = q->elementSize(frame->prefix % QLatin1String("left")).width();
if (q->hasElement(frame->prefix % QLatin1String("hint-left-margin"))) {
@ -825,6 +831,12 @@ void FrameSvgPrivate::updateSizes(FrameData *frame) const
frame->leftMargin = frame->leftWidth = 0;
}
if (q->hasElement(frame->prefix % QLatin1String("hint-shadow-left-margin"))) {
frame->shadowLeftMargin = q->elementSize(frame->prefix % QLatin1String("hint-shadow-left-margin")).width();
} else {
frame->shadowLeftMargin = 0;
}
frame->fixedRightWidth = q->elementSize(frame->prefix % QLatin1String("right")).width();
if (q->hasElement(frame->prefix % QLatin1String("hint-right-margin"))) {
@ -840,6 +852,12 @@ void FrameSvgPrivate::updateSizes(FrameData *frame) const
frame->rightMargin = frame->rightWidth = 0;
}
if (q->hasElement(frame->prefix % QLatin1String("hint-shadow-right-margin"))) {
frame->shadowRightMargin = q->elementSize(frame->prefix % QLatin1String("hint-shadow-right-margin")).width();
} else {
frame->shadowRightMargin = 0;
}
frame->fixedBottomHeight = q->elementSize(frame->prefix % QLatin1String("bottom")).height();
if (q->hasElement(frame->prefix % QLatin1String("hint-bottom-margin"))) {
@ -855,6 +873,12 @@ void FrameSvgPrivate::updateSizes(FrameData *frame) const
frame->bottomMargin = frame->bottomHeight = 0;
}
if (q->hasElement(frame->prefix % QLatin1String("hint-shadow-bottom-margin"))) {
frame->shadowBottomMargin = q->elementSize(frame->prefix % QLatin1String("hint-shadow-bottom-margin")).height();
} else {
frame->shadowBottomMargin = 0;
}
frame->composeOverBorder = (q->hasElement(frame->prefix % QLatin1String("hint-compose-over-border")) &&
q->hasElement(QLatin1String("mask-") % frame->prefix % QLatin1String("center")));

View File

@ -151,14 +151,6 @@ public:
*/
Q_INVOKABLE qreal fixedMarginSize(const Plasma::Types::MarginEdge edge) const;
/**
* Returns the shadows margin size given the margin edge we want.
* @param edge the margin edge we want, top, bottom, left or right
* @return the margin size
* @since 5.77
*/
Q_INVOKABLE qreal shadowMarginSize(const Plasma::Types::MarginEdge edge) const;
/**
* Convenience method that extracts the size of the four margins
* in the four output parameters
@ -170,6 +162,25 @@ public:
*/
Q_INVOKABLE void getFixedMargins(qreal &left, qreal &top, qreal &right, qreal &bottom) const;
/**
* Returns the shadows margin size given the margin edge we want.
* @param edge the margin edge we want, top, bottom, left or right
* @return the margin size
* @since 5.77
*/
Q_INVOKABLE qreal shadowMarginSize(const Plasma::Types::MarginEdge edge) const;
/**
* Convenience method that extracts the size of the four shadow margins
* in the four output parameters
* @param left left margin size
* @param top top margin size
* @param right right margin size
* @param bottom bottom margin size
* @since 5.77
*/
Q_INVOKABLE void getShadowMargins(qreal &left, qreal &top, qreal &right, qreal &bottom) const;
/**
* @return the rectangle of the center element, taking the margins into account.
*/

View File

@ -104,6 +104,12 @@ public:
int fixedRightMargin;
int fixedBottomMargin;
//margins, we only have the hint for shadows
int shadowTopMargin;
int shadowLeftMargin;
int shadowRightMargin;
int shadowBottomMargin;
qreal devicePixelRatio;
//size of the svg where the size of the "center"