diff --git a/src/agenda/agendaitem.h b/src/agenda/agendaitem.h --- a/src/agenda/agendaitem.h +++ b/src/agenda/agendaitem.h @@ -287,9 +287,9 @@ // paint all visible icons void paintIcons(QPainter *p, int &x, int y, int ft); - void drawRoundedRect(QPainter *p, const QRect &rect, - bool selected, const QColor &bgcolor, - bool frame, int ft, bool roundTop, bool roundBottom); + void drawEventRect(QPainter *p, const QRect &rect, + bool selected, const QColor &bgcolor, + bool frame, int ft); int mCellXLeft, mCellXRight; int mCellYTop, mCellYBottom; diff --git a/src/agenda/agendaitem.cpp b/src/agenda/agendaitem.cpp --- a/src/agenda/agendaitem.cpp +++ b/src/agenda/agendaitem.cpp @@ -810,7 +810,7 @@ QPainter p(this); p.setRenderHint(QPainter::Antialiasing); const int fmargin = 0; // frame margin - const int ft = 1; // frame thickness for layout, see drawRoundedRect(), + const int ft = 1; // frame thickness for layout, see drawEventRect(), // keep multiple of 2 const int margin = 5 + ft + fmargin; // frame + space between frame and content @@ -910,11 +910,8 @@ const int singleLineHeight = fm.boundingRect(mLabelText).height(); - const bool roundTop = !prevMultiItem(); - const bool roundBottom = !nextMultiItem(); - - drawRoundedRect(&p, QRect(fmargin, fmargin, width() - fmargin * 2, height() - fmargin * 2), - mSelected, bgColor, true, ft, roundTop, roundBottom); + drawEventRect(&p, QRect(fmargin, fmargin, width() - fmargin * 2, height() - fmargin * 2), + mSelected, bgColor, true, ft); // calculate the height of the full version (case 4) to test whether it is // possible @@ -1030,27 +1027,27 @@ longH = shortH; // paint headline - drawRoundedRect( + drawEventRect( &p, QRect(fmargin, fmargin, width() - fmargin * 2, - fmargin * 2 + margin + hlHeight), - mSelected, frameColor, false, ft, roundTop, false); + mSelected, frameColor, false, ft); } else { // single-day, all-day event // paint headline - drawRoundedRect( + drawEventRect( &p, QRect(fmargin, fmargin, width() - fmargin * 2, - fmargin * 2 + margin + hlHeight), - mSelected, frameColor, false, ft, roundTop, false); + mSelected, frameColor, false, ft); } } else { // to-do // paint headline - drawRoundedRect( + drawEventRect( &p, QRect(fmargin, fmargin, width() - fmargin * 2, - fmargin * 2 + margin + hlHeight), - mSelected, frameColor, false, ft, roundTop, false); + mSelected, frameColor, false, ft); } x += visRect.left(); @@ -1060,10 +1057,10 @@ hTxtWidth = visRect.right() - margin - x; } else { // paint headline - drawRoundedRect( + drawEventRect( &p, QRect(fmargin, fmargin, width() - fmargin * 2, - fmargin * 2 + margin + hlHeight), - mSelected, frameColor, false, ft, roundTop, false); + mSelected, frameColor, false, ft); txtWidth = width() - margin - x; eventX = x; @@ -1104,10 +1101,9 @@ } -void AgendaItem::drawRoundedRect(QPainter *p, const QRect &rect, +void AgendaItem::drawEventRect(QPainter *p, const QRect &rect, bool selected, const QColor &bgColor, - bool frame, int ft, bool roundTop, - bool roundBottom) + bool frame, int ft) { Q_UNUSED(ft); if (!mValid) { @@ -1124,33 +1120,20 @@ bool shrinkWidth = r.width() < 16; bool shrinkHeight = r.height() < 16; - qreal rnd = 2.1; + qreal horizontalPad = 2.1; int sw = shrinkWidth ? 10 : 11; int sh = shrinkHeight ? 10 : 11; - QRectF tr(r.x() + r.width() - sw - rnd, r.y() + rnd, sw, sh); - QRectF tl(r.x() + rnd, r.y() + rnd, sw, sh); - QRectF bl(r.x() + rnd, r.y() + r.height() - sh - 1 - rnd, sw, sh); - QRectF br(r.x() + r.width() - sw - rnd, r.y() + r.height() - sh - 1 - rnd, sw, sh); - - if (roundTop) { - path.moveTo(tr.topRight()); - path.arcTo(tr, 0.0, 90.0); - path.lineTo(tl.topRight()); - path.arcTo(tl, 90.0, 90.0); - } else { - path.moveTo(tr.topRight()); - path.lineTo(tl.topLeft()); - } + QRectF tr(r.x() + r.width() - sw - horizontalPad, r.y(), sw, sh); + QRectF tl(r.x() + horizontalPad, r.y(), sw, sh); + QRectF bl(r.x() + horizontalPad, r.y() + r.height() - sh - 1, sw, sh); + QRectF br(r.x() + r.width() - sw - horizontalPad, r.y() + r.height() - sh - 1, sw, sh); + + path.moveTo(tr.topRight()); + path.lineTo(tl.topLeft()); + + path.lineTo(bl.bottomLeft()); + path.lineTo(br.bottomRight()); - if (roundBottom) { - path.lineTo(bl.topLeft()); - path.arcTo(bl, 180.0, 90.0); - path.lineTo(br.bottomLeft()); - path.arcTo(br, 270.0, 90.0); - } else { - path.lineTo(bl.bottomLeft()); - path.lineTo(br.bottomRight()); - } path.closeSubpath(); // header @@ -1175,15 +1158,6 @@ p->setPen(Qt::NoPen); p->drawPath(path); - QPixmap separator; - QString key(QStringLiteral("ko_hsep")); - if (!QPixmapCache::find(key, separator)) { - separator = QPixmap(QStringLiteral(":/headerSeparator.png")); - QPixmapCache::insert(key, separator); - } - p->fillRect(QRect(r.x() + 3, r.y() + r.height() - 2, r.x() + r.width() - 4, 2), - QBrush(separator)); - p->restore(); return; } @@ -1225,99 +1199,6 @@ p->setRenderHint(QPainter::Antialiasing, false); - if (r.width() - 16 > 0) { - QPixmap topLines; - QString key(QStringLiteral("ko_t")); - if (!QPixmapCache::find(key, topLines)) { - topLines = QPixmap(QStringLiteral(":/topLines.png")); - QPixmapCache::insert(key, topLines); - } - p->setBrushOrigin(r.x() + 8, r.y()); - p->fillRect(QRect(r.x() + 8, r.y(), r.width() - 16, 5), - QBrush(topLines)); - - QPixmap bottomLines; - key = QStringLiteral("ko_b"); - if (!QPixmapCache::find(key, bottomLines)) { - bottomLines = QPixmap(QStringLiteral(":/bottomLines.png")); - QPixmapCache::insert(key, bottomLines); - } - p->setBrushOrigin(r.x() + 8, r.y() + r.height() - 6); - p->fillRect(QRect(r.x() + 8, r.y() + r.height() - 6, r.width() - 16, 6), - QBrush(bottomLines)); - - } - - if (r.height() - 16 > 0) { - - QPixmap leftLines; - QString key(QStringLiteral("ko_l")); - if (!QPixmapCache::find(key, leftLines)) { - leftLines = QPixmap(QStringLiteral(":/leftLines.png")); - QPixmapCache::insert(key, leftLines); - } - p->setBrushOrigin(r.x(), r.y() + 8); - p->fillRect(QRect(r.x(), r.y() + 8, 5, r.height() - 16), - QBrush(leftLines)); - - QPixmap rightLines; - key = QStringLiteral("ko_r"); - if (!QPixmapCache::find(key, rightLines)) { - rightLines = QPixmap(QStringLiteral(":/rightLines.png")); - QPixmapCache::insert(key, rightLines); - } - p->setBrushOrigin(r.x() + r.width() - 5, r.y() + 8); - p->fillRect(QRect(r.x() + r.width() - 5, r.y() + 8, 5, r.height() - 16), - QBrush(rightLines)); - } - - // don't overlap the edges - int lw = shrinkWidth ? r.width() / 2 : 8; - int rw = shrinkWidth ? r.width() - lw : 8; - int th = shrinkHeight ? r.height() / 2 : 8; - int bh = shrinkHeight ? r.height() - th : 8; - - // keep the bottom round for items which ending at 00:15 - if (shrinkHeight && !roundTop && roundBottom && r.height() > 3) { - bh += th - 3; - th = 3; - } - - QPixmap topLeft; - QString key = roundTop ? QStringLiteral("ko_tl") : QStringLiteral("ko_rtl"); - if (!QPixmapCache::find(key, topLeft)) { - topLeft = roundTop ? QPixmap(QStringLiteral(":/roundTopLeft.png")) : QPixmap(QStringLiteral(":/rectangularTopLeft.png")); - QPixmapCache::insert(key, topLeft); - } - p->drawPixmap(r.x(), r.y(), topLeft, 0, 0, lw, th); - - QPixmap topRight; - key = roundTop ? QStringLiteral("ko_tr") : QStringLiteral("ko_rtr"); - if (!QPixmapCache::find(key, topRight)) { - topRight = roundTop ? QPixmap(QStringLiteral(":/roundTopRight.png")) : QPixmap(QStringLiteral(":/rectangularTopRight.png")); - QPixmapCache::insert(key, topRight); - } - p->drawPixmap(r.x() + r.width() - rw, r.y(), topRight, 8 - rw, 0, rw, th); - - QPixmap bottomLeft; - key = roundBottom ? QStringLiteral("ko_bl") : QStringLiteral("ko_rbl"); - if (!QPixmapCache::find(key, bottomLeft)) { - bottomLeft = roundBottom ? QPixmap(QStringLiteral(":/roundBottomLeft.png")) : - QPixmap(QStringLiteral(":/rectangularBottomLeft.png")); - QPixmapCache::insert(key, bottomLeft); - } - p->drawPixmap(r.x(), r.y() + r.height() - bh, bottomLeft, 0, 8 - bh, lw, bh); - - QPixmap bottomRight; - key = roundBottom ? QStringLiteral("ko_br") : QStringLiteral("ko_rbr"); - if (!QPixmapCache::find(key, bottomRight)) { - bottomRight = roundBottom ? QPixmap(QStringLiteral(":/roundBottomRight.png")) : - QPixmap(QStringLiteral(":/rectangularBottomRight.png")); - QPixmapCache::insert(key, bottomRight); - } - p->drawPixmap(r.x() + r.width() - rw, r.y() + r.height() - bh, bottomRight, - 8 - rw, 8 - bh, rw, 8); - p->restore(); } diff --git a/src/month/monthgraphicsitems.h b/src/month/monthgraphicsitems.h --- a/src/month/monthgraphicsitems.h +++ b/src/month/monthgraphicsitems.h @@ -206,9 +206,6 @@ QString getToolTip() const; private: - // Shape of the item, see shape() - QPainterPath widgetPath(bool border) const; - // See startDate() QDate mStartDate; diff --git a/src/month/monthgraphicsitems.cpp b/src/month/monthgraphicsitems.cpp --- a/src/month/monthgraphicsitems.cpp +++ b/src/month/monthgraphicsitems.cpp @@ -165,51 +165,9 @@ // The returned shape must be a closed path, // otherwise MonthScene:itemAt(pos) can have // problems detecting the item - return widgetPath(false); -} - -// TODO: remove this method. -QPainterPath MonthGraphicsItem::widgetPath(bool border) const -{ - // If border is set we won't draw all the path. Items spanning on multiple - // rows won't have borders on their boundaries. - // If this is the mask, we draw it one pixel bigger - int x0 = 0; - int y0 = 0; - int x1 = static_cast(boundingRect().width()); - int y1 = static_cast(boundingRect().height()); - - int height = y1 - y0; - int beginRound = height / 3; - - QPainterPath path(QPoint(x0 + beginRound, y0)); - if (isBeginItem()) { - path.arcTo(QRect(x0, y0, beginRound * 2, height), +90, +180); - } else { - path.lineTo(x0, y0); - if (!border) { - path.lineTo(x0, y1); - } else { - path.moveTo(x0, y1); - } - path.lineTo(x0 + beginRound, y1); - } - - if (isEndItem()) { - path.lineTo(x1 - beginRound, y1); - path.arcTo(QRect(x1 - 2 * beginRound, y0, beginRound * 2, height), -90, +180); - } else { - path.lineTo(x1, y1); - if (!border) { - path.lineTo(x1, y0); - } else { - path.moveTo(x1, y0); - } - } - - // close path - path.lineTo(x0 + beginRound, y0); + QPainterPath path; + path.addRect(boundingRect()); return path; } @@ -252,16 +210,10 @@ QBrush brush(gradient); p->setBrush(brush); p->setPen(Qt::NoPen); - // Rounded rect without border - p->drawPath(widgetPath(false)); - - // Draw the border without fill - QPen pen(frameColor); - pen.setWidth(ft); - p->setPen(pen); - p->setBrush(Qt::NoBrush); - p->drawPath(widgetPath(true)); + // Create event box + p->drawRect(boundingRect()); + p->setPen(textColor); int alignFlag = Qt::AlignVCenter;