Changeset View
Changeset View
Standalone View
Standalone View
src/month/monthgraphicsitems.cpp
Show First 20 Lines • Show All 159 Lines • ▼ Show 20 Line(s) | 159 | { | |||
---|---|---|---|---|---|
160 | return startDate() == mMonthItem->startDate(); | 160 | return startDate() == mMonthItem->startDate(); | ||
161 | } | 161 | } | ||
162 | 162 | | |||
163 | QPainterPath MonthGraphicsItem::shape() const | 163 | QPainterPath MonthGraphicsItem::shape() const | ||
164 | { | 164 | { | ||
165 | // The returned shape must be a closed path, | 165 | // The returned shape must be a closed path, | ||
166 | // otherwise MonthScene:itemAt(pos) can have | 166 | // otherwise MonthScene:itemAt(pos) can have | ||
167 | // problems detecting the item | 167 | // problems detecting the item | ||
168 | return widgetPath(false); | | |||
169 | } | | |||
170 | | ||||
171 | // TODO: remove this method. | | |||
172 | QPainterPath MonthGraphicsItem::widgetPath(bool border) const | | |||
173 | { | | |||
174 | // If border is set we won't draw all the path. Items spanning on multiple | | |||
175 | // rows won't have borders on their boundaries. | | |||
176 | // If this is the mask, we draw it one pixel bigger | | |||
177 | int x0 = 0; | | |||
178 | int y0 = 0; | | |||
179 | int x1 = static_cast<int>(boundingRect().width()); | | |||
180 | int y1 = static_cast<int>(boundingRect().height()); | | |||
181 | | ||||
182 | int height = y1 - y0; | | |||
183 | int beginRound = height / 3; | | |||
184 | | ||||
185 | QPainterPath path(QPoint(x0 + beginRound, y0)); | | |||
186 | if (isBeginItem()) { | | |||
187 | path.arcTo(QRect(x0, y0, beginRound * 2, height), +90, +180); | | |||
188 | } else { | | |||
189 | path.lineTo(x0, y0); | | |||
190 | if (!border) { | | |||
191 | path.lineTo(x0, y1); | | |||
192 | } else { | | |||
193 | path.moveTo(x0, y1); | | |||
194 | } | | |||
195 | path.lineTo(x0 + beginRound, y1); | | |||
196 | } | | |||
197 | | ||||
198 | if (isEndItem()) { | | |||
199 | path.lineTo(x1 - beginRound, y1); | | |||
200 | path.arcTo(QRect(x1 - 2 * beginRound, y0, beginRound * 2, height), -90, +180); | | |||
201 | } else { | | |||
202 | path.lineTo(x1, y1); | | |||
203 | if (!border) { | | |||
204 | path.lineTo(x1, y0); | | |||
205 | } else { | | |||
206 | path.moveTo(x1, y0); | | |||
207 | } | | |||
208 | } | | |||
209 | | ||||
210 | // close path | | |||
211 | path.lineTo(x0 + beginRound, y0); | | |||
212 | 168 | | |||
169 | QPainterPath path; | ||||
170 | path.addRect(boundingRect()); | ||||
213 | return path; | 171 | return path; | ||
214 | } | 172 | } | ||
215 | 173 | | |||
216 | QRectF MonthGraphicsItem::boundingRect() const | 174 | QRectF MonthGraphicsItem::boundingRect() const | ||
217 | { | 175 | { | ||
218 | // width - 2 because of the cell-dividing line with width == 1 at beginning and end | 176 | // width - 2 because of the cell-dividing line with width == 1 at beginning and end | ||
219 | return QRectF(0, 0, (daySpan() + 1) * mMonthItem->monthScene()->columnWidth() - 2, | 177 | return QRectF(0, 0, (daySpan() + 1) * mMonthItem->monthScene()->columnWidth() - 2, | ||
220 | mMonthItem->monthScene()->itemHeight()); | 178 | mMonthItem->monthScene()->itemHeight()); | ||
Show All 26 Lines | 182 | { | |||
247 | 205 | | |||
248 | QLinearGradient gradient(0, 0, 0, boundingRect().height()); | 206 | QLinearGradient gradient(0, 0, 0, boundingRect().height()); | ||
249 | gradient.setColorAt(0, bgColor); | 207 | gradient.setColorAt(0, bgColor); | ||
250 | gradient.setColorAt(0.7, bgColor.dark(110)); | 208 | gradient.setColorAt(0.7, bgColor.dark(110)); | ||
251 | gradient.setColorAt(1, bgColor.dark(150)); | 209 | gradient.setColorAt(1, bgColor.dark(150)); | ||
252 | QBrush brush(gradient); | 210 | QBrush brush(gradient); | ||
253 | p->setBrush(brush); | 211 | p->setBrush(brush); | ||
254 | p->setPen(Qt::NoPen); | 212 | p->setPen(Qt::NoPen); | ||
255 | // Rounded rect without border | | |||
256 | p->drawPath(widgetPath(false)); | | |||
257 | 213 | | |||
258 | // Draw the border without fill | 214 | // Create event box | ||
259 | QPen pen(frameColor); | 215 | p->drawRect(boundingRect()); | ||
260 | pen.setWidth(ft); | | |||
261 | p->setPen(pen); | | |||
262 | p->setBrush(Qt::NoBrush); | | |||
263 | p->drawPath(widgetPath(true)); | | |||
264 | 216 | | |||
265 | p->setPen(textColor); | 217 | p->setPen(textColor); | ||
266 | 218 | | |||
267 | int alignFlag = Qt::AlignVCenter; | 219 | int alignFlag = Qt::AlignVCenter; | ||
268 | if (isBeginItem()) { | 220 | if (isBeginItem()) { | ||
269 | alignFlag |= Qt::AlignLeft; | 221 | alignFlag |= Qt::AlignLeft; | ||
270 | } else if (isEndItem()) { | 222 | } else if (isEndItem()) { | ||
271 | alignFlag |= Qt::AlignRight; | 223 | alignFlag |= Qt::AlignRight; | ||
▲ Show 20 Lines • Show All 126 Lines • Show Last 20 Lines |