]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Add a small invisible margin to the selection toggle in case the item-height is nearl...
authorPeter Penz <peter.penz19@gmail.com>
Wed, 22 Sep 2010 19:12:09 +0000 (19:12 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Wed, 22 Sep 2010 19:12:09 +0000 (19:12 +0000)
BUG: 169494
FIXED-IN: 4.6.0

svn path=/trunk/KDE/kdebase/apps/; revision=1178332

src/views/selectionmanager.cpp
src/views/selectiontoggle.cpp
src/views/selectiontoggle.h

index ac5f1c939cb8a35d8973e80fe9f3c669a72755e6..7353e5a39e940968cda76f50520ec39707519a92 100644 (file)
@@ -94,27 +94,27 @@ void SelectionManager::slotEntered(const QModelIndex& index)
             m_connected = true;
         }
 
-        // increase the size of the toggle for large items
-        const int height = m_view->iconSize().height();
-        if (height >= KIconLoader::SizeEnormous) {
-            m_toggle->resize(KIconLoader::SizeMedium, KIconLoader::SizeMedium);
-        } else if (height >= KIconLoader::SizeLarge) {
-            m_toggle->resize(KIconLoader::SizeSmallMedium, KIconLoader::SizeSmallMedium);
-        } else {
-            m_toggle->resize(KIconLoader::SizeSmall, KIconLoader::SizeSmall);
+        // Increase the size of the toggle for large items
+        const int iconHeight = m_view->iconSize().height();
+
+        int toggleSize = KIconLoader::SizeSmall;
+        if (iconHeight >= KIconLoader::SizeEnormous) {
+            toggleSize = KIconLoader::SizeMedium;
+        } else if (iconHeight >= KIconLoader::SizeLarge) {
+            toggleSize = KIconLoader::SizeSmallMedium;
         }
 
+        // Add a small invisible margin, if the item-height is nearly
+        // equal to the toggleSize (#169494).
         const QRect rect = m_view->visualRect(index);
-        int x = rect.left();
-        int y = rect.top();
-        if (height < KIconLoader::SizeSmallMedium) {
-            // The height is nearly equal to the smallest toggle height.
-            // Assure that the toggle is vertically centered instead
-            // of aligned on the top and gets more horizontal gap.
-            x += 2;
-            y += (rect.height() - m_toggle->height()) / 2;
+        int margin = (rect.height() - toggleSize) / 2;
+        if (margin > 4) {
+            margin = 0;
         }
-        m_toggle->move(QPoint(x, y));
+        toggleSize += 2 * margin;
+        m_toggle->setMargin(margin);
+        m_toggle->resize(toggleSize, toggleSize);
+        m_toggle->move(rect.topLeft());
 
         QItemSelectionModel* selModel = m_view->selectionModel();
         m_toggle->setChecked(selModel->isSelected(index));
index d802e22e082f73396ced43d816da704f2dea3cda..f5287a3dd7a2c05637f5669de31d61865696d7cc 100644 (file)
@@ -36,6 +36,7 @@ SelectionToggle::SelectionToggle(QWidget* parent) :
     m_isHovered(false),
     m_leftMouseButtonPressed(false),
     m_fadingValue(0),
+    m_margin(0),
     m_icon(),
     m_fadingTimeLine(0)
 {
@@ -72,6 +73,19 @@ void SelectionToggle::setUrl(const KUrl& url)
     }
 }
 
+void SelectionToggle::setMargin(int margin)
+{
+    if (margin != m_margin) {
+        m_margin = margin;
+        update();
+    }
+}
+
+int SelectionToggle::margin() const
+{
+    return m_margin;
+}
+
 KUrl SelectionToggle::url() const
 {
     return m_url;
@@ -161,10 +175,11 @@ void SelectionToggle::paintEvent(QPaintEvent* event)
     painter.setClipRect(event->rect());
 
     // draw the icon overlay
+    const QPoint pos(m_margin, m_margin);
     if (m_isHovered) {
         KIconEffect *iconEffect = KIconLoader::global()->iconEffect();
         QPixmap activeIcon = iconEffect->apply(m_icon, KIconLoader::Desktop, KIconLoader::ActiveState);
-        painter.drawPixmap(0, 0, activeIcon);
+        painter.drawPixmap(pos, activeIcon);
     } else {
         if (m_fadingValue < 255) {
             // apply an alpha mask respecting the fading value to the icon
@@ -173,12 +188,13 @@ void SelectionToggle::paintEvent(QPaintEvent* event)
             const QColor color(m_fadingValue, m_fadingValue, m_fadingValue);
             alphaMask.fill(color);
             icon.setAlphaChannel(alphaMask);
-            painter.drawPixmap(0, 0, icon);
+            painter.drawPixmap(pos, icon);
         } else {
             // no fading is required
-            painter.drawPixmap(0, 0, m_icon);
+            painter.drawPixmap(pos, m_icon);
         }
     }
+
 }
 
 void SelectionToggle::setFadingValue(int value)
@@ -194,9 +210,10 @@ void SelectionToggle::setFadingValue(int value)
 void SelectionToggle::setIconOverlay(bool checked)
 {
     const char* icon = checked ? "list-remove" : "list-add";
+    const int size = qMin(width() - 2 * m_margin, height() - 2 * m_margin);
     m_icon = KIconLoader::global()->loadIcon(icon,
                                              KIconLoader::NoGroup,
-                                             qMin(width(), height()));
+                                             size);
     update();
 }
 
index 5519272b38ed81116f3e9bf8152802d71a82b20f..210f1a3aa5b4e6b2c0bf61a56e2a89b28a1938cb 100644 (file)
@@ -53,6 +53,13 @@ public:
     void setUrl(const KUrl& url);
     KUrl url() const;
 
+    /**
+     * Sets the margin around the selection-icon in pixels. Per default
+     * the value is 0.
+     */
+    void setMargin(int margin);
+    int margin() const;
+
 public slots:
     virtual void setVisible(bool visible);
 
@@ -83,6 +90,7 @@ private:
     bool m_isHovered;
     bool m_leftMouseButtonPressed;
     int m_fadingValue;
+    int m_margin;
     QPixmap m_icon;
     QTimeLine* m_fadingTimeLine;
     KUrl m_url;