]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinview.cpp
Add name-only tooltip and make logicalHeightHints a pair of qreal and bool
[dolphin.git] / src / views / dolphinview.cpp
index bb537b982af6b3a35d575a2c9f2d64e2b5285600..573505e763122478666d1c1dae3c89b092f2ba8d 100644 (file)
@@ -59,6 +59,7 @@
 #include <QScrollBar>
 #include <QSize>
 #include <QTimer>
 #include <QScrollBar>
 #include <QSize>
 #include <QTimer>
+#include <QToolTip>
 #include <QVBoxLayout>
 
 DolphinView::DolphinView(const QUrl& url, QWidget* parent) :
 #include <QVBoxLayout>
 
 DolphinView::DolphinView(const QUrl& url, QWidget* parent) :
@@ -918,6 +919,11 @@ bool DolphinView::eventFilter(QObject* watched, QEvent* event)
         if (watched == m_view) {
             m_dragging = false;
         }
         if (watched == m_view) {
             m_dragging = false;
         }
+        break;
+
+    case QEvent::ToolTip:
+        tryShowNameToolTip(event);
+
     default:
         break;
     }
     default:
         break;
     }
@@ -1637,13 +1643,15 @@ void DolphinView::updateViewState()
 
 void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior)
 {
 
 void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior)
 {
-#ifdef HAVE_BALOO
     if (GeneralSettings::showToolTips()) {
     if (GeneralSettings::showToolTips()) {
+#ifdef HAVE_BALOO
         m_toolTipManager->hideToolTip(behavior);
         m_toolTipManager->hideToolTip(behavior);
-    }
 #else
         Q_UNUSED(behavior)
 #endif
 #else
         Q_UNUSED(behavior)
 #endif
+    } else if (m_mode == DolphinView::IconsView) {
+       QToolTip::hideText();
+    }
 }
 
 void DolphinView::slotTwoClicksRenamingTimerTimeout()
 }
 
 void DolphinView::slotTwoClicksRenamingTimerTimeout()
@@ -2158,3 +2166,25 @@ void DolphinView::updatePlaceholderLabel()
 
     m_placeholderLabel->setVisible(true);
 }
 
     m_placeholderLabel->setVisible(true);
 }
+
+void DolphinView::tryShowNameToolTip(QEvent* event)
+{
+    if (!GeneralSettings::showToolTips() && m_mode == DolphinView::IconsView) {
+        QHelpEvent *hoverEvent = reinterpret_cast<QHelpEvent *>(event);
+        const int index = m_view->itemAt(hoverEvent->pos());
+
+        if (index == -1) {
+            return;
+        }
+
+        // Check whether the filename has been elided
+        const bool isElided = m_view->isElided(index);
+
+        if(isElided) {
+            const KFileItem item = m_model->fileItem(index);
+            const QString text = item.text();
+            const QPoint pos = mapToGlobal(hoverEvent->pos());
+            QToolTip::showText(pos, text);
+        }
+    }
+}