Commit e2cb35fc authored by Glen Ditchfield's avatar Glen Ditchfield 🐛 Committed by Glen Ditchfield
Browse files

Fix up the printed incidence

  * Obey the "Use colors" checkbox.
  * Fully obey the "Show note lines" checkbox.
  * Adjust the header text's color to contrast with the background color.
  * Preserve spaces at the ends of captions.
  * Use the painter's pen color, not the theme's foreground color, for
    the rich description pen color.
parent 6bdd61ae
Pipeline #66664 passed with stage
in 5 minutes and 31 seconds
......@@ -190,7 +190,7 @@ protected:
int CalPrintIncidence::printCaptionAndText(QPainter &p, QRect box, const QString &caption, const QString &text, const QFont &captionFont, const QFont &textFont)
{
QFontMetrics captionFM(captionFont);
int textWd = captionFM.boundingRect(caption).width();
int textWd = captionFM.horizontalAdvance(caption);
QRect textRect(box);
QFont oldFont(p.font());
......@@ -260,7 +260,7 @@ void CalPrintIncidence::print(QPainter &p, int width, int height)
QRect box(0, 0, width, height);
QRect titleBox(box);
titleBox.setHeight(headerHeight());
QColor headerColor = categoryBgColor(*it);
QColor headerColor = mUseColors ? categoryBgColor(*it) : QColor();
// Draw summary as header, no small calendars in title bar, expand height if needed
int titleBottom = drawHeader(p, (*it)->summary(), QDate(), QDate(), titleBox, true, headerColor);
titleBox.setBottom(titleBottom);
......@@ -455,7 +455,9 @@ void CalPrintIncidence::print(QPainter &p, int width, int height)
/*expand=*/false,
captionFont,
textFont);
drawNoteLines(p, notesBox, notesPosition);
if (mShowNoteLines) {
drawNoteLines(p, notesBox, notesPosition);
}
} else {
QString subitemCaption;
if (relations.isEmpty()) {
......
......@@ -531,7 +531,11 @@ int CalPrintPluginBase::drawBoxWithCaption(QPainter &p,
p.save();
p.translate(textBox.x() - borderWidth, textBox.y());
QRect clipBox(0, 0, box.width(), boxHeight);
rtb.drawContents(&p, clipBox);
QAbstractTextDocumentLayout::PaintContext ctx;
ctx.palette.setColor(QPalette::Text, p.pen().color());
p.setClipRect(clipBox);
ctx.clip = clipBox;
rtb.documentLayout()->draw(&p, ctx);
p.restore();
textBox.setBottom(textBox.y() + rtb.documentLayout()->documentSize().height());
}
......@@ -575,6 +579,9 @@ int CalPrintPluginBase::drawHeader(QPainter &p, const QString &title, QDate mont
drawShadedBox(p, BOX_BORDER_WIDTH, backColor, box);
const auto oldPen {p.pen()};
p.setPen(getTextColor(backColor));
// prev month left, current month centered, next month right
QRect monthbox2(box.right() - 10 - smallMonthWidth, box.top(), smallMonthWidth, box.height());
if (month2.isValid()) {
......@@ -590,6 +597,8 @@ int CalPrintPluginBase::drawHeader(QPainter &p, const QString &title, QDate mont
// Set the margins
p.setFont(newFont);
p.drawText(textRect, Qt::AlignCenter | Qt::AlignVCenter | Qt::TextWordWrap, title);
p.setPen(oldPen);
p.setFont(oldFont);
return textRect.bottom();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment