]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kstandarditemlistwidget.cpp
Merge branch 'master' into frameworks
[dolphin.git] / src / kitemviews / kstandarditemlistwidget.cpp
index f7cf524842571d7631f65430c21ffbcaa4f9f3f9..f663b872555011288784933d1ed83bf60b983166 100644 (file)
 #include "kfileitemlistview.h"
 #include "kfileitemmodel.h"
 
-#include <KIcon>
+#include <QIcon>
 #include <KIconEffect>
 #include <KIconLoader>
-#include <KLocale>
-#include <kratingpainter.h>
+#include <KRatingPainter>
 #include <KStringHandler>
-#include <KDebug>
 
 #include "private/kfileitemclipboard.h"
 #include "private/kitemlistroleeditor.h"
 #include "private/kpixmapmodifier.h"
 
-#include <QFontMetricsF>
 #include <QGraphicsScene>
 #include <QGraphicsSceneResizeEvent>
 #include <QGraphicsView>
@@ -120,6 +117,8 @@ QString KStandardItemListWidgetInformant::itemText(int index, const KItemListVie
 
 bool KStandardItemListWidgetInformant::itemIsLink(int index, const KItemListView* view) const
 {
+    Q_UNUSED(index);
+    Q_UNUSED(view);
     return false;
 }
 
@@ -494,6 +493,29 @@ QRectF KStandardItemListWidget::textFocusRect() const
     return m_textRect;
 }
 
+QRectF KStandardItemListWidget::selectionRect() const
+{
+    const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing();
+
+    switch (m_layout) {
+    case IconsLayout:
+        return m_textRect;
+
+    case CompactLayout:
+    case DetailsLayout: {
+        const int padding = styleOption().padding;
+        QRectF adjustedIconRect = iconRect().adjusted(-padding, -padding, padding, padding);
+        return adjustedIconRect | m_textRect;
+    }
+
+    default:
+        Q_ASSERT(false);
+        break;
+    }
+
+    return m_textRect;
+}
+
 QRectF KStandardItemListWidget::expansionToggleRect() const
 {
     const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing();
@@ -659,7 +681,7 @@ void KStandardItemListWidget::dataChanged(const QHash<QByteArray, QVariant>& cur
     // The URL might have changed (i.e., if the sort order of the items has
     // been changed). Therefore, the "is cut" state must be updated.
     KFileItemClipboard* clipboard = KFileItemClipboard::instance();
-    const KUrl itemUrl = data().value("url").value<KUrl>();
+    const QUrl itemUrl = data().value("url").value<QUrl>();
     m_isCut = clipboard->isCut(itemUrl);
 
     // The icon-state might depend from other roles and hence is
@@ -810,7 +832,7 @@ void KStandardItemListWidget::showEvent(QShowEvent* event)
     // Listen to changes of the clipboard to mark the item as cut/uncut
     KFileItemClipboard* clipboard = KFileItemClipboard::instance();
 
-    const KUrl itemUrl = data().value("url").value<KUrl>();
+    const QUrl itemUrl = data().value("url").value<QUrl>();
     m_isCut = clipboard->isCut(itemUrl);
 
     connect(clipboard, &KFileItemClipboard::cutItemsChanged,
@@ -827,7 +849,7 @@ void KStandardItemListWidget::hideEvent(QHideEvent* event)
 
 void KStandardItemListWidget::slotCutItemsChanged()
 {
-    const KUrl itemUrl = data().value("url").value<KUrl>();
+    const QUrl itemUrl = data().value("url").value<QUrl>();
     const bool isCut = KFileItemClipboard::instance()->isCut(itemUrl);
     if (m_isCut != isCut) {
         m_isCut = isCut;
@@ -945,7 +967,7 @@ void KStandardItemListWidget::updatePixmapCache()
             KIconEffect::semiTransparent(m_pixmap);
         }
 
-        if (isSelected()) {
+        if (m_layout == IconsLayout && isSelected()) {
             const QColor color = palette().brush(QPalette::Normal, QPalette::Highlight).color();
             QImage image = m_pixmap.toImage();
             KIconEffect::colorize(image, color, 0.8f);
@@ -1113,14 +1135,24 @@ void KStandardItemListWidget::updateIconsLayoutTextCache()
             const int textLength = line.textStart() + line.textLength();
             if (textLength < nameText.length()) {
                 // Elide the last line of the text
-                QString lastTextLine = nameText.mid(line.textStart());
-                lastTextLine = m_customizedFontMetrics.elidedText(lastTextLine,
-                                                                  Qt::ElideRight,
-                                                                  maxWidth);
-                const QString elidedText = nameText.left(line.textStart()) + lastTextLine;
-                nameTextInfo->staticText.setText(elidedText);
-
-                const qreal lastLineWidth = m_customizedFontMetrics.boundingRect(lastTextLine).width();
+                qreal elidingWidth = maxWidth;
+                qreal lastLineWidth;
+                do {
+                    QString lastTextLine = nameText.mid(line.textStart());
+                    lastTextLine = m_customizedFontMetrics.elidedText(lastTextLine,
+                                                                      Qt::ElideRight,
+                                                                      elidingWidth);
+                    const QString elidedText = nameText.left(line.textStart()) + lastTextLine;
+                    nameTextInfo->staticText.setText(elidedText);
+
+                    lastLineWidth = m_customizedFontMetrics.boundingRect(lastTextLine).width();
+
+                    // We do the text eliding in a loop with decreasing width (1 px / iteration)
+                    // to avoid problems related to different width calculation code paths
+                    // within Qt. (see bug 337104)
+                    elidingWidth -= 1.0;
+                } while (lastLineWidth > maxWidth);
+
                 nameWidth = qMax(nameWidth, lastLineWidth);
             }
             break;
@@ -1407,7 +1439,7 @@ QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, const QStrin
     QPixmap pixmap;
 
     if (!QPixmapCache::find(key, pixmap)) {
-        const KIcon icon(name);
+        const QIcon icon = QIcon::fromTheme(name);
 
         int requestedSize;
         if (size <= KIconLoader::SizeSmall) {