]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kstandarditemlistwidget.cpp
Fix blinking when moving the mouse over an hidden item
[dolphin.git] / src / kitemviews / kstandarditemlistwidget.cpp
index c49031a41322c357568e8746687d0ab5c47a5f73..fcd0520457dc2cbe3ca1435129e20a0b9dfb28fc 100644 (file)
@@ -194,7 +194,8 @@ KStandardItemListWidget::KStandardItemListWidget(KItemListWidgetInformant* infor
     m_additionalInfoTextColor(),
     m_overlay(),
     m_rating(),
-    m_roleEditor(0)
+    m_roleEditor(0),
+    m_oldRoleEditor(0)
 {
 }
 
@@ -204,6 +205,7 @@ KStandardItemListWidget::~KStandardItemListWidget()
     m_textInfo.clear();
 
     delete m_roleEditor;
+    delete m_oldRoleEditor;
 }
 
 void KStandardItemListWidget::setLayout(Layout layout)
@@ -247,13 +249,14 @@ void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphic
 
     const KItemListStyleOption& itemListStyleOption = styleOption();
     if (isHovered()) {
+        const qreal opacity = painter->opacity();
         // Blend the unhovered and hovered pixmap if the hovering
         // animation is ongoing
         if (hoverOpacity() < 1.0) {
+            painter->setOpacity((1.0 - hoverOpacity()) * opacity);
             drawPixmap(painter, m_pixmap);
         }
 
-        const qreal opacity = painter->opacity();
         painter->setOpacity(hoverOpacity() * opacity);
         drawPixmap(painter, m_hoverPixmap);
         painter->setOpacity(opacity);
@@ -601,8 +604,8 @@ void KStandardItemListWidget::editedRoleChanged(const QByteArray& current, const
 {
     Q_UNUSED(previous);
 
-   QGraphicsView* parent = scene()->views()[0];
-   if (current.isEmpty() || !parent || current != "text") {
+    QGraphicsView* parent = scene()->views()[0];
+    if (current.isEmpty() || !parent || current != "text") {
         if (m_roleEditor) {
             emit roleEditingCanceled(index(), current, data().value(current));
 
@@ -610,10 +613,16 @@ void KStandardItemListWidget::editedRoleChanged(const QByteArray& current, const
                        this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
             disconnect(m_roleEditor, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
                        this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
-            m_roleEditor->deleteLater();
+            m_oldRoleEditor = m_roleEditor;
+            m_roleEditor->hide();
             m_roleEditor = 0;
         }
         return;
+    } else if (m_oldRoleEditor) {
+        // Delete the old editor before constructing the new one to
+        // prevent a memory leak.
+        m_oldRoleEditor->deleteLater();
+        m_oldRoleEditor = 0;
     }
 
     Q_ASSERT(!m_roleEditor);
@@ -832,7 +841,7 @@ void KStandardItemListWidget::updatePixmapCache()
         if (isSelected()) {
             const QColor color = palette().brush(QPalette::Normal, QPalette::Highlight).color();
             QImage image = m_pixmap.toImage();
-            KIconEffect::colorize(image, color, 1.0f);
+            KIconEffect::colorize(image, color, 0.8f);
             m_pixmap = QPixmap::fromImage(image);
         }
     }
@@ -1265,17 +1274,19 @@ QRectF KStandardItemListWidget::roleEditingRect(const QByteArray& role) const
 
 void KStandardItemListWidget::closeRoleEditor()
 {
+    disconnect(m_roleEditor, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)),
+               this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
+    disconnect(m_roleEditor, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
+               this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
+
     if (m_roleEditor->hasFocus()) {
         // If the editing was not ended by a FocusOut event, we have
         // to transfer the keyboard focus back to the KItemListContainer.
         scene()->views()[0]->parentWidget()->setFocus();
     }
 
-    disconnect(m_roleEditor, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)),
-               this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
-    disconnect(m_roleEditor, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
-               this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
-    m_roleEditor->deleteLater();
+    m_oldRoleEditor = m_roleEditor;
+    m_roleEditor->hide();
     m_roleEditor = 0;
 }