Changeset View
Changeset View
Standalone View
Standalone View
src/kitemviews/kstandarditemlistwidget.cpp
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | |||||
46 | 46 | | |||
47 | KStandardItemListWidgetInformant::~KStandardItemListWidgetInformant() | 47 | KStandardItemListWidgetInformant::~KStandardItemListWidgetInformant() | ||
48 | { | 48 | { | ||
49 | } | 49 | } | ||
50 | 50 | | |||
51 | void KStandardItemListWidgetInformant::calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const | 51 | void KStandardItemListWidgetInformant::calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const | ||
52 | { | 52 | { | ||
53 | switch (static_cast<const KStandardItemListView*>(view)->itemLayout()) { | 53 | switch (static_cast<const KStandardItemListView*>(view)->itemLayout()) { | ||
54 | case KStandardItemListWidget::IconsLayout: | 54 | case KStandardItemListView::ItemLayout::Icons: | ||
55 | calculateIconsLayoutItemSizeHints(logicalHeightHints, logicalWidthHint, view); | 55 | calculateIconsLayoutItemSizeHints(logicalHeightHints, logicalWidthHint, view); | ||
56 | break; | 56 | break; | ||
57 | 57 | | |||
58 | case KStandardItemListWidget::CompactLayout: | 58 | case KStandardItemListView::ItemLayout::Compact: | ||
59 | calculateCompactLayoutItemSizeHints(logicalHeightHints, logicalWidthHint, view); | 59 | calculateCompactLayoutItemSizeHints(logicalHeightHints, logicalWidthHint, view); | ||
60 | break; | 60 | break; | ||
61 | 61 | | |||
62 | case KStandardItemListWidget::DetailsLayout: | 62 | case KStandardItemListView::ItemLayout::Details: | ||
63 | calculateDetailsLayoutItemSizeHints(logicalHeightHints, logicalWidthHint, view); | 63 | calculateDetailsLayoutItemSizeHints(logicalHeightHints, logicalWidthHint, view); | ||
64 | break; | 64 | break; | ||
65 | 65 | | |||
66 | default: | 66 | default: | ||
67 | Q_ASSERT(false); | 67 | Q_ASSERT(false); | ||
68 | break; | 68 | break; | ||
69 | } | 69 | } | ||
70 | } | 70 | } | ||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Line(s) | 246 | KStandardItemListWidget::KStandardItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent) : | |||
249 | m_isHidden(false), | 249 | m_isHidden(false), | ||
250 | m_customizedFont(), | 250 | m_customizedFont(), | ||
251 | m_customizedFontMetrics(m_customizedFont), | 251 | m_customizedFontMetrics(m_customizedFont), | ||
252 | m_isExpandable(false), | 252 | m_isExpandable(false), | ||
253 | m_supportsItemExpanding(false), | 253 | m_supportsItemExpanding(false), | ||
254 | m_dirtyLayout(true), | 254 | m_dirtyLayout(true), | ||
255 | m_dirtyContent(true), | 255 | m_dirtyContent(true), | ||
256 | m_dirtyContentRoles(), | 256 | m_dirtyContentRoles(), | ||
257 | m_layout(IconsLayout), | 257 | m_layout(Layout::Icons), | ||
258 | m_pixmapPos(), | 258 | m_pixmapPos(), | ||
259 | m_pixmap(), | 259 | m_pixmap(), | ||
260 | m_scaledPixmapSize(), | 260 | m_scaledPixmapSize(), | ||
261 | m_iconRect(), | 261 | m_iconRect(), | ||
262 | m_hoverPixmap(), | 262 | m_hoverPixmap(), | ||
263 | m_textInfo(), | 263 | m_textInfo(), | ||
264 | m_textRect(), | 264 | m_textRect(), | ||
265 | m_sortedVisibleRoles(), | 265 | m_sortedVisibleRoles(), | ||
▲ Show 20 Lines • Show All 189 Lines • ▼ Show 20 Line(s) | 454 | { | |||
455 | // In the compact- and details-layout a larger textRect() is returned to be aligned | 455 | // In the compact- and details-layout a larger textRect() is returned to be aligned | ||
456 | // with the iconRect(). This is useful to have a larger selection/hover-area | 456 | // with the iconRect(). This is useful to have a larger selection/hover-area | ||
457 | // when having a quite large icon size but only one line of text. Still the | 457 | // when having a quite large icon size but only one line of text. Still the | ||
458 | // focus rectangle should be shown as narrow as possible around the text. | 458 | // focus rectangle should be shown as narrow as possible around the text. | ||
459 | 459 | | |||
460 | const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing(); | 460 | const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing(); | ||
461 | 461 | | |||
462 | switch (m_layout) { | 462 | switch (m_layout) { | ||
463 | case CompactLayout: { | 463 | case Layout::Compact: { | ||
464 | QRectF rect = m_textRect; | 464 | QRectF rect = m_textRect; | ||
465 | const TextInfo* topText = m_textInfo.value(m_sortedVisibleRoles.first()); | 465 | const TextInfo* topText = m_textInfo.value(m_sortedVisibleRoles.first()); | ||
466 | const TextInfo* bottomText = m_textInfo.value(m_sortedVisibleRoles.last()); | 466 | const TextInfo* bottomText = m_textInfo.value(m_sortedVisibleRoles.last()); | ||
467 | rect.setTop(topText->pos.y()); | 467 | rect.setTop(topText->pos.y()); | ||
468 | rect.setBottom(bottomText->pos.y() + bottomText->staticText.size().height()); | 468 | rect.setBottom(bottomText->pos.y() + bottomText->staticText.size().height()); | ||
469 | return rect; | 469 | return rect; | ||
470 | } | 470 | } | ||
471 | 471 | | |||
472 | case DetailsLayout: { | 472 | case Layout::Details: { | ||
473 | QRectF rect = m_textRect; | 473 | QRectF rect = m_textRect; | ||
474 | const TextInfo* textInfo = m_textInfo.value(m_sortedVisibleRoles.first()); | 474 | const TextInfo* textInfo = m_textInfo.value(m_sortedVisibleRoles.first()); | ||
475 | rect.setTop(textInfo->pos.y()); | 475 | rect.setTop(textInfo->pos.y()); | ||
476 | rect.setBottom(textInfo->pos.y() + textInfo->staticText.size().height()); | 476 | rect.setBottom(textInfo->pos.y() + textInfo->staticText.size().height()); | ||
477 | 477 | | |||
478 | const KItemListStyleOption& option = styleOption(); | 478 | const KItemListStyleOption& option = styleOption(); | ||
479 | if (option.extendedSelectionRegion) { | 479 | if (option.extendedSelectionRegion) { | ||
480 | const QString text = textInfo->staticText.text(); | 480 | const QString text = textInfo->staticText.text(); | ||
Show All 10 Lines | |||||
491 | return m_textRect; | 491 | return m_textRect; | ||
492 | } | 492 | } | ||
493 | 493 | | |||
494 | QRectF KStandardItemListWidget::selectionRect() const | 494 | QRectF KStandardItemListWidget::selectionRect() const | ||
495 | { | 495 | { | ||
496 | const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing(); | 496 | const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing(); | ||
497 | 497 | | |||
498 | switch (m_layout) { | 498 | switch (m_layout) { | ||
499 | case IconsLayout: | 499 | case Layout::Icons: | ||
500 | return m_textRect; | 500 | return m_textRect; | ||
501 | 501 | | |||
502 | case CompactLayout: | 502 | case Layout::Compact: | ||
503 | case DetailsLayout: { | 503 | case Layout::Details: { | ||
504 | const int padding = styleOption().padding; | 504 | const int padding = styleOption().padding; | ||
505 | QRectF adjustedIconRect = iconRect().adjusted(-padding, -padding, padding, padding); | 505 | QRectF adjustedIconRect = iconRect().adjusted(-padding, -padding, padding, padding); | ||
506 | return adjustedIconRect | m_textRect; | 506 | return adjustedIconRect | m_textRect; | ||
507 | } | 507 | } | ||
508 | 508 | | |||
509 | default: | 509 | default: | ||
510 | Q_ASSERT(false); | 510 | Q_ASSERT(false); | ||
511 | break; | 511 | break; | ||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 524 | { | |||
556 | 556 | | |||
557 | return QRectF(pos, QSizeF(toggleSize, toggleSize)); | 557 | return QRectF(pos, QSizeF(toggleSize, toggleSize)); | ||
558 | } | 558 | } | ||
559 | 559 | | |||
560 | QPixmap KStandardItemListWidget::createDragPixmap(const QStyleOptionGraphicsItem* option, | 560 | QPixmap KStandardItemListWidget::createDragPixmap(const QStyleOptionGraphicsItem* option, | ||
561 | QWidget* widget) | 561 | QWidget* widget) | ||
562 | { | 562 | { | ||
563 | QPixmap pixmap = KItemListWidget::createDragPixmap(option, widget); | 563 | QPixmap pixmap = KItemListWidget::createDragPixmap(option, widget); | ||
564 | if (m_layout != DetailsLayout) { | 564 | if (m_layout != Layout::Details) { | ||
565 | return pixmap; | 565 | return pixmap; | ||
566 | } | 566 | } | ||
567 | 567 | | |||
568 | // Only return the content of the text-column as pixmap | 568 | // Only return the content of the text-column as pixmap | ||
569 | const int leftClip = m_pixmapPos.x(); | 569 | const int leftClip = m_pixmapPos.x(); | ||
570 | 570 | | |||
571 | const TextInfo* textInfo = m_textInfo.value("text"); | 571 | const TextInfo* textInfo = m_textInfo.value("text"); | ||
572 | const int rightClip = textInfo->pos.x() + | 572 | const int rightClip = textInfo->pos.x() + | ||
▲ Show 20 Lines • Show All 360 Lines • ▼ Show 20 Line(s) | |||||
933 | } | 933 | } | ||
934 | 934 | | |||
935 | void KStandardItemListWidget::updatePixmapCache() | 935 | void KStandardItemListWidget::updatePixmapCache() | ||
936 | { | 936 | { | ||
937 | // Precondition: Requires already updated m_textPos values to calculate | 937 | // Precondition: Requires already updated m_textPos values to calculate | ||
938 | // the remaining height when the alignment is vertical. | 938 | // the remaining height when the alignment is vertical. | ||
939 | 939 | | |||
940 | const QSizeF widgetSize = size(); | 940 | const QSizeF widgetSize = size(); | ||
941 | const bool iconOnTop = (m_layout == IconsLayout); | 941 | const bool iconOnTop = (m_layout == Layout::Icons); | ||
942 | const KItemListStyleOption& option = styleOption(); | 942 | const KItemListStyleOption& option = styleOption(); | ||
943 | const qreal padding = option.padding; | 943 | const qreal padding = option.padding; | ||
944 | 944 | | |||
945 | const int maxIconWidth = iconOnTop ? widgetSize.width() - 2 * padding : option.iconSize; | 945 | const int maxIconWidth = iconOnTop ? widgetSize.width() - 2 * padding : option.iconSize; | ||
946 | const int maxIconHeight = option.iconSize; | 946 | const int maxIconHeight = option.iconSize; | ||
947 | 947 | | |||
948 | const QHash<QByteArray, QVariant> values = data(); | 948 | const QHash<QByteArray, QVariant> values = data(); | ||
949 | 949 | | |||
Show All 28 Lines | 977 | if (m_isCut) { | |||
978 | KIconEffect* effect = KIconLoader::global()->iconEffect(); | 978 | KIconEffect* effect = KIconLoader::global()->iconEffect(); | ||
979 | m_pixmap = effect->apply(m_pixmap, KIconLoader::Desktop, KIconLoader::DisabledState); | 979 | m_pixmap = effect->apply(m_pixmap, KIconLoader::Desktop, KIconLoader::DisabledState); | ||
980 | } | 980 | } | ||
981 | 981 | | |||
982 | if (m_isHidden) { | 982 | if (m_isHidden) { | ||
983 | KIconEffect::semiTransparent(m_pixmap); | 983 | KIconEffect::semiTransparent(m_pixmap); | ||
984 | } | 984 | } | ||
985 | 985 | | |||
986 | if (m_layout == IconsLayout && isSelected()) { | 986 | if (m_layout == Layout::Icons && isSelected()) { | ||
987 | const QColor color = palette().brush(QPalette::Normal, QPalette::Highlight).color(); | 987 | const QColor color = palette().brush(QPalette::Normal, QPalette::Highlight).color(); | ||
988 | QImage image = m_pixmap.toImage(); | 988 | QImage image = m_pixmap.toImage(); | ||
989 | KIconEffect::colorize(image, color, 0.8f); | 989 | KIconEffect::colorize(image, color, 0.8f); | ||
990 | m_pixmap = QPixmap::fromImage(image); | 990 | m_pixmap = QPixmap::fromImage(image); | ||
991 | } | 991 | } | ||
992 | } | 992 | } | ||
993 | 993 | | |||
994 | if (!m_overlay.isNull()) { | 994 | if (!m_overlay.isNull()) { | ||
995 | QPainter painter(&m_pixmap); | 995 | QPainter painter(&m_pixmap); | ||
996 | painter.drawPixmap(0, (m_pixmap.height() - m_overlay.height()) / m_pixmap.devicePixelRatio(), m_overlay); | 996 | painter.drawPixmap(0, (m_pixmap.height() - m_overlay.height()) / m_pixmap.devicePixelRatio(), m_overlay); | ||
997 | } | 997 | } | ||
998 | 998 | | |||
999 | int scaledIconSize = 0; | 999 | int scaledIconSize = 0; | ||
1000 | if (iconOnTop) { | 1000 | if (iconOnTop) { | ||
1001 | const TextInfo* textInfo = m_textInfo.value("text"); | 1001 | const TextInfo* textInfo = m_textInfo.value("text"); | ||
1002 | scaledIconSize = static_cast<int>(textInfo->pos.y() - 2 * padding); | 1002 | scaledIconSize = static_cast<int>(textInfo->pos.y() - 2 * padding); | ||
1003 | } else { | 1003 | } else { | ||
1004 | const int textRowsCount = (m_layout == CompactLayout) ? visibleRoles().count() : 1; | 1004 | const int textRowsCount = (m_layout == Layout::Compact) ? visibleRoles().count() : 1; | ||
1005 | const qreal requiredTextHeight = textRowsCount * m_customizedFontMetrics.height(); | 1005 | const qreal requiredTextHeight = textRowsCount * m_customizedFontMetrics.height(); | ||
1006 | scaledIconSize = (requiredTextHeight < maxIconHeight) ? | 1006 | scaledIconSize = (requiredTextHeight < maxIconHeight) ? | ||
1007 | widgetSize.height() - 2 * padding : maxIconHeight; | 1007 | widgetSize.height() - 2 * padding : maxIconHeight; | ||
1008 | } | 1008 | } | ||
1009 | 1009 | | |||
1010 | const int maxScaledIconWidth = iconOnTop ? widgetSize.width() - 2 * padding : scaledIconSize; | 1010 | const int maxScaledIconWidth = iconOnTop ? widgetSize.width() - 2 * padding : scaledIconSize; | ||
1011 | const int maxScaledIconHeight = scaledIconSize; | 1011 | const int maxScaledIconHeight = scaledIconSize; | ||
1012 | 1012 | | |||
Show All 30 Lines | 1041 | } else if (hoverOpacity() <= 0.0) { | |||
1043 | m_hoverPixmap = QPixmap(); | 1043 | m_hoverPixmap = QPixmap(); | ||
1044 | } | 1044 | } | ||
1045 | } | 1045 | } | ||
1046 | 1046 | | |||
1047 | void KStandardItemListWidget::updateTextsCache() | 1047 | void KStandardItemListWidget::updateTextsCache() | ||
1048 | { | 1048 | { | ||
1049 | QTextOption textOption; | 1049 | QTextOption textOption; | ||
1050 | switch (m_layout) { | 1050 | switch (m_layout) { | ||
1051 | case IconsLayout: | 1051 | case Layout::Icons: | ||
1052 | textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); | 1052 | textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); | ||
1053 | textOption.setAlignment(Qt::AlignHCenter); | 1053 | textOption.setAlignment(Qt::AlignHCenter); | ||
1054 | break; | 1054 | break; | ||
1055 | case CompactLayout: | 1055 | case Layout::Compact: | ||
1056 | case DetailsLayout: | 1056 | case Layout::Details: | ||
1057 | textOption.setAlignment(Qt::AlignLeft); | 1057 | textOption.setAlignment(Qt::AlignLeft); | ||
1058 | textOption.setWrapMode(QTextOption::NoWrap); | 1058 | textOption.setWrapMode(QTextOption::NoWrap); | ||
1059 | break; | 1059 | break; | ||
1060 | default: | 1060 | default: | ||
1061 | Q_ASSERT(false); | 1061 | Q_ASSERT(false); | ||
1062 | break; | 1062 | break; | ||
1063 | } | 1063 | } | ||
1064 | 1064 | | |||
1065 | qDeleteAll(m_textInfo); | 1065 | qDeleteAll(m_textInfo); | ||
1066 | m_textInfo.clear(); | 1066 | m_textInfo.clear(); | ||
1067 | for (int i = 0; i < m_sortedVisibleRoles.count(); ++i) { | 1067 | for (int i = 0; i < m_sortedVisibleRoles.count(); ++i) { | ||
1068 | TextInfo* textInfo = new TextInfo(); | 1068 | TextInfo* textInfo = new TextInfo(); | ||
1069 | textInfo->staticText.setTextFormat(Qt::PlainText); | 1069 | textInfo->staticText.setTextFormat(Qt::PlainText); | ||
1070 | textInfo->staticText.setPerformanceHint(QStaticText::AggressiveCaching); | 1070 | textInfo->staticText.setPerformanceHint(QStaticText::AggressiveCaching); | ||
1071 | textInfo->staticText.setTextOption(textOption); | 1071 | textInfo->staticText.setTextOption(textOption); | ||
1072 | m_textInfo.insert(m_sortedVisibleRoles[i], textInfo); | 1072 | m_textInfo.insert(m_sortedVisibleRoles[i], textInfo); | ||
1073 | } | 1073 | } | ||
1074 | 1074 | | |||
1075 | switch (m_layout) { | 1075 | switch (m_layout) { | ||
1076 | case IconsLayout: updateIconsLayoutTextCache(); break; | 1076 | case Layout::Icons: updateIconsLayoutTextCache(); break; | ||
1077 | case CompactLayout: updateCompactLayoutTextCache(); break; | 1077 | case Layout::Compact: updateCompactLayoutTextCache(); break; | ||
1078 | case DetailsLayout: updateDetailsLayoutTextCache(); break; | 1078 | case Layout::Details: updateDetailsLayoutTextCache(); break; | ||
1079 | default: Q_ASSERT(false); break; | 1079 | default: Q_ASSERT(false); break; | ||
1080 | } | 1080 | } | ||
1081 | 1081 | | |||
1082 | const TextInfo* ratingTextInfo = m_textInfo.value("rating"); | 1082 | const TextInfo* ratingTextInfo = m_textInfo.value("rating"); | ||
1083 | if (ratingTextInfo) { | 1083 | if (ratingTextInfo) { | ||
1084 | // The text of the rating-role has been set to empty to get | 1084 | // The text of the rating-role has been set to empty to get | ||
1085 | // replaced by a rating-image showing the rating as stars. | 1085 | // replaced by a rating-image showing the rating as stars. | ||
1086 | const KItemListStyleOption& option = styleOption(); | 1086 | const KItemListStyleOption& option = styleOption(); | ||
1087 | QSizeF ratingSize = preferredRatingSize(option); | 1087 | QSizeF ratingSize = preferredRatingSize(option); | ||
1088 | 1088 | | |||
1089 | const qreal availableWidth = (m_layout == DetailsLayout) | 1089 | const qreal availableWidth = (m_layout == Layout::Details) | ||
1090 | ? columnWidth("rating") - columnPadding(option) | 1090 | ? columnWidth("rating") - columnPadding(option) | ||
1091 | : size().width(); | 1091 | : size().width(); | ||
1092 | if (ratingSize.width() > availableWidth) { | 1092 | if (ratingSize.width() > availableWidth) { | ||
1093 | ratingSize.rwidth() = availableWidth; | 1093 | ratingSize.rwidth() = availableWidth; | ||
1094 | } | 1094 | } | ||
1095 | const qreal dpr = qApp->devicePixelRatio(); | 1095 | const qreal dpr = qApp->devicePixelRatio(); | ||
1096 | m_rating = QPixmap(ratingSize.toSize() * dpr); | 1096 | m_rating = QPixmap(ratingSize.toSize() * dpr); | ||
1097 | m_rating.setDevicePixelRatio(dpr); | 1097 | m_rating.setDevicePixelRatio(dpr); | ||
▲ Show 20 Lines • Show All 247 Lines • ▼ Show 20 Line(s) | 1282 | { | |||
1345 | } | 1345 | } | ||
1346 | } | 1346 | } | ||
1347 | 1347 | | |||
1348 | void KStandardItemListWidget::updateAdditionalInfoTextColor() | 1348 | void KStandardItemListWidget::updateAdditionalInfoTextColor() | ||
1349 | { | 1349 | { | ||
1350 | QColor c1; | 1350 | QColor c1; | ||
1351 | if (m_customTextColor.isValid()) { | 1351 | if (m_customTextColor.isValid()) { | ||
1352 | c1 = m_customTextColor; | 1352 | c1 = m_customTextColor; | ||
1353 | } else if (isSelected() && m_layout != DetailsLayout) { | 1353 | } else if (isSelected() && m_layout != Layout::Details) { | ||
1354 | c1 = styleOption().palette.highlightedText().color(); | 1354 | c1 = styleOption().palette.highlightedText().color(); | ||
1355 | } else { | 1355 | } else { | ||
1356 | c1 = styleOption().palette.text().color(); | 1356 | c1 = styleOption().palette.text().color(); | ||
1357 | } | 1357 | } | ||
1358 | 1358 | | |||
1359 | // For the color of the additional info the inactive text color | 1359 | // For the color of the additional info the inactive text color | ||
1360 | // is not used as this might lead to unreadable text for some color schemes. Instead | 1360 | // is not used as this might lead to unreadable text for some color schemes. Instead | ||
1361 | // the text color c1 is slightly mixed with the background color. | 1361 | // the text color c1 is slightly mixed with the background color. | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | |||||
1419 | QRectF KStandardItemListWidget::roleEditingRect(const QByteArray& role) const | 1419 | QRectF KStandardItemListWidget::roleEditingRect(const QByteArray& role) const | ||
1420 | { | 1420 | { | ||
1421 | const TextInfo* textInfo = m_textInfo.value(role); | 1421 | const TextInfo* textInfo = m_textInfo.value(role); | ||
1422 | if (!textInfo) { | 1422 | if (!textInfo) { | ||
1423 | return QRectF(); | 1423 | return QRectF(); | ||
1424 | } | 1424 | } | ||
1425 | 1425 | | |||
1426 | QRectF rect(textInfo->pos, textInfo->staticText.size()); | 1426 | QRectF rect(textInfo->pos, textInfo->staticText.size()); | ||
1427 | if (m_layout == DetailsLayout) { | 1427 | if (m_layout == Layout::Details) { | ||
1428 | rect.setWidth(columnWidth(role) - rect.x()); | 1428 | rect.setWidth(columnWidth(role) - rect.x()); | ||
1429 | } | 1429 | } | ||
1430 | 1430 | | |||
1431 | return rect; | 1431 | return rect; | ||
1432 | } | 1432 | } | ||
1433 | 1433 | | |||
1434 | void KStandardItemListWidget::closeRoleEditor() | 1434 | void KStandardItemListWidget::closeRoleEditor() | ||
1435 | { | 1435 | { | ||
▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines |