[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/kword/part
From: Inge Wallin <inge () lysator ! liu ! se>
Date: 2009-11-01 10:58:12
Message-ID: 1257073092.903567.30619.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1043344 by ingwa:
Optimize page border drawing by introducing a helper function. At the
same time fix a bug with line widths.
M +46 -136 KWCanvas.cpp
M +4 -0 KWCanvas.h
--- trunk/koffice/kword/part/KWCanvas.cpp #1043343:1043344
@@ -337,155 +337,65 @@
qreal zoomY;
viewConverter()->zoom( &zoomX, &zoomY );
- // Paint the left border.
- if (border.leftBorderStyle() != KoBorder::BorderNone) {
- painter.save();
+ KoBorder::BorderData borderSide = border.leftBorderData();
+ paintBorderSide(painter, borderSide, pen, borderRect.topLeft(), borderRect.bottomLeft(),
+ zoomX, 1, 0);
+ borderSide = border.topBorderData();
+ paintBorderSide(painter, borderSide, pen, borderRect.topLeft(), borderRect.topRight(),
+ zoomY, 0, 1);
- KoBorder::BorderData leftBorder = border.leftBorderData();
+ borderSide = border.rightBorderData();
+ paintBorderSide(painter, borderSide, pen, borderRect.topRight(), borderRect.bottomRight(),
+ zoomX, -1, 0);
- // Set up the painter and inner and outer pens.
- getPenData(leftBorder, pen);
+ borderSide = border.bottomBorderData();
+ paintBorderSide(painter, borderSide, pen, borderRect.bottomLeft(), borderRect.bottomRight(),
+ zoomY, 0, -1);
+}
- if (leftBorder.style == KoBorder::BorderDouble ) {
- // outerWidth is the width of the outer line. The offsets
- // are the distances from the center line of the whole
- // border to the centerlines of the outer and inner
- // borders respectively.
- qreal outerWidth = leftBorder.width - leftBorder.innerWidth - leftBorder.spacing;
- QPoint outerOffset(- leftBorder.width / 2.0 + outerWidth / 2.0, 0);
- QPoint innerOffset( leftBorder.width / 2.0 - leftBorder.innerWidth / 2.0, 0);
- // Draw the outer line.
- pen.setWidthF(zoomX * outerWidth);
- painter.setPen(pen);
- painter.drawLine(borderRect.topLeft() + outerOffset,
- borderRect.bottomLeft() + outerOffset);
+void KWCanvas::paintBorderSide(QPainter &painter, const KoBorder::BorderData &borderData, QPen &pen,
+ const QPointF &lineStart, const QPointF &lineEnd, qreal zoom,
+ int inwardsX, int inwardsY) const
+{
+ // Return if nothing to paint
+ if (borderData.style == KoBorder::BorderNone)
+ return;
- // Draw the inner line
- pen.setWidthF(zoomX * leftBorder.innerWidth);
- painter.setPen(pen);
- painter.drawLine(borderRect.topLeft() + innerOffset,
- borderRect.bottomLeft() + innerOffset);
- }
- else {
- pen.setWidthF(zoomX * leftBorder.width);
- painter.setPen(pen);
- painter.drawLine(borderRect.topLeft(), borderRect.bottomLeft());
- }
- }
+ painter.save();
- // Paint the top border.
- if (border.topBorderStyle() != KoBorder::BorderNone) {
- painter.save();
+ // Set up the painter and inner and outer pens.
+ getPenData(borderData, pen);
- KoBorder::BorderData topBorder = border.topBorderData();
+ if (borderData.style == KoBorder::BorderDouble ) {
+ // outerWidth is the width of the outer line. The offsets
+ // are the distances from the center line of the whole
+ // border to the centerlines of the outer and inner
+ // borders respectively.
+ qreal outerWidth = borderData.width - borderData.innerWidth - borderData.spacing;
+ qreal outerOffset = borderData.width / 2.0 + outerWidth / 2.0;
+ qreal innerOffset = borderData.width / 2.0 - borderData.innerWidth / 2.0;
- // Set up the painter and inner and outer pens.
- getPenData(topBorder, pen);
+ QPointF outerOffset2D(-inwardsX * outerOffset, -inwardsY * outerOffset);
+ QPointF innerOffset2D( inwardsX * innerOffset, inwardsY * innerOffset );
- if (topBorder.style == KoBorder::BorderDouble ) {
- // outerWidth is the width of the outer line. The offsets
- // are the distances from the center line of the whole
- // border to the centerlines of the outer and inner
- // borders respectively.
- qreal outerWidth = topBorder.width - topBorder.innerWidth - topBorder.spacing;
- QPoint outerOffset(0, - topBorder.width / 2.0 + outerWidth / 2.0);
- QPoint innerOffset(0, topBorder.width / 2.0 - topBorder.innerWidth / 2.0);
+ // Draw the outer line.
+ pen.setWidthF(zoom * outerWidth);
+ painter.setPen(pen);
+ painter.drawLine(lineStart + outerOffset2D, lineEnd + outerOffset2D);
- // Draw the outer line.
- pen.setWidthF(zoomX * outerWidth);
- painter.setPen(pen);
- painter.drawLine(borderRect.topLeft() + outerOffset,
- borderRect.topRight() + outerOffset);
-
- // Draw the inner line
- pen.setWidthF(zoomX * topBorder.innerWidth);
- painter.setPen(pen);
- painter.drawLine(borderRect.topLeft() + innerOffset,
- borderRect.topRight() + innerOffset);
- }
- else {
- pen.setWidthF(zoomX * topBorder.width);
- painter.setPen(pen);
- painter.drawLine(borderRect.topLeft(), borderRect.topRight());
- }
+ // Draw the inner line
+ pen.setWidthF(zoom * borderData.innerWidth);
+ painter.setPen(pen);
+ painter.drawLine(lineStart + innerOffset2D, lineEnd + innerOffset2D);
}
-
- // Paint the right border.
- if (border.rightBorderStyle() != KoBorder::BorderNone) {
- painter.save();
-
- KoBorder::BorderData rightBorder = border.rightBorderData();
-
- // Set up the painter and inner and outer pens.
- getPenData(rightBorder, pen);
-
- if (rightBorder.style == KoBorder::BorderDouble ) {
- // outerWidth is the width of the outer line. The offsets
- // are the distances from the center line of the whole
- // border to the centerlines of the outer and inner
- // borders respectively.
- qreal outerWidth = rightBorder.width - rightBorder.innerWidth - rightBorder.spacing;
- QPoint outerOffset( rightBorder.width / 2.0 + outerWidth / 2.0, 0);
- QPoint innerOffset(- rightBorder.width / 2.0 - rightBorder.innerWidth / 2.0, 0);
-
- // Draw the outer line.
- pen.setWidthF(zoomX * outerWidth);
- painter.setPen(pen);
- painter.drawLine(borderRect.topRight() + outerOffset,
- borderRect.bottomRight() + outerOffset);
-
- // Draw the inner line
- pen.setWidthF(zoomX * rightBorder.innerWidth);
- painter.setPen(pen);
- painter.drawLine(borderRect.topRight() + innerOffset,
- borderRect.bottomRight() + innerOffset);
- }
- else {
- pen.setWidthF(zoomX * rightBorder.width);
- painter.setPen(pen);
- painter.drawLine(borderRect.topRight(), borderRect.bottomRight());
- }
+ else {
+ pen.setWidthF(zoom * borderData.width);
+ painter.setPen(pen);
+ painter.drawLine(lineStart, lineEnd);
}
- // Paint the bottom border.
- if (border.bottomBorderStyle() != KoBorder::BorderNone) {
- painter.save();
-
- KoBorder::BorderData bottomBorder = border.bottomBorderData();
-
- // Set up the painter and inner and outer pens.
- getPenData(bottomBorder, pen);
-
- if (bottomBorder.style == KoBorder::BorderDouble ) {
- // outerWidth is the width of the outer line. The offsets
- // are the distances from the center line of the whole
- // border to the centerlines of the outer and inner
- // borders respectively.
- qreal outerWidth = bottomBorder.width - bottomBorder.innerWidth - bottomBorder.spacing;
- QPoint outerOffset(0, bottomBorder.width / 2.0 + outerWidth / 2.0);
- QPoint innerOffset(0, - bottomBorder.width / 2.0 - bottomBorder.innerWidth / 2.0);
-
- // Draw the outer line.
- pen.setWidthF(zoomX * outerWidth);
- painter.setPen(pen);
- painter.drawLine(borderRect.bottomLeft() + outerOffset,
- borderRect.bottomRight() + outerOffset);
-
- // Draw the inner line
- pen.setWidthF(zoomX * bottomBorder.innerWidth);
- painter.setPen(pen);
- painter.drawLine(borderRect.bottomLeft() + innerOffset,
- borderRect.bottomRight() + innerOffset);
- }
- else {
- pen.setWidthF(zoomX * bottomBorder.width);
- painter.setPen(pen);
- painter.drawLine(borderRect.bottomLeft(), borderRect.bottomRight());
- }
-
- painter.restore();
- }
+ painter.restore();
}
void KWCanvas::getPenData(const KoBorder::BorderData &borderData, QPen &pen) const
--- trunk/koffice/kword/part/KWCanvas.h #1043343:1043344
@@ -160,6 +160,10 @@
private:
void paintPageDecorations(QPainter &painter, KWViewMode::ViewMap &viewMap);
void paintBorder(QPainter &painter, const KoBorder &border, const QRectF &borderRect) const;
+ void paintBorderSide(QPainter &painter, const KoBorder::BorderData &borderData, QPen &pen,
+ const QPointF &lineStart, const QPointF &lineEnd, qreal zoom,
+ int inwardsX, int inwardsY) const;
+
void getPenData(const KoBorder::BorderData &borderData, QPen &pen) const;
KWDocument *m_document;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic