]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kstandarditemlistwidget.cpp
Make main view react to context menu events
[dolphin.git] / src / kitemviews / kstandarditemlistwidget.cpp
index 0772bccc9ff8ca042f00cd23520d53f60175edf0..54e1fa50b3bbb9a09af416cfbd12d0a04cb17ea0 100644 (file)
@@ -386,7 +386,7 @@ void KStandardItemListWidget::paint(QPainter *painter, const QStyleOptionGraphic
     }
 
     painter->setFont(m_customizedFont);
-    painter->setPen(textColor());
+    painter->setPen(textColor(*widget));
     const TextInfo *textInfo = m_textInfo.value("text");
 
     if (!textInfo) {
@@ -645,7 +645,7 @@ void KStandardItemListWidget::setTextColor(const QColor &color)
     }
 }
 
-QColor KStandardItemListWidget::textColor() const
+QColor KStandardItemListWidget::textColor(const QWidget &widget) const
 {
     if (!isSelected()) {
         if (m_isHidden) {
@@ -655,7 +655,7 @@ QColor KStandardItemListWidget::textColor() const
         }
     }
 
-    const QPalette::ColorGroup group = isActiveWindow() ? QPalette::Active : QPalette::Inactive;
+    const QPalette::ColorGroup group = isActiveWindow() && widget.hasFocus() ? QPalette::Active : QPalette::Inactive;
     const QPalette::ColorRole role = isSelected() ? QPalette::HighlightedText : normalTextColorRole();
     return styleOption().palette.color(group, role);
 }
@@ -821,6 +821,7 @@ void KStandardItemListWidget::editedRoleChanged(const QByteArray &current, const
         rect.setWidth(parent->width() - rect.left());
     }
     m_roleEditor->setGeometry(rect.toRect());
+    m_roleEditor->autoAdjustSize();
     m_roleEditor->show();
     m_roleEditor->setFocus();
 }
@@ -1015,8 +1016,11 @@ void KStandardItemListWidget::updatePixmapCache()
                 iconName = QStringLiteral("unknown");
             }
             const QStringList overlays = values["iconOverlays"].toStringList();
-            m_pixmap =
-                pixmapForIcon(iconName, overlays, maxIconHeight, m_layout != IconsLayout && isActiveWindow() && isSelected() ? QIcon::Selected : QIcon::Normal);
+            const bool hasFocus = scene()->views()[0]->parentWidget()->hasFocus();
+            m_pixmap = pixmapForIcon(iconName,
+                                     overlays,
+                                     maxIconHeight,
+                                     m_layout != IconsLayout && isActiveWindow() && isSelected() && hasFocus ? QIcon::Selected : QIcon::Normal);
 
         } else if (m_pixmap.width() / m_pixmap.devicePixelRatio() != maxIconWidth || m_pixmap.height() / m_pixmap.devicePixelRatio() != maxIconHeight) {
             // A custom pixmap has been applied. Assure that the pixmap
@@ -1202,6 +1206,16 @@ QString KStandardItemListWidget::elideRightKeepExtension(const QString &text, in
     return m_customizedFontMetrics.elidedText(text, Qt::ElideRight, elidingWidth);
 }
 
+QString KStandardItemListWidget::escapeString(const QString &text) const
+{
+    QString escaped(text);
+
+    const QChar returnSymbol(0x21b5);
+    escaped.replace('\n', returnSymbol);
+
+    return escaped;
+}
+
 void KStandardItemListWidget::updateIconsLayoutTextCache()
 {
     //      +------+
@@ -1224,7 +1238,7 @@ void KStandardItemListWidget::updateIconsLayoutTextCache()
     // Initialize properties for the "text" role. It will be used as anchor
     // for initializing the position of the other roles.
     TextInfo *nameTextInfo = m_textInfo.value("text");
-    const QString nameText = KStringHandler::preProcessWrap(values["text"].toString());
+    const QString nameText = KStringHandler::preProcessWrap(escapeString(values["text"].toString()));
     nameTextInfo->staticText.setText(nameText);
 
     // Calculate the number of lines required for the name and the required width
@@ -1278,7 +1292,7 @@ void KStandardItemListWidget::updateIconsLayoutTextCache()
 
     // Calculate the position for each additional information
     qreal y = nameTextInfo->pos.y() + nameHeight;
-    for (const QByteArray &role : qAsConst(m_sortedVisibleRoles)) {
+    for (const QByteArray &role : std::as_const(m_sortedVisibleRoles)) {
         if (role == "text") {
             continue;
         }
@@ -1344,8 +1358,8 @@ void KStandardItemListWidget::updateCompactLayoutTextCache()
     const qreal x = option.padding * 3 + iconSize();
     qreal y = qRound((widgetHeight - textLinesHeight) / 2);
     const qreal maxWidth = size().width() - x - option.padding;
-    for (const QByteArray &role : qAsConst(m_sortedVisibleRoles)) {
-        const QString text = roleText(role, values);
+    for (const QByteArray &role : std::as_const(m_sortedVisibleRoles)) {
+        const QString text = escapeString(roleText(role, values));
         TextInfo *textInfo = m_textInfo.value(role);
         textInfo->staticText.setText(text);
 
@@ -1394,7 +1408,7 @@ void KStandardItemListWidget::updateDetailsLayoutTextCache()
     qreal x = firstColumnInc;
     const qreal y = qMax(qreal(option.padding), (widgetHeight - fontHeight) / 2);
 
-    for (const QByteArray &role : qAsConst(m_sortedVisibleRoles)) {
+    for (const QByteArray &role : std::as_const(m_sortedVisibleRoles)) {
         QString text = roleText(role, values);
 
         // Elide the text in case it does not fit into the available column-width
@@ -1404,6 +1418,7 @@ void KStandardItemListWidget::updateDetailsLayoutTextCache()
 
         const bool isTextRole = (role == "text");
         if (isTextRole) {
+            text = escapeString(text);
             availableTextWidth -= firstColumnInc - sidePadding();
         }
 
@@ -1433,9 +1448,10 @@ void KStandardItemListWidget::updateDetailsLayoutTextCache()
 void KStandardItemListWidget::updateAdditionalInfoTextColor()
 {
     QColor c1;
+    const bool hasFocus = scene()->views()[0]->parentWidget()->hasFocus();
     if (m_customTextColor.isValid()) {
         c1 = m_customTextColor;
-    } else if (isSelected() && (m_layout != DetailsLayout || m_highlightEntireRow)) {
+    } else if (isSelected() && hasFocus && (m_layout != DetailsLayout || m_highlightEntireRow)) {
         // The detail text colour needs to match the main text (HighlightedText) for the same level
         // of readability. We short circuit early here to avoid interpolating with another colour.
         m_additionalInfoTextColor = styleOption().palette.color(QPalette::HighlightedText);