Changeset View
Changeset View
Standalone View
Standalone View
src/agenda/agendaitem.cpp
Show First 20 Lines • Show All 1131 Lines • ▼ Show 20 Line(s) | |||||
1132 | 1132 | | |||
1133 | void AgendaItem::drawRoundedRect(QPainter *p, const QRect &rect, bool selected, const QColor &bgColor, bool frame, int ft, bool roundTop, bool roundBottom) | 1133 | void AgendaItem::drawRoundedRect(QPainter *p, const QRect &rect, bool selected, const QColor &bgColor, bool frame, int ft, bool roundTop, bool roundBottom) | ||
1134 | { | 1134 | { | ||
1135 | Q_UNUSED(ft); | 1135 | Q_UNUSED(ft); | ||
1136 | if (!mValid) { | 1136 | if (!mValid) { | ||
1137 | return; | 1137 | return; | ||
1138 | } | 1138 | } | ||
1139 | 1139 | | |||
1140 | QRect r = rect; | | |||
1141 | r.adjust(0, 0, 1, 1); | | |||
1142 | | ||||
1143 | p->save(); | | |||
1144 | | ||||
1145 | QPainterPath path; | 1140 | QPainterPath path; | ||
1146 | 1141 | | |||
1147 | bool shrinkWidth = r.width() < 16; | 1142 | const int RECT_MARGIN = 2; | ||
1148 | bool shrinkHeight = r.height() < 16; | 1143 | const int RADIUS = 2; // absolute radius | ||
1149 | 1144 | | |||
1150 | qreal rnd = 2.1; | 1145 | const QRect rectWithMargin(rect.x() + RECT_MARGIN, rect.y() + RECT_MARGIN, rect.width() - 2 * RECT_MARGIN, rect.height() - 2 * RECT_MARGIN); | ||
1151 | int sw = shrinkWidth ? 10 : 11; | | |||
1152 | int sh = shrinkHeight ? 10 : 11; | | |||
1153 | QRectF tr(r.x() + r.width() - sw - rnd, r.y() + rnd, sw, sh); | | |||
1154 | QRectF tl(r.x() + rnd, r.y() + rnd, sw, sh); | | |||
1155 | QRectF bl(r.x() + rnd, r.y() + r.height() - sh - 1 - rnd, sw, sh); | | |||
1156 | QRectF br(r.x() + r.width() - sw - rnd, r.y() + r.height() - sh - 1 - rnd, sw, sh); | | |||
1157 | | ||||
1158 | if (roundTop) { | | |||
1159 | path.moveTo(tr.topRight()); | | |||
1160 | path.arcTo(tr, 0.0, 90.0); | | |||
1161 | path.lineTo(tl.topRight()); | | |||
1162 | path.arcTo(tl, 90.0, 90.0); | | |||
1163 | } else { | | |||
1164 | path.moveTo(tr.topRight()); | | |||
1165 | path.lineTo(tl.topLeft()); | | |||
1166 | } | | |||
1167 | 1146 | | |||
1168 | if (roundBottom) { | 1147 | const QPoint pointLeftTop(rectWithMargin.x(), rectWithMargin.y()); | ||
1169 | path.lineTo(bl.topLeft()); | 1148 | const QPoint pointRightTop(rectWithMargin.x() + rectWithMargin.width(), rectWithMargin.y()); | ||
1170 | path.arcTo(bl, 180.0, 90.0); | 1149 | const QPoint pointLeftBottom(rectWithMargin.x(), rectWithMargin.y() + rectWithMargin.height()); | ||
1171 | path.lineTo(br.bottomLeft()); | 1150 | const QPoint pointRightBottom(rectWithMargin.x() + rectWithMargin.width(), rectWithMargin.y() + rectWithMargin.height()); | ||
1172 | path.arcTo(br, 270.0, 90.0); | 1151 | | ||
1173 | } else { | 1152 | if (!roundTop && !roundBottom) { | ||
1174 | path.lineTo(bl.bottomLeft()); | 1153 | path.addRect(rectWithMargin); | ||
1175 | path.lineTo(br.bottomRight()); | 1154 | } else if (roundTop && roundBottom) { | ||
1155 | path.addRoundedRect(rectWithMargin, RADIUS, RADIUS, Qt::AbsoluteSize); | ||||
1156 | } else if (roundTop) { | ||||
1157 | path.moveTo(pointRightBottom); | ||||
1158 | path.lineTo(pointLeftBottom); | ||||
1159 | path.lineTo(QPoint(pointLeftTop.x(), pointLeftTop.y() + RADIUS)); | ||||
1160 | path.quadTo(pointLeftTop, QPoint(pointLeftTop.x() + RADIUS, pointLeftTop.y())); | ||||
1161 | path.lineTo(QPoint(pointRightTop.x() - RADIUS, pointRightTop.y())); | ||||
1162 | path.quadTo(pointRightTop, QPoint(pointRightTop.x(), pointRightTop.y() + RADIUS)); | ||||
1163 | path.lineTo(pointRightBottom); | ||||
1164 | } else if (roundBottom) { | ||||
1165 | path.moveTo(pointRightTop); | ||||
1166 | path.lineTo(QPoint(pointRightBottom.x(), pointRightBottom.y() - RADIUS)); | ||||
1167 | path.quadTo(pointRightBottom, QPoint(pointRightBottom.x() - RADIUS, pointRightBottom.y())); | ||||
1168 | path.lineTo(QPoint(pointLeftBottom.x() + RADIUS, pointLeftBottom.y())); | ||||
1169 | path.quadTo(pointLeftBottom, QPoint(pointLeftBottom.x(), pointLeftBottom.y() - RADIUS)); | ||||
1170 | path.lineTo(pointLeftTop); | ||||
1171 | path.lineTo(pointRightTop); | ||||
1176 | } | 1172 | } | ||
1173 | | ||||
1177 | path.closeSubpath(); | 1174 | path.closeSubpath(); | ||
1175 | p->save(); | ||||
dvratil: Could you try how it looks with `RADIUS = 2`? That might make it look close to what Breeze… | |||||
1176 | p->setRenderHint(QPainter::Antialiasing, false); | ||||
1177 | const QPen border(QBrush(QColor(200, 200, 200, 255)),1.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); | ||||
1178 | p->setPen(border); | ||||
1178 | 1179 | | |||
mlaurent: const each time that it's a constant variable please | |||||
1179 | // header | 1180 | // header | ||
1180 | if (!frame) { | 1181 | if (!frame) { | ||
1181 | QLinearGradient gradient(QPointF(r.x(), r.y()), QPointF(r.x(), r.height())); | 1182 | QBrush brushSolid(Qt::SolidPattern); | ||
mlaurent: QBrush brushSolid(Qt::SolidPattern); | |||||
1182 | 1183 | | |||
1183 | if (selected) { | 1184 | if (selected) { | ||
1184 | QColor top = bgColor.darker(250); | 1185 | QColor top = bgColor.darker(250); | ||
1185 | top.setAlpha(40); | 1186 | top.setAlpha(20); | ||
1186 | gradient.setColorAt(0, top); | 1187 | brushSolid.setColor(top); | ||
1187 | gradient.setColorAt(1, QColor(255, 255, 255, 30)); | | |||
1188 | } else { | 1188 | } else { | ||
1189 | gradient.setColorAt(0, QColor(255, 255, 255, 90)); | 1189 | brushSolid.setColor(QColor(255, 255, 255, 10)); | ||
1190 | gradient.setColorAt(1, QColor(0, 0, 0, 10)); | | |||
1191 | } | 1190 | } | ||
1192 | 1191 | | |||
1193 | p->setBrush(bgColor); | 1192 | p->setBrush(bgColor); | ||
1194 | p->setPen(Qt::NoPen); | | |||
1195 | p->drawPath(path); | 1193 | p->drawPath(path); | ||
1196 | 1194 | | |||
1197 | p->setBrush(gradient); | 1195 | p->setBrush(brushSolid); | ||
1198 | p->setPen(Qt::NoPen); | | |||
1199 | p->drawPath(path); | 1196 | p->drawPath(path); | ||
1200 | | ||||
1201 | QPixmap separator; | | |||
1202 | QString key(QStringLiteral("ko_hsep")); | | |||
1203 | if (!QPixmapCache::find(key, separator)) { | | |||
1204 | separator = QPixmap(QStringLiteral(":/headerSeparator.png")); | | |||
1205 | QPixmapCache::insert(key, separator); | | |||
1206 | } | | |||
1207 | p->fillRect(QRect(r.x() + 3, r.y() + r.height() - 2, r.x() + r.width() - 4, 2), | | |||
1208 | QBrush(separator)); | | |||
1209 | | ||||
1210 | p->restore(); | 1197 | p->restore(); | ||
I believe you should get here if an event in agenda spans multiple days: then the top is rounded only on the first day and the bottom is rounded only on the end day. dvratil: I believe you should get here if an event in agenda spans multiple days: then the top is… | |||||
ognarb: Thanks I, found a bug | |||||
1211 | return; | | |||
1212 | } | | |||
1213 | 1198 | | |||
1214 | QLinearGradient gradient(QPointF(r.x(), r.y()), QPointF(r.x(), r.height())); | 1199 | return; | ||
1215 | | ||||
1216 | if (r.height() > 50) { | | |||
1217 | if (mIncidence->allDay() | | |||
1218 | && mIncidence->dtStart() == mIncidence->dateTime(KCalCore::Incidence::RoleEnd) | | |||
1219 | && CalendarSupport::hasEvent(mIncidence)) { | | |||
1220 | gradient.setColorAt(0, bgColor.lighter(130)); | | |||
1221 | qreal t = 1.0 - (r.height() - 18.0) / r.height(); | | |||
1222 | gradient.setColorAt(t, bgColor.lighter(115)); | | |||
1223 | qreal b = (r.height() - 20.0) / r.height(); | | |||
1224 | gradient.setColorAt(b, bgColor); | | |||
1225 | } else { | | |||
1226 | gradient.setColorAt(0, bgColor.lighter(115)); | | |||
1227 | qreal b = (r.height() - 20.0) / r.height(); | | |||
1228 | gradient.setColorAt(b, bgColor); | | |||
1229 | } | | |||
1230 | gradient.setColorAt(1, bgColor.darker(110)); | | |||
1231 | } else { | | |||
1232 | if (mIncidence->allDay() | | |||
1233 | && mIncidence->dtStart() == mIncidence->dateTime(KCalCore::Incidence::RoleEnd) | | |||
1234 | && !CalendarSupport::hasTodo(mIncidence)) { | | |||
1235 | gradient.setColorAt(0, bgColor.lighter(130)); | | |||
1236 | gradient.setColorAt(0.35, bgColor.lighter(115)); | | |||
1237 | gradient.setColorAt(0.65, bgColor); | | |||
1238 | } else { | | |||
1239 | gradient.setColorAt(0, bgColor.lighter(115)); | | |||
1240 | gradient.setColorAt(0.65, bgColor); | | |||
1241 | } | | |||
1242 | gradient.setColorAt(1, bgColor.darker(110)); | | |||
1243 | } | 1200 | } | ||
1244 | 1201 | | |||
1245 | p->setBrush(gradient); | 1202 | p->setBrush(bgColor); | ||
1246 | p->setPen(Qt::NoPen); | | |||
1247 | p->drawPath(path); | 1203 | p->drawPath(path); | ||
1248 | | ||||
1249 | p->setRenderHint(QPainter::Antialiasing, false); | | |||
1250 | | ||||
1251 | if (r.width() - 16 > 0) { | | |||
1252 | QPixmap topLines; | | |||
1253 | QString key(QStringLiteral("ko_t")); | | |||
1254 | if (!QPixmapCache::find(key, topLines)) { | | |||
1255 | topLines = QPixmap(QStringLiteral(":/topLines.png")); | | |||
1256 | QPixmapCache::insert(key, topLines); | | |||
1257 | } | | |||
1258 | p->setBrushOrigin(r.x() + 8, r.y()); | | |||
1259 | p->fillRect(QRect(r.x() + 8, r.y(), r.width() - 16, 5), | | |||
1260 | QBrush(topLines)); | | |||
1261 | | ||||
1262 | QPixmap bottomLines; | | |||
1263 | key = QStringLiteral("ko_b"); | | |||
1264 | if (!QPixmapCache::find(key, bottomLines)) { | | |||
1265 | bottomLines = QPixmap(QStringLiteral(":/bottomLines.png")); | | |||
1266 | QPixmapCache::insert(key, bottomLines); | | |||
1267 | } | | |||
1268 | p->setBrushOrigin(r.x() + 8, r.y() + r.height() - 6); | | |||
1269 | p->fillRect(QRect(r.x() + 8, r.y() + r.height() - 6, r.width() - 16, 6), | | |||
1270 | QBrush(bottomLines)); | | |||
1271 | } | | |||
1272 | | ||||
1273 | if (r.height() - 16 > 0) { | | |||
1274 | QPixmap leftLines; | | |||
1275 | QString key(QStringLiteral("ko_l")); | | |||
1276 | if (!QPixmapCache::find(key, leftLines)) { | | |||
1277 | leftLines = QPixmap(QStringLiteral(":/leftLines.png")); | | |||
1278 | QPixmapCache::insert(key, leftLines); | | |||
1279 | } | | |||
1280 | p->setBrushOrigin(r.x(), r.y() + 8); | | |||
1281 | p->fillRect(QRect(r.x(), r.y() + 8, 5, r.height() - 16), | | |||
1282 | QBrush(leftLines)); | | |||
1283 | | ||||
1284 | QPixmap rightLines; | | |||
1285 | key = QStringLiteral("ko_r"); | | |||
1286 | if (!QPixmapCache::find(key, rightLines)) { | | |||
1287 | rightLines = QPixmap(QStringLiteral(":/rightLines.png")); | | |||
1288 | QPixmapCache::insert(key, rightLines); | | |||
1289 | } | | |||
1290 | p->setBrushOrigin(r.x() + r.width() - 5, r.y() + 8); | | |||
1291 | p->fillRect(QRect(r.x() + r.width() - 5, r.y() + 8, 5, r.height() - 16), | | |||
1292 | QBrush(rightLines)); | | |||
1293 | } | | |||
1294 | | ||||
1295 | // don't overlap the edges | | |||
1296 | int lw = shrinkWidth ? r.width() / 2 : 8; | | |||
1297 | int rw = shrinkWidth ? r.width() - lw : 8; | | |||
1298 | int th = shrinkHeight ? r.height() / 2 : 8; | | |||
1299 | int bh = shrinkHeight ? r.height() - th : 8; | | |||
1300 | | ||||
1301 | // keep the bottom round for items which ending at 00:15 | | |||
1302 | if (shrinkHeight && !roundTop && roundBottom && r.height() > 3) { | | |||
1303 | bh += th - 3; | | |||
1304 | th = 3; | | |||
1305 | } | | |||
1306 | | ||||
1307 | QPixmap topLeft; | | |||
1308 | QString key = roundTop ? QStringLiteral("ko_tl") : QStringLiteral("ko_rtl"); | | |||
1309 | if (!QPixmapCache::find(key, topLeft)) { | | |||
1310 | topLeft | | |||
1311 | = roundTop ? QPixmap(QStringLiteral(":/roundTopLeft.png")) : QPixmap(QStringLiteral( | | |||
1312 | ":/rectangularTopLeft.png")); | | |||
1313 | QPixmapCache::insert(key, topLeft); | | |||
1314 | } | | |||
1315 | p->drawPixmap(r.x(), r.y(), topLeft, 0, 0, lw, th); | | |||
1316 | | ||||
1317 | QPixmap topRight; | | |||
1318 | key = roundTop ? QStringLiteral("ko_tr") : QStringLiteral("ko_rtr"); | | |||
1319 | if (!QPixmapCache::find(key, topRight)) { | | |||
1320 | topRight = roundTop ? QPixmap(QStringLiteral(":/roundTopRight.png")) : QPixmap(QStringLiteral( | | |||
1321 | ":/rectangularTopRight.png")); | | |||
1322 | QPixmapCache::insert(key, topRight); | | |||
1323 | } | | |||
1324 | p->drawPixmap(r.x() + r.width() - rw, r.y(), topRight, 8 - rw, 0, rw, th); | | |||
1325 | | ||||
1326 | QPixmap bottomLeft; | | |||
1327 | key = roundBottom ? QStringLiteral("ko_bl") : QStringLiteral("ko_rbl"); | | |||
1328 | if (!QPixmapCache::find(key, bottomLeft)) { | | |||
1329 | bottomLeft = roundBottom ? QPixmap(QStringLiteral(":/roundBottomLeft.png")) | | |||
1330 | : QPixmap(QStringLiteral(":/rectangularBottomLeft.png")); | | |||
1331 | QPixmapCache::insert(key, bottomLeft); | | |||
1332 | } | | |||
1333 | p->drawPixmap(r.x(), r.y() + r.height() - bh, bottomLeft, 0, 8 - bh, lw, bh); | | |||
1334 | | ||||
1335 | QPixmap bottomRight; | | |||
1336 | key = roundBottom ? QStringLiteral("ko_br") : QStringLiteral("ko_rbr"); | | |||
1337 | if (!QPixmapCache::find(key, bottomRight)) { | | |||
1338 | bottomRight = roundBottom ? QPixmap(QStringLiteral(":/roundBottomRight.png")) | | |||
1339 | : QPixmap(QStringLiteral(":/rectangularBottomRight.png")); | | |||
1340 | QPixmapCache::insert(key, bottomRight); | | |||
1341 | } | | |||
1342 | p->drawPixmap(r.x() + r.width() - rw, r.y() + r.height() - bh, bottomRight, | | |||
1343 | 8 - rw, 8 - bh, rw, 8); | | |||
1344 | | ||||
1345 | p->restore(); | 1204 | p->restore(); | ||
1346 | } | 1205 | } | ||
1347 | 1206 | | |||
1348 | bool AgendaItem::eventFilter(QObject *obj, QEvent *event) | 1207 | bool AgendaItem::eventFilter(QObject *obj, QEvent *event) | ||
1349 | { | 1208 | { | ||
1350 | if (event->type() == QEvent::Paint) { | 1209 | if (event->type() == QEvent::Paint) { | ||
1351 | return mValid; | 1210 | return mValid; | ||
1352 | } else { | 1211 | } else { | ||
Show All 22 Lines |
Could you try how it looks with RADIUS = 2? That might make it look close to what Breeze widgets look like (the rounderd corners are barely visible there).