]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Assure that the item size is not exceeded -> the spacing is also respected for texts...
authorPeter Penz <peter.penz19@gmail.com>
Wed, 18 Jul 2007 19:52:28 +0000 (19:52 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Wed, 18 Jul 2007 19:52:28 +0000 (19:52 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=689651

src/dolphiniconsview.cpp
src/dolphiniconsview.h

index 237a319c835e181609db9fb341aa27cf4324879f..394dae3177a19ec1f5a774f0f60c8b254c27d61d 100644 (file)
@@ -35,7 +35,9 @@
 DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
     KCategorizedView(parent),
     m_controller(controller),
-    m_dragging(false)
+    m_itemSize(),
+    m_dragging(false),
+    m_dropRect()
 {
     Q_ASSERT(controller != 0);
     setViewMode(QListView::IconMode);
@@ -93,6 +95,39 @@ DolphinIconsView::~DolphinIconsView()
 {
 }
 
+QRect DolphinIconsView::visualRect(const QModelIndex& index) const
+{
+    if (itemCategorizer() == 0) {
+        const bool leftToRightFlow = (flow() == QListView::LeftToRight);
+
+        QRect itemRect = KCategorizedView::visualRect(index);
+        const int maxWidth  = m_itemSize.width();
+        const int maxHeight = m_itemSize.height();
+
+        if (itemRect.width() > maxWidth) {
+            // assure that the maximum item width is not exceeded
+            if (leftToRightFlow) {
+                const int left = itemRect.left() + (itemRect.width() - maxWidth) / 2;
+                itemRect.setLeft(left);
+            }
+            itemRect.setWidth(maxWidth);
+        }
+
+        if (itemRect.height() > maxHeight) {
+            // assure that the maximum item height is not exceeded
+            if (!leftToRightFlow) {
+                const int top = itemRect.top() + (itemRect.height() - maxHeight) / 2;
+                itemRect.setTop(top);
+            }
+            itemRect.setHeight(maxHeight);
+        }
+
+        return itemRect;
+    }
+
+    return KCategorizedView::visualRect(index);
+}
+
 QStyleOptionViewItem DolphinIconsView::viewOptions() const
 {
     return m_viewOptions;
@@ -321,6 +356,8 @@ void DolphinIconsView::updateGridSize(bool showPreview, bool showAdditionalInfo)
     const int spacing = settings->gridSpacing();
     setGridSize(QSize(itemWidth + spacing, itemHeight + spacing));
 
+    m_itemSize = QSize(itemWidth, itemHeight);
+
     m_controller->setZoomInPossible(isZoomInPossible());
     m_controller->setZoomOutPossible(isZoomOutPossible());
 }
index ec18400c6ed992bb6b3f7f4308a1f19ed74e902f..7e5544ec09fe5574836a1c920ba4f7098e511cc9 100644 (file)
 
 #include <kcategorizedview.h>
 #include <kitemcategorizer.h>
-#include <QtGui/QStyleOption>
+
+#include <QSize>
+#include <QStyleOption>
+
 #include <libdolphin_export.h>
 
 class DolphinController;
@@ -41,6 +44,9 @@ public:
     explicit DolphinIconsView(QWidget* parent, DolphinController* controller);
     virtual ~DolphinIconsView();
 
+    /** @see QAbstractItemView::visualRect() */
+    virtual QRect visualRect(const QModelIndex& index) const;
+
 protected:
     virtual QStyleOptionViewItem viewOptions() const;
     virtual void contextMenuEvent(QContextMenuEvent* event);
@@ -77,6 +83,8 @@ private:
     DolphinController* m_controller;
     QStyleOptionViewItem m_viewOptions;
 
+    QSize m_itemSize;
+
     bool m_dragging;   // TODO: remove this property when the issue #160611 is solved in Qt 4.4
     QRect m_dropRect;  // TODO: remove this property when the issue #160611 is solved in Qt 4.4
 };