Changeset View
Changeset View
Standalone View
Standalone View
src/agenda/agendaitem.cpp
Show First 20 Lines • Show All 804 Lines • ▼ Show 20 Line(s) | 796 | { | |||
---|---|---|---|---|---|
805 | if (ev->rect() != visRect && visRect.isValid() && ev->rect().isValid()) { | 805 | if (ev->rect() != visRect && visRect.isValid() && ev->rect().isValid()) { | ||
806 | update(visRect); | 806 | update(visRect); | ||
807 | return; | 807 | return; | ||
808 | } | 808 | } | ||
809 | 809 | | |||
810 | QPainter p(this); | 810 | QPainter p(this); | ||
811 | p.setRenderHint(QPainter::Antialiasing); | 811 | p.setRenderHint(QPainter::Antialiasing); | ||
812 | const int fmargin = 0; // frame margin | 812 | const int fmargin = 0; // frame margin | ||
813 | const int ft = 1; // frame thickness for layout, see drawRoundedRect(), | 813 | const int ft = 1; // frame thickness for layout, see drawEventRect(), | ||
814 | // keep multiple of 2 | 814 | // keep multiple of 2 | ||
815 | const int margin = 5 + ft + fmargin; // frame + space between frame and content | 815 | const int margin = 5 + ft + fmargin; // frame + space between frame and content | ||
816 | 816 | | |||
817 | // General idea is to always show the icons (even in the all-day events). | 817 | // General idea is to always show the icons (even in the all-day events). | ||
818 | // This creates a consistent feeling for the user when the view mode | 818 | // This creates a consistent feeling for the user when the view mode | ||
819 | // changes and therefore the available width changes. | 819 | // changes and therefore the available width changes. | ||
820 | // Also look at #17984 | 820 | // Also look at #17984 | ||
821 | 821 | | |||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | |||||
905 | const QColor textColor = EventViews::getTextColor(bgColor); | 905 | const QColor textColor = EventViews::getTextColor(bgColor); | ||
906 | p.setPen(textColor); | 906 | p.setPen(textColor); | ||
907 | 907 | | |||
908 | p.setFont(mEventView->preferences()->agendaViewFont()); | 908 | p.setFont(mEventView->preferences()->agendaViewFont()); | ||
909 | QFontMetrics fm = p.fontMetrics(); | 909 | QFontMetrics fm = p.fontMetrics(); | ||
910 | 910 | | |||
911 | const int singleLineHeight = fm.boundingRect(mLabelText).height(); | 911 | const int singleLineHeight = fm.boundingRect(mLabelText).height(); | ||
912 | 912 | | |||
913 | const bool roundTop = !prevMultiItem(); | 913 | drawEventRect(&p, QRect(fmargin, fmargin, width() - fmargin * 2, height() - fmargin * 2), | ||
914 | const bool roundBottom = !nextMultiItem(); | 914 | mSelected, bgColor, true, ft); | ||
915 | | ||||
916 | drawRoundedRect(&p, QRect(fmargin, fmargin, width() - fmargin * 2, height() - fmargin * 2), | | |||
917 | mSelected, bgColor, true, ft, roundTop, roundBottom); | | |||
918 | 915 | | |||
919 | // calculate the height of the full version (case 4) to test whether it is | 916 | // calculate the height of the full version (case 4) to test whether it is | ||
920 | // possible | 917 | // possible | ||
921 | 918 | | |||
922 | QString shortH; | 919 | QString shortH; | ||
923 | QString longH; | 920 | QString longH; | ||
924 | if (!isMultiItem()) { | 921 | if (!isMultiItem()) { | ||
925 | shortH = QLocale().toString(mIncidence->dateTime(KCalCore::Incidence::RoleDisplayStart).toLocalZone().time(), QLocale::ShortFormat); | 922 | shortH = QLocale().toString(mIncidence->dateTime(KCalCore::Incidence::RoleDisplayStart).toLocalZone().time(), QLocale::ShortFormat); | ||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | 1021 | if (event->isMultiDay(mEventView->preferences()->timeSpec())) { | |||
1025 | // multi-day, all-day event | 1022 | // multi-day, all-day event | ||
1026 | shortH = | 1023 | shortH = | ||
1027 | i18n("%1 - %2", | 1024 | i18n("%1 - %2", | ||
1028 | QLocale().toString(mIncidence->dtStart().toLocalZone().date()), | 1025 | QLocale().toString(mIncidence->dtStart().toLocalZone().date()), | ||
1029 | QLocale().toString(mIncidence->dateTime(KCalCore::Incidence::RoleEnd).toLocalZone().date())); | 1026 | QLocale().toString(mIncidence->dateTime(KCalCore::Incidence::RoleEnd).toLocalZone().date())); | ||
1030 | longH = shortH; | 1027 | longH = shortH; | ||
1031 | 1028 | | |||
1032 | // paint headline | 1029 | // paint headline | ||
1033 | drawRoundedRect( | 1030 | drawEventRect( | ||
1034 | &p, | 1031 | &p, | ||
1035 | QRect(fmargin, fmargin, width() - fmargin * 2, - fmargin * 2 + margin + hlHeight), | 1032 | QRect(fmargin, fmargin, width() - fmargin * 2, - fmargin * 2 + margin + hlHeight), | ||
1036 | mSelected, frameColor, false, ft, roundTop, false); | 1033 | mSelected, frameColor, false, ft); | ||
1037 | } else { | 1034 | } else { | ||
1038 | // single-day, all-day event | 1035 | // single-day, all-day event | ||
1039 | 1036 | | |||
1040 | // paint headline | 1037 | // paint headline | ||
1041 | drawRoundedRect( | 1038 | drawEventRect( | ||
1042 | &p, | 1039 | &p, | ||
1043 | QRect(fmargin, fmargin, width() - fmargin * 2, - fmargin * 2 + margin + hlHeight), | 1040 | QRect(fmargin, fmargin, width() - fmargin * 2, - fmargin * 2 + margin + hlHeight), | ||
1044 | mSelected, frameColor, false, ft, roundTop, false); | 1041 | mSelected, frameColor, false, ft); | ||
1045 | } | 1042 | } | ||
1046 | } else { | 1043 | } else { | ||
1047 | // to-do | 1044 | // to-do | ||
1048 | 1045 | | |||
1049 | // paint headline | 1046 | // paint headline | ||
1050 | drawRoundedRect( | 1047 | drawEventRect( | ||
1051 | &p, | 1048 | &p, | ||
1052 | QRect(fmargin, fmargin, width() - fmargin * 2, - fmargin * 2 + margin + hlHeight), | 1049 | QRect(fmargin, fmargin, width() - fmargin * 2, - fmargin * 2 + margin + hlHeight), | ||
1053 | mSelected, frameColor, false, ft, roundTop, false); | 1050 | mSelected, frameColor, false, ft); | ||
1054 | } | 1051 | } | ||
1055 | 1052 | | |||
1056 | x += visRect.left(); | 1053 | x += visRect.left(); | ||
1057 | eventX = x; | 1054 | eventX = x; | ||
1058 | txtWidth = visRect.right() - margin - x; | 1055 | txtWidth = visRect.right() - margin - x; | ||
1059 | paintIcons(&p, x, margin / 2, ft); | 1056 | paintIcons(&p, x, margin / 2, ft); | ||
1060 | hTxtWidth = visRect.right() - margin - x; | 1057 | hTxtWidth = visRect.right() - margin - x; | ||
1061 | } else { | 1058 | } else { | ||
1062 | // paint headline | 1059 | // paint headline | ||
1063 | drawRoundedRect( | 1060 | drawEventRect( | ||
1064 | &p, | 1061 | &p, | ||
1065 | QRect(fmargin, fmargin, width() - fmargin * 2, - fmargin * 2 + margin + hlHeight), | 1062 | QRect(fmargin, fmargin, width() - fmargin * 2, - fmargin * 2 + margin + hlHeight), | ||
1066 | mSelected, frameColor, false, ft, roundTop, false); | 1063 | mSelected, frameColor, false, ft); | ||
1067 | 1064 | | |||
1068 | txtWidth = width() - margin - x; | 1065 | txtWidth = width() - margin - x; | ||
1069 | eventX = x; | 1066 | eventX = x; | ||
1070 | paintIcons(&p, x, margin / 2, ft); | 1067 | paintIcons(&p, x, margin / 2, ft); | ||
1071 | hTxtWidth = width() - margin - x; | 1068 | hTxtWidth = width() - margin - x; | ||
1072 | } | 1069 | } | ||
1073 | 1070 | | |||
1074 | QString headline; | 1071 | QString headline; | ||
Show All 24 Lines | 1095 | if (ws.leftRef(ws.length() - 1).indexOf(QLatin1Char('\n')) >= 0) { | |||
1099 | ww.drawText(&p, eventX, y, Qt::AlignLeft | KWordWrap::FadeOut); | 1096 | ww.drawText(&p, eventX, y, Qt::AlignLeft | KWordWrap::FadeOut); | ||
1100 | } else { | 1097 | } else { | ||
1101 | ww.drawText(&p, eventX + (txtWidth - ww.boundingRect().width() - 2 * margin) / 2, y, | 1098 | ww.drawText(&p, eventX + (txtWidth - ww.boundingRect().width() - 2 * margin) / 2, y, | ||
1102 | Qt::AlignHCenter | KWordWrap::FadeOut); | 1099 | Qt::AlignHCenter | KWordWrap::FadeOut); | ||
1103 | } | 1100 | } | ||
1104 | 1101 | | |||
1105 | } | 1102 | } | ||
1106 | 1103 | | |||
1107 | void AgendaItem::drawRoundedRect(QPainter *p, const QRect &rect, | 1104 | void AgendaItem::drawEventRect(QPainter *p, const QRect &rect, | ||
1108 | bool selected, const QColor &bgColor, | 1105 | bool selected, const QColor &bgColor, | ||
1109 | bool frame, int ft, bool roundTop, | 1106 | bool frame, int ft) | ||
1110 | bool roundBottom) | | |||
1111 | { | 1107 | { | ||
1112 | Q_UNUSED(ft); | 1108 | Q_UNUSED(ft); | ||
1113 | if (!mValid) { | 1109 | if (!mValid) { | ||
1114 | return; | 1110 | return; | ||
1115 | } | 1111 | } | ||
1116 | 1112 | | |||
1117 | QRect r = rect; | 1113 | QRect r = rect; | ||
1118 | r.adjust(0, 0, 1, 1); | 1114 | r.adjust(0, 0, 1, 1); | ||
1119 | 1115 | | |||
1120 | p->save(); | 1116 | p->save(); | ||
1121 | 1117 | | |||
1122 | QPainterPath path; | 1118 | QPainterPath path; | ||
1123 | 1119 | | |||
1124 | bool shrinkWidth = r.width() < 16; | 1120 | bool shrinkWidth = r.width() < 16; | ||
1125 | bool shrinkHeight = r.height() < 16; | 1121 | bool shrinkHeight = r.height() < 16; | ||
1126 | 1122 | | |||
1127 | qreal rnd = 2.1; | 1123 | qreal horizontalPad = 2.1; | ||
1128 | int sw = shrinkWidth ? 10 : 11; | 1124 | int sw = shrinkWidth ? 10 : 11; | ||
1129 | int sh = shrinkHeight ? 10 : 11; | 1125 | int sh = shrinkHeight ? 10 : 11; | ||
1130 | QRectF tr(r.x() + r.width() - sw - rnd, r.y() + rnd, sw, sh); | 1126 | QRectF tr(r.x() + r.width() - sw - horizontalPad, r.y(), sw, sh); | ||
1131 | QRectF tl(r.x() + rnd, r.y() + rnd, sw, sh); | 1127 | QRectF tl(r.x() + horizontalPad, r.y(), sw, sh); | ||
1132 | QRectF bl(r.x() + rnd, r.y() + r.height() - sh - 1 - rnd, sw, sh); | 1128 | QRectF bl(r.x() + horizontalPad, r.y() + r.height() - sh - 1, sw, sh); | ||
1133 | QRectF br(r.x() + r.width() - sw - rnd, r.y() + r.height() - sh - 1 - rnd, sw, sh); | 1129 | QRectF br(r.x() + r.width() - sw - horizontalPad, r.y() + r.height() - sh - 1, sw, sh); | ||
1134 | 1130 | | |||
1135 | if (roundTop) { | | |||
1136 | path.moveTo(tr.topRight()); | | |||
1137 | path.arcTo(tr, 0.0, 90.0); | | |||
1138 | path.lineTo(tl.topRight()); | | |||
1139 | path.arcTo(tl, 90.0, 90.0); | | |||
1140 | } else { | | |||
1141 | path.moveTo(tr.topRight()); | 1131 | path.moveTo(tr.topRight()); | ||
1142 | path.lineTo(tl.topLeft()); | 1132 | path.lineTo(tl.topLeft()); | ||
1143 | } | | |||
1144 | 1133 | | |||
1145 | if (roundBottom) { | | |||
1146 | path.lineTo(bl.topLeft()); | | |||
1147 | path.arcTo(bl, 180.0, 90.0); | | |||
1148 | path.lineTo(br.bottomLeft()); | | |||
1149 | path.arcTo(br, 270.0, 90.0); | | |||
1150 | } else { | | |||
1151 | path.lineTo(bl.bottomLeft()); | 1134 | path.lineTo(bl.bottomLeft()); | ||
1152 | path.lineTo(br.bottomRight()); | 1135 | path.lineTo(br.bottomRight()); | ||
1153 | } | 1136 | | ||
1154 | path.closeSubpath(); | 1137 | path.closeSubpath(); | ||
1155 | 1138 | | |||
1156 | // header | 1139 | // header | ||
1157 | if (!frame) { | 1140 | if (!frame) { | ||
1158 | QLinearGradient gradient(QPointF(r.x(), r.y()), QPointF(r.x(), r.height())); | 1141 | QLinearGradient gradient(QPointF(r.x(), r.y()), QPointF(r.x(), r.height())); | ||
1159 | 1142 | | |||
1160 | if (selected) { | 1143 | if (selected) { | ||
1161 | QColor top = bgColor.dark(250); | 1144 | QColor top = bgColor.dark(250); | ||
1162 | top.setAlpha(40); | 1145 | top.setAlpha(40); | ||
1163 | gradient.setColorAt(0, top); | 1146 | gradient.setColorAt(0, top); | ||
1164 | gradient.setColorAt(1, QColor(255, 255, 255, 30)); | 1147 | gradient.setColorAt(1, QColor(255, 255, 255, 30)); | ||
1165 | } else { | 1148 | } else { | ||
1166 | gradient.setColorAt(0, QColor(255, 255, 255, 90)); | 1149 | gradient.setColorAt(0, QColor(255, 255, 255, 90)); | ||
1167 | gradient.setColorAt(1, QColor(0, 0, 0, 10)); | 1150 | gradient.setColorAt(1, QColor(0, 0, 0, 10)); | ||
1168 | } | 1151 | } | ||
1169 | 1152 | | |||
1170 | p->setBrush(bgColor); | 1153 | p->setBrush(bgColor); | ||
1171 | p->setPen(Qt::NoPen); | 1154 | p->setPen(Qt::NoPen); | ||
1172 | p->drawPath(path); | 1155 | p->drawPath(path); | ||
1173 | 1156 | | |||
1174 | p->setBrush(gradient); | 1157 | p->setBrush(gradient); | ||
1175 | p->setPen(Qt::NoPen); | 1158 | p->setPen(Qt::NoPen); | ||
1176 | p->drawPath(path); | 1159 | p->drawPath(path); | ||
1177 | 1160 | | |||
1178 | QPixmap separator; | | |||
1179 | QString key(QStringLiteral("ko_hsep")); | | |||
1180 | if (!QPixmapCache::find(key, separator)) { | | |||
1181 | separator = QPixmap(QStringLiteral(":/headerSeparator.png")); | | |||
1182 | QPixmapCache::insert(key, separator); | | |||
1183 | } | | |||
1184 | p->fillRect(QRect(r.x() + 3, r.y() + r.height() - 2, r.x() + r.width() - 4, 2), | | |||
1185 | QBrush(separator)); | | |||
1186 | | ||||
1187 | p->restore(); | 1161 | p->restore(); | ||
1188 | return; | 1162 | return; | ||
1189 | } | 1163 | } | ||
1190 | 1164 | | |||
1191 | QLinearGradient gradient(QPointF(r.x(), r.y()), QPointF(r.x(), r.height())); | 1165 | QLinearGradient gradient(QPointF(r.x(), r.y()), QPointF(r.x(), r.height())); | ||
1192 | 1166 | | |||
1193 | if (r.height() > 50) { | 1167 | if (r.height() > 50) { | ||
1194 | if (mIncidence->allDay() && | 1168 | if (mIncidence->allDay() && | ||
Show All 25 Lines | |||||
1220 | } | 1194 | } | ||
1221 | 1195 | | |||
1222 | p->setBrush(gradient); | 1196 | p->setBrush(gradient); | ||
1223 | p->setPen(Qt::NoPen); | 1197 | p->setPen(Qt::NoPen); | ||
1224 | p->drawPath(path); | 1198 | p->drawPath(path); | ||
1225 | 1199 | | |||
1226 | p->setRenderHint(QPainter::Antialiasing, false); | 1200 | p->setRenderHint(QPainter::Antialiasing, false); | ||
1227 | 1201 | | |||
1228 | if (r.width() - 16 > 0) { | | |||
1229 | QPixmap topLines; | | |||
1230 | QString key(QStringLiteral("ko_t")); | | |||
1231 | if (!QPixmapCache::find(key, topLines)) { | | |||
1232 | topLines = QPixmap(QStringLiteral(":/topLines.png")); | | |||
1233 | QPixmapCache::insert(key, topLines); | | |||
1234 | } | | |||
1235 | p->setBrushOrigin(r.x() + 8, r.y()); | | |||
1236 | p->fillRect(QRect(r.x() + 8, r.y(), r.width() - 16, 5), | | |||
1237 | QBrush(topLines)); | | |||
1238 | | ||||
1239 | QPixmap bottomLines; | | |||
1240 | key = QStringLiteral("ko_b"); | | |||
1241 | if (!QPixmapCache::find(key, bottomLines)) { | | |||
1242 | bottomLines = QPixmap(QStringLiteral(":/bottomLines.png")); | | |||
1243 | QPixmapCache::insert(key, bottomLines); | | |||
1244 | } | | |||
1245 | p->setBrushOrigin(r.x() + 8, r.y() + r.height() - 6); | | |||
1246 | p->fillRect(QRect(r.x() + 8, r.y() + r.height() - 6, r.width() - 16, 6), | | |||
1247 | QBrush(bottomLines)); | | |||
1248 | | ||||
1249 | } | | |||
1250 | | ||||
1251 | if (r.height() - 16 > 0) { | | |||
1252 | | ||||
1253 | QPixmap leftLines; | | |||
1254 | QString key(QStringLiteral("ko_l")); | | |||
1255 | if (!QPixmapCache::find(key, leftLines)) { | | |||
1256 | leftLines = QPixmap(QStringLiteral(":/leftLines.png")); | | |||
1257 | QPixmapCache::insert(key, leftLines); | | |||
1258 | } | | |||
1259 | p->setBrushOrigin(r.x(), r.y() + 8); | | |||
1260 | p->fillRect(QRect(r.x(), r.y() + 8, 5, r.height() - 16), | | |||
1261 | QBrush(leftLines)); | | |||
1262 | | ||||
1263 | QPixmap rightLines; | | |||
1264 | key = QStringLiteral("ko_r"); | | |||
1265 | if (!QPixmapCache::find(key, rightLines)) { | | |||
1266 | rightLines = QPixmap(QStringLiteral(":/rightLines.png")); | | |||
1267 | QPixmapCache::insert(key, rightLines); | | |||
1268 | } | | |||
1269 | p->setBrushOrigin(r.x() + r.width() - 5, r.y() + 8); | | |||
1270 | p->fillRect(QRect(r.x() + r.width() - 5, r.y() + 8, 5, r.height() - 16), | | |||
1271 | QBrush(rightLines)); | | |||
1272 | } | | |||
1273 | | ||||
1274 | // don't overlap the edges | | |||
1275 | int lw = shrinkWidth ? r.width() / 2 : 8; | | |||
1276 | int rw = shrinkWidth ? r.width() - lw : 8; | | |||
1277 | int th = shrinkHeight ? r.height() / 2 : 8; | | |||
1278 | int bh = shrinkHeight ? r.height() - th : 8; | | |||
1279 | | ||||
1280 | // keep the bottom round for items which ending at 00:15 | | |||
1281 | if (shrinkHeight && !roundTop && roundBottom && r.height() > 3) { | | |||
1282 | bh += th - 3; | | |||
1283 | th = 3; | | |||
1284 | } | | |||
1285 | | ||||
1286 | QPixmap topLeft; | | |||
1287 | QString key = roundTop ? QStringLiteral("ko_tl") : QStringLiteral("ko_rtl"); | | |||
1288 | if (!QPixmapCache::find(key, topLeft)) { | | |||
1289 | topLeft = roundTop ? QPixmap(QStringLiteral(":/roundTopLeft.png")) : QPixmap(QStringLiteral(":/rectangularTopLeft.png")); | | |||
1290 | QPixmapCache::insert(key, topLeft); | | |||
1291 | } | | |||
1292 | p->drawPixmap(r.x(), r.y(), topLeft, 0, 0, lw, th); | | |||
1293 | | ||||
1294 | QPixmap topRight; | | |||
1295 | key = roundTop ? QStringLiteral("ko_tr") : QStringLiteral("ko_rtr"); | | |||
1296 | if (!QPixmapCache::find(key, topRight)) { | | |||
1297 | topRight = roundTop ? QPixmap(QStringLiteral(":/roundTopRight.png")) : QPixmap(QStringLiteral(":/rectangularTopRight.png")); | | |||
1298 | QPixmapCache::insert(key, topRight); | | |||
1299 | } | | |||
1300 | p->drawPixmap(r.x() + r.width() - rw, r.y(), topRight, 8 - rw, 0, rw, th); | | |||
1301 | | ||||
1302 | QPixmap bottomLeft; | | |||
1303 | key = roundBottom ? QStringLiteral("ko_bl") : QStringLiteral("ko_rbl"); | | |||
1304 | if (!QPixmapCache::find(key, bottomLeft)) { | | |||
1305 | bottomLeft = roundBottom ? QPixmap(QStringLiteral(":/roundBottomLeft.png")) : | | |||
1306 | QPixmap(QStringLiteral(":/rectangularBottomLeft.png")); | | |||
1307 | QPixmapCache::insert(key, bottomLeft); | | |||
1308 | } | | |||
1309 | p->drawPixmap(r.x(), r.y() + r.height() - bh, bottomLeft, 0, 8 - bh, lw, bh); | | |||
1310 | | ||||
1311 | QPixmap bottomRight; | | |||
1312 | key = roundBottom ? QStringLiteral("ko_br") : QStringLiteral("ko_rbr"); | | |||
1313 | if (!QPixmapCache::find(key, bottomRight)) { | | |||
1314 | bottomRight = roundBottom ? QPixmap(QStringLiteral(":/roundBottomRight.png")) : | | |||
1315 | QPixmap(QStringLiteral(":/rectangularBottomRight.png")); | | |||
1316 | QPixmapCache::insert(key, bottomRight); | | |||
1317 | } | | |||
1318 | p->drawPixmap(r.x() + r.width() - rw, r.y() + r.height() - bh, bottomRight, | | |||
1319 | 8 - rw, 8 - bh, rw, 8); | | |||
1320 | | ||||
1321 | p->restore(); | 1202 | p->restore(); | ||
1322 | } | 1203 | } | ||
1323 | 1204 | | |||
1324 | bool AgendaItem::eventFilter(QObject *obj, QEvent *event) | 1205 | bool AgendaItem::eventFilter(QObject *obj, QEvent *event) | ||
1325 | { | 1206 | { | ||
1326 | if (event->type() == QEvent::Paint) { | 1207 | if (event->type() == QEvent::Paint) { | ||
1327 | return mValid; | 1208 | return mValid; | ||
1328 | } else { | 1209 | } else { | ||
Show All 24 Lines |