cleanups
Move variable declarations closer to its uses Prefer using QSize than width and height separately, so we can pass it around directly and use isEmpty Remove duplicated code in the central piece drawing
This commit is contained in:
parent
ae56796cb9
commit
33aa8e406d
@ -795,8 +795,6 @@ void FrameSvgPrivate::generateFrameBackground(FrameData *frame)
|
|||||||
{
|
{
|
||||||
//qDebug() << "generating background";
|
//qDebug() << "generating background";
|
||||||
const QSize size = frameSize(frame).toSize();
|
const QSize size = frameSize(frame).toSize();
|
||||||
const int topOffset = 0;
|
|
||||||
const int leftOffset = 0;
|
|
||||||
|
|
||||||
if (!size.isValid()) {
|
if (!size.isValid()) {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
@ -809,12 +807,7 @@ void FrameSvgPrivate::generateFrameBackground(FrameData *frame)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int contentWidth = size.width() - frame->leftWidth - frame->rightWidth;
|
const QSize contentSize(size.width() - frame->leftWidth - frame->rightWidth, size.height() - frame->topHeight - frame->bottomHeight);
|
||||||
const int contentHeight = size.height() - frame->topHeight - frame->bottomHeight;
|
|
||||||
int contentTop = 0;
|
|
||||||
int contentLeft = 0;
|
|
||||||
int rightOffset = contentWidth;
|
|
||||||
int bottomOffset = contentHeight;
|
|
||||||
|
|
||||||
frame->cachedBackground = QPixmap(size);
|
frame->cachedBackground = QPixmap(size);
|
||||||
frame->cachedBackground.fill(Qt::transparent);
|
frame->cachedBackground.fill(Qt::transparent);
|
||||||
@ -823,34 +816,29 @@ void FrameSvgPrivate::generateFrameBackground(FrameData *frame)
|
|||||||
p.setRenderHint(QPainter::SmoothPixmapTransform);
|
p.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||||
|
|
||||||
//CENTER
|
//CENTER
|
||||||
|
if (!contentSize.isEmpty()) {
|
||||||
|
const QString centerElementId = prefix % "center";
|
||||||
if (frame->tileCenter) {
|
if (frame->tileCenter) {
|
||||||
if (contentHeight > 0 && contentWidth > 0) {
|
QSize centerTileSize = q->elementSize(centerElementId);
|
||||||
QSize centerTileSize = q->elementSize(prefix % "center");
|
|
||||||
QPixmap center(centerTileSize);
|
QPixmap center(centerTileSize);
|
||||||
center.fill(Qt::transparent);
|
center.fill(Qt::transparent);
|
||||||
|
|
||||||
{
|
|
||||||
QPainter centerPainter(¢er);
|
QPainter centerPainter(¢er);
|
||||||
centerPainter.setCompositionMode(QPainter::CompositionMode_Source);
|
centerPainter.setCompositionMode(QPainter::CompositionMode_Source);
|
||||||
q->paint(¢erPainter, QRect(QPoint(0, 0), centerTileSize), prefix % "center");
|
q->paint(¢erPainter, QRect(QPoint(0, 0), centerTileSize),centerElementId);
|
||||||
}
|
|
||||||
|
|
||||||
if (frame->composeOverBorder) {
|
if (frame->composeOverBorder) {
|
||||||
p.drawTiledPixmap(QRect(QPoint(0, 0), size), center);
|
p.drawTiledPixmap(QRect(QPoint(0, 0), size), center);
|
||||||
} else {
|
} else {
|
||||||
p.drawTiledPixmap(QRect(frame->leftWidth, frame->topHeight,
|
p.drawTiledPixmap(QRect(QPoint(frame->leftWidth, frame->topHeight), contentSize), center);
|
||||||
contentWidth, contentHeight), center);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (contentHeight > 0 && contentWidth > 0) {
|
|
||||||
if (frame->composeOverBorder) {
|
if (frame->composeOverBorder) {
|
||||||
q->paint(&p, QRect(QPoint(0, 0), size),
|
q->paint(&p, QRect(QPoint(0, 0), size),
|
||||||
prefix % "center");
|
centerElementId);
|
||||||
} else {
|
} else {
|
||||||
q->paint(&p, QRect(frame->leftWidth, frame->topHeight,
|
q->paint(&p, QRect(QPoint(frame->leftWidth, frame->topHeight), contentSize),
|
||||||
contentWidth, contentHeight),
|
centerElementId);
|
||||||
prefix % "center");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -861,6 +849,10 @@ void FrameSvgPrivate::generateFrameBackground(FrameData *frame)
|
|||||||
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int contentTop = 0;
|
||||||
|
int contentLeft = 0;
|
||||||
|
int rightOffset = contentSize.width();
|
||||||
|
int bottomOffset = contentSize.height();
|
||||||
if (frame->enabledBorders & FrameSvg::LeftBorder && q->hasElement(prefix % "left")) {
|
if (frame->enabledBorders & FrameSvg::LeftBorder && q->hasElement(prefix % "left")) {
|
||||||
rightOffset += frame->leftWidth;
|
rightOffset += frame->leftWidth;
|
||||||
}
|
}
|
||||||
@ -875,6 +867,8 @@ void FrameSvgPrivate::generateFrameBackground(FrameData *frame)
|
|||||||
contentLeft = frame->leftWidth;
|
contentLeft = frame->leftWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int topOffset = 0;
|
||||||
|
const int leftOffset = 0;
|
||||||
paintCorner(p, frame, FrameSvg::LeftBorder|FrameSvg::TopBorder, QRect(leftOffset, topOffset, frame->leftWidth, frame->topHeight));
|
paintCorner(p, frame, FrameSvg::LeftBorder|FrameSvg::TopBorder, QRect(leftOffset, topOffset, frame->leftWidth, frame->topHeight));
|
||||||
paintCorner(p, frame, FrameSvg::RightBorder|FrameSvg::TopBorder, QRect(rightOffset, topOffset, frame->rightWidth, frame->topHeight));
|
paintCorner(p, frame, FrameSvg::RightBorder|FrameSvg::TopBorder, QRect(rightOffset, topOffset, frame->rightWidth, frame->topHeight));
|
||||||
paintCorner(p, frame, FrameSvg::LeftBorder|FrameSvg::BottomBorder, QRect(leftOffset, bottomOffset, frame->leftWidth, frame->bottomHeight));
|
paintCorner(p, frame, FrameSvg::LeftBorder|FrameSvg::BottomBorder, QRect(leftOffset, bottomOffset, frame->leftWidth, frame->bottomHeight));
|
||||||
@ -882,12 +876,12 @@ void FrameSvgPrivate::generateFrameBackground(FrameData *frame)
|
|||||||
|
|
||||||
// Sides
|
// Sides
|
||||||
const int leftHeight = q->elementSize(prefix % "left").height();
|
const int leftHeight = q->elementSize(prefix % "left").height();
|
||||||
paintBorder(p, frame, FrameSvg::LeftBorder, QSize(frame->leftWidth, leftHeight), QRect(leftOffset, contentTop, frame->leftWidth, contentHeight));
|
paintBorder(p, frame, FrameSvg::LeftBorder, QSize(frame->leftWidth, leftHeight), QRect(leftOffset, contentTop, frame->leftWidth, contentSize.height()));
|
||||||
paintBorder(p, frame, FrameSvg::RightBorder, QSize(frame->rightWidth, leftHeight), QRect(rightOffset, contentTop, frame->rightWidth, contentHeight));
|
paintBorder(p, frame, FrameSvg::RightBorder, QSize(frame->rightWidth, leftHeight), QRect(rightOffset, contentTop, frame->rightWidth, contentSize.height()));
|
||||||
|
|
||||||
const int topWidth = q->elementSize(prefix % "top").width();
|
const int topWidth = q->elementSize(prefix % "top").width();
|
||||||
paintBorder(p, frame, FrameSvg::TopBorder, QSize(topWidth, frame->topHeight), QRect(contentLeft, topOffset, contentWidth, frame->topHeight));
|
paintBorder(p, frame, FrameSvg::TopBorder, QSize(topWidth, frame->topHeight), QRect(contentLeft, topOffset, contentSize.width(), frame->topHeight));
|
||||||
paintBorder(p, frame, FrameSvg::BottomBorder, QSize(topWidth, frame->bottomHeight), QRect(contentLeft, bottomOffset, contentWidth, frame->bottomHeight));
|
paintBorder(p, frame, FrameSvg::BottomBorder, QSize(topWidth, frame->bottomHeight), QRect(contentLeft, bottomOffset, contentSize.width(), frame->bottomHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameSvgPrivate::paintBorder(QPainter& p, FrameData* frame, const FrameSvg::EnabledBorders borders, const QSize& size, const QRect& output) const
|
void FrameSvgPrivate::paintBorder(QPainter& p, FrameData* frame, const FrameSvg::EnabledBorders borders, const QSize& size, const QRect& output) const
|
||||||
|
Loading…
Reference in New Issue
Block a user