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 @@ -166,103 +166,77 @@ // 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); - } + QPainterPath path; + + const QRectF rect = boundingRect(); + + const QPoint pointLeftBottom(rect.x(), rect.y() + rect.height()); + const QPoint pointLeftTop(rect.x(), rect.y()); + const QPoint pointRightBottom(rect.x() + rect.width(), rect.y() + rect.height()); + const QPoint pointRightTop(rect.x() + rect.width(), rect.y()); + + const int RADIUS = 2; + + if (isBeginItem() && isEndItem()) { + path.addRoundedRect(rect, RADIUS, RADIUS, Qt::AbsoluteSize); + } else if (isBeginItem()) { + path.moveTo(pointRightTop); + path.lineTo(pointRightBottom); + path.lineTo(QPoint(pointLeftBottom.x() + RADIUS, pointLeftBottom.y())); + path.quadTo(pointLeftBottom, QPoint(pointLeftBottom.x(), pointLeftBottom.y() - RADIUS)); + path.lineTo(QPoint(pointLeftTop.x(), pointLeftTop.y() + RADIUS)); + path.quadTo(pointLeftTop, QPoint(pointLeftTop.x() + RADIUS, pointLeftTop.y())); + path.lineTo(pointRightTop); + } else if (isEndItem()) { + path.moveTo(pointLeftTop); + path.lineTo(pointLeftBottom); + path.lineTo(QPoint(pointRightBottom.x() - RADIUS, pointRightBottom.y())); + path.quadTo(pointRightBottom, QPoint(pointRightBottom.x(), pointRightBottom.y() - RADIUS)); + path.lineTo(QPoint(pointRightTop.x(), pointRightTop.y() + RADIUS)); + path.quadTo(pointRightTop, QPoint(pointRightTop.x() - RADIUS, pointRightTop.y())); + path.lineTo(pointLeftTop); } - - // close path - path.lineTo(x0 + beginRound, y0); - return path; } QRectF MonthGraphicsItem::boundingRect() const { // width - 2 because of the cell-dividing line with width == 1 at beginning and end - return QRectF(0, 0, (daySpan() + 1) * mMonthItem->monthScene()->columnWidth() - 2, + return QRectF(1, 0, (daySpan() + 1) * mMonthItem->monthScene()->columnWidth() - 2 - 2, mMonthItem->monthScene()->itemHeight()); } void MonthGraphicsItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { if (!mMonthItem->monthScene()->initialized()) { return; } + p->save(); MonthScene *scene = mMonthItem->monthScene(); p->setRenderHint(QPainter::Antialiasing); - int textMargin = 7; - + // draw background and border QColor bgColor = mMonthItem->bgColor(); - bgColor = mMonthItem->selected() - ? bgColor.lighter(EventView::BRIGHTNESS_FACTOR) : bgColor; + bgColor = mMonthItem->selected() ? bgColor.lighter(EventView::BRIGHTNESS_FACTOR) : bgColor; + QColor frameColor = mMonthItem->frameColor(); - frameColor = mMonthItem->selected() - ? frameColor.lighter(EventView::BRIGHTNESS_FACTOR) : frameColor; - QColor textColor = EventViews::getTextColor(bgColor); - + frameColor = mMonthItem->selected() ? frameColor.lighter(EventView::BRIGHTNESS_FACTOR) : frameColor; + const QPen border(frameColor, 1.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + // make moving or resizing items translucent if (mMonthItem->isMoving() || mMonthItem->isResizing()) { bgColor.setAlphaF(0.75f); } - QLinearGradient gradient(0, 0, 0, boundingRect().height()); - gradient.setColorAt(0, bgColor); - gradient.setColorAt(0.7, bgColor.darker(110)); - gradient.setColorAt(1, bgColor.darker(150)); - 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)); + p->setBrush(bgColor); + p->setPen(border); + p->drawPath(shape()); + // draw text + const QColor textColor = EventViews::getTextColor(bgColor); + int textMargin = 7; p->setPen(textColor); int alignFlag = Qt::AlignVCenter; @@ -281,9 +255,7 @@ // Every item should set its own LayoutDirection, or eliding fails miserably p->setLayoutDirection(text.isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight); - QRect textRect = QRect(textMargin, 0, - static_cast(boundingRect().width() - 2 * textMargin), - scene->itemHeight()); + QRect textRect(textMargin, 0, static_cast(boundingRect().width() - 2 * textMargin), scene->itemHeight()); if (mMonthItem->monthScene()->monthView()->preferences()->enableMonthItemIcons()) { const QVector icons = mMonthItem->icons(); @@ -328,6 +300,7 @@ text = p->fontMetrics().elidedText(text, Qt::ElideRight, textRect.width()); p->drawText(textRect, alignFlag, text); } + p->restore(); } void MonthGraphicsItem::setStartDate(const QDate &date)