]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/tooltips/tooltipmanager.cpp
Fix issue that the columns "Link Destination" and "Path" are shown outside the visibl...
[dolphin.git] / src / tooltips / tooltipmanager.cpp
index dc2663ebe9932c672586b847723b4d0cc0e8704d..bf26908ba4c4832a291b156075f2401fa1dc47cb 100644 (file)
@@ -123,7 +123,7 @@ void ToolTipManager::requestToolTip(const QModelIndex& index)
     // drag & drop operation is done (indicated by the left mouse button)
     if ((index.column() == DolphinModel::Name) && !(QApplication::mouseButtons() & Qt::LeftButton)) {
         m_waitOnPreviewTimer->stop();
-        m_fileMetaDataToolTip->hide();
+        hideToolTip();
 
         m_itemRect = m_view->visualRect(index);
         const QPoint pos = m_view->viewport()->mapToGlobal(m_itemRect.topLeft());
@@ -151,6 +151,7 @@ void ToolTipManager::hideToolTip()
     m_waitOnPreviewTimer->stop();
 
     m_fileMetaDataToolTip->hide();
+    m_fileMetaDataToolTip->setItems(KFileItemList());
 }
 
 void ToolTipManager::prepareToolTip()
@@ -225,6 +226,15 @@ void ToolTipManager::showToolTip(const QPixmap& pixmap)
         return;
     }
 
+    // The size hint provided by the tooltip is not necessarily equal to the
+    // real size of the tooltip after showing it. As long as the tooltip is aligned
+    // on the upper-left edge, this is no problem. If the tooltip is aligned at
+    // another edge, the real size must be respected and the position
+    // corrected. Whether a correction must be done, is indicated by the variables
+    // updateWidth and updateHeight:
+    bool updateWidth = false;
+    bool updateHeight = false;
+    
     int x = 0;
     int y = 0;
     if (hasRoomBelow || hasRoomAbove) {
@@ -232,18 +242,46 @@ void ToolTipManager::showToolTip(const QPixmap& pixmap)
         if (x + size.width() >= desktop.right()) {
             x = desktop.right() - size.width();
         }
-        y = hasRoomBelow ? m_itemRect.bottom() : m_itemRect.top() - size.height();
+        if (hasRoomBelow) {
+            y = m_itemRect.bottom();
+        } else {
+            y = m_itemRect.top() - size.height();
+            updateHeight = true;
+        }
     } else {
         Q_ASSERT(hasRoomToLeft || hasRoomToRight);
-        x = hasRoomToRight ? m_itemRect.right() : m_itemRect.left() - size.width();
+        if (hasRoomToRight) {
+            x = m_itemRect.right();
+        } else {
+            x = m_itemRect.left() - size.width();
+            updateWidth = true;
+        }
 
         // Put the tooltip at the bottom of the screen. The x-coordinate has already
         // been adjusted, so that no overlapping with m_itemRect occurs.
         y = desktop.bottom() - size.height();
+        updateHeight = true;
     }
 
-    m_fileMetaDataToolTip->move(x, y);
-    m_fileMetaDataToolTip->show();
+    if (!updateWidth && !updateHeight) {
+        // Default case: There is enough room below and right of the mouse
+        // pointer and the tooltip can be positioned there.
+        m_fileMetaDataToolTip->move(x, y);
+        m_fileMetaDataToolTip->show();
+    } else {
+        // There is not enough room to show the tooltip at the default position and
+        // it must be moved left or upwards. In this case the size hint of the
+        // tooltip is not sufficient and the real size must be respected.
+        // To prevent a flickering, the tooltip is first opened outside the visible
+        // desktop area and moved afterwards.
+        m_fileMetaDataToolTip->move(desktop.right() + 1, desktop.bottom() + 1);
+        m_fileMetaDataToolTip->show();
+
+        const QSize shownSize = m_fileMetaDataToolTip->size();
+        const int xDiff = updateWidth ? shownSize.width() - size.width() : 0;
+        const int yDiff = updateHeight ? shownSize.height() - size.height() : 0;
+        m_fileMetaDataToolTip->move(x - xDiff, y - yDiff);
+    }
 }
 
 #include "tooltipmanager.moc"