Changeset View
Changeset View
Standalone View
Standalone View
src/month/monthgraphicsitems.cpp
Show First 20 Lines • Show All 124 Lines • ▼ Show 20 Line(s) | 124 | if (manager == nullptr) { | |||
---|---|---|---|---|---|
125 | return i; | 125 | return i; | ||
126 | } | 126 | } | ||
127 | i++; | 127 | i++; | ||
128 | } | 128 | } | ||
129 | } | 129 | } | ||
130 | 130 | | |||
131 | //------------------------------------------------------------- | 131 | //------------------------------------------------------------- | ||
132 | // MONTHGRAPHICSITEM | 132 | // MONTHGRAPHICSITEM | ||
133 | static const int ft = 2; // frame thickness | 133 | static const int ft = 1; // frame thickness | ||
134 | 134 | | |||
135 | MonthGraphicsItem::MonthGraphicsItem(MonthItem *manager) | 135 | MonthGraphicsItem::MonthGraphicsItem(MonthItem *manager) | ||
136 | : QGraphicsItem(nullptr) | 136 | : QGraphicsItem(nullptr) | ||
137 | , mMonthItem(manager) | 137 | , mMonthItem(manager) | ||
138 | { | 138 | { | ||
139 | manager->monthScene()->addItem(this); | 139 | manager->monthScene()->addItem(this); | ||
140 | QTransform transform; | 140 | QTransform transform; | ||
141 | transform = transform.translate(0.5, 0.5); | 141 | transform = transform.translate(0.5, 0.5); | ||
Show All 28 Lines | |||||
170 | } | 170 | } | ||
171 | 171 | | |||
172 | // TODO: remove this method. | 172 | // TODO: remove this method. | ||
173 | QPainterPath MonthGraphicsItem::widgetPath(bool border) const | 173 | QPainterPath MonthGraphicsItem::widgetPath(bool border) const | ||
174 | { | 174 | { | ||
175 | // If border is set we won't draw all the path. Items spanning on multiple | 175 | // If border is set we won't draw all the path. Items spanning on multiple | ||
176 | // rows won't have borders on their boundaries. | 176 | // rows won't have borders on their boundaries. | ||
177 | // If this is the mask, we draw it one pixel bigger | 177 | // If this is the mask, we draw it one pixel bigger | ||
178 | int x0 = 0; | 178 | const int x0 = (!border && !isBeginItem())? -1 : 0; | ||
179 | int y0 = 0; | 179 | const int y0 = 0; | ||
180 | int x1 = static_cast<int>(boundingRect().width()); | 180 | const int x1 = static_cast<int>(boundingRect().width()); | ||
181 | int y1 = static_cast<int>(boundingRect().height()); | 181 | const int y1 = static_cast<int>(boundingRect().height()); | ||
182 | 182 | | |||
183 | int height = y1 - y0; | 183 | const int beginRound = 2; | ||
184 | int beginRound = height / 3; | 184 | const int margin = 1; | ||
185 | 185 | | |||
186 | QPainterPath path(QPoint(x0 + beginRound, y0)); | 186 | QPainterPath path(QPoint(x0 + beginRound, y0)); | ||
187 | if (isBeginItem()) { | 187 | if (isBeginItem()) { | ||
188 | path.arcTo(QRect(x0, y0, beginRound * 2, height), +90, +180); | 188 | path.quadTo(QPoint(x0 + margin, y0), QPoint(x0 + margin, y0 + beginRound)); | ||
189 | path.lineTo(QPoint(x0 + margin, y1 - beginRound)); | ||||
190 | path.quadTo(QPoint(x0 + margin, y1), QPoint(x0 + beginRound + margin, y1)); | ||||
189 | } else { | 191 | } else { | ||
190 | path.lineTo(x0, y0); | 192 | path.lineTo(x0, y0); | ||
191 | if (!border) { | 193 | if (!border) { | ||
192 | path.lineTo(x0, y1); | 194 | path.lineTo(x0, y1); | ||
193 | } else { | 195 | } else { | ||
194 | path.moveTo(x0, y1); | 196 | path.moveTo(x0, y1); | ||
195 | } | 197 | } | ||
196 | path.lineTo(x0 + beginRound, y1); | 198 | path.lineTo(x0 + beginRound, y1); | ||
197 | } | 199 | } | ||
198 | 200 | | |||
199 | if (isEndItem()) { | 201 | if (isEndItem()) { | ||
200 | path.lineTo(x1 - beginRound, y1); | 202 | path.lineTo(x1 - beginRound, y1); | ||
201 | path.arcTo(QRect(x1 - 2 * beginRound, y0, beginRound * 2, height), -90, +180); | 203 | path.quadTo(QPoint(x1 - margin, y1), QPoint(x1 - margin, y1 - beginRound)); | ||
204 | path.lineTo(QPoint(x1 - margin, y0 + beginRound)); | ||||
205 | path.quadTo(QPoint(x1 - margin, y0), QPoint(x1 - margin - beginRound, y0)); | ||||
202 | } else { | 206 | } else { | ||
203 | path.lineTo(x1, y1); | 207 | path.lineTo(x1, y1); | ||
204 | if (!border) { | 208 | if (!border) { | ||
205 | path.lineTo(x1, y0); | 209 | path.lineTo(x1, y0); | ||
dvratil: Do you maybe need to draw the background one pixel wider without the border? If you zoom in on… | |||||
206 | } else { | 210 | } else { | ||
207 | path.moveTo(x1, y0); | 211 | path.moveTo(x1, y0); | ||
208 | } | 212 | } | ||
209 | } | 213 | } | ||
210 | 214 | | |||
211 | // close path | 215 | // close path | ||
212 | path.lineTo(x0 + beginRound, y0); | 216 | path.lineTo(x0 + beginRound, y0); | ||
213 | 217 | | |||
Show All 10 Lines | |||||
224 | void MonthGraphicsItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) | 228 | void MonthGraphicsItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) | ||
225 | { | 229 | { | ||
226 | if (!mMonthItem->monthScene()->initialized()) { | 230 | if (!mMonthItem->monthScene()->initialized()) { | ||
227 | return; | 231 | return; | ||
228 | } | 232 | } | ||
229 | 233 | | |||
230 | MonthScene *scene = mMonthItem->monthScene(); | 234 | MonthScene *scene = mMonthItem->monthScene(); | ||
231 | 235 | | |||
232 | p->setRenderHint(QPainter::Antialiasing); | | |||
233 | 236 | | |||
234 | int textMargin = 7; | 237 | int textMargin = 7; | ||
235 | 238 | | |||
236 | QColor bgColor = mMonthItem->bgColor(); | 239 | QColor bgColor = mMonthItem->bgColor(); | ||
237 | bgColor = mMonthItem->selected() | 240 | bgColor = mMonthItem->selected() | ||
238 | ? bgColor.lighter(EventView::BRIGHTNESS_FACTOR) : bgColor; | 241 | ? bgColor.lighter(EventView::BRIGHTNESS_FACTOR) : bgColor; | ||
239 | QColor frameColor = mMonthItem->frameColor(); | 242 | QColor frameColor = mMonthItem->frameColor(); | ||
240 | frameColor = mMonthItem->selected() | 243 | frameColor = mMonthItem->selected() | ||
241 | ? frameColor.lighter(EventView::BRIGHTNESS_FACTOR) : frameColor; | 244 | ? frameColor.lighter(EventView::BRIGHTNESS_FACTOR) : frameColor; | ||
242 | QColor textColor = EventViews::getTextColor(bgColor); | 245 | QColor textColor = EventViews::getTextColor(bgColor); | ||
243 | 246 | | |||
244 | // make moving or resizing items translucent | 247 | // make moving or resizing items translucent | ||
245 | if (mMonthItem->isMoving() || mMonthItem->isResizing()) { | 248 | if (mMonthItem->isMoving() || mMonthItem->isResizing()) { | ||
246 | bgColor.setAlphaF(0.75f); | 249 | bgColor.setAlphaF(0.75f); | ||
247 | } | 250 | } | ||
248 | 251 | | |||
249 | QLinearGradient gradient(0, 0, 0, boundingRect().height()); | 252 | // draw the widget without border | ||
250 | gradient.setColorAt(0, bgColor); | 253 | p->setRenderHint(QPainter::Antialiasing, false); | ||
251 | gradient.setColorAt(0.7, bgColor.darker(110)); | 254 | p->setBrush(bgColor); | ||
252 | gradient.setColorAt(1, bgColor.darker(150)); | | |||
253 | QBrush brush(gradient); | | |||
254 | p->setBrush(brush); | | |||
255 | p->setPen(Qt::NoPen); | 255 | p->setPen(Qt::NoPen); | ||
256 | // Rounded rect without border | | |||
257 | p->drawPath(widgetPath(false)); | 256 | p->drawPath(widgetPath(false)); | ||
258 | 257 | | |||
259 | // Draw the border without fill | 258 | p->setRenderHint(QPainter::Antialiasing, true); | ||
260 | QPen pen(frameColor); | 259 | // draw the border without fill | ||
261 | pen.setWidth(ft); | 260 | const QPen pen(frameColor, ft, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); | ||
262 | p->setPen(pen); | 261 | p->setPen(pen); | ||
263 | p->setBrush(Qt::NoBrush); | 262 | p->setBrush(Qt::NoBrush); | ||
264 | p->drawPath(widgetPath(true)); | 263 | p->drawPath(widgetPath(true)); | ||
265 | 264 | | |||
265 | // draw text | ||||
266 | p->setPen(textColor); | 266 | p->setPen(textColor); | ||
267 | 267 | | |||
dvratil: `const` | |||||
268 | int alignFlag = Qt::AlignVCenter; | 268 | int alignFlag = Qt::AlignVCenter; | ||
269 | if (isBeginItem()) { | 269 | if (isBeginItem()) { | ||
270 | alignFlag |= Qt::AlignLeft; | 270 | alignFlag |= Qt::AlignLeft; | ||
271 | } else if (isEndItem()) { | 271 | } else if (isEndItem()) { | ||
272 | alignFlag |= Qt::AlignRight; | 272 | alignFlag |= Qt::AlignRight; | ||
273 | } else { | 273 | } else { | ||
274 | alignFlag |= Qt::AlignHCenter; | 274 | alignFlag |= Qt::AlignHCenter; | ||
275 | } | 275 | } | ||
▲ Show 20 Lines • Show All 121 Lines • Show Last 20 Lines |
Do you maybe need to draw the background one pixel wider without the border? If you zoom in on the latest screenshot, the right-most pixels on 21st are white (well, light-green, but I suspect that's aliasing or something like that).